简体   繁体   English

Google Action / Dialogflow:如何询问地理位置

[英]Google Action / Dialogflow : how to ask for geolocation

I'm trying to implement a simple app for Google Assistant.我正在尝试为 Google Assistant 实现一个简单的应用程序。 All works fine, but now I have a problem with the "permission" helper : https://developers.google.com/actions/assistant/helpers#helper_intents一切正常,但现在我遇到了“权限”助手的问题: https : //developers.google.com/actions/assistant/helpers#helper_intents

I have an intent connected with webhook to my java application.我有一个将 webhook 连接到我的 java 应用程序的意图。 When an user types a sentence similar to "near to me", I want to ask to him his location and then use lat/lon to perform a search.当用户输入类似于“靠近我”的句子时,我想询问他的位置,然后使用lat/lon执行搜索。

es: Brazilian restaurant near to me es:我附近的巴西餐厅

  1. my intent "searchRestaurant" is fired我的意图“searchRestaurant”被解雇

  2. I receive the webhook request and I parse it我收到 webhook 请求并解析它

  3. if I find a parameter that is connected to a sentence like "near to me", so instead to response with a "Card" or a "List" I return a JSON that represent the helper request :如果我发现一个参数连接到像“near to me”这样的句子,而不是用“Card”或“List”响应,我会返回一个代表帮助请求的JSON:


{
"conversationToken": "[]",
"expectUserResponse": true,
"expectedInputs": [
    {
        "inputPrompt": {
            "initialPrompts": [
                {
                    "textToSpeech": "PLACEHOLDER_FOR_PERMISSION"
                }
            ],
            "noInputPrompts": []
        },
        "possibileIntents": [
            {
                "intent": "actions.intent.PERMISSION",
                "inputValueData": {
                    "@type": "type.googleapis.com/google.actions.v2.PermissionValueSpec",
                    "optContext": "Posso accedere alla tua posizione?",
                    "permission": [
                        "NAME",
                        "DEVICE_PRECISE_LOCATION"
                    ]
                }
            }
        ]
    }
]
}

but something seems to be wrong, and I receive an error:但似乎有问题,我收到一个错误:

"{\\n \\"responseMetadata\\": {\\n \\"status\\": {\\n \\"code\\": 10,\\n \\"message\\": \\"Failed to parse Dialogflow response into AppResponse because of empty speech response\\",\\n \\"details\\": [{\\n \\"@type\\": \\"type.googleapis.com/google.protobuf.Value\\",\\n \\"value\\": \\"{\\\\"id\\\\":\\\\"1cc45c5e-c398-4ea7-98a5-408f31ce142d\\\\",\\\\"timestamp\\\\":\\\\"2018-08-02T14:45:05.752Z\\\\",\\\\"lang\\\\":\\\\"it\\\\",\\\\"result\\\\":{},\\\\"alternateResult\\\\":{},\\\\"status\\\\":{\\\\"code\\\\":206,\\\\"errorType\\\\":\\\\"partial_content\\\\",\\\\"errorDetails\\\\":\\\\"Webhook call failed. Error: Failed to parse webhook JSON response: Cannot find field: conversationToken in message google.cloud.dialogflow.v2.WebhookResponse.\\\\"},\\\\"sessionId\\\\":\\\\"1533221100163\\\\"}\\"\\n }]\\n }\\n }\\n}" "{\\n \\"responseMetadata\\": {\\n \\"status\\": {\\n \\"code\\": 10,\\n \\"message\\": \\"由于为空,无法将 Dialogflow 响应解析为 AppResponse语音回复\\",\\n \\"details\\": [{\\n \\"@type\\": \\"type.googleapis.com/google.protobuf.Value\\",\\n \\"value\\": \\" {\\\\"id\\\\":\\\\"1cc45c5e-c398-4ea7-98a5-408f31ce142d\\\\",\\\\"timestamp\\\\":\\\\"2018-08-02T14:45:05.752Z\\\\", \\\\"lang\\\\":\\\\"it\\\\",\\\\"result\\\\":{},\\\\"alternateResult\\\\":{},\\\\"status\\\\":{\\\\" code\\\\":206,\\\\"errorType\\\\":\\\\"partial_content\\\\",\\\\"errorDetails\\\\":\\\\"Webhook 调用失败。错误:无法解析 webhook JSON 响应:找不到字段:消息google.cloud.dialogflow.v2.WebhookResponse.\\\\"},\\\\"sessionId\\\\":\\\\"1533221100163\\\\"}\\"\\n }]\\n }\\n }\\n} 中的对话令牌”

The "conversationToken" is filled, so I don't understand the error message. “conversationToken”已填写,所以我不明白错误信息。 Maybe I'm trying to perform the operation in a wrong way.也许我试图以错误的方式执行操作。

So, which is the correct way to call this helper?那么,调用这个助手的正确方法是什么?

--> I've created a second intent " askGeolocation " that have "actions_intent_PERMISSION" as "Event", and ... if I understand correctly the documentation, should be trigger if the request for helper is correct. --> 我创建了第二个意图“ askGeolocation ”,将"actions_intent_PERMISSION"作为“事件”,并且...如果我正确理解文档,如果对帮助程序的请求正确,则应该触发。

How can I get this working?我怎样才能让它工作?

UPDATE :更新 :

I find some example of the json response for ask permission and seems that it should be different from the one above that i'm using :我找到了一些请求许可的 json 响应示例,似乎它应该与我正在使用的上面的不同:

https://github.com/dialogflow/fulfillment-webhook-json/blob/master/responses/v2/ActionsOnGoogle/AskForPermission.json https://github.com/dialogflow/fulfillment-webhook-json/blob/master/responses/v2/ActionsOnGoogle/AskForPermission.json

{
"payload": {
"google": {
  "expectUserResponse": true,
  "systemIntent": {
    "intent": "actions.intent.PERMISSION",
    "data": {
      "@type": "type.googleapis.com/google.actions.v2.PermissionValueSpec",
      "optContext": "To deliver your order",
      "permissions": [
        "NAME",
        "DEVICE_PRECISE_LOCATION"
      ]
        }
      }
    }
  }
}

so, i've implemented it and now the response seems to be good (no more error on parsing it), but i still receive an error on it validation :所以,我已经实现了它,现在响应似乎很好(解析它时不再出错),但我仍然收到验证错误:

UnparseableJsonResponse API Version 2: Failed to parse JSON response string with 'INVALID_ARGUMENT' error: "permission: Cannot find field." UnparseableJsonResponse API 版本 2:无法解析带有“INVALID_ARGUMENT”错误的 JSON 响应字符串:“权限:找不到字段。”

so, a problem still persist.所以,问题仍然存在。 Anyone know the cause?有谁知道原因吗?

Thanks谢谢

After some tests i found the problem.经过一些测试,我发现了问题。 I was returning a wrong json repsonse with "permission" instead of "permissions":我用“权限”而不是“权限”返回了错误的json响应:

"permission**s**": [
    "NAME",
    "DEVICE_PRECISE_LOCATION"
]

So the steps to ask for location are correct.所以询问位置的步骤是正确的。 I report them here as a little tutorial in order to help who is facing on it for the first time:我将它们作为一个小教程在这里报告,以帮助第一次面对它的人:

1) In DialogFlow, add some logic to your Intent, in order to understand when is ok to ask to user his location. 1) 在 DialogFlow 中,为您的 Intent 添加一些逻辑,以了解何时可以询问用户他的位置。 In my case, i've added a "parameter" that identify sentences like "nearby" and so on.就我而言,我添加了一个“参数”,用于标识“附近”等句子。

2) When my Intent is fired i receive to my java application a request like this : 2)当我的 Intent 被触发时,我会收到我的 Java 应用程序这样的请求:

...
"queryResult": {
"queryText": "ristorante argentino qui vicino",
"action": "bycategory",
"parameters": {
  "askgeolocation": "qui vicino",
  "TipoRistorante": ["ristorante", "argentino"]
},
...

3) If "askgeolocation" parameter is filled, instead to return a "simple message" o other type of message, i return a json for ask the permission to geolocation : 3)如果填充了“askgeolocation”参数,而不是返回“简单消息”或其他类型的消息,我会返回一个json以请求地理定位的许可:

{
"payload": {
"google": {
  "expectUserResponse": true,
  "systemIntent": {
    "intent": "actions.intent.PERMISSION",
    "data": {
      "@type": "type.googleapis.com/google.actions.v2.PermissionValueSpec",
      "optContext": "To deliver your order",
      "permissions": [
        "NAME",
        "DEVICE_PRECISE_LOCATION"
     ]
        }
      }
    }
  }
}

4) You MUST have a second Intent that is configured with "actions_intent_PERMISSION " event : 4) 你必须有第二个 Intent 配置了“actions_intent_PERMISSION”事件:

在此处输入图片说明

  • No training phrases没有训练短语
  • No Action and params没有操作和参数
  • No Responses没有回应

But with Fulfillment active :但是在实现活跃的情况下:

在此处输入图片说明

5) Once your response arrive to Google Assistant this is the message that appear : 5) 一旦您的回复到达 Google 助理,就会出现以下消息:

在此处输入图片说明

