aboutsummaryrefslogtreecommitdiff
path: root/lib/controllers/recording_menu.js
diff options
context:
space:
mode:
authorRubén Beltrán del Río <ben@nsovocal.com>2017-02-18 23:14:20 -0600
committerGitHub <noreply@github.com>2017-02-18 23:14:20 -0600
commit7404eac982a0d928866aeddaa1a0ea4d1f2d3870 (patch)
tree3834c528f1f88b52fcb33cc5025c6c7522bf21c7 /lib/controllers/recording_menu.js
parent5e981bca19ace2a7704f267175b6aa368e63bda0 (diff)
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
Diffstat (limited to 'lib/controllers/recording_menu.js')
-rw-r--r--lib/controllers/recording_menu.js82
1 files changed, 82 insertions, 0 deletions
diff --git a/lib/controllers/recording_menu.js b/lib/controllers/recording_menu.js
new file mode 100644
index 0000000..55f2836
--- /dev/null
+++ b/lib/controllers/recording_menu.js
@@ -0,0 +1,82 @@
+'use strict';
+
+const Twilio = require('twilio');
+
+const internals = {};
+
+internals.kMenuTimeout = 10; // timeout in seconds
+internals.kContentType = 'application/xml'; // The content type used to respond
+internals.kMenuLanguage = 'es-mx'; // the language to use
+internals.kMainMenuRoute = '/menus/main';
+internals.kListenMessageRoute = '/recordings/';
+internals.kMenuMessage = 'Escribe el numero de mensaje y presiona gato para terminar.';
+internals.kTimeoutMessage = 'Bueno... volviendo al menú principal.';
+internals.kMenuInvalidResponseMessage = 'No entendí... Volviendo al menu principal.'; // invalid selection message
+
+/**
+ * Handles the HTTP requests for the recording menu
+ *
+ * @class RecordingMenuController
+ */
+module.exports = internals.RecordingMenuController = class RecordingMenuController {
+
+ /**
+ * Serves the menu
+ *
+ * @function serveMenu
+ * @memberof RecordingMenuController
+ * @instance
+ * @return {generator} a koa compatible handler generator function
+ */
+ serveMenu() {
+
+ return function * () {
+
+ const response = new Twilio.TwimlResponse();
+
+ // the action will default to post in the same URL, so no change
+ // required there.
+ response.gather({
+ timeout: internals.kMenuTimeout
+ }, function nestedHandler() {
+
+ this.say(internals.kMenuMessage, { language: internals.kMenuLanguage });
+ })
+ .say(internals.kTimeoutMessage, { language: internals.kMenuLanguage })
+ .redirect(internals.kMainMenuRoute, { method: 'GET' });
+
+ this.type = internals.kContentType;
+ this.body = response.toString();
+ };
+ }
+
+ /**
+ * Parses the selected recording id
+ *
+ * @function parseMenuSelection
+ * @memberof RecordingMenuController
+ * @instance
+ * @return {generator} a koa compatible handler generator function
+ */
+ parseMenuSelection() {
+
+ return function * () {
+
+ const messageId = parseInt(this.request.body.Digits);
+
+ const response = new Twilio.TwimlResponse();
+
+ if (messageId) {
+ response.redirect(`${internals.kListenMessageRoute}${messageId}`, { method: 'GET' });
+ }
+ else {
+ response.say(internals.kMenuInvalidResponseMessage, { language: internals.kMenuLanguage })
+ .redirect(internals.kMainMenuRoute, { method: 'GET' });
+ }
+
+ this.type = internals.kContentType;
+ this.body = response.toString();
+ };
+ }
+};
+