Google采取的措施可正确回应

时间:2018-07-06 12:02:57

标签: c# asp.net-core dialogflow actions-on-google

我的C#网络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"}}}

这将导致以下错误

  

MalformedResponse'final_response'必须设置。

     

由于语音响应为空,无法将Dialogflow响应解析为AppResponse

尝试2

所以我继续尝试simple response

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

这也会导致

  

MalformedResponse'final_response'必须设置。

     

由于语音响应为空,无法将Dialogflow响应解析为AppResponse

我可以验证我的请求是否以application/json的身份发送

有人知道正确的回复格式吗?

2 个答案:

答案 0 :(得分:0)

根本问题实际上是ASP.NET Core默认情况下使用传输编码:为ActionResult分块,并且由于某些原因Dialogflow不支持解析分块传输

以下响应被操作接受。

[HttpPost]

public ContentResult Post([FromBody] FulfillmentRequst data)
    {

        var response = new FulfillmentResponse
        {
            fulfillmentText = "Hello from C# v2",
            };

        return Content(JsonConvert.SerializeObject(response), "application/json");
    }

答案 1 :(得分:-1)