A
A
Alexey2022-01-29 02:54:37
PHP
Alexey, 2022-01-29 02:54:37

How to correctly editMessageText in Telegram Bot?

Hello dear experts.
There is a telegram bot in which InlineKeyboard is implemented:

$message_id = $data['message']['message_id']; // ID сообщения
$bot_message_id = (int)$message_id+1;     

$main_keyboard = json_encode([
            "inline_keyboard" => [
                [
                    [
                        "text" => "Button 1",
                        "callback_data" => "btn1"
                    ],
                    [
                        "text" => "Button 2",
                        "callback_data" => "btn2"
                    ],
                    [
                        "text" => "Button 3",
                        "callback_data" => "btn3"
                    ]
                ]
            ]
        ]);

        if ($message_in == "test") {
                $message_out = "Test InlineKeyboard";
                $params = ['chat_id' => $chat_id, 'text' => $message_out, 'reply_markup' => $main_keyboard];
                file_get_contents($SOURCE_URL.$TOKEN_BOT.$METHOD_SENDMESSAGE.http_build_query($params)); 
            }

        if ($callback_data == "btn1") {
                $edit_message_out = 'Edited message!';
                $params = ['chat_id' => $callback_id, 'message_id' => $bot_message_id, 'text' => $edit_message_out, 'reply_markup' => $main_keyboard];
                file_get_contents($SOURCE_URL.$TOKEN_BOT.$METHOD_EDITMESSAGE.http_build_query($params));
            }


The question is - when you click on the button, the message does not change at all, but if 'message_id' is set manually, then the message changes. Tell me where to dig?
(int) tried to remove, added for the test. If you simply set /sendMessage and send it the $bot_message_id variable, then it normally digests it and displays it. But when composing an array parameter to send, /editMessageText doesn't want to do anything at all.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alekssamos, 2022-01-29
@edlirius

$message_id = $data['query']['message']['message_id']; // ID сообщения

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question