From 7404eac982a0d928866aeddaa1a0ea4d1f2d3870 Mon Sep 17 00:00:00 2001 From: Rubén Beltrán del Río Date: Sat, 18 Feb 2017 23:14:20 -0600 Subject: Handle Menus and Store / Recall recordings (#2) * Update calls for menu parsing in paw * Add twilio and bodyparser dependencies * Integrate menu routes * Add redirects to all menu selections. * Add pause to menu message * Update paw to handle all recordings cases * Add rec menu handler, recordings dummy handler * Add redis related configs * Add redis node module * Add missing comma to config * Remove dangling comma from config * Update paw to validate input * Add post validation dependencies * Update yarn lock * Store recordings in redis * Say post id in spanish * Use the word for the pound sign * Use a timestamp shifted by 2 and truncated to 10 --- lib/dead_drop.js | 72 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 35 deletions(-) (limited to 'lib/dead_drop.js') diff --git a/lib/dead_drop.js b/lib/dead_drop.js index 1ea86e8..6f97645 100644 --- a/lib/dead_drop.js +++ b/lib/dead_drop.js @@ -1,8 +1,13 @@ 'use strict'; const Koa = require('koa'); +const KoaBodyParser = require('koa-bodyparser'); const KoaRoute = require('koa-route'); +const MainMenuController = require('./controllers/main_menu'); +const RecordingMenuController = require('./controllers/recording_menu'); +const RecordingsController = require('./controllers/recordings'); + const internals = {}; /** @@ -42,60 +47,57 @@ module.exports = internals.DeadDrop = class DeadDrop { this._app = Koa(); - this._app.use(KoaRoute.get('/menus/main', function * () { - - this.body = 'I will return the main menu.'; - })); - - this._app.use(KoaRoute.post('/menus/main', function * () { + this._app.use(KoaBodyParser()); - this.body = 'I will parse the main menu.'; - })); + this._initializeMainMenuRoutes(); + this._initializeRecordingMenuRoutes(); + this._initializeRecordingsRoutes(); - this._app.use(KoaRoute.get('/menus/recording', function * () { + this._app.use(function * () { - this.body = 'I will return the select recording menu.'; - })); + this.body = 'How did you get here? Shoo!'; + }); - this._app.use(KoaRoute.post('/menus/recording', function * () { + } - this.body = 'I will parse the select recording menu.'; - })); + // Starts listening - this._app.use(KoaRoute.get('/recordings', function * () { + _startServer() { - this.body = 'I will initiate recording process'; - })); + this._app.listen(this.port); + } - this._app.use(KoaRoute.post('/recordings', function * () { + // Initializes the main menu routes. - this.body = 'I will create a new recording'; - })); + _initializeMainMenuRoutes() { - this._app.use(KoaRoute.get('/recordings/:id', function * (id) { + const mainMenuController = new MainMenuController(); - id = parseInt(id); + this._app.use(KoaRoute.get('/menus/main', mainMenuController.serveMenu())); + this._app.use(KoaRoute.post('/menus/main', mainMenuController.parseMenuSelection())); + } - if (id === 0) { - this.body = 'I will return a random recording'; - } - else { - this.body = 'I will return a specific recording'; - } - })); + // Initializes the recording menu routes. - this._app.use(function * () { + _initializeRecordingMenuRoutes() { - this.body = 'hello, world'; - }); + const recordingMenuController = new RecordingMenuController(); + this._app.use(KoaRoute.get('/menus/recording', recordingMenuController.serveMenu())); + this._app.use(KoaRoute.post('/menus/recording', recordingMenuController.parseMenuSelection())); } - // Starts listening + // Initializes the recordings routes. - _startServer() { + _initializeRecordingsRoutes() { - this._app.listen(this.port); + const recordingsController = new RecordingsController({ + redis: this.redis + }); + + this._app.use(KoaRoute.get('/recordings', recordingsController.startRecording())); + this._app.use(KoaRoute.post('/recordings', recordingsController.saveRecording())); + this._app.use(KoaRoute.get('/recordings/:id', recordingsController.getRecording())); } // Prints the banner. -- cgit