簡體   English   中英

地理編碼 API 和 DialogFlow 意圖獲取“錯誤:沒有為平台定義的響應:空”

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

我正在嘗試在對話流的完整內容中使用來自 Google 的地理編碼 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
});

我在這里錯過了什么?

經過很多麻煩后,我讓它工作了:

當承諾得到解決時,意圖處理程序需要您返回代理。

    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 的響應后立即回復用戶。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM