Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Tropo WebAPI Node.js Library

tree: 498a2402ac

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 samples
Octocat-spinner-32 tests
Octocat-spinner-32 .DS_Store fix to reflect ring event April 28, 2011
Octocat-spinner-32 README.md updated readme and and samples December 22, 2011
Octocat-spinner-32 package.json
README.md

Tropo WebAPI Node.js Library

A Node.js module for the Tropo WebAPI.

Installation

To get started you will first need to have Node.js installed. Howtonode has a good write-up on installing Node.js on Windows, Ubuntu and OSX.

If you have Node.js installed, and are using the Node Package Manager (npm), just do:

~$ npm install tropo-webapi -g

If you install with npm, then you can reference the tropo Node library in your node.js scripts like this:

require('tropo-webapi');

If you do not have npm installed, then you will then want to create a directory for your project, you may want to use a convention like this:

    ./project
    |-lib
    |-public
    |--css
    |--js
    |-vendor

Add this declaration to your server.js starting file

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

Running

You may then run your script from within the project directory with:

    node server.js

Sample Usage

Generate a JSON Doc

    var tropowebapi = require('tropo-webapi');
    var sys = require('sys');

    var tropo = new tropowebapi.TropoWebAPI(); 

    tropo.say("Hello, World.");

    sys.puts(tropowebapi.TropoJSON(tropo));

Respond to a Tropo WebAPI Session

    /**
    * A very simple node web server that will respond to requests
    * with the Tropo WebAPI JSON version of "Hello, World!" 
    */

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

    var server = http.createServer(function (request, response) {

        // Create a new instance of the TropoWebAPI object.
        var tropo = new tropowebapi.TropoWebAPI(); 
        tropo.say("Hello, World!");

        // Render out the JSON for Tropo to consume.
        response.writeHead(200, {'Content-Type': 'application/json'});
        response.end(tropowebapi.TropoJSON(tropo));

    }).listen(8000); // Listen on port 8000 for requests.

Samples

You may run the included samples from within the tropo-webapi-node directory as follows:

    node samples/hello-word-http.js

We have also included several examples for the Express.js Node framework. This may be run from within the tropo-webapi-node library as follows:

    node samples/express/hello-world.js
Something went wrong with that request. Please try again.