From 14967bd295400de88ef780b091b05af75b6ce4c7 Mon Sep 17 00:00:00 2001 From: yokkkoso Date: Sat, 7 Feb 2026 15:19:08 +1000 Subject: [PATCH] feat: support telegram topics in supergroups --- src/lib/server/notifications.ts | 11 +++++++---- .../settings/notifications/NotificationModal.svelte | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/lib/server/notifications.ts b/src/lib/server/notifications.ts index 6629cf4..b69005b 100644 --- a/src/lib/server/notifications.ts +++ b/src/lib/server/notifications.ts @@ -277,13 +277,13 @@ async function sendMattermost(appriseUrl: string, payload: NotificationPayload): // Telegram async function sendTelegram(appriseUrl: string, payload: NotificationPayload): Promise { - // tgram://bot_token/chat_id - const match = appriseUrl.match(/^tgram:\/\/([^/]+)\/(.+)/); + // tgram://bot_token/chat_id:topic_id? + const match = appriseUrl.match(/^tgram:\/\/([^/]+)\/([^:\/]+)(?::(\d+))?$/); if (!match) { - return { success: false, error: 'Invalid Telegram URL format. Expected: tgram://bot_token/chat_id' }; + return { success: false, error: 'Invalid Telegram URL format. Expected: tgram://bot_token/chat_id or tgram://bot_token/chat_id:topic_id' }; } - const [, botToken, chatId] = match; + const [, botToken, chatId, topicIdStr] = match; const url = `https://api.telegram.org/bot${botToken}/sendMessage`; // Escape markdown special characters in title and message @@ -291,6 +291,8 @@ async function sendTelegram(appriseUrl: string, payload: NotificationPayload): P const escapedMessage = escapeTelegramMarkdown(payload.message); const envTag = payload.environmentName ? ` \\[${escapeTelegramMarkdown(payload.environmentName)}\\]` : ''; + const topicId = Number.parseInt(topicIdStr, 10) + try { const response = await fetch(url, { method: 'POST', @@ -298,6 +300,7 @@ async function sendTelegram(appriseUrl: string, payload: NotificationPayload): P body: JSON.stringify({ chat_id: chatId, text: `*${escapedTitle}*${envTag}\n${escapedMessage}`, + message_thread_id: Number.isNaN(topicId) ? undefined : topicId, parse_mode: 'Markdown' }) }); diff --git a/src/routes/settings/notifications/NotificationModal.svelte b/src/routes/settings/notifications/NotificationModal.svelte index f83ea62..c3ce6b2 100644 --- a/src/routes/settings/notifications/NotificationModal.svelte +++ b/src/routes/settings/notifications/NotificationModal.svelte @@ -420,6 +420,7 @@ discord://webhook_id/webhook_token slack://token_a/token_b/token_c mmost://hostname/webhook-token tgram://bot_token/chat_id +tgram://bot_token/chat_id:topic_id ntfy://my-topic pushover://user_key/api_token jsons://hostname/webhook/path"