For basic Twilio setup, see the Configure > Numbers > Twilio guide.
Set up connector
Create a PolyAI Connector and retrieve your Connector Token.
Configure routing
Use TwiML or Twilio Studio to route calls to PolyAI.
Handle handoffs
Manage live-agent handoffs with the PolyAI Handoff API.
Capabilities
- Automated call handling: Twilio routes incoming calls to PolyAI virtual agents, where customer queries are resolved, or additional data is captured for live-agent handoffs.
- Live-agent handoffs: The PolyAI virtual agent passes contextual data from PolyAI to Twilio Flex, to be displayed in the Flex UI.
- Routing: Supports Twilio Studio flows and programmable routing using TwiML syntax.
Set up connector
To integrate PolyAI with Twilio, create a PolyAI Connector. The connector links Twilio with your PolyAI project configuration.Request connector setup
Connector setup is managed by PolyAI. Contact your account manager or PolyAI representative to request a connector for your Twilio integration. Provide the following information:- Friendly name: A descriptive name for your connector
- Account ID: Your PolyAI account identifier
- Project ID: Your PolyAI project identifier
- Client environment:
live,pre-release, orsandbox - Variant ID: (if applicable)
- Language codes: ASR and TTS language codes (e.g.,
en-GB,en-US)
Outputs
PolyAI will provide:- Connector ID: Used for debugging configurations.
- Connector Token: Required for linking the PolyAI Connector in Twilio.
Mapping notes
Each Twilio Connector maps directly to:- A PolyAI Connector.
- A PolyAI project configuration.
Configure routing
Twilio offers two routing methods: TwiML and Twilio Studio.TwiML syntax
Define your Twilio flow with the<Connect> tag:
Twilio Studio flow
- Open Twilio Studio.
- Add a Make HTTP Request widget to retrieve PolyAI handoff context using an API.
- Use a Send To Flex widget to route calls to agents with the retrieved context.
- Save and test the flow.
Handle handoffs
PolyAI provides detailed call context for live-agent handoffs:- Store handoff data: PolyAI captures customer information in the
context.state.handoffobject. - API retrieval: Twilio Functions fetch this data using the PolyAI Handoff API.
- Flex display: The data is passed to Twilio Flex, where live agents can view it in the Flex UI.
Example Twilio Function
Related documentation
- Configure > Numbers > Twilio - Basic Twilio phone number and SMS setup
- Call Handoffs - Configure handoff destinations
- Handoff API - Retrieve handoff context programmatically

