A comprehensive development environment for testing WhatsApp integrations without using real WhatsApp Cloud API endpoints, phone numbers, or incurring API costs.
- Full API Compatibility: Mimics WhatsApp Cloud API endpoints for seamless integration testing
- Message Sending & Receiving: Complete message flow simulation with realistic responses
- Webhook Simulation: Real-time webhook events for message delivery status, read receipts, and error handling
- π HMAC-SHA256 Signatures: Webhook requests include
x-hub-signature-256header matching WhatsApp's authentication spec - Template Management API: Full CRUD operations for WhatsApp message templates
- Hot-Reload Templates: Automatic template reloading when JSON files change - no server restart required
- Schema Validation: Ensures templates comply with WhatsApp Business API requirements
- Zero Cost Testing: Test without real phone numbers, API charges, or rate limits
- Persistent Storage: In-memory conversation and template storage for development sessions
- Real-time Testing Interface: React-based CLI for interactive message and template testing
- Template Browser: Easy template selection and preview with category filtering
- Variable Input System: Guided prompts for template parameter collection with validation
- Conversation History: View complete message and template history with timestamps
- Development Workflow: Seamless integration with existing development processes
- Hot-Reload Integration: Instantly test template changes without restarting CLI
- Multi-stage Docker Build: Optimized production and debug images
- Self-contained Binary: Compiled Bun executable with no runtime dependencies
- Health Checks: Built-in
/healthendpoint for container orchestration - Makefile Automation: 40+ targets for building, testing, and deploying
- Debug Support: Bun Inspector on port 9229 for interactive debugging
# Clone the repository
git clone https://github.com/fdarian/whap.git
cd whap
# Install dependencies
bun install# Terminal 1: Start the mock server
bun whap server
# Terminal 2: Start the CLI interface
bun whap tuiThe mock server runs on port 3010 and provides WhatsApp Cloud API compatible endpoints.
Configure webhook URLs to receive WhatsApp events using any of these methods (in priority order):
Create a whap.json file in your project root:
{
"$schema": "./schema/whap-config.schema.json",
"webhookUrls": [
"1234567890:http://localhost:4000/webhook",
"9876543210:http://localhost:5000/webhook",
"http://localhost:3000/fallback-webhook"
]
}Format Options:
"phoneNumber:url"- Phone-specific webhook mapping"url"- Fallback webhook URL (used when no phone-specific mapping exists)
# Fallback URL
export WEBHOOK_URL=http://localhost:4000/webhook
bun whap server
# Or phone-specific mapping
export WEBHOOK_URL=1234567890:http://localhost:4000/webhook
bun whap serverbun whap server --port 8080Configuration sources are applied in this order (highest to lowest priority):
- CLI arguments (
--webhook-url) - Environment variables (
WEBHOOK_URL) - Configuration file (
whap.json)
Webhook URLs without phone numbers are used as fallback URLs when no phone-specific mapping exists. If multiple fallback URLs are provided, the first entry in whap.json is used when WEBHOOK_URL is not set.
Configure webhook signature authentication to match WhatsApp's security requirements. Webhooks will include the X-Hub-Signature-256 header for signature verification.
Add to whap.json:
{
"webhookSecret": "your-app-secret"
}export WEBHOOK_SECRET="your-app-secret"
bun whap serverbun whap server --port 8080Signature Verification:
All outgoing webhook requests include the x-hub-signature-256 header when a secret is configured. Verify the signature using:
const crypto = require('crypto');
function verifyWebhookSignature(signature, secret, body) {
const expectedSignature = 'sha256=' +
crypto.createHmac('sha256', secret).update(body).digest('hex');
return signature === expectedSignature;
}Example:
Header: x-hub-signature-256: sha256=b6978b21c4467654c466607663db9b43fae44b71083568df403e0a077089208e
Secret: your-app-secret
Body: {"object":"whatsapp_business_account","entry":[...]}
Whap includes production-ready Docker support with multi-stage builds for minimal image sizes.
# Build production image
make build
# Run the server
make server
# Run the TUI interface (interactive mode)
make tui
# View all available commands
make help-
Production image (
whap:latest): Minimal runtime image (~150MB)- Self-contained Bun binary
- No source code or node_modules
- Health checks enabled
-
Debug image (
whap:debug): Full development image (~800MB)- Bun Inspector support (port 9229)
- Full source code
- Development dependencies
Build:
make build- Build production imagemake build_debug- Build debug image with source and Inspector
Run:
make server- Start mock server (port 3010)make tui- Start interactive CLI (with TTY)make run CMD="..."- Run arbitrary whap command
Development:
make test- Run test suitemake typecheck- TypeScript type checkingmake lint- Run Biome lintermake format- Run Biome formatter
Management:
make clean- Remove containers and imagesmake rm_containers- Stop and remove containersmake rmi- Remove images
Inspection:
make images- List whap imagesmake ps- List running containers
For development, mount your source directory to reflect changes without rebuilding:
# Run tests against live source
SRC_DIR=./src make test
# Type-check live source
SRC_DIR=./src make typecheck
# Lint live source
SRC_DIR=./src make lint
# Format and write back to host
SRC_DIR=./src make format# Change image tag
IMAGE_TAG=1.0.0 make build
# Change server port
SERVER_PORT=8080 make server
# Run with webhook secret
docker run -p 3010:3010 \
-e WEBHOOK_SECRET="your-secret" \
whap:latest server-
Create template files in the
templates/directory:// templates/welcome.json { "name": "welcome_message", "category": "UTILITY", "language": "en_US", "components": [ { "type": "BODY", "text": "Welcome {{1}}! Your account has been created successfully.", "example": { "body_text": [["John Doe"]] } } ] }
-
Templates auto-load - no restart required!
-
Test via CLI - select templates and enter variables interactively
-
Send via API - use standard WhatsApp Business API format
# 1. Create/modify template files in templates/
# 2. Templates hot-reload automatically
# 3. Test immediately in CLI interface
# 4. Send via API for integration testingcurl -X POST http://localhost:3010/v22.0/123456789/messages \
-H "Content-Type: application/json" \
-d '{
"messaging_product": "whatsapp",
"to": "1234567890",
"type": "template",
"template": {
"name": "welcome_message",
"language": { "code": "en_US" },
"components": [
{
"type": "body",
"parameters": [
{ "type": "text", "text": "John Doe" }
]
}
]
}
}'π Complete Template Documentation β
# Development
bun whap server # Start mock server (port 3010)
bun whap tui # Start interactive CLI
bun run dev:server # Start server in watch mode
# Testing
bun test # Run test suite
bun run test:watch # Run tests in watch mode
# Building
bun run build # Build for production# Build
make build # Build production Docker image
make build_debug # Build debug image with Inspector
# Run
make server # Run mock server in container
make tui # Run CLI interface in container
make test # Run tests in container
# Development with live source
SRC_DIR=./src make test # Run tests against live source
SRC_DIR=./src make typecheck # Type-check live source
SRC_DIR=./src make format # Format code and write backwhap/
βββ templates/ # Template JSON files
βββ src/
β βββ server/ # Mock server implementation
β β βββ routes/
β β β βββ messages.ts # Message sending (includes templates)
β β β βββ templates.ts # Template management API
β β βββ stores/
β β βββ template-store.ts # Template storage & validation
β βββ components/ # CLI interface
β βββ SimplifiedChatInterface.tsx
βββ docs/
β βββ templates.md # Complete template documentation
βββ package.json
- Zero Configuration: Works out-of-the-box with no setup required
- Hot-Reload: Templates update instantly during development
- Full API Compatibility: Drop-in replacement for WhatsApp Cloud API
- Interactive Testing: CLI-based template and message testing
- Schema Validation: Ensures templates meet WhatsApp requirements
- Webhook Simulation: Complete delivery status event simulation
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.