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); }
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(); } ); } }
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(); } ); } }