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

    Class TypeHandler<C, R>

    Handler that matches updates based on an arbitrary type predicate function.

    const customTypeHandler = new TypeHandler(
    (update) => Boolean(update.message_reaction),
    async (update, context) => { console.log("Reaction update received!"); }
    );

    Type Parameters

    Hierarchy (View Summary)

    Index
    • Constructs a new TypeHandler.

      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

      • typePredicate: (update: RawUpdate | Update) => boolean | Promise<boolean>

        Function that evaluates whether an update matches.

      • callback: HandlerCallback<C, R>

        Function invoked on match.

      Returns TypeHandler<C, R>

    callback: HandlerCallback<C, R>

    The underlying callback function to invoke on match.

    typePredicate: (update: RawUpdate | Update) => boolean | Promise<boolean>

    The custom type predicate function.

    • Evaluates the type predicate against the incoming update.

      Parameters

      • update: Update

        Incoming Telegram update.

      Returns Promise<boolean>

      true if the type predicate is satisfied.

    • Executes the registered handler callback with the given update and context.

      Parameters

      • update: Update

        The Telegram update to process.

      • context: C

        Callback context instance.

      Returns Promise<R>

      The value returned by the callback function.