Setup
Follow the WhatsApp deploy guide to create a Meta App, configure the WhatsApp Business API, and set up webhooks. Required configuration:WHATSAPP_ACCESS_TOKEN(from Meta App Dashboard > WhatsApp > API Setup)WHATSAPP_PHONE_NUMBER_ID(from WhatsApp > API Setup)WHATSAPP_VERIFY_TOKEN(any string you choose for webhook verification)- Webhook URL set to
{prefix}/webhook(use ngrok for local development)
Example Usage
- Agent
- Team
- Workflow
basic.py
See more examples including media agents, image generation, reasoning, and multiple bots.
Sessions
Each WhatsApp user gets a single session scoped to their phone number.Session format:
wa:{entity_id}:{user_id}. For example, an agent named “Basic Agent” talking to user +1234567890 produces wa:Basic Agent:1234567890./new to start a fresh session. The old session is preserved in the database, and a new session ID is created with a random suffix. This requires a db on the agent, team, or workflow.
Media
Users can send images, video, audio, and documents to the bot. Media is downloaded from Meta’s servers and passed to the agent automatically. Agents can send media back in their responses. See the media agent example for a complete multimodal agent, and the reference page for supported message types.WhatsAppTools
WhatsAppTools lets your agents send interactive messages: reply buttons, list menus, images, documents, locations, and reactions.
Multi-Instance
Run multiple bots on the same server with differentprefix values:
Phone Number Encryption
Enable with
enable_encryption=True to encrypt phone numbers before storing them as user_id. Raw numbers are never written to the database.user_id. Requires the cryptography package.
Security
Every incoming webhook is verified using HMAC-SHA256 signature validation:- The
X-Hub-Signature-256header is extracted - A signature is computed:
HMAC-SHA256(app_secret, request_body) - The computed signature is compared using constant-time comparison (
hmac.compare_digest)
Troubleshooting
No messages received
No messages received
Cause: Webhook not configured or not subscribed to the
messages field.Fix: In your Meta App Dashboard, go to WhatsApp > Configuration and verify the callback URL matches your tunnel URL (e.g., https://your-tunnel.ngrok.io/whatsapp/webhook). Click “Manage” and confirm you’re subscribed to the messages field.403 on webhook
403 on webhook
Cause: Invalid App Secret or missing signature validation config.Fix: Verify
WHATSAPP_APP_SECRET matches the value under App Settings > Basic in your Meta App Dashboard. For local development, set WHATSAPP_SKIP_SIGNATURE_VALIDATION=true.Webhook verification fails
Webhook verification fails
Cause: Verify token mismatch or server not running.Fix: Ensure
WHATSAPP_VERIFY_TOKEN matches the value you entered in the Meta webhook configuration. Your server must be running when you click “Verify and save”.Media not sending
Media not sending
Cause: Expired or insufficient access token.Fix: Temporary tokens expire after ~24 hours. For production, create a permanent System User token via Meta Business Manager. Ensure the token has
whatsapp_business_messaging permission.Bot not replying
Bot not replying
Cause: Missing environment variables or agent errors.Fix: Check application logs. Common causes:
WHATSAPP_ACCESS_TOKEN not set, expired token, or an error in your agent’s tools or model configuration.SSL certificate errors
SSL certificate errors
Cause: macOS system Python missing root certificates.Fix: Set the
SSL_CERT_FILE environment variable:Developer Resources
Interface Reference
All parameters, endpoints, and session handling details.
Deploy Guide
Create a Meta App, configure webhooks, and deploy step by step.
WhatsAppTools Reference
Toolkit parameters and methods for interactive messages, media, and locations.
Usage Examples
Agents, teams, media, image generation, reasoning, and more.