我想向机器人发送与此类似的内容
"[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:在此版本中,如果语音不包含任何相关实体,则效果很好。例如“我们可以见面吗?”工作良好。
这个版本的问题是当我尝试“我们明天见面吗?”时。明天已成功标识为日期时间实体,但是一旦它在此块中触到
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.");
}
最佳答案
试试这个,它可以在我的机器人上运行。
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);
}
}
]);