Local Telephone Numbers Rocking In The Free World (Through The Ngrok Data Center Closest To You)
Time to read: 4 minutes
Grab your phone. We’re going to try out ngrok’s new local traffic routing feature using local Twilio numbers in the US, EU, AP, and Australia.
Still got your phone in hand? Good. Welcome to Operation Keep On Ringing In The Free World. We’re going to buy four Twilio phone numbers in the four different ngrok data center territories and make them play music from local artists, piped through ngrok’s local data centers.
What You’ll Need
A Twilio Account
The latest version of ngrok.
Local Numbers, Local ngrok Data Centers, Local Music
The first place we’ll stop on Operation Keep It Ringing etc… is the US of A. Representing the US is Bruce Springsteen.
First, head to Twilio.com and buy an US phone number. Then store the song you to play to your listeners on in a directory called “Jams”. We’ll keep all our code here as well.
Fire up terminal, cd into the “Jams” directory and start up server in the language of your choice. I got a php server up and running with the command php -S localhost:8888.
Next, open a new Terminal window and fire up an ngrok server on the same port — but use the brand new routing feature.
./ngrok http -subdomain=[whatever your subdomain is] -region=us 8888
Now we have a way to get our code and our jams out to Twilio to play for the world. I’ll be playing “Born In The USA” to anyone that calls in. I saved the file as “Bruce.mp3” in the “Jams” directory. Now, just a few lines of XML and we’re ready.
I just need to tell Twilio that the to the caller should be to the Bruce track which I’ve made accessible via my ngrok localtunnel. Open up your text editor and enter the following.
Let’s save this file as “US.xml” Head back to Twilio, paste your ngrok forwarding url plus the file extension in the voice request field. My forwarding url is [whatever your subdomain is] and the file extension of my XML code is US.xml So I’d copy [whatever your subdomain is]/US.xml into the voice request URL field of my number.
Hit save and you’re done! Dial it up and you’ve got a US jam that’s locally routed.
Hitting Other Stops On The Tour
I used the same workflow to set up some rock-powered numbers in France, Japan, and Australia. Here’s the code powering those phone lines.
Number Locality: France
Ngrok Region: eu
Artist Chosen: Phoenix
Song: “Lizstomania”
./ngrok http -subdomain=[whatever your ngrok forwarding url is]-region=eu 8888
Number Locality: Japan
Ngrok Region: ap (Asia Pacific)
Artist Chosen: AKB48
Song: “Sugar Rush”
./ngrok http -subdomain=[whatever your ngrok forwarding url is] -region=ap 8888
Number Locality: Australia
Ngrok Region: au
Artist Chosen: AC/DC
Song: “Thunderstruck”
./ngrok http -subdomain=[whatever your ngrok forwarding url is] -region=au 8888
More Music Powered Hacks
That’s all there is to it! Now you’ve got less latency when you’re testing out your apps, and 100% more rock. If you need anymore music-themed Twilio ideas, try this rock-themed IVR tutorial in PHP.
Related Posts
Related Resources
Twilio Docs
From APIs to SDKs to sample apps
API reference documentation, SDKs, helper libraries, quickstarts, and tutorials for your language and platform.
Resource Center
The latest ebooks, industry reports, and webinars
Learn from customer engagement experts to improve your own communication.
Ahoy
Twilio's developer community hub
Best practices, code samples, and inspiration to build communications and digital engagement experiences.