I have a number of Node-RED flows running on four RPi-4Bs performing various tasks around my home.
Quite a few of these flows report a situation by sending text and/or a photo to Telegram on my mobile phone.
Sometimes I lose track of a 'telegram' bot-name and end-up deploying another Telegram node (with the same bot-name) which causes problems as (I found out to my cost) you can only run a single instance.
First of all I must emphase this is a simple solution for a 'telegrambot' server.
As you can see there is a single 'sender' and receiver' node for each 'bot-name', while mqtt-in and mqtt-out nodes are the main connection-points to the flow.
The topic the 'mqtt-in' node subscribes to is...
The topic the 'mqtt-out' node publishes to is left blank as the topic-name will be supplied by the 'change' node that is joined to it.
Each flow that wants to send a message to a specific Telegram bot needs to include these details in its mqtt-out node. As an example, here's part of the flow for one of my Infrared detectors.
The topic inside the mqtt-out node is
Going back to look at the top flow. The 'function' node labelled "split out 'bot' part" contains this...
const topicParts = msg.topic.split('/');
// Selecting a specific part of the topic
const selectedPart = topicParts; // "sensors"
msg.topic = selectedPart;
The 'switch' node directs msg.payload to the appropriate 'telegrambot' sender node.
I'm using a 'change' node (after the 'telegrambot' receiver node) to set the topic so the feedback is sent to the appropriate flow via the mqtt-out node.
I hope someone finds this idea useful?