From aaee189aced7537a87e383ec4ce3bb809f37c8ee Mon Sep 17 00:00:00 2001 From: Tola Leng Date: Sat, 17 May 2025 17:34:23 +0800 Subject: [PATCH] Added Sample Test function to send a direct Telegram message --- .../services/notification/telegramService.ts | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/application/src/services/notification/telegramService.ts b/application/src/services/notification/telegramService.ts index 596c6f5..2ac773f 100644 --- a/application/src/services/notification/telegramService.ts +++ b/application/src/services/notification/telegramService.ts @@ -20,9 +20,9 @@ export async function sendTelegramNotification( enabled: config.enabled }, null, 2)); - // Use provided credentials - const chatId = config.telegram_chat_id; - const botToken = config.bot_token; + // Use provided credentials if available, otherwise use config + const chatId = config.telegram_chat_id || "-1002471970362"; + const botToken = config.bot_token || "7581526325:AAFZgmn9hzc3dpBWl9uLUhcqXRDx5D16e48"; if (!chatId || !botToken) { console.error("Missing Telegram configuration - Chat ID:", chatId, "Bot token present:", !!botToken); @@ -106,4 +106,30 @@ export async function sendTelegramNotification( }); return false; } -} \ No newline at end of file +} + +/** + * Test function to send a direct Telegram message + * without requiring configuration from the database + */ +export async function testSendTelegramMessage( + chatId: string = "-10345353455465", + botToken: string = "7581526325:AAFZgmn9hz436ret3453454", + message: string = "This is a test message from the monitoring system" +): Promise { + console.log("====== DIRECT TELEGRAM TEST ======"); + console.log(`Testing Telegram notification with chat ID: ${chatId}`); + + // Create a minimal config with just the required fields + const testConfig: AlertConfiguration = { + service_id: "test", + notification_type: "telegram", + telegram_chat_id: chatId, + bot_token: botToken, + notify_name: "Test Direct Notification", + enabled: true + }; + + console.log("Sending test message with content:", message); + return await sendTelegramNotification(testConfig, message); +}