代码之家  ›  专栏  ›  技术社区  ›  Linda Lawton - DaImTo

对google正确响应的操作

  •  0
  • Linda Lawton - DaImTo  · 技术社区  · 8 年前

    我的C Web API已成功收到来自我在Google对话流上的操作的请求。但我在理解响应格式时遇到了问题。

    {
        "responseId": "96ee6c11-8f73-409f-8dac-8b6141d08483",
        "queryResult": {
            "queryText": "History",
            "action": "tell.fact",
            "parameters": {
                "category": "history"
            },
            "allRequiredParamsPresent": true,
            "fulfillmentMessages": [
                {
                    "text": {
                        "text": [
                            ""
                        ]
                    }
                }
            ],
            "outputContexts": [
                {
                    "name": "projects/project--6162817918903295576/agent/sessions/1530877719318/contexts/google_assistant_input_type_touch",
                    "parameters": {
                        "category.original": "History",
                        "category": "history"
                    }
                },
                {
                    "name": "projects/project--6162817918903295576/agent/sessions/1530877719318/contexts/actions_capability_screen_output",
                    "parameters": {
                        "category.original": "History",
                        "category": "history"
                    }
                },
                {
                    "name": "projects/project--6162817918903295576/agent/sessions/1530877719318/contexts/choose_fact-followup",
                    "lifespanCount": 2,
                    "parameters": {
                        "category.original": "History",
                        "category": "history"
                    }
                },
                {
                    "name": "projects/project--6162817918903295576/agent/sessions/1530877719318/contexts/actions_capability_audio_output",
                    "parameters": {
                        "category.original": "History",
                        "category": "history"
                    }
                },
                {
                    "name": "projects/project--6162817918903295576/agent/sessions/1530877719318/contexts/actions_capability_media_response_audio",
                    "parameters": {
                        "category.original": "History",
                        "category": "history"
                    }
                },
                {
                    "name": "projects/project--6162817918903295576/agent/sessions/1530877719318/contexts/actions_capability_web_browser",
                    "parameters": {
                        "category.original": "History",
                        "category": "history"
                    }
                }
            ],
            "intent": {
                "name": "projects/project--6162817918903295576/agent/intents/4a35cf33-e446-4b2b-a284-c70bc4dfce17",
                "displayName": "choose_fact"
            },
            "intentDetectionConfidence": 1,
            "languageCode": "en-us"
        },
        "originalDetectIntentRequest": {
            "source": "google",
            "version": "2",
            "payload": {
                "isInSandbox": true,
                "surface": {
                    "capabilities": [
                        {
                            "name": "actions.capability.AUDIO_OUTPUT"
                        },
                        {
                            "name": "actions.capability.SCREEN_OUTPUT"
                        },
                        {
                            "name": "actions.capability.MEDIA_RESPONSE_AUDIO"
                        },
                        {
                            "name": "actions.capability.WEB_BROWSER"
                        }
                    ]
                },
                "requestType": "SIMULATOR",
                "inputs": [
                    {
                        "rawInputs": [
                            {
                                "query": "History",
                                "inputType": "TOUCH"
                            }
                        ],
                        "arguments": [
                            {
                                "rawText": "History",
                                "textValue": "History",
                                "name": "text"
                            }
                        ],
                        "intent": "actions.intent.TEXT"
                    }
                ],
                "user": {
                    "lastSeen": "2018-07-06T11:44:24Z",
                    "locale": "en-US",
                    "userId": "AETml1TDDPgKmK2GqQ9ugHJc5hQM"
                },
                "conversation": {
                    "conversationId": "1530877719318",
                    "type": "ACTIVE",
                    "conversationToken": "[]"
                },
                "availableSurfaces": [
                    {
                        "capabilities": [
                            {
                                "name": "actions.capability.AUDIO_OUTPUT"
                            },
                            {
                                "name": "actions.capability.SCREEN_OUTPUT"
                            },
                            {
                                "name": "actions.capability.WEB_BROWSER"
                            }
                        ]
                    }
                ]
            }
        },
        "session": "projects/project--6162817918903295576/agent/sessions/1530877719318"
    }
    

    尝试一次

    文件 webhook 声明我的回答应该是那样的

    {"fulfillmentText":"Hello from C# v2","fulfillmentMessages":[{"card":{"title":"card title","subtitle":"sub title","imageUri":"https://assistant.google.com/static/images/molecule/Molecule-Formation-stop.png","buttons":[{"text":"button text","postback":"https://assistant.google.com/"}]}}],"source":"example.com","payload":{"google":{"expectUserResponse":true,"richResponse":{"items":[{"simpleResponse":{"textToSpeech":"Thi sis a simple response "}}]}},"facebook":{"text":"Hello facebook"},"slack":{"text":"Hello facebook"}},"outputContexts":[{"name":"projects/project--6162817918903295576/agent/sessions/2a210c67-4355-d565-de81-4d3ee7439e67","lifespanCount":5,"parameters":{"param":"parm value"}}],"followupEventInput":{"name":"event name","languageCode":"en-Us","parameters":{"param":"parm value"}}}
    

    这将导致以下错误

    必须设置格式错误的响应“最终响应”。

    由于语音响应为空,无法将DialogFlow响应分析为AppResponse

    尝试2

    所以我继续尝试 simple response

    {
      "payload": {
        "google": {
          "expectUserResponse": true,
          "richResponse": {
            "items": [
              {
                "simpleResponse": {
                  "textToSpeech": "this is a simple response"
                }
              }
            ]
          }
        }
      }
    }
    

    结果也是

    必须设置格式错误的响应“最终响应”。

    由于语音响应为空,无法将DialogFlow响应分析为AppResponse

    我可以确认我的请求是作为 application/json

    有人知道正确的响应格式吗?

    2 回复  |  直到 7 年前
        1
  •  0
  •   Linda Lawton - DaImTo    8 年前

    根本问题实际上是,默认情况下,asp.net core使用transfer encoding:chunked for actionresult,由于某些原因,dialogflow不支持分析chunked transfer

    以下响应被操作接受。

    [HttpPost]
    
    public ContentResult Post([FromBody] FulfillmentRequst data)
        {
    
            var response = new FulfillmentResponse
            {
                fulfillmentText = "Hello from C# v2",
                };
    
            return Content(JsonConvert.SerializeObject(response), "application/json");
        }
    
    推荐文章