Documentation - v1.2.0-alpha.3
    Preparing search index...

    Class TurnState<TConversationState, TUserState>

    Base class defining a collection of turn state scopes.

    Developers can create a derived class that extends TurnState to add additional state scopes.

    class MyTurnState extends TurnState {
    protected async onComputeStorageKeys(context) {
    const keys = await super.onComputeStorageKeys(context);
    keys['myScope'] = `myScopeKey`;
    return keys;
    }

    public get myScope() {
    const scope = this.getScope('myScope');
    if (!scope) {
    throw new Error(`MyTurnState hasn't been loaded. Call load() first.`);
    }
    return scope.value;
    }

    public set myScope(value) {
    const scope = this.getScope('myScope');
    if (!scope) {
    throw new Error(`MyTurnState hasn't been loaded. Call load() first.`);
    }
    scope.replace(value);
    }
    }

    Type Parameters

    Implements

    Index

    Constructors

    Accessors

    Methods

    • Marks the conversation state for deletion.

      Returns void

      Error if state hasn't been loaded

      The state will be deleted from storage on the next call to save().

    • Marks the user state for deletion.

      Returns void

      Error if state hasn't been loaded

      The state will be deleted from storage on the next call to save().

    • Deletes a value from state by dot-notation path.

      Parameters

      • path: string

        The path to the value to delete

      Returns void

      Format: "scope.property" or just "property" (defaults to temp scope) The temp scope is internal-only, not persisted to storage, and exists only for the current turn.

    • Gets a value from state by dot-notation path.

      Type Parameters

      • TValue = unknown

        The type of the value to retrieve

      Parameters

      • path: string

        The path to the value

      Returns TValue

      The value at the specified path

      Format: "scope.property" or just "property" (defaults to temp scope)

    • Checks if a value exists in state by dot-notation path.

      Parameters

      • path: string

        The path to check

      Returns boolean

      True if the value exists, false otherwise

      Format: "scope.property" or just "property" (defaults to temp scope)

    • Loads state from storage into memory.

      Parameters

      • context: TurnContext

        The turn context

      • Optionalstorage: Storage

        Optional storage provider (if not provided, state will be in-memory only)

      • force: boolean = false

        If true, forces a reload from storage even if state is already loaded

      Returns Promise<boolean>

      Promise that resolves to true if state was loaded, false if it was already loaded

    • Protected

      Computes the storage keys for each scope based on the turn context.

      Parameters

      Returns Promise<Record<string, string>>

      Promise that resolves to a dictionary of scope names to storage keys

      Override this method in derived classes to add or modify storage keys.

    • Saves state changes to storage.

      Parameters

      • context: TurnContext

        The turn context

      • Optionalstorage: Storage

        Optional storage provider (if not provided, state changes won't be persisted)

      Returns Promise<void>

      Promise that resolves when the save operation is complete

      Error if state hasn't been loaded

      Only changed scopes will be persisted.

    • Sets a value in state by dot-notation path.

      Parameters

      • path: string

        The path to set

      • value: unknown

        The value to set

      Returns void

      Format: "scope.property" or just "property" (defaults to temp scope)