How can I query the user's location in API.ai?

I am creating an agent using api.ai and using PHP script as webhook. The documentation is not clear on how to do this, but I want to ask for permission on the user's coarse location so that they win no need to provide their location for requests.

I've tried iterating over the JSON they mention and putting it as a custom payload for the default greeting intent, but none of them prompt me for permission to use my location.

How can I ask the user to get their location?

EDIT: If I set my PHP script to respond with the intent.welcome

following JSON:

{
    "data": {
        "google": {
            "expectUserResponse": true,
            "systemIntent": {
                "intent": "actions.intent.PERMISSION",
                "data": {
                    "@type": "type.googleapis.com/google.actions.v2.PermissionValueSpec",
                    "optContext": "To provide an accurate experience, ",
                    "permissions": ["DEVICE_PRECISE_LOCATION"]
                }
            }
        }
    }
}

      

The app asks me, "To provide an accurate experience, I just need to get my address from Google. Is this ok?"

However, if I say yes, then the app keeps asking questions like β€œSorry, can you say this again?” So I can't get it to do anything.

+1


source to share


1 answer


You need to create a new intent with the event set to actions_intent_PERMISSION

. (See image below.)

When this event is fired, your web hockey will be called with a JSON field originalRequest.data.device.location

in the request body filled with the requested location information.



enter image description here

+2


source







All Articles