Tropo is part of CiscoLearn More

Dial and SMS your APIs with Tropo

Posted on December 22, 2011 by Adam Kalsey

The number of APIs available are increasing by the day and so is the popularity of Node.JS, the server-side event-driven javascript framework. This got me thinking… How cool would it be to be able to call or sms an API with your phone using Node.JS?

This is a pretty simple thing to do with Tropo and Nodester. Tropo has an NPM module available for adding Voice, SMS, and Instant Messaging to Node.JS applications and Nodester has REST APIs available to report on the status of the platform. 25 lines of Node.JS code later, we now have an Node.JS application using the Tropo API to dial and sms the API to retrieve the status of the platform.

Here’s the phone number: (480) 428-8723 to call or SMS.

Install the Tropo WebAPI and Mikeal Rogers’ Request NPM modules:

npm install tropo-webapi -g
npm install request -g

Run this code on localhost or deploy it to a Node.JS hosting service like Nodester.

var http = require('http');
var tropowebapi = require('tropo-webapi');
var request = require('request');

http.createServer(function (req, res) {

// Create a new instance of the TropoWebAPI object.
var tropo = new tropowebapi.TropoWebAPI();

// Fetch Nodester status -> http://api.nodester.com/status
// returns {"status":"up","appshosted":2878,"appsrunning":1759}
request('http://api.nodester.com/status', function (error, response, body) {
if (!error && response.statusCode == 200) {

// console.log(body) // Print status
var statusreq = JSON.parse(body);

tropo.say('nodester is ' + statusreq["status"] + ' and hosting ' + statusreq["appshosted"] + ' applications with '+ statusreq["appsrunning"] + ' running at the moment ');

res.writeHead(200, {'Content-Type': 'application/json'});
res.end(tropowebapi.TropoJSON(tropo));
}
})

}).listen(13151);

One of the really cool things about the Tropo API is that you can write your app one time and it automatically runs on multiple communications channels such as: Voice, SMS, and Instant Message.

Leave a Reply