Email used to be the primary method of delivering system alerts & notification. However, it becomes hard to find a free and effective way to send system generated emails. Free email hosting is no longer that available like 10 years ago. (That’s why I have a post of how to create your own email server) And because of most big players defending spams, those system generated email successful delivery rate drops significantly and has noticeable delay. People tend to use SMS gateway for instantly message notification. But it costs more. Today, I introduce a way to use Telegram bot API for almost realtime push notification for system notifications.
System: Synology DSM 7.0
- First step is to open Synology DSM portal and navigate to Notification – Application Webhooks. (Not sure if the webhooks is the new feature of DSM 7.0)
2. Choose to add a new webhook, and choose Custom.
3. Enter the Webhook URL. You need to obtain your own API token and ChatID from Telegram to update the URL below.
4. Now we open Telegram app on your mobile phone or from Telegram desktop app. Find @BotFather and type
/newbot to start the conversation or use Menu to choose the command. Follow the instruction to set your bot’s unique name and get API Token. And remember to say something to the bot you just created, so that the bot you send message from then on.
5. You also need to find @GetIDsBot to know your id number. After this, go back to step #3 to update the webhook URL with your API Token and ChatID.
6. After updated webhook URL, you can edit additional API query parameter at this step, if no, then skip this one.
7. Change the text parameter to Message Content.
8. Finally, check the Rules setting to make sure what kind of alerts/notification need to go through this Telegram Bot Push service. Since it is cost free, you can set all alerts go this way.
9. Do some test and you will receive the notification on Telegram.
Hope this post is helpful for you.
BTW, in the similar way, you can move all other system notification from email to Telegram bot.
For Mikrotik RouterOS notification, you can use script to trigger the Telegram API by using below format. You can leave your comments if you want me to post detail of how to use Telegram bot for Mikrotik alerts.
/tool fetch "https://api.telegram.org/bot[API Token]/sendmessage?chat_id=[ChatID]&text=Hello+world" keep-result=no;