waba
README.md
# waba
Open-source, agent-native WhatsApp Business Platform. Hosted free at **[mcp.waba.cloud](https://mcp.waba.cloud/mcp)**, or self-host it with your own Meta app. There is no dashboard: the product is a **remote MCP server** plus a **plugin** for Claude (Claude Code, claude.ai, Cowork) and OpenAI (ChatGPT, Codex). An AI agent can sign up and run the whole WABA lifecycle:
- **Signup**: email code, by OAuth (connectors) or by the public signup MCP (headless agents get an API key).
- **Onboarding**: hosted Embedded Signup for **Cloud API** or **Coexistence** (WhatsApp Business app and API on one number).
- **Numbers**: status, quality, messaging limit, verification, registration and two-step PIN, business profile, Coexistence sync.
- **Templates**: pre-flight lint against Meta's common rejection reasons, then submit, track, edit and delete.
- **Messaging**: text, templates, media, interactive, reactions and read receipts. Policy is enforced server-side: the 24-hour window, marketing opt-in, quality pause and idempotency.
- **Events and webhooks**: every Meta webhook is stored, normalised into a per-account event stream, and fanned out to customer endpoints. Delivery is signed (Standard Webhooks) and retried for about 3 days. You also get a delivery log, replay, pause and resume, secret rotation, and auto-disable for dead endpoints. Agents without a URL use `events_poll`.
The hosted service runs as a **Meta Tech Provider** (Periskope). Customers own their WABAs and pay Meta directly. We hold their business tokens (AES-256-GCM at rest) and never pass a client's token through to Meta.
```
Agent ──MCP (Streamable HTTP, OAuth 2.1 / API key)──► /mcp ─► core ─► Graph API v27
│
Meta ──webhooks──► /webhooks/meta ─► meta_webhook_log ─► events ─► webhook_deliveries ─► customer endpoints
└──► events_poll
```
## Layout
| Path | What |
|---|---|
| `src/core/` | Domain logic: accounts, onboarding/numbers (`waba.ts`), templates, messages, events, webhooks, Meta ingest |
| `src/meta/graph.ts` | Graph API client with Meta error codes mapped to agent hints |
| `src/auth/oauth.ts` | OAuth 2.1 AS: PKCE, CIMD + DCR, refresh rotation with reuse detection, RFC 9207 `iss`, API keys |
| `src/mcp/` | Tool surface (46 tools, all annotated), resources, prompts |
| `src/http/` | Express app: MCP, OAuth pages, hosted Embedded Signup page, Meta webhook receiver, small REST |
| `plugin/` | One plugin, three manifests (Claude Code, Codex/OpenAI, portable) + 4 skills |
| `docs/platform-notes.md` | Verified Meta/MCP facts this code depends on |
## Run locally
```bash
cp .env.example .env # set ENCRYPTION_KEY=$(openssl rand -base64 32)
npm install
npm run dev # embedded PGlite, codes printed to the log
npm test # 38 tests; set TEST_DATABASE_URL to also run against real Postgres
```
Production: Postgres (`DATABASE_URL`), `EMAIL_PROVIDER=resend`, HTTPS `PUBLIC_URL`. `docker compose up` runs Postgres, the web node and a separate webhook worker (`RUN_WORKER_IN_PROCESS=false` on web nodes; workers scale horizontally with `SKIP LOCKED`).
## Meta app setup
1. **WhatsApp → Configuration → Webhook**:
- Callback: `${PUBLIC_URL}/webhooks/meta`
- Verify token: `META_WEBHOOK_VERIFY_TOKEN`
- Subscribe to: `messages`, `message_template_status_update`, `template_category_update`, `message_template_quality_update`, `phone_number_quality_update`, `phone_number_name_update`, `account_update`, `account_review_update`, `account_alerts`, `business_capability_update`, `history`, `smb_app_state_sync`, `smb_message_echoes`.
2. **Facebook Login for Business**: create an Embedded Signup configuration and set `META_ES_CONFIG_ID`. Optionally create a second one for Coexistence (`META_ES_COEX_CONFIG_ID`); otherwise `featureType: whatsapp_business_app_onboarding` is sent on the same config.
3. Allowed domains for the JS SDK: add `PUBLIC_URL`'s host.
## Connect an agent
| Surface | How |
|---|---|
| Claude Code | `claude plugin marketplace add periskope-org/waba` then `claude plugin install waba@periskope` (OAuth on first use). Set `WABA_MCP_URL` if not using the default host. |
| claude.ai / Cowork | Settings → Connectors → Add custom connector → `${PUBLIC_URL}/mcp` |
| ChatGPT / Codex | Plugin from `plugin/` (`.codex-plugin/plugin.json`), or in `~/.codex/config.toml`: `[mcp_servers.whatsapp] url = "${PUBLIC_URL}/mcp"` then `codex mcp login whatsapp` |
| OpenAI Responses API | `{"type":"mcp","server_label":"whatsapp","server_url":"${PUBLIC_URL}/mcp","authorization":"<api key>"}` |
| Any headless agent | Call `account_signup` / `account_verify` on `${PUBLIC_URL}/mcp/signup` (or `POST /v1/signup`, `/v1/signup/verify`) → API key → `Authorization: Bearer wk_live_…` on `/mcp` |
## Webhooks for customers
Payload: `{ id, cursor, type, created_at, account_id, waba_id, phone_number_id, data }`.
Headers:
- `webhook-id`
- `webhook-timestamp`
- `webhook-signature: v1,<base64>`: HMAC-SHA256 with the base64-decoded `whsec_` secret over `"{id}.{timestamp}.{body}"`. During rotation, two signatures are sent for 24 hours.
- Also: `x-event-type`, `x-delivery-id`, `x-delivery-attempt`.
Delivery is at least once and not strictly ordered. Retries: 10s, 1m, 5m, 30m, 2h, 5h, 10h, 24h, 24h.
## Self-hosting
You need your own Meta app with WhatsApp, Tech Provider (or Solution Partner) status, and an Embedded Signup configuration. Follow **Meta app setup** above, set the env vars in `.env.example`, and point `plugin/.mcp.json` at your host with `WABA_MCP_URL`.
## Contributing and security
Issues and PRs are welcome. Run `npm run typecheck && npm test` before opening a PR. Please report vulnerabilities privately, as described in [SECURITY.md](SECURITY.md), not in public issues.
## License
[Apache-2.0](LICENSE). WhatsApp and Meta are trademarks of Meta Platforms, Inc. This project is not affiliated with or endorsed by Meta.
## Not done yet
- MCP Apps UI (e.g. an onboarding card rendered inline in Claude/ChatGPT)
- Retention jobs for `events`, `meta_webhook_log` and `webhook_attempts`
- KMS envelope encryption
- Per-account send quotas
- Resumable-upload helper for media template headers
- Plugin icon and privacy/terms URLs
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues