Cover image for Virtual support phone number with Twilio

Virtual support phone number with Twilio

josefrousek profile image Josef Rousek Originally published at blog.rousek.name ・3 min read

For a long time I was looking for a simple and, well, cheap solution to isolate my support phone number from my personal number and I recently found the solution.

I like how Twilio makes things simple for developers so they were my first and only bet. What was I actually trying to achieve? I wanted to have a phone number that I could redirect to my phone and when the traffic gets high enough send caller to voicemail when needed. I also wanted to make a phone calls from that number using SIP phone.

First, create a Twilio account and get voice-enabled phone number. Now we need to connect the dots. Let's assume +420111111111 is your number and +420999999999 is the number you got from Twilio.

Receiving calls

Twilio uses TwiML a markup language used to tell Twilio what to do when you receive an incoming call or SMS. The place where we will store our TwiML commands is called TwiML Bins. TwiML Bins allow you to write TwiML that Twilio will host for you - so we don't have to spin up a web server.

Runtime > TwiML Bins is the place where we can manage our Bins.

Create a new bin called Forward incoming calls to my phone and paste following code.

<?xml version="1.0" encoding="UTF-8"?>
  <Dial callerId="+420999999999">

Incoming call Bin

Then we need to associate this bin with a phone number. In Phone Numbers > Manage Numbers section select your phone number and look for a field called A call comes in. Select TwiML and the select the bin we just created.

Phone number management

That's it, you should now be able to accept incoming phone calls. Try calling your Twilio number.

Making calls using your Twilio number

To make outgoing call using the Twilio number we will need to use VoIP application like Zoiper which is available on Android and iOS. To use this application we need to set up a SIP domain. In Programmable Voice > SIP Domains create a new domain.

New SIP Domain

Make sure that you associate credentials for both Voice Authentication and SIP Registration. Then we create another TwiML Bin to handle outgoing calls.

<?xml version="1.0" encoding="UTF-8"?>
  <Dial callerId="+420999999999">

The interesting part of this command is {{#e164}}{{To}}{{/e164}}. When using SIP Interface the To value that gets passed down is in following form sip:+15125551212@freelance.sip.us1.twilio.com. Function e164 extracts the phone number from this text. After saving this bin we will copy its URL and use it as Request URL in the SIP Domain we created.

Zoiper configuration

Now that Twilio is setup we can actually make an outgoing call. We will use our SIP credentials we created before. You might have to fill in domain with the region us1 as domain without region or with any other didn't work for me.

Zoiper Configuration

I'm pretty happy with the way how this solution works and the calls and number itself are cheap.


Editor guide
lorismi34947986 profile image
Lori Smith

Hey, I just love the way you describe about the virtual phone numbers

dangargano profile image

Another alternative to Twilio is toll free numbers from Global Call Forwarding or AI Telephone

mf777star profile image

I'd never heard of Twilio until I read your post. Interesting! I have been using virtual phone numbers for some time and have been very happy with the benefits the numbers and features have brought to my business. I honestly can't imagine using my regular cell phone or a landline for business. Virtual is the way to go.