6) Now, if user answer "ok" you receive this json on your webhook : 6) 现在,如果用户回答“ok”,你会在你的 webhook 上收到这个 json:

     {
   "responseId": "32cf46cf-80d8-xxxxxxxxxxxxxxxxxxxxx",
   "queryResult": {
     "queryText": "actions_intent_PERMISSION",
     "action": "geoposition",
     "parameters": {
     },
 "allRequiredParamsPresent": true,
 "fulfillmentMessages": [{
   "text": {
     "text": [""]
   }
 }],
 "outputContexts": [{
   "name": "projects/xxxxxxxxxxxxxxxxxxxxx"
 }, {
   "name": "projects/xxxxxxxxxxxxxxxxxxxxx",
   "parameters": {
     "PERMISSION": true
   }
 }, {
   "name": "projects/xxxxxxxxxxxxxxxxxxxxx"
 }, {
   "name": "projects/xxxxxxxxxxxxxxxxxxxxx"
 }, {
   "name": "projects/xxxxxxxxxxxxxxxxxxxxx"
 }, {
   "name": "projects/xxxxxxxxxxxxxxxxxxxxx"
 }],
 "intent": {
   "name": "projects/xxxxxxxxxxxxxxxxxxxxx",
   "displayName": "geoposition"
 },
 "intentDetectionConfidence": 1.0,
 "languageCode": "it"
 },
 "originalDetectIntentRequest": {
 "source": "google",
 "version": "2",
 "payload": {
   "isInSandbox": true,
   "surface": {
     "capabilities": [{
       "name": "actions.capability.MEDIA_RESPONSE_AUDIO"
     }, {
       "name": "actions.capability.SCREEN_OUTPUT"
     }, {
       "name": "actions.capability.AUDIO_OUTPUT"
     }, {
       "name": "actions.capability.WEB_BROWSER"
     }]
   },
   "requestType": "SIMULATOR",
   "inputs": [{
     "rawInputs": [{
       "inputType": "KEYBOARD"
     }],
     "arguments": [{
       "textValue": "true",
       "name": "PERMISSION",
       "boolValue": true
     }],
     "intent": "actions.intent.PERMISSION"
   }],
   "user": {
     "lastSeen": "2018-08-03T08:55:20Z",
     "permissions": ["NAME", "DEVICE_PRECISE_LOCATION"],
     "profile": {
       "displayName": ".... full name of the user ...",
       "givenName": "... name ...",
       "familyName": "... surname ..."
     },
     "locale": "it-IT",
     "userId": "xxxxxxxxxxxxxxxxxxxxx"
   },
   "device": {
     "location": {
       "coordinates": {
         "latitude": 45.xxxxxx,
         "longitude": 9.xxxxxx
       }
     }
   },
   "conversation": {
     "conversationId": "xxxxxxxxxxxxxxxxxxxxx",
     "type": "ACTIVE",
     "conversationToken": "[]"
   },
   "availableSurfaces": [{
     "capabilities": [{
       "name": "actions.capability.SCREEN_OUTPUT"
     }, {
       "name": "actions.capability.AUDIO_OUTPUT"
     }, {
       "name": "actions.capability.WEB_BROWSER"
     }]
   }]
     }
   },
   "session": "projects/xxxxxxxxxxxxxxxxxxxxx"
 }

that contains, name/surname and latitude/longitude.包含姓名/姓氏和纬度/经度。 This information can be saved in your application, in order to not perform again this steps.可以将此信息保存在您的应用程序中,以免再次执行此步骤。

I hope this helps.我希望这有帮助。

Davide戴维德

In your intent, you can ask for a parameter with a custom Entity.在您的意图中,您可以使用自定义实体请求参数。 This you can do like this:你可以这样做:

  • entity you can define as "near"您可以定义为“附近”的实体
  • put all the synonyms for near for which you want to trigger location permission in this entity把你想触发位置权限的所有近义词放在这个实体中
  • do not mark this parameter as "required"不要将此参数标记为“必需”
  • do not put any prompt不要放任何提示
  • in the training phrases, add some phrases with this parameter在训练短语中,添加一些带有此参数的短语
  • in your webhook, keep a check on the parameter, if present ask for permission if not continue.在您的 webhook 中,检查参数,如果存在则请求许可,如果不继续。
  • add a permission event to another intent将权限事件添加到另一个意图
  • do your post permission processing in that intent在该意图中进行您的发布许可处理


Entity实体
在此处输入图片说明
Intent意图
在此处输入图片说明

I hope you get it.我希望你能明白。

There are samples on this topic specifically that guide you through exactly what's needed for requesting permissions in Node and Java .有专门针对此主题的示例可指导您准确了解在NodeJava 中请求权限所需的内容。

Note: There are helper intents samples available in Node and Java as well.注意: NodeJava 中也有帮助程序意图示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM