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. 

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: