Time to Talk about Twilio.
Hey! I haven't written on here in forever,
But I was suddenly inspired to write a post about the magical platform known as Twilio! I used it this weekend at the NYT Developers Hack Day, and I loved it!
What is Twilio exactly?
"We empower developers to build powerful communication. Twilio powers the future of business communications, enabling phones, VoIP, and messaging to be embedded into web, desktop, and mobile software. We take care of the messy telecom hardware and expose a globally available cloud API that developers can interact with to build intelligent & complex communications systems. As your app’s usage scales up or down, Twilio automatically scales with you. You only pay for what you use - no contracts, no shenanigans."
It's essentially a streamlined way for developers to interact with phones via voice/text (Even Multimedia, although I was informed that this particular function is not available in the US currently). Uses include (But are in no way limited to) sending status texts to users, arranging and creating conference calls, call recording and transcription, and even a TTS service for calls.
Plus, it's incredibly affordable, which was the biggest surprise to me. You can reserve a line for $1/Month. Incoming and outgoing texts are $0.0075 each, and calls hover around $0.01-$0.02/m depending on certain circumstances (Location, Incoming/Outgoing, etc...).
It even has a free service where you can generate simple url functions for voice API functionality.
What I did with Twilio!
I spent a good 2-3 hours of the hackathon attending the talks and trying to figure out which API. But when I got to Twilio I was certain that I NEEDED to use it. I wanted to do a game originally, but I soon realized that there was too much scope for the time and moved on. I got the idea for my eventual project from trading buisness cards with a few people. I thought to myself, "I like buisness cards... but I'm going to lose these and forget about all of these awesome people". Then it clicked. It would be so much easier to get all of their card info onto my phone directly.
So I threw on my headphones and began to work on an information trading service, which included a Node/Express/Mongo back-end with Twilio handling communication. It was pretty easy, most of my problems were issues with rushing and forgetting about Node being asynchronous (Happens ALL the time T-T).
How it works!
The basic concept was this: People who want to trade information simply need to give each other a single code/username. Each person could then send a text to the service, which would return a text with all registered information from that person (Including a picture if MMS was available). This could include names, e-mails, websites, phone numbers, or anything else you would find on a buisness card.
In order to do this, I simply needed a web server and Twilio. I chose to use NodeJS and the Twilio module, but Twilio has libraries for most major platforms. My particular set-up included Express (Ridiculously streamlined HTTP servers) and MongoJS (Interface for Node to the MongoDB API).
After making a Twilio account, I was given a phone number to test on. On Twilio's Dashboard, I set the request URL for the messaging service to call against.
Now whenever a text would be sent to this number, an HTTP POST would be sent to the server containing a data object. This object holds the body of the message, the phone number, location, date, etc.
The rest was on the backend. I routed the requests as such.
Code
The important parts for Twilio's purposes is the "req.body.Body" part. That contains the raw message string from the text. Also "req.body.From" is the string for the sender's number. I also have two functions. One is "ME", which uses the sender's number to look-up his information, the other is "ID" which allows the user to look up information with another person's uid code. I then Query the database for whatever the user requested, and then we finally get to the magic.
Code
BOOM. I drop in the number and the message, and can send a text JUST LIKE THAT.
Ok... it's not *TOO* impressive, but it's just so straightforward. And this is only the beginning of what can be done. The Docs contain numerous examples of the power and versatility of Twilio.
Which Brings us to Now.
So this was pretty much all I got done for the Hackathon. I actually spent the time to make the app functional instead of faking it, so it's a solid app instead of an interactive slide show. But the app itself is pretty useless. What I really wanted to explore was a platform which I've never developed on before, which is what Twilio opened up to me.
I plan on working on this a little more, then I'll drop it in a repository. Hopefully it will serve as a good example of how easy Twilio is to pick up.
Anyway, thanks for reading! I've been meaning to write about more of my work. And definitely check out Twilio, it's super cool and the evangelists are awesome! See you next time!









