Geocoding API和DialogFlow意图得到'错误:未为平台定义响应:null'

问题描述 投票:0回答:1

我正在尝试在对话框流程的完整范围内使用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
});

我在这里想念什么?

javascript geolocation dialogflow geocoding google-geocoding-api
1个回答
0
投票

经过很多麻烦之后我开始工作了:

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

    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获得响应后立即回复用户。

© www.soinside.com 2019 - 2024. All rights reserved.