[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M773XGHD9CD5W1XKT7W75VGH":3,"skill-same:01M773XGHD9CD5W1XKT7W75VGH":52},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":30,"commitSha":31,"skillDirectory":32,"forksCount":33,"repositoryHtmlUrl":34,"repositoryHomepageUrl":6,"ownerHtmlUrl":35,"ownerBlogUrl":6,"ownerDescription":36,"updatedAt":37,"install":38,"resources":51},"01M773XGHD9CD5W1XKT7W75VGH","whatsapp-business-api",null,"WhatsApp Business Platform (Cloud API) - Complete reference for sending messages, receiving webhooks, managing templates, media, phone numbers, and account operations. Language-agnostic patterns for any project. Trigger: When working with WhatsApp Business API, Cloud API, WhatsApp messaging, WhatsApp webhooks, message templates, WhatsApp integration, Meta Graph API for WhatsApp.","davidcoachdev\u002Fdcfiles","davidcoachdev","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F69812733?v=4","01M758C4BR16TAV1N47W319E9V","David H. Caycedo Blum.","01M758C4CCZA2ZYGA0BGMXCDRH",1,"MIT","https:\u002F\u002Fgithub.com\u002Fdavidcoachdev\u002Fdcfiles\u002Fblob\u002Fmain\u002Fconfig\u002F.config\u002Fopencode\u002Fskills\u002Fwhatsapp-business-api\u002FSKILL.md",[],[],"2026-11-12 13:55:43",false,"---\nname: whatsapp-business-api\ndescription: >\n  WhatsApp Business Platform (Cloud API) - Complete reference for sending messages,\n  receiving webhooks, managing templates, media, phone numbers, and account operations.\n  Language-agnostic patterns for any project.\n  Trigger: When working with WhatsApp Business API, Cloud API, WhatsApp messaging,\n  WhatsApp webhooks, message templates, WhatsApp integration, Meta Graph API for WhatsApp.\nlicense: MIT\nmetadata:\n  author: gentle-ai\n  version: \"1.0\"\n  api_version: \"v21.0\"\n  last_updated: \"2026-03-31\"\n---\n\n## When to Use\n\n- Integrating WhatsApp Business Platform (Cloud API) into any project\n- Sending messages (text, media, interactive, templates) via WhatsApp\n- Receiving and processing inbound messages via webhooks\n- Managing message templates (create, approve, categorize)\n- Uploading\u002Fdownloading media files\n- Managing phone numbers and WABA (WhatsApp Business Account)\n- Building chatbots, notification systems, CRM integrations\n- Implementing conversation-based messaging workflows\n\n## Architecture Overview\n\n```\n┌──────────────┐     POST \u002F{version}\u002F{phone_id}\u002Fmessages     ┌─────────────────┐\n│   Your App   │ ──────────────────────────────────────────► │  Meta Graph API │\n│  (Any Lang)  │ ◄────────────────────────────────────────── │  graph.facebook │\n└──────────────┘         JSON Response                       │     .com        │\n       ▲                                                      └────────┬────────┘\n       │                                                              │\n       │  POST (events)                                               │\n       │  GET  (verification)                                         │\n       └──────────────────────────────────────────────────────────────┘\n                     Webhook Push Notifications\n```\n\n### Key Concepts\n\n| Concept | Description |\n|---------|-------------|\n| **WABA** | WhatsApp Business Account — the top-level container |\n| **Phone Number ID** | Unique ID for each registered phone number |\n| **24-Hour Window** | Free-form messages only within 24h of customer's last reply |\n| **Template Messages** | Pre-approved messages for initiating conversations outside 24h window |\n| **Conversation-Based Pricing** | Meta charges per 24h conversation window, not per message |\n| **Messaging Tiers** | New numbers: 250\u002F24h → scale to unlimited via verification + quality |\n\n## Base URL & Authentication\n\n### Base URL\n\n```\nhttps:\u002F\u002Fgraph.facebook.com\u002Fv21.0\n```\n\nCurrent stable version: **v21.0** (as of early 2026). Check Meta docs for latest.\n\n### Authentication\n\n```\nAuthorization: Bearer {ACCESS_TOKEN}\nContent-Type: application\u002Fjson\n```\n\n### Access Token Types\n\n| Type | Lifespan | Use Case |\n|------|----------|----------|\n| **Temporary** | ~24 hours | Testing\u002Fdevelopment only |\n| **System User Token** | Never expires | Production — generate via Business Manager |\n\n### Required Permissions\n\n- `whatsapp_business_messaging` — Send\u002Freceive messages\n- `whatsapp_business_management` — Manage templates, phone numbers, account\n\n### Permanent Token Setup (Production)\n\n1. Go to **Meta Business Manager** → Business Settings\n2. **Users → System Users → Add** (role: Admin)\n3. Select user → **Assign Assets** → select your WhatsApp app → **Full Control**\n4. **Generate Token** with permissions: `whatsapp_business_messaging`, `whatsapp_business_management`\n5. Copy token — shown only once\n6. Store as environment variable: `WA_ACCESS_TOKEN`\n\n## Environment Variables\n\n```bash\n# Required\nWA_ACCESS_TOKEN=your_permanent_access_token\nWA_PHONE_NUMBER_ID=your_phone_number_id\nWA_VERIFY_TOKEN=your_webhook_verify_token   # Custom string you define\nWA_APP_SECRET=your_app_secret               # For webhook signature verification\n\n# Optional\nWA_API_VERSION=v21.0\nWA_BASE_URL=https:\u002F\u002Fgraph.facebook.com\nWA_WABA_ID=your_waba_id                     # WhatsApp Business Account ID\n```\n\n## Core Endpoints Reference\n\n### Messages\n\n| Method | Endpoint | Description |\n|--------|----------|-------------|\n| POST | `\u002F{version}\u002F{phone-number-id}\u002Fmessages` | Send any message type |\n\n### Media\n\n| Method | Endpoint | Description |\n|--------|----------|-------------|\n| POST | `\u002F{version}\u002F{phone-number-id}\u002Fmedia` | Upload media |\n| GET | `\u002F{version}\u002F{media-id}` | Get media URL (returns `url` field) |\n| GET | `{url}` (from GET response) | Download binary media |\n\n### Phone Numbers\n\n| Method | Endpoint | Description |\n|--------|----------|-------------|\n| GET | `\u002F{version}\u002F{waba-id}\u002Fphone_numbers` | List registered numbers |\n| GET | `\u002F{version}\u002F{phone-number-id}` | Get phone number details |\n| POST | `\u002F{version}\u002F{phone-number-id}\u002Fregister` | Register a number |\n| POST | `\u002F{version}\u002F{phone-number-id}\u002Fderegister` | Deregister a number |\n\n### Templates (Business Management API)\n\n| Method | Endpoint | Description |\n|--------|----------|-------------|\n| GET | `\u002F{version}\u002F{waba-id}\u002Fmessage_templates` | List templates |\n| POST | `\u002F{version}\u002F{waba-id}\u002Fmessage_templates` | Create template |\n| GET | `\u002F{version}\u002F{template-id}` | Get template details |\n| DELETE | `\u002F{version}\u002F{template-id}` | Delete template |\n\n### Webhooks\n\n| Method | Endpoint | Description |\n|--------|----------|-------------|\n| GET | `\u002F{your-webhook-url}` | Verification (Meta sends this) |\n| POST | `\u002F{your-webhook-url}` | Event notifications |\n| POST | `\u002F{version}\u002F{waba-id}\u002Fsubscribed_apps` | Subscribe app to WABA |\n| GET | `\u002F{version}\u002F{waba-id}\u002Fsubscribed_apps` | Verify subscription |\n\n## Sending Messages\n\n### Common Request Structure\n\nAll messages share this base structure:\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"recipient_type\": \"individual\",\n  \"to\": \"\u003CE.164_PHONE_NUMBER>\",\n  \"type\": \"\u003CMESSAGE_TYPE>\"\n}\n```\n\n- **Phone format**: E.164 — country code without `+`, no spaces, no leading zeros\n  - Correct: `14155551234`\n  - Incorrect: `+1 (415) 555-1234`, `04155551234`\n- **`messaging_product`**: Always `\"whatsapp\"`\n- **`recipient_type`**: Always `\"individual\"` (for now)\n\n### Text Message\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"to\": \"14155551234\",\n  \"type\": \"text\",\n  \"text\": {\n    \"preview_url\": false,\n    \"body\": \"Your order #12345 is on its way!\"\n  }\n}\n```\n\n- `preview_url`: Set `true` to generate link previews\n- `body`: Max 4096 characters\n\n### Image Message\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"to\": \"14155551234\",\n  \"type\": \"image\",\n  \"image\": {\n    \"link\": \"https:\u002F\u002Fexample.com\u002Fimage.jpg\",\n    \"caption\": \"Here's your product photo\"\n  }\n}\n```\n\nOr by media ID (pre-uploaded):\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"to\": \"14155551234\",\n  \"type\": \"image\",\n  \"image\": {\n    \"id\": \"\u003CMEDIA_ID>\",\n    \"caption\": \"Here's your product photo\"\n  }\n}\n```\n\n### Document Message\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"to\": \"14155551234\",\n  \"type\": \"document\",\n  \"document\": {\n    \"link\": \"https:\u002F\u002Fexample.com\u002Finvoice.pdf\",\n    \"caption\": \"Your invoice\",\n    \"filename\": \"invoice_12345.pdf\"\n  }\n}\n```\n\n### Video Message\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"to\": \"14155551234\",\n  \"type\": \"video\",\n  \"video\": {\n    \"link\": \"https:\u002F\u002Fexample.com\u002Fvideo.mp4\",\n    \"caption\": \"Product demo\"\n  }\n}\n```\n\n### Audio Message\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"to\": \"14155551234\",\n  \"type\": \"audio\",\n  \"audio\": {\n    \"link\": \"https:\u002F\u002Fexample.com\u002Fvoice.ogg\"\n  }\n}\n```\n\n### Sticker Message\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"to\": \"14155551234\",\n  \"type\": \"sticker\",\n  \"sticker\": {\n    \"link\": \"https:\u002F\u002Fexample.com\u002Fsticker.webp\"\n  }\n}\n```\n\n### Location Message\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"to\": \"14155551234\",\n  \"type\": \"location\",\n  \"location\": {\n    \"longitude\": -122.42533,\n    \"latitude\": 37.758056,\n    \"name\": \"Meta Headquarters\",\n    \"address\": \"1601 Willow Rd, Menlo Park, CA 94025\"\n  }\n}\n```\n\n### Contacts Message\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"to\": \"14155551234\",\n  \"type\": \"contacts\",\n  \"contacts\": [\n    {\n      \"name\": {\n        \"formatted_name\": \"John Doe\",\n        \"first_name\": \"John\",\n        \"last_name\": \"Doe\"\n      },\n      \"phones\": [\n        {\n          \"phone\": \"+14155551234\",\n          \"type\": \"CELL\"\n        }\n      ]\n    }\n  ]\n}\n```\n\n### Interactive — Reply Buttons (max 3)\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"to\": \"14155551234\",\n  \"type\": \"interactive\",\n  \"interactive\": {\n    \"type\": \"button\",\n    \"header\": {\n      \"type\": \"text\",\n      \"text\": \"Order Status\"\n    },\n    \"body\": {\n      \"text\": \"Your order #12345 is out for delivery. What would you like to do?\"\n    },\n    \"footer\": {\n      \"text\": \"Powered by YourBrand\"\n    },\n    \"action\": {\n      \"buttons\": [\n        {\n          \"type\": \"reply\",\n          \"reply\": { \"id\": \"track_order\", \"title\": \"Track Shipment\" }\n        },\n        {\n          \"type\": \"reply\",\n          \"reply\": { \"id\": \"contact_support\", \"title\": \"Contact Support\" }\n        },\n        {\n          \"type\": \"reply\",\n          \"reply\": { \"id\": \"change_address\", \"title\": \"Change Address\" }\n        }\n      ]\n    }\n  }\n}\n```\n\n### Interactive — List Message (max 10 options)\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"to\": \"14155551234\",\n  \"type\": \"interactive\",\n  \"interactive\": {\n    \"type\": \"list\",\n    \"header\": {\n      \"type\": \"text\",\n      \"text\": \"Help & Support\"\n    },\n    \"body\": {\n      \"text\": \"How can we help you? Select a topic:\"\n    },\n    \"action\": {\n      \"button\": \"Select Topic\",\n      \"sections\": [\n        {\n          \"title\": \"Orders\",\n          \"rows\": [\n            { \"id\": \"order_status\", \"title\": \"Order Status\", \"description\": \"Where is my package?\" },\n            { \"id\": \"order_cancel\", \"title\": \"Cancellation\", \"description\": \"Cancel my order\" },\n            { \"id\": \"order_return\", \"title\": \"Returns\", \"description\": \"Return an item\" }\n          ]\n        },\n        {\n          \"title\": \"Products\",\n          \"rows\": [\n            { \"id\": \"product_info\", \"title\": \"Product Advice\", \"description\": \"Help choosing\" },\n            { \"id\": \"product_stock\", \"title\": \"Availability\", \"description\": \"Is item X in stock?\" }\n          ]\n        }\n      ]\n    }\n  }\n}\n```\n\n### Template Message (outside 24h window)\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"to\": \"14155551234\",\n  \"type\": \"template\",\n  \"template\": {\n    \"name\": \"order_shipped\",\n    \"language\": { \"code\": \"en\" },\n    \"components\": [\n      {\n        \"type\": \"body\",\n        \"parameters\": [\n          { \"type\": \"text\", \"text\": \"John\" },\n          { \"type\": \"text\", \"text\": \"12345\" },\n          { \"type\": \"text\", \"text\": \"FedEx Express\" }\n        ]\n      }\n    ]\n  }\n}\n```\n\n### Template with Header (media)\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"to\": \"14155551234\",\n  \"type\": \"template\",\n  \"template\": {\n    \"name\": \"shipping_update\",\n    \"language\": { \"code\": \"en\" },\n    \"components\": [\n      {\n        \"type\": \"header\",\n        \"parameters\": [\n          { \"type\": \"image\", \"image\": { \"link\": \"https:\u002F\u002Fexample.com\u002Fpackage.jpg\" } }\n        ]\n      },\n      {\n        \"type\": \"body\",\n        \"parameters\": [\n          { \"type\": \"text\", \"text\": \"John\" },\n          { \"type\": \"text\", \"text\": \"12345\" }\n        ]\n      }\n    ]\n  }\n}\n```\n\n### Template with Buttons\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"to\": \"14155551234\",\n  \"type\": \"template\",\n  \"template\": {\n    \"name\": \"appointment_reminder\",\n    \"language\": { \"code\": \"en\" },\n    \"components\": [\n      {\n        \"type\": \"body\",\n        \"parameters\": [\n          { \"type\": \"text\", \"text\": \"John\" },\n          { \"type\": \"date_time\", \"date_time\": { \"fallback_value\": \"Tomorrow at 3pm\" } }\n        ]\n      },\n      {\n        \"type\": \"button\",\n        \"sub_type\": \"quick_reply\",\n        \"index\": 0,\n        \"parameters\": [\n          { \"type\": \"payload\", \"payload\": \"confirm_yes\" }\n        ]\n      },\n      {\n        \"type\": \"button\",\n        \"sub_type\": \"quick_reply\",\n        \"index\": 1,\n        \"parameters\": [\n          { \"type\": \"payload\", \"payload\": \"reschedule\" }\n        ]\n      }\n    ]\n  }\n}\n```\n\n## Template Categories\n\n| Category | Purpose | Cost | Review Time |\n|----------|---------|------|-------------|\n| **Marketing** | Promotions, offers, product launches | Highest | 24-48h |\n| **Utility** | Order confirmations, shipping updates, receipts | Lower | 24-48h |\n| **Authentication** | OTP, login codes, account verification | Fixed\u002Flowest | 24-48h |\n| **Service** | Support ticket updates, ongoing task help | Low | 24-48h |\n\n### Creating a Template via API\n\n```json\nPOST \u002F{version}\u002F{waba-id}\u002Fmessage_templates\n{\n  \"name\": \"order_shipped\",\n  \"category\": \"UTILITY\",\n  \"language\": \"en\",\n  \"components\": [\n    {\n      \"type\": \"body\",\n      \"text\": \"Hi {{1}}, your order {{2}} has been shipped via {{3}}. Track it here: {{4}}\"\n    },\n    {\n      \"type\": \"footer\",\n      \"text\": \"Reply STOP to opt out\"\n    },\n    {\n      \"type\": \"buttons\",\n      \"buttons\": [\n        {\n          \"type\": \"QUICK_REPLY\",\n          \"text\": \"Track Order\"\n        },\n        {\n          \"type\": \"QUICK_REPLY\",\n          \"text\": \"Contact Support\"\n        }\n      ]\n    }\n  ]\n}\n```\n\n### Template Rules\n\n- Once approved, templates **cannot be edited** — create a new one\n- Each template must have **one clear purpose** — no hybrid templates\n- Utility templates must be **neutral** — no promotional content\n- Authentication templates must be **short and clear** — no branding\u002Fslogans\n- Variable format: `{{1}}`, `{{2}}`, etc.\n- Max 1024 characters for body text\n\n## Message Status Response\n\nSuccessful send returns:\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"contacts\": [\n    {\n      \"input\": \"14155551234\",\n      \"wa_id\": \"14155551234\"\n    }\n  ],\n  \"messages\": [\n    {\n      \"id\": \"wamid.HBgMNDE1NTU1MTIzNBUCABIY...\"\n    }\n  ]\n}\n```\n\n## Webhooks\n\n### Verification (GET)\n\nWhen you register a webhook URL, Meta sends:\n\n```\nGET \u002Fyour-webhook-url?\n  hub.mode=subscribe&\n  hub.verify_token=YOUR_VERIFY_TOKEN&\n  hub.challenge=RANDOM_CHALLENGE_STRING\n```\n\nYour endpoint must:\n1. Verify `hub.mode == \"subscribe\"`\n2. Verify `hub.verify_token` matches your secret\n3. Respond with `hub.challenge` value as plain text body + HTTP 200\n\n### Event Notifications (POST)\n\nStandard top-level structure:\n\n```json\n{\n  \"object\": \"whatsapp_business_account\",\n  \"entry\": [\n    {\n      \"id\": \"\u003CWABA_ID>\",\n      \"changes\": [\n        {\n          \"value\": { ... },\n          \"field\": \"messages\"\n        }\n      ]\n    }\n  ]\n}\n```\n\n### Webhook Fields (Subscription Types)\n\n| Field | Events |\n|-------|--------|\n| `messages` | Inbound messages + outbound status updates |\n| `account_update` | Policy violations, account restrictions |\n| `message_template_status_update` | Template APPROVED\u002FREJECTED\u002FPENDING\u002Fetc. |\n| `phone_number_quality_update` | Quality rating changes (GREEN\u002FYELLOW\u002FRED) |\n| `phone_number_name_update` | Display name approved\u002Frejected |\n| `business_capability_update` | Messaging tier changes |\n| `security` | Security alerts |\n| `flows` | WhatsApp Flows endpoint availability |\n\n### Inbound Message Webhook\n\n```json\n{\n  \"object\": \"whatsapp_business_account\",\n  \"entry\": [\n    {\n      \"id\": \"WABA_ID\",\n      \"changes\": [\n        {\n          \"value\": {\n            \"messaging_product\": \"whatsapp\",\n            \"metadata\": {\n              \"display_phone_number\": \"14155552345\",\n              \"phone_number_id\": \"PHONE_NUMBER_ID\"\n            },\n            \"contacts\": [\n              {\n                \"profile\": { \"name\": \"Jane Doe\" },\n                \"wa_id\": \"14155551234\"\n              }\n            ],\n            \"messages\": [\n              {\n                \"from\": \"14155551234\",\n                \"id\": \"wamid.HBgMNDE1NTU1MTIzNBUCABIY...\",\n                \"timestamp\": \"1699000000\",\n                \"type\": \"text\",\n                \"text\": { \"body\": \"Hello, I need help with my order\" }\n              }\n            ]\n          },\n          \"field\": \"messages\"\n        }\n      ]\n    }\n  ]\n}\n```\n\n### Inbound Message Types\n\n| `type` | Content Field | Description |\n|--------|---------------|-------------|\n| `text` | `text.body` | Plain text message |\n| `image` | `image` | Image with `id`, `mime_type`, `caption`, `sha256` |\n| `document` | `document` | Document with `id`, `filename`, `mime_type`, `caption` |\n| `video` | `video` | Video with `id`, `mime_type`, `caption` |\n| `audio` | `audio` | Audio with `id`, `mime_type`, `voice` (bool) |\n| `sticker` | `sticker` | Sticker with `id`, `mime_type`, `animated` (bool) |\n| `location` | `location` | `latitude`, `longitude`, `name`, `address` |\n| `contacts` | `contacts` | Array of contact objects |\n| `interactive` | `interactive` | Button\u002Flist reply — `type`, `button_reply` or `list_reply` |\n| `reaction` | `reaction` | `message_id`, `emoji` |\n| `order` | `order` | Product inquiry from catalog |\n| `system` | `system` | Phone number changes, etc. |\n\n### Interactive Button Reply Webhook\n\n```json\n{\n  \"messages\": [\n    {\n      \"from\": \"14155551234\",\n      \"id\": \"wamid.HBgMNDE1NTU1MTIzNBUCABIY...\",\n      \"timestamp\": \"1699000000\",\n      \"type\": \"interactive\",\n      \"interactive\": {\n        \"type\": \"button_reply\",\n        \"button_reply\": {\n          \"id\": \"track_order\",\n          \"title\": \"Track Shipment\"\n        }\n      }\n    }\n  ]\n}\n```\n\n### List Reply Webhook\n\n```json\n{\n  \"messages\": [\n    {\n      \"from\": \"14155551234\",\n      \"id\": \"wamid.HBgMNDE1NTU1MTIzNBUCABIY...\",\n      \"timestamp\": \"1699000000\",\n      \"type\": \"interactive\",\n      \"interactive\": {\n        \"type\": \"list_reply\",\n        \"list_reply\": {\n          \"id\": \"order_status\",\n          \"title\": \"Order Status\",\n          \"description\": \"Where is my package?\"\n        }\n      }\n    }\n  ]\n}\n```\n\n### Message Status Webhook\n\n```json\n{\n  \"entry\": [\n    {\n      \"changes\": [\n        {\n          \"value\": {\n            \"messaging_product\": \"whatsapp\",\n            \"metadata\": {\n              \"display_phone_number\": \"14155552345\",\n              \"phone_number_id\": \"PHONE_NUMBER_ID\"\n            },\n            \"statuses\": [\n              {\n                \"id\": \"wamid.HBgMNDE1NTU1MTIzNBUCABIY...\",\n                \"status\": \"delivered\",\n                \"timestamp\": \"1699000000\",\n                \"recipient_id\": \"14155551234\",\n                \"conversation\": {\n                  \"id\": \"CONVERSATION_ID\",\n                  \"origin\": { \"type\": \"utility\" }\n                },\n                \"pricing\": {\n                  \"billable\": true,\n                  \"pricing_model\": \"CBP\",\n                  \"category\": \"utility\"\n                }\n              }\n            ]\n          },\n          \"field\": \"messages\"\n        }\n      ]\n    }\n  ]\n}\n```\n\n### Status Values\n\n| Status | Meaning |\n|--------|---------|\n| `sent` | Message left Meta's servers |\n| `delivered` | Message reached recipient's device |\n| `read` | Recipient opened the message |\n| `failed` | Message failed to send (check `errors` array) |\n| `deleted` | Recipient deleted the message |\n\n### Webhook Security — Signature Verification\n\nEvery POST includes `X-Hub-Signature-256` header:\n\n```\nX-Hub-Signature-256: sha256=\u003CHMAC_SHA256_HASH>\n```\n\nVerification steps:\n1. Get the **raw request body** (before any JSON parsing middleware)\n2. Compute HMAC-SHA256 using your **App Secret** as the key\n3. Compare with the header value (strip `sha256=` prefix)\n4. Use **timing-safe comparison** to prevent timing attacks\n\n## Media Operations\n\n### Upload Media\n\n```\nPOST \u002F{version}\u002F{phone-number-id}\u002Fmedia\nAuthorization: Bearer {TOKEN}\nContent-Type: multipart\u002Fform-data\n\nfile: \u003Cbinary_file>\ntype: \u003CMIME_TYPE>\nmessaging_product: whatsapp\n```\n\nResponse:\n```json\n{\n  \"id\": \"\u003CMEDIA_ID>\"\n}\n```\n\n### Get Media URL\n\n```\nGET \u002F{version}\u002F{media-id}\nAuthorization: Bearer {TOKEN}\n```\n\nResponse:\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"url\": \"https:\u002F\u002Flookaside.fbsbx.com\u002Fwhatsapp_business\u002Fattachments\u002F?mid=...\",\n  \"mime_type\": \"image\u002Fjpeg\",\n  \"sha256\": \"...\",\n  \"file_size\": 12345,\n  \"id\": \"\u003CMEDIA_ID>\"\n}\n```\n\n### Download Media\n\nUse the `url` from the GET response:\n```\nGET {url}\nAuthorization: Bearer {TOKEN}\n```\n\nReturns binary file content.\n\n### Media Limits\n\n| Type | Max Size | Supported Formats |\n|------|----------|-------------------|\n| Image | 16 MB | JPEG, PNG |\n| Video | 64 MB | MP4, 3GPP |\n| Audio | 16 MB | OGG, MP3, AAC |\n| Document | 100 MB | Any (PDF, DOC, XLS, PPT, etc.) |\n| Sticker | 500 KB | WebP (static or animated) |\n\n## Phone Numbers\n\n### List Phone Numbers\n\n```\nGET \u002F{version}\u002F{waba-id}\u002Fphone_numbers\nAuthorization: Bearer {TOKEN}\n```\n\nResponse:\n```json\n{\n  \"data\": [\n    {\n      \"id\": \"PHONE_NUMBER_ID\",\n      \"display_phone_number\": \"+14155552345\",\n      \"quality_rating\": \"GREEN\",\n      \"verified_name\": \"Your Business\",\n      \"code_verification_status\": \"VERIFIED\",\n      \"platform_type\": \"CLOUD_API\"\n    }\n  ]\n}\n```\n\n### Register a Phone Number\n\n```\nPOST \u002F{version}\u002F{phone-number-id}\u002Fregister\nAuthorization: Bearer {TOKEN}\nContent-Type: application\u002Fjson\n\n{\n  \"messaging_product\": \"whatsapp\",\n  \"pin\": \"123456\"\n}\n```\n\nThe PIN is the SMS\u002Fvoice verification code sent to the phone number.\n\n## Pricing & 24-Hour Window\n\n### The 24-Hour Rule\n\n- When a customer messages you, a **24-hour session** opens\n- Within this window: send **any message type** (free-form text, media, buttons)\n- After 24h: only **template messages** allowed\n- Each new customer message **resets** the 24h window\n\n### Conversation Categories (Pricing)\n\n| Category | Description | Relative Cost |\n|----------|-------------|---------------|\n| **Marketing** | Promotions, offers, brand awareness | Highest |\n| **Utility** | Order confirmations, shipping, receipts | Lower |\n| **Authentication** | OTP, login codes | Fixed\u002Flowest |\n| **Service** | User-initiated, support responses | Low |\n\n### Free Tier\n\n- First **1,000 service conversations** per month are free\n- Utility templates sent **within an open 24h window** are free\n\n### Cost Optimization\n\n- Respond within the 24h window whenever possible\n- Use utility templates for transactional messages\n- Avoid marketing category unless truly promotional\n- Monitor quality rating — low rating = higher costs + lower limits\n\n## Messaging Limits\n\n| Tier | Messages\u002F24h | Requirement |\n|------|-------------|-------------|\n| **Tier 1** | 1,000 | Phone number verified |\n| **Tier 2** | 10,000 | Business verified + good quality rating |\n| **Tier 3** | 100,000 | Stable high quality over weeks |\n| **Unlimited** | ∞ | Consistently high quality, no spam |\n\n- New numbers start at **250 messages\u002F24h** (testing tier)\n- Rate limit: **80 messages\u002Fsecond** per phone number (upgradable to 1,000 MPS)\n- Per-user pair rate limit: **1 message every 6 seconds**\n\n## Error Handling\n\n### Common Error Codes\n\n| Code | Meaning | Solution |\n|------|---------|----------|\n| `131030` | Invalid recipient number | Check E.164 format |\n| `131031` | No active 24h window | Use a template message |\n| `131047` | Re-engagement required | Customer must reply first (opt-in) |\n| `131053` | Media URL not reachable | Make URL publicly accessible |\n| `130429` | Rate limit reached | Throttle to max 80 msg\u002Fsec |\n| `131026` | Message undeliverable | Number not on WhatsApp or blocked |\n| `131006` | Service unavailable | Retry with backoff |\n| `131008` | Message failed | Check message format |\n| `368` | Temporary suspension | Wait 24h, improve quality |\n| `100` | Invalid parameter | Check endpoint\u002Fpath params |\n| `190` | Invalid\u002Fexpired token | Refresh token |\n\n### Error Response Format\n\n```json\n{\n  \"error\": {\n    \"message\": \"Unsupported post request.\",\n    \"type\": \"OAuthException\",\n    \"code\": 100,\n    \"error_subcode\": 131030,\n    \"fbtrace_id\": \"ABC123\"\n  }\n}\n```\n\n## Best Practices\n\n### 1. Acknowledge Webhooks Immediately\n\nReturn HTTP 200 **immediately**, then process asynchronously. Meta's timeout is 5-10 seconds.\n\n```\nWebhook Handler → Validate Signature → Enqueue → Return 200\n                                           ↓\n                                    Background Worker\n                                    (DB, API calls, etc.)\n```\n\n### 2. Implement Idempotent Processing\n\nUse message IDs as deduplication keys. Store processed IDs with TTL (Redis recommended).\n\n### 3. Handle Out-of-Order Events\n\nWhatsApp does NOT guarantee ordering. Use `timestamp` fields, not arrival order. Design state machines to be monotonic: `sent → delivered → read`, never backward.\n\n### 4. Verify Webhook Signatures in Production\n\nAlways validate `X-Hub-Signature-256`. Use timing-safe comparison.\n\n### 5. Subscribe App to WABA\n\nCommon gotcha: the webhook URL is configured but the app isn't subscribed to the WABA.\n\n```\nPOST \u002F{version}\u002F{waba-id}\u002Fsubscribed_apps\n```\n\nVerify with:\n```\nGET \u002F{version}\u002F{waba-id}\u002Fsubscribed_apps\n```\n\n### 6. Monitor Quality & Template Status\n\nSubscribe to `phone_number_quality_update` and `message_template_status_update` webhooks to catch issues before they impact messaging.\n\n### 7. Plan for Capacity\n\n- Each outbound message can generate up to 3 webhook callbacks (sent, delivered, read)\n- Server should handle: **3x outgoing traffic + 1x incoming traffic**\n- Retry bursts: when your endpoint recovers, expect a spike\n\n### 8. Use Permanent Tokens in Production\n\nNever use the 24h temporary token in production. Set up System User tokens.\n\n### 9. Store Raw Webhook Payloads\n\nLog every raw webhook payload to durable storage before processing. Meta has no replay API.\n\n### 10. AI Policy Compliance (2026)\n\n- **Allowed**: Task-specific bots (support, sales, booking)\n- **Prohibited**: General-purpose AI assistants, \"ask me anything\" bots, bots impersonating humans\n- Always disclose bot identity when appropriate\n\n## Webhook Setup Checklist\n\n1. [ ] Create endpoint that handles GET (verification) and POST (events)\n2. [ ] Define a `WA_VERIFY_TOKEN` (custom secret string)\n3. [ ] Register webhook URL in Meta App Dashboard → WhatsApp → Configuration\n4. [ ] Subscribe to desired fields: `messages`, `account_update`, etc.\n5. [ ] Subscribe app to WABA: `POST \u002F{waba-id}\u002Fsubscribed_apps`\n6. [ ] Implement signature verification using `WA_APP_SECRET`\n7. [ ] Implement idempotent processing with message ID deduplication\n8. [ ] Set up async processing (message queue)\n9. [ ] Add monitoring\u002Falerting for webhook failures\n10. [ ] Test with Meta's \"Test\" button in dashboard\n\n## Common Gotchas\n\n| Gotcha | Solution |\n|--------|----------|\n| Token expires after 24h | Use System User permanent token |\n| Webhooks not arriving | Check WABA subscription via API |\n| Template rejected | Check category match, remove promotional content from utility |\n| Messages fail with 131031 | Outside 24h window — use template |\n| Media download fails | URL expires — download immediately after getting URL |\n| Duplicate webhook events | Implement idempotent processing with message ID |\n| Events out of order | Use timestamps, not arrival order |\n| Phone number already in use | Cannot use number active on WhatsApp\u002FWhatsApp Business app |\n| Rate limit 130429 | Throttle to 80 msg\u002Fsec, implement queue |\n","## When to Use\n\n- Integrating WhatsApp Business Platform (Cloud API) into any project\n- Sending messages (text, media, interactive, templates) via WhatsApp\n- Receiving and processing inbound messages via webhooks\n- Managing message templates (create, approve, categorize)\n- Uploading\u002Fdownloading media files\n- Managing phone numbers and WABA (WhatsApp Business Account)\n- Building chatbots, notification systems, CRM integrations\n- Implementing conversation-based messaging workflows\n\n## Architecture Overview\n\n```\n┌──────────────┐     POST \u002F{version}\u002F{phone_id}\u002Fmessages     ┌─────────────────┐\n│   Your App   │ ──────────────────────────────────────────► │  Meta Graph API │\n│  (Any Lang)  │ ◄────────────────────────────────────────── │  graph.facebook │\n└──────────────┘         JSON Response                       │     .com        │\n       ▲                                                      └────────┬────────┘\n       │                                                              │\n       │  POST (events)                                               │\n       │  GET  (verification)                                         │\n       └──────────────────────────────────────────────────────────────┘\n                     Webhook Push Notifications\n```\n\n### Key Concepts\n\n| Concept | Description |\n|---------|-------------|\n| **WABA** | WhatsApp Business Account — the top-level container |\n| **Phone Number ID** | Unique ID for each registered phone number |\n| **24-Hour Window** | Free-form messages only within 24h of customer's last reply |\n| **Template Messages** | Pre-approved messages for initiating conversations outside 24h window |\n| **Conversation-Based Pricing** | Meta charges per 24h conversation window, not per message |\n| **Messaging Tiers** | New numbers: 250\u002F24h → scale to unlimited via verification + quality |\n\n## Base URL & Authentication\n\n### Base URL\n\n```\nhttps:\u002F\u002Fgraph.facebook.com\u002Fv21.0\n```\n\nCurrent stable version: **v21.0** (as of early 2026). Check Meta docs for latest.\n\n### Authentication\n\n```\nAuthorization: Bearer {ACCESS_TOKEN}\nContent-Type: application\u002Fjson\n```\n\n### Access Token Types\n\n| Type | Lifespan | Use Case |\n|------|----------|----------|\n| **Temporary** | ~24 hours | Testing\u002Fdevelopment only |\n| **System User Token** | Never expires | Production — generate via Business Manager |\n\n### Required Permissions\n\n- `whatsapp_business_messaging` — Send\u002Freceive messages\n- `whatsapp_business_management` — Manage templates, phone numbers, account\n\n### Permanent Token Setup (Production)\n\n1. Go to **Meta Business Manager** → Business Settings\n2. **Users → System Users → Add** (role: Admin)\n3. Select user → **Assign Assets** → select your WhatsApp app → **Full Control**\n4. **Generate Token** with permissions: `whatsapp_business_messaging`, `whatsapp_business_management`\n5. Copy token — shown only once\n6. Store as environment variable: `WA_ACCESS_TOKEN`\n\n## Environment Variables\n\n```bash\n# Required\nWA_ACCESS_TOKEN=your_permanent_access_token\nWA_PHONE_NUMBER_ID=your_phone_number_id\nWA_VERIFY_TOKEN=your_webhook_verify_token   # Custom string you define\nWA_APP_SECRET=your_app_secret               # For webhook signature verification\n\n# Optional\nWA_API_VERSION=v21.0\nWA_BASE_URL=https:\u002F\u002Fgraph.facebook.com\nWA_WABA_ID=your_waba_id                     # WhatsApp Business Account ID\n```\n\n## Core Endpoints Reference\n\n### Messages\n\n| Method | Endpoint | Description |\n|--------|----------|-------------|\n| POST | `\u002F{version}\u002F{phone-number-id}\u002Fmessages` | Send any message type |\n\n### Media\n\n| Method | Endpoint | Description |\n|--------|----------|-------------|\n| POST | `\u002F{version}\u002F{phone-number-id}\u002Fmedia` | Upload media |\n| GET | `\u002F{version}\u002F{media-id}` | Get media URL (returns `url` field) |\n| GET | `{url}` (from GET response) | Download binary media |\n\n### Phone Numbers\n\n| Method | Endpoint | Description |\n|--------|----------|-------------|\n| GET | `\u002F{version}\u002F{waba-id}\u002Fphone_numbers` | List registered numbers |\n| GET | `\u002F{version}\u002F{phone-number-id}` | Get phone number details |\n| POST | `\u002F{version}\u002F{phone-number-id}\u002Fregister` | Register a number |\n| POST | `\u002F{version}\u002F{phone-number-id}\u002Fderegister` | Deregister a number |\n\n### Templates (Business Management API)\n\n| Method | Endpoint | Description |\n|--------|----------|-------------|\n| GET | `\u002F{version}\u002F{waba-id}\u002Fmessage_templates` | List templates |\n| POST | `\u002F{version}\u002F{waba-id}\u002Fmessage_templates` | Create template |\n| GET | `\u002F{version}\u002F{template-id}` | Get template details |\n| DELETE | `\u002F{version}\u002F{template-id}` | Delete template |\n\n### Webhooks\n\n| Method | Endpoint | Description |\n|--------|----------|-------------|\n| GET | `\u002F{your-webhook-url}` | Verification (Meta sends this) |\n| POST | `\u002F{your-webhook-url}` | Event notifications |\n| POST | `\u002F{version}\u002F{waba-id}\u002Fsubscribed_apps` | Subscribe app to WABA |\n| GET | `\u002F{version}\u002F{waba-id}\u002Fsubscribed_apps` | Verify subscription |\n\n## Sending Messages\n\n### Common Request Structure\n\nAll messages share this base structure:\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"recipient_type\": \"individual\",\n  \"to\": \"\u003CE.164_PHONE_NUMBER>\",\n  \"type\": \"\u003CMESSAGE_TYPE>\"\n}\n```\n\n- **Phone format**: E.164 — country code without `+`, no spaces, no leading zeros\n  - Correct: `14155551234`\n  - Incorrect: `+1 (415) 555-1234`, `04155551234`\n- **`messaging_product`**: Always `\"whatsapp\"`\n- **`recipient_type`**: Always `\"individual\"` (for now)\n\n### Text Message\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"to\": \"14155551234\",\n  \"type\": \"text\",\n  \"text\": {\n    \"preview_url\": false,\n    \"body\": \"Your order #12345 is on its way!\"\n  }\n}\n```\n\n- `preview_url`: Set `true` to generate link previews\n- `body`: Max 4096 characters\n\n### Image Message\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"to\": \"14155551234\",\n  \"type\": \"image\",\n  \"image\": {\n    \"link\": \"https:\u002F\u002Fexample.com\u002Fimage.jpg\",\n    \"caption\": \"Here's your product photo\"\n  }\n}\n```\n\nOr by media ID (pre-uploaded):\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"to\": \"14155551234\",\n  \"type\": \"image\",\n  \"image\": {\n    \"id\": \"\u003CMEDIA_ID>\",\n    \"caption\": \"Here's your product photo\"\n  }\n}\n```\n\n### Document Message\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"to\": \"14155551234\",\n  \"type\": \"document\",\n  \"document\": {\n    \"link\": \"https:\u002F\u002Fexample.com\u002Finvoice.pdf\",\n    \"caption\": \"Your invoice\",\n    \"filename\": \"invoice_12345.pdf\"\n  }\n}\n```\n\n### Video Message\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"to\": \"14155551234\",\n  \"type\": \"video\",\n  \"video\": {\n    \"link\": \"https:\u002F\u002Fexample.com\u002Fvideo.mp4\",\n    \"caption\": \"Product demo\"\n  }\n}\n```\n\n### Audio Message\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"to\": \"14155551234\",\n  \"type\": \"audio\",\n  \"audio\": {\n    \"link\": \"https:\u002F\u002Fexample.com\u002Fvoice.ogg\"\n  }\n}\n```\n\n### Sticker Message\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"to\": \"14155551234\",\n  \"type\": \"sticker\",\n  \"sticker\": {\n    \"link\": \"https:\u002F\u002Fexample.com\u002Fsticker.webp\"\n  }\n}\n```\n\n### Location Message\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"to\": \"14155551234\",\n  \"type\": \"location\",\n  \"location\": {\n    \"longitude\": -122.42533,\n    \"latitude\": 37.758056,\n    \"name\": \"Meta Headquarters\",\n    \"address\": \"1601 Willow Rd, Menlo Park, CA 94025\"\n  }\n}\n```\n\n### Contacts Message\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"to\": \"14155551234\",\n  \"type\": \"contacts\",\n  \"contacts\": [\n    {\n      \"name\": {\n        \"formatted_name\": \"John Doe\",\n        \"first_name\": \"John\",\n        \"last_name\": \"Doe\"\n      },\n      \"phones\": [\n        {\n          \"phone\": \"+14155551234\",\n          \"type\": \"CELL\"\n        }\n      ]\n    }\n  ]\n}\n```\n\n### Interactive — Reply Buttons (max 3)\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"to\": \"14155551234\",\n  \"type\": \"interactive\",\n  \"interactive\": {\n    \"type\": \"button\",\n    \"header\": {\n      \"type\": \"text\",\n      \"text\": \"Order Status\"\n    },\n    \"body\": {\n      \"text\": \"Your order #12345 is out for delivery. What would you like to do?\"\n    },\n    \"footer\": {\n      \"text\": \"Powered by YourBrand\"\n    },\n    \"action\": {\n      \"buttons\": [\n        {\n          \"type\": \"reply\",\n          \"reply\": { \"id\": \"track_order\", \"title\": \"Track Shipment\" }\n        },\n        {\n          \"type\": \"reply\",\n          \"reply\": { \"id\": \"contact_support\", \"title\": \"Contact Support\" }\n        },\n        {\n          \"type\": \"reply\",\n          \"reply\": { \"id\": \"change_address\", \"title\": \"Change Address\" }\n        }\n      ]\n    }\n  }\n}\n```\n\n### Interactive — List Message (max 10 options)\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"to\": \"14155551234\",\n  \"type\": \"interactive\",\n  \"interactive\": {\n    \"type\": \"list\",\n    \"header\": {\n      \"type\": \"text\",\n      \"text\": \"Help & Support\"\n    },\n    \"body\": {\n      \"text\": \"How can we help you? Select a topic:\"\n    },\n    \"action\": {\n      \"button\": \"Select Topic\",\n      \"sections\": [\n        {\n          \"title\": \"Orders\",\n          \"rows\": [\n            { \"id\": \"order_status\", \"title\": \"Order Status\", \"description\": \"Where is my package?\" },\n            { \"id\": \"order_cancel\", \"title\": \"Cancellation\", \"description\": \"Cancel my order\" },\n            { \"id\": \"order_return\", \"title\": \"Returns\", \"description\": \"Return an item\" }\n          ]\n        },\n        {\n          \"title\": \"Products\",\n          \"rows\": [\n            { \"id\": \"product_info\", \"title\": \"Product Advice\", \"description\": \"Help choosing\" },\n            { \"id\": \"product_stock\", \"title\": \"Availability\", \"description\": \"Is item X in stock?\" }\n          ]\n        }\n      ]\n    }\n  }\n}\n```\n\n### Template Message (outside 24h window)\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"to\": \"14155551234\",\n  \"type\": \"template\",\n  \"template\": {\n    \"name\": \"order_shipped\",\n    \"language\": { \"code\": \"en\" },\n    \"components\": [\n      {\n        \"type\": \"body\",\n        \"parameters\": [\n          { \"type\": \"text\", \"text\": \"John\" },\n          { \"type\": \"text\", \"text\": \"12345\" },\n          { \"type\": \"text\", \"text\": \"FedEx Express\" }\n        ]\n      }\n    ]\n  }\n}\n```\n\n### Template with Header (media)\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"to\": \"14155551234\",\n  \"type\": \"template\",\n  \"template\": {\n    \"name\": \"shipping_update\",\n    \"language\": { \"code\": \"en\" },\n    \"components\": [\n      {\n        \"type\": \"header\",\n        \"parameters\": [\n          { \"type\": \"image\", \"image\": { \"link\": \"https:\u002F\u002Fexample.com\u002Fpackage.jpg\" } }\n        ]\n      },\n      {\n        \"type\": \"body\",\n        \"parameters\": [\n          { \"type\": \"text\", \"text\": \"John\" },\n          { \"type\": \"text\", \"text\": \"12345\" }\n        ]\n      }\n    ]\n  }\n}\n```\n\n### Template with Buttons\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"to\": \"14155551234\",\n  \"type\": \"template\",\n  \"template\": {\n    \"name\": \"appointment_reminder\",\n    \"language\": { \"code\": \"en\" },\n    \"components\": [\n      {\n        \"type\": \"body\",\n        \"parameters\": [\n          { \"type\": \"text\", \"text\": \"John\" },\n          { \"type\": \"date_time\", \"date_time\": { \"fallback_value\": \"Tomorrow at 3pm\" } }\n        ]\n      },\n      {\n        \"type\": \"button\",\n        \"sub_type\": \"quick_reply\",\n        \"index\": 0,\n        \"parameters\": [\n          { \"type\": \"payload\", \"payload\": \"confirm_yes\" }\n        ]\n      },\n      {\n        \"type\": \"button\",\n        \"sub_type\": \"quick_reply\",\n        \"index\": 1,\n        \"parameters\": [\n          { \"type\": \"payload\", \"payload\": \"reschedule\" }\n        ]\n      }\n    ]\n  }\n}\n```\n\n## Template Categories\n\n| Category | Purpose | Cost | Review Time |\n|----------|---------|------|-------------|\n| **Marketing** | Promotions, offers, product launches | Highest | 24-48h |\n| **Utility** | Order confirmations, shipping updates, receipts | Lower | 24-48h |\n| **Authentication** | OTP, login codes, account verification | Fixed\u002Flowest | 24-48h |\n| **Service** | Support ticket updates, ongoing task help | Low | 24-48h |\n\n### Creating a Template via API\n\n```json\nPOST \u002F{version}\u002F{waba-id}\u002Fmessage_templates\n{\n  \"name\": \"order_shipped\",\n  \"category\": \"UTILITY\",\n  \"language\": \"en\",\n  \"components\": [\n    {\n      \"type\": \"body\",\n      \"text\": \"Hi {{1}}, your order {{2}} has been shipped via {{3}}. Track it here: {{4}}\"\n    },\n    {\n      \"type\": \"footer\",\n      \"text\": \"Reply STOP to opt out\"\n    },\n    {\n      \"type\": \"buttons\",\n      \"buttons\": [\n        {\n          \"type\": \"QUICK_REPLY\",\n          \"text\": \"Track Order\"\n        },\n        {\n          \"type\": \"QUICK_REPLY\",\n          \"text\": \"Contact Support\"\n        }\n      ]\n    }\n  ]\n}\n```\n\n### Template Rules\n\n- Once approved, templates **cannot be edited** — create a new one\n- Each template must have **one clear purpose** — no hybrid templates\n- Utility templates must be **neutral** — no promotional content\n- Authentication templates must be **short and clear** — no branding\u002Fslogans\n- Variable format: `{{1}}`, `{{2}}`, etc.\n- Max 1024 characters for body text\n\n## Message Status Response\n\nSuccessful send returns:\n\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"contacts\": [\n    {\n      \"input\": \"14155551234\",\n      \"wa_id\": \"14155551234\"\n    }\n  ],\n  \"messages\": [\n    {\n      \"id\": \"wamid.HBgMNDE1NTU1MTIzNBUCABIY...\"\n    }\n  ]\n}\n```\n\n## Webhooks\n\n### Verification (GET)\n\nWhen you register a webhook URL, Meta sends:\n\n```\nGET \u002Fyour-webhook-url?\n  hub.mode=subscribe&\n  hub.verify_token=YOUR_VERIFY_TOKEN&\n  hub.challenge=RANDOM_CHALLENGE_STRING\n```\n\nYour endpoint must:\n1. Verify `hub.mode == \"subscribe\"`\n2. Verify `hub.verify_token` matches your secret\n3. Respond with `hub.challenge` value as plain text body + HTTP 200\n\n### Event Notifications (POST)\n\nStandard top-level structure:\n\n```json\n{\n  \"object\": \"whatsapp_business_account\",\n  \"entry\": [\n    {\n      \"id\": \"\u003CWABA_ID>\",\n      \"changes\": [\n        {\n          \"value\": { ... },\n          \"field\": \"messages\"\n        }\n      ]\n    }\n  ]\n}\n```\n\n### Webhook Fields (Subscription Types)\n\n| Field | Events |\n|-------|--------|\n| `messages` | Inbound messages + outbound status updates |\n| `account_update` | Policy violations, account restrictions |\n| `message_template_status_update` | Template APPROVED\u002FREJECTED\u002FPENDING\u002Fetc. |\n| `phone_number_quality_update` | Quality rating changes (GREEN\u002FYELLOW\u002FRED) |\n| `phone_number_name_update` | Display name approved\u002Frejected |\n| `business_capability_update` | Messaging tier changes |\n| `security` | Security alerts |\n| `flows` | WhatsApp Flows endpoint availability |\n\n### Inbound Message Webhook\n\n```json\n{\n  \"object\": \"whatsapp_business_account\",\n  \"entry\": [\n    {\n      \"id\": \"WABA_ID\",\n      \"changes\": [\n        {\n          \"value\": {\n            \"messaging_product\": \"whatsapp\",\n            \"metadata\": {\n              \"display_phone_number\": \"14155552345\",\n              \"phone_number_id\": \"PHONE_NUMBER_ID\"\n            },\n            \"contacts\": [\n              {\n                \"profile\": { \"name\": \"Jane Doe\" },\n                \"wa_id\": \"14155551234\"\n              }\n            ],\n            \"messages\": [\n              {\n                \"from\": \"14155551234\",\n                \"id\": \"wamid.HBgMNDE1NTU1MTIzNBUCABIY...\",\n                \"timestamp\": \"1699000000\",\n                \"type\": \"text\",\n                \"text\": { \"body\": \"Hello, I need help with my order\" }\n              }\n            ]\n          },\n          \"field\": \"messages\"\n        }\n      ]\n    }\n  ]\n}\n```\n\n### Inbound Message Types\n\n| `type` | Content Field | Description |\n|--------|---------------|-------------|\n| `text` | `text.body` | Plain text message |\n| `image` | `image` | Image with `id`, `mime_type`, `caption`, `sha256` |\n| `document` | `document` | Document with `id`, `filename`, `mime_type`, `caption` |\n| `video` | `video` | Video with `id`, `mime_type`, `caption` |\n| `audio` | `audio` | Audio with `id`, `mime_type`, `voice` (bool) |\n| `sticker` | `sticker` | Sticker with `id`, `mime_type`, `animated` (bool) |\n| `location` | `location` | `latitude`, `longitude`, `name`, `address` |\n| `contacts` | `contacts` | Array of contact objects |\n| `interactive` | `interactive` | Button\u002Flist reply — `type`, `button_reply` or `list_reply` |\n| `reaction` | `reaction` | `message_id`, `emoji` |\n| `order` | `order` | Product inquiry from catalog |\n| `system` | `system` | Phone number changes, etc. |\n\n### Interactive Button Reply Webhook\n\n```json\n{\n  \"messages\": [\n    {\n      \"from\": \"14155551234\",\n      \"id\": \"wamid.HBgMNDE1NTU1MTIzNBUCABIY...\",\n      \"timestamp\": \"1699000000\",\n      \"type\": \"interactive\",\n      \"interactive\": {\n        \"type\": \"button_reply\",\n        \"button_reply\": {\n          \"id\": \"track_order\",\n          \"title\": \"Track Shipment\"\n        }\n      }\n    }\n  ]\n}\n```\n\n### List Reply Webhook\n\n```json\n{\n  \"messages\": [\n    {\n      \"from\": \"14155551234\",\n      \"id\": \"wamid.HBgMNDE1NTU1MTIzNBUCABIY...\",\n      \"timestamp\": \"1699000000\",\n      \"type\": \"interactive\",\n      \"interactive\": {\n        \"type\": \"list_reply\",\n        \"list_reply\": {\n          \"id\": \"order_status\",\n          \"title\": \"Order Status\",\n          \"description\": \"Where is my package?\"\n        }\n      }\n    }\n  ]\n}\n```\n\n### Message Status Webhook\n\n```json\n{\n  \"entry\": [\n    {\n      \"changes\": [\n        {\n          \"value\": {\n            \"messaging_product\": \"whatsapp\",\n            \"metadata\": {\n              \"display_phone_number\": \"14155552345\",\n              \"phone_number_id\": \"PHONE_NUMBER_ID\"\n            },\n            \"statuses\": [\n              {\n                \"id\": \"wamid.HBgMNDE1NTU1MTIzNBUCABIY...\",\n                \"status\": \"delivered\",\n                \"timestamp\": \"1699000000\",\n                \"recipient_id\": \"14155551234\",\n                \"conversation\": {\n                  \"id\": \"CONVERSATION_ID\",\n                  \"origin\": { \"type\": \"utility\" }\n                },\n                \"pricing\": {\n                  \"billable\": true,\n                  \"pricing_model\": \"CBP\",\n                  \"category\": \"utility\"\n                }\n              }\n            ]\n          },\n          \"field\": \"messages\"\n        }\n      ]\n    }\n  ]\n}\n```\n\n### Status Values\n\n| Status | Meaning |\n|--------|---------|\n| `sent` | Message left Meta's servers |\n| `delivered` | Message reached recipient's device |\n| `read` | Recipient opened the message |\n| `failed` | Message failed to send (check `errors` array) |\n| `deleted` | Recipient deleted the message |\n\n### Webhook Security — Signature Verification\n\nEvery POST includes `X-Hub-Signature-256` header:\n\n```\nX-Hub-Signature-256: sha256=\u003CHMAC_SHA256_HASH>\n```\n\nVerification steps:\n1. Get the **raw request body** (before any JSON parsing middleware)\n2. Compute HMAC-SHA256 using your **App Secret** as the key\n3. Compare with the header value (strip `sha256=` prefix)\n4. Use **timing-safe comparison** to prevent timing attacks\n\n## Media Operations\n\n### Upload Media\n\n```\nPOST \u002F{version}\u002F{phone-number-id}\u002Fmedia\nAuthorization: Bearer {TOKEN}\nContent-Type: multipart\u002Fform-data\n\nfile: \u003Cbinary_file>\ntype: \u003CMIME_TYPE>\nmessaging_product: whatsapp\n```\n\nResponse:\n```json\n{\n  \"id\": \"\u003CMEDIA_ID>\"\n}\n```\n\n### Get Media URL\n\n```\nGET \u002F{version}\u002F{media-id}\nAuthorization: Bearer {TOKEN}\n```\n\nResponse:\n```json\n{\n  \"messaging_product\": \"whatsapp\",\n  \"url\": \"https:\u002F\u002Flookaside.fbsbx.com\u002Fwhatsapp_business\u002Fattachments\u002F?mid=...\",\n  \"mime_type\": \"image\u002Fjpeg\",\n  \"sha256\": \"...\",\n  \"file_size\": 12345,\n  \"id\": \"\u003CMEDIA_ID>\"\n}\n```\n\n### Download Media\n\nUse the `url` from the GET response:\n```\nGET {url}\nAuthorization: Bearer {TOKEN}\n```\n\nReturns binary file content.\n\n### Media Limits\n\n| Type | Max Size | Supported Formats |\n|------|----------|-------------------|\n| Image | 16 MB | JPEG, PNG |\n| Video | 64 MB | MP4, 3GPP |\n| Audio | 16 MB | OGG, MP3, AAC |\n| Document | 100 MB | Any (PDF, DOC, XLS, PPT, etc.) |\n| Sticker | 500 KB | WebP (static or animated) |\n\n## Phone Numbers\n\n### List Phone Numbers\n\n```\nGET \u002F{version}\u002F{waba-id}\u002Fphone_numbers\nAuthorization: Bearer {TOKEN}\n```\n\nResponse:\n```json\n{\n  \"data\": [\n    {\n      \"id\": \"PHONE_NUMBER_ID\",\n      \"display_phone_number\": \"+14155552345\",\n      \"quality_rating\": \"GREEN\",\n      \"verified_name\": \"Your Business\",\n      \"code_verification_status\": \"VERIFIED\",\n      \"platform_type\": \"CLOUD_API\"\n    }\n  ]\n}\n```\n\n### Register a Phone Number\n\n```\nPOST \u002F{version}\u002F{phone-number-id}\u002Fregister\nAuthorization: Bearer {TOKEN}\nContent-Type: application\u002Fjson\n\n{\n  \"messaging_product\": \"whatsapp\",\n  \"pin\": \"123456\"\n}\n```\n\nThe PIN is the SMS\u002Fvoice verification code sent to the phone number.\n\n## Pricing & 24-Hour Window\n\n### The 24-Hour Rule\n\n- When a customer messages you, a **24-hour session** opens\n- Within this window: send **any message type** (free-form text, media, buttons)\n- After 24h: only **template messages** allowed\n- Each new customer message **resets** the 24h window\n\n### Conversation Categories (Pricing)\n\n| Category | Description | Relative Cost |\n|----------|-------------|---------------|\n| **Marketing** | Promotions, offers, brand awareness | Highest |\n| **Utility** | Order confirmations, shipping, receipts | Lower |\n| **Authentication** | OTP, login codes | Fixed\u002Flowest |\n| **Service** | User-initiated, support responses | Low |\n\n### Free Tier\n\n- First **1,000 service conversations** per month are free\n- Utility templates sent **within an open 24h window** are free\n\n### Cost Optimization\n\n- Respond within the 24h window whenever possible\n- Use utility templates for transactional messages\n- Avoid marketing category unless truly promotional\n- Monitor quality rating — low rating = higher costs + lower limits\n\n## Messaging Limits\n\n| Tier | Messages\u002F24h | Requirement |\n|------|-------------|-------------|\n| **Tier 1** | 1,000 | Phone number verified |\n| **Tier 2** | 10,000 | Business verified + good quality rating |\n| **Tier 3** | 100,000 | Stable high quality over weeks |\n| **Unlimited** | ∞ | Consistently high quality, no spam |\n\n- New numbers start at **250 messages\u002F24h** (testing tier)\n- Rate limit: **80 messages\u002Fsecond** per phone number (upgradable to 1,000 MPS)\n- Per-user pair rate limit: **1 message every 6 seconds**\n\n## Error Handling\n\n### Common Error Codes\n\n| Code | Meaning | Solution |\n|------|---------|----------|\n| `131030` | Invalid recipient number | Check E.164 format |\n| `131031` | No active 24h window | Use a template message |\n| `131047` | Re-engagement required | Customer must reply first (opt-in) |\n| `131053` | Media URL not reachable | Make URL publicly accessible |\n| `130429` | Rate limit reached | Throttle to max 80 msg\u002Fsec |\n| `131026` | Message undeliverable | Number not on WhatsApp or blocked |\n| `131006` | Service unavailable | Retry with backoff |\n| `131008` | Message failed | Check message format |\n| `368` | Temporary suspension | Wait 24h, improve quality |\n| `100` | Invalid parameter | Check endpoint\u002Fpath params |\n| `190` | Invalid\u002Fexpired token | Refresh token |\n\n### Error Response Format\n\n```json\n{\n  \"error\": {\n    \"message\": \"Unsupported post request.\",\n    \"type\": \"OAuthException\",\n    \"code\": 100,\n    \"error_subcode\": 131030,\n    \"fbtrace_id\": \"ABC123\"\n  }\n}\n```\n\n## Best Practices\n\n### 1. Acknowledge Webhooks Immediately\n\nReturn HTTP 200 **immediately**, then process asynchronously. Meta's timeout is 5-10 seconds.\n\n```\nWebhook Handler → Validate Signature → Enqueue → Return 200\n                                           ↓\n                                    Background Worker\n                                    (DB, API calls, etc.)\n```\n\n### 2. Implement Idempotent Processing\n\nUse message IDs as deduplication keys. Store processed IDs with TTL (Redis recommended).\n\n### 3. Handle Out-of-Order Events\n\nWhatsApp does NOT guarantee ordering. Use `timestamp` fields, not arrival order. Design state machines to be monotonic: `sent → delivered → read`, never backward.\n\n### 4. Verify Webhook Signatures in Production\n\nAlways validate `X-Hub-Signature-256`. Use timing-safe comparison.\n\n### 5. Subscribe App to WABA\n\nCommon gotcha: the webhook URL is configured but the app isn't subscribed to the WABA.\n\n```\nPOST \u002F{version}\u002F{waba-id}\u002Fsubscribed_apps\n```\n\nVerify with:\n```\nGET \u002F{version}\u002F{waba-id}\u002Fsubscribed_apps\n```\n\n### 6. Monitor Quality & Template Status\n\nSubscribe to `phone_number_quality_update` and `message_template_status_update` webhooks to catch issues before they impact messaging.\n\n### 7. Plan for Capacity\n\n- Each outbound message can generate up to 3 webhook callbacks (sent, delivered, read)\n- Server should handle: **3x outgoing traffic + 1x incoming traffic**\n- Retry bursts: when your endpoint recovers, expect a spike\n\n### 8. Use Permanent Tokens in Production\n\nNever use the 24h temporary token in production. Set up System User tokens.\n\n### 9. Store Raw Webhook Payloads\n\nLog every raw webhook payload to durable storage before processing. Meta has no replay API.\n\n### 10. AI Policy Compliance (2026)\n\n- **Allowed**: Task-specific bots (support, sales, booking)\n- **Prohibited**: General-purpose AI assistants, \"ask me anything\" bots, bots impersonating humans\n- Always disclose bot identity when appropriate\n\n## Webhook Setup Checklist\n\n1. [ ] Create endpoint that handles GET (verification) and POST (events)\n2. [ ] Define a `WA_VERIFY_TOKEN` (custom secret string)\n3. [ ] Register webhook URL in Meta App Dashboard → WhatsApp → Configuration\n4. [ ] Subscribe to desired fields: `messages`, `account_update`, etc.\n5. [ ] Subscribe app to WABA: `POST \u002F{waba-id}\u002Fsubscribed_apps`\n6. [ ] Implement signature verification using `WA_APP_SECRET`\n7. [ ] Implement idempotent processing with message ID deduplication\n8. [ ] Set up async processing (message queue)\n9. [ ] Add monitoring\u002Falerting for webhook failures\n10. [ ] Test with Meta's \"Test\" button in dashboard\n\n## Common Gotchas\n\n| Gotcha | Solution |\n|--------|----------|\n| Token expires after 24h | Use System User permanent token |\n| Webhooks not arriving | Check WABA subscription via API |\n| Template rejected | Check category match, remove promotional content from utility |\n| Messages fail with 131031 | Outside 24h window — use template |\n| Media download fails | URL expires — download immediately after getting URL |\n| Duplicate webhook events | Implement idempotent processing with message ID |\n| Events out of order | Use timestamps, not arrival order |\n| Phone number already in use | Cannot use number active on WhatsApp\u002FWhatsApp Business app |\n| Rate limit 130429 | Throttle to 80 msg\u002Fsec, implement queue |\n",{"name":5,"license":15,"metadata":24,"description":29},{"author":25,"version":26,"api_version":27,"last_updated":28},"gentle-ai","1.0","v21.0","2026-03-31","WhatsApp Business Platform (Cloud API) - Complete reference for sending messages, receiving webhooks, managing templates, media, phone numbers, and account operations. Language-agnostic patterns for any project. Trigger: When working with WhatsApp Business API, Cloud API, WhatsApp messaging, WhatsApp webhooks, message templates, WhatsApp integration, Meta Graph API for WhatsApp.\n","main","5dc86f90a5cbe45db3acd917825461b3ed6937fb","config\u002F.config\u002Fopencode\u002Fskills\u002Fwhatsapp-business-api",0,"https:\u002F\u002Fgithub.com\u002Fdavidcoachdev\u002Fdcfiles","https:\u002F\u002Fgithub.com\u002Fdavidcoachdev","🌐 Apasionado por crear soluciones web escalables y eficientes. \r\n🧑‍🏫 Coach Dev.\r\n💻 Frontend Dev. \r\n🎚️Backend Dev.\r\n📊 Agile\u002FScrum.\r\n🚀100% remoto.","2026-08-26 07:28:05",{"source":8,"skillName":5,"commands":39,"prompt":49,"zipAvailable":50},[40,43,46],{"tool":41,"command":42},"npx","npx skills add davidcoachdev\u002Fdcfiles --skill whatsapp-business-api",{"tool":44,"command":45},"bunx","bunx skills add davidcoachdev\u002Fdcfiles --skill whatsapp-business-api",{"tool":47,"command":48},"pnpm","pnpm dlx skills add davidcoachdev\u002Fdcfiles --skill whatsapp-business-api","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fdavidcoachdev\u002Fdcfiles\u002Fblob\u002Fmain\u002Fconfig\u002F.config\u002Fopencode\u002Fskills\u002Fwhatsapp-business-api\u002FSKILL.md",true,[],[53,61,68,75,82,89],{"skillNo":54,"name":55,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":57,"licenseFileUrl":6,"sourceHtmlUrl":58,"categories":59,"keywords":60,"publishedAt":19},"01M7740FETMZY1VTYAEFY1TWY7","zustand-5","Zustand 5 state management patterns. Trigger: When managing React state with Zustand.","Apache-2.0","https:\u002F\u002Fgithub.com\u002Fdavidcoachdev\u002Fdcfiles\u002Fblob\u002Fmain\u002Fconfig\u002F.config\u002Fopencode\u002Fskills\u002Fzustand-5\u002FSKILL.md",[],[],{"skillNo":62,"name":63,"nameZh":6,"description":64,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":57,"licenseFileUrl":6,"sourceHtmlUrl":65,"categories":66,"keywords":67,"publishedAt":19},"01M773ZZM9V68SA1AKP4WF4J29","zod-4","Zod 4 schema validation patterns. Trigger: When using Zod for validation - breaking changes from v3.","https:\u002F\u002Fgithub.com\u002Fdavidcoachdev\u002Fdcfiles\u002Fblob\u002Fmain\u002Fconfig\u002F.config\u002Fopencode\u002Fskills\u002Fzod-4\u002FSKILL.md",[],[],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":57,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":19},"01M773ZJFR90CQAY0N9QR40QVP","x-bookmark-quote-posts","Workflow para revisar bookmarks de X\u002FTwitter y convertirlos en drafts de quote posts. Accede a la sección de bookmarks vía browser headless, extrae posts recientes, y genera drafts con voz personal del usuario. No publica ni muta X — solo genera contenido para revisión. Trigger: X bookmarks, Twitter bookmarks, quote posts, bookmark automation, crear quote posts, revisar bookmarks, growth content X.","https:\u002F\u002Fgithub.com\u002Fdavidcoachdev\u002Fdcfiles\u002Fblob\u002Fmain\u002Fconfig\u002F.config\u002Fopencode\u002Fskills\u002Fx-bookmark-quote-posts\u002FSKILL.md",[],[],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":19},"01M773Z2RGV3786FV310SDB0YD","writing-skills","Use when creating new skills, editing existing skills, or verifying skills work before deployment","https:\u002F\u002Fgithub.com\u002Fdavidcoachdev\u002Fdcfiles\u002Fblob\u002Fmain\u002Fconfig\u002F.config\u002Fopencode\u002Fskills\u002Fwriting-skills\u002FSKILL.md",[],[],{"skillNo":83,"name":84,"nameZh":6,"description":85,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":19},"01M773YJH3KDSW467CSS63CSRJ","writing-plans","Use when you have a spec or requirements for a multi-step task, before touching code","https:\u002F\u002Fgithub.com\u002Fdavidcoachdev\u002Fdcfiles\u002Fblob\u002Fmain\u002Fconfig\u002F.config\u002Fopencode\u002Fskills\u002Fwriting-plans\u002FSKILL.md",[],[],{"skillNo":90,"name":91,"nameZh":6,"description":92,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":57,"licenseFileUrl":6,"sourceHtmlUrl":93,"categories":94,"keywords":95,"publishedAt":19},"01M773Y3S3H2CPRK5S8YFHWB5C","work-unit-commits","Plan commits as reviewable work units. Trigger: implementation, commit splitting, chained PRs, or keeping tests and docs with code.","https:\u002F\u002Fgithub.com\u002Fdavidcoachdev\u002Fdcfiles\u002Fblob\u002Fmain\u002Fconfig\u002F.config\u002Fopencode\u002Fskills\u002Fwork-unit-commits\u002FSKILL.md",[],[]]