Get Started with Twilio and Parse Using the Twilio Cloud Module

November 08, 2012
Written by
Meghan Murphy
Contributor
Opinions expressed by Twilio contributors are their own

Twilio Bug Logo

Parse is a seriously awesome platform for building mobile apps and we’re teaming up to make it even easier for mobile developers to access the Twilio API through Parse’s Cloud Code. Today Parse introduces the Twilio Cloud Module, one of many upcoming Parse integrations on their new Cloud Modules product, all making it simple to use third party services when building your mobile apps.

Mobile developers are using Twilio in incredible ways, like the drawing collab app DrawChat that uses phone number verification to protect its users. Or the social app Path that uses Twilio SMS for mobile app distribution. Whatever Twilio feature you want to add to your mobile app, now you can easily integrate within Parse.

We asked Parse Engineer Mattieu Gamache-Asselin to give us an example of how you could use Twilio and Parse together, and he wrote this super tutorial for getting started. Follow Mattieu on Twitter @mattieuga, and if you have questions get in touch with the Parse team at feedback@parse.com

Using Twilio with Parse

Mattieu Gamache-Asselin
In this short tutorial, we’ll take a look at a sample Parse and Twilio application. This small app allows you to send SMSs to phone numbers stored on Parse or in the device’s address book. The entire application require no servers, the SMSs are sent using Twilio, and the data storage and server side logic is handled by Parse. Note that we won’t have the chance to go through all of the code in this blog post, but you can download the entire source for this project on github.

Before we dive into the code, let’s take a look at how this app is organized. The app itself is a native iOS application written in Objective-C using the Parse SDK. When we’ll want to send an SMS, we’ll use the SDK to make a call to a Cloud Code function. Cloud Code is a JavaScript based platform that allows you to write functions and hooks that are executed on the Parse servers. It’s the perfect place to make a secure call to the Twilio API. To help us interact with Twilio, we’ll use the Twilio Cloud Module, a small JavaScript library that makes it dead simple to use Twilio. Cloud Modules are JavaScript modules based on the CommonJS standard that are available from Parse’s Cloud Code platform.

In the iOS application, we present a table view that loads friends from the Friend table in your Parse app. Each of these friends have a phone number associated with them. When we tap on one, we make a call to a Cloud Function.

In this Cloud Function we start by initializing the Twilio Cloud Module with our Twilio account sid and auth token. We then call the sendSMS function and provide the body parameters (as defined by the Twilio API) as well as a success and failure callback function. All of this code is located in the main.js file which is uploaded to Parse using the Cloud Code tool.

And that’s it! The friend you selected will receive an invitation SMS and no servers are needed. Download the app from the github repository and try it out for yourself! You’ll need both a Parse account (which you can create here) as well as a Twilio account and you’ll need to set your keys and tokens as described in the readme included with the app.

Make sure you to check out the Twilio Cloud Module and Parse for your next mobile or web app, and drop us an email feedback@parse.com if you have any questions.

Links