Voice JavaScript SDK: Reference Components
Info
You're viewing the documentation for the 2.X version of the Voice JavaScript SDK. View the Migration Guide to learn how to migrate from 1.X to 2.X or view the 1.x-specific documentation.
While the quickstarts enable you to quickly set up a functional application for making and receiving phone calls via a web browser in just a few minutes, the reference components offer flexible building blocks for your Twilio Voice applications. Designed around common Twilio Voice use cases, these components leverage Web Components to showcase integrated backend and frontend implementations. You can easily incorporate these components into your application or use them as a foundation for your development needs.
Before proceeding, take a moment to explore how the JavaScript SDK works and review the getting started page to familiarize yourself with key concepts.
The reference components demonstrate several common Twilio Voice use cases. For detailed implementation guidance, visit the Twilio Voice JavaScript Reference Components repository. These use cases include:
- Dialer
- Place outgoing calls
- Receive incoming calls
- Basic call control (uses Conference)
- Perform cold or warm transfers
- Add or remove participants
- Hold and Resume a call
- Mute and Unmute a call
- Monitoring (uses Conference)
- Observe call progress
- Track conference call status
- View quality metrics
- Receive warnings
- View errors
- Voice AI Assistant
- Place an outbound call and connect to an agent
- Provide a WebSocket server
- Basic OpenAI integration
- Clone the Twilio Voice JavaScript Reference Components GitHub repository.
git clone https://github.com/twilio/twilio-voice-js-reference-components.git
- Install the dependencies.
npm install
- Copy
example.env
to.env
, then supply the required values. For details about each variable, see the quickstart.
1# Port number to run the server on2PORT=303034# Twilio account sid5ACCOUNT_SID=ACxxxxxxxxxxxxxx67# Twilio API key8API_KEY_SID=SKxxxxxxxxxxxxxx910# Twilio API secret11API_KEY_SECRET=xxxxxxxxxxxxxx1213# Twilio TwiML App SID14# The Voice Request URL must point to one of the /twiml endpoints listed later in this guide.15# For details, see https://www.twilio.com/docs/voice/sdks/javascript#twiml-applications16APP_SID=APxxxxxxxxxxxxxx1718# Twilio auth token19AUTH_TOKEN=xxxxxxxxxxxxxx2021# Caller ID22CALLER_ID=+112345678902324# Public base URL that Twilio can reach.25# If you run the components locally, use a tunneling service such as ngrok.26# Do not include the scheme (https:// or wss://) in the URL.27CALLBACK_BASE_URL=foo.ngrok.dev2829# Default identity to use30DEFAULT_IDENTITY=alice3132# twilio-voice-ai-assistant33# See https://platform.openai.com/settings/organization/api-keys34OPENAI_API_KEY="sk-proj......."
- In the Twilio Console, open your TwiML App settings and set Voice Request URL to the endpoint for the component you want to test:
1https://yourdomain/twilio-voice-dialer/twiml2https://yourdomain/twilio-voice-basic-call-control/twiml3https://yourdomain/twilio-voice-monitoring/twiml4https://yourdomain/twilio-voice-ai-assistant/twiml
- Start the local server under the
twilio-voice-js-reference-components
folder.
npm start
- Open a browser and navigate to a component URL.
- Dialer: http://localhost:3030/twilio-voice-dialer?identity=bob
- Basic call control: http://localhost:3030/twilio-voice-basic-call-control?identity=bob
- Monitoring: http://localhost:3030/twilio-voice-monitoring?identity=bob
- Voice AI Assistant: http://localhost:3030/twilio-voice-ai-assistant?identity=bob