Robo Calling with Twilio

Last updated: Jul 15, 2012

Every one hates to get political or an automated spam robo call; however, I recently had the opportunity to create one that people loved and it was stupid simple thanks to Twilio.

My girlfriend has a tradition of reciting the speech from the movie Independence Day, on our Independence Day:


She has the speech memorized and had been manually calling her friends each year to deliver the performance. People loved it but her list of people to call grew to over 100 people which took over three hours of calling last year.

This year I told her I could probably help her out and automate it. I didn’t expect it to be so easy.

I first had her export her contacts from her phone into a CSV where she edited some of the contacts. We then used the following Ruby script that I created with the fantastic twilio-ruby library to load the CSV and loop through each phone number:

    require 'rubygems'
    require 'twilio-ruby'
    require 'csv'

    # put your own credentials here
    account_sid = 'ACCOUNTID'
    auth_token = 'TOKEN'

    # set up a client to talk to the Twilio REST API
    @client = Twilio::REST::Client.new account_sid, auth_token

    CSV.foreach('phonenumbers.csv', :headers => true) do |csv_obj|
        if csv_obj['PhoneNumbers']
            phone_number = csv_obj['PhoneNumbers']
            puts phone_number # <-- Watch the progress
            @call = @client.account.calls.create(
            :from => '+15551234567',
            :to => phone_number,
              :url => 'http://someinternetaccessiblepath.com/twilio.html'
              )
          end
    end

I set the from phone number to hers so to her friends it appears that the call is coming directly from her phone.

Twilio requires a URL to hit once the recipient picks up. Since my response is static I hosted both the MP3 and Response XML on Amazon S3 to avoid the hassle of setting up a web server.

Here is all that is required:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Play>https://s3.amazonaws.com/somes3bucket/id4/id4-high.mp3</Play>
</Response>

We used Audacity to put some background music to the speech and add some megaphone like echo for maximum effect.

Here is the end result.

Need to print shipping labels on your site?

Checkout my product RocketShipIt for simple easy-to-use developer tools for UPS™ FedEx™ USPS™ and more.

Get notified on new posts or other things I'm working on

Share: