utility टेम्पलेट बनाएं, उसे Meta से मंज़ूर करवाएं, ऑर्डर भेजे जाने या अपॉइंटमेंट कल होने पर उसे एक ग्राहक को भेजें, और डिलीवरी तथा रीड स्टेटस ट्रैक करें।
जब कोई ऑर्डर भेजा जाता है या अपॉइंटमेंट कल होता है, तो आपका सिस्टम एक API कॉल करता है और ग्राहक को आपके बिज़नेस की ओर से एक WhatsApp मैसेज मिलता है: "नमस्ते John, आपका ऑर्डर #1234 भेज दिया गया है।"
मैसेज आगे बढ़ने पर उसका स्टेटस आपको वापस मिलता है (sent, delivered, read, या कारण के साथ failed), webhook से या API से पूछकर। मैसेज app2email के Activity Log और बातचीत में भी दिखता है।
WhatsApp किसी बिज़नेस को अपना सादा टेक्स्ट केवल तभी भेजने देता है जब ग्राहक के आपके नंबर पर आखिरी मैसेज को 24 घंटे से कम हुए हों। app2email सुरक्षा के लिए 15 मिनट पहले रोक देता है। शिपिंग अपडेट या अपॉइंटमेंट रिमाइंडर आमतौर पर ग्राहक के आखिरी बार लिखने के कई दिन बाद आता है, इसलिए सामान्य टेक्स्ट मैसेज 422 outside_24h_window के साथ अस्वीकार कर दिया जाएगा।
टेम्पलेट एक ऐसा मैसेज टेक्स्ट है जिसे Meta ने जांचकर मंज़ूर किया है। इसे किसी भी समय भेजा जा सकता है, इसके प्लेसहोल्डर ({{1}}, {{2}}, ...) में आपके अपने मान डालकर।
टेम्पलेट की एक श्रेणी होती है। ऑर्डर, डिलीवरी, अकाउंट और अपॉइंटमेंट के अपडेट UTILITY हैं। प्रचार MARKETING हैं। अंतिम श्रेणी Meta खुद तय करता है, इसलिए utility टेम्पलेट में ऑफ़र और बिक्री वाले शब्द न रखें।
whatsapp_payment_issue) के साथ विफल होता है।| Scope | इस गाइड में यह किसलिए है |
|---|---|
templates:manage | टेम्पलेट बनाना और बदलना (POST /templates, PATCH /templates/{name}) |
messages:read | टेम्पलेट का स्टेटस (GET /templates/{name}) और मैसेज का स्टेटस (GET /messages/{message_id}) पढ़ना |
messages:send | सूचना भेजना (POST /messages) |
webhooks:manage | स्टेटस इवेंट पाने वाला webhook जोड़ना (POST /webhooks) |
Default key (जो तब बनी थी जब keys में अनुमतियां नहीं होती थीं) में templates:manage नहीं है। उस scope वाली, या Full access (*) वाली key बनाएं। GET /v1/YOUR_NUMBER/me दिखाता है कि आपकी key के scopes क्या हैं।
पहले आज़माना। आपके अपने नंबर पर sandbox key (sandbox फ़्लैग वाली key, API key पेज पर) हर जांच असल में चलाती है और WhatsApp को कुछ नहीं भेजती। जवाब में "sandbox": true होता है, मैसेज id wamid.SANDBOX. से शुरू होते हैं, और message.status इवेंट sent, delivered और read फिर भी आते हैं। sandbox key टेम्पलेट नहीं बना सकती (403 sandbox_key), इसलिए टेम्पलेट सामान्य key से बनाएं।
बिना किसी अकाउंट के, POST https://api.app2email.com/v1/account/sandbox (बिना key, बिना body), या Management MCP सर्वर का create_sandbox टूल, डेमो नंबर 12025550100 के लिए तुरंत मिलने वाली sandbox key देता है। इसमें GET /templates और POST /messages हैं, इसलिए आप डेमो नंबर का कोई टेम्पलेट उसके नकली ग्राहकों को भेज सकते हैं: 12025550101 जवाब देता है, 12025550103 विफल होता है। देखें Sandbox।
क्रमांकित प्लेसहोल्डर वाला टेक्स्ट भेजें, और example में हर एक के लिए एक नमूना मान दें। Meta के समीक्षक नमूने पढ़ते हैं। नाम में छोटे अक्षर, अंक और अंडरस्कोर इस्तेमाल हो सकते हैं।
curl -s https://api.app2email.com/v1/YOUR_NUMBER/templates \
-H "Authorization: Bearer $A2E_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "order_update",
"language": "en",
"category": "UTILITY",
"components": [
{
"type": "BODY",
"text": "Hi {{1}}, your order {{2}} has shipped.",
"example": { "body_text": [["John", "#1234"]] }
}
]
}'const res = await fetch("https://api.app2email.com/v1/YOUR_NUMBER/templates", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.A2E_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
name: "order_update",
language: "en",
category: "UTILITY",
components: [
{
type: "BODY",
text: "Hi {{1}}, your order {{2}} has shipped.",
example: { body_text: [["John", "#1234"]] },
},
],
}),
});
console.log(res.status, await res.json());import os, requests
res = requests.post(
"https://api.app2email.com/v1/YOUR_NUMBER/templates",
headers={"Authorization": f"Bearer {os.environ['A2E_KEY']}"},
json={
"name": "order_update",
"language": "en",
"category": "UTILITY",
"components": [
{
"type": "BODY",
"text": "Hi {{1}}, your order {{2}} has shipped.",
"example": {"body_text": [["John", "#1234"]]},
}
],
},
)
print(res.status_code, res.json())जवाब में आपको क्या मिलता है (HTTP 201): टेम्पलेट Meta के पास समीक्षा में है।
{
"success": true,
"request_id": "c3ppl",
"template": {
"id": "2234567890",
"name": "order_update",
"language": "en",
"category": "UTILITY",
"status": "PENDING"
},
"note": "Submitted to WhatsApp for review (minutes to a day). You get a template.status_changed webhook event with the result, or GET https://api.app2email.com/v1/4976659348270/templates/order_update."
}अपॉइंटमेंट के लिए दूसरा टेम्पलेट उसी तरह बनाएं, जैसे appointment_reminder, टेक्स्ट Hi {{1}}, this is a reminder of your {{2}} tomorrow at {{3}}. Reply to this message if you need to change it. और नमूने [["Ava", "haircut", "10:30"]] के साथ।
टेम्पलेट WhatsApp Business Account के होते हैं: उस अकाउंट का हर नंबर उन्हें इस्तेमाल कर सकता है।
ट्रैकिंग बटन, जिसे Meta ने लिखा है। Meta की Template Library में तैयार utility टेक्स्ट हैं: GET /template-library?topic=ORDER_MANAGEMENT&usecase=SHIPMENT_CONFIRMATION उन्हें सूचीबद्ध करता है। components की जगह library_template_name के साथ एक बनाएं, और उसके बटन की वेबसाइट दें:
{
"name": "my_delivery_update",
"language": "en_US",
"category": "UTILITY",
"library_template_name": "delivery_update_1",
"library_template_button_inputs": [
{
"type": "URL",
"url": {
"base_url": "https://www.example.com/{{1}}",
"url_suffix_example": "https://www.example.com/order/1234"
}
}
]
}समीक्षा में कुछ मिनट से एक दिन तक लगता है। आपको दो में से एक तरीके से पता चलता है।
template.status_changed webhook इवेंट (WhatsApp Business Account के हर नंबर को भेजा जाता है):
{
"id": "evt_Xq3k9m2Lw8Rt5Yp1Zs01",
"type": "template.status_changed",
"created": "2026-11-06T01:00:00.000Z",
"number": "4976659348270",
"data": {
"template": { "name": "order_update", "language": "en", "id": "1234567890123456" },
"status": "APPROVED",
"can_send": true,
"timestamp": "2026-11-06T01:00:00.000Z"
}
}या पूछें: GET /v1/YOUR_NUMBER/templates/order_update (scope messages:read)। यह कैश से नहीं, WhatsApp से पढ़ा जाता है, इसलिए अभी बदला हुआ स्टेटस दिखता है।
curl -s https://api.app2email.com/v1/YOUR_NUMBER/templates/order_update \
-H "Authorization: Bearer $A2E_KEY"const res = await fetch("https://api.app2email.com/v1/YOUR_NUMBER/templates/order_update", {
headers: { Authorization: `Bearer ${process.env.A2E_KEY}` },
});
const { versions } = await res.json();
console.log(versions.map((v) => [v.language, v.status, v.rejected_reason]));res = requests.get(
"https://api.app2email.com/v1/YOUR_NUMBER/templates/order_update",
headers={"Authorization": f"Bearer {os.environ['A2E_KEY']}"},
)
for v in res.json()["versions"]:
print(v["language"], v["status"], v.get("rejected_reason"))जवाब में आपको क्या मिलता है: हर भाषा के लिए versions में एक एंट्री, जिसमें status, can_send, उसे कौन-से मान needs हैं, और एक पूरा example_request होता है, जिसे मान बदलकर आप भेज सकते हैं।
{
"success": true,
"request_id": "k7qtm",
"name": "order_update",
"versions": [
{
"id": "1234567890",
"name": "order_update",
"language": "en",
"category": "UTILITY",
"status": "APPROVED",
"can_send": true,
"needs": { "body": "2 text values" },
"example_request": {
"to": "61412345678",
"type": "template",
"template": {
"name": "order_update",
"language": { "code": "en" },
"components": [
{
"type": "body",
"parameters": [
{ "type": "text", "text": "John" },
{ "type": "text", "text": "#1234" }
]
}
]
}
}
}
]
}अस्वीकृति ऐसी दिखती है: status REJECTED है, can_send false है, और rejected_reason (GET /templates/{name} में) या reason (template.status_changed इवेंट में) बताता है कि क्यों। टेक्स्ट ठीक करें और PATCH /v1/YOUR_NUMBER/templates/order_update और नए components से उसे फिर भेजें। केवल APPROVED, REJECTED या PAUSED टेम्पलेट बदले जा सकते हैं, और मंज़ूर किया हुआ दिन में अधिकतम एक बार और 30 दिन में 10 बार।
अगर Meta ने टेम्पलेट को दूसरी श्रेणी में डाल दिया, तो GET /templates/{name} में previous_category और correct_category उसे दिखाते हैं।
हर सिस्टम के लिए एक webhook काफ़ी है: नंबर के हर webhook को हर इवेंट मिलता है, और आप जिन प्रकारों को संभालते हैं उन्हें चुन लेते हैं। प्रति नंबर अधिकतम 5। Scope webhooks:manage।
curl -s https://api.app2email.com/v1/YOUR_NUMBER/webhooks \
-H "Authorization: Bearer $A2E_KEY" \
-H "Content-Type: application/json" \
-d '{ "url": "https://hooks.example.com/app2email" }'const res = await fetch("https://api.app2email.com/v1/YOUR_NUMBER/webhooks", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.A2E_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ url: "https://hooks.example.com/app2email" }),
});
const { webhook } = await res.json();
console.log(webhook.id, webhook.secret); // store the secret: it signs every eventres = requests.post(
"https://api.app2email.com/v1/YOUR_NUMBER/webhooks",
headers={"Authorization": f"Bearer {os.environ['A2E_KEY']}"},
json={"url": "https://hooks.example.com/app2email"},
)
webhook = res.json()["webhook"]
print(webhook["id"], webhook["secret"]) # store the secret: it signs every eventजवाब में आपको क्या मिलता है: webhook, उसके id और उसके secret (whsec_...) के साथ। secret को अपने सर्वर पर रखें।
अभी कोई सार्वजनिक पता नहीं है? GET /v1/YOUR_NUMBER/events?wait=25 इसके बजाय वही इवेंट ले आता है। जवाब का cursor संभालकर रखें और अगली कॉल में उसे after के रूप में दें।
टेम्पलेट ग्राहक के नंबर पर भेजें (पहले देश कोड, सिर्फ़ अंक), हर प्लेसहोल्डर के लिए क्रम से एक मान के साथ।
दो अतिरिक्त चीज़ें इसे प्रोडक्शन के लिए सुरक्षित बनाती हैं:
Idempotency-Key हेडर: इस सूचना के लिए अनोखा मान, जैसे आपका ऑर्डर नंबर और इवेंट। अगर आपका जॉब दो बार चले, या टाइमआउट के बाद आप दोबारा कोशिश करें, तो मैसेज फिर नहीं भेजा जाता।callback_data: आपका अपना छोटा संदर्भ (512 अक्षर तक)। यह इस मैसेज के message.status इवेंट में data.callback_data के रूप में लौटता है, ताकि आप पहले मैसेज id सहेजे बिना स्टेटस को अपने ऑर्डर से मिला सकें।curl -s https://api.app2email.com/v1/YOUR_NUMBER/messages \
-H "Authorization: Bearer $A2E_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: order-1234-shipped" \
-d '{
"to": "61412345678",
"type": "template",
"template": {
"name": "order_update",
"language": { "code": "en" },
"components": [
{
"type": "body",
"parameters": [
{ "type": "text", "text": "John" },
{ "type": "text", "text": "#1234" }
]
}
]
},
"callback_data": "order-1234"
}'async function sendShipped(order) {
const res = await fetch("https://api.app2email.com/v1/YOUR_NUMBER/messages", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.A2E_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": `order-${order.id}-shipped`,
},
body: JSON.stringify({
to: order.phone, // "61412345678"
type: "template",
template: {
name: "order_update",
language: { code: "en" },
components: [
{
type: "body",
parameters: [
{ type: "text", text: order.firstName },
{ type: "text", text: `#${order.id}` },
],
},
],
},
callback_data: `order-${order.id}`,
}),
});
const body = await res.json();
if (!res.ok) throw new Error(`${body.error.code}: ${body.error.how_to_fix}`);
return body.message_id; // keep it with the order
}def send_shipped(order):
res = requests.post(
"https://api.app2email.com/v1/YOUR_NUMBER/messages",
headers={
"Authorization": f"Bearer {os.environ['A2E_KEY']}",
"Idempotency-Key": f"order-{order['id']}-shipped",
},
json={
"to": order["phone"], # "61412345678"
"type": "template",
"template": {
"name": "order_update",
"language": {"code": "en"},
"components": [
{
"type": "body",
"parameters": [
{"type": "text", "text": order["first_name"]},
{"type": "text", "text": f"#{order['id']}"},
],
}
],
},
"callback_data": f"order-{order['id']}",
},
)
body = res.json()
if not res.ok:
raise RuntimeError(f"{body['error']['code']}: {body['error']['how_to_fix']}")
return body["message_id"] # keep it with the orderजवाब में आपको क्या मिलता है (HTTP 200): WhatsApp ने मैसेज स्वीकार कर लिया। text वह मैसेज है जैसा ग्राहक उसे देखता है।
{
"success": true,
"request_id": "kxrkf",
"message_id": "wamid.HBgLNjE0MTIzNDU2NzgVAgARGBJTQU1QTEVfVEVTVF9FVkVOVAA=",
"status": "accepted",
"from": "4976659348270",
"to": "61412345678",
"template": { "name": "order_update", "language": "en", "category": "UTILITY" },
"text": "Hi John, your order #1234 has shipped.",
"conversation_url": "https://www.app2email.com/conversation/61412345678_4976659348270_...",
"note": "accepted by WhatsApp. delivery and read status appear in your app2email Activity Log (WhatsApp sent).",
"contacts": [{ "input": "61412345678", "wa_id": "61412345678" }]
}बनाते समय body में "dry_run": true जोड़ें। हर चीज़ असली भेजने की तरह जांची जाती है (टेम्पलेट के मान, नंबर, Do Not Call सूची, मासिक सीमा) और जवाब में ठीक वही WhatsApp मैसेज दिखता है। कुछ भी भेजा, लॉग या गिना नहीं जाता।
वही कॉल, appointment_reminder टेम्पलेट के साथ। आप इसे अभी अपने रोज़ के जॉब से भेज सकते हैं, या send_at (समय क्षेत्र के साथ ISO 8601, 1 मिनट से 29 दिन आगे तक) से app2email को समय दे सकते हैं:
{
"to": "61412345678",
"type": "template",
"template": {
"name": "appointment_reminder",
"language": { "code": "en" },
"components": [
{
"type": "body",
"parameters": [
{ "type": "text", "text": "Ava" },
{ "type": "text", "text": "haircut" },
{ "type": "text", "text": "10:30" }
]
}
]
},
"send_at": "2026-12-01T09:00:00+11:00",
"callback_data": "appt-5521"
}शेड्यूल किया गया मैसेज HTTP 202 के साथ status: "scheduled", scheduled_for और एक ब्रॉडकास्ट code लौटाता है। हर चीज़ एक साथ जांची जाती है, और Do Not Call सूची और मासिक सीमा समय आने पर फिर से जांची जाती है। अगर अपॉइंटमेंट रद्द हो जाए, तो POST /v1/YOUR_NUMBER/broadcasts/{code}/cancel से मैसेज रद्द करें।
app2email के अपने Book-and-Pay से की गई बुकिंग को पुष्टि और रिमाइंडर बिना किसी कोड के मिल जाते हैं: यह अपने utility टेम्पलेट खुद बनाता है और विंडो बंद होने पर उन्हें इस्तेमाल करता है। देखें WhatsApp पर अपॉइंटमेंट बुकिंग।
अगर टेम्पलेट दस्तावेज़ हेडर के साथ मंज़ूर हुआ था, तो हर मैसेज के साथ PDF भेजें: link के रूप में जिसे app2email डाउनलोड करता है, filename के साथ base64 data के रूप में, या POST /media से मिले मीडिया id के रूप में। टेम्पलेट का अपना नमूना दस्तावेज़ भेजने के लिए हेडर छोड़ दें। दस्तावेज़ 100 MB तक हो सकते हैं।
{
"to": "61412345678",
"type": "template",
"template": {
"name": "invoice_ready",
"language": { "code": "en" },
"components": [
{
"type": "header",
"parameters": [
{
"type": "document",
"document": { "data": "JVBERi0xLjQKJ...", "filename": "invoice-1234.pdf" }
}
]
},
{
"type": "body",
"parameters": [{ "type": "text", "text": "#1234" }]
}
]
}
}अगर टेम्पलेट में प्लेसहोल्डर वाला URL बटन है (जैसे ऊपर वाला Template Library का), तो पते का अंतिम हिस्सा बटन कॉम्पोनेंट के रूप में दें। index बटन की स्थिति है, "0" से शुरू:
{
"type": "button",
"sub_type": "url",
"index": "0",
"parameters": [{ "type": "text", "text": "order/1234" }]
}पक्का नहीं कि टेम्पलेट को क्या चाहिए? GET /templates/{name} में needs और example_request हर हेडर, body और बटन का मान सूचीबद्ध करते हैं।
ग्राहक को आपके बिज़नेस के नाम से एक मैसेज दिखता है, जिसमें टेम्पलेट का टेक्स्ट और उसमें आपके मान होते हैं, साथ में दस्तावेज़ या बटन, अगर टेम्पलेट में है। अगर वे जवाब देते हैं, तो 24 घंटे की विंडो खुल जाती है और आप सामान्य मैसेज से उत्तर दे सकते हैं।
आपकी तरफ़, मैसेज के आगे बढ़ने पर message.status इवेंट आते हैं। status है sent, delivered, read या failed (वॉइस मैसेज के लिए played भी, और clicked तथा deleted)।
{
"id": "evt_Xq3k9m2Lw8Rt5Yp1Zs01",
"type": "message.status",
"created": "2026-11-06T01:00:00.000Z",
"number": "4976659348270",
"data": {
"message_id": "wamid.HBgLNjE0MTIzNDU2NzgVAgARGBJTQU1QTEVfVEVTVF9FVkVOVAA=",
"to": "61412345678",
"status": "delivered",
"timestamp": "2026-11-06T01:00:00.000Z",
"sent_by": "api",
"whatsapp_status": "delivered",
"recipient_user_id": "AU.1234567890123456",
"pricing": { "billable": true, "pricing_model": "PMP", "type": "regular", "category": "utility" },
"callback_data": "order-1234"
}
}जो मैसेज डिलीवर नहीं हो पाया, वह message.failed इवेंट के रूप में भी आता है, उसी डेटा के साथ और एक error के साथ जिसमें Meta का code, app2email का error_code और how_to_fix होता है:
{
"id": "evt_Xq3k9m2Lw8Rt5Yp1Zs01",
"type": "message.failed",
"created": "2026-11-06T01:00:00.000Z",
"number": "4976659348270",
"data": {
"message_id": "wamid.HBgLNjE0MTIzNDU2NzgVAgARGBJTQU1QTEVfVEVTVF9FVkVOVAA=",
"to": "61412345678",
"status": "failed",
"timestamp": "2026-11-06T01:00:00.000Z",
"error": {
"code": 131026,
"message": "Message Undeliverable.",
"title": "Message undeliverable",
"details": "Message Undeliverable.",
"error_code": "recipient_unreachable",
"how_to_fix": "WhatsApp could not deliver to this number. Check it is a WhatsApp number written with its country code (digits only, eg 61412345678), and that the person uses an up to date WhatsApp.",
"is_retriable": false
},
"sent_by": "api",
"whatsapp_status": "failed"
}
}इवेंट क्रम से बाहर आ सकते हैं, इसलिए read अपने delivered से पहले आ सकता है। हर message_id के लिए सबसे आगे का स्टेटस रखें और उसे पीछे न करें।
या स्टेटस पूछें GET /v1/YOUR_NUMBER/messages/{message_id} से (scope messages:read; id को URL-encode करें)। यह नंबर से भेजे गए किसी भी मैसेज के लिए काम करता है, और इसमें स्टेटस, हर चरण का समय, विफल होने का कारण, और ग्राहक का जवाब या बटन टैप होता है।
curl -s "https://api.app2email.com/v1/YOUR_NUMBER/messages/wamid.HBgLNjE0MTIzNDU2NzgVAgARGBJTQU1QTEVfVEVTVF9FVkVOVAA%3D" \
-H "Authorization: Bearer $A2E_KEY"const id = encodeURIComponent(messageId);
const res = await fetch(`https://api.app2email.com/v1/YOUR_NUMBER/messages/${id}`, {
headers: { Authorization: `Bearer ${process.env.A2E_KEY}` },
});
const msg = await res.json();
console.log(msg.status, msg.times);from urllib.parse import quote
res = requests.get(
f"https://api.app2email.com/v1/YOUR_NUMBER/messages/{quote(message_id, safe='')}",
headers={"Authorization": f"Bearer {os.environ['A2E_KEY']}"},
)
msg = res.json()
print(msg["status"], msg.get("times"))जवाब में आपको क्या मिलता है: status इनमें से एक होता है: accepted, sent, delivered, read, failed, deleted, queued या unknown। जो चरण अभी तक नहीं आए, वे times में नहीं होते।
{
"success": true,
"request_id": "p4n8w",
"message_id": "wamid.HBgLNjE0MTIzNDU2NzgVAgARGBJTQU1QTEVfVEVTVF9FVkVOVAA=",
"to": "61412345678",
"status": "read",
"sent_by": "api",
"text": "Hi John, your order #1234 has shipped.",
"times": {
"submitted": "2026-11-06T01:00:00Z",
"accepted": "2026-11-06T01:00:01Z",
"sent": "2026-11-06T01:00:02Z",
"delivered": "2026-11-06T01:00:04Z",
"read": "2026-11-06T01:12:40Z"
},
"conversation_url": "https://www.app2email.com/conversation/61412345678_4976659348270_..."
}एक साथ कई मैसेज के लिए, GET /v1/YOUR_NUMBER/messages?status=failed&since=2026-11-06T00:00:00Z विफल मैसेज की सूची देता है, और GET /v1/YOUR_NUMBER/stats?from=&to= किसी अवधि के लिए भेजे, डिलीवर हुए, पढ़े गए और विफल मैसेज की गिनती देता है।
app2email एक तय मासिक प्लान लेता है; हर सूचना प्लान का एक मैसेज गिनी जाती है, प्रति मैसेज कोई अतिरिक्त मार्कअप नहीं (कीमतें)। Meta भी टेम्पलेट मैसेज के लिए शुल्क लेता है, सीधे आपके WhatsApp Business Account के भुगतान के तरीके पर। कीमत टेम्पलेट की श्रेणी और ग्राहक के देश पर निर्भर करती है, और ज़्यादातर देशों में utility टेम्पलेट मार्केटिंग टेम्पलेट से सस्ते होते हैं। यह ऑर्डर और अपॉइंटमेंट अपडेट को पूरी तरह सूचना देने वाला रखने का एक और कारण है। स्टेटस इवेंट में pricing ऑब्जेक्ट दिखाता है कि Meta ने हर मैसेज को कैसे गिना (billable, category), और GET /v1/YOUR_NUMBER/usage में meta_pricing महीने को श्रेणी के अनुसार अनुमानित लागत के साथ जोड़ता है। शुरू करने से पहले अनुमान के लिए WhatsApp प्राइसिंग कैलकुलेटर इस्तेमाल करें।
हर इवेंट में हेडर X-App2email-Signature: t=<unix seconds>,v1=<hex> होता है। v1 मान "<t>.<raw body>" का HMAC-SHA256 है, जिसमें webhook का secret (whsec_..., उपसर्ग समेत) key है। हर v1= जांचें (secret बदलने के बाद जब तक पुराना secret रखा जाता है तब तक दो होते हैं), उसे कच्ची body पर ठीक वैसे ही निकालें जैसी मिली थी, और पुराने t को अस्वीकार करें। Meta के webhooks के लिए लिखे कोड के लिए X-Hub-Signature-256: sha256=<hex> (कच्ची body का HMAC-SHA256, केवल मौजूदा secret) भी मौजूद है।
import crypto from "node:crypto";
import express from "express";
export function verifyWebhook(rawBody, header, secret, toleranceSeconds = 300) {
const t = /(?:^|,)\s*t=(\d+)/.exec(header ?? "")?.[1];
const v1 = [...(header ?? "").matchAll(/(?:^|,)\s*v1=([0-9a-f]+)/g)].map((m) => m[1]);
if (!t || v1.length === 0 || Math.abs(Date.now() / 1000 - Number(t)) > toleranceSeconds) return false;
const expected = crypto.createHmac("sha256", secret).update(t + ".").update(rawBody).digest("hex");
return v1.some((v) => v.length === expected.length && crypto.timingSafeEqual(Buffer.from(v), Buffer.from(expected)));
}
const app = express();
app.post("/app2email", express.raw({ type: "application/json" }), async (req, res) => {
if (!verifyWebhook(req.body, req.get("X-App2email-Signature"), process.env.WEBHOOK_SECRET)) return res.sendStatus(401);
const event = JSON.parse(req.body);
if (await alreadySeen(req.get("X-App2email-Delivery"))) return res.sendStatus(200); // a retry
if (event.type === "message.status") await saveStatus(event.data.callback_data, event.data.message_id, event.data.status, event.data.error);
if (event.type === "template.status_changed") await saveTemplateStatus(event.data.template, event.data.status, event.data.reason);
res.sendStatus(200); // within 10 seconds
});import hashlib, hmac, json, os, re, time
from flask import Flask, request
def verify_webhook(raw_body: bytes, header: str, secret: str, tolerance: int = 300) -> bool:
t = re.search(r"(?:^|,)\s*t=(\d+)", header or "")
v1 = re.findall(r"(?:^|,)\s*v1=([0-9a-f]+)", header or "")
if not t or not v1 or abs(time.time() - int(t.group(1))) > tolerance:
return False
expected = hmac.new(secret.encode(), t.group(1).encode() + b"." + raw_body, hashlib.sha256).hexdigest()
return any(hmac.compare_digest(v, expected) for v in v1)
app = Flask(__name__)
@app.post("/app2email")
def app2email():
raw = request.get_data()
if not verify_webhook(raw, request.headers.get("X-App2email-Signature"), os.environ["WEBHOOK_SECRET"]):
return "", 401
if already_seen(request.headers.get("X-App2email-Delivery")):
return "", 200 # a retry
event = json.loads(raw)
if event["type"] == "message.status":
d = event["data"]
save_status(d.get("callback_data"), d["message_id"], d["status"], d.get("error"))
return "", 200 # within 10 seconds10 सेकंड के भीतर 2xx स्टेटस से जवाब दें। नहीं तो इवेंट 10 सेकंड, 1 मिनट, 5 मिनट, 30 मिनट, 1, 2, 4, 8 और 16 घंटे बाद फिर भेजा जाता है। X-App2email-Delivery (इवेंट का id, evt_...) हर दोबारा कोशिश पर वही रहता है, इसलिए उसे सहेजें और जिस इवेंट को आप संभाल चुके हैं उसे छोड़ दें। धीमा काम जवाब देने के बाद करें।
ऐसा Idempotency-Key हेडर भेजें जो सूचना का हो, कोशिश का नहीं: order-1234-shipped, appt-5521-reminder। 24 घंटे के भीतर वही key वाली वही रिक्वेस्ट दोबारा नहीं भेजी जाती; उसे पहला जवाब मिलता है, हेडर Idempotent-Replayed: true के साथ।
422 idempotency_key_reused। अलग मैसेज के लिए नई key इस्तेमाल करें।409 idempotency_request_in_progress। रुकें और उसी key से दोबारा कोशिश करें।409 idempotency_request_interrupted। हो सकता है मैसेज चला गया हो: नई key से भेजने से पहले GET /messages?to=61412345678 जांचें।key 24 घंटे तक रखी जाती है। ऐसे जॉब के लिए जो कई दिन बाद फिर चल सकता है, message_id को भी ऑर्डर इवेंट के साथ अपने डेटाबेस में रखें और जब वह पहले से हो तो न भेजें।
हर जवाब में X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset (दोबारा पूरा होने तक के सेकंड) और X-RateLimit-Policy होते हैं। सीमा पार करने पर आपको Retry-After हेडर और error.retry_after_seconds के साथ 429 rate_limited मिलता है: उतनी देर रुकें, फिर वही रिक्वेस्ट दोबारा भेजें।
500, 502, 503 या टाइमआउट: बढ़ते अंतराल के साथ कुछ बार दोबारा कोशिश करें, उसी Idempotency-Key के साथ।429 too_many_messages_to_recipient या 429 whatsapp_rate_limit: WhatsApp की अपनी सीमा। सेकंड नहीं, मिनटों के लिए रुकें।429 monthly_limit_reached: प्लान के मैसेज खत्म हो गए हैं। अगले बिलिंग महीने या अपग्रेड तक दोबारा कोशिश न करें।4xx: बिना बदलाव के दोबारा कोशिश न करें। error.code से तय करें और how_to_fix का पालन करें। error.is_retriable बताता है कि वही रिक्वेस्ट बाद में चल सकती है या नहीं।मंज़ूर किया हुआ टेम्पलेट किसी भी समय जा सकता है। सामान्य टेक्स्ट, चित्र या दस्तावेज़ केवल ग्राहक के आखिरी मैसेज के 24 घंटे के भीतर काम करता है (app2email 15 मिनट पहले रोक देता है)। इसलिए जब ग्राहक जवाब में पूछे "Can I change the address?", तो आप सादे टेक्स्ट में जवाब दे सकते हैं। GET /v1/YOUR_NUMBER/conversations/61412345678 window_open और window_closes_at दिखाता है।
Do Not Call सूची और ऑप्ट-इन नियम (/settings/optin) मार्केटिंग टेम्पलेट पर लागू होते हैं। Do Not Call सूची में मौजूद ग्राहक को ऑर्डर अपडेट जैसे utility टेम्पलेट फिर भी मिल सकते हैं।
हर टेम्पलेट की श्रेणी Meta खुद तय करता है, और बाद में बदल भी सकता है। अगर कोई टेम्पलेट MARKETING बन जाए, तो उस पर Do Not Call सूची और ऑप्ट-इन नियम लागू होते हैं और उसका बिल मार्केटिंग के रूप में बनता है। template.status_changed इवेंट पर नज़र रखें, और अपनी सूचनाओं के टेक्स्ट में प्रचार न रखें।
WhatsApp लोगों की प्रतिक्रिया के आधार पर हर टेम्पलेट की गुणवत्ता भी आंकता है। RED quality_score वाला टेम्पलेट रोका जा सकता है, और रोका गया टेम्पलेट 422 template_paused लौटाता है।
हर त्रुटि JSON होती है, जिसमें error.code, message, how_to_fix और सपोर्ट को बताने के लिए एक request_id होता है। हर कोड के लिए त्रुटियां देखें।
| कोड | कब | क्या करें |
|---|---|---|
403 insufficient_scope | key में कोई scope नहीं है (details.required_scope) | ज़रूरत के अनुसार templates:manage, messages:send, messages:read या webhooks:manage वाली key इस्तेमाल करें |
403 sandbox_key | sandbox key से टेम्पलेट बनाना या बदलना | टेम्पलेट के लिए सामान्य key इस्तेमाल करें |
400 invalid_template_category | category MARKETING, UTILITY या AUTHENTICATION नहीं है | ऑर्डर और अपॉइंटमेंट अपडेट के लिए UTILITY इस्तेमाल करें |
400 invalid_template_components | किसी कॉम्पोनेंट में type नहीं है (HEADER, BODY, FOOTER, BUTTONS) | कॉम्पोनेंट WhatsApp के अपने फ़ॉर्मैट में होते हैं; ऊपर के उदाहरण से मिलाएं |
409 template_already_exists | यही नाम और भाषा मौजूद है (या हटाई जा रही है) | दूसरा नाम या भाषा इस्तेमाल करें |
422 template_rejected | WhatsApp ने टेम्पलेट स्वीकार नहीं किया | whatsapp_error के अनुसार उसे ठीक करें और फिर भेजें |
404 template_not_found | नाम अकाउंट के किसी टेम्पलेट से नहीं मिलता | नाम छोटे अक्षरों में हों और ठीक मिलें; details.available_templates देखें |
422 template_not_approved | टेम्पलेट लंबित, अस्वीकृत, रुका हुआ या अक्षम है | मंज़ूरी का इंतज़ार करें, या उसे ठीक करें; GET /templates/{name} जांचें |
422 template_parameters_invalid | मान टेम्पलेट से मेल नहीं खाते | details.problems और example_request से body ठीक करें |
422 template_parameter_count_mismatch | Meta त्रुटि 132000: मानों की संख्या गलत | हर प्लेसहोल्डर के लिए एक मान भेजें; example_request देखें |
422 template_paused | Meta त्रुटि 132015: कम गुणवत्ता के कारण रोका गया | दूसरा टेम्पलेट इस्तेमाल करें, या इसे बदलें |
422 outside_24h_window | आपने विंडो के बाहर टेम्पलेट नहीं, सादा टेक्स्ट भेजा | इसके बजाय मंज़ूर किया हुआ टेम्पलेट भेजें |
403 whatsapp_payment_issue | Meta त्रुटि 131042: Meta आपके WhatsApp अकाउंट से भुगतान नहीं ले सका | WhatsApp Manager में भुगतान का तरीका जोड़ें या ठीक करें |
422 recipient_unreachable | Meta त्रुटि 131026 | जांचें कि नंबर में देश कोड है और वह WhatsApp इस्तेमाल करता है |
422 media_download_failed | दस्तावेज़ का link डाउनलोड नहीं हो सका | ऐसा लिंक इस्तेमाल करें जो बिना लॉगिन के खुलता हो, या base64 data भेजें |
422 idempotency_key_reused | वही Idempotency-Key, अलग body | अलग मैसेज के लिए नई key इस्तेमाल करें |
429 rate_limited | इस key के लिए बहुत ज़्यादा कॉल | Retry-After सेकंड रुकें, फिर दोबारा कोशिश करें |
429 monthly_limit_reached | इस महीने प्लान के मैसेज खत्म हो गए हैं | अगले बिलिंग महीने का इंतज़ार करें, या अपग्रेड करें |
404 message_not_found | इस नंबर से उस id का कोई मैसेज नहीं है | भेजने के जवाब का message_id इस्तेमाल करें, URL-encoded |
webhook से मैसेज पाएं और टेक्स्ट, बटन और सूचियों से जवाब दें।
एक सूची या सेगमेंट को एक टेम्पलेट, सहमति और Do Not Call सूची के साथ।
किसी एजेंट को MCP सर्वर से जोड़ें और उसे मैसेज पढ़ने और भेजने दें।
बातचीत का owner सेट करें ताकि जब कोई व्यक्ति जवाब दे, तब आपका बॉट किनारे हट जाए।
चैट में भुगतान का अनुरोध भेजें और भुगतान होने पर इवेंट पाएं।