public static bool kaiden_discord_event_publish(string magicParam) { try { PgUnicorn unicorn = new PgUnicorn(); DataTable eventsToAnnounce = unicorn.DataTableOfSql("select id, name from events where published_discord = false AND published = true"); foreach (DataRow ev in eventsToAnnounce.Rows) { // ex. https://my.bendrocorp.com/events#!/op-sunday-76 // Send WebHook to general chat WebHookPayload webHookPayload = new WebHookPayload() { content = $"@everyone A new operation has been posted to the Employee Portal! You can get more information here: https://my.bendrocorp.com/events/{ev["id"].ToString()}" }; WebhookSender.Send(generalDiscordChannel, webHookPayload).Wait(); unicorn.ExecuteNonQueryOfSql($"update events set published_discord = true where id = {ev["id"].ToString()}"); } return(true); } catch (Exception) { return(false); } }
public static async Task <bool> Send(string uri, WebHookPayload payload) { var client = new HttpClient(); HttpResponseMessage res = await client.PostAsync(uri, new StringContent(JsonConvert.SerializeObject(payload), Encoding.UTF8, "application/json")); if (res.StatusCode == System.Net.HttpStatusCode.OK) { return(true); } else { return(false); } }