Roger Stringer Shows You How To Live Blog With Twilio SMS And Simperium
Time to read: 3 minutes
Roger Stringer (pictured right), independent developer, Twilio DOer, and author of the Twilio Cookbook built a hack that lets you post photo and text updates to your blog via Twilio SMS.
Read the full post originally published on his blog here, and check out his tutorial below.
Live Blogging with Twilio and Simperium
Live blogging is pretty handy, when attending events, it never hurts to be able live blog about the latest new gadgets.
We’re going to build a simple live blogging app using PHP, Simperium and Twilio.
This particular live blog solution is set up for one event, this means all posts to the phone number we specify will show up.
You could build on this to allow for multiple events, but that’s a little more than we want to dive into today.
And yes, we could also use Pusher for this, but I like Simperium as it serves as both a datastore and a real-time push service, so that way we can store our posts on Simperium, and viewers are updated instantly.
Since these posts are just a line or two or text and a picture.. We don’t need anything too advanced for our data storage…
Since it’s the framework I use for a lot of projects, I once again, built this using the Jolt Micro Framework, which works well for building apps rapidly.
You’ll need a few things things to set this up:
- A Twilio account
- A Simperium.com account
- The Twilio PHP library
- The Simperium PHP library
- Download the Jolt PHP Framework
- Unzip it, open up config.ini, and add the following settings:
- Create a folder called Services/
- Download the Twilio PHP library and save it to the Services/ folder.
- Download the Simperium PHP library and save it to the Services/ folder.
- Open index.php and copy the following code:
Our main focus is the /listener section of the code, which is what talks to Twilio.
When we receive a new message, we check to see if the message had any images or not, and if it did, then we cycle through each image. We then save the image locally, resize it, and post it to Simperium using the Simperium PHP library. If no image was passed, then we just save the message as it was sent to the system.
The other part of this is how we get a unique id for each post, which is using the generate_uuid() to create a unique UUID compatible string.
7. Create a file called functions.php, and copy the following code:
The main part of this file is the cropResize function which will take any given image and crop and resize it to fit the dimensions we give it. This is handy when dealing with larger sized images.
8. Open views/home.php and copy the following code:
- This is the brains of our real-time notifications, as we send posts and images to our live blogging app, this is where it will get displayed as soon as the posts are processed.
- Upload the files to your web server.
- Create a folder called images/ and make it writable, inside this folder, create a folder called original/ and a folder called procesed/, make sure these are writable as well.
- Log into your twilio account, and point a phone number to http://MYSITEURL/listener for SMS messages
- Open up your web site: http://MYSITEURL/
- Send some text or a picture to the phone number and watch it appear on the web site.
We’ve now built a basic live blogging tool, nothing too fancy, but you can take it from here and build on it to make something more fancy.
I’ve also uploaded the demo app to Github, so you can view it in its entirety here
Related Posts
Related Resources
Twilio Docs
From APIs to SDKs to sample apps
API reference documentation, SDKs, helper libraries, quickstarts, and tutorials for your language and platform.
Resource Center
The latest ebooks, industry reports, and webinars
Learn from customer engagement experts to improve your own communication.
Ahoy
Twilio's developer community hub
Best practices, code samples, and inspiration to build communications and digital engagement experiences.