Look Who's Talking

Look who's talking

Once Upon a Time

Have a seat, I will tell you a story.

Before talking about Twilio, I’m going to talk about my motivation to use it. It was for a support phone app, Support Roulette. After all, we didn’t use it exactly as is, although we used part of it.

Due to the easiness to implement an app able to answer a call, record a voice message, send and receive a text message, in other words, an app which talks, I got inspired to write this post and also to present a Tech Talk (Vim talk hehe) about it.

Support Roulette

We needed a phone support 24x7 in case the website becomes unavailable and other possible urgent issues.

Our idea was to nominate a support developer weekly.

The MVP was to buy a cheap cellphone (its battery is infinite, on the other hand, it doesn’t even have the snake game) and keep it with the developer on duty. The idea was mainly to have a fixed phone number for our customer service call, in case of emergency.

Problems with the cheap cellphone

Everybody already has a cellphone. Carrying another is annoying. Easy, very easy to forget.

Solution

We decided to use a Communication as a Service (CaaS) to register a fixed phone number in Brazil, which receives a call and redirects it to the developer on duty cellphone.

Voip

The standard Voip services that we evaluated, even though they allow to register a fixed phone number in Brazil and redirect the calls, don’t allow to change the redirect target number via API. We would have to access their control panel weekly and configure the new redirect target number. As developers, we want to schedule the support agenda and have an app that will notify the new developer on duty and make the redirects.

Why Twilio?

Other options

There are other options of CaaS, however not all of them offer fixed phone number in Brazil or simple and well documented API. Based on what we evaluated, Plivio seemed to be the best competitor.

Apps which talk

Given communication (voice and text) powers to an app, we can add many interesting features, such as:

Have look at Twilio Customer Success Stories for other use cases.

Homemade Pingdom with Monit + Twilio

Monit is an utility for managing and monitoring process, programs etc.

Pingdom is a service for monitoring uptime, downtime and performance of websites.

An usual usage of Pingdom is to use it only to monitor uptime, basically to notify someone if the website is down. We can achieve it in a homemade way with Monit + Twilio.

Monit script

# /etc/monitrc

check host rexnuke with address 127.0.0.1
  if failed port 8080
   with timeout 15 seconds
   then
   exec "ruby notify-site-is-down.rb"

Ruby script

# /usr/bin/notify-site-is-down.rb
require "rubygems"
require "twilio-ruby"

account_sid = "ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
auth_token = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"

@client = Twilio::REST::Client.new account_sid, auth_token

@client.account.sms.messages.create(
  from: "+5511…",
  to: "+5511…",
  body: "Houston we have a problem, the website is down."
)

Costs

In the case of Support Roulette, there are two costs: one for voice, when Twilio receives a call and redirects it and another for text, to notify the new developer on duty (“Congratulations, you are the new developer on duty :trollface:”).

Voice

The voice cost is in two legs: to receive and redirect (make) a call.

To receive a call: 1¢/minute

To make a call: 33¢/minute

Text

SMS messaging from an American Twilio phone number to Brazil starts at 1.2¢ however this price will vary depending on the carrier you are sending SMS messages to. Elaine Tsai, Twilio Support

Brazilian fixed number phone lines don’t send text yet. To send a text to Brazil, an American number is required. The main inconvenience of doing it, is, in case it’s needed to send or reply a message, it must be to an American number.

To send a text: starts at 1.2¢/message

Fixed number

Fixed brazilian number: 3$/month

Fixed american number: 1$/month

Getting started

The initial steps are: TwiMLTM: the Twilio Markup Language and Twilio REST Web Service Interface.

Example of TwiMLTM:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Say voice="woman">Please leave a message after the tone.</Say>
</Response>

I also recommend you to have a look at Support Roulete source code, it is a simple Sinatra application which uses the gem twilio-ruby and builders to generate TwiMLTM. It can be free hosted on Heroku.

Twimlets

Twimlets are tiny web applications that implement basic communication functionality, such as: call forward, voicemail etc.

If you are in New York but you want a fixed number in Rio de Janeiro, you can easily create a Twilio account, configure a twimlet for a forward call and in less than 10 minutes everything will be working as expected. Awesome!