Previously, I made a post about setting up a Telegram bot with Node-RED and sending notifications using a call service node. This works great for basic notifications, although it doesn’t handle any of the custom formatting that Telegram supports, or the logging that can be kept. To get better notifications, we’ll want to have everything contained within Redbot. This will setup notifications to be completely handled in node-RED, instead of using the call service node to call the “telegram_bot.send_message” service. Doing it this way, removes the need to have anything setup in YAML and allows Redbot to keep logs of everything that happens.
If you set up Redbot as was previously discussed in the first post, you’ll want to go back into the configuration of either the the Telegram sender, or receiver nodes and add a logging location. I created a folder log location in my local config location, path looks like /config/www/logs. You want to add this to the bot configuration inside Redbot and append whatever you want to call the log file.
So now, anything that travels through the Sender and Receiver nodes of the bot, will be logged in that location.
To make an example, we’ll need to grab an inject node, a conversation node, a text node and a link node. You’ll need to configure the conversation node with the bot you configured for the send/receiver nodes, and also a chat or group ID. This ID is for whomever you want to receive the notification. My family is all in one Telegram group with the house bot, so I send to that group ID. If you are only going to receive these notifications, use your chat ID. You’ll also need to configure the text node. With this node you can enter different variations of the message you want to send, and it will randomly send the different versions, giving the bot a sense of personality. Place the inject node in front of the conversation node, and the text node behind the conversation node.
Now go to whatever tab you have your telegram bot set up in, and grab a link in node
In the configuration call is something descriptive so you know what it is when you link to it. Connect it to the Telegram bot receiver node:
Go back to wherever it was you were setting up the conversation and text nodes, and grab a link out node. Go into the config, and put a check mark next to the name of the link in node you just created.
Now, connect everything. Once connected, if you hover over the link out node, it will show you the tab that it’s connected to.
Now if you press the inject node button, it passes through the conversation and text nodes, and the link node connects it to the telegram bot. Click it a bunch of times and it will send all the different variations randomly.
So, if you want to use this method of notification, you just need to replace the call service nodes, with the conversation and text nodes, as well as a link out node.
Here’s one of my flows where I replaced a call service node after the stoptimer with the conversation and text nodes.