Permalink
Browse files

Modified Session and Result samples.

  • Loading branch information...
1 parent dfa6330 commit 68910c97bcd56bc301faefd75a0b6e26ab637ab5 @mheadd mheadd committed Sep 30, 2010
Showing with 32 additions and 15 deletions.
  1. +29 −13 samples/use-result.js
  2. +3 −2 samples/use-session.js
View
@@ -9,27 +9,43 @@ var tropo = require('../lib/tropo-webapi');
var server = http.createServer(function (request, response) {
+ // Get the pathname for the current request.
+ var pathname = require('url').parse(request.url).pathname;
+
// Add a listener for the data event (incoming data from the HTTP request)
request.addListener('data', function(data){
json = data.toString();
});
// Add a listener for the EOF event on the incoming stream.
request.addListener('end', function() {
+
+ // Create a new instance of the TropoWebAPI object.
+ var tropo = new TropoWebAPI();
- // Create a new instance of the Session object and give it the JSON delivered from Tropo.
- var result = Result(json);
-
- // Create a new instance of the TropoWebAPI object.
- var tropo = new TropoWebAPI();
-
- // Build the response.
- tropo.say("Your select was, " + result.interpretation);
- tropo.hangup();
-
- // Render out the JSON for Tropo to consume.
- response.writeHead(200, {'Content-Type': 'application/json'});
- response.end(TropoJSON(tropo));
+ // The path for the first step in the application flow (ask the caller for input).
+ if(pathname == '/') {
+
+ var say = new Say("Please enter a number one through 5.");
+ var choices = new Choices("1,2,3,4,5");
+ 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));
+
+ }
+
+ // The second step in the application flow - input is submitted via Result JSON delivered from Tropo.
+ if(pathname == '/selection') {
+
+ // Create a new instance of the Result object and give it the JSON delivered from Tropo.
+ var result = Result(json);
+ tropo.say("Your selection was, " + result.interpretation + ". Goodbye.");
+ tropo.hangup();
+ response.writeHead(200, {'Content-Type': 'application/json'});
+ response.end(TropoJSON(tropo));
+
+ }
})
View
@@ -24,8 +24,9 @@ var server = http.createServer(function (request, response) {
// Create a new instance of the TropoWebAPI object.
var tropo = new TropoWebAPI();
- // Build the response.
- tropo.say("Your account ID is, " + accountId);
+ // Build the response with the userType property of the session object.
+ tropo.say("Your user type is, " + session.userType);
+ tropo.say('Goodbye.');
tropo.hangup();
// Render out the JSON for Tropo to consume.

0 comments on commit 68910c9

Please sign in to comment.