Archive for January, 2012

Playing with a Monkey

Upon reading the first few quickstart lessons I knew I was gonna enjoy this since Twilio chose to replace the standard and cliché “Hello World” with a more appropriate “Hello Monkey” introduction application.

I figured that exploring the SMS component of the platform might be an easier place to start given the simplistic nature of SMS in general. I wanted to start with a simple script for sending an outbound SMS message to a small list of recipients, so I read over the guide for Sending Text Messages via the Rest API and began writing some code based on the sample in the referenced quickstart. The documentation on that quicktart guide is really easy to follow and worth a read.

Here is what my first script turned out to look like.


 require "Services/Twilio.php";

 // set my AccountSid and AuthToken

 // instantiate a new Twilio Rest Client
 $client = new Services_Twilio($AccountSid, $AuthToken);

 // make a list of people I know, indexed by phone number.
 $people = array(
 "+1415XXXXXXX" => "Reid",
 "+1415XXXXXXX" => "Michael",

 foreach ($people as $number => $name) {

 // Send a new outgoing SMS */
 $sms = $client->account->sms_messages->create(
 // the number I'm sending FROM, must be a number associated with my Twilio account (either verified or a purchased number). Go to your account page on Twilio to either purchase a number or verify an existing number.
 "XXX-XXX-XXXX", $number,

 // the body of the SMS message. $name will be the name from the list of people above.
 "Hey $name, I'm just sending you a quick message to try Twilio."

 // Let me know that the message was sent.
 echo "Sent message to $name";

Once that was created, I simply pushed this file (and the associated PHP helper libraries) to our dotcloud account. Once our URL was returned, I launched it via a browser and within a few seconds received our first SMS message. Or, you can run the php code from the terminal on a Mac simply with php sms_send.php

Beyond easy.

In my next post I’ll discuss how I played with merging the Callin’ Oates code such that we could send an SMS message to individuals that called into our phone number. 


Getting Set….

When Michael and I got together to start playing with the Twilio tools and APIs for the first time, I was immediately intrigued by the simplicity of the system and how well Twilio had laid out the guide for beginners. As you could see in my first post, the necessary code is pretty straightforward. However, there was some pre-work that had to be done prior to our first lines of code being written.

Before we could really get started, we had to build out a primitive dev environment to allow us to collaborate on the codebase while experimenting. Here is what we needed:

  1. Dropbox account for sharing files. If you don’t have one, get one.
  2. dotCloud account for deploying the applications. Once you have an account, you will need to install their command line interface (CLI) application. Instructions available here. If you already have access to a server on the web, you might be able to skip this step and use your own.
  3. Twilio account. Free to create and play around with. Go get one…..I’ll wait.
  4. A Twilio phone number to use. Once you get into your Twilio account, go ahead and buy a number. I didn’t worry about the area codes, most cell phones these days are free long distance anyway.
  5. I was most familiar with PHP, so I chose that as the basis for our work. Depending on the language of your choice, you will likely need to download the API libraries from Twilio.

Michael and I are Apple fanboys so all of this development was done on our Macs.

Our first usage of the system was going to simply be for exploration of the platform while learning the nuts and bolts of the TwiML language used to power our future applications. Once our dev environment was created and running we turned to the Twilio docs, specifically their quickstart guides to learn. The first example, Hello Monkey.