Class WebhookClient

Represents a client for handling Telegram updates using webhooks.

Constructors

Properties

isClosed: boolean

Indicates whether the webhook client is closed.

offset: number

The offset used to keep track of the latest updates.

webhookFilter: ((request: IncomingMessage & {
    body?: Update;
}, options: {
    path: string;
    secretToken?: string;
    token: string;
}) => boolean)

Filters incoming webhook requests to verify their authenticity.

Type declaration

    • (request, options): boolean
    • Parameters

      • request: IncomingMessage & {
            body?: Update;
        }

        The incoming request.

      • options: {
            path: string;
            secretToken?: string;
            token: string;
        }

        The options for filtering the request.

        • path: string
        • OptionalsecretToken?: string
        • token: string

      Returns boolean

      Whether the request is valid.

webhookServer?: Server<typeof IncomingMessage, typeof ServerResponse> | Server<typeof IncomingMessage, typeof ServerResponse>

The HTTP or HTTPS server for handling webhook requests.

Methods

  • Closes the webhook server.

    Returns boolean

    The closed state of the webhook client.

  • Creates a callback function for handling webhook requests.

    Parameters

    • OptionalrequestCallback: RequestListener

      The callback function to handle requests.

    • Optionaloptions: {
          path?: string;
          secretToken?: string;
      }

      The options for creating the webhook callback.

      • Optionalpath?: string
      • OptionalsecretToken?: string

    Returns Promise<RequestListener | ((request: IncomingMessage & {
        body?: Update;
    }, response: ServerResponse<IncomingMessage>) => void)>

    The created callback function.

  • Starts the webhook server to receive updates from Telegram.

    Parameters

    • Optionalpath: string

      The path for the webhook endpoint.

    • OptionalsecretToken: string

      The secret token for verifying webhook requests.

    • Optionaloptions: {
          host?: string;
          port?: number;
          requestCallback?: RequestListener;
          tlsOptions?: TlsOptions;
      }

      The options for the webhook server.

      • Optionalhost?: string
      • Optionalport?: number
      • OptionalrequestCallback?: RequestListener
      • OptionaltlsOptions?: TlsOptions

    Returns Promise<void>