Skip to content

Instantly share code, notes, and snippets.

@hijonathan
Created June 17, 2020 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hijonathan/00140ad144902ed9bf0aab9acf5e6b36 to your computer and use it in GitHub Desktop.
Save hijonathan/00140ad144902ed9bf0aab9acf5e6b36 to your computer and use it in GitHub Desktop.
/**
* 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