import { MenuRange } from "https://deno.land/x/grammy_menu@v1.2.2/mod.ts";
Adds a new text button. You may pass any number of listeners. They will be called when the button is pressed.
menu.text('Hit me!', ctx => ctx.reply('Ouch!'))
If you pass several listeners, make sure that you understand what middleware is.
You can also use this method to register a button that depends on the current context.
function greetInstruction(ctx: Context): string {
const username = ctx.from?.first_name
return `Greet ${username ?? 'me'}!`,
}
const menu = new Menu('my-menu')
.text(greetInstruction, ctx => ctx.reply("I'm too shy."))
bot.use(menu)
// This will send a menu with one text button, and the text has the name
// of the user that the bot is replying to.
bot.on('message', ctx => ctx.reply('What shall I do?', { reply_markup: menu }))
If you base the text on session data, you can easily create a settings panel with toggle buttons.
// Button will toggle between 'Yes' and 'No' when pressed
menu.text(ctx => ctx.session.flag ? 'Yes' : 'No', async ctx => {
ctx.session.flag = !ctx.session.flag
await ctx.menu.update()
})