StatePropertyAccessor interface

Defines methods for accessing a state property created in a BotState object.

Remarks

To create a state property in a state management objet, use the createProperty<T> method.

Methods

delete(TurnContext)

Deletes the persisted property from its backing storage object.

get(TurnContext)

Reads a persisted property from its backing storage object.

get(TurnContext, T)
set(TurnContext, T)

Assigns a new value to the properties backing storage object.

Method Details

delete(TurnContext)

Deletes the persisted property from its backing storage object.

function delete(context: TurnContext): Promise<void>

Parameters

context
TurnContext

Context for the current turn of conversation with the user.

Returns

Promise<void>

Remarks

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

await myProperty.delete(context);

get(TurnContext)

Reads a persisted property from its backing storage object.

function get(context: TurnContext): Promise<T | undefined>

Parameters

context
TurnContext

Context for the current turn of conversation with the user.

Returns

Promise<T | undefined>

Remarks

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 });

get(TurnContext, T)

function get(context: TurnContext, defaultValue: T): Promise<T>

Parameters

context
TurnContext
defaultValue

T

Returns

Promise<T>

set(TurnContext, T)

Assigns a new value to the properties backing storage object.

function set(context: TurnContext, value: T): Promise<void>

Parameters

context
TurnContext

Context for the current turn of conversation with the user.

value

T

Value to assign.

Returns

Promise<void>

Remarks

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);