我想送一个类似这个的机器人
"[Person] wants to meet at [Place] at [Date]"然而,如果这个人错过了一些信息,我希望机器人一片片地要求它。
因此,例如,如果一个人写道:
"Let's meet!"机器人会提出一系列的问题来满足所有的数据要求。类似于:
如果被问的人是这样的:
"Alex would like to meet tomorrow"然后机器人只会问
"Where should they meet?"一旦它完成了所有所需的数据,它就会发送一个响应如下:
"Great, I will meet [Person] in [Location] at [DateTime]"我一直在尝试这样的方法,但运气不佳,并遇到了“对session.EndDialog()的太多调用”错误:
dialog.on('Meeting', [
function (session, results, next) {
var person = builder.EntityRecognizer.findEntity(results.entities, 'Person');
if(!person){
builder.Prompts.text(session, prompts.meetingPersonMissing);
} else {
next({ response: {
person: person.entity
}
});
}
},
function (session, results, next) {
var location = builder.EntityRecognizer.findEntity(results.entities, 'location');
if(!location){
builder.Prompts.text(session, prompts.meetingLocationMissing);
} else {
// Pass title to next step.
next({ response: {
person: results.person,
location: location.entity
}
});
}
},
function (session, results, next) {
var time = builder.EntityRecognizer.findEntity(results.entities, 'builtin.datetime.date');
if(!time){
builder.Prompts.text(session, prompts.meetingTimeMissing);
} else {
next({ response: {
person: results.person,
location: results.location,
time: time.entity
}
});
}
},
function (session, results) {
if (results.response) {
session.send(prompts.meetingSubmited);
} else {
session.send(prompts.canceled);
}
}
]);失败的尝试#2 (不再从‘next()’传递数据)。这将导致相同的EndDialog错误。
dialog.on('Meeting', [
function (session, results, next) {
var person = builder.EntityRecognizer.findEntity(results.entities, 'Person');
var location = builder.EntityRecognizer.findEntity(results.entities, 'location');
var time = builder.EntityRecognizer.findEntity(results.entities, 'builtin.datetime');
session.messageData = {
person: person || null,
location: location || null,
time: time || null
}
if(!session.messageData.person){
builder.Prompts.text(session.messageData.person, prompts.meetingPersonMissing);
} else {
next();
}
},
function (session, results, next) {
if(!session.messageData.location){
builder.Prompts.text(session.messageData.location, prompts.meetingLocationMissing);
} else {
next();
}
},
function (session, results, next) {
if(!session.messageData.time){
builder.Prompts.text(session.messageData.time, prompts.meetingTimeMissing);
} else {
next();
}
},
function (session, results) {
debugger;
if (results.response) {
session.send('Meeting scheduled');
} else {
session.send(prompts.canceled);
}
}
]);更新3:在这个版本中,如果话语不包含任何相关的实体,它就工作得很好。例如“我们能见面吗?”效果很好。
这个版本的问题是,当我试着“我们明天能见面吗?”“明日”被成功地标识为一个datetime实体,但是一旦它在这个块中命中next():
function getDate(session, results){
session.dialogData.topic = results.response;
if(session.dialogData.date){
next();
}else{
builder.Prompts.time(session, "What date would you like to meet?");
}
}它失败了,给了我同样的Too many calls to to session.EndDialog()问题
dialog.on('Meeting', [meetingQuery, getDate, getTime, respondMeeting]);
function meetingQuery(session, results){
if (results.response) {
session.dialogData.date = builder.EntityRecognizer.resolveTime([results.response]);
}
session.userData = {
person: session.message.from.name
}
builder.Prompts.text(session, "Hi "+ session.userData.person +"!\n\n What is the meeting in reference too?");
}
function getDate(session, results){
session.dialogData.topic = results.response;
if(session.dialogData.date){
next();
}else{
builder.Prompts.time(session, "What date would you like to meet?");
}
}
function getTime(session, results){
if (results.response) {
session.dialogData.date = builder.EntityRecognizer.resolveTime([results.response]);
}
if(session.dialogData.time){
next();
}else{
builder.Prompts.choice(session, "Your professor has the follow times availeble?", ["1pm", "2pm", "3pm"]);
}
}
function respondMeeting(session, results){
var time = results.response;
session.send("Your meeting has been schedueld for " + session.dialogData.date + " at " + time.entity + ". Check your email for the invite.");
}发布于 2016-05-14 23:55:02
试一试,它能在我的机器人上工作。
dialog.on('QuieroQueMeLlamen', [
function (session, args) {
var Telefono = builder.EntityRecognizer.findEntity(args.entities, 'Usuario::Telefono');
if(!Telefono){
builder.Prompts.number(session, "Dame un número telefónico donde pueda llamarte una de nuestras enfermeras (sin espacios ni caracteres: ej: 3206907529)");
}
},
function (session, results) {
if (results.response) {
//IF STRLEN es un celular entonces:
session.send("Te estamos llamando al número %s, por favor contesta", results.response);
}
}
]);
发布于 2016-05-10 09:48:40
不应该将参数传递给next()函数,而是使用session.YOUVARIABLES通过瀑布存储数据。
类似于:
function (session, results, next) {
var person = builder.EntityRecognizer.findEntity(results.entities, 'Person');
if(!person){
builder.Prompts.text(session, prompts.meetingPersonMissing);
} else {
session.person = person.entity
next();
}
}发布于 2016-05-29 18:41:51
我觉得你应该
results.response.person 而不是
results.person 这一瀑布的其他关闭也是如此。
https://stackoverflow.com/questions/37107380
复制相似问题