在我的azure机器人中,我具有默认机器人“ DialogBot.cs”。我想在其OnMessageActivityAsync()方法中基于用户输入调用特定的瀑布。
但是,一旦我解析了输入,就不知道如何触发特定的瀑布。可以说瀑布称为“ SpecificDialog”。我尝试了这个:
await Dialog.RunAsync(turnContext, ConversationState.CreateProperty<DialogState>(nameof(SpecificDialog)), cancellationToken)
;
但这不起作用。我将如何完成?
我假设您正在使用其中一个示例。我将基于CoreBot给出答案。
您应该将称为的对话框称为Dialog.RunAsync()
“根”对话框或“父”对话框,所有其他对话框都从该对话框中分支出来。要更改由此调用的对话框,请Startup.cs
查找类似以下的行:
// 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);
仅供参考:
在Node中,这有点不同。在CoreBot中,MainDialog通过以下方式传递给机器人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,它对MainDialog
每条消息都进行了调用:
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();
});
你不具备设置你的机器人了这种方式,但它是目前推荐的设计,你就会有实现我们的文档和样本,如果你按照这个更简单的时间。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句