Overview
WhatsAppClient enables real-time voice conversations between WhatsApp users and your Pipecat bot through the WhatsApp Business API. When users call your WhatsApp Business number, the client handles webhook events, establishes WebRTC connections, and manages the voice call lifecycle.
The transport integrates with Meta’s WhatsApp Cloud API to receive incoming calls, process WebRTC signaling, and maintain call state throughout the conversation.
WhatsApp API Reference
API methods for Pipecat’s WhatsApp Cloud API integration
WhatsApp Client Reference
Pipecat’s Client for handling webhooks and WebRTC connections
Example Implementation
Complete WhatsApp voice bot example
WhatsApp Business API Docs
Meta’s official WhatsApp calling documentation
Installation
To useWhatsAppClient, install the required dependencies:
Prerequisites
WhatsApp Business API Setup
Before usingWhatsAppClient, you need:
- WhatsApp Business API Account: Set up through Meta Developer Console
- Phone Number Configuration: Enable voice calling capability for your business number
- Webhook Configuration: Configure webhook endpoint to receive call events
- Access Tokens: Generate API access token and phone number ID
Required Environment Variables
WHATSAPP_TOKEN: WhatsApp Business API access tokenWHATSAPP_PHONE_NUMBER_ID: Your business phone number IDWHATSAPP_WEBHOOK_VERIFICATION_TOKEN: Token for webhook verification
Key Features
- Incoming Call Handling: Automatically accepts WhatsApp voice calls
- WebRTC Integration: Establishes peer-to-peer audio connections
- Webhook Processing: Handles Meta’s webhook events for call lifecycle
- Call Management: Supports call acceptance, rejection, and termination
- Real-time Audio: Bidirectional audio streaming for natural conversations
Configuration
WhatsAppClient
WhatsAppClient is the main class for handling WhatsApp call connections. It manages webhook processing, WebRTC connection establishment, and call lifecycle.
str
required
WhatsApp Business API access token for authentication.
str
required
WhatsApp Business phone number ID.
aiohttp.ClientSession
required
An aiohttp session for making async HTTP requests to the WhatsApp Cloud API.
List[IceServer]
default:"None"
List of ICE servers for WebRTC connections. If
None, defaults to Google’s
public STUN server (stun:stun.l.google.com:19302).str
default:"None"
WhatsApp App Secret for validating that webhook requests came from WhatsApp.
When set, all incoming webhooks are verified using HMAC SHA-256 signature
validation, so pass the raw request body and the
X-Hub-Signature-256 header
to handle_webhook_request() as raw_body and sha256_signature; a webhook
without them raises.Usage
WhatsAppClient requires a webhook server to handle incoming calls and a bot implementation to process the conversations. It works with SmallWebRTCTransport under the hood for WebRTC connectivity.
The WhatsAppClient handles the WhatsApp-specific webhook processing and call management, while the actual audio transport uses a SmallWebRTCConnection for each call.
Connection Callback Signature
When handling webhook requests, you provide a connection callback that receives the established WebRTC connection and call metadata:WhatsAppConnectCall object contains:
from_: Caller’s phone numberto: Called phone numberid: Unique call identifierdirection: Call direction (“inbound” or “outbound”)timestamp: Call timestamp
- FastAPI webhook server with verification endpoint
- WhatsApp client configuration
- Bot integration with Pipecat pipeline using
SmallWebRTCTransport - Environment setup and deployment
Methods
handle_verify_webhook_request()
hub.challenge of Meta’s webhook verification request, for the endpoint to send back. params are the request’s query parameters. Raises ValueError when a parameter is missing, hub.mode isn’t "subscribe", or hub.verify_token doesn’t match expected_verification_token.
handle_webhook_request()
connect event answers the call with a new SmallWebRTCConnection and passes it to connection_callback, and a terminate event disconnects the call. Returns True when the event was handled, and False when ending a call fails. Raises ValueError when the request has no connect or terminate event, and Exception when the signature check or answering the call fails. An exception in connection_callback is logged, not raised.
terminate_all_calls()
Notes
- WhatsApp only supports SHA-256 fingerprints in SDP, so the client automatically filters out other fingerprint types.
- Each incoming call creates a new
SmallWebRTCConnectionthat can be used withSmallWebRTCTransport. - The client supports both
pre_acceptandacceptcall flow as required by the WhatsApp Cloud API.
Additional Resources
- Events Overview - Overview of all events in Pipecat
- SmallWebRTCTransport - The underlying transport used for WebRTC connectivity
- WhatsApp Cloud API Calling Docs - Official WhatsApp calling documentation