所以最近我一直在尝试在tableCard响应中编写代码,但似乎无法使其正常工作。这是我的代码(Node.JS):

{"fulfillmentText": text,
  "fulfillmentMessages": [
    {
      "platform": "ACTIONS_ON_GOOGLE",
      "simpleResponses": {"simpleResponses": [{"textToSpeech": text}]}
    },
    {
      "platform": "ACTIONS_ON_GOOGLE",
      "tableCard": {
        "rows": [
          {
            "cells": [
              {"text": "row 1 item 1"},
              {"text": "row 1 item 2"},
              {"text": "row 1 item 3"}
            ],
          },
          {
            "cells": [
              {"text": "row 2 item 1"},
              {"text": "row 2 item 2"},
              {"text": "row 2 item 3"}
            ],
          }
        ],
        "columnProperties": [
          {"header": "header 1"},
          {"header": "header 2"},
          {"header": "header 3"}
        ]
      }
    }
  ]
};


我格式化代码的方式是否存在错误,或者Dialogflow不支持tableCard?这是我运行它时遇到的错误:

"webhookStatus": {
  "code": 3,
  "message": "Webhook call failed. Error: Failed to parse webhook JSON response: Cannot find field: tableCard in message google.cloud.dialogflow.v2beta1.Intent.Message."
}

最佳答案

tableCard是Google特定于Actions的元素,因此需要将其设置为响应中特定于平台的“有效负载”属性的一部分。像这样:

{
    "payload": {
        "google": {
            "expectUserResponse": true,
            "richResponse": {
                "items": [
                    {
                        "simpleResponse": {
                            "textToSpeech": "Welcome to my agent!"
                        }
                    },
                    {
                        "tableCard": {
                            "rows": [
                                {
                                    "cells": [
                                        {
                                            "text": "row 1 item 1"
                                        },
                                        {
                                            "text": "row 1 item 2"
                                        },
                                        {
                                            "text": "row 1 item 3"
                                        }
                                    ],
                                    "dividerAfter": true
                                },
                                {
                                    "cells": [
                                        {
                                            "text": "row 2 item 1"
                                        },
                                        {
                                            "text": "row 2 item 2"
                                        },
                                        {
                                            "text": "row 2 item 3"
                                        }
                                    ],
                                    "dividerAfter": true
                                }
                            ],
                            "columnProperties": [
                                {
                                    "header": "header 1"
                                },
                                {
                                    "header": "header 2"
                                },
                                {
                                    "header": "header 3"
                                }
                            ]
                        }
                    }
                ]
            }
        }
    },
    "outputContexts": []
}

10-06 15:39