Building Beyond Google Voice With Twilio: Working Hours, Whitelists and Blacklists

You can download this entire application from Github.

I have a confession.The number on my business cards is not a Twilio number–it’s for Google voice.

I’ve used Google Voice for forwarding and voicemail and it’s served me well but I wanted to add more awesome features like whitelisting, black listing, transcribing voice mail, and managing lists via SMS. That’s when Twilio fit into the picture.

I’ll show you how I used Twilio to get fine grained control over who calls me when. At any time, I’m interacting with customers, event organizers, and partners who need to reach me outside business hours. But, there are a bunch of people who may not need to reach me at 11pm on a Wednesday.

When setting these features up, three concepts stood out: working hours, whitelists, and blacklists.

At first pass, that seemed complex, so I decided to build into it step by step.

Step 1: Call Forwarding

A call comes in and we forward it to my selected number. The explanation is almost longer than the code:
 

Step 2: Adding Voice Mail

Next, we need voice mail captured and emailed to us. For flexibility, I wired two possible options: recording url only or recording url and text transcription. I can choose which via the parameters on the Record verb.
 

The two options result in similar code, so I’ll just share the recording url-only option here:
 

Step 3: Whitelists & Working Hours

Up to this point, I haven’t created any new functionality, so let’s introduce working hours. If you call during working hours, you are forwarded, otherwise you get voice mail. Of course, now we should add a whitelist so some people – my wife, boss, etc – always get through. We can accomplish this by adding lines 6, 10, and separate actions for allowed vs disallowed as seen here:
 

The function is_allowed (line 10) is pretty simple. If the caller is on the whitelist, they get through automatically. Otherwise the caller is subject to the configured working hours:
 

That’s a good start, but it assumes that we a) know our whitelist in advance and b) want to hear from everyone during working hours. Let’s be honest, there are some people who should always get voice mail.

Step 4: Blacklists, Whitelists and SMS-Control

Finally, let’s add a blacklist and an SMS interface to manage each lists. First, let’s catch the incoming text messages and validate they’re from me:
 

* Caveat: In our Security documentation, you can find more information about validating the request as truly coming from Twilio. I absolutely recommend that for production.

Finally let’s actually route and process the incoming message:

This allows us to use SMS to manage the whitelist (allow 17035551212), the blacklist (block 15128675309), check which list a number is on (status 15128675309), or clear them from the list completely (remove 17035551212). Now, whether I’m boarding a flight, sitting at my desk, or at a conference with flaky wifi, I can update my lists and route my calls accordingly with just a text message.

While this is steadily becoming a powerful little application, it’s still only a fraction of what is possible. With just a little more effort, I could have realtime call tracking and logging, retrieve information from a CRM – like Salesforce or SugarCRM – to provide a “whisper” before I even take the call, or integrate with my calendar to route calls even more intelligently.

Regardless, now my only limitation is the time I want to put into it, not the functionality available.

If you’d like to help with the project, you can download the code from Github.