地理编码API和DialogFlow意图获取'错误:未为平台定义响应:null'

我正在尝试在对话框流程的完整范围内使用Google的Geocoding API。

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

我从官方github存储库的README中获取了这段代码:

 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
});

我在这里想念什么?

wangzhufeng 回答:地理编码API和DialogFlow意图获取'错误:未为平台定义响应:null'

在遇到很多麻烦之后,我开始工作了:

意图处理程序需要您在诺言解决后返回代理商。

    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);
    });
  }

通过这种方式,代理会在收到来自Geocoding API的响应后立即回复用户。

本文链接:https://www.f2er.com/2933408.html

大家都在问