import { Menu } from "https://deno.land/x/grammy_menu@v1.2.2/menu.ts";
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.api.sendMessage
, 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.
Constructors
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
Methods
Prevents this menu from being modified further in the future.
Replaces known menu instances in the payload by their rendered versions.
A menu is known if it is contained in this menu's index. Only the
reply_markup
property of the given object is checked for containing a
menu.
Renders the menu to a static object of inline keyboard buttons by concatenating all ranges, and applying the given context object to all functions.
Returns the menu instance for the given identifier. If the identifier is
the same as this menu's identifier, this
is returned.
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.use(menu)
for the parent menu only. You do not need to make all
submenus interactive by passing them to bot.use
.