Voice JavaScript SDK Reference Components
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.
These components might reference third-party services or open source software outside of Twilio. Twilio provides these references as-is without any warranties. You must review, comply with, and maintain appropriate licenses for any such third-party services or open source tools. Twilio possesses no liability whatsoever for any such third-party services or open source software.
Before proceeding, familiarize yourself with key concepts: how the JavaScript SDK works and getting started.
The reference components demonstrate several common Twilio Voice use cases. To review detailed implementations, see 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 Conversation
- Place an outbound call and connect to an agent
- Provide a WebSocket server
- Basic OpenAI integration
- Noise Cancellation
- Apply RNNoise noise suppression to outgoing microphone audio
- Apply RNNoise noise suppression to incoming call audio
- Independently enable or disable noise suppression for each audio direction during an active call
-
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.envto.env, then supply the required values. To learn about each variable, see the quickstart.View an example .env file -
Expose your local server to the public internet so Twilio can reach it for webhooks. If you run the components locally, use a tunneling service such as ngrok.
ngrok http 3030Copy the forwarding host that ngrok returns and set it as
CALLBACK_BASE_URLin your.env— without thehttps://scheme, since the code prependshttps:///wss://itself. If you changedPORT, tunnel to that port instead of3030. -
In the Twilio Console, open your TwiML App settings and set Voice Request URL to the endpoint for the component you want to test, using your public host from step 4 in place of
yourdomain:1https://yourdomain/twilio-voice-dialer/twiml2https://yourdomain/twilio-voice-basic-call-control/twiml3https://yourdomain/twilio-voice-monitoring/twiml4https://yourdomain/twilio-voice-ai-conversation/twiml5https://yourdomain/twilio-voice-noise-cancellation/twiml
- Start the local server under the
twilio-voice-js-reference-componentsfolder.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 Conversation:
http://localhost:3030/twilio-voice-ai-conversation?identity=bob - Noise Cancellation:
http://localhost:3030/twilio-voice-noise-cancellation?identity=bob
- Dialer: