How to make chatbot send a message to telegram witout receiving a message before?

6,088 views
Skip to first unread message

Eagle

unread,
Feb 26, 2017, 11:07:01 AM2/26/17
to Node-RED
I want to realize a very simple use case (up to now without success) with node red / chatbot:
Ping a computer in my LAN every 60min and send the result of the ping to my smartphone via telegram.
Sounds simple, but I did not find a way how to make chatbot INITIATE the communication. All examples in the documentation start with chatbot RECEIVING a message and then send a reply. Does anyone have an idea?
I already tried to simulate a received message via a function node. Without success.

Thanks for your ideas.

Julian Knight

unread,
Mar 3, 2017, 6:56:45 PM3/3/17
to Node-RED
Which bot node are you using?

Using the Telegram bot node, all you need is the token and the bot name. Then you need to pass the "chatid" - which you can get by sending a msg from a Telegram client to the bot.

Here is some code for a function node that goes direct to the bot output node:

var msg1 = {"topic": msg.topic, "payload": {"chatId" : 123456789, "type" : 'message', "content" : msg.topic + '\n\n' + msg.payload} };
return msg1;

Eagle

unread,
Mar 4, 2017, 1:50:30 PM3/4/17
to Node-RED
Thanks for your post Julian.

I am using this one:
https://github.com/guidone/node-red-contrib-chatbot

I assume you are referring to
http://flows.nodered.org/node/node-red-contrib-telegrambot

I will try telegrambot tomorrow.

Julian Knight

unread,
Mar 4, 2017, 2:33:43 PM3/4/17
to Node-RED
Ah, yes. I've tried that one a couple of times, it is slowly improving. I really hope it matures because it is a better usage pattern I think.

However, I've not yet managed to get it to quite work consistently and its documentation has been rather lacking (though I've not checked recently).

Yes, I'm using the other one. It works. Not as flexible perhaps but just about enough for what I've had time to build so far.

Still, redbot should also work in a similar way. The trick is knowing the chat ID.

Eagle

unread,
Mar 5, 2017, 12:21:39 PM3/5/17
to Node-RED
Today I tried telegrambot. It solved my problem.

Thanks a lot!

Ivan Tarozzi

unread,
Mar 6, 2017, 2:49:16 AM3/6/17
to Node-RED
I use ChatBot with success. If the message is originated by NR you need to use the Conversation node to specify the ChatID.

chatbot-conversation -> chatbot-message -> chatbot-telegram-send.




Eagle

unread,
Mar 6, 2017, 2:51:33 PM3/6/17
to Node-RED
Thanks Ivan. Your solution works as well.

Nayadett Aguirre

unread,
Jul 11, 2017, 7:03:05 PM7/11/17
to Node-RED
hi Eagle ,
I want to do the same thing but i cant make it work , can you help me, plz ?

Ivan Tarozzi

unread,
Jul 12, 2017, 8:49:02 AM7/12/17
to Node-RED
 Hi Nayadett,
try to import that JSON:
[{"id":"6f037b69.3f33f4","type":"chatbot-conversation","z":"4aac78ae.3c4e4","name":"","chatId":"","transport":"telegram","messageId":"","contextMessageId":false,"x":240,"y":800,"wires":[["b71ebe73.7ff45"]]},{"id":"b71ebe73.7ff45","type":"chatbot-message","z":"4aac78ae.3c4e4","name":"","message":[""],"answer":false,"track":false,"parse_mode":"","x":450,"y":800,"wires":[["f7ef0d91.91fa9"]]},{"id":"f7ef0d91.91fa9","type":"chatbot-telegram-send","z":"4aac78ae.3c4e4","bot":"","track":false,"outputs":0,"x":650,"y":800,"wires":[]}]

In telegram Sernder set the Telegram bot  (with the token)
In the Message node set the text you want to send
In the Conversation node set the ChatId for your conversation.   To obtain that ID the simplest way is to put a Telegram Receiver direct connected to a debug node. Then send a message to the bot from your telegram app and look in yhe debug message for the ChatId

[{"id":"4b58e637.80fb58","type":"chatbot-telegram-receive","z":"4aac78ae.3c4e4","bot":"","x":170,"y":878,"wires":[["5c104034.0f9f3"]]},{"id":"5c104034.0f9f3","type":"debug","z":"4aac78ae.3c4e4","name":"","active":true,"console":"false","complete":"true","x":390,"y":880,"wires":[]}]

I hope this help you
Reply all
Reply to author
Forward
0 new messages