首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Bot框架:多级瀑布

Bot框架:多级瀑布
EN

Stack Overflow用户
提问于 2016-05-09 03:33:23
回答 3查看 1.3K关注 0票数 2

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

代码语言:javascript
复制
"[Person] wants to meet at [Place] at [Date]"

然而,如果这个人错过了一些信息,我希望机器人一片片地要求它。

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

代码语言:javascript
复制
"Let's meet!"

机器人会提出一系列的问题来满足所有的数据要求。类似于:

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

如果被问的人是这样的:

代码语言:javascript
复制
"Alex would like to meet tomorrow"

然后机器人只会问

代码语言:javascript
复制
"Where should they meet?"

一旦它完成了所有所需的数据,它就会发送一个响应如下:

代码语言:javascript
复制
"Great, I will meet [Person] in [Location] at [DateTime]"

我一直在尝试这样的方法,但运气不佳,并遇到了“对session.EndDialog()的太多调用”错误:

代码语言:javascript
复制
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错误。

代码语言:javascript
复制
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()

代码语言:javascript
复制
 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()问题

代码语言:javascript
复制
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.");
}
EN

回答 3

Stack Overflow用户

发布于 2016-05-14 23:55:02

试一试,它能在我的机器人上工作。

代码语言:javascript
复制
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);
        } 
    }
]);

票数 1
EN

Stack Overflow用户

发布于 2016-05-10 09:48:40

不应该将参数传递给next()函数,而是使用session.YOUVARIABLES通过瀑布存储数据。

类似于:

代码语言:javascript
复制
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
EN

Stack Overflow用户

发布于 2016-05-29 18:41:51

我觉得你应该

代码语言:javascript
复制
results.response.person 

而不是

代码语言:javascript
复制
results.person 

这一瀑布的其他关闭也是如此。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37107380

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档