【问题标题】:Getting no values from context in Dialogflow在 Dialogflow 中不从上下文中获取任何值
【发布时间】:2020-05-28 19:54:54
【问题描述】:

我在 Dialogflow 中创建了一个聊天机器人,当调用 Welcome Intent 时,我会从 API 接收用户的电子邮件 ID,并将其存储在上下文中:mail。 我在另一个 Intent 中访问此电子邮件以注册用户,但我没有得到任何价值。在控制台上打印上下文时,它显示了电子邮件 ID,那么为什么不在 RegisterUser Intent 中呢? 我使用内联编辑器在 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
  }

【问题讨论】:

    标签: node.js dialogflow-es


    【解决方案1】:

    我不确定你是哪个版本?但你也可以像下面那样做。 我认为您正在使用 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');
    

    希望这会有所帮助!

    【讨论】:

    • 是的,很抱歉没有说清楚。我正在使用内联 node.js 实现。
    • 不过,你可以试试这个方法,我相信,它应该也适用于内联编辑器。
    • 我试过了,但它给出了这个错误:status": { "code": 10, "message": "由于平台响应无效,无法将 Dialogflow 响应解析为 AppResponse:找不到 RichResponse或在 agentId 的平台响应中的 SystemIntent:b655666c-93fe-4fad-939c-de5e70a2d48e 和 intentId:06013eeb-8e66-47f1-85c6-8c35d6fdf7fb。 WebhookStatus: code: 14\nmessage: \"Webhook call failed. Error: UNAVAILABLE.\"\n." }
    • 你使用的是哪个版本,我已经在 NodeJS 客户端上使用了 "dialogflow-fulfillment": "^0.6.1"。
    • 我正在使用 "dialogflow": "^0.6.0", "dialogflow-fulfillment": "^0.5.0" 这可能是导致错误的原因吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-24
    • 1970-01-01
    • 1970-01-01
    • 2018-12-16
    • 1970-01-01
    • 2020-02-20
    • 1970-01-01
    相关资源
    最近更新 更多