Ojas Maru
Ojas Maru

Reputation: 459

Multiple waterfall conversation in Microsoft Bot framework

Is it possible to have multiple waterfall conversation in Microsoft Bot framework?

I am having a Rootdialog (derived from ComponentDialog (WaterfallDialog)), which accepts users's initial input. I want to use this dialogue to initiate a login process to an external service. Once this login is successful, I would like to initiate a specific waterfall dialogue based on users initial input.

For example, User says

Flow1 --> Start Root dialogue (For login process) --> Start Flow1 (Waterfall) dialog

Flow2 --> Start Root dialogue (For login process) --> Start Flow2 (Waterfall) dialog

I tried doing this but the moment I call BeginDialogAsync from Root dialogue, it hangs

return await stepContext.BeginDialogAsync("flow1", null, cancellationToken);

Please let me know what am I missing here, Thanks in Advance

Upvotes: 2

Views: 1417

Answers (2)

Doug
Doug

Reputation: 11

I know this post is a little old but I don't see any other complete answers so here goes.

In reading the original question, I could see how you might want to implement this as separate dialogs that get launched from a main dialog, in which case you'd want to created separate ComponentDialogs that implement their own WaterfallDialog to solve the problem.

But, if you're asking if you can have multiple WaterfallDialogs within a single ComponentDialog, yes you certainly can. In order to do this, you must assign each WaterfallDialog an Id property value, by doing something like this:

var flow1steps= new WaterfallStep[] { step1, step2, step3 };
var flow2steps = new WaterfallStep[] { step1, step2, step3 };
var flow1Dialog= new WaterfallDialog(nameof(WaterfallDialog), flow1steps) { Id = "flow1" };
var flow2Dialog = new WaterfallDialog(nameof(WaterfallDialog), flow2steps) { Id = "flow2" };

In this scenario, if you wanted to start with "flow1Dialog" you would set the InitialDialogId in your constructor to "flow1Dialog" like this:

InitialDialogId = "flow1Dialog";

Then, when you're ready to redirect the dialog to "flow2", you can use flow2Dialog's WaterfallDialog.Id. For example, to redirect to flow2Dialog from any other step in your root dialog or flow1Dialog, do this:

return await stepContext.BeginDialogAsync("flow2");

BeingDialogAsync() vs ReplaceDialogAsync()

You could use BeginDialogAsync(), but unless you need control to eventually return to the originating dialog, that may result in dialog stack clutter that you don't want. Using ReplaceDialogAsync() replaces the current dialog on the stack with the new one, this can make it easier to manage looping and redirecting since the stack is not cluttered with old dialogs that you don't want to have to deal with at some point.

Upvotes: 0

ranusharao
ranusharao

Reputation: 1854

Yes, it is very much possible to have multiple waterfall conversations in bot framework. There is a concept of waterfall dialogs in bot framework v4, where a waterfall accepts a stack of functions that will be executed in sequence. Each step of the conversation is implemented as an asynchronous function that takes a waterfall step context (step) parameter. Each waterfall step can ask a question of the user and the user's response will be passed to the next step in the waterfall. You also have component dialogs which allows you to reuse dialog sets.

Refer to the multi-turn prompt sample, which uses a waterfall dialog, a few prompts, and a component dialog to create a simple interaction that asks the user a series of questions and the bot-authentication sample.

Hope this helps!!

Upvotes: 1

Related Questions