Setup
Follow the WhatsApp setup guide in the Whatsapp Cookbook. You will need environment variables:WHATSAPP_ACCESS_TOKEN
WHATSAPP_PHONE_NUMBER_ID
WHATSAPP_VERIFY_TOKEN
- Optional (production):
WHATSAPP_APP_SECRET
andAPP_ENV=production
Example Usage
Create an agent, expose it with theWhatsapp
interface, and serve via AgentOS
:
Core Components
Whatsapp
(interface): Wraps an AgnoAgent
orTeam
for WhatsApp via FastAPI.AgentOS.serve
: Serves the FastAPI app using Uvicorn.
Whatsapp
Interface
Main entry point for Agno WhatsApp applications.
Initialization Parameters
Parameter | Type | Default | Description |
---|---|---|---|
agent | Optional[Agent] | None | Agno Agent instance. |
team | Optional[Team] | None | Agno Team instance. |
agent
or team
.
Key Method
Method | Parameters | Return Type | Description |
---|---|---|---|
get_router | use_async: bool = True | APIRouter | Returns the FastAPI router and attaches endpoints. |
Endpoints
Mounted under the/whatsapp
prefix:
GET /whatsapp/status
- Health/status of the interface.
GET /whatsapp/webhook
- Verifies WhatsApp webhook (
hub.challenge
). - Returns
hub.challenge
on success;403
on token mismatch;500
ifWHATSAPP_VERIFY_TOKEN
missing.
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"}
,403
invalid signature,500
errors.