コード例 #1
0
        public async Task <string> PushAsync(string webhook, MattermostNotificationBody message)
        {
            var request = new RestRequest
            {
                Method   = Method.POST,
                Resource = "/"
            };

            request.AddJsonBody(message);

            var api = new ApiRequest();

            return(await Task.Run(
                       () =>
            {
                var result = api.Execute(request, new Uri(webhook));
                return result.Content;
            }));
        }
コード例 #2
0
        private async Task Push(MattermostNotificationSettings config, string message)
        {
            try
            {
                var notification = new MattermostNotificationBody {
                    username = config.Username, channel = config.Channel ?? string.Empty, icon_url = config.IconUrl ?? string.Empty, text = message
                };

                var result = await Api.PushAsync(config.WebhookUrl, notification);

                if (!result.Equals("ok"))
                {
                    Log.Error("Mattermost returned a message that was not 'ok', the notification did not get pushed");
                    Log.Error($"Message that mattermost returned: {result}");
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }