在我的azure机器人中,我具有默认机器人“ DialogBot.cs”。我想在其OnMessageActivityAsync()方法中基于用户输入调用特定的瀑布。
但是,一旦我解析了输入,我将不知道如何触发特定的瀑布。可以说瀑布称为“ SpecificDialog”。我尝试过:
await Dialog.RunAsync(turnContext, ConversationState.CreateProperty<DialogState>(nameof(SpecificDialog)), cancellationToken)
;
但这不起作用。我该怎么办?
答案 0 :(得分:0)
我假设您正在使用其中一个示例。我将以CoreBot为基础回答问题。
您应该将Dialog.RunAsync()
调用的对话框视为所有其他对话框都从中分支并从中流动的“根”对话框或“父”对话框。要更改由此调用的对话框,请查看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>>();
要将其更改为MainDialog
以外的对话框,只需将其替换为适当的对话框即可。
进入根或父对话框后,您call another dialog with BeginDialogAsync()
:
stepContext.BeginDialogAsync(nameof(BookingDialog), new BookingDetails(), cancellationToken);
仅供参考:
这在Node中工作略有不同。在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);
您可以看到它调用了DialogAndWelcomeBot
,它扩展了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();
});
您没有没有以这种方式设置您的机器人,但是这是当前推荐的设计,如果您遵循此方法,则可以更轻松地实现我们的文档和示例。