2016-05-09 40 views
2

我想类似一个机器人的东西发送到这个博特Framwork:多步瀑布

"[Person] wants to meet at [Place] at [Date]" 

但是,如果对方没有的一些信息我想机器人,要求它一块一块。

因此,举例来说,如果一个人写道:

"Let's meet!" 

僵尸程序会问一系列问题,以满足所有的数据要求。例如:

  1. 我会与谁见面?
  2. 他们应该在哪里见面?
  3. 什么时间和日期?

如果人问类似:

"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(不再传递数据,下()“)。这将导致相同的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."); 
} 

回答

0

您应该参数不传递到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(); 
    } 
} 
+0

谢谢,不幸的是它没有工作。我认为发生了什么是next()在某个时候调用EndDialog,所以我需要BeginDialog,或者完全删除next()。这只是一个猜测 我根据您的反馈更新了我的问题。 – abritez

1

试试这个,它适用于我的机器人。

dialog.on('QuieroQueMeLlamen', [ 
 
    function (session, args) { 
 
    \t var Telefono = builder.EntityRecognizer.findEntity(args.entities, 'Usuario::Telefono'); 
 
     
 
     if(!Telefono){ 
 
     \t 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) { 
 
     \t //IF STRLEN es un celular entonces: 
 
      session.send("Te estamos llamando al número %s, por favor contesta", results.response); 
 
     } 
 
    } 
 
]);

0

我想你应该访问,而不是

results.response.person 

results.person 

同样适用于其他关闭这个瀑布。