Share via


ComponentDialog class

Base class for a dialog that contains other child dialogs.

Extends

Remarks

Component dialogs let you break your agent's logic up into components that can themselves be added as a dialog to another ComponentDialog or DialogSet. Components can also be exported as part of a node package and used within other agents.

Constructors

ComponentDialog<O>(string)

Creates a new instance of the Dialog class.

Properties

id

Unique ID of the dialog.

Inherited Properties

dialogs

The containers dialog set.

EndOfTurn

Gets a default end-of-turn result.

Methods

addDialog(Dialog<{}>)

Adds a child Dialog or prompt to the components internal DialogSet.

beginDialog(DialogContext, O)

Called when the dialog is started and pushed onto the parent's dialog stack. By default, this calls the Dialog.BeginDialogAsync(DialogContext, object, CancellationToken) method of the component dialog's initial dialog, as defined by InitialDialogId. Override this method in a derived class to implement interrupt logic.

continueDialog(DialogContext)

Called when the dialog is continued, where it is the active dialog and the user replies with a new Activity. If this method is not overridden, the dialog automatically ends when the user replies.

createChildContext(DialogContext)

Creates the inner dialog context

endDialog(TurnContext, DialogInstance<any>, DialogReason)

Called when the Dialog is ending.

repromptDialog(TurnContext, DialogInstance<any>)

Called when the dialog should re-prompt the user for input.

resumeDialog(DialogContext, DialogReason, any)

Called when a child dialog on the parent's dialog stack completed this turn, returning control to this dialog component.

Inherited Methods

configure(Record<string, unknown>)

Fluent method for configuring the object.

findDialog(string)

Finds a child dialog that was previously added to the container.

getConverter(string)

Gets the converter for the selector configuration. *

getVersion()

An encoded string used to aid in the detection of agent changes on re-deployment.

onDialogEvent(DialogContext, DialogEvent)

Called when an event has been raised, using DialogContext.emitEvent(), by either the current dialog or a dialog that the current dialog started.

Constructor Details

ComponentDialog<O>(string)

Creates a new instance of the Dialog class.

new ComponentDialog(dialogId?: string)

Parameters

dialogId

string

Optional. unique ID of the dialog.

Property Details

id

Unique ID of the dialog.

string id

Property Value

string

The Id for the dialog.

Inherited Property Details

dialogs

The containers dialog set.

dialogs: DialogSet

Property Value

Inherited From DialogContainer.dialogs

EndOfTurn

Gets a default end-of-turn result.

static EndOfTurn: DialogTurnResult<any>

Property Value

Remarks

This result indicates that a dialog (or a logical step within a dialog) has completed processing for the current turn, is still active, and is waiting for more input.

Inherited From DialogContainer.EndOfTurn

Method Details

addDialog(Dialog<{}>)

Adds a child Dialog or prompt to the components internal DialogSet.

function addDialog(dialog: Dialog<{}>): ComponentDialog<O>

Parameters

dialog

Dialog<{}>

The child Dialog or prompt to add.

Returns

The ComponentDialog after the operation is complete.

Remarks

The Dialog.id of the first child added to the component will be assigned to the initialDialogId property.

beginDialog(DialogContext, O)

Called when the dialog is started and pushed onto the parent's dialog stack. By default, this calls the Dialog.BeginDialogAsync(DialogContext, object, CancellationToken) method of the component dialog's initial dialog, as defined by InitialDialogId. Override this method in a derived class to implement interrupt logic.

function beginDialog(outerDialogContext: DialogContext, options?: O): Promise<DialogTurnResult<any>>

Parameters

outerDialogContext
DialogContext

The parent DialogContext for the current turn of conversation.

options

O

Optional, initial information to pass to the dialog.

Returns

Promise<DialogTurnResult<any>>

A Promise representing the asynchronous operation.

Remarks

If the task is successful, the result indicates whether the dialog is still active after the turn has been processed by the dialog.

continueDialog(DialogContext)

Called when the dialog is continued, where it is the active dialog and the user replies with a new Activity. If this method is not overridden, the dialog automatically ends when the user replies.

function continueDialog(outerDialogContext: DialogContext): Promise<DialogTurnResult<any>>

Parameters

outerDialogContext
DialogContext

The parent DialogContext for the current turn of conversation.

Returns

Promise<DialogTurnResult<any>>

A Promise representing the asynchronous operation.

Remarks

