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

    Class BasePersistenceAbstract

    Base abstract persistence class that handles common serialization and key-value mapping.

    Extending this class allows writing new database drivers (PostgreSQL, Redis, MongoDB) with minimal boilerplate code.

    export class SimpleKvPersistence extends BasePersistence {
    private store = new Map<string, string>();
    protected async getRaw(key: string) { return this.store.get(key) ?? null; }
    protected async setRaw(key: string, val: string) { this.store.set(key, val); }
    protected async deleteRaw(key: string) { this.store.delete(key); }
    }

    Implements

    Index
    • Optional method to delete chat data for a specific chat ID.

      Parameters

      • chatId: string | number

        Telegram chat ID.

      Returns Promise<void>

    • Optional method to delete conversation state.

      Parameters

      • key: string

        Conversation key composite.

      Returns Promise<void>

    • Parameters

      • key: string

      Returns Promise<void>

    • Optional method to delete user data for a specific user ID.

      Parameters

      • userId: number

        Telegram user ID.

      Returns Promise<void>

    • Retrieves global bot data.

      Returns Promise<Record<string, unknown>>

      Bot data object.

    • Retrieves stored chat data for a specific chat ID.

      Parameters

      • chatId: string | number

        Telegram chat ID (number or string).

      Returns Promise<Record<string, unknown>>

      Chat data object (returns empty object if none found).

    • Retrieves all active conversation states.

      Returns Promise<Map<string, string | number>>

      A map of conversation keys to state values.

    • Parameters

      • key: string

      Returns Promise<string | null>

    • Retrieves stored user data for a specific user ID.

      Parameters

      • userId: number

        Telegram user ID.

      Returns Promise<Record<string, unknown>>

      User data object (returns empty object if none found).

    • Stores global bot data.

      Parameters

      • data: Record<string, unknown>

        Key-value map of global bot state.

      Returns Promise<void>

      Resolves when data is saved.

    • Stores chat data for a specific chat ID.

      Parameters

      • chatId: string | number

        Telegram chat ID (number or string).

      • data: Record<string, unknown>

        Key-value map of chat state.

      Returns Promise<void>

      Resolves when data is saved.

    • Parameters

      • key: string
      • value: string

      Returns Promise<void>

    • Stores user data for a specific user ID.

      Parameters

      • userId: number

        Telegram user ID.

      • data: Record<string, unknown>

        Key-value map of user state.

      Returns Promise<void>

      Resolves when data is saved.

    • Updates or saves the state for a specific conversation key.

      Parameters

      • key: string

        Conversation key composite (e.g. chat_id + user_id).

      • state: string | number

        Conversation state identifier or step number.

      Returns Promise<void>

      Resolves when state is updated.