Handling your business calls and texts like a... boss!
Time to read: 3 minutes
I dread the idea of having ever to change my phone number. Be it because I'm getting spammed, or because someone thinks it's a good idea to call me during the night every night for the...rest...of...my...life. I'd much rather throw away all my business cards with a disposable phone number than to dispose of my real phone number which I had for 15 years now.
To make sure we never have to dispose of our real number, today we are going to look at how to provision new phone numbers that you can give out to people or put on your business cards without leaving the Twilio Console.
Our tools
- A Twilio account - you can get one for free here
- (optional) A picture frame - because you're going to want to put your picture up looking like a boss when you finish this.
Handling text messages
The first thing we need to do is go to the phone numbers page and buy a phone number.
The beauty of these numbers is that we can release them just as easily as we can get them, which ties well with the idea of never having to "release" the beloved phone numbers we've held for years. (Note that Twilio will charge for holding a phone number for part of a month).
I chose a UK mobile number and then headed to the setup page. In that page and under "Messaging", select "TwiML" and press the "+" button.
On the modal window that the "+" button just opened, enter a name for your TwiML bin. I called mine "Business Card". Add the following code to handle incoming SMS messages.
Replace the value YOUR_PHONE_NUMBER
with your actual mobile number in E.164 format so any incoming messages to your Twilio phone number get redirected to you, then hit 'Save'. You're done with this setup and are ready to handle phone calls.
Handling voice calls
We could do the same thing we did above with phone calls and be done with it, but I like to treat people who call me directly a little better.
Head to Runtime and create a new Twilio Function. On the Management page click the "+", choose "Blank" and click "Create". Give that a name – I called mine "Personal Voicemail" – and set the path to be "/personal-voicemail".
We want to do a couple of things with this function:
- Be able to answer calls to our Twilio number on our own number
- Block certain numbers
Choose "Incoming Voice Calls" under "Event" and add the following code:
The code above check that the number calling your Twilio number is not in the deny list and in that case will forward the call to your real telephone number, and you can let it go to voicemail.
Make sure you replace the YOUR_PHONE_NUMBER
value with your actual mobile number. If you have any numbers you want to add to the deny list, add them comma-delimited like so:
Go back to the phone numbers page. Under "Voice & Fax" choose "Function" for "When a Call Comes in" and then select your new function and hit save.
When someone calls or texts your Twilio phone number, they should get redirected to your real phone number. You will then have the option to answer it or send straight to voicemail as you would normally.
Boss mode: Unlocked!
Now that our number is safe from spam or abuse, we can rest assured knowing that if ever anyone gets hold of our Twilio number and decides to abuse it, we can always release it and get another one using the code we've already written.
Furthermore, we can have several numbers using the same code so we can give them away at different occasions.
I would love to hear about smart ways in which you use Twilio to make your life easier. Hit me up on @marcos_placona or leave a comment below.
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.