简体   繁体   中英

PHP telegram bot : Bad Request: message to edit not found

I used this GitHub package to construct my Telegram bot. I want to edit my sent message from the bot. I get confused because I think everything is right!!!

  $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);

but when I saw the logs, $newmess['message_id'] is empty, according to the Telegram docs, if message sent success, the response contains keys such as message_id ! ( https://core.telegram.org/bots/api#message )

here is the log:

ok: False error_code: 400 description: Bad Request: message identifier is not specified

solved: $newmess['result']['message_id'] result key is required.

It is also possible to get message to edit not found error when the user clicks on the inline keyboard button after some time. In that case, an error happens due to the removed message. Telegram can remove your message from the server at any time (related to Bot API). In that case, you will receive a malformed response.

{
   "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"
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM