Sandbox and staging setup for WhatsApp products
How to separate development, staging and production for a WhatsApp integration: test numbers, tokens, webhooks, data and the traps of shared subscriptions.
WhatsApp is awkward to test because the other end of every conversation is a real phone and a real person. Teams drift into one of two bad habits: testing in production with real customer numbers, or never testing the failure paths at all. A good environment setup removes both temptations. This article describes how to split environments, what Meta provides for development, how to keep staging from receiving production events and what to do about the parts that cannot be faked.
What does Meta provide for development?
Meta provides a test setup in its developer dashboard: a test messaging account, a test business phone number and a way to send to a recipient number you add. It is a convenient start, but it is not a full sandbox with simulated recipients and failure injection.
In Meta's getting-started flow, the API Setup section lets a developer pick or create a messaging account, choose a sender number and enter a recipient. The page does not describe a separate sandbox mode or limits on test recipients, so treat any claim about a built-in simulator with suspicion. The temporary access token generated in the dashboard expires quickly and is meant for initial testing; for development Meta recommends a system user with a permanent token and the whatsapp_business_messaging, whatsapp_business_management and business_management permissions. Replying to a message opens the 24-hour window, which is how you test non-template messages.
How should environments be separated?
Separate them completely: distinct provider organisations or accounts, distinct credentials, distinct webhook endpoints and distinct databases. Sharing any of them is how staging code sends a message to a real customer.
| Concern | Development | Staging | Production |
|---|---|---|---|
| WhatsApp number | Meta test number | A dedicated real number used only by the team | Customer numbers |
| Provider credentials | Personal, short-lived | Staging organisation keys | Production keys in a vault |
| Webhook endpoint | Tunnel to a developer machine | Stable HTTPS staging URL | Production URL |
| Database | Local, synthetic data | Synthetic or anonymised data | Real data |
| Templates | Test names with a prefix | Mirrors production names | Approved production templates |
With a platform that models each customer as an organisation, such as CRPRO Hub, a staging organisation is simply another organisation: its keys, channels and webhooks are isolated from production by design, and an id from another organisation answers 404. That makes a mistaken staging call to a production channel fail instead of send. Name the staging organisation and keys clearly so nobody confuses them in a terminal.
How do webhooks reach a development machine?
Use a public HTTPS tunnel to the developer's machine, register it as a short-lived endpoint and delete it when finished. Provider endpoints must be HTTPS and resolve to a public host, so localhost URLs are rejected.
The Hub, for example, rejects private, loopback and link-local destinations with 400 WEBHOOK_URL_NOT_ALLOWED, and requires https. It also rate-limits endpoint test events to 10 per hour per endpoint, so rehearse the receiver with captured fixtures rather than sending a test for every code change. The webhooks reference lists the headers needed to reproduce a signed delivery locally.
# replay a captured delivery against a local receiver, re-signing with the dev secret
BODY=$(cat fixtures/message-received.json)
TS=$(date +%s)
ID=$(uuidgen | tr 'A-Z' 'a-z')
SIG=$(printf '%s.%s.%s' "$TS" "$ID" "$BODY" | openssl dgst -sha256 -hmac "$DEV_WEBHOOK_SECRET" -hex | sed 's/^.* //')
curl -X POST http://localhost:3000/webhooks/hub \
-H "Content-Type: application/json" \
-H "X-Hub-Delivery-Id: $ID" -H "X-Hub-Timestamp: $TS" \
-H "X-Hub-Signature-Version: v2" -H "X-Hub-Signature-256: sha256=$SIG" \
-d "$BODY"The script signs the string the way the native format specifies: timestamp, dot, delivery id, dot, raw body. It lets you exercise signature checks, deduplication and error handling without a live number, and the fixture file can be a body captured from a real delivery with personal data scrubbed.
Why can staging receive production events?
Meta sends webhook retries to all apps subscribed to a messaging account, so a staging app subscribed to a production account will see production traffic. Subscribe staging only to test accounts, never to a customer's account.
The documentation states that retries go to all apps subscribed to the messaging account, which means duplicate notifications can occur and a staging endpoint that is also subscribed receives real events. If a staging system must read real data for a debugging session, treat it as production for security, access and retention. Otherwise keep the boundary hard: staging apps, test accounts, test numbers.
What data belongs in non-production environments?
Synthetic data by default. Real phone numbers and conversations in staging bring privacy obligations without bringing benefits.
- Generate fake contacts with obviously fake numbers and mark them in the data.
- Anonymise any fixture copied from production, including phone numbers, names and message text.
- Block outbound sends from staging to anything but an allowlist of internal numbers.
- Run a guard on startup that refuses to boot if production credentials are configured in a non-production environment.
- Keep staging databases out of production backups and analytics.
The allowlist guard is cheap and pays for itself the first time a migration script replays a customer list against the staging key.
How do changes move from staging to production?
Promote the same build with different configuration, never different code. The only differences between environments should be environment variables, secret references and endpoint URLs.
- Keep a config checklist per environment: provider base URL, key reference, webhook secret reference, channel ids, allowlist.
- Create production webhook endpoints from a script or infrastructure code, so the event subscription list matches staging exactly.
- Remember that an endpoint with no event list receives every event type on the Hub, so state the list explicitly in both environments.
- Run the smoke suite against production after each deploy using an internal number, and alert if it fails.
What cannot be faked and how to cover it?
Delivery behaviour, quality ratings, template approval and Meta-side rate limits cannot be simulated faithfully, so cover them with a fake provider for logic tests and a small number of real-number smoke tests for the rest.
Build a fake of your provider client that can return acceptance, 429, temporary errors and the error codes you handle, and emit status webhooks on demand. Reserve the real staging number for a short smoke suite: send a template, receive a reply, check a status webhook, check a signature. The testing-strategy article in this series expands on what to put in each layer, and the quickstart shows the minimal authenticated calls for the smoke suite.
Frequently asked questions
Does Meta offer a full WhatsApp sandbox?
Meta offers a test messaging account and test number in the developer dashboard, but its getting-started page does not describe a sandbox with simulated recipients or failure injection. Plan to fake the provider for logic tests.
Can staging and production share a webhook endpoint?
Avoid it. Use separate endpoints and credentials, and subscribe staging only to test accounts, because Meta delivers notifications to every app subscribed to a messaging account.
What token should I use in development?
Not the temporary dashboard token for anything beyond a first test. Meta recommends a system user with a permanent token and the required permissions, stored like any other secret.
Fontes
Documentação oficial da Meta, conferida em 31 de outubro de 2026.