Skip to content

Instantly share code, notes, and snippets.

@Sinequanonh
Last active September 8, 2024 15:10
Show Gist options
  • Save Sinequanonh/f5625a2807f89ce4f6634cd3b1ab65a0 to your computer and use it in GitHub Desktop.
Save Sinequanonh/f5625a2807f89ce4f6634cd3b1ab65a0 to your computer and use it in GitHub Desktop.
Nodejs script to send Telegram push notifications
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
}
@jugaldb
Copy link

jugaldb commented Oct 8, 2020

GG, thanks

@oshToy
Copy link

oshToy commented Oct 15, 2020

tnx, helped me

@setiawanjemy88
Copy link

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment