如何在 Google Assistant 中显示来自 Dialogflow Webhook 的 Table 卡片

How to display a Table Card from Dialogflow Webhook in Google Assistant

我已经设置了一个 ASP.NET MVC 4 Web API 来处理对话流实现。我的目标是与 Google 助手集成并显示 Table 卡片作为响应。我正在通过 Google 操作控制台模拟器进行测试。

我已经在 GoogleCloudDialogflowV2IntentMessage Payload 字段中添加了 Table 卡片详细信息,基于我在此处找到的内容:

来自我的 API Webhook 的 Fulfillment 响应最终看起来像这样:

{
  "followupEventInput": {
    "languageCode": null,
    "name": null,
    "parameters": null,
    "ETag": null
  },
  "fulfillmentMessages": [
    {
      "basicCard": null,
      "card": null,
      "carouselSelect": null,
      "image": null,
      "linkOutSuggestion": null,
      "listSelect": null,
      "payload": {
        "google": {
          "expectUserResponse": false,
          "richResponse": {
            "items": [
              {
                "simpleResponse": {
                  "textToSpeech": "Simple Response TEST",
                  "ssml": "Simple Response TEST SSML",
                  "displayText": "Simple Response TEST DISPLAY"
                }
              },
              {
                "tableCard": {
                  "title": "Title",
                  "subtitle": "Subtitle",
                  "image": {
                    "url": "https://www.google.org/static/logo_googledotorg.svg",
                    "accessibilityText": "Image Accessibility Text TEST"
                  },
                  "columnProperties": [
                    {
                      "header": "BanksID",
                      "horizontalAlignment": "LEADING"
                    },
                    {
                      "header": "Name",
                      "horizontalAlignment": "LEADING"
                    }
                  ],
                  "rows": [
                    {
                      "cells": [
                        {
                          "text": "3"
                        },
                        {
                          "text": "Bank 1 TEST"
                        }
                      ],
                      "dividerAfter": false
                    }
                  ],
                  "buttons": [
                    {
                      "title": "Weblink Title",
                      "openUrlAction": {
                        "url": "https://www.google.org",
                        "urlTypeHint": "URL_TYPE_HINT_UNSPECIFIED"
                      }
                    }
                  ]
                }
              }
            ]
          }
        }
      },
      "platform": null,
      "quickReplies": null,
      "simpleResponses": {
        "simpleResponses": [
          {
            "displayText": "Simple Response DISPLAY TEST",
            "ssml": "Simple Response TEST SSML",
            "textToSpeech": "Simple Response TEST",
            "ETag": null
          }
        ],
        "ETag": null
      },
      "suggestions": null,
      "text": null,
      "ETag": null
    }
  ],
  "fulfillmentText": "TEST successful.",
  "outputContexts": [
    {
      "lifespanCount": 5,
      "name": "banks",
      "parameters": {
        "TForView": "rra",
        "DBVerb": "rra",
        "TForView.original": "",
        "DBVerb.original": ""
      },
      "ETag": null
    }
  ],
  "payload": null,
  "source": null,
  "ETag": null
}

问题是我在模拟器中没有看到 Table 卡。我的 JSON 响应格式可能不正确,因此 Google 助手无法正确解释它,但我不知道如何更改它。我不知道正确的格式是什么。或许我还遗漏了其他东西。

如何通过 Webhook 响应在 Google 助手中显示 Table 卡片?

感谢任何帮助/其他想法。

通过查看 Dialogflow 控制台 > 诊断信息 > 履行状态。

我发现在 GoogleCloudDialogflowV2IntentMessage 中我同时设置了 SimpleResponses 字段和 Payload 字段; Google 助理不太喜欢这样。因此,我将 SimpleResponses 字段设置为 null,然后在 Google 动作模拟器上获得了所需的显示响应。

SimpleResponses 已经添加到 Payload 字段中,Google 助手对此没有问题,只是 PayloadSimpleResponses 已设置。