【问题标题】:How to Get Message_id from sent message By BOT Telegram?如何从 BOT Telegram 发送的消息中获取 Message_id?
【发布时间】: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


【解决方案1】:

您的 file_get_contents 调用返回一个包含状态代码和 messageId 的结果。

$result = file_get_contents("https://api.telegram.org/bot$token/sendMessage?" . http_build_query($data) );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-20
    • 1970-01-01
    • 1970-01-01
    • 2019-03-09
    相关资源
    最近更新 更多