Creating a Custom International Calling Card with Twilio

When I came downstairs this morning I was greeted by two bubbly and very sleep deprived Australians eager for some tea, and a chance to call Mum.  My first thought – there’s a Twilio app for that (or there will be soon)!

Being in the Christmas sprint, I decided I’d quickly code up an application that would make it easy for them to call a U.S. number from the landline at our house or any local phone, and be forwarded to their mom’s, boyfriends, and other folks through a simple menu.  20 minutes later, we made our first call!


Setting Up the International “Calling Card”

Twilio doesn’t provide international phone numbers, but you can set up a U.S. number and have it forward to an international destination using the <Dial> verb.  You don’t even need to use the REST API to make the outbound calls, its so simple!

Files to create:

  • * Handler for the incoming call, to greet the caller and read the menu, gather the menu selection keypress
  • * PHP handler for taking the keypress and directing the application to the right file to dial the number
  • * Files for each of the phone menu options, going to the different numbers to call

Setting up incoming-call.php

This first file is the one that I pointed the Twilio phone number to, to handle incoming calls.  It greets the caller and reads them a menu of people to call, and asks them to press a number to start.

It looks something like this:

Setting up make-call.php

After the caller has pressed as key, the application posts the results to make-call.php, so we need to create a php file that understands what to do next with that information, and route the call.

Setting up TwiML to Connect the Call

As you can see in the previous php script make-call.php, each selection directed the application to a different file.  This file is a very simple piece of TwiML that uses the <Dial> verb to connect the call.  Each one is pretty much the same, and looks like this:

It’s Not Pre-paid, It’s Pay-As-You-Go

The best part about this for Elisa and Lauren is that it isn’t a prepaid card where they spend $50 and and are stuck with the card, even if they don’t use it up.  I’m billing them for exactly the amount they use, and they don’t have to pay for it until after the fact.  I can imagine turning custom pay-as-you-go calling cards into a really interesting business.

So there you have it.  If you have any international guests in your home this holiday season, or are interested in going into the calling card business, this might be a good place to start.  The app took less than 20 minutes to write, mostly because we were goofing around with the text to speech quite a bit, and is written with PHP.

You do need an upgraded Twilio account to get a phone number and make international calls, so maybe some Twilio minutes would be a good thing to ask Santa to bring you.  Happy holidays!

  • Very cool.
    I recently had my iPhone unlocked at place in Koh Samui, Thailand (hanging out here for a few months). Popped in a cheap pay-as-you-go SIM card, and since all incoming calls are free, I realized I could make a quick Twilio app that I could load up in Safari and type in any phone number to call. I’d press submit, and have it call my Thai number, and once I picked up, have it connect me to the number I entered into the form. A very cheap way to call anywhere in the world.
    Soon I plan on re-building my entire business phone system using Twilio. The new features like call screening and conference calling are awesome.
    Met a few of ya’ll in SF earlier this year, and love what you’re doing.
    Keep up the good work Twilio!

  • Very cool.
    I recently had my iPhone unlocked at place in Koh Samui, Thailand (hanging out here for a few months). Popped in a cheap pay-as-you-go SIM card, and since all incoming calls are free, I realized I could make a quick Twilio app that I could load up in Safari and type in any phone number to call. I’d press submit, and have it call my Thai number, and once I picked up, have it connect me to the number I entered into the form. A very cheap way to call anywhere in the world.
    Soon I plan on re-building my entire business phone system using Twilio. The new features like call screening and conference calling are awesome.
    Met a few of ya’ll in SF earlier this year, and love what you’re doing.
    Keep up the good work Twilio!

  • Very sweet script.
    I’m doing something similar can’t wait to get it off the ground!!
    This code really got me going. I’m looking at a way to use back-end db and update contacts on the fly. Hopefully also let them charge up their account from a website.
    I want this for those free incoming cell phones too. That could save me tonnes :)
    Thx for sharing, this code finally got me into the Twilio vibe!!

  • Very sweet script.
    I’m doing something similar can’t wait to get it off the ground!!
    This code really got me going. I’m looking at a way to use back-end db and update contacts on the fly. Hopefully also let them charge up their account from a website.
    I want this for those free incoming cell phones too. That could save me tonnes :)
    Thx for sharing, this code finally got me into the Twilio vibe!!

  • Very interesting concept, thanks for the tutorial and the information!

  • Very interesting concept, thanks for the tutorial and the information!

  • Prepaid Cards

    Amantel offer international prepaid
    phone cards to call long distance calling from USA, Canada and
    Australia. Cheapest and best cell phone calling cards to call India,
    Pakistan, Sri Lanka, Bangladesh and Nepal.

    Amantel calling card also available to
    call Kenya @ 2.5¢, Liberia @ 4.5¢, Nigeria @ 1.9¢, Cameroon
    @4.8¢, Ethiopia @ 5.9¢, Ghana @ 4.5¢, Guyana @ 5.5¢, Senegal
    @6.6¢ and Uganda @ 2.9¢ from USA and Canada.

    For more info visit-

    Website: http://www.amantel.com

    Email: info@amantel.com

  • Quentin

    Hi,

    I am interested in doing the same thing (transferring a US number to my Chinese number, perhaps with a Nodejs layer). I wanted to have a quick look at what you did but the repository is not available anymore. It is a bit of a old post, I hope you will help me.

    • Hi, all the code you would need is above. We’ll try to updated this post to make it easier to read. If you have questions just email help@twilio.com and the team can walk you through it.

  • Simple Call

    Can anyone suggest be the best international calling card to make frequent call to London, Canada and Bangladesh from India as my family and relatives lives there. I need a reliable connection that should be free from drop age, hassle, fuss and distrubance.