Menu
A menu is a set of interactive buttons that is displayed beneath a message. It uses an inline keyboard for that, so in a sense, a menu is just an inline keyboard spiced up with interactivity (such as navigation between multiple pages).
// Creating a simple menu
const menu = new Menu('my-menu-identifier')
.text('A', ctx => ctx.reply('You pressed A!')).row()
.text('B', ctx => ctx.reply('You pressed B!'))
// Make it interactive
bot.use(menu)
bot.command('start', async ctx => {
// Send the menu:
await ctx.reply('Check out this menu:', {
reply_markup: menu
})
})
Sending the menu is not directly possible via bot
, only via the context object, at least not yet.
Check out the official documentation to see how you can create menus that span several pages, how to navigate between them, and more.
Extends
Implements
Type Parameters
C
Constructors
Menu(id: string, options: MenuOptions<C>);
Creates a new menu with the given identifier.
Check out the official documentation to see how you can create menus that span several pages, how to navigate between them, and more.
Properties
inline_keyboard
readonly inline_keyboard: Proxy;
Used internally by the menu, do not touch or you’ll burn yourself.
Methods
register
Registers a submenu. This makes it accessible for navigation, and sets its parent menu to this
menu.
Optionally, you can specify the identifier of a different parent menu as a second argument. The parent menu is the menu that is targeted when backwards navigation is performed.
Note that once you registered a submenu, it is sufficient to call bot
for the parent menu only. You do not need to make all submenus interactive by passing them to bot
.
at
at(id: string);
Returns the menu instance for the given identifier. If the identifier is the same as this menu’s identifier, this
is returned.
middleware
middleware();