Dialogflow v2 API-卡未在模拟器中显示

时间:2018-06-21 02:33:15

标签: dialogflow google-home google-assist-api

我有一个实现的挂钩。 以下是响应的代码

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

以下是dialogflow GUI的结果

enter image description here

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

enter image description here

模拟器和手机均未显示卡。我在这里错过明显的东西吗?

1 个答案:

答案 0 :(得分:2)

要使卡片上显示丰富的响应(如卡片),您必须使用响应JSON的 payload 部分,下面是一个示例:

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

查看this github库以获取所有丰富响应的JSON格式。