Dialogflow v2 API-卡未在模拟器中显示 [英] Dialogflow v2 API - cards not shown in the simulator

查看:105
本文介绍了Dialogflow v2 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的结果

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

模拟器和手机均未显示卡.我是否在这里遗漏了一些明显的东西?

解决方案

对于要在Google Assistant上显示的卡片之类的丰富响应,您必须使用响应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": {}
}

查看 github存储库,以获取所有丰富响应的JSON格式./p>

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?

解决方案

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.

这篇关于Dialogflow v2 API-卡未在模拟器中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