Esempio n. 1
0
        private void ProcessWebHook(WebHooksPendingItem webhook)
        {
            UpdateHealth();
            webhook.IsProcessing = true;
            webhook.Collection.Save();

            //check what type of webhook it is:
            switch ((WebHookType)webhook.Type)
            {
            case WebHookType.Integration:
                //Right now only ServiceNow is integrated this way, so we only check for those links, however at some point we'll have to include more integrations here.
                ServiceNow serviceNow = new ServiceNow(webhook, LoginUser);
                serviceNow.Process(_threadNumber);
                break;

            default:
                Logs.WriteEvent("Unknown webhook type. Not implemented yet.");
                Logs.WriteData(webhook.Row);
                webhook.Delete();
                webhook.Collection.Save();
                break;
            }
        }
        private void ProcessIntegration(HttpContext context)
        {
            const int       orgIdSegment        = 4;
            const int       webhookTokenSegment = 5;
            IntegrationApps processApp;
            string          app = string.Empty;

            if (context.Request.Url.Segments.Count() > 3)
            {
                app = context.Request.Url.Segments[3].TrimEnd('/');

                if (Enum.TryParse(app, true, out processApp))
                {
                    CRMLinkTableItem crmLink = null;

                    switch (processApp)
                    {
                    case IntegrationApps.ServiceNow:
                        if (ValidateIntegrationRequest(processApp, context, ref crmLink))
                        {
                            int    organizationId = -1;
                            string webhookToken   = string.Empty;
                            int.TryParse(context.Request.Url.Segments[orgIdSegment].TrimEnd('/'), out organizationId);
                            webhookToken = context.Request.Url.Segments[webhookTokenSegment].TrimEnd('/');

                            string jsonData = ReadJsonData(context);

                            if (!string.IsNullOrEmpty(jsonData))
                            {
                                log.InfoFormat("Body: {0}", jsonData);

                                WebHooksPendingItem newPendingWebHook = (new WebHooksPending(LoginUser.Anonymous)).AddNewWebHooksPendingItem();
                                newPendingWebHook.OrganizationId = organizationId;
                                newPendingWebHook.RefType        = (int)ReferenceType.Tickets;
                                newPendingWebHook.Type           = (short)WebHookType.Integration;
                                newPendingWebHook.Url            = context.Request.Url.AbsolutePath;
                                newPendingWebHook.BodyData       = jsonData;
                                newPendingWebHook.Token          = webhookToken;
                                newPendingWebHook.Inbound        = true;
                                newPendingWebHook.IsProcessing   = false;
                                newPendingWebHook.DateCreated    = DateTime.UtcNow;
                                newPendingWebHook.Collection.Save();

                                Log(context, "Queued", LogType.Client);
                            }
                            else
                            {
                                Log(context, "This integration needs data to process and it was not found.", isError: true);
                                Log(context, "Body data is expected", LogType.Client, isError: true, httpStatusCode: HttpStatusCode.BadRequest);
                            }
                        }
                        break;

                    case IntegrationApps.Unknown:
                    default:
                        break;
                    }
                }
                else
                {
                    Log(context, string.Format("Integration webhook for \"{0}\" not found", app), isError: true);
                    Log(context, "Webhook requested not implemented", LogType.Client, isError: true, httpStatusCode: HttpStatusCode.NotImplemented);
                }
            }
            else
            {
                Log(context, "Integration type not found", LogType.Both, isError: true, httpStatusCode: HttpStatusCode.NotImplemented);
            }
        }
Esempio n. 3
0
 public WebHooks(WebHooksPendingItem webhook, int threadNumber)
 {
     _webHook      = webhook;
     _threadNumber = threadNumber;
 }