Dialogflow v2 API - cards not shown in the simulator

你离开我真会死。 提交于 2020-01-15 10:07:35

问题


I've a webhook for fulfillment. Below is the code that's responding back

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

Below is the result from dialogflow GUI

Below is what I get when I run from the simulator or from the Google Assistant application on the Android phone

Both the simulator and phone are not showing the cards. Am I missing something obvious here?


回答1:


For rich responses like cards to show on Google Assistant you have to use the payload part of response JSON, here is an example:

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

Check out this github repo for all rich-responses' JSON formats.



来源:https://stackoverflow.com/questions/50959535/dialogflow-v2-api-cards-not-shown-in-the-simulator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!