skip to Main Content

Tell me pls, how to resize inline (not reply) buttons in a Telegram bot? The docs does not say anything at all about the resize of inline buttons.

Code:

foreach ($sections as $section) {
  $arrKeyboard[] = [
    'text' => $section->getTitle(),
    'callback_data' => '....'
  ];
}

$keyboard = new TelegramBotApiTypesInlineInlineKeyboardMarkup([$arrKeyboard]);
$telegramBot->sendMessage($message->getChat()->getId(), $answer, 'markdown', false, null, $keyboard);

How it looks

2

Answers


  1. Chosen as BEST ANSWER
    foreach ($sections as $section) {
      $arrKeyboard[] = [
        [
            'text' => $section->getTitle(),
            'callback_data' => '....'
        ]
      ];
    }
    
    $keyboard = new TelegramBotApiTypesInlineInlineKeyboardMarkup($arrKeyboard);
    $telegramBot->sendMessage($message->getChat()->getId(), $answer, 'markdown', false, null, $keyboard);
    

  2. You can use array_chunk function to set how many items should be displayed in each row.

    foreach ($sections as $section) {
      $arrKeyboard[] = [
        [
            'text' => $section->getTitle(),
            'callback_data' => '....'
        ]
      ];
    }
    array_chunk($arrKeyboard,2); // this will show 2 items in each row of inline keyboard. 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search