Inline Menu
The InlineMenu
class extends Conversation and help you to provide an easy interface to
create inline menu messages in your bot.
Methods
menuText(string $text, array $opt = [])
Set the message text and the optional message parametersaddButtonRow(... InlineKeyboardButton $buttons)
Set a row of buttons to the current message
When you use a button withcallback_data
, you must set the value ascallbackData@methodName
and create a method with the namemethodName
clearButtons()
Remove the buttons from the current messageorNext(?string $orNext)
Call a method if there is no matching handlersshowMenu(bool $reopen = false, bool $noHandlers = false, bool $noMiddlewares = false)
Send the message with buttonscloseMenu()
Close the menu deleting the current message
Changing Telegram method type
Override the following methods only to change the Telegram method used:
doOpen()
Send the message. Default:sendMessage
doUpdate()
Edit the message. Default:editMessageText
doClose()
Delete the message. Default:deleteMessage
Example
class ChooseColorMenu extends InlineMenu
{
public function start(Nutgram $bot)
{
$this->menuText('Choose a color:')
->addButtonRow(InlineKeyboardButton::make('Red', callback_data: 'red@handleColor'))
->addButtonRow(InlineKeyboardButton::make('Green', callback_data: 'green@handleColor'))
->addButtonRow(InlineKeyboardButton::make('Yellow', callback_data: 'yellow@handleColor'))
->orNext('none')
->showMenu();
}
public function handleColor(Nutgram $bot)
{
$color = $bot->callbackQuery()->data;
$this->menuText("Choosen: $color!")
->showMenu();
}
public function none(Nutgram $bot)
{
$bot->sendMessage('Bye!');
$this->end();
}
}
Result: