首页 文章

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

提问于
浏览
1

我正在尝试为Google智能助理实施一个简单的应用 . 一切正常,但现在我的"permission"助手有问题:https://developers.google.com/actions/assistant/helpers#helper_intents

我有一个意图与webhook连接到我的Java应用程序 . 当用户键入类似于"near to me"的句子时,我想向他询问他的位置,然后使用 lat/lon 执行搜索 .

es:靠近我的巴西餐厅

  • 我的意图“searchRestaurant”被解雇了

  • 我收到了webhook请求并解析了它

  • 如果我找到一个连接到“靠近我”这样的句子的参数,那么用“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"
                    ]
                }
            }
        ]
    }
]
}

但似乎有些错误,我收到一个错误:

“{\ n \”responseMetadata \“:{\ n \”status \“:{\ n \”code \“:10,\ n \”message \“:\”无法将Dialogflow响应解析为AppResponse,因为空语音响应\“,\ n \”详细信息\“:[{\ n \”@ type \“:\”type.googleapis.com/google.protobuf.Value \“,\ n \”值\“:\ “{\” ID \ “:\” 1cc45c5e-c398-4ea7-98a5-408f31ce142d \”,\ “时间戳\”:\ “2018-08-02T14:45:05.752Z \” \ “郎\”:\ “它\”,\ “结果\”:{},\ “alternateResult \”:{},\ “状态\”:{\ “code \”:206,\“errorType \”:\“partial_content \”,\“errorDetails \”:\“Webhook调用失败 . 错误:无法解析webhook JSON响应:找不到字段:messagesToken in message google.cloud.dialogflow.v2.WebhookResponse . \“},\”sessionId \“:\”1533221100163 \“} \”\ n}] \ n} \ n} \ n }”

“conversationToken”已填充,因此我不理解错误消息 . 也许我正试图以错误的方式执行操作 .

那么,调用这个帮助器的正确方法是什么?

  • 我创建了第二个意图“ askGeolocation ”,其中 "actions_intent_PERMISSION" 为"Event",并且......如果我正确理解了文档,如果对帮助程序的请求是正确的,则应该触发 .

我怎样才能使这个工作?

更新:

我找到了一些关于ask权限的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"
      ]
        }
      }
    }
  }
}

所以,我已经实现了它,现在响应似乎很好(解析它没有更多错误),但我仍然收到验证错误:

UnparseableJsonResponse API Version 2: Failed to parse JSON response string with 'INVALID_ARGUMENT' error: "permission: Cannot find field."

所以,问题仍然存在 . 谁知道原因?

谢谢

2 回答

  • 0

    在您的意图中,您可以使用自定义实体请求参数 . 你可以这样做:

    您可以将

    • 实体定义为"near"

    • 将所有要在其中触发位置权限的同义词放在此实体中

    • 不要将此参数标记为"required"

    • 不要提示任何提示

    • 在训练短语中,使用此参数添加一些短语
      在您的webhook中

    • ,检查参数,如果存在请求许可,如果不继续 .

    • 将权限事件添加到另一个intent

    • 在该意图中进行您的发布权限处理

    实体

    enter image description here

    意图

    enter image description here

    我希望你明白 .

  • 2

    经过一些测试后我发现了问题 . 我用“权限”而不是“权限”返回了错误的json repsonse:

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

    因此,询问位置的步骤是正确的 . 我在这里作为一个小教程报告它们,以帮助第一次面对它的人:

    1)在DialogFlow中,为你的Intent添加一些逻辑,以便了解何时可以向用户询问他的位置 . 就我而言,我添加了一个“参数”来识别“附近”等句子 .

    2)当我的Intent被解雇时,我收到我的java应用程序这样的请求:

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

    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)你必须有一个配置了“actions_intent_PERMISSION”事件的第二个Intent:

    enter image description here

    • 没有训练短语

    • 没有行动和参数

    • 没有回应

    但随着Fulfillment活跃:

    enter image description here

    5)一旦您的回复到达Google智能助理,就会显示以下消息:

    enter image description here

    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"
     }
    

    包含,名称/姓氏和纬度/经度 . 此信息可以保存在您的应用程序中,以便不再执行此步骤 .

    我希望这有帮助 .

    达维德

相关问题