var env = process.env.NODE_ENV || 'development';
var config = require(__dirname + '/../../config/config.json')[env];
var twilio = require('twilio');

exports.respond = function(req, res) {
    // array of script responses
    var responses_array = ["Welcome to the smoke alarm request system (para español, texto 'ES'). We need to ask four questions to process your request. Please text back the answer to each and wait for the next question. First, what is your name?", "What is your address, including the unit number, city, state, and zipcode?", "Is the number you're texting from the best way to get in touch with you? If so, text YES. Otherwise, please text a phone number where we can reach you.", "One last question: is there an email address we can use to contact you? If not, text NONE. If yes, please text us the email address.", "Thank you for your smoke alarm request! Your request number is <serial number>. To contact your local Red Cross about this request, call <local phone number>. We will be in touch with you to schedule an installation."];
    // TODO: the last response will need to be changed after we store
    // the request and get the RC region name, serial number, and other
    // info from the db.

    // Increment or initialize views, up to the length of our array.  If
    // we're at the end of the array, start over.
    if (req.session.views && req.session.views < responses_array.length ) {
        req.session.views++;
    }
    else {
        req.session.views = 1;
    }

    // TODO: store their incoming texts and construct a request object
    // from them to insert into the db.  This might be a totally
    // separate function.

    var resp = new twilio.TwimlResponse();
    
    // Send response, from array above
    resp.sms(responses_array[req.session.views - 1]);

    res.writeHead(200, {
        'Content-Type':'text/xml'
    });
    res.end(resp.toString());

};

@@ -143,16 +143,264 @@
 lio');%0A%0A
+var http = require('http'),%0A    express = require('express'),%0A    bodyParser = require('body-parser'),%0A    cookieParser = require('cookie-parser');%0A%0Avar app = express();%0Aapp.use(bodyParser.urlencoded(%7B extended: true %7D)); %0Aapp.use(cookieParser())%0A%0A
 exports.
@@ -1470,16 +1470,157 @@
 he db.%0A%0A
+    var twiml = new twilio.TwimlResponse();%0A    console.log(%22DEBUG: %22 + req.cookies);%0A    var counter = parseInt(req.cookies.counter) %7C%7C 0;%0A%0A
     // I
@@ -1746,48 +1746,18 @@
 if (
-req.session.views && req.session.views %3C
+counter %3E=
  res
@@ -1775,17 +1775,16 @@
 y.length
- 
 ) %7B%0A    
@@ -1791,486 +1791,385 @@
     
-req.session.views++;%0A    %7D%0A    else %7B%0A        req.session.views = 1;%0A    %7D%0A%0A    // TODO: store their incoming texts and construct a request object%0A    // from them to insert into the db.  This might be a totally%0A    // separate function.%0A%0A    var resp = new twilio.TwimlResponse();%0A    %0A    // Send response, from array above%0A    resp.sms(responses_array%5Breq.session.views - 1%5D);%0A%0A    res.writeHead(200, %7B%0A        'Content-Type':'text/xml'%0A    %7D);%0A    res.end(resp.toString());%0A%0A%7D;
+counter = 0;%0A    %7D%0A    twiml.message(responses_array%5Bcounter%5D);%0A%0A    counter = counter + 1;%0A    res.cookie('counter',counter);%0A    res.writeHead(200, %7B'Content-Type': 'text/xml'%7D);%0A    res.end(twiml.toString());%0A%0A    // TODO: store their incoming texts and construct a request object%0A    // from them to insert into the db.  This might be a totally%0A    // separate function.%0A%0A%7D;%0A%0A
 %0A

Store the session correctly: #121