Class Composer<C>

Type Parameters

Hierarchy

Implements

Constructors

Properties

handler: MiddlewareFn<C>
mount: {
    <Ctx, Filter>(filters, ...fns): MiddlewareFn<Ctx>;
    <Ctx, Filter>(filters, ...fns): MiddlewareFn<Ctx>;
} = Composer.on

Type declaration

    • <Ctx, Filter>(filters, ...fns): MiddlewareFn<Ctx>
    • Generates middleware for handling provided update types.

      Type Parameters

      Parameters

      • filters: MaybeArray<Filter>
      • Rest ...fns: NonemptyReadonlyArray<Middleware<FilteredContext<Ctx, Filter>>>
        Rest

      Returns MiddlewareFn<Ctx>

      Deprecated

      use Composer.on instead

    • <Ctx, Filter>(filters, ...fns): MiddlewareFn<Ctx>
    • Generates middleware for handling provided update types.

      Type Parameters

      • Ctx extends Context<Update>

      • Filter extends "text" | "sticker" | "animation" | "audio" | "document" | "photo" | "video" | "video_note" | "voice" | "callback_query" | "channel_post" | "chat_member" | "chosen_inline_result" | "edited_channel_post" | "message_reaction" | "message_reaction_count" | "edited_message" | "inline_query" | "message" | "my_chat_member" | "pre_checkout_query" | "poll_answer" | "poll" | "shipping_query" | "chat_join_request" | "chat_boost" | "removed_chat_boost" | "has_media_spoiler" | "contact" | "dice" | "location" | "new_chat_members" | "left_chat_member" | "new_chat_title" | "new_chat_photo" | "delete_chat_photo" | "group_chat_created" | "supergroup_chat_created" | "channel_chat_created" | "message_auto_delete_timer_changed" | "migrate_to_chat_id" | "migrate_from_chat_id" | "pinned_message" | "invoice" | "successful_payment" | "users_shared" | "chat_shared" | "connected_website" | "write_access_allowed" | "passport_data" | "proximity_alert_triggered" | "boost_added" | "forum_topic_created" | "forum_topic_edited" | "forum_topic_closed" | "forum_topic_reopened" | "general_forum_topic_hidden" | "general_forum_topic_unhidden" | "giveaway_created" | "giveaway" | "giveaway_winners" | "giveaway_completed" | "video_chat_scheduled" | "video_chat_started" | "video_chat_ended" | "video_chat_participants_invited" | "web_app_data" | "game" | "story" | "venue" | "forward_date"

      Parameters

      Returns MiddlewareFn<Ctx>

      Deprecated

      use Composer.on instead

