Created
June 30, 2014 17:17
-
-
Save jclement/fec86d0aa9998db9d7c6 to your computer and use it in GitHub Desktop.
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
var express = require('express'); | |
var router = express.Router(); | |
var redis = require('redis').createClient(); | |
var twilio = require('twilio'); | |
/* GET home page. */ | |
router.get('/', function(req, res) { | |
res.render('index', { title: 'Express' }); | |
}); | |
router.post('/voice/incoming', function(req, res) { | |
var resp = new twilio.TwimlResponse(); | |
resp.say({voice: 'woman'}, 'Hello... Welcome to the stupid phone based square root finder. '); | |
resp.gather({timeout: 30, finishOnKey:'#', action:'https://adipose.net/dev/voice/sqrt'}, function() { | |
this.say({voice: 'woman'}, 'Enter a number and press pound'); | |
}); | |
res.writeHead(200, {'Content-type': 'text/xml'}); | |
res.end(resp.toString()); | |
}); | |
router.post('/voice/sqrt', function(req, res) { | |
console.log('Digits:',req.param('Digits')); | |
var resp = new twilio.TwimlResponse(); | |
var digits = parseInt(req.param('Digits')); | |
if (digits === 42) { | |
resp.say({voice: 'man'}, 'The answer to life, the universe and everything... dialing...'); | |
resp.dial({record:true}, "403801...."); | |
} else { | |
resp.say({voice: 'man'}, 'The square root is ' + Math.sqrt(digits) + '. Aren\'t you happy now you miserable excuse for a human?'); | |
} | |
res.writeHead(200, {'Content-type': 'text/xml'}); | |
res.end(resp.toString()); | |
}); | |
router.post('/sms/incoming', function(req, res) { | |
var resp = new twilio.TwimlResponse(); | |
resp.message( req.param('From') + ' said "' + req.param('Body') + '"'); | |
res.writeHead(200, {'Content-type': 'text/xml'}); | |
res.end(resp.toString()); | |
}); | |
module.exports = router; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment