Reputation: 204
I want to make it so that my Google Assistant Chat Bot can request to know the users location and then tell them the closest Doctors surgery for example. I don't want it so that the user views the map, I just want it so that the bot comes back and says "The nearest doctors surgery to you is the Theatre Royal Surgery. It's 10 miles from your location."
Is there a way of doing this? If so some help would be greatly appreciated.
Upvotes: 1
Views: 85
Reputation: 50701
Yes, you want to take a look at the user information helper, which will ask the user if it can get their location (either their current location if asked on a mobile device, or the location they have set if using a Google Home or similar device) and share it with your Action.
If you are using the actions-on-google library, this is done using the Permission helper, and your code might look something like
app.intent('ask_for_permissions_detailed', (conv) => {
// Choose one or more supported permissions to request:
// NAME, DEVICE_PRECISE_LOCATION, DEVICE_COARSE_LOCATION
const options = {
context: 'To address you by name and know your location',
// Ask for more than one permission. User can authorize all or none.
permissions: ['NAME', 'DEVICE_PRECISE_LOCATION'],
};
conv.ask(new Permission(options));
});
Using the dialogflow-fulfillment library is similar.
If you're using the multivocal library, you want the Session/Location
environment to be set, so you could require that for any Intents you need it for and it will be requested with something like
"Local": {
"und": {
"Requirements": {
"Intent.compute.distance": "Session/Location"
}
}
}
You can then use Maps' Place Search API to give it the location and search terms for what you're looking for to get a list of nearby results and send them back.
Upvotes: 3