Class Telegraf<C>

Type Parameters

Hierarchy

Constructors

Properties

botInfo?: UserFromGetMe

Set manually to avoid implicit getMe call in launch or webhookCallback

botInfoCall?: Promise<UserFromGetMe>
context: Partial<C> = {}
options: Options<C>
polling?: Polling
telegram: Telegram
webhookFilter: ((this, req) => boolean) = ...

Type declaration

    • (this, req): boolean
    • Assign to this to customise the webhook filter middleware. { path, secretToken } will be bound to this rather than the Telegraf instance. Remember to assign a regular function and not an arrow function so it's bindable.

      Parameters

      • this: {
            hookPath: string;
            path: string;
            secretToken?: string;
        }
        • hookPath: string

          Deprecated

          Use path instead

        • path: string
        • Optional secretToken?: string
      • req: IncomingMessage

      Returns boolean

webhookServer?: Server<typeof IncomingMessage, typeof ServerResponse> | Server<typeof IncomingMessage, typeof ServerResponse>
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

Accessors

  • get webhookReply(): boolean
  • Returns boolean

    Deprecated

    use ctx.telegram.webhookReply

  • set webhookReply(webhookReply): void
  • Parameters

    • webhookReply: boolean

    Returns void

    Deprecated

    use ctx.telegram.webhookReply

Methods

  • Registers middleware for handling matching callback queries.

    Parameters

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

    Returns Telegraf<C>

  • Override error handling

    Parameters

    • handler: ((err, ctx) => MaybePromise<void>)
        • (err, ctx): MaybePromise<void>
        • Parameters

          • err: unknown
          • ctx: C

          Returns MaybePromise<void>

    Returns Telegraf<C>

  • Specify a url to receive incoming updates via webhook. Returns an Express-style middleware you can pass to app.use()

    Parameters

    • opts: {
          domain: string;
          path?: string;
      } & Omit<{}, "url" | "chat_id">

    Returns Promise<((req, res, next?) => Promise<void>)>

  • Parameters

    • opts: {
          domain: string;
          path?: string;
      }
      • domain: string
      • Optional path?: string

    Returns {
        domain: string;
        path: string;
        url: string;
    }

    • domain: string
    • path: string
    • url: string
  • 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 Telegraf<C>

    Deprecated

    use Composer::on

  • Parameters

    • err: unknown
    • ctx: C

    Returns MaybePromise<void>

  • Parameters

    • update: Update
    • Optional webhookResponse: ServerResponse<IncomingMessage>
      Optional

    Returns Promise<void>

  • 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 Telegraf<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 Telegraf<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 Telegraf<C>

    Deprecated

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

  • Parameters

    • path: string
    • Optional tlsOptions: TlsOptions
      Optional
    • Optional port: number
      Optional
    • Optional host: string
      Optional
    • Optional cb: RequestListener<typeof IncomingMessage, typeof ServerResponse>
      Optional
    • Optional secretToken: string
      Optional

    Returns Telegraf<C>

  • Parameters

    • reason: string = 'unspecified'

    Returns void

  • You must call bot.telegram.setWebhook for this to work. You should probably use Telegraf.createWebhook instead.

    Parameters

    • path: string = '/'
    • opts: {
          secretToken?: string;
      } = {}
      • Optional secretToken?: string

    Returns ((req, res, next?) => Promise<void>)

      • (req, res, next?): Promise<void>
      • Parameters

        • req: IncomingMessage & {
              body?: Update;
          }
        • res: ServerResponse<IncomingMessage>
        • next: (() => void) = ...
            • (): void
            • Returns void

        Returns Promise<void>

  • 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>

  • 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>

  • 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 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>

Generated using TypeDoc