Skip to main content

Interface Parameters

Pass one of agent, team, or workflow to the Whatsapp constructor.
from agno.os.interfaces.whatsapp import Whatsapp

Whatsapp(agent=my_agent, prefix="/whatsapp")
ParameterTypeDefaultDescription
agentOptional[Union[Agent, RemoteAgent]]NoneAgno Agent instance.
teamOptional[Union[Team, RemoteTeam]]NoneAgno Team instance.
workflowOptional[Union[Workflow, RemoteWorkflow]]NoneAgno Workflow instance.
prefixstr"/whatsapp"URL prefix for WhatsApp endpoints (e.g., /whatsapp means webhooks arrive at /whatsapp/webhook).
tagsOptional[List[str]]NoneFastAPI route tags for API documentation. Defaults to ["Whatsapp"].
show_reasoningboolFalseWhen True, sends the model’s reasoning content as an italicized message before the main response.
send_user_number_to_contextboolFalseWhen True, injects the user’s phone number and incoming message ID into the agent’s context via dependencies.
access_tokenOptional[str]NoneWhatsApp Business API access token. Falls back to WHATSAPP_ACCESS_TOKEN environment variable.
phone_number_idOptional[str]NoneWhatsApp Business phone number ID. Falls back to WHATSAPP_PHONE_NUMBER_ID environment variable.
verify_tokenOptional[str]NoneWebhook verification token. Falls back to WHATSAPP_VERIFY_TOKEN environment variable.
media_timeoutint30Timeout in seconds for media downloads from and uploads to Meta’s media API.
enable_encryptionboolFalseWhen True, encrypts user phone numbers with AES-256-GCM before storing them as user_id. Requires WHATSAPP_ENCRYPTION_KEY or the encryption_key parameter.
encryption_keyOptional[str]None32-byte hex key (64 characters) for phone number encryption. Falls back to WHATSAPP_ENCRYPTION_KEY environment variable.

Endpoints

Available at the /whatsapp prefix (customizable with prefix).

GET {prefix}/status

Returns {"status": "available"}. Use for health checks.

GET {prefix}/webhook

Handles WhatsApp webhook verification during setup.
StatusDescription
200Verification successful. Returns the hub.challenge value.
400Missing hub.challenge parameter.
403hub.verify_token does not match WHATSAPP_VERIFY_TOKEN.
500WHATSAPP_VERIFY_TOKEN is not set.

POST {prefix}/webhook

Receives all WhatsApp webhook events. Processing happens in the background so Meta gets a response within their timeout window.
StatusDescription
200 {"status": "processing"}Messages received and queued for background processing.
200 {"status": "ignored"}Non-WhatsApp event (e.g., object is not whatsapp_business_account).
403Invalid X-Hub-Signature-256 signature.
500WHATSAPP_APP_SECRET not set and WHATSAPP_SKIP_SIGNATURE_VALIDATION not enabled.

Built-in Message Handling

Message TypeBehavior
TextPassed directly to the agent as the input message.
Image, video, audio, documentDownloaded from Meta’s media API and passed as Agno media objects (Image, Video, Audio, File).
Interactive (button reply)The selected button’s title is extracted and passed as text input.
Interactive (list reply)The selected row’s title and description are extracted and passed as text input.
/new commandCreates a new session. Old session is preserved. Requires a db on the agent/team/workflow.
Unsupported typesStickers, contacts, and other types receive a “not supported yet” reply.

Outgoing Media

Agent responses containing media are automatically uploaded to Meta’s media API and sent to the user.
FormatBehavior
Images (JPEG, PNG)Uploaded and sent. Other formats (GIF, WebP, HEIC) are skipped.
VideoUploaded and sent as video/mp4.
Audio (AAC, MP4, MPEG, OGG, WAV)Uploaded and sent directly.
Audio (raw PCM, e.g., from TTS)Auto-converted to WAV before upload.
DocumentsUploaded with detected MIME type and filename.
Long text (>4096 chars)Split into numbered batches: [1/3], [2/3], [3/3].

Developer Resources

WhatsApp Guide

Setup, code examples, media handling, and troubleshooting.

WhatsAppTools Reference

Toolkit parameters and methods for interactive messages, media, and locations.