在一个Webhook(用Java编写)中,作为为account linking配置的动作的一部分,该动作具有以下拓扑:
purchase.type
我正在尝试从传入的请求中提取 userId 和OAuth accessToken 。
两个初始请求(在链接流开始之前):
Actions-on-Google->Dialogflow->Webhook,
和链接后的链接:
[java] 02-25-2019 16:41:33 [qtp2056234595-232] INFO domain.lola.user.utils.http.ControllerUtils [toString:30] - Received AoG Request {
[java] "responseId": "8da3a8c2-2d60-4675-b249-a39bbc1840c9",
[java] "queryResult": {
[java] "queryText": "GOOGLE_ASSISTANT_WELCOME",
[java] "parameters": {
[java] "any": ""
[java] },
[java] "allRequiredParamsPresent": true,
[java] "fulfillmentMessages": [{
[java] "text": {
[java] "text": [""]
[java] }
[java] }],
[java] "outputContexts": [{
[java] "name": "projects/speechbank-e8a15/agent/sessions/ABwppHEEjeH_tnJt20xAXWhtglLPVUHLgTuf1WVfDzN_FGr46jKppLq3P--zPd3g-3890FJu7hErWAdOZAQeBg/contexts/google_assistant_welcome",
[java] "parameters": {
[java] "any.original": "",
[java] "any": ""
[java] }
[java] }, {
[java] "name": "projects/speechbank-e8a15/agent/sessions/ABwppHEEjeH_tnJt20xAXWhtglLPVUHLgTuf1WVfDzN_FGr46jKppLq3P--zPd3g-3890FJu7hErWAdOZAQeBg/contexts/actions_capability_screen_output",
[java] "parameters": {
[java] "any.original": "",
[java] "any": ""
[java] }
[java] }, {
[java] "name": "projects/speechbank-e8a15/agent/sessions/ABwppHEEjeH_tnJt20xAXWhtglLPVUHLgTuf1WVfDzN_FGr46jKppLq3P--zPd3g-3890FJu7hErWAdOZAQeBg/contexts/google_assistant_input_type_voice",
[java] "parameters": {
[java] "any.original": "",
[java] "any": ""
[java] }
[java] }, {
[java] "name": "projects/speechbank-e8a15/agent/sessions/ABwppHEEjeH_tnJt20xAXWhtglLPVUHLgTuf1WVfDzN_FGr46jKppLq3P--zPd3g-3890FJu7hErWAdOZAQeBg/contexts/actions_capability_audio_output",
[java] "parameters": {
[java] "any.original": "",
[java] "any": ""
[java] }
[java] }, {
[java] "name": "projects/speechbank-e8a15/agent/sessions/ABwppHEEjeH_tnJt20xAXWhtglLPVUHLgTuf1WVfDzN_FGr46jKppLq3P--zPd3g-3890FJu7hErWAdOZAQeBg/contexts/actions_capability_media_response_audio",
[java] "parameters": {
[java] "any.original": "",
[java] "any": ""
[java] }
[java] }, {
[java] "name": "projects/speechbank-e8a15/agent/sessions/ABwppHEEjeH_tnJt20xAXWhtglLPVUHLgTuf1WVfDzN_FGr46jKppLq3P--zPd3g-3890FJu7hErWAdOZAQeBg/contexts/actions_capability_web_browser",
[java] "parameters": {
[java] "any.original": "",
[java] "any": ""
[java] }
[java] }],
[java] "intent": {
[java] "name": "projects/speechbank-e8a15/agent/intents/f645f492-f6dc-4e7e-8da6-45711c654ad0",
[java] "displayName": "RawText"
[java] },
[java] "intentDetectionConfidence": 1.0,
[java] "languageCode": "en-us"
[java] },
[java] "originalDetectIntentRequest": {
[java] "source": "google",
[java] "version": "2",
[java] "payload": {
[java] "isInSandbox": true,
[java] "surface": {
[java] "capabilities": [{
[java] "name": "actions.capability.AUDIO_OUTPUT"
[java] }, {
[java] "name": "actions.capability.MEDIA_RESPONSE_AUDIO"
[java] }, {
[java] "name": "actions.capability.WEB_BROWSER"
[java] }, {
[java] "name": "actions.capability.SCREEN_OUTPUT"
[java] }]
[java] },
[java] "inputs": [{
[java] "rawInputs": [{
[java] "query": "open speech Bank",
[java] "inputType": "VOICE"
[java] }],
[java] "intent": "actions.intent.MAIN"
[java] }],
[java] "user": {
[java] "userStorage": "{\"data\":{}}",
[java] "lastSeen": "2019-02-25T16:40:39Z",
[java] "locale": "en-US",
[java] "userId": "ABwppHFQHUBr0RrWA_OuL-kK2sxTPUvQtL3D-x2Ydr-7uxLt9zzEFzJrGB-X96d9XY8k9XTJj-RUg9WpzGB9jg"
[java] },
[java] "conversation": {
[java] "conversationId": "ABwppHEEjeH_tnJt20xAXWhtglLPVUHLgTuf1WVfDzN_FGr46jKppLq3P--zPd3g-3890FJu7hErWAdOZAQeBg",
[java] "type": "NEW"
[java] },
[java] "availableSurfaces": [{
[java] "capabilities": [{
[java] "name": "actions.capability.AUDIO_OUTPUT"
[java] }, {
[java] "name": "actions.capability.WEB_BROWSER"
[java] }, {
[java] "name": "actions.capability.SCREEN_OUTPUT"
[java] }]
[java] }]
[java] }
[java] },
[java] "session": "projects/speechbank-e8a15/agent/sessions/ABwppHEEjeH_tnJt20xAXWhtglLPVUHLgTuf1WVfDzN_FGr46jKppLq3P--zPd3g-3890FJu7hErWAdOZAQeBg"
[java] }
似乎包含 [java] "responseId": "2aa05bec-9fd3-4387-8e87-ef70509395db",
[java] "queryResult": {
[java] "queryText": "actions_intent_SIGN_IN",
[java] "parameters": {
[java] },
[java] "allRequiredParamsPresent": true,
[java] "fulfillmentMessages": [{
[java] "text": {
[java] "text": [""]
[java] }
[java] }],
[java] "outputContexts": [{
[java] "name": "projects/speechbank-e8a15/agent/sessions/ABwppHEEjeH_tnJt20xAXWhtglLPVUHLgTuf1WVfDzN_FGr46jKppLq3P--zPd3g-3890FJu7hErWAdOZAQeBg/contexts/actions_capability_screen_output"
[java] }, {
[java] "name": "projects/speechbank-e8a15/agent/sessions/ABwppHEEjeH_tnJt20xAXWhtglLPVUHLgTuf1WVfDzN_FGr46jKppLq3P--zPd3g-3890FJu7hErWAdOZAQeBg/contexts/actions_intent_sign_in",
[java] "parameters": {
[java] "SIGN_IN": {
[java] "@type": "type.googleapis.com/google.actions.v2.SignInValue",
[java] "status": "OK"
[java] },
[java] "text": ""
[java] }
[java] }, {
[java] "name": "projects/speechbank-e8a15/agent/sessions/ABwppHEEjeH_tnJt20xAXWhtglLPVUHLgTuf1WVfDzN_FGr46jKppLq3P--zPd3g-3890FJu7hErWAdOZAQeBg/contexts/_actions_on_google",
[java] "lifespanCount": 98,
[java] "parameters": {
[java] "data": "{}"
[java] }
[java] }, {
[java] "name": "projects/speechbank-e8a15/agent/sessions/ABwppHEEjeH_tnJt20xAXWhtglLPVUHLgTuf1WVfDzN_FGr46jKppLq3P--zPd3g-3890FJu7hErWAdOZAQeBg/contexts/actions_capability_audio_output"
[java] }, {
[java] "name": "projects/speechbank-e8a15/agent/sessions/ABwppHEEjeH_tnJt20xAXWhtglLPVUHLgTuf1WVfDzN_FGr46jKppLq3P--zPd3g-3890FJu7hErWAdOZAQeBg/contexts/actions_capability_media_response_audio"
[java] }, {
[java] "name": "projects/speechbank-e8a15/agent/sessions/ABwppHEEjeH_tnJt20xAXWhtglLPVUHLgTuf1WVfDzN_FGr46jKppLq3P--zPd3g-3890FJu7hErWAdOZAQeBg/contexts/actions_capability_web_browser"
[java] }],
[java] "intent": {
[java] "name": "projects/speechbank-e8a15/agent/intents/88bbeb61-b612-47b1-b0e5-8d0de392a0c3",
[java] "displayName": "SignInIntent"
[java] },
[java] "intentDetectionConfidence": 1.0,
[java] "languageCode": "en-us"
[java] },
[java] "originalDetectIntentRequest": {
[java] "source": "google",
[java] "version": "2",
[java] "payload": {
[java] "isInSandbox": true,
[java] "surface": {
[java] "capabilities": [{
[java] "name": "actions.capability.WEB_BROWSER"
[java] }, {
[java] "name": "actions.capability.AUDIO_OUTPUT"
[java] }, {
[java] "name": "actions.capability.SCREEN_OUTPUT"
[java] }, {
[java] "name": "actions.capability.MEDIA_RESPONSE_AUDIO"
[java] }]
[java] },
[java] "inputs": [{
[java] "rawInputs": [{
[java] }],
[java] "arguments": [{
[java] "extension": {
[java] "@type": "type.googleapis.com/google.actions.v2.SignInValue",
[java] "status": "OK"
[java] },
[java] "name": "SIGN_IN"
[java] }, {
[java] "name": "text"
[java] }],
[java] "intent": "actions.intent.SIGN_IN"
[java] }],
[java] "user": {
[java] "userStorage": "{\"data\":{}}",
[java] "lastSeen": "2019-02-25T16:40:39Z",
[java] "accessToken": "token1",
[java] "locale": "en-US",
[java] "userId": "ABwppHFQHUBr0RrWA_OuL-kK2sxTPUvQtL3D-x2Ydr-7uxLt9zzEFzJrGB-X96d9XY8k9XTJj-RUg9WpzGB9jg"
[java] },
[java] "conversation": {
[java] "conversationId": "ABwppHEEjeH_tnJt20xAXWhtglLPVUHLgTuf1WVfDzN_FGr46jKppLq3P--zPd3g-3890FJu7hErWAdOZAQeBg",
[java] "type": "ACTIVE",
[java] "conversationToken": "[\"_actions_on_google\"]"
[java] },
[java] "availableSurfaces": [{
[java] "capabilities": [{
[java] "name": "actions.capability.WEB_BROWSER"
[java] }, {
[java] "name": "actions.capability.AUDIO_OUTPUT"
[java] }, {
[java] "name": "actions.capability.SCREEN_OUTPUT"
[java] }]
[java] }]
[java] }
[java] },
[java] "session": "projects/speechbank-e8a15/agent/sessions/ABwppHEEjeH_tnJt20xAXWhtglLPVUHLgTuf1WVfDzN_FGr46jKppLq3P--zPd3g-3890FJu7hErWAdOZAQeBg"
[java] }
字段。 userId
仅在链接之后才出现,这是正确的。
但是,在我的webhook中,在两种情况下,我都使用以下命令捕获accessToken
和userId
(除其他因素外):
accessToken
在两种情况下,我都看到它们都以private void logUserDetails(ActionRequest request) {
String userId = request.getAppRequest().getUser().getUserId();
log.info("request.getAppRequest().getUser().getUserId()={}",userId);
String idToken = request.getUser().getIdToken();
log.info("idToken={}",idToken);
String usrId = request.getUser().getUserId();
log.info("request.getUser().getUserId()={}",usrId);
String queryText = request.getWebhookRequest().getQueryResult().getQueryText();
log.info("queryText={}", queryText);
}
的形式返回:
帐户前链接:
null
发布帐户链接:
[java] 02-25-2019 16:41:33 INFO AoGApp [logUserDetails:23] - request.getAppRequest().getUser().getUserId()=null
[java] 02-25-2019 16:41:33 INFO AoGApp [logUserDetails:26] - idToken=null
[java] 02-25-2019 16:41:33 INFO AoGApp [logUserDetails:29] - request.getUser().getUserId()=null
[java] 02-25-2019 16:41:33 INFO AoGApp [logUserDetails:32] - queryText=GOOGLE_ASSISTANT_WELCOME
通过Java API,[java] 02-25-2019 16:43:25 INFO AoGApp [logUserDetails:23] - request.getAppRequest().getUser().getUserId()=null
[java] 02-25-2019 16:43:25 INFO AoGApp [logUserDetails:26] - idToken=null
[java] 02-25-2019 16:43:25 INFO AoGApp [logUserDetails:29] - request.getUser().getUserId()=null
[java] 02-25-2019 16:43:25 INFO AoGApp [logUserDetails:32] - queryText=actions_intent_SIGN_IN
似乎是唯一提取实际值的,但对于传入请求中的其他字段,{{1 }}。
我有几个问题:
Google queryText
在什么时候创建,什么触发了它的创建?换句话说,在某种情况下,请求中的null
实际上是userId
,在生成其值之前,我是否能够在请求中看到这种情况? ?
如何从进入Webhook的请求中提取其他字段?我做错了什么,使得通过Java API解析请求所返回的结果与原始请求上看到的值不同?