เทมเพลตข้อความสื่อจะขยายเนื้อหาที่คุณสามารถส่งไปยังผู้รับได้นอกเหนือจากประเภทเทมเพลตข้อความมาตรฐาน เพื่อใส่สื่อและส่วนหัวรวมไว้ด้วยโดยใช้อ็อบเจ็กต์ components
อ็อบเจ็กต์ components
ช่วยให้คุณระบุ type
ของข้อความและ parameters
ของข้อความได้
POST
ไปยัง /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 }, ] } }
การตอบกลับที่สำเร็จจะมีอ็อบเจ็กต์ messages
ที่มี id
{ "messages": [{ "id": "gBEGkYiEB1VXAglK1ZEqA1YKPrU" }] }
การตอบกลับที่ไม่สำเร็จจะมีอ็อบเจ็กต์ข้อผิดพลาดพร้อมสตริงข้อผิดพลาด รหัสข้อผิดพลาด และข้อมูลอื่นๆ
หากมีการส่งเทมเพลตไปยังบัญชีที่ไม่สามารถรับเทมเพลตได้ ระบบจะส่งข้อผิดพลาด 1026 (ReceiverIncapable)
ในอ็อบเจ็กต์ข้อผิดพลาดไปยังเซิร์ฟเวอร์ Webhooks ที่กำหนดค่าไว้
โปรดดูข้อมูลเพิ่มเติมเกี่ยวกับข้อผิดพลาดที่รหัสข้อผิดพลาดและรหัสสถานะ
ตัวอย่างเหล่านี้แสดงขั้นตอนการตั้งค่าเทมเพลตข้อความสื่อ โดยเริ่มจากการสร้างเทมเพลตในตัวจัดการธุรกิจของคุณ และส่งเทมเพลตข้อความด้วยการเรียกใช้ API ไปยังตำแหน่งข้อมูล messages
ตัวอย่างเหล่านี้ใช้เพื่อแสดงให้เห็นภาพเท่านั้นและไม่สามารถนำไปใช้ได้ คุณต้องสร้างตัวอย่างของคุณเองและขออนุมัติเพื่อทดสอบฟังก์ชันการทำงานของเทมเพลตข้อความสื่อ
ตัวอย่างนี้แสดงวิธีการสร้างเทมเพลตข้อความสื่อที่มีรูปคิวอาร์โค้ด
messages
จะเพิ่มลงในข้อมูลพารามิเตอร์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" } ] } ] } }
ตัวอย่างนี้แสดงวิธีการสร้างเทมเพลตข้อความสื่อที่มีเอกสาร PDF
messages
จะเพิ่มลงในข้อมูลพารามิเตอร์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 } } ] } ] } }