我正在尝试将 WhatsApp Flows 与端点结合使用。
我正在 Flow Manager 中生成 JSON,并且屏幕在预览视图中正确显示。
我的问题出现在交互式视图中。
此设置用于支持目的,因此每个屏幕都有选项和输入字段。
第一个屏幕有三个选项,当我选择一个时,结果将发送到 webhook。
这就是我遇到问题的地方:我发送的响应似乎不正确。
我已经设置了私钥和公钥,并将它们发送到 Graph API,并且我能够成功解密和加密消息。
这是请求(当我选择一个选项并单击“下一步”时,WhatsApp 发送到 webhook):
{
"version": "3.0",
"action": "data_exchange",
"data": {
"product_selection": "ini_opc_1"
},
"flowToken": "flows-builder-5aeaa687"
}
网络钩子响应:
{
"screen": "screen_2",
"data": {
"extension_message_response": {
"params": {
"flow_token": "flows-builder-5aeaa687"
}
}
}
}
错误:
RadioButtonsGroup“product_selection”缺少必需的属性 “数据源”。
我的问题是:如果 screen_2 已经存在,为什么还要询问产品?
换句话说,我只是想指示 WhatsApp 在哪个屏幕上导航到。
这是前两个屏幕的 JSON。
{
"version": "5.1",
"data_api_version": "3.0",
"routing_model": {
"screen_1": [
"screen_2"
],
"screen_2": [
"..."
]
},
"screens": [
{
"id": "screen_1",
"title": "This is the screen 1",
"data": {
"products": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"title": {
"type": "string"
}
}
},
"__example__": [
{
"id": "ini_opc_1",
"title": "Opt 1"
},
{
"id": "ini_opc_2",
"title": "Opt 2"
},
{
"id": "ini_opc_3",
"title": "Opt 3"
}
]
}
},
"layout": {
"type": "SingleColumnLayout",
"children": [
{
"type": "Form",
"name": "selector_form",
"children": [
{
"type": "RadioButtonsGroup",
"label": "Some welcome msg",
"name": "product_selection",
"data-source": "${data.products}",
"required": true
},
{
"type": "Footer",
"label": "Continuar",
"on-click-action": {
"name": "data_exchange",
"payload": {
"product_selection": "${form.product_selection}"
}
}
}
]
}
]
}
},
{
"id": "screen_2",
"title": "This is the screen 2",
"data": {
"products": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"title": {
"type": "string"
}
}
},
"__example__": [
{
"id": "susc_opc_1",
"title": "Some opt 1"
},
{
"id": "susc_opc_2",
"title": "Some opt 2"
},
{
"id": "susc_opc_3",
"title": "Some opt 3"
}
]
}
},
"layout": {
"type": "SingleColumnLayout",
"children": [
{
"type": "Form",
"name": "selector_form",
"children": [
{
"type": "RadioButtonsGroup",
"label": "Screen 2 msg",
"name": "product_selection",
"data-source": "${data.products}",
"required": true
},
{
"type": "Footer",
"label": "Continuar",
"on-click-action": {
"name": "data_exchange",
"payload": {
"product_selection": "${form.product_selection}"
}
}
}
]
}
]
}
}
]
}
您的端点响应似乎不正确。如果您尝试导航到 screen_two,则需要返回单选按钮所需的屏幕名称和动态数据
products
,如下所示
{
"screen": "screen_two",
"data": {
"products": [
{
"id": "susc_opc_1",
"title": "Some opt 1"
},
{
"id": "susc_opc_2",
"title": "Some opt 2"
},
{
"id": "susc_opc_3",
"title": "Some opt 3"
}
]
}
}
如果您想使单选按钮选项静态(不从端点返回),则可以将列表放在流 JSON 中的
data-source
属性下,如下所示。您还需要删除此屏幕下的 data
属性,因为它仅用于动态数据。
{
"type": "RadioButtonsGroup",
"label": "Screen 2 msg",
"name": "product_selection",
"data-source": [
{
"id": "susc_opc_1",
"title": "Some opt 23"
},
{
"id": "susc_opc_2",
"title": "Some opt 2"
},
{
"id": "susc_opc_3",
"title": "Some opt 3"
}
],
"required": true
},
最后,Flows Manager 页面底部的“端点”在“端点片段”(屏幕截图右侧)下提供了示例端点请求和响应,以帮助进行设置。