Twilio launched MMS last week on all of its US and Canada phone numbers. A variety of hacks were unleashed by myself and other members of the evangelism team (if you haven't checked out the Mustached Messaging Service, you really need to 'stash yourself).
One of the hacks I put together (animated cats via MMS) is actually so easy to build that I wanted to show you how I put it together so that you can get started with your own MMS hacks! If you want to see the cat gif hack on your phone, send "cats" to (484)483-2287.
I'm super stoked to see what you build so make sure to email me at email@example.com or hit me up on Twitter @brentschooley with your MMS creations. For now, let me show you how to stitch this hack together and send animated cat gifs to your phone via MMS.
(This project is available on Github)
What you'll need to make this work is a Twilio account (create one here) with an MMS-enabled number and a Sinatra server with the twilio-ruby gem installed. You can install Sinatra and twilio-ruby by punching the following lines into the terminal:
With those pieces in place, all we need to do is create a file to hold our server code. Run this in terminal:
I promised this would be quick and easy so I'm just going to drop this code here:
This code uses the wonderfully simple API known as The Cat API to generate a random animated cat gif. This URL is passed as the Media URL for the Response that will be sent back to Twilio when an incoming text message is received at your Twilio number. (Note: If you are not using a helper library and are just returning TwiML directly, you will need to properly escape the ampersands in the URL.)
Speaking of incoming messages, you'll need to set up your Twilio number to point at the server code you just wrote to handle those incoming texts. You can do that here. Click on your number and set the Messaging Request URL as shown below to point at the URL where you deployed your Sinatra server (I recommend Heroku - details here):
That's it! Send your Twilio number a text message and you should receive a random animated cat gif. Share this with all of your friends!
I think sending a text message and getting back a cute little cat running around doing something hilarious is pretty rad. That being said, I'm really excited to see what you'll do with Twilio MMS! Please leave a comment on this post or email me at firstname.lastname@example.org or find me on Twitter @brentschooley and share what you build.