import { Composer } from "https://deno.land/x/grammy@v1.30.1/composer.ts";
Registers some middleware for callback queries, i.e. the updates that Telegram delivers to your bot when a user clicks an inline button (that is a button under a message).
This method is essentially the same as calling
bot.on('callback_query:data', ctx => { ... })
but it also allows you to match the query data against a given text or regular expression.
// Create an inline keyboard
const keyboard = new InlineKeyboard().text('Go!', 'button-payload')
// Send a message with the keyboard
await bot.api.sendMessage(chat_id, 'Press a button!', {
reply_markup: keyboard
})
// Listen to users pressing buttons with that specific payload
bot.callbackQuery('button-payload', ctx => { ... })
// Listen to users pressing any button your bot ever sent
bot.on('callback_query:data', ctx => { ... })
Always remember to call answerCallbackQuery
—even if you don't perform
any action: https://core.telegram.org/bots/api#answercallbackquery
bot.on('callback_query:data', async ctx => {
await ctx.answerCallbackQuery()
})
You can pass an array of triggers. Your middleware will be executed if at least one of them matches.
Parameters
trigger: MaybeArray<string | RegExp>
The string to look for in the payload
...middleware: Array<CallbackQueryMiddleware<C>>
The middleware to register