TurnState class

Represents the turn state for a conversation. Turn state includes conversation state, user state, and temporary state. Provides methods to access, modify, and delete the state objects.

Properties

conversation

Gets the conversation state from the turn state.

isLoaded

Gets a value indicating whether the applications turn state has been loaded.

temp

Accessor for the temp state.

user

Accessor for the user state.

Methods

deleteConversationState()

Deletes the state object for the current conversation from storage.

deleteTempState()

Deletes the temp state object.

deleteUserState()

Deletes the state object for the current user from storage.

deleteValue(string)

Deletes a value from the memory.

getScope(string)

Gets a state scope by name.

getValue<TValue>(string)

Retrieves a value from the memory.

hasValue(string)

Checks if a value exists in the memory.

load(TurnContext, Storage)

Loads all of the state scopes for the current turn.

save(TurnContext, Storage)

Saves all of the state scopes for the current turn.

setValue(string, unknown)

Assigns a value to the memory.

Property Details

conversation

Gets the conversation state from the turn state.

TConversationState conversation

Property Value

TConversationState

The conversation state.

isLoaded

Gets a value indicating whether the applications turn state has been loaded.

boolean isLoaded

Property Value

boolean

True if the applications turn state has been loaded, false otherwise.

temp

Accessor for the temp state.

TTempState temp

Property Value

TTempState

The temp TurnState.

user

Accessor for the user state.

TUserState user

Property Value

TUserState

The user TurnState.

Method Details

deleteConversationState()

Deletes the state object for the current conversation from storage.

function deleteConversationState()

deleteTempState()

Deletes the temp state object.

function deleteTempState()

deleteUserState()

Deletes the state object for the current user from storage.

function deleteUserState()

deleteValue(string)

Deletes a value from the memory.

function deleteValue(path: string)

Parameters

path

string

Path to the value to delete in the form of [scope].property. If scope is omitted, the value is deleted from the temporary scope.

getScope(string)

Gets a state scope by name.

function getScope(scope: string): undefined | TurnStateEntry

Parameters

scope

string

Name of the state scope to return. (i.e. 'conversation', 'user', or 'temp')

Returns

undefined | TurnStateEntry

The state scope or undefined if not found.

getValue<TValue>(string)

Retrieves a value from the memory.

function getValue<TValue>(path: string): TValue

Parameters

path

string

Path to the value to retrieve in the form of [scope].property. If scope is omitted, the value is retrieved from the temporary scope.

Returns

TValue

The value or undefined if not found.

hasValue(string)

Checks if a value exists in the memory.

function hasValue(path: string): boolean

Parameters

path

string

Path to the value to check in the form of [scope].property. If scope is omitted, the value is checked in the temporary scope.

Returns

boolean

True if the value exists, false otherwise.

load(TurnContext, Storage)

Loads all of the state scopes for the current turn.

function load(context: TurnContext, storage?: Storage): Promise<boolean>

Parameters

context

TurnContext

Context for the current turn of conversation with the user.

storage

Storage

Optional. Storage provider to load state scopes from.

Returns

Promise<boolean>

True if the states needed to be loaded.

save(TurnContext, Storage)

Saves all of the state scopes for the current turn.

function save(context: TurnContext, storage?: Storage): Promise<void>

Parameters

context

TurnContext

Context for the current turn of conversation with the user.

storage

Storage

Optional. Storage provider to save state scopes to.

Returns

Promise<void>

setValue(string, unknown)

Assigns a value to the memory.

function setValue(path: string, value: unknown)

Parameters

path

string

Path to the value to assign in the form of [scope].property. If scope is omitted, the value is assigned to the temporary scope.

value

unknown

Value to assign.