Reputation:
I am using MS bot framework and I am trying to build a bot that would handle dialogs that can branch instead of just a flat scenario.
For example, in the first message the bot asks user a question, and depending on the answer launches one of the three child dialogs, which, in turn, can launch their own child dialogs depending on user input.
So i'm looking for something like this:
if (userAnswer == "option 1") {
LaunchSupportDialog();
}
else {
LaunchNewOrderDialog();
}
The examples provided by Microsoft are either flat (e.g. a bot that can handle sandwich orders, without branches, executing each step in succession), or where the branching is done automatically by LUIS based on the user intent.
I am looking for something much less smart so it looks like I'm just missing some kind of method or class that would be able to do that.
The docs state:
Explicit management of the stack of active dialogs is possible through IDialogStack.Call and IDialogStack.Done, explicitly composing dialogs into a larger conversation. It is also possible to implicitly manage the stack of active dialogs through the fluent Chain methods.
but I didn't find any examples of how to create a new IDialogStack object, or how to explicitly call .Call() or .Done(), or use the Chain class methods for that.
Upvotes: 1
Views: 1458
Reputation: 777
One option is to use Chains which offer the Switch
construct for branching.
IDialog<string> MyDialog =
Chain
.PostToChain()
.Switch(
new Case<string, IDialog<string>>(userAnswer => userAnswer == "option 1", (ctx, _) => Option1Dialog),
Chain.Default<string, IDialog<string>>((ctx, _) => DefaultDialog))
.Unwrap()
.Select(dialogResult => $"The result is: {dialogResult}")
.PostToUser();
This example waits for a message from the user, starts a dialog depending on the message (Option1Dialog
or DefaultDialog
, both of type IDialog<string>
), transform the dialog result and sends it back to the user.
Please refer to this part of the documentation for more details (although, unfortunately, it doesn't have many examples).
Upvotes: 2