Host agents as Whatsapp Applications.
Prerequisites
Create a Meta App
Set Up a Meta Business Account
Setup WhatsApp Business API
Setup Environment Variables
.envrc
file in your project root with the following content, replacing placeholder values with your actual credentials:direnv allow
).Setup Webhook with ngrok
WHATSAPP_WEBHOOK_URL
environment variable and your Meta App webhook configuration each time ngrok assigns a new URL.https://
URL provided by ngrok. This is your base ngrok URL./webhook
(or your chosen prefix) to the ngrok URL (e.g., https://<random-string>.ngrok-free.app/webhook
). Update WHATSAPP_WEBHOOK_URL
in your .envrc
if necessary.WHATSAPP_VERIFY_TOKEN
in your .envrc
file.messages
field under whatsapp_business_account
.Configure Application Environment
APP_ENV
environment variable:WHATSAPP_APP_SECRET
for webhook signature validation:
WhatsappAPI
, and serve it:
OPENAI_API_KEY
environment variable is set if using OpenAI models.http://localhost:8000
), but interaction is primarily via WhatsApp through the configured webhook.http://localhost:8000/docs
.WhatsappAPI
: Wraps Agno agents/teams for WhatsApp integration via FastAPI.WhatsappAPI.serve
: Serves the FastAPI app using Uvicorn, configured for WhatsApp.WhatsappAPI
ClassParameter | Type | Default | Description |
---|---|---|---|
agent | Optional[Agent] | None | Agno Agent instance. |
team | Optional[Team] | None | Agno Team instance. |
settings | Optional[APIAppSettings] | None | API configuration. Defaults if None . |
api_app | Optional[FastAPI] | None | Existing FastAPI app. New one created if None . |
router | Optional[APIRouter] | None | Existing APIRouter. New one created if None . |
app_id | Optional[str] | None | App identifier (autogenerated if not set). |
name | Optional[str] | None | Name for the App. |
description | Optional[str] | None | Description for the App. |
agent
or team
, not both.
Method | Parameters | Return Type | Description |
---|---|---|---|
get_app | use_async: bool = True prefix: str = "" | FastAPI | Returns configured FastAPI app. Sets prefix, error handlers, and includes WhatsApp routers. Async router is used by default. |
prefix
(default is root level: ""
).
GET /webhook
200 OK
: Returns hub.challenge
if tokens match.403 Forbidden
: Token mismatch or invalid mode.500 Internal Server Error
: WHATSAPP_VERIFY_TOKEN
not set.POST /webhook
APP_ENV="production"
and WHATSAPP_APP_SECRET
is set).agent.arun()
or team.arun()
.200 OK
: {"status": "processing"}
or {"status": "ignored"}
.403 Forbidden
: Invalid signature.500 Internal Server Error
: Other processing errors.Parameter | Type | Default | Description |
---|---|---|---|
app | Union[str, FastAPI] | N/A | FastAPI app instance or import string (Required). |
host | str | "localhost" | Host to bind. |
port | int | 7777 | Port to bind. |
reload | bool | False | Enable auto-reload for development. |