Geocoding API and DialogFlow intent getting ' Error: No responses defined for platform: null '

Geocoding API and DialogFlow intent getting ' Error: No responses defined for platform: null '

我正在尝试在对话流的完整内容中使用 Google 中的地理编码 API。

详细:我要用户给我他的地址并找到经纬度。

我从官方 github 存储库的自述文件中获取了这段代码:

 googleMapsClient.geocode({address: '1600 Amphitheatre Parkway, Mountain View, CA'})
  .asPromise()
  .then((response) => {
    console.log(response.json.results);
  })
  .catch((err) => {
    console.log(err);
  });

并以这种方式在我的意图处理程序中使用它:

    function findAddress(agent){
    var intent = new Intent(agent);
    parametersCustom.address = agent.parameters.address+', '+agent.parameters["geo-city"];
    agent = intent.finalSetup();
    return googleMapsClient.geocode({address: parametersCustom.address}).asPromise()
    .then((response) => {
      console.log(response.json.results[0].geometry.location);
    })
    .catch((err) => {
      console.log(err);
    });
}

但是当我在 DialogFlow 的内联编辑器中 运行 它时,我得到这个错误:

Error: No responses defined for platform: null
    at V2Agent.sendResponses_ (/srv/node_modules/dialogflow-fulfillment/src/v2-agent.js:243:13)
    at WebhookClient.send_ (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:505:17)
    at promise.then (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:316:38)
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:229:7)

我已经正确设置了(根据官方文档):

  const googleMapsClient = require('@google/maps').createClient({
  key: 'your API key here',
  Promise: Promise
});

我在这里错过了什么?

在经历了很多麻烦之后,我让它工作了:

当 promise 得到解决时,意图处理程序需要您 return 代理。

    function findAddress(agent){
    var intent = new Intent(agent);
    parametersCustom.address = agent.parameters.address+', '+agent.parameters["geo-city"];
    agent = intent.finalSetup();
    return googleMapsClient.geocode({address: parametersCustom.address}).asPromise()
    .then((response) => {
      console.log(response.json.results[0].geometry.location);
      parametersCustom.location = response.json.results[0].geometry.location;
      parametersCustom.formatted_address = response.json.results[0].formatted_address;
      return agent.add('Formatted address' +parametersCustom.formatted_address+' Lat and long ='+parametersCustom.location);
    })
    .catch((err) => {
      console.log(err);
    });
  }

这样代理会在收到地理编码的响应后立即回复用户 API。