Dialogs are mainly used for conversational flow. So state has to be maintained for dialogs to know the details of the conversation. Dialogs state has to be maintained in the memory for the same reason.
Please find the below classes involved with dialog to get the properties,
- DialogSet – Collection of dialogs.
- DialogContext – Information about active dialogs.
- DialogInstance – Information about 1 Active dialog.
- DialogTurnResult – Status information about recent active dialog.
There are different types of dialogs, Refer to the below link for information about each dialog :
Let’s consider an example where we fill out basic details information in Teams. Follow the given steps:
- Create an Echo Bot as mentioned in our previous blog.
2. Install “Microsoft.Bot.Builder.Dialogs” from Nuget Package.
3. Include the following lines in the Configure Services function in Startup.cs
services.AddSingleton<IStorage, MemoryStorage>(); services.AddSingleton<UserState>(); services.AddSingleton<ConversationState>(); services.AddSingleton<UserProfileDialog>(); services.AddTransient<IBot, EchoBot<UserProfileDialog>>();
is the line which specifies about the dialog which is being called in Echo Bot.
4. Add classes UserProfileDialog and UserProfile to the project.
5. As mentioned in UserProfileDialog.cs, set of dialogs used in this scenario are given below.
AddDialog(new WaterfallDialog(nameof(WaterfallDialog), waterfallSteps)); AddDialog(new TextPrompt(nameof(TextPrompt))); AddDialog(new NumberPrompt<int>(nameof(NumberPrompt<int>), AgePromptValidatorAsync)); AddDialog(new ChoicePrompt(nameof(ChoicePrompt))); AddDialog(new ConfirmPrompt(nameof(ConfirmPrompt))); AddDialog(new AttachmentPrompt(nameof(AttachmentPrompt), PicturePromptValidatorAsync)).
You can specify which dialog to call with the following line:
InitialDialogId = nameof(WaterfallDialog);
The Waterfall Dialog is a type of dialog where a set of steps are called as mentioned in the waterfall Steps. After each step, the next step function will be called as specified in the Step order.
6. To manually go to Next Step, you can use the following line:
return await stepContext.NextAsync(<any value to be passed to the next step>, cancellationToken);
Upon successful execution of the program, the output will resemble the screenshots in ascending order.
Please find the sample in below repository.
Hope this helps in understanding conversational flow using dialogs.