Skip to content

Commit

Permalink
Handle punctuation/uppercase in speechResult
Browse files Browse the repository at this point in the history
  • Loading branch information
jlian authored Jul 17, 2018
1 parent 5aaed4a commit f5eef50
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions door-open.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse();

console.log('Speech: ' + event.SpeechResult + '. Confidence: ' + event.Confidence)

// Get rid of random non-alphabetical chars and put to lower case
var cleanString = event.SpeechResult.replace(/[^\w\s]|_/g, "")
.replace(/\s+/g, " ");
var cleanSpeechResult = cleanString.toLowerCase();

console.log('Speech: ' + cleanSpeechResult + '; confidence: ' + event.Confidence)
console.log('Digits: ' + event.Digits)

if ( (event.SpeechResult == context.PASSPHRASE && event.Confidence > 0.5) || event.Digits == context.PASSCODE) {

if ( (cleanSpeechResult == context.PASSPHRASE && event.Confidence > 0.5)
|| event.Digits == context.PASSCODE) {
// Check if we have a password match, and open the door
twiml.say({voice: 'man'}, 'Nice! fam!')
twiml.play({digits: '9'}) // Pressing 9 sends DTFM tone to open the door
Expand All @@ -18,4 +24,4 @@ exports.handler = function(context, event, callback) {
twiml.redirect('/call-residents')
callback(null, twiml)
}
}
}

0 comments on commit f5eef50

Please sign in to comment.