Module

x/grammy/composer.ts>Composer#lazy

The Telegram Bot Framework.
Very Popular
Latest
method Composer.prototype.lazy
import { Composer } from "https://dotland.deno.dev/x/grammy@v1.31.0/composer.ts";

This is an advanced method of grammY.

Executes some middleware that can be generated on the fly for each context. Pass a factory function that creates some middleware (or a middleware array even). The factory function will be called once per context, and its result will be executed with the context object.

// The middleware returned by `createMyMiddleware` will be used only once
bot.lazy(ctx => createMyMiddleware(ctx))

You may generate this middleware in an async fashion.

You can decide to return an empty array ([]) if you don't want to run any middleware for a given context object. This is equivalent to returning an empty instance of Composer.

Parameters

middlewareFactory: (ctx: C) => MaybePromise<MaybeArray<Middleware<C>>>

The factory function creating the middleware