Articles → MICROSOFT BOT FRAMEWORK → Waterfall Model In Microsoft Bot Framework
Waterfall Model In Microsoft Bot Framework
What Is A Waterfall Model?
Implementation
- Create a new class "RootDialog" that implements "ComponentDialog".
public class RootDialog : ComponentDialog{
}
- In "Startup.cs", add the following code.
services.AddSingleton<RootDialog>();
services.AddTransient<IBot, Karan_EchoBot.Bots.EchoBot<RootDialog>>();
- Change the definition of “EchoBot”.
public class EchoBot < T >: ActivityHandler where T: Microsoft.Bot.Builder.Dialogs.Dialog {
private IConfiguration _configuration;
private UserState _userState;
private ConversationState _conversationState;
private Microsoft.Bot.Builder.Dialogs.Dialog _dialog;
private IStatePropertyAccessor < UserData > _userData;
private IStatePropertyAccessor < ConversationData > _conversationData;
public EchoBot(IConfiguration configuration, UserState userState, ConversationState conversationState, T dialog) {
_configuration = configuration;
_userState = userState;
_conversationState = conversationState;
this._dialog = dialog;
_userData = userState.CreateProperty < UserData > ("UserData");
_conversationData = conversationState.CreateProperty < ConversationData > ("ConversationData");
}
}
- In the "OnMessageActivityAsync" method, call the "RootDialog" class.
protected override async Task OnMessageActivityAsync(ITurnContext < IMessageActivity > turnContext, CancellationToken cancellationToken) {
await _dialog.RunAsync(turnContext, _conversationState.CreateProperty <DialogState> ("DialogState"), cancellationToken);
}
- Implement a waterfall model in "RootDialog.cs".
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Karan_EchoBot.Dialog {
public class RootDialog: ComponentDialog {
public RootDialog(): base(nameof(RootDialog)) {
var steps = new WaterfallStep[] {
FirstStep,
SecondStep
};
AddDialog(new WaterfallDialog("WaterFallId", steps));
}
private async Task < DialogTurnResult > SecondStep(WaterfallStepContext stepContext, CancellationToken cancellationToken) {
await stepContext.Context.SendActivityAsync(MessageFactory.Text("This is the second message"), cancellationToken);
return await stepContext.EndDialogAsync(null);
}
private async Task < DialogTurnResult > FirstStep(WaterfallStepContext stepContext, CancellationToken cancellationToken) {
await stepContext.Context.SendActivityAsync(MessageFactory.Text("This is the first message"), cancellationToken);
return Microsoft.Bot.Builder.Dialogs.Dialog.EndOfTurn;
}
}
}
Output
Click to Enlarge