3 const Twilio
= require('twilio');
7 internals
.kMenuTimeout
= 10; // timeout in seconds
8 internals
.kMenuDigits
= 1; // number of digits in the menu
9 internals
.kContentType
= 'application/xml'; // The content type used to respond
10 internals
.kMenuLanguage
= 'es-mx'; // the language to use
11 internals
.kTimeoutMessage
= 'Oh... está bien. Adios!';
12 internals
.kMainMenuRoute
= '/menus/main';
13 internals
.kRecordingMenuRoute
= '/menus/recording';
14 internals
.kRandomMessageRoute
= '/recordings/0';
15 internals
.kLeaveMessageRoute
= '/recordings';
16 internals
.kMenuMessage
= 'Para dejar un mensaje, presiona 1. ' +
17 'Para escuchar un mensaje al azar, presiona 2. ' +
18 'Para escuchar un mensaje específico, presioan 3.'; // the message that will be shown
19 internals
.kMenuInvalidResponseMessage
= 'No entendí... Volviendo al menu principal.'; // invalid selection message
20 internals
.kMenuOptions
= {
22 listenToRandomMessage: 2,
23 listenToSpecificMessage: 3
24 }; // the menu options
27 * Handles the HTTP requests for the main menu
29 * @class MainMenuController
31 module
.exports
= internals
.MainMenuController
= class MainMenuController
{
37 * @memberof MainMenuController
39 * @return {generator} a koa compatible handler generator function
43 return function * () {
45 const response
= new Twilio
.TwimlResponse();
47 // the action will default to post in the same URL, so no change
50 timeout: internals
.kMenuTimeout
,
51 numDigits: internals
.kMenuDigits
52 }, function nestedHandler() {
54 this.say(internals
.kMenuMessage
, { language: internals
.kMenuLanguage
});
55 }).say(internals
.kTimeoutMessage
, { language: internals
.kMenuLanguage
});
57 this.type
= internals
.kContentType
;
58 this.body
= response
.toString();
63 * Parses the selected main menu response
65 * @function parseMenuSelection
66 * @memberof MainMenuController
68 * @return {generator} a koa compatible handler generator function
70 parseMenuSelection() {
72 return function * () {
74 const menuSelection
= parseInt(this.request
.body
.Digits
);
76 const response
= new Twilio
.TwimlResponse();
78 if (menuSelection
=== internals
.kMenuOptions
.leaveMessage
) {
79 response
.redirect(internals
.kLeaveMessageRoute
, { method: 'GET' });
81 else if (menuSelection
=== internals
.kMenuOptions
.listenToRandomMessage
) {
82 response
.redirect(internals
.kRandomMessageRoute
, { method: 'GET' });
84 else if (menuSelection
=== internals
.kMenuOptions
.listenToSpecificMessage
) {
85 response
.redirect(internals
.kRecordingMenuRoute
, { method: 'GET' });
88 response
.say(internals
.kMenuInvalidResponseMessage
, { language: internals
.kMenuLanguage
})
89 .redirect(internals
.kMainMenuRoute
, { method: 'GET' });
92 this.type
= internals
.kContentType
;
93 this.body
= response
.toString();