The Twilio Voice Client SDK has been renamed to Twilio Voice JavaScript SDK as of version 2.0.
The Programmable Voice SDKs allow you to add voice-over-IP (VoIP) calling directly into your web and native mobile applications.
Twilio provides four Voice SDKs:
Once you've decided on your platform, explore what Programmable Voice can do using one of Twilio's quickstarts:
Building an application with a Voice SDK requires the use of several Twilio resources. This section explains what these resources are and how they work together with your application to enable VoIP Voice calling in your browser, Electron app, or iOS or Android devices. This is not a how-to guide, but rather a general overview.
While the Voice SDKs are used to power client-side applications that the end user will see, you will still need to use some server-side code. The server side will work in tandem with Twilio to enable and manage calls to/from your client-side application.
Each Voice SDK has its own documentation on how to use the SDK on the client side. Click on an SDK below to view its client-side documentation.
The rest of this page explains how your server-side application communicates with Twilio and the Voice SDKs.
Building an application with any of the Voice SDKs requires:
An endpoint that can handle and respond to HTTP requests from Twilio
AccessTokens, which contain:
AccessTokens serve as the credentials for your end users, and are the key piece that connects your SDK-powered application, Twilio, and your server-side application.
AccessTokens are JSON Web Tokens (JWTs) that your application can create using a Helper Library. An AccessToken contains information that Twilio needs to ensure that:
Since they contain so much necessary information, AccessTokens are the first things you should check when your Voice SDK application encounters an error. You can decode an AccessToken at JWT.io.
A decoded, properly-formed AccessToken payload for a Voice SDK end user is shown below.
_18{_18 "jti": "SK835c7c8ac38c0617205f41fd71d4bb38-1643132114",_18 "grants": {_18 "identity": "SalesDepartment",_18 "voice": {_18 "incoming": {_18 "allow": true_18 },_18 "outgoing": {_18 "application_sid": "APe4c9832e936010a33e130a8b3333db71"_18 }_18 }_18 },_18 "iat": 1643132114,_18 "exp": 1643135714,_18 "iss": "SK835c7c8ac38c0617205f41fd71d4bb38",_18 "sub": "ACd29d942e419c9bdafbc55a27b1da79b1"_18}
The grants.identity
property contains the identity of the SDK end-user. To connect a call to this particular SDK user, you use this identity between <Client>'s opening and closing tags.
The grants.voice.incoming.allow
property is set to true
, which allows the SDK end-user to receive calls.
The grants.voice.outgoing.application_sid
property contains the SID for your TwiML App (see TwiML Apps section below for more information).
A typical Voice SDK use case handles AccessToken generation within the server-side application. The following example scenario illustrates one way this could work in your application:
http://www.example.com/token
.
GET
request to your
http://www.example.com/token
endpoint to retrieve an AccessToken.
GET
request. Using a
Helper Library,
your application creates an AccessToken and sends it in the response to the
GET
request from your client-side application.
See the AccessTokens documentation for more information. The Voice SDK quickstart applications also have examples of /token
endpoints that generate AccessTokens.
The AccessToken's grants.voice.outgoing.application_sid
property contains the SID for a TwiML App. A TwiML App is a Twilio Resource which holds Voice and Messaging configuration URLs. You'll only use the Voice Configuration URLs for your Voice SDK application.
You can create and configure TwiML Apps via the Console (shown in the image below) or the API.