Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/lib/server/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,27 +209,30 @@ async function sendSlack(appriseUrl: string, payload: NotificationPayload): Prom

// 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
const escapedTitle = escapeTelegramMarkdown(payload.title);
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',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
chat_id: chatId,
text: `*${escapedTitle}*${envTag}\n${escapedMessage}`,
message_thread_id: Number.isNaN(topicId) ? undefined : topicId,
parse_mode: 'Markdown'
})
});
Expand Down
1 change: 1 addition & 0 deletions src/routes/settings/notifications/NotificationModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down