Permalink
Browse files

Added debug info

  • Loading branch information...
1 parent 9bf30d0 commit 1a3f62135423f2cc906f220c69588fa1168101c2 Anatoliy Chakkaev committed Jun 8, 2012
Showing with 27 additions and 4 deletions.
  1. +5 −0 config/environment.js
  2. +22 −4 lib/tropo.js
View
5 config/environment.js
@@ -12,6 +12,11 @@ app.configure(function(){
app.use(express.cookieParser('secret'));
app.use(express.session({secret: 'secret'}));
app.use(express.methodOverride());
+ app.use(function (req, res, next) {
+ console.log(req.url);
+ console.log(req.body);
+ next();
+ });
app.use(app.router);
});
View
26 lib/tropo.js
@@ -17,6 +17,7 @@ app.startTropoSession = function (message, callback) {
port: 443,
path: '/1.0/sessions?action=create&token=' + token + '&messageId=' + message.id
}, function (res) {
+ console.log('Tropo session for', message.id, 'started');
// res.on('data', console.log);
});
req.on('error', console.log);
@@ -27,6 +28,8 @@ var callbacks = ['incomplete', 'hangup', 'error', 'continue'];
app.post('/tropo/text', function (req, res) {
+ console.log('send tropo task');
+
var messageId = req.body.session.parameters.messageId;
var sessionId = req.body.session.id;
var session = tropoSessions[messageId];
@@ -35,7 +38,7 @@ app.post('/tropo/text', function (req, res) {
// tropo.call(to, null, null, null, null, null, "SMS", null, null, null);
tropo.call(message.phone);
- tropo.say(message.text);
+ tropo.say(message.message);
callbacks.forEach(function (callback) {
tropo.on(callback, null, '/tropo/callback/' + callback, true);
});
@@ -54,10 +57,25 @@ function callbackHandler(callback) {
var messageId = tropoSessionsIndex[sessionId];
var session = tropoSessions[messageId];
req.body.result.callback = callback;
- session.callback(req.body.result);
- delete tropoSessions[messageId];
- delete tropoSessionsIndex[sessionId];
+ session.callback.send(req.body.result);
+ // delete tropoSessions[messageId];
+ // delete tropoSessionsIndex[sessionId];
res.send(200);
};
}
+app.post('/messages', function (req, res) {
+
+ app.models.Message.create(req.body.Message, function (err, message) {
+ if (err) {
+ flash('error', 'Message can not be created');
+ render('new', {
+ message: message,
+ title: 'New message'
+ });
+ } else {
+ message.send(res);
+ }
+ });
+});
+

0 comments on commit 1a3f621

Please sign in to comment.