单击后如何编辑嵌入式键盘?

时间:2018-12-03 17:10:56

标签: telegram-bot

我使用botman

单击后需要更改键盘。 输入命令/invoice

之后,在@shopbot(Telegram)中实现示例

我如何尝试:

$keyboard = Keyboard::create()->type( Keyboard::TYPE_INLINE )
        ->oneTimeKeyboard(false)
        ->addRow( KeyboardButton::create("My inline button")->callbackData('first_inline'),
            KeyboardButton::create("My inline button2")->callbackData('second_inline'))
        ->toArray();

    $changedKb = Keyboard::create()->type( Keyboard::TYPE_INLINE )
        ->oneTimeKeyboard(false)
        ->addRow( KeyboardButton::create("Changed")->callbackData('first_inline'),
            KeyboardButton::create("Changed2")->callbackData('second_inline'))
        ->toArray();

    return $this->ask('Test to inline', function (Answer $answer) use ($changedKb) {
        $this->bot->sendRequest('editMessageReplyMarkup',
            [
                'message_id' => $answer->getMessage()->getPayload()['message_id']
            ] + $changedKb, $answer->getMessage());
    }, $keyboard);

使用editMessageReplyMarkup,我没有成功,单击按钮后,文本更改了,但是按钮立即消失了

也许有人有解决方案,不一定是通过机器人来解决的

1 个答案:

答案 0 :(得分:0)

TelegramDriver类上有一个方法,可以删除键盘,可以对其进行更改

/**
 * This hide the inline keyboard, if is an interactive message.
 */
public function messagesHandled()
{
    $callback = $this->payload->get('callback_query');
    $hideInlineKeyboard = $this->config->get('hideInlineKeyboard', true);

    if ($callback !== null) {
        $callback['message']['chat']['id'];
        $this->removeInlineKeyboard($callback['message']['chat']['id'],
            $callback['message']['message_id']);
    }
}