DialogSet class
A related set of dialogs that can all call each other.
Remarks
The constructor for the dialog set should be passed a state property that will be used to persist the dialog stack for the set:
const { ConversationState, MemoryStorage, ActivityTypes } = require('botbuilder');
const { DialogSet, Dialog, DialogTurnStatus } = require('botbuilder-dialogs');
const convoState = new ConversationState(new MemoryStorage());
const dialogState = convoState.createProperty('dialogState');
const dialogs = new DialogSet(dialogState);
The bot can add dialogs or prompts to the set using the add() method:
class GreetingDialog extends Dialog {
async beginDialog(dc, options) {
await dc.context.sendActivity(`Hi! I'm a bot.`);
return await dc.endDialog();
}
}
dialogs.add(new GreetingDialog('greeting'));
To interact with the sets dialogs you can call createContext() with the
current TurnContext
. That will create a DialogContext
that can be used to start or continue
execution of the sets dialogs:
// Create DialogContext for the current turn
const dc = await dialogs.createContext(turnContext);
// Try to continue executing an active multi-turn dialog
const result = await dc.continueDialog();
// Send greeting if no other dialogs active
if (result.status == DialogTurnStatus.empty && dc.context.activity.type == ActivityTypes.Message) {
await dc.beginDialog('greeting');
}
Constructors
Dialog |
Creates a new DialogSet instance. |
Properties
telemetry |
Set the telemetry client for this dialog set and apply it to all current dialogs. Set the telemetry client for this dialog set and apply it to all current dialogs. Future dialogs added to the set will also inherit this client. |
Methods
add<T>(T) | Adds a new dialog or prompt to the set. |
create |
Creates a dialog context which can be used to work with the dialogs in the set. |
find(string) | Finds a dialog that was previously added to the set using add(). |
get |
Gets the Dialogs of the set. |
get |
Returns a 32-bit hash of the all the |
Constructor Details
DialogSet(StatePropertyAccessor<DialogState>)
Creates a new DialogSet instance.
new DialogSet(dialogState?: StatePropertyAccessor<DialogState>)
Parameters
- dialogState
-
StatePropertyAccessor<DialogState>
(Optional) state property used to persist the sets dialog stack.
Remarks
If the dialogState
property is not passed in, calls to createContext()
will return an error. You will need to create a DialogContext
for the set manually and
pass in your own state object for persisting the sets dialog stack:
const dc = new DialogContext(dialogs, turnContext, state);
Property Details
telemetryClient
Set the telemetry client for this dialog set and apply it to all current dialogs. Set the telemetry client for this dialog set and apply it to all current dialogs. Future dialogs added to the set will also inherit this client.
BotTelemetryClient telemetryClient
Property Value
BotTelemetryClient
The BotTelemetryClient to use for logging.
Method Details
add<T>(T)
Adds a new dialog or prompt to the set.
function add<T>(dialog: T): this
Parameters
- dialog
-
T
The dialog or prompt to add. If a telemetryClient is present on the dialog set, it will be added to each dialog.
Returns
this
The dialog set after the operation is complete.
Remarks
If the Dialog.id
being added already exists in the set, the dialogs id will be updated to
include a suffix which makes it unique. So adding 2 dialogs named "duplicate" to the set
would result in the first one having an id of "duplicate" and the second one having an id
of "duplicate2".
createContext(TurnContext)
Creates a dialog context which can be used to work with the dialogs in the set.
function createContext(context: TurnContext): Promise<DialogContext>
Parameters
- context
-
TurnContext
Context for the current turn of conversation with the user.
Returns
Promise<DialogContext>
A promise representing the asynchronous operation.
find(string)
Finds a dialog that was previously added to the set using add().
function find(dialogId: string): Dialog | undefined
Parameters
- dialogId
-
string
ID of the dialog or prompt to lookup.
Returns
Dialog | undefined
The dialog if found; otherwise undefined.
Remarks
This example finds a dialog named "greeting":
const dialog = dialogs.find('greeting');
getDialogs()
getVersion()
Returns a 32-bit hash of the all the Dialog.version
values in the set.
function getVersion(): string
Returns
string
A version that will change when any of the child dialogs version changes.
Remarks
This hash is persisted to state storage and used to detect changes to a dialog set.