Skip to content

Instantly share code, notes, and snippets.

@kwhinnery
Created February 23, 2014 04:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwhinnery/9166737 to your computer and use it in GitHub Desktop.
Save kwhinnery/9166737 to your computer and use it in GitHub Desktop.
// 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);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment