Setup
Set up your WhatsApp Business API and configure the webhook URL to point to your AgentOS instance. Required environment variables:WHATSAPP_ACCESS_TOKENWHATSAPP_PHONE_NUMBER_IDWHATSAPP_VERIFY_TOKEN- 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, so a single WhatsApp conversation corresponds to a single session. This should be considered when managing session history.Example Usage
Create an agent, expose it with theWhatsapp interface, and serve via AgentOS:
Core Components
Whatsapp(interface): Wraps an AgnoAgentorTeamfor WhatsApp via FastAPI.AgentOS.serve: Serves the FastAPI app using Uvicorn.
Whatsapp Interface
Main entry point for Agno WhatsApp applications.
Initialization Parameters
Provide
agent or team.
Key Method
Endpoints
Mounted under the/whatsapp prefix:
GET /whatsapp/status
- Health/status of the interface.
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); bypassed in development mode. - Processes text, image, video, audio, and document messages via the agent/team.
- Sends replies (splits long messages; uploads and sends generated images).
- Responses:
200 {"status": "processing"}or{"status": "ignored"},403invalid signature,500errors.