0

I'm trying to simulate how to send a message to a bot from a url but it doesn't work.

I try to explain (note: all the ids and tokens are not real, they are only to explain !!) ..

I've built a first bot from BotFather named Bot1Bot and then, form url if I try

https://api.telegram.org/bot532708503:BBGn5ORfLppFu05-bi088F4SyKAiITfXH1w/getme

the response is

{"ok":true,"result":{"id":532708503,"is_bot":true,"first_name":"Bot1Bot","username":"Bot1Bot"}}

Then I've built a second bot from BotFather named Bot2Bot and then, form url if I try

https://api.telegram.org/bot632805599:XXGn7ORfLppFu06-bd099F4SyKAiITfXH1y/getme

the response is

{"ok":true,"result":{"id":632805599,"is_bot":true,"first_name":"Bot2Bot","username":"Bot2Bot"}}

Now I'd like to simulate how to send a message from Bot1Bot to Bot2Bot and so I've tried this request ...

https://api.telegram.org/bot532708503:BBGn5ORfLppFu05-bi088F4SyKAiITfXH1w/sendmessage?chat_id=632805599&text=xxxxxxxx

or this request ...

https://api.telegram.org/bot632805599:XXGn7ORfLppFu06-bd099F4SyKAiITfXH1y/sendmessage?chat_id=532708503&text=xxxxxxxx

.. but the response is

{"ok":false,"error_code":400,"description":"Bad Request: chat not found"}

Where am I doing wrong?

Are there some settings in my two bots that I've to set?

My final goal is to do the same in a PHP code ...

Cesare
  • 1,629
  • 9
  • 30
  • 72
  • Your url query for a bot to send a message is using "chatId" not userId or botId. Note: Bot can not initiate chat with a person, only reply to it. This means that you cannot get a valid chatId until user starts using your bot by finding it first. This generates chatId that your bot then can use to send private messages to that specific user only. Groups are different, but have limitations. But channels - bots there can see messages from each other. Just turn on "Sign messages" setting, and look for "AuthorSignature" property to identify which bot sent a message. And DO NOT PUT THEM IN A LOOP! – That Marc Jun 28 '21 at 21:47
  • Also note: Channel webhooks are entirely separated from chat and group ones. Thus, most bots will not receive, process and respond to channel messages - it's on developer to implement and use, if and only if you really need to use more than 1 of your bots and link them together. If this does not include any person in between, it's better to use a different communication approach between two services, and not a bot system. This is why this approach will not work to create your own bots to communicate with 3rd party ones out there. – That Marc Jun 28 '21 at 21:54

1 Answers1

1

actually, telegram bot to bot communication is not possible. chat_id used in URL is chat_id of a person that subscribed to your bot and by this chat_id and your Bot token, you can send a message to a subscribed user.

Even if you add them both to one group chats so that @bot1 will send /start@bot2 and @bot2 will send /start@bot1, they won't get these messages.

Robot
  • 913
  • 6
  • 8