Things you’ll need
- An active Plivo account with API credentials
- One or more Plivo provisioned phone numbers
- A public-facing server or tunneling service like ngrok
- API keys for speech-to-text, text-to-speech, and LLM services
Plivo Dial-in Example
Complete dial-in implementation using Plivo Media Streaming over WebSocket
Plivo Dial-out Example
Outbound calling using Plivo Media Streaming with WebSocket transport
Phone Number Setup
You’ll need Plivo phone numbers for both dial-in and dial-out functionality:- Visit plivo.com and purchase phone numbers
- Ensure your numbers support Voice capabilities
- Configure XML applications for dial-in numbers (covered below)
Environment Setup
Configure your environment variables for Plivo and AI services:.env
Dial-in
Dial-in allows users to call your Plivo number and connect to your Pipecat bot via WebSocket Media Streaming.How It Works
Here’s the sequence of events when someone calls your Plivo number:- Plivo receives an incoming call to your phone number
- Plivo calls your XML server with call details
- Your server responds with XML that establishes a WebSocket connection
- Plivo opens a WebSocket to your server with real-time audio
- Your bot processes the audio using the Pipecat pipeline
- The bot responds with audio sent back to Plivo over WebSocket
- Plivo plays the audio to the caller in real-time
Set up your XML server
Your server handles Plivo webhooks and WebSocket connections for real-time audio streaming. When Plivo receives a call, your server:- Receives the webhook with call details (CallUUID, caller information)
- Returns XML that establishes a WebSocket connection to your server
- Accepts the WebSocket connection from Plivo
- Parses call data from the WebSocket messages
- Runs the Pipecat bot with the parsed call information
Custom Data with Query Parameters
You can pass custom data to your bot by adding query parameters to the WebSocket URL in your XML response. This works for both dial-in and dial-out scenarios:server.py
Complete Server Implementation
See the full FastAPI server code with XML generation and WebSocket handling
Configure your Pipecat bot for dial-in
Your bot receives the WebSocket connection and parses the call data to extract call information. The key components are: WebSocket Parsing: Pipecat’s built-in parser extracts call data from Plivo’s WebSocket messages:bot.py
bot.py
Complete Bot Implementation
See the full bot.py with WebSocket parsing, transport setup, and pipeline
configuration
Set up Plivo XML application
Configure your Plivo phone number to use your XML application:- Go to the Plivo Console
- Navigate to Voice → XML Applications
- Create a new XML Application with your server’s webhook URL
- Assign the XML Application to your phone number
Run the Example
For local development, use ngrok to expose your local server:Complete Setup Instructions
See the full README with step-by-step setup, XML configuration, and testing
Dial-out
Dial-out allows your bot to initiate calls to phone numbers using Plivo’s outbound calling capabilities with WebSocket Media Streaming.How It Works
Here’s the sequence of events for dial-out calls:- Your application triggers a dial-out (via API call or user action)
- Server initiates a Plivo call to the target phone number
- Plivo establishes the call and opens a WebSocket connection
- Your bot joins the WebSocket and sets up the pipeline
- The recipient answers and is connected to your bot
- The bot handles the conversation with real-time audio streaming
Set up your server for dial-out
The dial-out server creates outbound calls and manages WebSocket connections. When you trigger a dial-out call, your server:- Receives the dial-out request with target phone number and parameters
- Creates a Plivo call using the Voice API with XML that establishes WebSocket
- Accepts the WebSocket connection from Plivo
- Parses call data from the WebSocket messages
- Runs the Pipecat bot with the call information
Complete Server Implementation
See the full FastAPI server code with outbound call creation and WebSocket
handling
Configure your Pipecat bot for dial-out
The dial-out bot configuration is similar to dial-in. You can also pass custom data using the same query parameter approach described in the Custom Data with Query Parameters section above. Call Information: Extract call details from Plivo’s WebSocket messages:bot.py
bot.py
Complete Bot Implementation
See the full bot.py with outbound call handling and call information usage
Run the Example
To test dial-out functionality:- Start your server: Run your FastAPI server
- Trigger a call: Make an API request to start an outbound call
- Answer your phone: The bot will call the specified number
- Talk to your bot: Have a conversation with your AI agent
Complete Setup Instructions
See the full README with step-by-step setup, API usage, and outbound call
configuration
Key Features
Audio Format and Sample Rate
Plivo Media Streaming uses 8kHz mono audio with μ-law encoding. Configure your pipeline accordingly:Automatic Call Termination
When you provide Plivo credentials to thePlivoFrameSerializer
, it automatically ends calls when your pipeline ends:
Deployment
Local Development
Use ngrok to expose your local server for testing:Pipecat Cloud Deployment
For production deployment without managing your own infrastructure, use Pipecat Cloud:Plivo WebSocket on Pipecat Cloud
Deploy Plivo WebSocket bots with automatic scaling and managed infrastructure
Self-Hosted Production Deployment
For fully self-hosted production deployment, ensure your servers are:- Publicly accessible with HTTPS
- Able to handle concurrent WebSocket connections
- Properly configured with Plivo API credentials
- Implementing proper error handling and logging
Next Steps
- Explore the complete examples for full implementations
- Learn about Daily + Twilio SIP integration for advanced telephony scenarios
- Check out Daily PSTN integration for direct phone number provisioning