Things you’ll need
- An active Telnyx account with API credentials
- One or more Telnyx provisioned phone numbers
- A public-facing server or tunneling service like ngrok (for dial-out only)
- API keys for speech-to-text, text-to-speech, and LLM services
Telnyx Dial-in Example
Complete dial-in implementation using Telnyx Media Streaming over WebSocket
Telnyx Dial-out Example
Outbound calling using Telnyx Media Streaming with WebSocket transport
Phone Number Setup
You’ll need Telnyx phone numbers for both dial-in and dial-out functionality:- Visit telnyx.com and purchase phone numbers
- Ensure your numbers support Voice capabilities
- Configure TeXML applications for dial-in numbers (covered below)
Environment Setup
Configure your environment variables for Telnyx and AI services:.env
Dial-in
Dial-in allows users to call your Telnyx number and connect to your Pipecat bot via WebSocket Media Streaming. Unlike Twilio, Telnyx automatically provides caller information (to/from numbers) in the WebSocket messages, so no custom server is needed for basic dial-in functionality.How It Works
Here’s the sequence of events when someone calls your Telnyx number:- Telnyx receives an incoming call to your phone number
- Telnyx executes your TeXML application which establishes a WebSocket connection
- Telnyx opens a WebSocket to your server with real-time audio and call metadata
- Your bot processes the audio using the Pipecat pipeline
- The bot responds with audio sent back to Telnyx over WebSocket
- Telnyx plays the audio to the caller in real-time
Set up your TeXML application
Telnyx uses TeXML (Telnyx Extensible Markup Language) to control call flow. For dial-in, you create a TeXML application that establishes a WebSocket connection directly to your bot:TeXML for dial-in
bidirectionalMode="rtp" parameter enables real-time audio streaming in both directions.
Personalizing Your Bot with Caller Information
Telnyx automatically includes caller information (to/from numbers) in the WebSocket messages. You can use the caller’s phone number to:- Look up customer information in your database
- Personalize greetings and responses based on caller identity
- Route calls to different bot behaviors (e.g., VIP handling, support vs sales)
- Implement custom business logic based on the caller
Configure your Pipecat bot for dial-in
Your bot receives the WebSocket connection and automatically gets call information from Telnyx’s WebSocket messages. The key components are: WebSocket Parsing: Pipecat’s built-in parser extracts call data from Telnyx’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 Telnyx TeXML application
Configure your Telnyx phone number to use your TeXML application:- Go to the Telnyx Portal
- Navigate to Voice → Programmable Voice → TeXML Applications
- Create a new TeXML Application with your WebSocket URL
- Assign the TeXML Application to your phone number
Complete Setup Instructions
See the full README with step-by-step setup, TeXML configuration, and testing
Dial-out
Dial-out allows your bot to initiate calls to phone numbers using Telnyx’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 Telnyx call using the Call Control API
- Telnyx 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 Telnyx call using the Call Control API with a webhook URL
- Accepts the WebSocket connection from Telnyx
- Parses call data including call control information
- 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, with Telnyx automatically providing call information. Call Information: Telnyx provides call details in the WebSocket messages:bot.py
server.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
Telnyx Media Streaming uses 8kHz mono audio with 16-bit PCM encoding. Configure your pipeline accordingly:Automatic Call Termination
When you provide Telnyx API credentials to theTelnyxFrameSerializer, it automatically ends calls when your pipeline ends:
Built-in Call Information
Unlike other providers, Telnyx automatically includes caller information (to/from numbers) in the WebSocket messages, eliminating the need for custom webhook servers in basic dial-in scenarios.Deployment
Pipecat Cloud Deployment
For production deployment without managing your own infrastructure, use Pipecat Cloud:Telnyx WebSocket on Pipecat Cloud
Deploy Telnyx 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 Telnyx 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