首页 > 解决方案 > Dialogflow 从 webhook 更改表面

问题描述

我正在尝试从我的 webhook 发送响应以触发更改到另一个表面的过程,但 Google 上的 Actions 总是抛出:

必须设置 MalformedResponse 'final_response'。

而且它不是很有帮助。

这是我返回的 JSON:

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

在 Dialogflow 上,我设置了 2 个意图;一个返回此处指定的 json 的意图,以及带有事件 actions_intent_NEW_SURFACE 的另一个意图,所以我知道用户对更改表面的问题的反应。

我一直在阅读这些网站:

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

在 Google 上的操作,带有 actions.intent.NEW_SURFACE 的 webhook 响应(这似乎与我有同样的问题,但 OP 没有写响应。)

但他们都没有让我对这件事有所了解。

标签: dialogflow-esactions-on-google

解决方案


您似乎正在尝试发送完整的 Action SDK 正文作为 Dialogflow 响应的一部分。虽然payload.googleJSON 部分包含类似于Action SDK 响应的对象,但存在一些差异。您可以查看https://developers.google.com/actions/build/json/dialogflow-webhook-json#dialogflow-response-body了解使用帮助程序时响应应该是什么的完整示例,但我认为您的响应需要像

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

推荐阅读