【问题标题】:PHP telegram bot : Bad Request: message to edit not foundPHP电报机器人:错误请求:未找到要编辑的消息
【发布时间】:2020-08-16 07:20:57
【问题描述】:

我使用这个 GitHub 包来构建我的 Telegram 机器人。我想编辑我从机器人发送的消息。我很困惑,因为我认为一切都是正确的!!!

  $content = array('chat_id' => $chat_id, 'text' => "
  some text
  " );
// sending message, it will return Telegram JSON's reply, contains message_id which is used further to //edit sent message (https://core.telegram.org/bots/api#message)
  $newmess=  $telegram->sendMessage($content);

// in order to edit the message we should provide the //(https://core.telegram.org/bots/api#editmessagetext) keys
// message_id is achieved by the last message sent ($newmess the message_id key)
  $content = array('chat_id' => $newmess['chat']['id'],'message_id'=>$newmess['message_id'],'text' => "


  some text 2
  ");

  $telegram->editMessageText($content);

但是当我看到日志时,$newmess['message_id'] 是空的!根据电报文档,如果消息发送成功,则响应包含诸如 message_id 之类的键! (https://core.telegram.org/bots/api#message)

这是日志:

好的:错误 错误代码:400 描述:错误请求:未指定消息标识符

【问题讨论】:

    标签: php bots telegram


    【解决方案1】:

    已解决:$newmess['result']['message_id'] 结果键是必需的。

    【讨论】:

      【解决方案2】:

      当用户在一段时间后单击内嵌键盘按钮时,也可能会收到 message to edit not found 错误。在这种情况下,由于已删除消息而发生错误。 Telegram 可以随时从服务器中删除您的消息(与 Bot API 相关)。在这种情况下,您将收到格式错误的响应。

      {
         "update_id":23******9,
         "callback_query":{
            "id":"14*****11",
            "from":{
               "id":34*****0,
               "is_bot":false,
               "first_name":"*****",
               "last_name":"*****",
               "username":"*****",
               "language_code":"uk"
            },
            "message":{
               "message_id":74*****77,
               "chat":{
                  "id":34*****10,
                  "first_name":"*****",
                  "last_name":"*****",
                  "username":"*****",
                  "type":"private"
               },
               "date":0
            },
            "chat_instance":"-26***736",
            "data":"con***920"
         }
      }
      

      【讨论】:

        猜你喜欢
        • 2021-09-14
        • 1970-01-01
        • 2017-05-13
        • 1970-01-01
        • 2017-09-01
        • 1970-01-01
        • 2018-01-09
        • 2018-03-05
        • 2022-07-06
        相关资源
        最近更新 更多