【问题标题】:How can I create a response with rich messages in Dialogflow?如何在 Dialogflow 中创建包含丰富消息的响应?
【发布时间】:2018-04-16 13:22:32
【问题描述】:

目前,当一个意图被调用时,我正在调用一个 webhook 并从 web 服务获取响应,如下所示的 json 结构。

{
  "speech": "this text is spoken out loud if the platform supports voice interactions",
  "displayText": "this text is displayed visually"
}

这只是文字。或者,例如,我必须得到什么响应才能显示列表。

我尝试了 dialogflow 文档的丰富消息部分。这些结构不起作用。

【问题讨论】:

    标签: actions-on-google dialogflow-es api-ai


    【解决方案1】:

    每次 DialogFlow 匹配一个意图时,您都可以要求 DialogFlow 向特定端点发送请求。您显然必须编写一个端点。

    这将允许您检索匹配的意图,以及匹配的参数和上下文,并使用它们做一些有用的工作。

    How to use Message Object in Dialogflow

    Kommunicate - Custom webhook Dialogflow integration example

    使用 webhook 的富消息示例

    {
    "fulfillmentMessages": [{
        "payload": {
            "message": "Object1",
            "platform": "",  // Example - Facebook, Slack...etc
    
          {
            "name": "Save Promo",
            "action": {
              "type": "quickReply",
              "payload": {
                "message": "text will be sent as message",
                "replyMetadata": {
                  "key1": "value1"
                }
              }
            }
          },
          {
            "name": "Save Coupon",
            "action": {
              "type": "quickReply",
              "payload": {
                "message": "text will be sent as message",
                "replyMetadata": {
                  "key1": "value1"
                }
              }
            }
          }
    }, {
        "payload": {
            "message": "Object2",
            "platform": ""   // Example - Facebook, Slack...etc
        }
    }]
    

    }

    【讨论】:

      【解决方案2】:

      要在回复中添加“Google 列表上的操作”,您需要在回复中使用 data 字段,以包含一个带有应说内容的 richResponse,以及一个包含以下内容的 systemIntent列表信息。

      您可以在他们的github example repository 看到更多示例,但这里是显示列表的示例:

      {
        "data": {
          "google": {
            "expectUserResponse": true,
            "richResponse": {
              "items": [
                {
                  "simpleResponse": {
                    "textToSpeech": "Choose an item"
                  }
                }
              ]
            },
            "systemIntent": {
              "intent": "actions.intent.OPTION",
              "data": {
                "@type": "type.googleapis.com/google.actions.v2.OptionValueSpec",
                "listSelect": {
                  "title": "Hello",
                  "items": [
                    {
                      "optionInfo": {
                        "key": "first title"
                      },
                      "description": "first description",
                      "image": {
                        "url": "https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png",
                        "accessibilityText": "first alt"
                      },
                      "title": "first title"
                    },
                    {
                      "optionInfo": {
                        "key": "second"
                      },
                      "description": "second description",
                      "image": {
                        "url": "https://lh3.googleusercontent.com/Nu3a6F80WfixUqf_ec_vgXy_c0-0r4VLJRXjVFF_X_CIilEu8B9fT35qyTEj_PEsKw",
                        "accessibilityText": "second alt"
                      },
                      "title": "second title"
                    }
                  ]
                }
              }
            }
          }
        }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-10-08
        • 2021-05-19
        • 2020-08-12
        • 1970-01-01
        • 1970-01-01
        • 2012-06-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多