diff --git a/src/lib/server/notifications.ts b/src/lib/server/notifications.ts index 79b43ee..b91b5c9 100644 --- a/src/lib/server/notifications.ts +++ b/src/lib/server/notifications.ts @@ -209,13 +209,13 @@ async function sendSlack(appriseUrl: string, payload: NotificationPayload): Prom // 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 @@ -223,6 +223,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', @@ -230,6 +232,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 ea09408..7637936 100644 --- a/src/routes/settings/notifications/NotificationModal.svelte +++ b/src/routes/settings/notifications/NotificationModal.svelte @@ -415,6 +415,7 @@ discord://webhook_id/webhook_token slack://token_a/token_b/token_c tgram://bot_token/chat_id +tgram://bot_token/chat_id:topic_id ntfy://my-topic pushover://user_key/api_token jsons://hostname/webhook/path"