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

    Class ConversationHandler<C>

    Manages multi-step conversational flows and state transitions.

    const convHandler = new ConversationHandler({
    entry_points: [new CommandHandler("start", startCallback)],
    states: {
    1: [new MessageHandler(filters.TEXT, nameCallback)],
    2: [new MessageHandler(filters.PHOTO, photoCallback)],
    },
    fallbacks: [new CommandHandler("cancel", cancelCallback)],
    });
    app.addHandler(convHandler);

    Type Parameters

    Hierarchy (View Summary)

    Index
    allow_reentry: boolean

    Whether to allow re-entering via entry_points while active.

    callback: HandlerCallback<C, any>

    The underlying callback function to invoke on match.

    conversations: Map<string, string | number> = ...

    In-memory storage for conversations: key -> state

    Readonlyentry_points

    entry_points: BaseHandler<C, any>[]

    Handlers that initiate this conversation.

    fallbacks: BaseHandler<C, any>[]

    Fallback handlers when state handlers do not match or when cancelling.

    map_to_parent?: Record<string | number, string | number>

    Parent state transition mappings for nested conversation handlers.

    name?: string

    Optional name identifying this conversation in persistence.

    per_chat: boolean

    Whether conversation is tracked per chat.

    per_message: boolean

    Whether conversation is tracked per message.

    per_user: boolean

    Whether conversation is tracked per user.

    persistent: boolean

    Whether state should be saved to persistence.

    states: Map<string | number, BaseHandler<C, any>[]>

    Handlers indexed by state identifier.

    END: number = -1

    Special state indicating that the conversation has ended.

    TIMEOUT: number = -2

    Special state indicating that the conversation timed out.

    • Checks whether the update matches an entry point, current state handler, or fallback.

      Parameters

      • update: Update

        Incoming Telegram update.

      Returns Promise<boolean>

      True if a handler matches.

    • Dispatches the update to the matched handler and updates conversation state.

      Parameters

      • update: Update

        Incoming Telegram update.

      • context: C

        Callback context for this update.

      Returns Promise<string | number | undefined>

      The next state (or ConversationHandler.END/ConversationHandler.TIMEOUT) returned by the matched handler callback.