【问题标题】:dialogflow Webhookclient "request_" propertydialogflow Webhookclient“request_”属性
【发布时间】:2018-11-01 17:00:53
【问题描述】:

我正在尝试使用 Dialogflow 构建一个 facebook messenger 聊天机器人。在 dialogflow 实现内联编辑器中,我发现可以使用 agent.request_.body 来获取请求的正文。我假设“request_”是 WebhoodClient 对象的属性?但是我找不到任何详细说明的文档,请您告知我的理解是否正确以及在哪里可以找到参考或文档?

const agent = new WebhookClient({ request, response });
console.log(JSON.stringify(agent.request_.body));

谢谢

【问题讨论】:

    标签: dialogflow-es facebook-chatbot


    【解决方案1】:

    Google 提供了 Dialogflow webhook here 的文档,其中包括此示例 webhook 以检查参数并动态创建槽填充提示:

    exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
    
      const agent = new WebhookClient({ request, response });
    
      function flight(agent) {
        const city = agent.parameters['geo-city'];
        const time = agent.parameters['time'];
        const gotCity = city.length > 0;
        const gotTime = time.length > 0;
    
        if(gotCity && gotTime) {
            agent.add(`Nice, you want to fly to ${city} at ${time}.`);
        } else if (gotCity && !gotTime) {
            agent.add('Let me know which time you want to fly');
        } else if (gotTime && !gotCity) {
            agent.add('Let me know which city you want to fly to');
        } else {
            agent.add('Let me know which city and time you want to fly');
        }
      }
    
      let intentMap = new Map();
      intentMap.set('flight', flight);
      agent.handleRequest(intentMap);
    });
    

    我的猜测是添加

    console.log(agent);
    

    在定义飞行函数之前,然后检查日志以查看代理包含哪些对象,然后添加 console.log(agent.fakeObjectName) 的迭代,直到找到所需的信息。

    如果您关注 the deployment process recommended in Actions on Google's Codelabs level 2,您的日志将显示在 Firebase 控制台中,如下所示:

    希望有帮助!

    【讨论】:

      【解决方案2】:

      只是一个注释。 我有一个类似这样的代码:

      const city = agent.parameters['geo-city'];
      

      有一个图标表明它最好用点表示法书写。 在我将其更改为后消失了:

      const city = agent.parameters.geo-city;
      

      【讨论】:

      • 虽然你的建议总体上是好的,但在这种情况下,由于名称中有-,它不起作用
      猜你喜欢
      • 1970-01-01
      • 2020-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-28
      • 2021-09-03
      • 2022-10-07
      • 2019-07-03
      相关资源
      最近更新 更多