Twilio Brings the Power of Communications to IBM Cloud Platform, Codename: BlueMix

February 24, 2014
Written by
Twilio
Twilion

ibm-logo-800px

Twilio is joining forces with IBM to bring voice, messaging, and VoIP functionality to developers on the IBM Cloud Platform. Today, IBM announced the open beta for Codename: BlueMix, a cloud platform that combines open source PaaS technology with a host of application services. Developers can deploy and manage Twilio applications quickly from the BlueMix administrative console, configuring Twilio account information in a single step.

The BlueMix beta and the Twilio partnership were announced on stage at IBM’s Pulse Conference in Las Vegas, NV. Robert LeBlanc, IBM SVP, Software and Cloud Solutions Group, revealed IBM Codename: BlueMix to the audience and introduced Jeff Lawson, Twilio CEO and Co-Founder, who talked about the partnership and demonstrated building a Twilio SMS and Client application on top of the BlueMix platform.

The Nitty Gritty On BlueMix

codenamebluemix

As a developer, you have likely seen explosive growth in the number of cloud offerings that promise to abstract infrastructure (Infrastructure as a service, IaaS) and the app development stack (Platform as a service, PaaS). BlueMix is definitely born of that movement, but it has some properties that stand out in the crowd.

The core technology that powers BlueMix is the popular and powerful Cloud Foundry, an open source PaaS that is infrastructure agnostic. For BlueMix, it means that developers can immediately take advantage of open source contributions to that ecosystem, like custom buildpacks. Cloud Foundry also makes it really easy to deploy your application and view logs from your production apps. In addition to the functionality of Cloud Foundry, developers will be able to quickly integrate services provided both by IBM and and third parties like Twilio.

 To get started, sign up for the BlueMix beta. Once you’re accepted into the beta, you’ll be able to install the standard Cloud Foundry “cf” command line utility (version 6 is a Go executable you can download here).  Follow these instructions to configure the “cf” CLI app to hit the IBM BlueMix API server. Next, open the BlueMix admin console to create your first app.

Get Started Building a Twilio App on BlueMix

When you signed up for the BlueMix beta, you created an IBM ID.  Use that ID to log in to the BlueMix dashboard (linked from the home page here). Here, you should be able to create a new app

1
On the next screen, you will see a variety of choices for what type of app to create.  You can choose a boilerplate app with some pre-configured code and services, or you can create a new app in Java, Ruby, or node.js. Let’s create a new app using node.js

2
Click the “Create Application” button, and give your app a name.  I’ve called my app “twilio-big-blue”. Once created, your app should be listed on your dashboard home page

3
Click on the app. You have a little bit of configuration you have to take care of to get your app ready to rock with Twilio. On your app’s detail page, scroll down a bit to a section titled “services.” Here you can choose application services like MongoDB, Redis, IBM SSO, or Twilio to add to your application a la carte. Click “Add New Service”

4
..and then scroll down to choose Twilio

5
In the resulting dialogue, you will need to input your Twilio Account SID and Auth Token. You can then pull in these values as system environment variables in the code you are about to write.  These values can be found on your Twilio account dashboard

6
After adding your Twilio service, it will appear under your app’s configuration, but it will probably be named something goofy

7

Click on the Twilio service, and rename it to just plain ”Twilio”

8
Awesome – now let’s write a simple node.js app, and push it up to BlueMix!

 

Writing and Deploying A Twilio-powered node.js App

First thing is first, if you haven’t done so already, you will need to install node.js on your system. Then, open up a terminal window and create a new directory for your Twilio/BlueMix app. Initialize your node app with a package.json config file using this command

 
> npm init
 
You should be able to accept the defaults for most of the questions the “npm init” command will ask you by pressing enter. Next, install the twilio module for node, as well as gopher, a variant of the popular Express web framework with a bit more functionality and default configuration out of the box
 
> npm install --save twilio gopher
 
Next, create a new file called “app.js.” This will pull in our Twilio account credentials and define a single URL route that will send us a text message. Then display the message’s unique identifier in the browser when the URL is requested

// Node module dependencies
var app = require('gopher'),
    twilio = require('twilio');

// Pull in Twilio config from the BlueMix environment
// The VCAP_SERVICES environment variable contains a JSON string with all your
// BlueMix environment data
var config = JSON.parse(process.env.VCAP_SERVICES);

// Loop through user-provided config info and pull out our Twilio credentials
var twilioSid, twilioToken;
config['user-provided'].forEach(function(service) {
    if (service.name == 'Twilio') {
        twilioSid = service.credentials.accountSID;
        twilioToken = service.credentials.authToken;
    }
});

// Define a URL that will send a message, and display the message ID in the
// browser. View the numbers you own and can text from here:
// https://www.twilio.com/user/account/phone-numbers/incoming
app.get('/', function(request, response) {
    var client = new twilio.RestClient(twilioSid, twilioToken);

    client.sendMessage({
        to:'your cell phone',
        from:'a Twilio number you own',
        body:'go big blue!'
    }, function(err, message) {
        response.send('Message sent! ID: '+message.sid);
    });
});

Make sure to change the “to” and “from” fields to be your mobile number and a Twilio number you control. Now, it’s time to push our code to BlueMix. Using the cf utility, enter the following command in your app’s directory, replacing “twilio-big-blue” with your app name:
 
> cf push twilio-big-blue
 
After a minute or so, your application will be pushed up to BlueMix. Visit your app’s root URL in a web browser. Behold! You just sent a text message with Twilio on BlueMix

9

If you have any questions or comments on the integration, be sure to let us know.