Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Voice SDKs


(warning)

Warning

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:

  • Voice JavaScript SDK , which allows users to make and receive VoIP calls in a web browser or an Electron app
  • Voice iOS SDK , which allows users to make and receive VoIP calls on iOS devices
  • Voice Android SDK , which allows users to make and receive VoIP calls on Android devices
  • Voice React Native SDK , which allows users to make and receive VoIP calls on Android or iOS devices

Quickstarts

quickstarts page anchor

Once you've decided on your platform, explore what Programmable Voice can do using one of Twilio's quickstarts:


Build a Voice SDK application

build-a-voice-sdk-application page anchor

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.

Requirements

requirements page anchor

Building an application with any of the Voice SDKs requires:

  • A Twilio Account
  • One or more Twilio Phone Numbers
  • An endpoint that can handle and respond to HTTP requests from Twilio

    • Some requests from Twilio (such as those sent when your Twilio phone number receives an incoming call) will require Voice TwiML instructions to be sent in response.
    • Other requests, like status callbacks, provide your server-side application with information related to calls, recordings, etc. For these requests, Twilio only expects a successful HTTP status code in response.
  • AccessTokens, which contain:

  • One of the Voice SDKs
  • A Helper Library to generate AccessTokens and TwiML (depending on your use case)

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(link takes you to an external page)) that your application can create using a Helper Library. An AccessToken contains information that Twilio needs to ensure that:

  • The calls to/from the Voice SDK are associated with the correct Twilio account
  • Incoming calls are enabled or disabled
  • The identity of the end user of the Voice SDK is known to Twilio
  • Outbound calls from your Voice SDK application are handled by Twilio using the proper TwiML instructions
  • The AccessTokens will expire at the proper time

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(link takes you to an external page).

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:

  1. Your server-side application has an endpoint at http://www.example.com/token .
  2. Your client-side application sends a GET request to your http://www.example.com/token endpoint to retrieve an AccessToken.
  3. Your server-side application receives the 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.
  4. Your client-side application receives the AccessToken.

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(link takes you to an external page) (shown in the image below) or the API.

Create a new TwiML App in the Console and configure the Voice Configuration Request URL.Rate this page:

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.