Skip to content

Commit

Permalink
✨ Add support for multiple Telegram channels (#249)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
gxres042 and AnandChowdhary authored May 5, 2024
1 parent 45ac1d6 commit 1a286bd
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/helpers/notifme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,18 @@ export const sendNotification = async (message: string) => {
if (getSecret("NOTIFICATION_TELEGRAM") && getSecret("NOTIFICATION_TELEGRAM_BOT_KEY")) {
console.log("Sending Telegram");
try {
await axios.post(
`https://api.telegram.org/bot${getSecret("NOTIFICATION_TELEGRAM_BOT_KEY")}/sendMessage`,
{
parse_mode: "Markdown",
disable_web_page_preview: true,
chat_id: getSecret("NOTIFICATION_TELEGRAM_CHAT_ID"),
text: message.replace(/_/g, '\\_'),
}
);
const chatIds = getSecret("NOTIFICATION_TELEGRAM_CHAT_ID").split(",");

Check failure on line 334 in src/helpers/notifme.ts

View workflow job for this annotation

GitHub Actions / Build and Publish

Object is possibly 'undefined'.
for (const chatId of chatIds) {
await axios.post(
`https://api.telegram.org/bot${getSecret("NOTIFICATION_TELEGRAM_BOT_KEY")}/sendMessage`,
{
parse_mode: "Markdown",
disable_web_page_preview: true,
chat_id: chatId.trim(),
text: message.replace(/_/g, '\\_'),
}
);
}
console.log("Success Telegram");
} catch (error) {
console.log("Got an error", error);
Expand Down

0 comments on commit 1a286bd

Please sign in to comment.