diff --git a/src/config/config.ts b/src/config/config.ts index eb1741a76..aa6b6a927 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -214,7 +214,12 @@ export class Configuration { telegram = { botToken: process.env.TELEGRAM_BOT_TOKEN ?? '', - chatId: process.env.TELEGRAM_CHAT_ID ?? '', + // Comma-separated list of chat ids that should receive notifications. + // Each operator's chat-id (or a group id) goes here, no spaces required. + chatIds: (process.env.TELEGRAM_CHAT_IDS ?? '') + .split(',') + .map((id) => id.trim()) + .filter((id) => id.length > 0), }; // --- GETTERS --- // diff --git a/src/integration/telegram/services/telegram.service.ts b/src/integration/telegram/services/telegram.service.ts index 5d591b31b..daeedb231 100644 --- a/src/integration/telegram/services/telegram.service.ts +++ b/src/integration/telegram/services/telegram.service.ts @@ -19,32 +19,39 @@ export class TelegramService { constructor(private readonly httpService: HttpService) {} async sendMessage(message: string): Promise { - if (!Config.telegram.botToken || !Config.telegram.chatId) { + if (!Config.telegram.botToken || Config.telegram.chatIds.length === 0) { this.logger.info('Telegram not configured, skipping message'); return false; } - try { - const url = `${this.baseUrl}/bot${Config.telegram.botToken}/sendMessage`; - const response = await this.httpService.post( - url, - { - chat_id: Config.telegram.chatId, - text: message, - parse_mode: 'HTML', - }, - { tryCount: 5, retryDelay: 2000 }, - ); - - if (!response.ok) { - this.logger.error(`Telegram API error: ${response.description}`); - return false; - } + // Deliver to every recipient. Returns true iff at least one delivery succeeded; per- + // recipient failures are logged and skipped so a single bad chat-id (e.g. user blocked + // the bot) doesn't suppress the entire alert. + const url = `${this.baseUrl}/bot${Config.telegram.botToken}/sendMessage`; + let anyDelivered = false; + for (const chatId of Config.telegram.chatIds) { + try { + const response = await this.httpService.post( + url, + { + chat_id: chatId, + text: message, + parse_mode: 'HTML', + }, + { tryCount: 5, retryDelay: 2000 }, + ); - return true; - } catch (e) { - this.logger.error('Failed to send Telegram message', e); - return false; + if (!response.ok) { + this.logger.error(`Telegram API error for chat ${chatId}: ${response.description}`); + continue; + } + + anyDelivered = true; + } catch (e) { + this.logger.error(`Failed to send Telegram message to chat ${chatId}`, e); + } } + + return anyDelivered; } }