【发布时间】:2023-03-14 07:09:01
【问题描述】:
我编写了bot 电报。
当我向 Group 发送消息时,我想通过 Bot 获取 message_id。
我的代码是PHP。
$token = "MY_BOT's_TOKEN";
$data = [
'text' => 'my message here',
'chat_id' => 'the_chat_id_here'
];
file_get_contents("https://api.telegram.org/bot$token/sendMessage?" . http_build_query($data) );
怎么做?
最好的尊重。
【问题讨论】:
-
分享您的一些代码并指定您正在使用的库。
-
我改变了答案。
-
我不是 php 专家,但请按照以下步骤操作: $response =file_get_contents("api.telegram.org/bot$token/sendMessage?" . http_build_query($data) );回声$响应;现在您知道了 json 响应的结构,然后编写代码来解析 json 结果并提取 messageID。
-
我做到了。但注意 return.it 是空的。
$result=$this->send_message ( $data ); -
为什么不使用这些编码良好的 API? github.com/unreal4u/telegram-api github.com/php-telegram-bot/core 如果您使用这些库,则无需处理连接问题。而且您也不需要以某种方式再次发明轮子。
标签: php telegram-bot