【问题标题】:How to stay in dialog triggered by LUIS nodejs如何留在由 LUIS nodejs 触发的对话框中
【发布时间】:2018-08-24 13:01:25
【问题描述】:

我正在使用 MS 的 Bot Framework 玩一些聊天机器人。 我创建了一个用来预订航班的软件,它集成了 LUIS。

我的问题是:一旦进入由 LUIS 触发的航班预订对话框,我想检查有关航班的所有信息是否由用户提供(出发城市、到达城市、日期、航空公司...) .所以如果我错过了一个信息,例如出发城市,机器人会问“你能给我出发城市吗?” qnd 如果我写“来自伦敦”,LUIS 会将其检测为新的航班预订并触发另一个对话。但我显然希望它留在对话框中!

这是到目前为止的对话代码,以防万一缺少出发城市:

// Main dialog with LUIS
bot.dialog('FlightBookingDialog', [
function (session, args, next) {
    // Resolve and store any entity passed from LUIS.
    var intent = args.intent;

    session.dialogData.airline = builder.EntityRecognizer.findEntity(intent.entities, 'Airline');
    session.dialogData.class = builder.EntityRecognizer.findEntity(intent.entities, 'Class');
    session.dialogData.date_time = builder.EntityRecognizer.findEntity(intent.entities, 'builtin.datetimeV2');
    session.dialogData.departure = builder.EntityRecognizer.findEntity(intent.entities, 'Departure');
    session.dialogData.destination = builder.EntityRecognizer.findEntity(intent.entities, 'Destination');
    session.dialogData.number_tickets = builder.EntityRecognizer.findEntity(intent.entities, 'number');

    session.send("I see you want to travel, great !");

    if(!session.dialogData.departure) {
        builder.Prompts.text(session, "Can you specify me a departure city please ?");
    } else {
        next();
    }
},
function (session, args, results, next) {
    if (results.response) {
        builder.LuisRecognizer.recognize(session.message.text, luisModelUrl,
            function(err, intents, entities) {
                if(entities) {
                    var departure = builder.EntityRecognizer.findEntity(intents.entities, 'Departure');
                    if (departure) {
                        session.dialogData.departure = departure;
                    }
                }
            }
       );
    };

    session.send("Good !");
},

]).triggerAction({ 匹配:'FlightBooking' });

【问题讨论】:

    标签: node.js dialog botframework bots azure-language-understanding


    【解决方案1】:

    如果我理解正确,我认为您可以更新代码以具有多个匹配项。从此documentation page 代码可能会更新为如下所示:

    var intents = new builder.IntentDialog({ recognizers: [recognizer] })
    .matches('Greeting', (session) => {
        session.send('You reached Greeting intent, you said \'%s\'.', session.message.text);
    })
    .matches('Note.Create', [(session, args, next) => {
            // Resolve and store any Note.Title entity passed from LUIS.
            var intent = args.intent;
            var title = builder.EntityRecognizer.findEntity(intent.entities, 'Note.Title');
    
            var note = session.dialogData.note = {
              title: title ? title.entity : null,
            };
    
            // Prompt for title
            if (!note.title) {
                builder.Prompts.text(session, 'What would you like to call your note?');
            } else {
                next();
            }
        },
        (session, results, next) => {
            var note = session.dialogData.note;
            if (results.response) {
                note.title = results.response;
            }
    
            // Prompt for the text of the note
            if (!note.text) {
                builder.Prompts.text(session, 'What would you like to say in your note?');
            } else {
                next();
            }
        },
        (session, results) => {
            var note = session.dialogData.note;
            if (results.response) {
                note.text = results.response;
            }
    
            // If the object for storing notes in session.userData doesn't exist yet, initialize it
            if (!session.userData.notes) {
                session.userData.notes = {};
                console.log("initializing session.userData.notes in CreateNote dialog");
            }
            // Save notes in the notes object
            session.userData.notes[note.title] = note;
    
            // Send confirmation to user
            session.endDialog('Creating note named "%s" with text "%s"',
                note.title, note.text);
        }])
    

    请注意,在机器人拥有处理请求所需的所有信息之前,没有endDialog 方法。

    希望能帮助或至少让您走上正确的道路!

    【讨论】:

    • 感谢您的明确回答。我想我已经看到了,问题是我没有在 mu nodejs 代码中声明意图,它们是直接在他们网站上的我的 LUIS 应用程序中声明的Web 应用程序 GUI 工具。我不知道这个代码示例是否可以与它“组合”。但我会试试这个代码示例,看看我是否不再需要触发问题
    【解决方案2】:

    我在这里找到了解决方案: https://github.com/Microsoft/BotFramework-Samples/tree/master/docs-samples/Node/basics-naturalLanguage

    他们正是在谈论我的问题,我将其发布在这里,以便处于相同情况的人可以看到它。

    你必须去IntentDialog部分,Ctrl+F它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多