Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Bot框架:多步骤瀑布_Node.js_Bots_Botframework - Fatal编程技术网

Node.js Bot框架:多步骤瀑布

Node.js Bot框架:多步骤瀑布,node.js,bots,botframework,Node.js,Bots,Botframework,我想发送一个类似的机器人 "[Person] wants to meet at [Place] at [Date]" 然而,如果这个人遗漏了一些信息,我希望机器人一点一点地请求它 例如,如果一个人写: "Let's meet!" 机器人会问一系列问题以满足所有数据要求。比如: "Alex would like to meet tomorrow" 我将会见谁 他们应该在哪里见面 什么日期和时间 如果此人提出以下问题: "Alex would like to meet tomorrow" 然

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

"[Person] wants to meet at [Place] at [Date]"
然而,如果这个人遗漏了一些信息,我希望机器人一点一点地请求它

例如,如果一个人写:

"Let's meet!"
机器人会问一系列问题以满足所有数据要求。比如:

"Alex would like to meet tomorrow"
  • 我将会见谁
  • 他们应该在哪里见面
  • 什么日期和时间
  • 如果此人提出以下问题:

    "Alex would like to meet tomorrow"
    
    然后机器人只会问

    "Where should they meet?"
    
    完成所有所需数据后,将发送如下响应:

    "Great, I will meet [Person] in [Location] at [DateTime]"
    
    我一直在尝试这样的方法,但运气不好,出现了“对session.EndDialog()的调用太多”错误:

    尝试失败#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?");   
         }
    
    }
    
    它失败了,并且给了我相同的
    对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.");
    }
    

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

    试试这个,它对我的机器人有效

    dialog.on('QuieroQueMeLlamen'[
    函数(会话,args){
    var Telefono=builder.EntityRecognizer.findEntity(args.entities,'Usuario::Telefono');
    如果(!Telefono){
    builder.Prompts.number(会话“Dame un número telefónico donde pueda llamarte una de nuestras enfermeras(sin espacios ni caracteres:ej:3206907529)”;
    }      
    },
    功能(会话、结果){
    if(results.response){
    //如果STRLEN是非cellular随从:
    session.send(“Te estamos llamando alúmero%s,por vour contracta”,results.response);
    } 
    }
    
    ]);我认为您应该访问

    results.response.person 
    
    而不是

    results.person 
    

    此瀑布的其他闭包也是如此。

    谢谢,不幸的是,它不起作用。我认为现在发生的是next()在某个时刻调用EndDialog,所以我需要开始使用,或者以某种方式完全删除next()。这只是一个猜测,我根据你的反馈更新了我的问题。