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

六眼飞鱼酱① 提交于 2019-12-23 03:29:33

问题


I'm creating an agent using api.ai and using a PHP script as a webhook. The documentation doesn't make it clear on how to do it, but I'm wanting to request permission to the user's coarse location so they won't have to provide their location for requests.

I've tried echo-ing the JSON they mention, and putting it in as a custom payload for the default welcome intent, but neither of those seem to prompt me for permission to use my location.

How do I ask a user for permission to get their location?

EDIT: If I set my PHP script to respond to intent.welcome with the 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'll just need to get your street address from Google. Is that ok?"

However if I say "yes", then the app keeps asking things like "Sorry, could you say that again?", so I can't actually get it to do anything.


回答1:


You need to create a new Intent with the Event set to actions_intent_PERMISSION. (See image below.)

When this Event is triggered, your webhook will be called with the JSON originalRequest.data.device.location field in the request body populated with the location information you've requested.



来源:https://stackoverflow.com/questions/45389874/how-can-i-request-the-users-location-in-api-ai

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!