Ejemplo n.º 1
0
        public static void PostMessage(string title, string text, params Attachment[] attachments)
        {
            if (!Enabled) {
                return;
            }

            var payload = new SlackPayload
            {
                Username = Username,
                IconEmoji = IconEmoji,
                IconUrl = IconUrl,
                Channel = Channel,
                Title = title,
                Text = text,
                Attachments = attachments.ToList()
            };

            PostMessage(payload);
        }
Ejemplo n.º 2
0
        public static void PostMessage(string title, string text, params Attachment[] attachments)
        {
            if (!Enabled)
            {
                return;
            }

            var payload = new SlackPayload
            {
                Username    = Username,
                IconEmoji   = IconEmoji,
                IconUrl     = IconUrl,
                Channel     = Channel,
                Title       = title,
                Text        = text,
                Attachments = attachments.ToList()
            };

            PostMessage(payload);
        }
Ejemplo n.º 3
0
        private static void PostMessage(SlackPayload payload)
        {
            if (payload == null) {
                throw new ArgumentException(nameof(payload));
            }

            var payloadSerialized = JsonConvert.SerializeObject(payload);

            var data = new List<KeyValuePair<string, string>> {
                new KeyValuePair<string, string>("payload", payloadSerialized)
            };

            using (var client = new HttpClient()) {
                var content = new FormUrlEncodedContent(data);

                client.PostAsync(WebhookUrl, content)
                      .ContinueWith(
                          (postTask) => {
                              postTask.Result.EnsureSuccessStatusCode();
                          }
                      );
            }
        }
Ejemplo n.º 4
0
        private static void PostMessage(SlackPayload payload)
        {
            if (payload == null)
            {
                throw new ArgumentException(nameof(payload));
            }

            var payloadSerialized = JsonConvert.SerializeObject(payload);

            var data = new List <KeyValuePair <string, string> > {
                new KeyValuePair <string, string>("payload", payloadSerialized)
            };

            using (var client = new HttpClient()) {
                var content = new FormUrlEncodedContent(data);

                client.PostAsync(WebhookUrl, content)
                .ContinueWith(
                    (postTask) => {
                    postTask.Result.EnsureSuccessStatusCode();
                }
                    );
            }
        }