Methods

  • Registers middleware for handling matching callback queries.

    Parameters

    • triggers: Triggers<NarrowedContext<C, CallbackQueryUpdate<CallbackQuery>>>
    • Rest ...fns: MatchedMiddleware<C, "callback_query">
      Rest

    Returns Composer<C>

  • Parameters

    • cashtag: MaybeArray<string>
    • Rest ...fns: MatchedMiddleware<C, "channel_post" | "message">
      Rest

    Returns Composer<C>

  • Registers middleware for handling specified commands.

    Parameters

    • command: Triggers<NarrowedContext<C, {
          message: New & NonChannel & TextMessage;
          update_id: number;
      }>>
    • Rest ...fns: NonemptyReadonlyArray<Middleware<Context<{
          message: New & NonChannel & TextMessage;
          update_id: number;
      }> & Omit<C, keyof Context<Update>> & CommandContextExtn>>
      Rest

    Returns Composer<C>

  • Parameters

    • email: Triggers<C>
    • Rest ...fns: MatchedMiddleware<C, "channel_post" | "message">
      Rest

    Returns Composer<C>

  • Registers middleware for handling updates matching given type guard function.

    Type Parameters

    • U extends Update

    Parameters

    • guardFn: ((update) => update is U)
        • (update): update is U
        • Parameters

          • update: Update

          Returns update is U

    • Rest ...fns: NonemptyReadonlyArray<Middleware<NarrowedContext<C, U>, U>>
      Rest

    Returns Composer<C>

    Deprecated

    use Composer::on

  • Parameters

    • hashtag: MaybeArray<string>
    • Rest ...fns: MatchedMiddleware<C, "channel_post" | "message">
      Rest

    Returns Composer<C>

  • Registers middleware for handling matching text messages.

    Parameters

    • triggers: Triggers<NarrowedContext<C, {
          message: New & NonChannel & TextMessage;
          update_id: number;
      }>>
    • Rest ...fns: MatchedMiddleware<C, "text">
      Rest

    Returns Composer<C>

  • Registers middleware for handling matching inline queries.

    Parameters

    • triggers: Triggers<NarrowedContext<C, InlineQueryUpdate>>
    • Rest ...fns: MatchedMiddleware<C, "inline_query">
      Rest

    Returns Composer<C>

  • Parameters

    • mention: MaybeArray<string>
    • Rest ...fns: MatchedMiddleware<C, "channel_post" | "message">
      Rest

    Returns Composer<C>

  • Registers middleware for handling updates narrowed by update types or filter queries.

    Type Parameters

    Parameters

    • filters: MaybeArray<Filter>
    • Rest ...fns: NonemptyReadonlyArray<Middleware<FilteredContext<C, Filter>>>
      Rest

    Returns Composer<C>

  • Registers middleware for handling updates narrowed by update types or message subtypes.

    Type Parameters

    • Filter extends "text" | "sticker" | "animation" | "audio" | "document" | "photo" | "video" | "video_note" | "voice" | "callback_query" | "channel_post" | "chat_member" | "chosen_inline_result" | "edited_channel_post" | "message_reaction" | "message_reaction_count" | "edited_message" | "inline_query" | "message" | "my_chat_member" | "pre_checkout_query" | "poll_answer" | "poll" | "shipping_query" | "chat_join_request" | "chat_boost" | "removed_chat_boost" | "has_media_spoiler" | "contact" | "dice" | "location" | "new_chat_members" | "left_chat_member" | "new_chat_title" | "new_chat_photo" | "delete_chat_photo" | "group_chat_created" | "supergroup_chat_created" | "channel_chat_created" | "message_auto_delete_timer_changed" | "migrate_to_chat_id" | "migrate_from_chat_id" | "pinned_message" | "invoice" | "successful_payment" | "users_shared" | "chat_shared" | "connected_website" | "write_access_allowed" | "passport_data" | "proximity_alert_triggered" | "boost_added" | "forum_topic_created" | "forum_topic_edited" | "forum_topic_closed" | "forum_topic_reopened" | "general_forum_topic_hidden" | "general_forum_topic_unhidden" | "giveaway_created" | "giveaway" | "giveaway_winners" | "giveaway_completed" | "video_chat_scheduled" | "video_chat_started" | "video_chat_ended" | "video_chat_participants_invited" | "web_app_data" | "game" | "story" | "venue" | "forward_date"

    Parameters

    Returns Composer<C>

    Deprecated

    Use filter utils instead. Support for Message subtype in Composer::on will be removed in Telegraf v5.

  • Parameters

    • number: Triggers<C>
    • Rest ...fns: MatchedMiddleware<C, "channel_post" | "message">
      Rest

    Returns Composer<C>

  • Parameters

    • reaction: MaybeArray<ReactionAddedOrRemoved>
    • Rest ...fns: NonemptyReadonlyArray<Middleware<Context<MessageReactionUpdate> & Omit<C, keyof Context<Update>> & {
          match: ReactionAddedOrRemoved;
      }, MessageReactionUpdate>>
      Rest

    Returns Composer<C>

  • Parameters

    • text: Triggers<C>
    • Rest ...fns: MatchedMiddleware<C, "channel_post" | "message">
      Rest

    Returns Composer<C>

  • Registers a middleware for handling /start

    Parameters

    • Rest ...fns: NonemptyReadonlyArray<Middleware<Context<{
          message: New & NonChannel & TextMessage;
          update_id: number;
      }> & Omit<C, keyof Context<Update>> & StartContextExtn>>
      Rest

    Returns Composer<C>

  • Parameters

    • link: Triggers<C>
    • Rest ...fns: MatchedMiddleware<C, "channel_post" | "message">
      Rest

    Returns Composer<C>

  • Parameters

    • mention: Triggers<C>
    • Rest ...fns: MatchedMiddleware<C, "channel_post" | "message">
      Rest

    Returns Composer<C>

  • Parameters

    • url: Triggers<C>
    • Rest ...fns: MatchedMiddleware<C, "channel_post" | "message">
      Rest

    Returns Composer<C>

  • Generates middleware for handling matching callback queries.

    Type Parameters

    Parameters

    • triggers: Triggers<NarrowedContext<C, CallbackQueryUpdate<CallbackQuery>>>
    • Rest ...fns: MatchedMiddleware<C, "callback_query">
      Rest

    Returns MiddlewareFn<C>

  • Type Parameters

    Parameters

    • predicate: boolean | Predicate<C> | AsyncPredicate<C>
    • trueMiddleware: Middleware<C>

      middleware to run if the predicate returns true

    • falseMiddleware: Middleware<C>

      middleware to run if the predicate returns false

    Returns MiddlewareFn<C>

  • Generates middleware running only in specified chat types.

    Type Parameters

    Parameters

    • type: MaybeArray<"channel" | "group" | "supergroup" | "private">
    • Rest ...fns: NonemptyReadonlyArray<Middleware<C>>
      Rest

    Returns MiddlewareFn<C>

  • Type Parameters

    • C extends Context<Update>

    • Handlers extends Record<string | number | symbol, Middleware<C>>

    Parameters

    • routeFn: ((ctx) => MaybePromise<keyof Handlers>)
        • (ctx): MaybePromise<keyof Handlers>
        • Parameters

          • ctx: C

          Returns MaybePromise<keyof Handlers>

    • handlers: Handlers

    Returns Middleware<C>

  • Type Parameters

    Parameters

    • entityType: MaybeArray<string>
    • predicate: Triggers<C>
    • Rest ...fns: MatchedMiddleware<C, "channel_post" | "message">
      Rest

    Returns MiddlewareFn<C>

  • Generates optional middleware based on a predicate that only operates on ctx.update.

    Example:

    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.

    Type Parameters

    • C extends Context<Update>

    • U extends Update

    Parameters

    • guardFn: ((u) => u is U)

      predicate to decide whether to run the middleware based on the ctx.update object

        • (u): u is U
        • Parameters

          • u: Update

          Returns u is U

    • Rest ...fns: NonemptyReadonlyArray<Middleware<NarrowedContext<C, U>, U>>

      middleware to run if the predicate returns true

      Rest

    Returns MiddlewareFn<C>

    See

    Composer.optional for a more generic version of this method that allows the predicate to operate on ctx itself

    Deprecated

    use Composer.on

  • Generates middleware for handling matching text messages.

    Type Parameters

    Parameters

    • triggers: Triggers<NarrowedContext<C, {
          message: New & NonChannel & TextMessage;
          update_id: number;
      }>>
    • Rest ...fns: MatchedMiddleware<C, "text">
      Rest

    Returns MiddlewareFn<C>

  • Generates middleware for handling matching inline queries.

    Type Parameters

    Parameters

    • triggers: Triggers<NarrowedContext<C, InlineQueryUpdate>>
    • Rest ...fns: MatchedMiddleware<C, "inline_query">
      Rest

    Returns MiddlewareFn<C>

  • Type Parameters

    Parameters

    • status: MaybeArray<"creator" | "administrator" | "member" | "restricted" | "left" | "kicked">
    • Rest ...fns: NonemptyReadonlyArray<Middleware<C>>
      Rest

    Returns MiddlewareFn<C>

  • Generates middleware for handling updates narrowed by update types or filter queries.

    Type Parameters

    Parameters

    • filters: MaybeArray<Filter>
    • Rest ...fns: NonemptyReadonlyArray<Middleware<FilteredContext<Ctx, Filter>>>
      Rest

    Returns MiddlewareFn<Ctx>

  • Generates middleware for handling updates narrowed by update types or message subtype.

    Type Parameters

    • Ctx extends Context<Update>

    • Filter extends "text" | "sticker" | "animation" | "audio" | "document" | "photo" | "video" | "video_note" | "voice" | "callback_query" | "channel_post" | "chat_member" | "chosen_inline_result" | "edited_channel_post" | "message_reaction" | "message_reaction_count" | "edited_message" | "inline_query" | "message" | "my_chat_member" | "pre_checkout_query" | "poll_answer" | "poll" | "shipping_query" | "chat_join_request" | "chat_boost" | "removed_chat_boost" | "has_media_spoiler" | "contact" | "dice" | "location" | "new_chat_members" | "left_chat_member" | "new_chat_title" | "new_chat_photo" | "delete_chat_photo" | "group_chat_created" | "supergroup_chat_created" | "channel_chat_created" | "message_auto_delete_timer_changed" | "migrate_to_chat_id" | "migrate_from_chat_id" | "pinned_message" | "invoice" | "successful_payment" | "users_shared" | "chat_shared" | "connected_website" | "write_access_allowed" | "passport_data" | "proximity_alert_triggered" | "boost_added" | "forum_topic_created" | "forum_topic_edited" | "forum_topic_closed" | "forum_topic_reopened" | "general_forum_topic_hidden" | "general_forum_topic_unhidden" | "giveaway_created" | "giveaway" | "giveaway_winners" | "giveaway_completed" | "video_chat_scheduled" | "video_chat_started" | "video_chat_ended" | "video_chat_participants_invited" | "web_app_data" | "game" | "story" | "venue" | "forward_date"

    Parameters

    Returns MiddlewareFn<Ctx>

    Deprecated

    Use filter utils instead. Support for Message subtype in Composer.on will be removed in Telegraf v5.

  • Generates optional middleware.

    Type Parameters

    Parameters

    • predicate: Predicate<C> | AsyncPredicate<C>

      predicate to decide on a context object whether to run the middleware

    • Rest ...fns: NonemptyReadonlyArray<Middleware<C>>

      middleware to run if the predicate returns true

      Rest

    Returns MiddlewareFn<C>

  • Type Parameters

    Parameters

    • reaction: MaybeArray<ReactionAddedOrRemoved>
    • Rest ...fns: NonemptyReadonlyArray<Middleware<Context<MessageReactionUpdate> & Omit<C, keyof Context<Update>> & {
          match: ReactionAddedOrRemoved;
      }, MessageReactionUpdate>>
      Rest

    Returns MiddlewareFn<C>

Generated using TypeDoc