В webhook (написано на Java ), как часть действия, настроенного для связывания учетной записи со следующей топологией:
Actions-on-Google->Dialogflow->Webhook,
Я пытаюсьизвлечь userId и OAuth accessToken из входящих запросов.
Оба начальных запроса (до запуска потока связывания):
[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
поле.accessToken
начинает появляться только после связывания, что является правильным.
Тем не менее, в моем webhook, в обоих случаях я использую следующее для захвата 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] 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
С помощью API Java queryText
представляется единственным , извлекающим фактическое значение, но не для других полей из входящих запросов, где они находятсявсе null
.
У меня есть пара вопросов:
В какой момент userId
создается Google и что вызывает его создание?Другими словами, будет ли случай, когда userId
в запросе на самом деле будет null
, до того как его значение будет сгенерировано, смогу ли я когда-нибудь увидеть такую ситуацию в запросе, поступающем в мой webhook?
Как я могу извлечь другие поля из запроса, поступающего в мой webhook?Что я делаю не так, когда синтаксический анализ запроса через Java API возвращает результаты, отличные от значений, полученных в необработанном запросе?