Skip to content

Commit 1a286bd

Browse files
✨ Add support for multiple Telegram channels (#249)
* Add support for multiple NOTIFICATION_TELEGRAM_CHAT_ID * Update src/helpers/notifme.ts * Update src/helpers/notifme.ts * Update src/helpers/notifme.ts * MY MISTAKE: BOT_KEY => CHAT_ID --------- Co-authored-by: Anand Chowdhary <github@anandchowdhary.com>
1 parent 45ac1d6 commit 1a286bd

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/helpers/notifme.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -331,15 +331,18 @@ export const sendNotification = async (message: string) => {
331331
if (getSecret("NOTIFICATION_TELEGRAM") && getSecret("NOTIFICATION_TELEGRAM_BOT_KEY")) {
332332
console.log("Sending Telegram");
333333
try {
334-
await axios.post(
335-
`https://api.telegram.org/bot${getSecret("NOTIFICATION_TELEGRAM_BOT_KEY")}/sendMessage`,
336-
{
337-
parse_mode: "Markdown",
338-
disable_web_page_preview: true,
339-
chat_id: getSecret("NOTIFICATION_TELEGRAM_CHAT_ID"),
340-
text: message.replace(/_/g, '\\_'),
341-
}
342-
);
334+
const chatIds = getSecret("NOTIFICATION_TELEGRAM_CHAT_ID").split(",");
335+
for (const chatId of chatIds) {
336+
await axios.post(
337+
`https://api.telegram.org/bot${getSecret("NOTIFICATION_TELEGRAM_BOT_KEY")}/sendMessage`,
338+
{
339+
parse_mode: "Markdown",
340+
disable_web_page_preview: true,
341+
chat_id: chatId.trim(),
342+
text: message.replace(/_/g, '\\_'),
343+
}
344+
);
345+
}
343346
console.log("Success Telegram");
344347
} catch (error) {
345348
console.log("Got an error", error);

0 commit comments

Comments
 (0)