Ngoài loại mẫu tin nhắn tiêu chuẩn, bạn có thể sử dụng đối tượng components
để gửi cho người nhận mẫu tin nhắn có chứa file phương tiện có file phương tiện và tiêu đề. Với đối tượng components
, bạn có thể cho biết type
tin nhắn và parameters
của tin nhắn.
POST
đến /messages
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": [ # The following parameters code example includes several different possible header types, # not all are required for a media message template API call. { "type": "text", "text": "replacement_text" } # OR { "type": "document", "document": { "id": "your-media-id", # filename is an optional parameter "filename": "your-document-filename" } } # OR { "type": "document", "document": { "link": "the-provider-name/protocol://the-url", # provider and filename are optional parameters "provider": { "name" : "provider-name" }, "filename": "your-document-filename" } } # OR { "type": "video", "video": { "id": "your-media-id" } } # OR { "type": "video", "video": { "link": "the-provider-name/protocol://the-url" # provider is an optional parameter "provider": { "name" : "provider-name" } } } # OR { "type": "image", "image": { "link": "http(s)://the-url", # provider is an optional parameter "provider": { "name" : "provider-name" }, } } ] # 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 }, ] } }
Nếu thành công, hệ thống sẽ trả về một đối tượng messages
chứa id
.
{ "messages": [{ "id": "gBEGkYiEB1VXAglK1ZEqA1YKPrU" }] }
Nếu không thành công, hệ thống sẽ trả về một phản hồi có chứa đối tượng lỗi bao gồm chuỗi lỗi, mã lỗi và các thông tin khác.
Nếu bạn gửi mẫu cho tài khoản không thể nhận mẫu này, máy chủ Webhook đã đặt cấu hình sẽ nhận được lỗi 1026 (ReceiverIncapable)
trong đối tượng lỗi.
Hãy xem phần Mã lỗi và mã trạng thái để biết thêm thông tin về lỗi.
Các ví dụ này minh họa quy trình thiết lập mẫu tin nhắn có chứa file phương tiện, bắt đầu từ tạo mẫu trong Trình quản lý kinh doanh và gửi mẫu tin nhắn bằng lệnh gọi API đến điểm cuối messages
.
Các ví dụ này chỉ mang tính minh họa nên bạn không thể sử dụng. Bạn phải tạo các mẫu của riêng mình và gửi đi phê duyệt để thử nghiệm chức năng của mẫu tin nhắn có chứa file phương tiện.
Ví dụ này minh họa quy trình tạo mẫu tin nhắn có chứa file phương tiện có hình ảnh mã QR.
messages
thêm vào thông tin về thông số.POST /v1/messages { "to": "your-test-recipient-wa-id", "recipient_type": "individual", "type": "template", "template": { "namespace": "88b39973_f0d5_54e1_29cf_e80f1e3da4f2", "name": "movie_ticket_update", "language": { "code": "en", "policy": "deterministic" }, "components": [ { "type": "header", "parameters": [ { "type": "image", "image": { "id": "your-image-id" } } ] }, { "type": "body", "parameters": [ { "type": "text", "text": "Star Rangers" }, { "type": "date_time", "date_time" : { "fallback_value": "May 1st, 2019 8:45pm", "day_of_month": 20, "year": 2019, "month": 9, "hour": 20, "minute": 45 } }, { "type": "text", "text": "Carnival, Sangam" }, { "type": "text", "text": "Silver" }, { "type": "text", "text": "F6, F7, F8" } ] } ] } }
Ví dụ này minh họa quy trình tạo mẫu tin nhắn có chứa file phương tiện có tệp PDF.
messages
thêm vào thông tin về thông số.POST /v1/messages { "to": "your-test-recipient-wa-id", "recipient_type": "individual", "type": "template", "template": { "namespace": "88b39973_f0d5_54e1_29cf_e80f1e3da4f2", "name": "flight_confirmation", "language": { "code": "en", "policy": "deterministic" }, "components": [ { "type": "header", "parameters": [ { "type": "document", "document": { "filename": "MRRATH-CGK-KUL.pdf", "link": "link-to-your-document" } } ] }, { "type": "body", "parameters": [ { "type": "text", "text": "CGK (Jakarta)" }, { "type": "text", "text": "KUL (Kuala Lumpur)" }, { "type": "date_time", "date_time" : { "fallback_value": "20th April 2019, 12:20pm", "day_of_month": 20, "year": 2019, "month": 9, "hour": 12, "minute": 10 } } ] } ] } }