telebot-ts API Documentation - v1.0.0
    Preparing search index...

    Class CallbackQueryHandler<C, R>

    Handler for button clicks and callback queries from inline keyboards.

    const clickHandler = new CallbackQueryHandler(/^btn_/, async (update, context) => {
    await context.bot.answerCallbackQuery({ callback_query_id: update.callback_query!.id });
    });

    Type Parameters

    Hierarchy (View Summary)

    Index
    • Creates a new CallbackQueryHandler.

      Type Parameters

      • C extends CallbackContext<
            Record<string, unknown>,
            Record<string, unknown>,
            Record<string, unknown>,
        > = CallbackContext<
            Record<string, unknown>,
            Record<string, unknown>,
            Record<string, unknown>,
        >

        Type of the callback context.

      • R = unknown

        Return value type.

      Parameters

      • callbackOrPattern:
            | string
            | RegExp
            | HandlerCallback<C, R>
            | ((data: string) => boolean)
            | null
            | undefined

        The callback function, or (when callbackOrPattern2 is the callback) a string/RegExp pattern matched against callback_data.

      • OptionalcallbackOrPattern2: string | RegExp | HandlerCallback<C, R> | ((data: string) => boolean) | null

        The pattern (string, RegExp, or predicate function) matched against callback_data, or (when callbackOrPattern is the pattern) the callback.

      Returns CallbackQueryHandler<C, R>

      When only the callback is given, pass it alone. When a pattern is also given, the callback must be the first argument and the pattern (string, RegExp, or predicate function) the second, e.g. new CallbackQueryHandler(callback, /^btn_/).

    callback: HandlerCallback<C, R>

    The underlying callback function to invoke on match.

    pattern?: string | RegExp | ((data: string) => boolean)

    Optional pattern or predicate string/regex matching callback_data.

    • Checks whether the update contains a matching callback_query and evaluates its data against the pattern.

      Parameters

      • update: Update

        The update to test.

      Returns Promise<boolean>

      true if the callback query matches the configured pattern or predicate.

    • Populates context.matches if using a RegExp pattern and executes the callback.

      Parameters

      • update: Update

        The incoming update.

      • context: C

        Callback context instance.

      Returns Promise<R>

      Result from callback execution.