A Little More Fun With Twilio

I’m been trying to keep up with multiple stories (Sprint-Clearwire “4G”,  Harbinger Capital’s nationwide LTE network , iPad) while running around tending other assignments.  No, I don’t have much of a smartphone,  more of a Bronze-age artifact that came with my Verizon plan.  So how do I monitor my RSS feeds  using my basic cell phone when I’m away from desk?

My only requirement was that I won’t compromise my core philosophy of  applying minimal programming effort to the task at hand. I’m thankful to be living in the right era to help me stay true to my beliefs: they’re so many great software components and productivity  tools available that it’s possible to glue together off-the-shelf parts to produce a useful digital time-saver with minimal perspiration.

As you know from a previous post, I’m excited about Twilio’s VoiceXML-lite hosting service. I will also reveal for the first time my love for a visual-oriented RSS mashup tool from Yahoo, called Pipes.

I just needed to glue a simple Pipes workflow to a little bit of PHP that calls Twilio’s SMS service and I’d have a poor man’s news notifier. 

I find myself monitoring Google Reader many times a day  to follow my favorite blogs and news services.  I’m not always at my desk, and as I explained I’m one of the last people in America without a smartphone. It would be a great if I could  be notified of current stories by SMS—say within the last few hours–that match certain criteria.

Yahoo Pipes solved the first piece of the puzzle. I discovered this rapid development (but under-publicized ) programming tool about a year ago when I was grappling with the problem of hunting down stale content and bad URLs in a large corporate web site. Pipes is peerless at reading multiple streams of Web content, filtering, and generating a new, unique RSS feed without a stitch of programming.

It’s really an exercise  in drawing connectors between Pipes widgets– think of it as Unix Pipes specialized for the web age. You can get a glimpse of my handiwork over on the right. ( I’ve also made the Pipe project public, just click on the image.)

The remainder of the project was pretty straight forward. I’m thankful to De-Panther for making public his Curl-based PHP code for reading  RSS feeds.  I just modified it a tad.

The other—and to my mind—the most import piece was Twilio’s REST APIs. It provides the critical connection between the Internet- and the cell phone -verses.   This project  would not have been possible without Twilio’s straightforward cloud-based voice  and messaging functions.

I’m currently using the trial account, and now leaning towards using Twilio’s pay-as-you-go  when my balance reaches $0.

global $RSS_Content;
// Include the PHP TwilioRest library
require "twilio.php";

// Twilio REST API version
$ApiVersion = "2008-08-01";

// Set our AccountSid and AuthToken
$AccountSid = "XXXXXXXXXXXXXXXXXXXXXXXXXXX"
$AuthToken = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX";

// Instantiate a new Twilio Rest Client
$client = new TwilioRestClient($AccountSid, $AuthToken);

$size =4;
RSS_Retrieve("http://pipes.yahoo.com/pipes/pipe.run?_id=6b4fee9a603787f21ba153ac0ca28b06&_render=rss", $size);
if($size > 0)
$recents = array_slice($RSS_Content, 0, $size);

foreach($recents as $article)
{
$title = $article["title"];
$descr = strip_tags($article["description"]);
$descr = substr($descr,0,80)."...";

// Send a new outgoinging SMS by POST'ing to the SMS resource
$response = $client->request("/$ApiVersion/Accounts/$AccountSid/SMS/Messages",
"POST", array(
"To" => "862-224-4612",
"From" => "415-599-2671",
"Body" => "!!"."$title"."!!".$descr
));

}

To summarize: My Pipes widget streams out headlines  no older than two hours  that contain keywords I’m interested in.  I tweaked some PHP code—it runs as a cron job on Blue Host, my blog hosting service—that periodically reads and parses the synthetic Pipes feed.   The last piece: a headline and the first few characters of the story are SMSs’ed to my cell phone courtesy of Twilio’s REST API.

I am now very informed and up-to-date-no matter where I happen to be.

Reblog this post [with Zemanta]