2

I am trying to get the user location in Dialogflow, but so far I am not able to get it.

I have found information showing how to get the location in Dialogflow using Google assistance like this article. The thing is that I just want to do it with a chatbot and get the response there. I have tried as well the code below but still not working:

'use strict';

const functions = require('firebase-functions');
const admin = require('firebase-admin');


const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const {Permission} = require('actions-on-google');

process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements


exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
  const agent = new WebhookClient({ request, response });
  console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
  console.log('Dialogflow Request body: ' + JSON.stringify(request.body));

   function requestPermission(agent) {
    agent.requestSource = agent.ACTIONS_ON_GOOGLE;
    let conv = agent.conv();
    console.log('conv '+conv);
    conv.ask(new Permission({
    context: 'to locate you',
    permissions: 'DEVICE_PRECISE_LOCATION',
    }));
    agent.add(conv); // Please add this

    }

  function welcome(agent) {
    agent.add(`Welcome to my agent!`);
  }

  function fallback(agent) {
    agent.add(`I didn't understand`);
    agent.add(`I'm sorry, can you try again?`);
  }



  let intentMap = new Map();
  intentMap.set('Default Welcome Intent', welcome);
  intentMap.set('Default Fallback Intent', fallback);

  intentMap.set('request_permission', requestPermission);

  agent.handleRequest(intentMap);
});

I added an intent call "request_permission". I will appreciate any help or recomendation.

1 Answers1

0

There is no general solution in Dialogflow to get the location. Not all systems that work with Dialogflow have a way to transmit location automatically, and others use different means via messages.

The solution for Actions on Google just works with the Google Assistant.

Prisoner
  • 49,922
  • 7
  • 53
  • 105