模拟从url向机器人发送消息 [英] Simulate sending a message to a bot from url
问题描述
我正在尝试模拟如何从url向机器人发送消息,但这不起作用.
I'm trying to simulate how to send a message to a bot from a url but it doesn't work.
我尝试解释(注意:所有的id和令牌都不是真实的,它们只是为了解释!!).
我从BotFather构建了第一个bot,名为Bot1Bot,然后,如果尝试使用,则形成url
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
响应为
{"ok":true,"result":{"id":532708503,"is_bot":true,"first_name":"Bot1Bot","username":"Bot1Bot"}}
然后,我从BotFather构建了另一个名为Bot2Bot的bot,然后,如果尝试使用,则形成url
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
响应为
{"ok":true,"result":{"id":632805599,"is_bot":true,"first_name":"Bot2Bot","username":"Bot2Bot"}}
现在,我想模拟如何从Bot1Bot向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
或此请求...
https://api.telegram.org/bot632805599:XXGn7ORfLppFu06-bd099F4SyKAiITfXH1y/sendmessage?chat_id=532708503&text=xxxxxxxx
..但响应为
{"ok":false,"error_code":400,"description":"Bad Request: chat not found"}
我在哪里做错了?
我的两个机器人中是否需要设置一些设置?
Are there some settings in my two bots that I've to set?
我的最终目标是在PHP代码中执行相同的操作……
My final goal is to do the same in a PHP code ...
推荐答案
实际上,无法实现电报机器人与机器人之间的通信. URL中使用的chat_id是已订阅您的漫游器的人的chat_id,通过此chat_id和您的Bot令牌,您可以向已订阅的用户发送消息.
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.
即使将它们都添加到一个群聊中,以便@ bot1发送/start @ bot2和@ bot2发送/start @ bot1,他们也不会收到这些消息.
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.
这篇关于模拟从url向机器人发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!