2

我有一个实现的 webhook。下面是响应的代码

  let result_obj = {
    "fulfillmentText": "This is a text response",
    "fulfillmentMessages": [
      {
        "text": {
          "text": [
            "this is test"
          ]
        }
      },
      {
        "card": {
          "title": "card title",
          "subtitle": "card text",
          "imageUri": "https://assistant.google.com/static/images/molecule/Molecule-Formation-stop.png",
          "buttons": [
            {
              "text": "button text",
              "postback": "https://assistant.google.com/"
            }
          ]
        }
      }
    ]
}

以下是对话流 GUI 的结果

在此处输入图像描述

以下是我从模拟器或 Android 手机上的 Google Assistant 应用程序运行时得到的结果

在此处输入图像描述

模拟器和手机都没有显示卡片。我在这里遗漏了一些明显的东西吗?

4

1 回答 1

2

对于要在 Google Assistant 上显示的丰富响应(例如卡片),您必须使用响应 JSON 的有效负载部分,下面是一个示例:

{
    "fulfillmentText": "This is a text response",
    "fulfillmentMessages": [],
    "source": "example.com",
    "payload": {
        "google": {
            "expectUserResponse": true,
            "richResponse": {
                "items": [
                    {
                        "simpleResponse": {
                            "textToSpeech": "This is a Basic Card:"
                        }
                    },
                    {
                        "basicCard": {
                            "title": "card title",
                            "image": {
                                "url": "https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png",
                                "accessibilityText": "Google Logo"
                            },
                            "buttons": [
                                {
                                    "title": "Button Title",
                                    "openUrlAction": {
                                        "url": "https://www.google.com"
                                    }
                                }
                            ],
                            "imageDisplayOptions": "WHITE"
                        }
                    }
                ]
            }
        }
    },
    "outputContexts": [],
    "followupEventInput": {}
}

查看这个github 存储库,了解所有丰富响应的 JSON 格式。

于 2018-06-21T05:39:32.570 回答