DialogStateManager class

The DialogStateManager manages memory scopes and path resolvers.

Remarks

MemoryScopes are named root level objects, which can exist either in the dialog context or off of turn state. Path resolvers allow for shortcut behavior for mapping things like $foo -> dialog.foo

Constructors

DialogStateManager(DialogContext, DialogStateManagerConfiguration)

Initializes a new instance of the DialogStateManager class.

Properties

configuration

Gets or sets the configured path resolvers and memory scopes for the dialog state manager.

Methods

anyPathChanged(number, string[])

Check to see if any path has changed since watermark.

deleteScopesMemory(string)

Deletes all of the backing memory for a given scope.

deleteValue(string)

Delete property from memory

getMemorySnapshot()

Gets all memory scopes suitable for logging.

getValue<T>(string, T | () => T)

Get the value from memory using path expression.

loadAllScopes()

Ensures that all memory scopes have been loaded for the current turn.

parsePath(string, boolean)

Normalizes the path segments of a passed in path.

saveAllChanges()

Saves any changes made to memory scopes.

setValue(string, any)

Set memory to value.

trackPaths(string[])

Track when specific paths are changed.

transformPath(string)

Transform the path using the registered path transformers.

version()

Gets the version number.

Constructor Details

DialogStateManager(DialogContext, DialogStateManagerConfiguration)

Initializes a new instance of the DialogStateManager class.

new DialogStateManager(dc: DialogContext, configuration?: DialogStateManagerConfiguration)

Parameters

dc
DialogContext

The dialog context for the current turn of the conversation.

configuration
DialogStateManagerConfiguration

Configuration for the dialog state manager.

Property Details

configuration

Gets or sets the configured path resolvers and memory scopes for the dialog state manager.

configuration: DialogStateManagerConfiguration

Property Value

Remarks

There is a single set of configuration information for a given chain of dialog contexts. Assigning a new configuration to any DialogStateManager within the chain will update the configuration for the entire chain.

Method Details

anyPathChanged(number, string[])

Check to see if any path has changed since watermark.

function anyPathChanged(counter: number, paths: string[]): boolean

Parameters

counter

number

Time counter to compare to.

paths

string[]

Paths from trackPaths() to check.

Returns

boolean

True if any path has changed since counter.

deleteScopesMemory(string)

Deletes all of the backing memory for a given scope.

function deleteScopesMemory(name: string): Promise<void>

Parameters

name

string

Name of the scope.

Returns

Promise<void>

deleteValue(string)

Delete property from memory

function deleteValue(pathExpression: string)

Parameters

pathExpression

string

The leaf property to remove.

getMemorySnapshot()

Gets all memory scopes suitable for logging.

function getMemorySnapshot(): object

Returns

object

Object which represents all memory scopes.

getValue<T>(string, T | () => T)

Get the value from memory using path expression.

function getValue<T>(pathExpression: string, defaultValue?: T | () => T): T

Parameters

pathExpression

string

Path expression to use.

defaultValue

T | () => T

(Optional) default value to use if the path isn't found. May be a function that returns the default value to use.

Returns

T

The found value or undefined if not found and no defaultValue specified.

Remarks

This always returns a CLONE of the memory, any modifications to the result will not affect memory.

loadAllScopes()

Ensures that all memory scopes have been loaded for the current turn.

function loadAllScopes(): Promise<void>

Returns

Promise<void>

Remarks

This should be called at the beginning of the turn.

parsePath(string, boolean)

Normalizes the path segments of a passed in path.

function parsePath(pathExpression: string, allowNestedPaths?: boolean): string | number[]

Parameters

pathExpression

string

The path to normalize.

allowNestedPaths

boolean

Optional. If false then detection of a nested path will cause an empty path to be returned. Defaults to 'true'.

Returns

string | number[]

The normalized path.

Remarks

A path of profile.address[0] will be normalized to profile.address.0.

saveAllChanges()

Saves any changes made to memory scopes.

function saveAllChanges(): Promise<void>

Returns

Promise<void>

Remarks

This should be called at the end of the turn.

setValue(string, any)

Set memory to value.

function setValue(pathExpression: string, value: any)

Parameters

pathExpression

string

Path to memory.

value

any

Value to set.

trackPaths(string[])

Track when specific paths are changed.

function trackPaths(paths: string[]): string[]

Parameters

paths

string[]

Paths to track.

Returns

string[]

Normalized paths to pass to anyPathChanged().

transformPath(string)

Transform the path using the registered path transformers.

function transformPath(pathExpression: string): string

Parameters

pathExpression

string

The path to transform.

Returns

string

The transformed path.

version()

Gets the version number.

function version(): string

Returns

string

A string with the version number.