Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added several Express framework examples.

  • Loading branch information...
commit ee0ec6e5cc504fec9ef107dac4bc11900347fcd0 1 parent 631b4ea
@jsgoecke jsgoecke authored
View
22 samples/express/hello-world.js
@@ -0,0 +1,22 @@
+/**
+ * Showing with the Express framwork http://expressjs.com/
+ * Express must be installed for this sample to work
+ */
+
+require('../../lib/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();
+ // Use the say method https://www.tropo.com/docs/webapi/say.htm
+ tropo.say("Hello World!");
+
+ res.send(TropoJSON(tropo));
+});
+
+
+app.listen(8000);
+console.log('Server running on http://0.0.0.0:8000/')
View
40 samples/express/resource-routing.js
@@ -0,0 +1,40 @@
+/**
+ * Showing with the Express framwork http://expressjs.com/
+ * Express must be installed for this sample to work
+ */
+
+require('../../lib/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();
+ // 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));
+});
+
+app.post('/one', function(req, res){
+ // Create a new instance of the TropoWebAPI object.
+ var tropo = new TropoWebAPI();
+ tropo.say("Hello from resource one!");
+ tropo.on("continue", null, "/two", true);
+
+ res.send(TropoJSON(tropo));
+});
+
+app.post('/two', function(req, res){
+ // Create a new instance of the TropoWebAPI object.
+ var tropo = new TropoWebAPI();
+ tropo.say("Hello from resource two!");
+ tropo.say("Well, enough of that. Goodbye.");
+
+ res.send(TropoJSON(tropo));
+});
+
+app.listen(8000);
+console.log('Server running on http://0.0.0.0:8000/')
View
46 samples/express/say-ask.js
@@ -0,0 +1,46 @@
+/**
+ * Showing with the Express framwork http://expressjs.com/
+ * Express must be installed for this sample to work
+ */
+
+require('../../lib/tropo-webapi');
+var express = require('express');
+var app = express.createServer();
+
+/**
+ * Required to process the HTTP body
+ * req.body has the Object while req.rawBody has the JSON string
+ */
+app.configure(function(){
+ app.use(express.bodyDecoder());
+});
+
+app.post('/', function(req, res){
+ // Create a new instance of the TropoWebAPI object.
+ var tropo = new TropoWebAPI();
+ // Use the say method https://www.tropo.com/docs/webapi/say.htm
+ tropo.say("Welcome to my Tropo Web API node demo.");
+
+ // Demonstrates how to use the base Tropo action classes.
+ var say = new Say("Please enter your 5 digit zip code.");
+ var choices = new Choices("[5 DIGITS]");
+
+ // Action classes can be passes as parameters to TropoWebAPI class methods.
+ // use the ask method https://www.tropo.com/docs/webapi/ask.htm
+ tropo.ask(choices, 3, false, null, "foo", null, true, say, 5, null);
+ // use the on method https://www.tropo.com/docs/webapi/on.htm
+ tropo.on("continue", null, "/answer", true);
+
+ res.send(TropoJSON(tropo));
+});
+
+app.post('/answer', function(req, res){
+ // Create a new instance of the TropoWebAPI object.
+ var tropo = new TropoWebAPI();
+ tropo.say("Your zip code is " + req.body['result']['actions']['interpretation']);
+
+ res.send(TropoJSON(tropo));
+});
+
+app.listen(8000);
+console.log('Server running on http://0.0.0.0:8000/')
View
32 samples/express/use-session.js
@@ -0,0 +1,32 @@
+/**
+ * Showing with the Express framwork http://expressjs.com/
+ * Express must be installed for this sample to work
+ */
+
+require('../../lib/tropo-webapi');
+var express = require('express');
+var app = express.createServer();
+
+/**
+ * Required to process the HTTP body
+ * req.body has the Object while req.rawBody has the JSON string
+ */
+app.configure(function(){
+ app.use(express.bodyDecoder());
+});
+
+app.post('/', function(req, res){
+ console.log(req.body)
+
+ // Create a new instance of the TropoWebAPI object.
+ var tropo = new 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));
+});
+
+
+app.listen(8000);
+console.log('Server running on http://0.0.0.0:8000/')
Please sign in to comment.
Something went wrong with that request. Please try again.