0
votes

My C# web API has successfully received a request from my Actions on google dialog flow. But I am having issues understanding what the response format should be.

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

attempt one

The documentation webhook states that my response should look like that

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

This results in the following error

MalformedResponse 'final_response' must be set.

Failed to parse Dialogflow response into AppResponse because of empty speech response

attempt 2

So i went on to try simple response

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

Which also results with

MalformedResponse 'final_response' must be set.

Failed to parse Dialogflow response into AppResponse because of empty speech response

I can verify that my requests are being sent as application/json

Does anyone know the proper response format?

2

2 Answers

0
votes

The root problem is actually ASP.NET Core by default uses transfer-encoding: chunked for ActionResult and for some reason Dialogflow does not support parsing chunked transfer

The following response is accepted by actions.

[HttpPost]

public ContentResult Post([FromBody] FulfillmentRequst data)
    {

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

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