Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.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 在Dialogflow中不从上下文获取值_Node.js_Dialogflow Es - Fatal编程技术网

Node.js 在Dialogflow中不从上下文获取值

Node.js 在Dialogflow中不从上下文获取值,node.js,dialogflow-es,Node.js,Dialogflow Es,我在Dialogflow中创建了一个聊天机器人,在其中调用Welcome Intent时,我从API接收用户的电子邮件id,并将其存储在context:mail中。 我访问此电子邮件的另一个目的是注册用户,但我没有得到任何价值。在控制台上打印上下文时,它会显示电子邮件id,那么为什么不在RegisterUser意图中呢? 我使用内联编辑器在Dialogflow中实现 欢迎意向: function getmail(agent){ var myJSONOb = { "param1"

我在Dialogflow中创建了一个聊天机器人,在其中调用Welcome Intent时,我从API接收用户的电子邮件id,并将其存储在context:mail中。 我访问此电子邮件的另一个目的是注册用户,但我没有得到任何价值。在控制台上打印上下文时,它会显示电子邮件id,那么为什么不在RegisterUser意图中呢? 我使用内联编辑器在Dialogflow中实现

欢迎意向:

 function getmail(agent){  
  var myJSONOb = {
    "param1":param1
  };
    var options = {
      method: 'post',
      uri: 'my_API',
      body: myJSONOb,
      json: true
    };
    process.env.NODE_TLS_REJECT_UNAUTHORIZED = false;
    return rp( options )
     .then( body => {
      let ctx = {'name': 'mail', 'lifespan': 15, 'parameters': {'email':body.mail}};
      agent.setContext(ctx);
     // this prints: { name: 'mail', lifespan: 15, parameters: { email: 'mymail@gmail.com' } }

     })
     .catch( err => {...
     });
  }
注册用户:

  function registerUser(agent){
    let params = agent.getContext("mail").parameters;
    let email = params.email;
    agent.add("email "+email);
    //this just prints : 'email' and no value
  }

我不知道你是哪个版本的?但你也可以像下面这样做。 我认为您正在使用NodeJS实现webhook

// Set the context
    agent.context.set({
            name: 'global_main_context',
            lifespan: 5,
            parameters: param
        });
// get the context
let globalContext = agent.context.get('global_main_context');

希望这有帮助

是的,很抱歉没有说清楚。我正在使用inline node.js实现。不过,您可以尝试这种方法,我相信,它也应该可以与内联编辑器一起使用。我尝试过这种方法,但它给出了以下错误:status:{“code”:10,“message”:无法将Dialogflow response解析为AppResponse,因为平台响应无效:在agentId:b655666c-93fe-4fad-939c-de5e70a2d48e和intentId:06013eeb-8e66-47f1-85c6-8c35d6fdf7fb的平台响应中找不到RichResponse或SystemIntent。Webhook状态:代码:14\n消息:\“Webhook调用失败。错误:不可用。\”\n。}您使用的是哪个版本,我在NodeJS客户端上与“dialogflow fulfillment”:“^0.6.1”一起使用过。我使用的是“dialogflow”:“^0.6.0”,“dialogflow fulfillment”:“^0.5.0”这可能是导致错误的原因吗?