If the task is successful, the result indicates whether the dialog is still active after the turn has been processed by the dialog. The result may also contain a return value.

createChildContext(DialogContext)

Creates the inner dialog context

function createChildContext(outerDialogContext: DialogContext): DialogContext

Parameters

outerDialogContext
DialogContext

the outer dialog context

Returns

The created Dialog Context.

endDialog(TurnContext, DialogInstance<any>, DialogReason)

Called when the Dialog is ending.

function endDialog(context: TurnContext, instance: DialogInstance<any>, reason: DialogReason): Promise<void>

Parameters

context
TurnContext

The TurnContext object for this turn.

instance

DialogInstance<any>

State information associated with the instance of this component Dialog on its parent's dialog stack.

reason
DialogReason

Reason why the Dialog ended.

Returns

Promise<void>

A Promise representing the asynchronous operation.

Remarks

When this method is called from the parent dialog's context, the component Dialog cancels all of the dialogs on its inner dialog stack before ending.

repromptDialog(TurnContext, DialogInstance<any>)

Called when the dialog should re-prompt the user for input.

function repromptDialog(context: TurnContext, instance: DialogInstance<any>): Promise<void>

Parameters

context
TurnContext

The TurnContext object for this turn.

instance

DialogInstance<any>

State information for this dialog.

Returns

Promise<void>

A Promise representing the asynchronous operation.

resumeDialog(DialogContext, DialogReason, any)

Called when a child dialog on the parent's dialog stack completed this turn, returning control to this dialog component.

function resumeDialog(outerDialogContext: DialogContext, _reason: DialogReason, _result?: any): Promise<DialogTurnResult<any>>

Parameters

outerDialogContext
DialogContext

The DialogContext for the current turn of conversation.

_reason
DialogReason

Reason why the dialog resumed.

_result

any

Optional, value returned from the dialog that was called. The type of the value returned is dependent on the child dialog.

Returns

Promise<DialogTurnResult<any>>

A Promise representing the asynchronous operation.

Remarks

If the task is successful, the result indicates whether this dialog is still active after this dialog turn has been processed. Generally, the child dialog was started with a call to beginDialog(DialogContext, object) in the parent's context. However, if the DialogContext.replaceDialog(string, object) method is called, the logical child dialog may be different than the original. If this method is not overridden, the dialog automatically calls its RepromptDialog(ITurnContext, DialogInstance) when the user replies.

Inherited Method Details

configure(Record<string, unknown>)

Fluent method for configuring the object.

function configure(config: Record<string, unknown>): ComponentDialog<O>

Parameters

config

Record<string, unknown>

Configuration settings to apply.

Returns

The Configurable after the operation is complete.

Inherited From DialogContainer.configure

findDialog(string)

Finds a child dialog that was previously added to the container.

function findDialog(dialogId: string): undefined | Dialog<{}>

Parameters

dialogId

string

ID of the dialog to lookup.

Returns

undefined | Dialog<{}>

The Dialog if found; otherwise null.

Inherited From DialogContainer.findDialog

getConverter(string)

Gets the converter for the selector configuration. *

function getConverter(_property: string): Converter<unknown, unknown> | ConverterFactory<unknown, unknown>

Parameters

_property

string

The key of the conditional selector configuration. *

Returns

Converter<unknown, unknown> | ConverterFactory<unknown, unknown>

The converter for the selector configuration.

Inherited From DialogContainer.getConverter

getVersion()

An encoded string used to aid in the detection of agent changes on re-deployment.

function getVersion(): string

Returns

string

Unique string which should only change when dialog has changed in a way that should restart the dialog.

Remarks

This defaults to returning the dialog's id but can be overridden to provide more precise change detection logic. Any dialog on the stack that has its version change will result in a versionChanged event will be raised. If this event is not handled by the agent, an error will be thrown resulting in the agent error handler logic being run.

Returning an empty string will disable version tracking for the component all together.

Inherited From DialogContainer.getVersion

onDialogEvent(DialogContext, DialogEvent)

Called when an event has been raised, using DialogContext.emitEvent(), by either the current dialog or a dialog that the current dialog started.

function onDialogEvent(dialogContext: DialogContext, event: DialogEvent): Promise<boolean>

Parameters

dialogContext
DialogContext

The dialog context for the current turn of conversation.

event
DialogEvent

The event being raised.

Returns

Promise<boolean>

True if the event is handled by the current dialog and bubbling should stop.

Inherited From DialogContainer.onDialogEvent