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

    Class CommandHandler<C, R>

    Handler for Telegram bot commands (e.g. /start, /help).

    const startHandler = new CommandHandler("start", async (update, context) => {
    await context.bot.sendMessage({ chat_id: update.effective_chat!.id, text: "Hello!" });
    });

    Type Parameters

    Hierarchy (View Summary)

    Index
    • Creates a new CommandHandler.

      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

      • command: string | string[]

        A single command string (e.g. "start") or an array of aliases.

      • callback: HandlerCallback<C, R>

        Function invoked when the command matches.

      • Optionalfilters: BaseFilter

        Optional additional filter criteria.

      Returns CommandHandler<C, R>

      When command is empty or contains only whitespace.

    callback: HandlerCallback<C, R>

    The underlying callback function to invoke on match.

    commands: Set<string>

    Normalized set of command names that trigger this handler (without / or @botname).

    filters?: BaseFilter

    Optional secondary filter to apply before triggering.

    • Checks whether the update contains a matching bot command.

      Parameters

      • update: Update

        The update to test.

      Returns Promise<boolean>

      true if command matches, false otherwise.

    • Parses positional command arguments into context.args and executes callback.

      Parameters

      • update: Update

        The incoming update.

      • context: C

        Callback context instance.

      Returns Promise<R>

      Result from callback execution.