From afc9d46bd7cbc5fb7a4e6fc97df4922a0a81f127 Mon Sep 17 00:00:00 2001 From: Skorpios Date: Mon, 17 Feb 2025 09:39:28 -0800 Subject: [PATCH] Refactored notification messsages into an array of acceptable types. --- Server/service/notificationService.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Server/service/notificationService.js b/Server/service/notificationService.js index 1bd4d8f8b..3f4efb403 100644 --- a/Server/service/notificationService.js +++ b/Server/service/notificationService.js @@ -1,5 +1,12 @@ const SERVICE_NAME = "NotificationService"; const TELEGRAM_API_BASE_URL = "https://api.telegram.org/bot"; +const PLATFORM_TYPES = ['telegram', 'slack', 'discord']; + +const MESSAGE_FORMATTERS = { + telegram: (messageText, chatId) => ({ chat_id: chatId, text: messageText }), + slack: (messageText) => ({ text: messageText }), + discord: (messageText) => ({ content: messageText }) +}; class NotificationService { static SERVICE_NAME = SERVICE_NAME; @@ -39,16 +46,11 @@ class NotificationService { monitor.url ); - if (platform === 'telegram') { - return { chat_id: chatId, text: messageText }; + if (!PLATFORM_TYPES.includes(platform)) { + return undefined; } - if (platform === 'slack') { - return { text: messageText }; - } - if (platform === 'discord') { - return { content: messageText }; - } - return undefined; + + return MESSAGE_FORMATTERS[platform](messageText, chatId); } /**