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

    Interface StatePropertyAccessor<T>

    Interface for accessing a property in state storage with type safety.

    This interface defines standard methods for working with persisted state properties, allowing property access with strong typing to reduce errors when working with complex state objects.

    interface StatePropertyAccessor<T = any> {
        delete(context: TurnContext): Promise<void>;
        get(context: TurnContext): Promise<T | undefined>;
        get(context: TurnContext, defaultValue: T): Promise<T>;
        set(context: TurnContext, value: T): Promise<void>;
    }

    Type Parameters

    • T = any

      The type of the property being accessed

    Implemented by

    Index

    Methods

    Methods

    • Reads a persisted property from its backing storage object.

      Parameters

      • context: TurnContext

        Context for the current turn of conversation with the user.

      Returns Promise<T | undefined>

      The properties backing storage object SHOULD be loaded into memory on first access.

      If the property does not currently exist on the storage object and a defaultValue has been specified, a clone of the defaultValue SHOULD be copied to the storage object. If a defaultValue has not been specified then a value of undefined SHOULD be returned.

      const value = await myProperty.get(context, { count: 0 });
      
    • Reads a persisted property from its backing storage object.

      Parameters

      • context: TurnContext

        Context for the current turn of conversation with the user.

      • defaultValue: T

        (Optional) default value to copy to the backing storage object if the property isn't found.

      Returns Promise<T>

    • Assigns a new value to the properties backing storage object.

      Parameters

      • context: TurnContext

        Context for the current turn of conversation with the user.

      • value: T

        Value to assign.

      Returns Promise<void>

      The properties backing storage object SHOULD be loaded into memory on first access.

      Depending on the state systems implementation, an additional step may be required to persist the actual changes to disk.

      await myProperty.set(context, value);