In my azure bot, I have the default bot "DialogBot.cs". In its OnMessageActivityAsync() method, I am wanting to call a specific waterfall based on user input.
Once I parse the input however, I don't know how to trigger the specific waterfall. Lets say the waterfall is called 'SpecificDialog'. I tried this:
await Dialog.RunAsync(turnContext, ConversationState.CreateProperty<DialogState>(nameof(SpecificDialog)), cancellationToken)
;
but that doesn't work. How would I accomplish this?
I'm assuming you're working with one of the Samples. I'll base my answer off of CoreBot.
You should think of the dialog called by Dialog.RunAsync()
as the "root" or "parent" dialog from which all other dialogs branch and flow from. To change which dialog is called by this, look in Startup.cs
for a line that looks like this:
// Create the bot as a transient. In this case the ASP Controller is expecting an IBot.
services.AddTransient<IBot, DialogAndWelcomeBot<MainDialog>>();
To change that to a dialog other than MainDialog
, you just replace it with the appropriate dialog.
Once you're in your root or parent dialog, you call another dialog with BeginDialogAsync()
:
stepContext.BeginDialogAsync(nameof(BookingDialog), new BookingDetails(), cancellationToken);
FYI to others:
This works just a little bit different in Node. In CoreBot, the MainDialog is passed to the bot in index.js
:
const dialog = new MainDialog(luisRecognizer, bookingDialog);
const bot = new DialogAndWelcomeBot(conversationState, userState, dialog);
[...]
// Listen for incoming activities and route them to your bot main dialog.
server.post('/api/messages', (req, res) => {
// Route received a request to adapter for processing
adapter.processActivity(req, res, async (turnContext) => {
// route to bot activity handler.
await bot.run(turnContext);
You can see that it calls DialogAndWelcomeBot
, which extends DialogBot, which calls MainDialog
on every message:
this.onMessage(async (context, next) => {
console.log('Running dialog with Message Activity.');
// Run the Dialog with the new message Activity.
await this.dialog.run(context, this.dialogState);
// By calling next() you ensure that the next BotHandler is run.
await next();
});
You don't have to set your bot up this way, but it's the currently recommended design and you'll have an easier time implementing our docs and samples if you follow this.