Example #1
0
 /// <summary>
 /// REmove web hook
 /// </summary>
 /// <returns></returns>
 public async Task RemoveWebhookAsync()
 {
     try
     {
         var webhookParams = new WebhookParams("");
         await MakeApiRequestAsync <SetWebhookApiResponse>("set_webhook", webhookParams);
     }
     catch (Exception ex)
     { }
 }
Example #2
0
        /// <inheritdoc/>
        public async Task <Webhook> CreateWebhookAsync(string name, string targetUrl, WebhookResource resource,
                                                       EventType eventType, string filter = "", string secret = "")
        {
            ValidateWebhookParameters(name, targetUrl);

            var webhookParams = new WebhookParams
            {
                Name      = name,
                TargetUrl = targetUrl,
                Resource  = resource,
                Event     = eventType,
                Filter    = filter,
                Secret    = secret
            };

            return(await TeamsClient.PostResultAsync <Webhook, WebhookParams>(WxTeamsConstants.WebhooksUrl, webhookParams));
        }
Example #3
0
        public async Task <IActionResult> SetWebhookAsync()
        {
            try
            {
                WebhookParams p = new WebhookParams(_configuration["HttpsForWeebHook"]);
                p.EventTypes    = ((IEnumerable <EventTypeEnum>)Enum.GetValues(typeof(EventTypeEnum)));
                p.SendUserName  = true;
                p.SendUserPhoto = true;
                var retVal = await _viberBot.SetWebhookAsync(p);

                return(Ok(retVal));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.ToString(), "FUBAR here");
                return(null);
            }
        }
Example #4
0
        async Task Dispatch(Event <LogEventData> evt)
        {
            using (var client = new HttpClient())
            {
                client.Timeout = new TimeSpan(0, 0, 10);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                var title = evt.Data.Level.ToString();
                if (!string.IsNullOrWhiteSpace(TitlePropertyName) && evt.Data.Properties.ContainsKey(TitlePropertyName))
                {
                    title = evt.Data.Properties[TitlePropertyName].ToString() + " - " + title;
                }

                var prms = new WebhookParams
                {
                    UserName  = string.IsNullOrWhiteSpace(NotifierBotName) ? "Seq notifier" : NotifierBotName,
                    AvatarUrl = AvatarUrl,
                    Embeds    = new WebhookParamsEmbeds[]
                    {
                        new WebhookParamsEmbeds()
                        {
                            Title       = title,
                            Url         = string.Format("{0}/#/events?filter=@Id%20%3D%3D%20%22{1}%22&show=expanded\">", BaseUrl, evt.Id),
                            Description = evt.Data.RenderedMessage,
                            Color       = Color.HasValue ? Color.Value : _levelColorMap[evt.Data.Level]
                        }
                    }
                };

                var response = await client.PostAsJsonAsync(
                    DiscordWebhookUrl,
                    prms);

                if (!response.IsSuccessStatusCode)
                {
                    Log
                    .ForContext("Uri", response.RequestMessage.RequestUri)
                    .Error("Could not send Discord message {@prms}, server replied {StatusCode} {StatusMessage}: {Message}", prms, Convert.ToInt32(response.StatusCode), response.StatusCode, await response.Content.ReadAsStringAsync());
                }
            }
        }
Example #5
0
        /// <summary>
        /// Set Web Hook
        /// </summary>
        /// <param name="webhookParams"></param>
        /// <returns></returns>
        public async Task <IEnumerable <EventTypeEnum> > SetWebhookAsync(WebhookParams webhookParams)
        {
            var result = new SetWebhookApiResponse();

            try
            {
                if (webhookParams == null)
                {
                    throw new ArgumentNullException(nameof(webhookParams));
                }

                result = await MakeApiRequestAsync <SetWebhookApiResponse>("set_webhook", webhookParams);

                _logger.LogInformation("this thing Works " + nameof(SetWebhookAsync));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.ToString(), nameof(SetWebhookAsync));
            }
            return(result?.EventTypes);
        }
Example #6
0
        /// <inheritdoc/>
        public async Task <Webhook> UpdateWebhookAsync(string webhookId, string name, string targetUrl, string secret = "",
                                                       WebhookStatus?status = null)
        {
            ValidateWebhookParameters(name, targetUrl);

            var webhookParams = new WebhookParams
            {
                Name      = name,
                TargetUrl = targetUrl
            };

            if (!string.IsNullOrEmpty(secret))
            {
                webhookParams.Secret = secret;
            }

            if (status != null)
            {
                webhookParams.Status = status;
            }

            return(await TeamsClient.PutResultAsync <Webhook, WebhookParams>($"{WxTeamsConstants.WebhooksUrl}/{webhookId}", webhookParams));
        }