Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/grammy_menu/deps.deno.ts>Composer#on

Interactive menus for grammY.
Latest
method Composer.prototype.on
import { Composer } from "https://deno.land/x/grammy_menu@v1.3.0/deps.deno.ts";

Registers some middleware that will only be executed for some specific updates, namely those matching the provided filter query. Filter queries are a concise way to specify which updates you are interested in.

Here are some examples of valid filter queries:

// All kinds of message updates
bot.on('message', ctx => { ... })

// Only text messages
bot.on('message:text', ctx => { ... })

// Only text messages with URL
bot.on('message:entities:url', ctx => { ... })

// Text messages and text channel posts
bot.on(':text', ctx => { ... })

// Messages with URL in text or caption (i.e. entities or caption entities)
bot.on('message::url', ctx => { ... })

// Messages or channel posts with URL in text or caption
bot.on('::url', ctx => { ... })

You can use autocomplete in VS Code to see all available filter queries. Check out the documentation on the website to learn more about filter queries in grammY.

It is possible to pass multiple filter queries in an array, i.e.

// Matches all text messages and edited text messages that contain a URL
bot.on(['message:entities:url', 'edited_message:entities:url'], ctx => { ... })

Your middleware will be executed if any of the provided filter queries matches (logical OR).

If you instead want to match all of the provided filter queries (logical AND), you can chain the .on calls:

// Matches all messages and channel posts that both a) contain a URL and b) are forwards
bot.on('::url').on(':forward_origin', ctx => { ... })

Parameters

filter: Q | Q[]

The filter query to use, may also be an array of queries

...middleware: Array<Middleware<Filter<C, Q>>>

The middleware to register behind the given filter