using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; namespace GB5Shared.WebhookPublisher { public class WebhookPublisher : IWebhookPublisher { private readonly HttpClient _httpClient; public WebhookPublisher() { _httpClient = new HttpClient(); } public async Task TriggerWebhookAsync(string url, object payload) { string jsonPayload = JsonConvert.SerializeObject(payload); var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json"); try { HttpResponseMessage response = await _httpClient.PostAsync(url, content); if (response.IsSuccessStatusCode) { return "Webhook triggered successfully."; } else { return "Failed to trigger webhook"; } } catch (Exception ) { throw; } } } }