我在我的代码中使用LUIS识别器来触发对话框。在我的一个对话框('搜索')中,当用户输入'cancel'时,我想调用'help'对话框。我希望通过cancelAction中的onSelectAction实现这一点。但是我收到一个错误:
(node:42184) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Dialog[BotBuilder:help] not found.
但是我的代码中有一个“帮助”对话框。这是否发生是因为“帮助”不在对话框堆栈中?任何关于如何调试它的指针都将非常感激。
var builder = require('botbuilder');
var restify = require('restify');
// Setup Restify Server
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
// Create connector and listen for messages
var connector = new builder.ChatConnector({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
server.post('/api/messages', connector.listen());
var bot = new builder.UniversalBot(connector, function (session) {
session.replaceDialog('search');
});
bot.dialog('help', [
function (session, args, next) {
session.send('Help dialog');
}
]);
bot.dialog('search', [
function (session, args, next) {
builder.Prompts.text(session, 'What would you like to search?');
}
]).cancelAction('cancelAction', 'Ok, cancelling your search', {
matches: /^cancel$/,
onSelectAction: (session, args, next) => {
session.replaceDialog('help', args);
}
});
根据replaceDialog
的评论:
结束当前对话框并开始一个新对话框。在新对话框完成之前,不会恢复父对话框。
根据onSelectAction
行动源代码中的评论:
/**
...
* It's important to note that this is not a waterfall and you should call `next()` if you
* would like the actions default behavior to run.
*/
onSelectAction?: (session: Session, args?: IActionRouteData, next?: Function) => void;
看来我们需要先调用next()
,这可以删除botbuilder
库,这个动作会将库改为*
。
所以,试试以下:
bot.dialog('search', [
function (session, args, next) {
builder.Prompts.text(session, 'What would you like to search?');
}
]).cancelAction('cancelAction', 'Ok, cancelling your search', {
matches: /^cancel$/,
onSelectAction: (session, args, next) => {
next();
session.replaceDialog('help', args);
}
});