forked from tropo/tropo-webapi-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added several Express framework examples.
- Loading branch information
Showing
4 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/') |