コード例 #1
0
ファイル: SlackNotification.cs プロジェクト: jwor80/Ombi
        protected override async Task Send(NotificationMessage model, SlackNotificationSettings settings)
        {
            try
            {
                var body = new SlackNotificationBody
                {
                    channel    = settings.Channel,
                    icon_emoji = settings.IconEmoji,
                    icon_url   = settings.IconUrl,
                    text       = model.Message,
                    username   = settings.Username
                };

                await Api.PushAsync(settings.Team, settings.Token, settings.Service, body);
            }
            catch (Exception e)
            {
                Logger.LogError(LoggingEvents.SlackNotification, e, "Failed to send Slack Notification");
            }
        }
コード例 #2
0
        private async Task Push(SlackNotificationSettings config, string message)
        {
            try
            {
                var notification = new SlackNotificationBody {
                    username = config.Username, channel = config.Channel ?? string.Empty, text = message
                };

                var result = await Api.PushAsync(config.Team, config.Token, config.Service, notification);

                if (!result.Equals("ok"))
                {
                    Log.Error("Slack returned a message that was not 'ok', the notification did not get pushed");
                    Log.Error($"Message that slack returned: {result}");
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
コード例 #3
0
        public async Task <string> PushAsync(string team, string token, string service, SlackNotificationBody message)
        {
            var request = new RestRequest
            {
                Method   = Method.POST,
                Resource = "/services/{team}/{service}/{token}"
            };

            request.AddUrlSegment("team", team);
            request.AddUrlSegment("service", service);
            request.AddUrlSegment("token", token);
            request.AddJsonBody(message);

            var api = new ApiRequest();

            return(await Task.Run(
                       () =>
            {
                var result = api.Execute(request, new Uri("https://hooks.slack.com/"));
                return result.Content;
            }));
        }
コード例 #4
0
ファイル: SlackApi.cs プロジェクト: itzfk0/ombi
        public async Task <string> PushAsync(string team, string token, string service, SlackNotificationBody message)
        {
            var     request = new Request($"/services/{team}/{service}/{token}", BaseUrl, HttpMethod.Post);
            dynamic body    = new ExpandoObject();

            body.channel    = message.channel;
            body.text       = message.text;
            body.username   = message.username;
            body.link_names = 1;

            if (!string.IsNullOrEmpty(message.icon_url))
            {
                body.icon_url = message.icon_url;
            }

            if (!string.IsNullOrEmpty(message.icon_emoji))
            {
                body.icon_emoji = message.icon_emoji;
            }
            request.AddJsonBody(body);
            request.ApplicationJsonContentType();

            return(await Api.RequestContent(request));
        }