node.js - Azure Bot NodeJS 等待其他对话框完成

标签 node.js azure botframework azure-bot-service

我目前正在使用 Azure 的 Bot 服务构建一个聊天机器人。我使用 NLU-Bot,与 waterfall 流混合,因为根据我想要获取一些特定信息的意图。 因此我匹配 intent1 并想要

var intents = new builder.IntentDialog({ recognizers: [recognizer] })
.matches('intent1', (session, args, results) =>{

    session.beginDialog("getRequiredInformations");
    session.send("I received your information");
})

bot.dialog('getRequiredInformations', [
    (session) =>{       
        var levels = ['Beginner', 'Intermediate', 'Expert'];
        builder.Prompts.choice(session, "What's your level ?", levels, { listStyle: builder.ListStyle.button, maxRetries: 0 });
    },
    (session, results) => {
        session.conversationData.level = results.response.entity;
    }
]);

我想要做的是等到我们收到来自 getRequiredInformations 对话框的答案,然后继续使用包含已识别意图的原始对话框。上面的代码 session.send("I receive your information"); 在用户输入答案之前发送。

我也尝试过使用 bot.beginDialogAction('getRequiredInformations', 'getRequiredInformations'); 但我认为不可能在对话框中调用它。

我怎样才能实现这一目标?

最佳答案

发现您的代码片段存在多处错误,请引用以下修改:

bot.dialog('intent1', [(session, args, next) => {
    session.beginDialog("getRequiredInformations");
}, (session, args, next) => {
    session.send("I received your information");
    session.send(session.conversationData.level)
}]).triggerAction({
    matches: 'intent1'
})

bot.dialog('getRequiredInformations', [
    (session) => {
        var levels = ['Beginner', 'Intermediate', 'Expert'];
        builder.Prompts.choice(session, "What's your level ?", levels, {
            listStyle: builder.ListStyle.button,
            maxRetries: 0
        });
    },
    (session, results) => {
        session.conversationData.level = results.response.entity;
        session.endDialog();
    }
]);

But this means there is not really an opportunity to wait for the dialog to finish like a callback or anything, I need to do this with a waterfall?

如果我理解正确,您可以尝试使用以下代码片段仅在堆栈中没有对话框的情况下启用 luis 识别器。

var recognizer = new builder.LuisRecognizer(luisAppUrl)
 .onEnabled(function (context, callback) {
     var enabled = context.dialogStack().length == 0;
     callback(null, enabled);
 });

关于node.js - Azure Bot NodeJS 等待其他对话框完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49350200/

相关文章:

azure - 在 Azure API 管理中,我可以使用订阅 key 作为请求 header 的一部分而不是查询字符串参数吗?

bots - 单击卡片中的按钮时如何识别特定附件?

javascript - Microsoft Bot Framework - 如何从第 3 方 API 发送响应

node.js - typescript 和 NodeJS : ReferenceError : Module is not defined

node.js - Reactjs 无法建立套接字连接,它在调用 componentDidMount 时打开并获取响应

node.js - 如何使用nodejs获取特定时区的当前小时?

mysql - 插入数据库并选择值

.net - 使用 Connect-AzAccount 服务主体从 dotnet 中调用 PowerShell 脚本并进行身份验证

azure - 业务用户上传 Data Lake ETL 输入的解决方案

azure - 使用新的基于AAD的访问控制通过Web浏览器通过URI访问Blob文件