dialogflow Webhookclient“ request_”属性

时间:2018-11-01 17:00:54

标签: dialogflow facebook-chatbot

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

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

谢谢

2 个答案:

答案 0 :(得分:1)

Google提供了Dialogflow webhooks 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控制台中,如下所示:

Firebase console - Functions - Logs

希望有帮助!

答案 1 :(得分:0)

请注意。 我有类似的代码:

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

有一个图标表明最好用点表示法书写。 我将其更改为:

const city = agent.parameters.geo-city;