E
E
Evgeny2021-09-06 04:11:10
Bots
Evgeny, 2021-09-06 04:11:10

How to make buttons under the chat in a telegram bot?

I can’t figure out how to make buttons under the chat in the bot, I didn’t find the necessary information. You need to make buttons (at least one) as in the screenshot: I

61356a6ad8980541052262.png

wrote the code for the command so that when it is entered, a button under the chat pops up, which can be pressed

Function for the button that returns json:

function reply_keyboard($array) {
return json_encode(['reply_keyboard' => $array]); }


The command that calls the button:

if (strpos($message, "/start") === 0) { // Команда /start
    $cocktails_button = [];
    $reply_markup = reply_keyboard($cocktails_button);
}


The problem is that it does not work, that is, the button does not appear after entering the command, I don’t know what I might have missed

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny, 2021-09-07
@fakin_kiska

For starters, I made a function that returns json

function reply_keyboard($array) {
    return json_encode(['keyboard' => $array]);
}

Then I made a separate command (in my case, it is the /start command), which sends the text and this button under the chat:
if (strpos($message, "/start") === 0) { // Команда /start, вызов кнопки под чатом
    $post = [
        'chat_id' => $chat_id,
        'text' => 'Напиши любое сообщение или нажми на кнопку ниже, чтобы начать!',
        $cocktails_button = [],
        'reply_markup' => reply_keyboard($cocktails_button),
        'resize_keyboard' => true,
        'one_time_keyboard' => true
    ];
    sendRequest('sendMessage', $post);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question