Setup
Required environment variables:-
WHATSAPP_VERIFY_TOKEN(for webhook verification) -
WHATSAPP_ACCESS_TOKEN(required by WhatsAppTools for sending messages) -
WHATSAPP_PHONE_NUMBER_ID(required by WhatsAppTools for sending messages) -
Optional (production):
WHATSAPP_APP_SECRET(for webhook signature validation)
Operating Modes
- TASK (default) – Each message is processed as an independent task; no conversation history. Best for one-off queries and stateless bots.
- CHAT – Messages from the same sender share a conversation session. The agent remembers context. Best for conversational and support use cases.
Heartbeat
When used with anAutonomousAgent that has heartbeat=True, the interface periodically sends the agent’s heartbeat_message to the agent, then delivers the response to the WhatsApp recipient.
The target recipient is resolved automatically from the first incoming message. You can also set it explicitly via heartbeat_recipient.
Reset Command (CHAT mode only)
In CHAT mode, senders can clear their conversation by sending the reset command (e.g./reset) as a message. Configure it with reset_command; set to None to disable.
If the agent has a workspace configured, the reset command will also trigger a dynamic greeting message based on the workspace configuration. See Workspace for details.
Access Control (Whitelist)
Passallowed_numbers (list of phone numbers in international format, e.g. ["905551234567"]). Only those numbers are processed; others receive “This operation not allowed”. Omit allowed_numbers (or set None) to allow all senders.
Example Usage
Create an agent, expose it with theWhatsAppInterface interface, and serve via InterfaceManager. Example with CHAT mode, reset command, and optional whitelist:
Core Components
-
WhatsAppInterface(interface): Wraps an UpsonicAgentfor WhatsApp via FastAPI. -
InterfaceManager.serve: Serves the FastAPI app using Uvicorn.
WhatsAppInterface Interface
Main entry point for Upsonic WhatsApp applications.
Initialization Parameters
Key Methods
Endpoints
Mounted under the/whatsapp prefix:
GET /whatsapp/webhook
-
Verifies WhatsApp webhook (
hub.challenge). -
Returns
hub.challengeon success;403on token mismatch;500ifWHATSAPP_VERIFY_TOKENmissing.
POST /whatsapp/webhook
- Receives WhatsApp messages and events.
-
Validates signature (
X-Hub-Signature-256); skipped ifWHATSAPP_APP_SECRETnot configured. - Processes text, image, video, audio, and document messages via the agent.
- Sends replies (splits long messages; uploads and sends generated images).
-
Responses:
200 {"status": "processing"},200 {"status": "ignored"}, or200 {"status": "invalid_payload"},403invalid signature,500errors.
GET /whatsapp/health
- Health/status of the interface.

