Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

updated readme and and samples

  • Loading branch information...
commit 68f50ccf6d734dfb1a54accab33b68d5b797c5c4 1 parent 9583b2f
@chrismatthieu authored
View
18 README.md
@@ -11,7 +11,7 @@ To get started you will first need to have Node.js installed. Howtonode has a go
If you have Node.js installed, and are using the Node Package Manager (npm), just do:
-~$ npm install tropo-webapi
+~$ 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:
@@ -30,10 +30,10 @@ If you do not have npm installed, then you will then want to create a directory
|-vendor
</pre>
-Next copy the tropo-webapi-node/lib/tropo-webapi.js & tropo-webapi-node/lib/base.js in the project/lib directory. Then you may create a server.js file in the project directory that requires the Tropo WebAPI Node library as follows:
+Add this declaration to your server.js starting file
<pre>
- require('../lib/tropo-webapi');
+ var tropowebapi = require('tropo-webapi');
</pre>
Running
@@ -52,14 +52,14 @@ Generate a JSON Doc
-------------------
<pre>
- require('tropo-webapi');
+ var tropowebapi = require('tropo-webapi');
var sys = require('sys');
- var tropo = new TropoWebAPI();
+ var tropo = new tropowebapi.TropoWebAPI();
tropo.say("Hello, World.");
- sys.puts(TropoJSON(tropo));
+ sys.puts(tropowebapi.TropoJSON(tropo));
</pre>
Respond to a Tropo WebAPI Session
@@ -72,17 +72,17 @@ Respond to a Tropo WebAPI Session
*/
var http = require('http');
- require('tropo-webapi');
+ var tropowebapi = require('tropo-webapi');
var server = http.createServer(function (request, response) {
// Create a new instance of the TropoWebAPI object.
- var tropo = new TropoWebAPI();
+ 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(TropoJSON(tropo));
+ response.end(tropowebapi.TropoJSON(tropo));
}).listen(8000); // Listen on port 8000 for requests.
</pre>
View
6 samples/express/hello-world.js
@@ -3,18 +3,18 @@
* Express must be installed for this sample to work
*/
-require('../../lib/tropo-webapi');
+var tropowebapi = require('tropo-webapi');
var express = require('express');
var app = express.createServer();
app.post('/', function(req, res){
// Create a new instance of the TropoWebAPI object.
- var tropo = new TropoWebAPI();
+ var tropo = new tropowebapi.TropoWebAPI();
// Use the say method https://www.tropo.com/docs/webapi/say.htm
tropo.say("Hello World!");
- res.send(TropoJSON(tropo));
+ res.send(tropowebapi.TropoJSON(tropo));
});
View
14 samples/express/resource-routing.js
@@ -3,37 +3,37 @@
* Express must be installed for this sample to work
*/
-require('../../lib/tropo-webapi');
+var tropowebapi = require('tropo-webapi');
var express = require('express');
var app = express.createServer();
app.post('/', function(req, res){
// Create a new instance of the TropoWebAPI object.
- var tropo = new TropoWebAPI();
+ var tropo = new tropowebapi.TropoWebAPI();
// Use the say method https://www.tropo.com/docs/webapi/say.htm
tropo.say("Welcome to my Tropo Web API node demo.");
// Use the on method https://www.tropo.com/docs/webapi/on.htm
tropo.on("continue", null, "/one", true);
- res.send(TropoJSON(tropo));
+ res.send(tropowebapi.TropoJSON(tropo));
});
app.post('/one', function(req, res){
// Create a new instance of the TropoWebAPI object.
- var tropo = new TropoWebAPI();
+ var tropo = new tropowebapi.TropoWebAPI();
tropo.say("Hello from resource one!");
tropo.on("continue", null, "/two", true);
- res.send(TropoJSON(tropo));
+ res.send(tropowebapi.TropoJSON(tropo));
});
app.post('/two', function(req, res){
// Create a new instance of the TropoWebAPI object.
- var tropo = new TropoWebAPI();
+ var tropo = new tropowebapi.TropoWebAPI();
tropo.say("Hello from resource two!");
tropo.say("Well, enough of that. Goodbye.");
- res.send(TropoJSON(tropo));
+ res.send(tropowebapi.TropoJSON(tropo));
});
app.listen(8000);
View
10 samples/express/say-ask.js
@@ -3,7 +3,7 @@
* Express must be installed for this sample to work
*/
-require('../../lib/tropo-webapi');
+var tropowebapi = require('tropo-webapi');
var express = require('express');
var app = express.createServer();
@@ -17,7 +17,7 @@ app.configure(function(){
app.post('/', function(req, res){
// Create a new instance of the TropoWebAPI object.
- var tropo = new TropoWebAPI();
+ var tropo = new tropowebapi.TropoWebAPI();
// Use the say method https://www.tropo.com/docs/webapi/say.htm
tropo.say("Welcome to my Tropo Web API node demo.");
@@ -31,15 +31,15 @@ app.post('/', function(req, res){
// use the on method https://www.tropo.com/docs/webapi/on.htm
tropo.on("continue", null, "/answer", true);
- res.send(TropoJSON(tropo));
+ res.send(tropowebapi.TropoJSON(tropo));
});
app.post('/answer', function(req, res){
// Create a new instance of the TropoWebAPI object.
- var tropo = new TropoWebAPI();
+ var tropo = new tropowebapi.TropoWebAPI();
tropo.say("Your zip code is " + req.body['result']['actions']['interpretation']);
- res.send(TropoJSON(tropo));
+ res.send(tropowebapi.TropoJSON(tropo));
});
app.listen(8000);
View
6 samples/express/use-session.js
@@ -3,7 +3,7 @@
* Express must be installed for this sample to work
*/
-require('../../lib/tropo-webapi');
+var tropowebapi = require('tropo-webapi');
var express = require('express');
var app = express.createServer();
@@ -19,12 +19,12 @@ app.post('/', function(req, res){
console.log(req.body)
// Create a new instance of the TropoWebAPI object.
- var tropo = new TropoWebAPI();
+ var tropo = new tropowebapi.TropoWebAPI();
// Use the say method https://www.tropo.com/docs/webapi/say.htm
tropo.say("You are a " + req.body['session']['userType']);
tropo.say("Did you not know that already? Goodbye.")
- res.send(TropoJSON(tropo));
+ res.send(tropowebapi.TropoJSON(tropo));
});
View
6 samples/hello-world-http.js
@@ -4,16 +4,16 @@
*/
var http = require('http');
-require('../lib/tropo-webapi');
+var tropowebapi = require('tropo-webapi');
var server = http.createServer(function (request, response) {
// Create a new instance of the TropoWebAPI object.
- var tropo = new TropoWebAPI();
+ 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(TropoJSON(tropo));
+ response.end(tropowebapi.TropoJSON(tropo));
}).listen(8000); // Listen on port 8000 for requests.
View
6 samples/hello-world-nohttp.js
@@ -4,15 +4,15 @@
* ~$ node path/to/tropo-webapi-node/samples/sample-1.js
*/
-require('../lib/tropo-webapi');
+var tropowebapi = require('tropo-webapi');
var sys = require('sys');
// Create a new instance of the TropoWebAPI object.
-var tropo = new TropoWebAPI();
+var tropo = new tropowebapi.TropoWebAPI();
// Say something and then hangup. (Note, null values are excluded from rendered JSON.)
tropo.say("Hello, World.", null, null, true, "carmen");
tropo.hangup();
// Write out the rendered JSON.
-sys.puts(TropoJSON(tropo));
+sys.puts(tropowebapi.TropoJSON(tropo));
View
4 samples/provisioning/add-address.js
@@ -5,14 +5,14 @@
*
*/
-require('../../lib/tropo-provisioning');
+var tropowebapi = require('tropo-webapi');
var sys = require('sys');
var userid = '';
var password = '';
var applicationID = '';
-var p = new TropoProvision(userid, password);
+var p = new tropowebapi.TropoProvision(userid, password);
p.updateApplicationAddress(applicationID, 'aim', null, null, null, null, null, 'AIMUser01', 'password', null);
View
4 samples/provisioning/add-number.js
@@ -6,14 +6,14 @@
*
*/
-require('../../lib/tropo-provisioning');
+var tropowebapi = require('tropo-webapi');
var sys = require('sys');
var userid = '';
var password = '';
var applicationID = '';
-var p = new TropoProvision(userid, password);
+var p = new tropowebapi.TropoProvision(userid, password);
p.updateApplicationAddress(applicationID, 'number', '1407', null, null, null, null, null, null, null);
View
4 samples/provisioning/add-token.js
@@ -5,14 +5,14 @@
*
*/
-require('../../lib/tropo-provisioning');
+var tropowebapi = require('tropo-webapi');
var sys = require('sys');
var userid = '';
var password = '';
var applicationID = '';
-var p = new TropoProvision(userid, password);
+var p = new tropowebapi.TropoProvision(userid, password);
p.updateApplicationAddress(applicationID, 'token', null, null, null, null, 'messaging', null, null, null);
View
4 samples/provisioning/create-app.js
@@ -7,7 +7,7 @@
*
*/
-require('../../lib/tropo-provisioning');
+var tropowebapi = require('tropo-webapi');
var sys = require('sys');
var userid = '';
@@ -18,7 +18,7 @@ var messagingURL = 'http://somefakehost.com/tropo/app.json';
var platform = 'webapi';
var partition = 'staging';
-var p = new TropoProvision(userid, password);
+var p = new tropowebapi.TropoProvision(userid, password);
p.createApplication(name, voiceURL, messagingURL, platform, partition);
View
4 samples/provisioning/delete-address.js
@@ -4,7 +4,7 @@
*
*/
-require('../../lib/tropo-provisioning');
+var tropowebapi = require('tropo-webapi');
var sys = require('sys');
var userid = '';
@@ -12,7 +12,7 @@ var password = '';
var applicationID = '';
var myNumber = '';
-var p = new TropoProvision(userid, password);
+var p = new tropowebapi.TropoProvision(userid, password);
p.deleteApplicationAddress(applicationID, 'number', myNumber);
View
4 samples/provisioning/delete-app.js
@@ -5,14 +5,14 @@
*
*/
-require('../../lib/tropo-provisioning');
+var tropowebapi = require('tropo-webapi');
var sys = require('sys');
var userid = '';
var password = '';
var applicationID = '';
-var p = new TropoProvision(userid, password);
+var p = new tropowebapi.TropoProvision(userid, password);
p.deleteApplication(applicationID);
View
6 samples/resource-routing.js
@@ -6,7 +6,7 @@
var http = require('http');
-var tropo = require('../lib/tropo-webapi');
+var tropowebapi = require('tropo-webapi');
var server = http.createServer(function (request, response) {
@@ -30,7 +30,7 @@ var server = http.createServer(function (request, response) {
request.addListener('end', function() {
// Create a new instance of the TropoWebAPI object.
- var tropo = new TropoWebAPI();
+ var tropo = new tropowebapi.TropoWebAPI();
if(pathname == '/') {
@@ -61,7 +61,7 @@ var server = http.createServer(function (request, response) {
// Render out the JSON for Tropo to consume.
response.writeHead(200, {'Content-Type': 'application/json'});
- response.end(TropoJSON(tropo));
+ response.end(tropowebapi.TropoJSON(tropo));
})
}
View
6 samples/say-ask.js
@@ -4,12 +4,12 @@
*/
var http = require('http');
-require('../lib/tropo-webapi');
+var tropowebapi = require('tropo-webapi');
var server = http.createServer(function (request, response) {
// Create a new instance of the TropoWebAPI object.
- var tropo = new TropoWebAPI();
+ var tropo = new tropowebapi.TropoWebAPI();
tropo.say("Welcome to my Tropo Web API node demo.");
// Demonstrates how to use the base Tropo action classes.
@@ -22,6 +22,6 @@ var server = http.createServer(function (request, response) {
// Render out the JSON for Tropo to consume.
response.writeHead(200, {'Content-Type': 'application/json'});
- response.end(TropoJSON(tropo));
+ response.end(tropowebapi.TropoJSON(tropo));
}).listen(8000); // Listen on port 8000 for requests.
View
6 samples/transfer.js
@@ -4,18 +4,18 @@
*/
var http = require('http');
-require('../lib/tropo-webapi');
+var tropowebapi = require('tropo-webapi');
var server = http.createServer(function (request, response) {
// Create a new instance of the TropoWebAPI object.
- var tropo = new TropoWebAPI();
+ var tropo = new tropowebapi.TropoWebAPI();
tropo.say('Please hold while your call is transferred.');
tropo.transfer('mheadd@sip2sip.info', false, null, null, {'x-caller-name' : 'Mark Headd'}, null, null, true, '#', 60.0);
// Render out the JSON for Tropo to consume.
response.writeHead(200, {'Content-Type': 'application/json'});
- response.end(TropoJSON(tropo));
+ response.end(tropowebapi.TropoJSON(tropo));
}).listen(8000); // Listen on port 8000 for requests.
View
8 samples/use-result.js
@@ -5,7 +5,7 @@
var http = require('http');
-var tropo = require('../lib/tropo-webapi');
+var tropowebapi = require('tropo-webapi');
var server = http.createServer(function (request, response) {
@@ -23,7 +23,7 @@ var server = http.createServer(function (request, response) {
try {
// Create a new instance of the TropoWebAPI object.
- var tropo = new TropoWebAPI();
+ var tropo = new tropowebapi.TropoWebAPI();
// The path for the first step in the application flow (ask the caller for input).
if(pathname == '/') {
@@ -33,7 +33,7 @@ var server = http.createServer(function (request, response) {
tropo.ask(choices, 3, false, null, "foo", null, true, say, 5, null);
tropo.on("continue", null, '/selection', true);
response.writeHead(200, {'Content-Type': 'application/json'});
- response.end(TropoJSON(tropo));
+ response.end(tropowebapi.TropoJSON(tropo));
}
@@ -45,7 +45,7 @@ var server = http.createServer(function (request, response) {
tropo.say("Your selection was, " + result.interpretation + ". Goodbye.");
tropo.hangup();
response.writeHead(200, {'Content-Type': 'application/json'});
- response.end(TropoJSON(tropo));
+ response.end(tropowebapi.TropoJSON(tropo));
}
}
View
6 samples/use-session.js
@@ -5,7 +5,7 @@
var sys = require('sys');
var http = require('http');
-var tropo = require('../lib/tropo-webapi');
+var tropowebapi = require('tropo-webapi');
var server = http.createServer(function (request, response) {
@@ -23,7 +23,7 @@ var server = http.createServer(function (request, response) {
var session = Session(json);
// Create a new instance of the TropoWebAPI object.
- var tropo = new TropoWebAPI();
+ var tropo = new tropowebapi.TropoWebAPI();
// Build the response with the userType property of the session object.
tropo.say("Your user type is, " + session.userType);
@@ -32,7 +32,7 @@ var server = http.createServer(function (request, response) {
// Render out the JSON for Tropo to consume.
response.writeHead(200, {'Content-Type': 'application/json'});
- response.end(TropoJSON(tropo));
+ response.end(tropowebapi.TropoJSON(tropo));
}
Please sign in to comment.
Something went wrong with that request. Please try again.