Articles → MICROSOFT BOT FRAMEWORK → Waterfall model in Microsoft Bot Framework

Waterfall model in Microsoft Bot Framework






What is a waterfall model?





Implementation






public class RootDialog : ComponentDialog{
}




services.AddSingleton<RootDialog>();
services.AddTransient<IBot, Karan_EchoBot.Bots.EchoBot<RootDialog>>();




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");
  }
}




protected override async Task OnMessageActivityAsync(ITurnContext < IMessageActivity > turnContext, CancellationToken cancellationToken) {
  await _dialog.RunAsync(turnContext, _conversationState.CreateProperty <DialogState> ("DialogState"), cancellationToken);
}




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


Picture showing the output of waterfall model in microsoft bot framework

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Sunday, December 27, 2020

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250