我假设您正在使用其中一个示例。我的答案将基于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.js 中的工作方式略有不同。在 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();
});
您没有必须以这种方式设置您的机器人,但这是目前推荐的设计,如果您遵循这一点,您将更容易实施我们的文档和示例。