Botframework 在完成当前意图对话框之前不会中断其他意图对话框

Botframework No Interruptions from other Intent Dialogs until done with current Intent Dialog

我已经使用 LUIS.ai 设计了 ​​A 和 B。在意图 A 中,我使用 builder.Prompts.text 来询问用户几个问题。但是,有时根据答案,它会切换到意图 B。我猜它恰好与我的意图 B 相匹配,尽管我认为它不应该。有没有办法防止这种情况发生?如果我正在通过意图 A 的对话,我不希望在我完成之前受到其他意图的任何干扰。这是我的代码示例。

bot.dialog('A', [
    function (session, args, next) {
        ...
    }, 
    function (session, args, next) {
        ...
    },
    function (session, args) {
        ...
    }
]).triggerAction({
    matches: 'A'
});


bot.dialog('B', [
    function (session, args, next) {
        ...
    }, 
    function (session, args, next) {
        ...
    },
    function (session, args) {
        ...
    }
]).triggerAction({
    matches: 'B'
});

这就是 triggerAction 对你所做的。它们可以非常方便地让您的对话框保持打开状态 (http://www.pveller.com/smarter-conversations-part-2-open-dialogs),但在您的情况下它们会妨碍您。

如果将对话置于 IntentDialog 下,则可以使对话不受 全局路由系统的影响。如果您所做的只是 AB,那么这将是您的代码的不可中断等价物:

const intents = new builder.IntentDialog({
    recognizers: [
        new builder.LuisRecognizer(process.env.LUIS_ENDPOINT)
    ]
});

intents.matches('A', 'A');
intents.matches('B', 'B');

bot.dialog('/', intents);
bot.dialog('A', []);
bot.dialog('B', []);

你所要做的就是:

var recognizer = new builder.LuisRecognizer(url) 
    .onEnabled(function (context, callback) {
        // LUIS is only ON when there are no tasks pending(e.g. Prompt text) 
        var enabled = context.dialogStack().length === 0; 
        callback(null, enabled); 
    });