Created
June 17, 2020 23:16
-
-
Save hijonathan/00140ad144902ed9bf0aab9acf5e6b36 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* Passphrase. | |
* Simple passphrase entry | |
*/ | |
const accessMap = { | |
"tennessee": ['Caroline', 'Clay'], | |
"leia": ['Dog Walkers'], | |
"coffee": ['Jonathan', 'Connie'] | |
}; | |
const passcodes = Object.keys(accessMap); | |
exports.handler = function(context, event, callback) { | |
const twiml = new Twilio.twiml.VoiceResponse(); | |
if (event.SpeechResult != null) { | |
let command = event.SpeechResult.toLowerCase(); | |
console.log(`Received the command: ${command}.`) | |
if (passcodes.indexOf(command) > -1) { | |
console.log(`Approved valid passcode: ${command}`); | |
// TODO: Log the fact that they got access. | |
// Let them in. | |
// Space out the digits so the service doesn't choke on it. | |
twiml.play({ | |
digits: [...context.DTMF_DIGITS].map(x => `w${x}`).reduce((m, v) => m+v) | |
}); | |
} else { | |
// Forward to a real person. | |
console.log(`Invalid passcode: "${command}".`); | |
twiml.say('Hang on while I find a human.'); | |
twiml.dial(context.JONATHANS_NUMBER); | |
twiml.say("No one is available to help you. Goodbye."); | |
} | |
} | |
else { | |
twiml.gather({ | |
input: 'speech', | |
timeout: 10, | |
hints: passcodes.join(','), | |
}).say("Please say your password"); | |
} | |
callback(null, twiml); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment