如何在API.ai中请求用户的位置? [英] How can I request the user's location in API.ai?

查看:58
本文介绍了如何在API.ai中请求用户的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用api.ai创建一个代理并将PHP脚本用作Webhook。


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.

解决方案

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.

这篇关于如何在API.ai中请求用户的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