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? - #3 by TotallyInformation, 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

Hi there

After spending some time finding out the limitations of telegram bots not being able to talk to each other, I wanted to share my solution:

My problem was:

I wanted to realize a presence detection for Node Red. I only have Node Red running on a Raspberry Pi. I tried all kind of different things like Unifi Controller (very buggy), Tasker (if WiFi connected and also near WiFI) and HTTP Request via local network to node red (very buggy because of WiFi connection problems)...I Don't want to do presence detection via Bluetooth ether, because it's also depending on wireless signal, and these technologies get disconnected all the time. I'm also working with PIR Sensors, but when no movement, not detection...I was thinking about messages that don't depend on local area network...or VPN...or risky exposing of node red to the the internet...

So I endet up with Tasker / Autolocation / Autonotification / Remote Bot for Telegram & Viber to Node Red with node-red-contrib-telegrambot.

So basically my Phone is doing the presence detection and then sends a message to telegram which is then received by the telegrambot-receiver Node on node red.

So here is how I do it at the moment, still testing, but for now it works great:

Tasker Profile with Autolocation Plugin, detecting if I'm in or out of a 300 Meter Radius of my home, this is running on my phone I always have with me. When in or out, one message (Text "Home" or "Away") gets sent with the corresponding task of the Profile via the Tasker Plugin Remote Bot for Telegram & Viber to the bot chat. So the Bot in Node Red receiver node is the same bot as within the Tasker Remote Bot Plugin. Node Red Receiver node is now not able to see the message (no bot to bot talking, even if it is the same bot). But I do get this message on a separate Android Phone at home which is running the same Telegram account and has Tasker and the Plugin AutoNotification installed. So there a notification with the possibility to answer directly within that notification pop up. Tasker and AutoNotification can see and answer that message. If the Text is from Telegram and is "Home" one profile kicks in, which answers to the same bot with the reply of "Home". Because this text is sent with Tasker and AutoNotification and not from a bot, the bot is now able to see the message. Which means, I now receive the text "Home" from Tasker and AutoNotification from the separat phone on my Node red receiver Node. From there I can work with the payload "Home" or "Away". Because the Bot-Chat is not public and only accessible with the Token, I think it is pretty safe. Maybe I get to learn a different opinion here :wink:

I still have one annoying thing to solve: because the answer from Tasker and AutoNotification is going to bot, the bot answers with a message, saying that it is not understanding what I want from it. This message then pops up on telegram on all devices with the same telegram account. So I tried multiple ways around it, but could not find a solution yet:
I tried to ad the bot as an admin to a privat group chat, so that the original message goes to this chat. But then the notification I get on the separat phone running Tasker and AutoNotification does not have the option to answer directly within the notification. So AutoNotification can see the text from the bot, but is not able to answer.
I also tried to click away the last notification (the bot not understanding my text) via Tasker and AutoInput, but this is only possible, when screed is on and not locked.

So this is it. I know, It's a loooong workaround and quiet complicated. But it works for me. Maybe this is some help for other users...

bots are not seen in groups, it serves to avoid loops

bots only talk in channels