如何在Google Assistant中显示来自Dialogflow Webhook的表格卡

时间:2019-09-02 11:04:55

标签: c# asp.net-web-api dialogflow dialogflow-fulfillment

我已经设置了ASP.NET MVC 4 Web API来处理dialogflow实现。我的目标是与Google Assistant集成并显示一张表格卡片作为回应。我正在通过Google Actions Console模拟器进行测试。

根据我在这里发现的信息,我已经在GoogleCloudDialogflowV2IntentMessage Payload字段中添加了表格卡片的详细信息:

How to add Table Card in Dialogflow Fulfillment?

我的API Webhook的实现响应最终看起来像这样:

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

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

如何通过Webhook响应在Google Assistant中显示表格卡片?

任何帮助/其他想法都表示赞赏。

1 个答案:

答案 0 :(得分:0)

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

我发现在GoogleCloudDialogflowV2IntentMessage中同时设置了SimpleResponses字段和Payload字段;和Google助手不太一样。因此,我将SimpleResponses字段设置为null,然后在Google Actions Simulator上获得了所需的显示响应。

SimpleResponses已添加到Payload字段中,而Google Assistant并没有遇到任何麻烦,只需设置PayloadSimpleResponses即可。