php 如何在Telegram机器人中调整内联按钮的大小?

z5btuh9x  于 2023-03-07  发布在  PHP
关注(0)|答案(2)|浏览(134)

请告诉我,如何在电报机器人中调整内嵌(不是回复)按钮的大小?文档中根本没有提到内嵌按钮的大小。
代码:

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

$keyboard = new \TelegramBot\Api\Types\Inline\InlineKeyboardMarkup([$arrKeyboard]);
$telegramBot->sendMessage($message->getChat()->getId(), $answer, 'markdown', false, null, $keyboard);

rqqzpn5f

rqqzpn5f1#

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

$keyboard = new \TelegramBot\Api\Types\Inline\InlineKeyboardMarkup($arrKeyboard);
$telegramBot->sendMessage($message->getChat()->getId(), $answer, 'markdown', false, null, $keyboard);
rqqzpn5f

rqqzpn5f2#

您可以使用array_chunk函数来设置每行应显示多少项。

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.

相关问题