feat: support telegram topics in supergroups

This commit is contained in:
yokkkoso
2026-02-07 15:19:08 +10:00
committed by Jarek Krochmalski
parent 7fe4b25563
commit c210ef0a8e
2 changed files with 8 additions and 4 deletions
+7 -4
View File
@@ -277,13 +277,13 @@ async function sendMattermost(appriseUrl: string, payload: NotificationPayload):
// Telegram
async function sendTelegram(appriseUrl: string, payload: NotificationPayload): Promise<NotificationResult> {
// 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'
})
});
@@ -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"