我正在使用MS的Bot Framework玩聊天机器人。 我创建了一个应该预订航班的航班,并且它集成了LUIS。
我的问题是:一旦我在LUIS触发的航班预订对话框中,我想检查有关航班的所有信息是否由用户提供(出发城市,到达城市,日期,航空公司......) 。因此,如果我错过了一个信息,例如离开的城市,机器人会问'你能给我一个出发城吗?'如果我写'来自伦敦',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' });
答案 0 :(得分:0)
如果我理解正确,我认为你可以更新代码以获得多个匹配。从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
方法。
希望有助于或至少让你走上正确的道路!
答案 1 :(得分:0)
我在这里找到了解决方案: https://github.com/Microsoft/BotFramework-Samples/tree/master/docs-samples/Node/basics-naturalLanguage
他们正在谈论我的问题,我在这里发布,以便处于同样情况的人可以看到它。
您必须转到IntentDialog
部分, Ctrl + F 。