【问题标题】:Microsoft BOT framework intents machingMicrosoft BOT 框架意图机器
【发布时间】:2017-05-05 14:11:27
【问题描述】:

我最近开始使用带有 Node.js SDK 的 Microsoft BOT 框架开发 BOT 应用程序。我想知道是否可以在对话框中检查匹配的意图。例如,

var builder = require('botbuilder');
var bot = new builder.UniversalBot(connector);
var intents = new builder.IntentDialog();
bot.dialog('/', intents);

此意图将检查问候语。

intents.matchesAny([/^hi/i, /^hello/i], [
    function (session) {
        var displayName = session.message.user.name;
        var firstName = displayName.substr(0, displayName.indexOf(' '));
        session.send('Hello I’m M2C2! How can I help you %s? If you need help just say HELP.', firstName);
    }
]);

此意图将匹配检查卡余额。

intents.matchesAny([/^balance/i, /^card balance/i], [
    function (session) {
        session.beginDialog('/check-balance');
    }
]);

这是检查余额的对话框。

bot.dialog('/check-balance', [
    function (session) {
        builder.Prompts.text(session, "Sure, I can find the balance for you! May I know the card number that you want to check the balance of?");
    },
    function (session, results) {
        if (isNaN(results.response)) {
            session.send('Invalid card number %s', results.response);
        } else {
            session.send('The balance on your %s card is $ 50', results.response);
        }
        session.endDialog();
    }
]);

我想知道的是是否可以在 check-balance 对话框中检查任何匹配的意图。假设用户输入了一个无效的卡号,我想确保该命令与任何定义的意图都不匹配,以便我可以确定显示无效的卡号响应,如果匹配,则执行匹配的意图。

【问题讨论】:

  • 用“balance”或“hi”回答提示不会触发它们对应的对话框。使用Prompts.text() 时,不应尝试匹配意图。但是,如果您使用的是triggerAction(),则任何与其"matches" 属性匹配的话语都会触发。

标签: node.js botframework


【解决方案1】:
intents.matches(/^(exit)|(quit)/, [
function (session) {
    session.beginDialog('/exit');
}]);


bot.dialog('/exit',[
function(session){
    if(session.message.text=='exit'||'quit'){
        session.send("Yor are exit");
    } else { session.send("you are not exit"); }                                                            
}])

【讨论】:

  • 所以在这种情况下,我必须使用一系列 if else 语句检查每个意图。
猜你喜欢
  • 2017-02-16
  • 2019-11-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多