Setup
Follow the WhatsApp setup guide in the deploy overview. Required environment variables:WHATSAPP_ACCESS_TOKEN(from Meta App Dashboard)WHATSAPP_PHONE_NUMBER_ID(from WhatsApp API Setup)WHATSAPP_VERIFY_TOKEN(a string you create for webhook verification)- Optional (production):
WHATSAPP_APP_SECRETandAPP_ENV=production
The user’s phone number is automatically used as the
user_id for runs. This ensures that sessions and memory are appropriately scoped to the user.The phone number is also used for the session_id (format: wa:{phone_number}), so a single WhatsApp conversation corresponds to a single session.Example Usage
Create an agent, expose it with theWhatsapp interface, and serve via AgentOS:
basic.py
Core Components
Whatsapp(interface): Wraps an AgnoAgent,Team, orWorkflowfor WhatsApp via FastAPI.AgentOS.serve: Serves the FastAPI app using Uvicorn.
Whatsapp Interface
Main entry point for Agno WhatsApp applications.
Initialization Parameters
Provide
agent, team, or workflow.
Key Method
Endpoints
Mounted under the/whatsapp prefix:
GET /whatsapp/status
- Health/status check for the interface.
- Returns
{"status": "available"}.
GET /whatsapp/webhook
- Handles WhatsApp webhook verification (
hub.challenge). - Returns
hub.challengeon success;403on token mismatch;500ifWHATSAPP_VERIFY_TOKENis not set.
POST /whatsapp/webhook
- Receives WhatsApp messages and events.
- Validates the
X-Hub-Signature-256header; bypassed whenAPP_ENV=development. - Processes text, image, video, audio, and document messages via the agent/team/workflow.
- Sends replies back to the user (splits long messages at WhatsApp’s 4096 character limit; uploads and sends generated images).
- Responses:
200 {"status": "processing"}or{"status": "ignored"},403invalid signature,500errors.
Session Management
Sessions are scoped by phone number:- Session ID format:
wa:{phone_number} - The user’s phone number is used as both the
user_idand the base for thesession_id - Each WhatsApp conversation maps to a single session
Media Support
Inbound (user sends to bot): images, video, audio, and documents. Media is downloaded via the WhatsApp Business API and passed to the agent as image, video, audio, or file inputs. Outbound (agent sends to user): generated images are uploaded to the WhatsApp Media API and sent as native WhatsApp image messages. Text responses are split into batches if they exceed the 4096 character limit.Reasoning Support
When the agent produces reasoning content (e.g., from ReasoningTools or ThinkingTools), it is sent as a separate italicized message before the main response.Testing the Integration
- Run the app locally:
python <my-app>.py(ensure ngrok is running) - In your Meta App’s WhatsApp Setup, configure the webhook URL to
https://YOUR-NGROK-URL/whatsapp/webhook - Subscribe to the
messageswebhook field - Send a message from your test phone number to the WhatsApp Business number