Dialogflow change surface from webhook

Viewed 391

I am trying to send a response from my webhook to trigger the process to change to another surface, but Actions on Google always throws:

MalformedResponse 'final_response' must be set.

And that it's not very helpful.

This is the JSON I am returning:

{
    "payload": {
        "google": {
            "expectUserResponse": true,
            "conversationToken": "{\"data\":{}}",
            "userStorage": "{\"data\":{}}",
            "expectedInputs": [
                {
                    "inputPrompt": {
                        "richInitialPrompt": {
                            "items": [
                                {
                                    "simpleResponse": {
                                        "textToSpeech": "PLACEHOLDER"
                                    }
                                }
                            ]
                        }
                    },
                    "possibleIntents": [
                        {
                            "intent": "actions.intent.NEW_SURFACE",
                            "inputValueData": {
                                "@type": "type.googleapis.com/google.actions.v2.NewSurfaceValueSpec",
                                "capabilities": [
                                    {
                                        "name": "actions.capability.SCREEN_OUTPUT"
                                    }
                                ],
                                "context": "Sure, I have some sample images for you.",
                                "notificationTitle": "Sample Images"
                            }
                        }
                    ]
                }
            ]
        }
    }
}

On Dialogflow I have setup 2 intents; one intent that returns the json specified here, and another intent with the event actions_intent_NEW_SURFACE, so I know what the user responded to the question to change surface.

I have been reading these sites:

https://developers.google.com/actions/assistant/surface-capabilities#multi-surface_conversations

https://dialogflow.com/docs/reference/api-v2/rest/Shared.Types/WebhookResponse

https://developers.google.com/actions/build/json/dialogflow-webhook-json#dialogflow-response-body

Action On Google, webhook response with actions.intent.NEW_SURFACE (This seems like the same problem has I have, but the OP didn't write the response.)

But none of them throw me some light on this matter.

1 Answers

It looks like you're trying to send a full Action SDK body as part of your Dialogflow response. While the payload.google portion of the JSON contains objects that are similar to the Action SDK response, there are some differences. You can see https://developers.google.com/actions/build/json/dialogflow-webhook-json#dialogflow-response-body for a full example of what the response should be when using a helper, but I think your response needs to be something like

{
    "payload": {
        "google": {
            "expectUserResponse": true,
            "userStorage": "{\"data\":{}}",
            "richResponse": {
                "items": [
                    {
                        "simpleResponse": {
                            "textToSpeech": "PLACEHOLDER"
                        }
                    }
                ]
            },
            "systemIntent": {
                "intent": "actions.intent.NEW_SURFACE",
                "inputValueData": {
                    "@type": "type.googleapis.com/google.actions.v2.NewSurfaceValueSpec",
                    "capabilities": [
                        "actions.capability.SCREEN_OUTPUT"
                    ],
                    "context": "Sure, I have some sample images for you.",
                    "notificationTitle": "Sample Images"
                }
            }
        }
    }
}
Related