【问题标题】:Bot Framework: Multi step waterfallBot Framework:多步瀑布
【发布时间】:2018-05-31 00:00:34
【问题描述】:

我想发送一个类似这样的机器人

"[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(不再从 '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:在这个版本中,如果话语不包含任何相关实体,它会很好地工作。例如“我们可以见面吗?”工作正常。

这个版本的问题是当我尝试“我们明天可以见面吗?”时。 Tomorrow 被成功识别为日期时间实体,但是一旦它在此块中点击 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.");
}

【问题讨论】:

    标签: node.js bots botframework


    【解决方案1】:

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

    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);
            } 
        }
    ]);

    【讨论】:

      【解决方案2】:

      您不应将参数传递给 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();
          }
      }
      

      【讨论】:

      • 谢谢,不幸的是它没有用。我认为正在发生的事情是 next() 在某个时候调用 EndDialog,所以我需要 BeginDialog,或者以某种方式完全删除 next()。这只是一个猜测,我根据您的反馈更新了我的问题。
      【解决方案3】:

      我认为你应该访问

      results.response.person 
      

      而不是

      results.person 
      

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

      【讨论】:

        猜你喜欢
        • 2017-07-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-13
        • 2020-09-06
        相关资源
        最近更新 更多