From 2e95b31a6f0375fb7500bedc981c7718e0c63d9f Mon Sep 17 00:00:00 2001 From: Wyatt Murray <113722636+Skyfall1235@users.noreply.github.com> Date: Mon, 1 Dec 2025 12:34:12 -0500 Subject: [PATCH 1/2] Add WebhookService and DatabaseService classes Implemented WebhookService and DatabaseService classes with methods for managing webhooks and SQLite database connections. --- src/RandomAPI/Program.cs | 78 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/src/RandomAPI/Program.cs b/src/RandomAPI/Program.cs index b554e9b..b89392a 100644 --- a/src/RandomAPI/Program.cs +++ b/src/RandomAPI/Program.cs @@ -26,12 +26,65 @@ //TODO: +// - good logging service. rabapp has an event table, i bet i could do something worse + +// - add a db. sqlite will probably work here since its small +//how tf will i get a db in here + // - AlertGatewayService // API Endpoint Goal: POST / alert / ingest // Brief Description(Project Scope): Centralized Notification Hub with Discord Integration. // Receives generic webhooks (from Sentry, CI/CD, etc.), standardizes the payload, applies personalized filtering rules, and routes the cleaned alert to your Discord channel using a webhook. // The service will format the alert into a visually appealing Discord Embed using a library like discord-webhook or requests. -public class WebhookService { } +public class WebhookPayload +{ + //payload, timestamp, event enum probably +} +public interface IWebhookService +{ + Task SendWebhookAsync(object payload); + void AddListener(string url); + IEnumerable GetListeners(); +} + +public class WebhookService : IWebhookService +{ + private readonly HttpClient _httpClient; + private readonly ConcurrentBag _listeners = new ConcurrentBag(); + + public WebhookService(HttpClient httpClient) + { + _httpClient = httpClient; + } + + public void AddListener(string url) + { + // validate url here + _listeners.Add(url); + } + + public IEnumerable GetListeners() => _listeners; + + public async Task SendWebhookAsync(WebhookPayload payload) + { + string json = JsonConvert.SerializeObject(payload); + var content = new StringContent(json, Encoding.UTF8, "application/json"); +//this can be wayyyy better + foreach (var url in _listeners) + { + try + { + var response = await _httpClient.PostAsync(url, content); + Console.WriteLine($"Sent to {url}: {response.StatusCode}"); + } + catch (Exception ex) + { + Console.WriteLine($"Error sending to {url}: {ex.Message}"); + } + } + } +} + // - HealthCheckAggregator // API Endpoint Goal: GET / health / summary @@ -47,3 +100,26 @@ public class HealthCheckService { } // Supports robust searching by language (python, sql) and customizable tags (regex, lambda, auth). public class UniversalSnippetService { } // will require a db + + +// - basic sqlite db +public class DatabaseService +{ + private readonly string _connectionString; + + public DatabaseService(string dbPath = "Data/myapp.db") + { + //WILL NEED TO BE UPDATED + _connectionString = $"Data Source={dbPath}"; + } + + /// + /// Opens a connection to SQLite, executes an action, then closes the connection. + /// + public void Execute(Action action) + { + using var connection = new SqliteConnection(_connectionString); + connection.Open(); + action(connection); + } +} From c16c729879586337c1c32486bf5a395d41534cc7 Mon Sep 17 00:00:00 2001 From: Wyatt Murray <113722636+Skyfall1235@users.noreply.github.com> Date: Mon, 1 Dec 2025 12:46:39 -0500 Subject: [PATCH 2/2] trigger codql --- src/RandomAPI/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RandomAPI/Program.cs b/src/RandomAPI/Program.cs index b89392a..b5904fd 100644 --- a/src/RandomAPI/Program.cs +++ b/src/RandomAPI/Program.cs @@ -69,7 +69,7 @@ public async Task SendWebhookAsync(WebhookPayload payload) { string json = JsonConvert.SerializeObject(payload); var content = new StringContent(json, Encoding.UTF8, "application/json"); -//this can be wayyyy better +//this can be wayyyyy better foreach (var url in _listeners) { try