E
E
Evgeny2021-07-16 21:56:19
PHP
Evgeny, 2021-07-16 21:56:19

How to delete a message in a telegram bot after clicking on any button?

switch ($callback_data) {
        case 'Media':
            $post = [
                'chat_id' => $user_id,
                'text' => 'Отлично, а теперь выбери нужный вопрос:',
                'reply_markup' => inline_keyboard([
                    ,
                    ,
                    ,
                    ]),
            ];
            telegram('sendMessage', $post);
            break;}

Code example with callback_data above

The bot displays the value of callback_data in the chat along with the text that is attached to it (which also needs to be deleted or not displayed at all)

How to deal with this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nokimaro, 2021-07-16
@fakin_kiska

https://core.telegram.org/bots/api#deletemessage

<?php
function deleteMessage($callback_query, $bot_api_key)
{
    $apiUri = 'https://api.telegram.org/bot'.$bot_api_key.'/deleteMessage?'.
              '&chat_id='.$callback_query->message->chat->id.
              '&message_id='.$callback_query->message->message_id.
              '';

    return file_get_contents($apiUri);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question