Working around PSTN congestion with Twilio Client
Time to read: 5 minutes
In these unprecedented times of social distancing and a virus pandemic, we are seeing a huge increase in the number of voice calls being made. Our Super Network team is working around the clock to ensure that calls make it through. However, in some areas, we are seeing that lines from carriers are so congested that the calls are never reaching Twilio. Here in this tutorial, we will outline some options to bypass the congestion on the PSTN by using Twilio Client.
Twilio Client is a WebRTC based voice client that works in browsers and mobile devices using a data connection. Once a client call is connected to Twilio it can be routed directly to your existing infrastructure via SIP or uncongested PSTN paths allowing calls to continue to flow.
Currently, your customers and staff may be struggling to connect to your contact centers or business-critical services because of congestion on the public telephone network. Twilio Client allows your customers to leverage their data connections to bypass the congested parts of the public network in several ways.
- Direct routing to your Twilio application
- Routing to your existing infrastructure via SIP
- Routing into your infrastructure by directing calls to non-congested links
If you’re already running your telephone applications on Twilio, then it is a straightforward matter to point the Twilio Client directly to your incoming studio flow or TwiML voice application. Twilio Studio is a visual interface to design, deploy, and scale customer communications. You can find out more in the Twilio Studio User Guide.
If you run a large network with connections to the public telephone network in different regions, then customer calls can be routed through to less busy offices either domestically or internationally with no additional costs to the calling party. This is achieved by routing the customer's call over Twilio’s Global Super Network. In the example below the US Office is unreachable, so we're using the Twilio Super Network to carry the call to separate infrastructure in Australia.
Twilio’s Client SDKs allow you to make voice calls to and from a web browser or mobile application and a Twilio TwiML voice application. Twilio Client leverages WebRTC and has built-in orchestration of all signaling, media, and firewall traversal services to provide a seamless experience.
A key part to note with the client setup is that in order to connect to Twilio’s infrastructure, a client requires a valid Access Token. Access Tokens are generated by your application logic using the Twilio Libraries. They allow a client to connect to a specific voice application only. Therefore, by tightly controlling Access Tokens, you can control access and routing of your voice client.
The security of your web-based client is an important consideration. It usually doesn’t take long for public-facing voice clients to be found by scanning tools. There are several ways that your application should be secured here.
- Restrict where the client can call. For this scenario, I recommend having it either forward to a fixed point or provide a simple visual IVR e.g., three different options that a user can click.
- Reduce exposure to your web client by placing the client page behind an existing login system or by producing short-lived access URLs that are shared with customers or staff via some other means such as SMS, chat, or email.
- Add a pin and or password that a user needs to enter when they first connect. This could be a simple Twilio Studio Flow or an update to your on premise queues.
- Overview of Twilio Client
- Build In-Browser Calling with Twilio Client
- React Twilio Phone by Phil Nash
When setting up your Client experience, you’ll need to think about whether you want to allow users to enter DTMF digits, perhaps to navigate an IVR. If you do, then you’ll need to ensure that your client phone presents a dialpad to the users and leverage the sendDigits command in the client library.
Connecting to Twilio over SIP is relatively easy. We have two types of connectivity: SIP Interface, which connects to Twilio’s Programmable Voice infrastructure and Elastic SIP Trunking, which is a replacement for traditional SIP services from carriers with instant global scale.
We’re going to be using SIP Interface here, refer to this introduction to SIP with Programmable Voice to get started. In particular, for outbound calls towards your infrastructure, you should refer to Receiving SIP from Twilio. If you’re looking for configuration guides for your equipment, you should check out some of our SIP Trunking Configuration Guides.
As mentioned above, each Twilio Client access token is tied to a TwiML application. The TwiML application points to the logic that Twilio should execute to route your call. We will now show how to handle the routing for the three options above.
This is the simplest solution to setup. Point the TwiML application Request URL at your Studio Flow or Twilio Application URL as shown below
Routing to SIP Infrastructure
The simplest way to route to your SIP infrastructure is to create a TwiML Bin that points to your SIP endpoint. To do this, head over to create a TwiML Bin in the console. Create a bin similar to the one below, replacing the SIP destination with your chosen target. Once you create the TwiML Bin, you should copy the URL and put this into your TwiML Applications request URL.
Routing to an alternate PSTN link
Sending to an alternative PSTN link is what we would usually refer to as call forwarding. Call forwarding can be set up in a similar way to above, for example as with the below TwiML Bin.
<?xml version="1.0" encoding="UTF-8"?>
Alternatively, other options such as Studio or Twilio Functions can also be used as outlined here.
As we have seen here, Twilio’s WebRTC based clients can be used to allow your customers and staff to easily bypass congested PSTN infrastructure enabling you to deliver better experiences and provide essential services in this time of need.
From APIs to SDKs to sample apps
API reference documentation, SDKs, helper libraries, quickstarts, and tutorials for your language and platform.
The latest ebooks, industry reports, and webinars
Learn from customer engagement experts to improve your own communication.
Twilio's developer community hub
Best practices, code samples, and inspiration to build communications and digital engagement experiences.