A telegram bot question with http POST


I have installed node-red-contrib-telegrambot, setup a bot on telegram, got a bot token and it is basically working. I can send messages from phone and pick them up in node red and vice versa.
However, when I use the http POST method to send a message, for example using

curl --data "chat_id=<id>&text=somemessage" https://api.telegram.org/bot<bottoken>/sendMessage

the message is received on the phone ok but not by the telegram receive node in node red.
Any ideas?


I do know that you cannot link bots together in Telegram and it may be that you are hitting that issue.


Perhaps I am missing something fundamental in how this is supposed to work. I have only got one bot. I am going to sleep on it and see if it makes more sense in the morning.


I have done a bit more investigating, and I think I understand the problem.
As I said I have created a bot and I have access to that from the telegram app in the phone and the nodes in node-red. I can also open a web browser view of the bot. If I send a message from the phone then it is picked up by the receive node in node red and also on the web view. If I send a message from node red using the telegram sender node then I see it on the phone and in the web view.
However, if I use the bot api [1] to send a message to the bot it is seen by the phone and web view but not by node red. The reason is that the bot api is single user. Only one client can use it at a time, and the node red nodes are using that api. The result is that when I send a message using the POST sendMessage url then the bot assumes it is from the same client as the node red nodes, so the requests for new messages from node red are not given that message.
What I am actually trying to do is send a message from Tasker on the phone back to node red. At the moment I don't see how to do this.
The other thing I would like to do is allow two instances of node-red (remote from each other) to communicate via telegram and this falls over the same issue. They cannot both connect to the same bot.

[1] https://core.telegram.org/bots/api


I am now thinking this is not possible. I tried making two bots and put them both into a group, connecting one NR instance to each bot. If I send to the group from the android app then both NRs receive the message, and if I send to the group from either NR then other clients receive the messages except the other NR client. I suspect the designers have intentionally built the Telegram system to allow person to machine and machine to person comms, but not to allow communication between machines. I can see that this could be abused so perhaps it is not surprising.


I think that's exactly right. The question came up in a previous discussion, What is a good way for sending messages between Node-Red and your smart phone also in case the smartphone is not connected to your LAN?, and there does not seem to be an obvious way to work around it.


Thanks for that @drmibell, I had missed that thread as I was not thinking of doing this at that point. I think I am probably going to setup a publicly accessible MQTT server and solve the problem that way.


This is what I said before. You cannot make two bots talk to each other because it is considered a security risk, quite possibly a performance risk for the platform too - imagine two runaway bots having a rapid "conversation". Using the API is a bot.

It is annoying of course.

You might be able to get round it by using a headless browser and the Telegram web interface. But messy and fragile.


Yes, what wasn't clear from the docs was that you can't use the send message api to send messages to a bot (from one NR instance for example) and then receive the messages from that same bot in another NR instance. Which isn't two bots communicating as there is only one bot.


I was able to use 2 bots by adding them both to a public group. I use Tasker to HTTP Post a message into the chat via bot 1, bot 2 receive node sees the message from bot 1 in the chat and triggers events accordingly. For security, msg.originalMessage.author_signature shows who sent the message into the chat, so even if someone joins (because it is public) and you don't have time to kick them out before messages are sent (I send arbitrary letters for events, even if someone got in they wouldnt know what letters did what) you can confirm it was bot 1 who sent the message and only trigger events if so


OK, thanks for that. I solved my problem using a different route (publicly accessible MQTT server, protected of course).


Okay awesome. My Tasker MQTT plugin would sometimes randomly not work and I had to update the Task to fix it, which was irritating. That inspired the switch to Telegram for triggering events from tasker.


Hello sallen135

Is there any tutorial where i may learn ho to communicate two node red instance using telegram ?


No tutorial that I know of, but if you had 2 different bots, both in a public channel, each node red instance could have a bot listening in the channel. When one says something, the other will output it. That would connect the instances


i was able to build my bot with help from Csongor Varga

great vid great guy!


I don't think that you can have 2 bots that communicate with each other can you?


I wouldn't say they communicate with each other necessarily, but if they are both in the same public chat, the receive node for 1 bot will output messages sent by the other bot