Using Telnyx with Twilio
The Telnyx network offers unparalleled security, reliability and call quality. That’s because we’re a true carrier, and unlike many CPaaS providers, we don’t rely on middlemen to provide core communications functionality and routing.
But we appreciate that switching providers is no easy task. That’s why we’ve made our SIP services incredibly easy to integrate with whichever communications provider you’re already using. By making one simple change to your existing TwiML code, Twilio will send your calls to Telnyx via SIP, and we’ll then deliver your calls to their destination.
So you can still experience all the benefits of our superior network while continuing to use your existing applications.
So… What are the benefits?
The Telnyx network improves call quality, global scalability and lowers latency, all at significantly lower costs than any other provider. Customers typically save around 40% on voice costs when they choose to leverage our private, global network.
How do I get started?
The following instructions will explain how to configure both sides so that calls from Twilio are authenticated using your Telnyx Connection.
In this guide we use a TwiML application as an example, but the token configuration on Twilio side will follow the same analogy for any other Twilio API based application (SDK, node, python, etc).
- Login to the Telnyx Mission Control portal.
- Click on the Connections menu option and then Add Connection.
- Enter a Name and select Type: IP address.
- Under Expert IP Auth Settings choose the option Token and register the suggested Token (or define any alphanumeric value that you prefer). Click Save.
- On the same connection, click "+ Add IP" to add the following Signaling IP addresses that belong to Twilio. To do that just go to Twilio’s Networking Information page on the portal, and see what are the Signaling IPs for your region. For example, if you are using Twilio North America Virginia those would be:
- Click on Save all Changes. Your Connection should look like the image below.
- Click on the Outbound menu option and create a new Outbound Profile or use an existing one.
Assign the new Connection to the Outbound Profile to allow outbound calls to be authorized.
Your Telnyx Connection is now ready to accept traffic from your Twilio account!
Note: the following example uses a TwiML based application, but the same analogy and guidance for the Telnyx Token configuration is the same for any other Twilio API based application, i.e. SDK, Python, Node, etc.
- Login to the Twilio Portal.
Have your TwiML application set in TwiML Apps tab:
Create an TwiML application that forwards calls to Telnyx and adds a Token header like the one from this example:
1 2 3 4 5 6 7 8 9 10 11
<?xml version="1.0" ?> <Response> <Say>Please hold while we connect the call.</Say> <Dial> <Sip> sip:<your-destination-number>@sip.telnyx.com?X-Telnyx-Token=<your-connection-token> </Sip> </Dial> </Response>
- You can trigger your application by adding it to a call flow, e.g. assigning it to a Twilio phone number and making a call to that number.
- Once the application reaches that step, Twilio will send a SIP INVITE message to Telnyx to establish the call like the one from this example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
INVITE sip:<your-to-number>@sip.telnyx.com SIP/2.0 Record-Route: <sip:18.104.22.168:5060;lr> CSeq: 1 INVITE From: "<your-from-number>" <sip:<your-from-number>@sip.twilio.com>;tag=------------- To: <sip:<your-to-number>@sip.telnyx.com> Max-Forwards: 67 Date: Wed, 16 Oct 2019 21:20:40 GMT Min-SE: 120 X-Telnyx-Token: <your-token> Call-ID: ------------------------ Via: SIP/2.0/UDP 22.214.171.124:5060;branch=------------- Via: SIP/2.0/UDP 172.18.18.112:5060;rport=5060;received=172.18.18.112;branch=---------------- Contact: "<your-from-number>" <sip:<your-from-number>@172.18.18.112:5060;transport=udp> Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,NOTIFY User-Agent: Twilio Gateway X-Twilio-AccountSid: <your-twilio-id> Content-Type: application/sdp X-Twilio-CallSid: -------------- Content-Length: 238 v=0 o=root 1836844584 1836844584 IN IP4 126.96.36.199 s=Twilio Media Gateway c=IN IP4 188.8.131.52 t=0 0 m=audio 12240 RTP/AVP 0 101 a=rtpmap:0 PCMU/8000 a=rtpmap:101 telephone-event/8000 a=fmtp:101 0-16 a=ptime:20 a=sendrecv
- Telnyx will accept that SIP INVITE and will place/redirect the call to the PSTN number placed in the SIP URI.
The Telnyx customer support team is available 24/7 to provide you with technical support and answer any questions about using Telnyx with your Twilio application.
Telnyx is not associated with, sponsored or endorsed by Twilio.