Host agents as WhatsApp applicationsUse the WhatsApp interface to serve Agents via WhatsApp. It mounts webhook routes on a FastAPI app and sends responses back to WhatsApp users and threads.
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)
Example Usage
Create an agent, expose it with theWhatsAppInterface interface, and serve via InterfaceManager:
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
| Parameter | Type | Default | Description |
|---|---|---|---|
agent | Agent | Required | Upsonic Agent instance. |
verify_token | Optional[str] | None | WhatsApp webhook verification token (or set WHATSAPP_VERIFY_TOKEN). |
app_secret | Optional[str] | None | WhatsApp app secret for signature validation (or set WHATSAPP_APP_SECRET). |
name | str | "WhatsApp" | Interface name. |
Key Method
| Method | Parameters | Return Type | Description |
|---|---|---|---|
attach_routes | None | APIRouter | Returns the FastAPI router and attaches endpoints. |
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.

