对话框流(api.ai)Webhook请求中的设备位置 [英] Device location in dialogflow (api.ai) webhook request
问题描述
我正在使用Google Assistant的Dialogflow聊天机器人,在以下Webhook请求JSON示例中:
I'm working on a Dialogflow chat bot for Google Assistant, in the webhook request JSON example here:
https://developers.google.com/actions/reference/v1/dialogflow-webhook
webhook接收包括其位置的设备数据:
the webhook receives device data including its location:
"device": {
"location": {
"coordinates": {
"latitude": 123.456,
"longitude": -123.456
},
"formatted_address": "1234 Random Road, Anytown, CA 12345, United States",
"zip_code": "12345",
"city": "Anytown"
}
}
出于某种原因,我的Webhook没有收到任何设备数据( device键完全丢失)。有人知道我在做什么错或如何包含这些数据吗?
For some reason my webhook is not receiving any device data (the "device" key is missing completely). Does anyone know what I'm doing wrong or how I can include this data?
推荐答案
您需要先询问用户的位置权限。然后,它们的位置将在请求JSON中可用。这是一个很好的示例
You'll need to ask for the user's location permissions first. Then their location will be made available in the request JSON. Here's a good example of how to do it.
注意,您可以要求两种不同的位置:
Note, you can ask for two different kinds of location:
DEVICE_PRECISE_LOCATION
将为您提供确切的纬度
和经度
,以及 DEVICE_COARSE_LOCATION
将为您提供更广泛的位置信息。通常最好的做法是仅使用应用程序所需的最少侵入权限,因此,如果您的应用程序可以适应较粗略的位置,则应选择使用它。
DEVICE_PRECISE_LOCATION
will give you their exact latitude
and longitude
, and DEVICE_COARSE_LOCATION
will provide you with broader location information. It's generally good practice to only use the least intrusive permissions your applications need, so if your app can settle for a coarse location, then you should opt for it.
请注意,您正在查看v1 API,该API已被弃用,并计划在不久的将来删除。确保您正在使用 v2文档。
Note that you're looking at the v1 API, which is deprecated and scheduled to be removed in the near future. Make sure you're working with the v2 documentation.
这篇关于对话框流(api.ai)Webhook请求中的设备位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!