Search code examples
javascriptgeolocationdialogflow-esgeocodinggoogle-geocoding-api

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


I'm trying to use Geocoding API from Google inside the dialogflow's fullfillment.

In detail: I want the user to give me his address and find the latitude and longitude.

I took this piece of code from the official github repository's README:

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

And use it in my intent handler this way:

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

But when I run it on the Inline Editor in DialogFlow I get this error:

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)

I already did the setup the right way (according to the official documentation):

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

What am I missing here?


Solution

  • After a lot of trouble I got it working:

    the intent handler NEEDS you to return an agent when the promise is resolved.

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

    This way the agent will reply to the user as soon as it get the response from Geocoding API.