/** @format */ import * as tg from './core/types/typegram'; import * as tt from './telegram-types'; import { Middleware, MiddlewareFn, MiddlewareObj } from './middleware'; import Context, { FilteredContext, NarrowedContext } from './context'; import { MaybeArray, NonemptyReadonlyArray, MaybePromise, Guard } from './core/helpers/util'; import { type CallbackQuery } from './core/types/typegram'; import { Digit, Reaction } from './reactions'; type ReactionAddedOrRemoved = Reaction | `-${tg.TelegramEmoji}` | `-${Digit}${string}`; export type Triggers = MaybeArray>; type TriggerFn = (value: string, ctx: C) => RegExpExecArray | null; export type Predicate = (t: T) => boolean; export type AsyncPredicate = (t: T) => Promise; export type MatchedMiddleware = NonemptyReadonlyArray & { match: RegExpExecArray; }, tt.MountMap[T]>>; interface StartContextExtn extends tt.CommandContextExtn { /** * @deprecated Use ctx.payload instead */ startPayload: string; } export declare class Composer implements MiddlewareObj { private handler; constructor(...fns: ReadonlyArray>); /** * Registers a middleware. */ use(...fns: ReadonlyArray>): this; /** * Registers middleware for handling updates * matching given type guard function. * @deprecated use `Composer::on` */ guard(guardFn: (update: tg.Update) => update is U, ...fns: NonemptyReadonlyArray, U>>): this; /** * Registers middleware for handling updates narrowed by update types or filter queries. */ on>(filters: MaybeArray, ...fns: NonemptyReadonlyArray>>): this; /** * Registers middleware for handling updates narrowed by update types or message subtypes. * @deprecated Use filter utils instead. Support for Message subtype in `Composer::on` will be removed in Telegraf v5. */ on(filters: MaybeArray, ...fns: NonemptyReadonlyArray, tt.MountMap[Filter]>>): this; /** * Registers middleware for handling matching text messages. */ hears(triggers: Triggers>, ...fns: MatchedMiddleware): this; /** * Registers middleware for handling specified commands. */ command(command: Triggers>, ...fns: NonemptyReadonlyArray & tt.CommandContextExtn>>): this; /** * Registers middleware for handling matching callback queries. */ action(triggers: Triggers>, ...fns: MatchedMiddleware): this; /** * Registers middleware for handling matching inline queries. */ inlineQuery(triggers: Triggers>, ...fns: MatchedMiddleware): this; /** * Registers middleware for handling game queries */ gameQuery(...fns: NonemptyReadonlyArray>>>): this; reaction(reaction: MaybeArray, ...fns: NonemptyReadonlyArray & { match: ReactionAddedOrRemoved; }, tg.Update.MessageReactionUpdate>>): this; /** * Registers middleware for dropping matching updates. */ drop(predicate: Predicate): this; /** @deprecated use `Composer::drop` */ filter(predicate: Predicate): this; private entity; email(email: Triggers, ...fns: MatchedMiddleware): this; url(url: Triggers, ...fns: MatchedMiddleware): this; textLink(link: Triggers, ...fns: MatchedMiddleware): this; textMention(mention: Triggers, ...fns: MatchedMiddleware): this; mention(mention: MaybeArray, ...fns: MatchedMiddleware): this; phone(number: Triggers, ...fns: MatchedMiddleware): this; hashtag(hashtag: MaybeArray, ...fns: MatchedMiddleware): this; cashtag(cashtag: MaybeArray, ...fns: MatchedMiddleware): this; spoiler(text: Triggers, ...fns: MatchedMiddleware): this; /** * Registers a middleware for handling /start */ start(...fns: NonemptyReadonlyArray & StartContextExtn>>): this; /** * Registers a middleware for handling /help */ help(...fns: NonemptyReadonlyArray & tt.CommandContextExtn>>): this; /** * Registers a middleware for handling /settings */ settings(...fns: NonemptyReadonlyArray & tt.CommandContextExtn>>): this; middleware(): MiddlewareFn; static reply(...args: Parameters): MiddlewareFn; static catch(errorHandler: (err: unknown, ctx: C) => void, ...fns: ReadonlyArray>): MiddlewareFn; /** * Generates middleware that runs in the background. */ static fork(middleware: Middleware): MiddlewareFn; static tap(middleware: Middleware): MiddlewareFn; /** * Generates middleware that gives up control to the next middleware. */ static passThru(): MiddlewareFn; static lazy(factoryFn: (ctx: C) => MaybePromise>): MiddlewareFn; static log(logFn?: (s: string) => void): MiddlewareFn; /** * @param trueMiddleware middleware to run if the predicate returns true * @param falseMiddleware middleware to run if the predicate returns false */ static branch(predicate: boolean | Predicate | AsyncPredicate, trueMiddleware: Middleware, falseMiddleware: Middleware): MiddlewareFn; /** * Generates optional middleware. * @param predicate predicate to decide on a context object whether to run the middleware * @param fns middleware to run if the predicate returns true */ static optional(predicate: Predicate | AsyncPredicate, ...fns: NonemptyReadonlyArray>): MiddlewareFn; /** @deprecated use `Composer.drop` */ static filter(predicate: Predicate): MiddlewareFn; /** * Generates middleware for dropping matching updates. */ static drop(predicate: Predicate): MiddlewareFn; static dispatch>>(routeFn: (ctx: C) => MaybePromise, handlers: Handlers): Middleware; /** * Generates optional middleware based on a predicate that only operates on `ctx.update`. * * Example: * ```ts * import { Composer, Update } from 'telegraf' * * const predicate = (u): u is Update.MessageUpdate => 'message' in u * const middleware = Composer.guard(predicate, (ctx) => { * const message = ctx.update.message * }) * ``` * * Note that `Composer.on('message')` is preferred over this. * * @param guardFn predicate to decide whether to run the middleware based on the `ctx.update` object * @param fns middleware to run if the predicate returns true * @see `Composer.optional` for a more generic version of this method that allows the predicate to operate on `ctx` itself * @deprecated use `Composer.on` */ static guard(guardFn: (u: tg.Update) => u is U, ...fns: NonemptyReadonlyArray, U>>): MiddlewareFn; /** * Generates middleware for handling updates narrowed by update types or filter queries. */ static on>(filters: MaybeArray, ...fns: NonemptyReadonlyArray>>): MiddlewareFn; /** * Generates middleware for handling updates narrowed by update types or message subtype. * @deprecated Use filter utils instead. Support for Message subtype in `Composer.on` will be removed in Telegraf v5. */ static on(filters: MaybeArray, ...fns: NonemptyReadonlyArray, tt.MountMap[Filter]>>): MiddlewareFn; /** * Generates middleware for handling provided update types. * @deprecated use `Composer.on` instead */ static mount: typeof Composer.on; private static entity; static entityText(entityType: MaybeArray, predicate: Triggers, ...fns: MatchedMiddleware): MiddlewareFn; static email(email: Triggers, ...fns: MatchedMiddleware): MiddlewareFn; static phone(number: Triggers, ...fns: MatchedMiddleware): MiddlewareFn; static url(url: Triggers, ...fns: MatchedMiddleware): MiddlewareFn; static textLink(link: Triggers, ...fns: MatchedMiddleware): MiddlewareFn; static textMention(mention: Triggers, ...fns: MatchedMiddleware): MiddlewareFn; static mention(mention: MaybeArray, ...fns: MatchedMiddleware): MiddlewareFn; static hashtag(hashtag: MaybeArray, ...fns: MatchedMiddleware): MiddlewareFn; static cashtag(cashtag: MaybeArray, ...fns: MatchedMiddleware): MiddlewareFn; static spoiler(text: Triggers, ...fns: MatchedMiddleware): MiddlewareFn; private static match; /** * Generates middleware for handling matching text messages. */ static hears(triggers: Triggers>, ...fns: MatchedMiddleware): MiddlewareFn; /** * Generates middleware for handling specified commands. */ static command(command: Triggers>, ...fns: NonemptyReadonlyArray & tt.CommandContextExtn>>): MiddlewareFn; /** * Generates middleware for handling matching callback queries. */ static action(triggers: Triggers>, ...fns: MatchedMiddleware): MiddlewareFn; /** * Generates middleware for handling matching inline queries. */ static inlineQuery(triggers: Triggers>, ...fns: MatchedMiddleware): MiddlewareFn; static reaction(reaction: MaybeArray, ...fns: NonemptyReadonlyArray & { match: ReactionAddedOrRemoved; }, tg.Update.MessageReactionUpdate>>): MiddlewareFn; /** * Generates middleware responding only to specified users. */ static acl(userId: MaybeArray, ...fns: NonemptyReadonlyArray>): MiddlewareFn; private static memberStatus; /** * Generates middleware responding only to chat admins and chat creator. */ static admin(...fns: NonemptyReadonlyArray>): MiddlewareFn; /** * Generates middleware responding only to chat creator. */ static creator(...fns: NonemptyReadonlyArray>): MiddlewareFn; /** * Generates middleware running only in specified chat types. */ static chatType(type: MaybeArray, ...fns: NonemptyReadonlyArray>): MiddlewareFn; /** * Generates middleware running only in private chats. */ static privateChat(...fns: NonemptyReadonlyArray>): MiddlewareFn; /** * Generates middleware running only in groups and supergroups. */ static groupChat(...fns: NonemptyReadonlyArray>): MiddlewareFn; /** * Generates middleware for handling game queries. */ static gameQuery(...fns: NonemptyReadonlyArray>>>): MiddlewareFn; static unwrap(handler: Middleware): MiddlewareFn; static compose(middlewares: ReadonlyArray>): MiddlewareFn; } export default Composer; //# sourceMappingURL=composer.d.ts.map