如何在 Dialogflow 中创建包含丰富消息的响应?

How can I create a response with rich messages in Dialogflow?

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

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

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

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

要在 Google 列表上添加操作作为回复的一部分,您需要在回复中使用 data 字段来包含 richResponse said,以及包含列表信息的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"
              }
            ]
          }
        }
      }
    }
  }
}

每次 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
    }
}]

}