Last active
September 8, 2024 15:10
-
-
Save Sinequanonh/f5625a2807f89ce4f6634cd3b1ab65a0 to your computer and use it in GitHub Desktop.
Nodejs script to send Telegram push notifications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const TelegramBot = require('node-telegram-bot-api'); | |
// replace the value below with the Telegram token you receive from @BotFather | |
const token = YOUR_TOKEN; | |
// read the doc from https://github.com/yagop/node-telegram-bot-api to know how to catch the chatId | |
const chatId = CHAT_ID; | |
const bot = new TelegramBot(token, { polling: false }); | |
const telegrambot = (message, json) => { | |
try { | |
bot.sendMessage(chatId, message + '\n\n<pre>' + JSON.stringify(json, null, 2) + '</pre>', { | |
parse_mode: 'html' | |
}); | |
} catch (err) { | |
console.log('Something went wrong when trying to send a Telegram notification', err); | |
} | |
} | |
const ACTIONS = { | |
NEW_USER: 'πββοΈnew user', | |
NEW_MONITOR: 'π₯ new monitor', | |
LATENCY: 'π¨βπ» somebody has used the latency tool', | |
NEW_STATUS_PAGE: 'π new status page', | |
NEW_SUBSCRIPTION: 'π°π°π° a user has subscribed!', | |
NEW_PAYMENT: 'π€ a payment has processed', | |
WEEKLY_REPORTS_SENDING: 'β΄οΈ Weekly reports are being sent', | |
WEEKLY_REPORTS_SENT: 'β Weekly reports have been sent', | |
END_TRIAL_USERS: 'β end of trial users today', | |
TRIAL_USERS_SOON_END: 'π users that end their trials in 3 days', | |
} | |
module.exports = { | |
telegrambot, | |
ACTIONS | |
} |
tnx, helped me
Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
GG, thanks