botas-core
    Preparing search index...

    Interface TurnState

    State container for a single turn, providing scoped access to conversation, user, and temporary state.

    bot.on('message', async (ctx) => {
    const count = ctx.state?.conversation.get<number>('count') ?? 0
    ctx.state?.conversation.set('count', count + 1)
    await ctx.send(`Turn ${count + 1}`)
    })
    interface TurnState {
        conversation: StateScope;
        user: StateScope;
        temp: StateScope;
        getValue<T = unknown>(path: string): T | undefined;
        setValue<T>(path: string, value: T): void;
        hasValue(path: string): boolean;
        deleteValue(path: string): void;
        deleteConversationState(): void;
        deleteUserState(): void;
        deleteTempState(): void;
    }

    Implemented by

    Index

    Properties

    conversation: StateScope

    Conversation-scoped state (persisted per conversation).

    User-scoped state (persisted per user across conversations).

    Temporary state for the current turn (not persisted).

    Methods

    • Get a value by path. Path format: "[scope].property" or "property" (defaults to temp).

      Type Parameters

      • T = unknown

      Parameters

      • path: string

      Returns T | undefined

      ctx.state?.getValue<number>('conversation.count')
      ctx.state?.getValue<string>('input') // defaults to temp scope
    • Set a value by path. Path format: "[scope].property" or "property" (defaults to temp).

      Type Parameters

      • T

      Parameters

      • path: string
      • value: T

      Returns void

      ctx.state?.setValue('conversation.count', 42)
      ctx.state?.setValue('input', 'hello') // defaults to temp scope