Introducing Twilio Application Connect for Programmable Voice

February 21, 2023
Written by

Introducing Application Connect

As Twilio grows and powers more customer applications, more Twilio customers want to interact with other Twilio customers.

For some time now, Twilio customers have wanted to be able to send calls from their Voice applications to other customers' Voice applications, whether as a method of forwarding a call or to use a third-party service. Additionally, Twilio customers who want to compose applications and separate functional concerns (for example: call control, IVR, Pay, etc.) can't do this within a single account and have to resort to composing large, complex applications to do the job.

Introducing Twilio Application Connect

Today, we are excited to announce the launch of Twilio Application Connect.

Application Connect will allow you to streamline your Voice call flows across and between your Twilio accounts and with other Twilio customers. With this new functionality, you can connect your Twilio Programmable Voice applications directly from one Twilio account to another without adding phone numbers, call legs, or complexity while maintaining valuable call context across the connection. And: no more unnecessary PSTN/SIP call legs!

Before Twilio Application Connect, if you wanted to connect Twilio accounts, you needed something in-between to call, whether a Twilio Phone Number or an external SIP proxy. Those solutions resulted in additional connectivity call legs, adding costs and complexity to your call flow. Additionally, maintaining valuable customer context required the aforementioned SIP proxy, which could be difficult, time-consuming, expensive, and could add latency.

Twilio Application Connect eliminates the need for these methods and dramatically simplifies how you connect your Voice calls between Twilio accounts. A simple TwiML command allows you to connect your Application to another account's Application, without adding PSTN or SIP call legs. The result is a more straightforward, direct way to connect your Voice calls to other accounts without the hassle and added connectivity charges inherent in previous solutions.

The actual process is straightforward – use the existing TwiML <Dial> verb with the new <Application> noun to send your call to another Application SID:

<Dial>
 <Application>APxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</Application>
</Dial>

A Call that invokes this new method will be directly connected to the Application in question without adding any extra inbound or outbound call legs.

You can pass context using custom parameters in your <Dial> statement, and they will show up at the destination Application as part of the webhook it invokes, just like your typical Twilio call. You can then handle the call in the same way as if it reached your Application from a Twilio phone number, SIP Domain, or Client connection.

Twilio Application Connect Flow for Programmable Voice

How it works

Twilio Application Connect works essentially the same way you are already used to using Twilio Programmable Voice; you connect legs of a Voice call using the existing <Dial> verb with the new <Application> noun.

You handle the Inbound call leg (to your Twilio phone number, SIP domain, or Client SDK) the same way you do today. Application Connect uses the existing Programmable Voice TwiML Application construct to encapsulate your created applications that return TwiML code into a reusable resource. You create a TwiML application containing a Webhook URL; this gives you an Application SID. Using this Application SID, you can dial out to your TwiML Application using <Dial><Application> commands.

Pass as much context as you like using the <Parameter> noun, with simple attribute/value pairs; they will show up in the receiving Application’s webhook! Then, when the receiving Application has done its thing, it can return context back to the caller using the <Hangup> or <Reject> verbs, and the same <Parameter> noun.

You can enable/disable inbound <Dial><Application> calls on your TwiML Apps (also known as Application Resources) from your Twilio Voice Console under your TwiML Apps, or by setting the PublicApplicationConnectEnabled property of the Application Resource to true. Allowing calls via <Dial><Application> on a particular TwiML App opens it up to receive <Dial><Application> connections from anyone, so you should only give the TwiML App’s Application SID for that application to Twilio and your trusted party that needs to connect, and you should implement some sort of authentication in the receiving TwiML App.

TwiML Syntax

The TwiML example below shows a basic use of <Dial><Application>. These instructions can be used in any TwiML endpoint to direct a call to a TwiML App.

<?xml version="1.0" encoding="UTF-8"?>
<Response>
 <Dial action="http://example.com/your-action-endpoint">
   <Application copyParentTo="true" customerId="CustomerFriendlyName">
   <ApplicationSid>AP1234567890abcdef1234567890abcd</ApplicationSid>
     <Parameter name="AccountNumber" value="12345"/>
     <Parameter name="TicketNumber" value="9876"/>
   </Application>
 </Dial>
</Response>

Specify the receiving TwiML App's SID by nesting the <ApplicationSid> noun between <Application>'s opening and closing tags. The receiving TwiML App's Voice Request URL will receive an HTTP request from Twilio containing the default request parameters, as well as any other parameters specified with <Parameter> nouns.

Returning Parameters

At the end of a <Dial> instruction, Twilio sends a request to the <Dial> verb's action URL. TwiML Apps that receive calls via <Dial><Application> can send custom parameters in this request to the action URL by using <Hangup><Parameter> or <Reject><Parameter> TwiML.

Parameters sent to the originating <Dial>'s action URL with <Hangup><Parameter> or <Reject><Parameter> will be prefixed with ReturnParam_.

Returning Parameters using <Hangup>

<?xml version="1.0" encoding="UTF-8"?>
<Response>
 <Pause length="1"/>
 <Say>Congratulations, Your Application connected!</Say>
 <Hangup>
   <Parameter name="AgentName" value="Alice"/>
   <Parameter name="CallDuration" value="342"/>
 </Hangup>
</Response>
<?xml version="1.0" encoding="UTF-8"?>
<Response>
 <Reject reason=”rejected”>
   <Parameter name="CallState" value="refused"/>
   <Parameter name="RejectReason" value="Invalid Account"/>
 </Reject>
</Response>

Simplified Billing

Billing is performed only on the receiving call leg at $0.0025 per minute. This offers significant savings over the previous methods of connecting across accounts/applications, as this eliminates billing legs at a price lower than even our SIP In/Out rates.

What this Enables

This functionality unlocks a plethora of options for numerous customer use-cases:

  • Existing Twilio customers can now easily use the services of other valuable customer products powered by Twilio without resorting to calling out via the PSTN.
  • Customers can also use different Twilio subaccounts to separate traffic, functions, or engineering team access to their call flow(s).
  • New customers can simplify their solutions using Twilio-powered services by using a Twilio phone number to terminate calls, rather than complex/lengthy forwarding from other carriers, eliminating extra call legs and simplifying troubleshooting.
  • Enterprise customers can more easily route their Voice traffic between departments/business units/entities within their organization while maintaining context.
  • Customers can more quickly and efficiently use exciting Twilio products like Flex, Pay, or Gather, where sensitive data needs to be isolated by sequestering traffic to Applications that handle those functions.

Twilio customers amaze us daily with the unique and powerful solutions they build. Now, with Application Connect, extending and multiplying those solutions for other Twilio customers and solutions with their unique setups is possible.

For more information on Twilio Application Connect, please check out the Usage and TwiML documentation, contact Twilio Sales or your Account team, or reach out to Twilio Support.

We can't wait to see what you build!

Bill Harrison is a Product Manager of SIP and Voice Connectivity at Twilio. He spends way too much time reading PCAPs, discussing SIP and BYOC, coaching youth hockey, and watching his beloved Boston sports teams. He can be reached at wharrison [at] twilio.com