G
G
generate2021-10-17 13:54:52
PHP
generate, 2021-10-17 13:54:52

How to set a key for a button in a telegram bot?

I am doing this now

$buttons = [
  'resize_keyboard' => true,
  'keyboard' => [
    ['Кнопка 1', 'Кнопка 2'],
  ],
];

$content = array(
    'chat_id' => $data['message']['from']['id'],
    'reply_markup' => json_encode($buttons),
    'text' => "Test"
);


message_to_telegram($content);

function message_to_telegram($array)
{
    $ch = curl_init();
    curl_setopt_array(
        $ch,
        array(
            CURLOPT_URL => 'https://api.telegram.org/botAPI/sendMessage',
            CURLOPT_POST => TRUE,
            CURLOPT_RETURNTRANSFER => TRUE,
            CURLOPT_TIMEOUT => 10,
            CURLOPT_POSTFIELDS => $array,
        )
    );
    curl_exec($ch);
}


But why can't I set a key for the buttons?
$buttons = [
  'resize_keyboard' => true,
  'keyboard' => [
    [ 'btn1' => 'Кнопка 1',   'btn2'  => 'Кнопка 2'],
  ],
];

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shurshur, 2021-10-17
@generate

"Keys" can only be set for the inline keyboard.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question