Pesan Template
Template WhatsApp diperlukan untuk mengirim pesan di luar window 24 jam (pembuka percakapan). Template harus dalam status APPROVED di Meta sebelum dapat digunakan.
Kelola template di cpaas.id halaman Template Pesan.
Request Body
Section titled “Request Body”Template dengan Parameter Teks
Section titled “Template dengan Parameter Teks”{ "messaging_product": "whatsapp", "to": "6281234567890", "type": "template", "template": { "name": "order_confirmation", "language": { "code": "id" }, "components": [ { "type": "body", "parameters": [ { "type": "text", "text": "John Doe" }, { "type": "text", "text": "ORD-12345" } ] } ] }}Field template
Section titled “Field template”| Field | Tipe | Wajib | Keterangan |
|---|---|---|---|
name | string | Ya | Nama template (harus sudah APPROVED) |
language | object | Ya | Objek bahasa dengan field code |
components | array | Tidak | Array komponen dinamis (header, body, button) |
Field language
Section titled “Field language”| Field | Tipe | Wajib | Keterangan |
|---|---|---|---|
code | string | Ya | Kode bahasa/locale, misalnya "id", "en_US", "en" |
Field components[]
Section titled “Field components[]”| Field | Tipe | Wajib | Keterangan |
|---|---|---|---|
type | string | Ya | Jenis komponen: "header", "body", "button" |
parameters | array | Tidak | Parameter dinamis untuk komponen ini |
sub_type | string | Tidak | Sub-tipe untuk button: "url", "quick_reply" |
index | string/number | Tidak | Indeks button (0-based), untuk komponen button |
Parameter Tipe
Section titled “Parameter Tipe”Setiap parameter dalam parameters memiliki field type:
| Tipe | Contoh | Keterangan |
|---|---|---|
text | { "type": "text", "text": "John" } | Parameter teks |
image | { "type": "image", "image": { "link": "..." } } | Gambar di header |
document | { "type": "document", "document": { "link": "..." } } | Dokumen di header |
currency | { "type": "currency", "currency": { "fallback_value": "Rp 150.000", "code": "IDR", "amount_1000": 150000000 } } | Nilai mata uang |
coupon_code | { "type": "coupon_code", "coupon_code": "DISKON50" } | Kode kupon |
Contoh: Template dengan Button URL
Section titled “Contoh: Template dengan Button URL”{ "messaging_product": "whatsapp", "to": "6281234567890", "type": "template", "template": { "name": "payment_reminder", "language": { "code": "id" }, "components": [ { "type": "body", "parameters": [ { "type": "text", "text": "Budi Santoso" }, { "type": "currency", "currency": { "fallback_value": "Rp 250.000", "code": "IDR", "amount_1000": 250000000 } } ] }, { "type": "button", "sub_type": "url", "index": "0", "parameters": [ { "type": "text", "text": "INV-2026-001" } ] } ] }}Contoh Lengkap (Template Sederhana)
Section titled “Contoh Lengkap (Template Sederhana)”curl -X POST https://messaging.cpaas.id/v1/YOUR_PHONE_NUMBER_ID/messages \ -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{ "messaging_product": "whatsapp", "to": "6281234567890", "type": "template", "template": { "name": "order_confirmation", "language": { "code": "id" }, "components": [ { "type": "body", "parameters": [ { "type": "text", "text": "John Doe" }, { "type": "text", "text": "ORD-12345" } ] } ] } }'import requests
url = "https://messaging.cpaas.id/v1/YOUR_PHONE_NUMBER_ID/messages"headers = { "Authorization": "Bearer YOUR_API_KEY", "Content-Type": "application/json"}payload = { "messaging_product": "whatsapp", "to": "6281234567890", "type": "template", "template": { "name": "order_confirmation", "language": {"code": "id"}, "components": [ { "type": "body", "parameters": [ {"type": "text", "text": "John Doe"}, {"type": "text", "text": "ORD-12345"} ] } ] }}
response = requests.post(url, json=payload, headers=headers)print(response.json())const response = await fetch( 'https://messaging.cpaas.id/v1/YOUR_PHONE_NUMBER_ID/messages', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json', }, body: JSON.stringify({ messaging_product: 'whatsapp', to: '6281234567890', type: 'template', template: { name: 'order_confirmation', language: { code: 'id' }, components: [ { type: 'body', parameters: [ { type: 'text', text: 'John Doe' }, { type: 'text', text: 'ORD-12345' }, ], }, ], }, }), });const data = await response.json();console.log(data);Response
Section titled “Response”{ "messaging_product": "whatsapp", "messages": [ { "id": "msg_f7a816e2-8397-11f0-8e34-010203040506" } ]}Webhook Status yang Akan Anda Terima
Section titled “Webhook Status yang Akan Anda Terima”message.status.sent— Template berhasil dikirimmessage.status.delivered— Template sampai ke perangkat penerimamessage.status.read— Template dibaca oleh penerima
Selain itu, Anda juga dapat menerima event terkait status template itu sendiri:
| Event | Keterangan |
|---|---|
template_status_update | Status template berubah (APPROVED, REJECTED, PENDING) |
template_quality_update | Update kualitas template |
template_category_update | Perubahan kategori template oleh Meta |
Lihat halaman Webhook untuk detail format payload setiap event.