How to send notifications to Telegram from Qnap

In this post I’m going to tell you how to make QNAP notifications reach you on Telegram instead of those provided by Notification Center default.

TABLE OF CONTENT


Why Notification Matters

Knowing in real time what happens on our NAS is something that is of great interest, especially if you have a good handful of services deployed, as is my case. Failed access attempts, Failed backup status, Firmware update etc., are many of the notifications that the server can send us automatically and with hardly any configuration.

Notification Center

With Notification Center, we can easily send such message to us through various channels. Four default channels provided by Notification Center are: Email/SMS/Instant MSG(Skype)/Push Service(Qmanager). I don’t like Email since it’s not high-frequency app at all. The second one “SMS” will cost us extra $ if we send phone sms and the latter two requires Skype/Qmanager APPs installed in our phone.

Over time, Telegram is showing that it’s a solid and also private service, especially when compared to WhatsApp. In order to send notifications from our NAS to Telegram we need to create a Bot first and use Telegram Bot API to send message later. And fortunately, Notification Center provides the ability to customize SMSC services.

Telegram side configuration

API

These two apis are used in the configuration.

  1. sendMessage

You can send message using this api, “token” and “chat_id” should replace with your customized settings.

https://api.telegram.org/bot<token>/sendMessage?chat_id=<chat_id>&text=@@Text@@&user=@@UserName@@&password=@@Password@@&to=@@PhoneNumber@@
  1. getUpdates

You can retrieve “chat_id” using this api

https://api.telegram.org/bot<token>/getUpdates

Get token

To create a Bot in Telegram we have to open a chat with @BotFather, the father of all Bots. Just type /newbot to @BotFather and follow the instructions, finally you’ll get a token:“:*”

Get chat_id

Open a chat with @your_robot, send anything start with /, such as /start. Using this tool to retrieve the chat id.

In token field, type your token and hit “Try it”. You’ll get a response json. In the json string, save “chat.id” as describe in the image below.

QNAP configuration

Custom SMSC service

Open Notification Center, In “Service Account and Device Pairing” => SMS => Add SMSC Service.

Replace the <token> and <chat_id> with the strings you get from previous setup.

https://api.telegram.org/bot<token>/sendMessage?chat_id=<chat_id>&text=@@Text@@&user=@@UserName@@&password=@@Password@@&to=@@PhoneNumber@@
  • SMS service provider: “custom”
  • Alias: “whatever you named it”
  • URL template text: “https://api.telegram…”

Create Rule

In “System Notification Rules” => “Create Rule”. Follow the instructions to select what you are interest in and in step 3 choose the Method “SMS”=>“Alias_name”.

Remember to fill in the phone number which can be ignored but is required. You can test the configuration by click the mail icon in the up-right corner. If everything works fine, you’ll receive a message in your chat session with your robot.

This is a test message from NAS:"NAS NAME"

Save the change, and wait for the real notification!

Reference

https://forum.qnap.com/viewtopic.php?t=156191

Post a Comment

1 Comments

  1. October 2022 and unfortunately this doesn't work. The 'Get Updates' page example is completely different and when I try to enter https://api.telegram.org/bot12345678 in the 'Add SMSC Service' page in QNAP QTS, it just says "Incorrect or missing information in @@PhoneNumber@@ in the URL template text."

    I'd love an update to this tutorial

    ReplyDelete