在我的天蓝色机器人中,我有默认的bot "DialogBot.cs“。在它的OnMessageActivityAsync()方法中,我想根据用户输入调用特定的瀑布。
但是,一旦解析了输入,我就不知道如何触发特定的瀑布。让我们说,瀑布被称为“指定对话框”。我试过这个:
await Dialog.RunAsync(turnContext, ConversationState.CreateProperty<DialogState>(nameof(SpecificDialog)), cancellationToken);
但这不管用。我怎样才能做到这一点?
发布于 2020-01-13 17:31:46
我猜你是和其中一个样本一起工作的。我的答案将以CoreBot为基础。
您应该将Dialog.RunAsync()调用的对话框看作是“根”或“父”对话框,所有其他对话框都会从中分支和流动。若要更改此对话框所调用的对话框,请查看看上去像这样的行
// Create the bot as a transient. In this case the ASP Controller is expecting an IBot.
services.AddTransient<IBot, DialogAndWelcomeBot<MainDialog>>();要将其更改为MainDialog以外的对话框,只需将其替换为适当的对话框。
一旦您在根或父对话框中,您就会BeginDialogAsync()
stepContext.BeginDialogAsync(nameof(BookingDialog), new BookingDetails(), cancellationToken);FYI给其他人:
这在Node中的工作方式有点不同。在CoreBot,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,在每一个讯息上
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();
});您不必以这种方式设置bot,但这是当前推荐的设计,如果您遵循此设计,您将更容易地实现我们的文档和示例。
https://stackoverflow.com/questions/59689055
复制相似问题