jmhobbs

Developing For Twilio In PHP - Introducing Twillip

Last weekend I had the fun opportunity of building my first Twillio app with a group at the Omaha Startup Weekend. We wrote a phone based version of chattroulette called Call Spinner which includes a cool advertising system we hope to expand on.

Developing for Twilio isn't that hard, it's mostly just about generating the right XML. We used the PHP library Twilio provides and it's pretty nice, but debugging off of the Twilio website was a waste of money and not much fun.

So, over the last few days I worked out a nice debugging tool I decided to call Twillip. What it does is conditionally wrap your code and prints it in a clean fashion, with links and variables and other goodies like that.

Super simple to use too! Here, this is a contrived example. Normally you probably want some sort of cool dispatcher (I have one of those if you want it) and to check that requests are signed, etc.

example.php

addSay( 'This app uses Twillip for obviously awesome reasons!' );
    $r->addPlay( 'funky-beats.mp3', array( 'loop' => 3 ) );
    $r->addRedirect( '/doesntexist.php' );
  }
  else {
    $r->addSay( 'Oh no! I didn\'t get sent a phone number! Who in blue blazes are you?' );
    $r->addSay( 'This line will generate a PHP warning now: ' . $_REQUEST['Caller'] );
  }
  $r->respond();

  if( IS_DEV ) { Twillip::End(); }

Sweet, so what does that buy us? Only this awesome interface is all!

Twillip - Oops!

But there is an error! $_REQUEST['Caller'] isn't set. We can fix that by clicking on the Add New Input and filling it in.

Twillip - New Input Prompt

Twillip - New Input

There it is! Now we can click Reload Page and it will refresh with all of the inputs.

Twillip - No More Errors!

You can't tell in the image, but the Redirect and Play verbs are both clickable links, and will bring all of the variables in the input section with them.

Seeing is believing, so try it out at http://static.velvetcache.org/pages/2010/09/16/developing-for-twilio-in-php-introducing-twillip/demo/

You can grab the source at http://github.com/jmhobbs/Twillip.