我们将弃用本地 API。请参阅我们的本地 API 弃用文档,了解弃用详情以及如何迁移到我们的下一代云端 API。
互动消息模板在标准消息模板和媒体消息模板类型的基础上,增加了允许向收件人发送的内容,其中包括使用 components 对象的互动按钮。
我们提供了两种预定义按钮:
这些按钮可以附加到文本消息或媒体消息中。在你创建互动消息模板并且这些模板经过批准后,你可以将其用于通知消息以及客服消息。
你需要:
消息模板获批后,你就可以使用 API 发送消息。
/messages 发出 POST 请求
POST /v1/messages
{
"to": "recipient_wa_id",
"type": "template",
"template": {
"namespace": "your-namespace",
"language": {
"policy": "deterministic",
"code": "your-language-and-locale-code"
},
"name": "your-template-name",
"components": [
{
"type" : "header",
"parameters": [
{
"type": "text",
"text": "replacement_text"
}
]
# end header
},
{
"type" : "body",
"parameters": [
{
"type": "text",
"text": "replacement_text"
},
{
"type": "currency",
"currency" : {
"fallback_value": "$100.99",
"code": "USD",
"amount_1000": 100990
}
},
{
"type": "date_time",
"date_time" : {
"fallback_value": "February 25, 1977",
"day_of_week": 5,
"day_of_month": 25,
"year": 1977,
"month": 2,
"hour": 15,
"minute": 33, #OR
"timestamp": 1485470276
}
},
{
...
# Any additional template parameters
}
]
# end body
},
# The following part of this code example includes several possible button types,
# not all are required for an interactive message template API call.
{
"type": "button",
"sub_type" : "quick_reply",
"index": "0",
"parameters": [
{
"type": "payload",
# Business Developer-defined payload
"payload":"aGlzIHRoaXMgaXMgY29vZHNhc2phZHdpcXdlMGZoIGFTIEZISUQgV1FEV0RT"
}
]
},
{
"type": "button",
"sub_type" : "url",
"index": "1",
"parameters": [
{
"type": "text",
# Business Developer-defined dynamic URL suffix
"text": "9rwnB8RbYmPF5t2Mn09x4h"
}
]
},
{
"type": "button",
"sub_type" : "url",
"index": "2",
"parameters": [
{
"type": "text",
# Business Developer-defined dynamic URL suffix
"text": "ticket.pdf"
}
]
}
]
}
}
成功响应包含带有 id 的 messages 对象。
{
"messages": [{
"id": "gBEGkYiEB1VXAglK1ZEqA1YKPrU"
}]
}
失败响应会包含错误对象,其中包含错误字符串、错误代码和其他信息。
如果你向无法接收模板的账户发送模板,则系统会在错误对象中向已配置的 Webhook 服务器发送 1026 (ReceiverIncapable) 错误。
如需获取关于错误的更多信息,请参阅错误和状态代码。
用户点击快速回复按钮时,系统将向商家返回响应。详情请参阅通过点击快速回复按钮回调。用户也可以选择不点击该按钮,只向你发送自由格式的消息。
{
"contacts": [
{
"profile": {
"name": "Kerry Fisher"
},
"wa_id": "16505551234"
}
],
"messages": [
{
"button": {
"payload": "No-Button-Payload",
"text": "No"
},
"context": {
"from": "16315558007",
"id": "gBGGFmkiWVVPAgkgQkwi7IORac0"
},
"from": "16505551234",
"id": "ABGGFmkiWVVPAgo-sKD87hgxPHdF",
"timestamp": "1591210827",
"type": "button"
}
]
# If there are any errors, an errors field (array) will be present
"errors": [ { ... } ]
}
这些示例将阐明设置互动消息模板的流程,包括在商务管理平台创建模板,以及通过向 messages 端点发出 API 调用来发送消息模板。
本示例将展示如何创建包含快速回复按钮的互动媒体消息模板。

messages API 调用中添加参数信息。
POST /v1/messages
{
"to": "your-test-recipient-wa-id",
"recipient_type": "individual",
"type": "template",
"template": {
"namespace": "88b39973_f0d5_54e1_29cf_e80f1e3da4f2",
"name": "upcoming_trip_reminder",
"language": {
"code": "en",
"policy": "deterministic"
},
"components": [
{
"type": "header",
"parameters": [
{
"type": "text",
"text": "12/26"
}
]
},
{
"type": "body",
"parameters": [
{
"type": "text",
"text": "*Ski Trip*"
},
{
"type": "date_time",
"date_time" : {
"fallback_value": "29th July 2019, 8:00am",
"day_of_month": "29",
"year": "2019",
"month": "7",
"hour": "8",
"minute": "00"
}
},
{
"type": "text",
"text": "*Squaw Valley Ski Resort, Tahoe*"
}
]
},
{
"type": "button",
"sub_type": "quick_reply",
"index": 0,
"parameters": [
{
"type": "payload",
"payload": "Yes-Button-Payload"
}
]
},
{
"type": "button",
"sub_type": "quick_reply",
"index": 1,
"parameters": [
{
"type": "payload",
"payload": "No-Button-Payload"
}
]
}
]
}
}

本示例将展示如何创建包含网址和电话号码按钮的互动媒体消息模板。
messages API 调用中添加参数信息。
POST /v1/messages
{
"to": "your-test-recipient-wa-id",
"recipient_type": "individual",
"type": "template",
"template": {
"namespace": "88b39973_f0d5_54e1_29cf_e80f1e3da4f2",
"name": "oculus_shipment_update",
"language": {
"code": "en",
"policy": "deterministic"
},
"components": [
{
"type": "header",
"parameters": [{
"type": "image",
"image": {
"link": "link-to-your-image"
}
}]
},
{
"type": "body",
"parameters": [
{
"type": "text",
"text": "Anand"
},
{
"type": "text",
"text": "Quest"
},
{
"type": "text",
"text": "113-0921387"
},
{
"type": "date_time",
"date_time" : {
"fallback_value": "23rd Nov 2019",
"day_of_month": "20",
"year": "2019",
"month": "9"
}
}
]
},
{
"type": "button",
"index": "0",
"sub_type": "url",
"parameters": [
{
"type": "text",
"text": "1Z999AA10123456784"
}
]
}
]
}
}
