-
Notifications
You must be signed in to change notification settings - Fork 11
/
door-open.js
27 lines (23 loc) · 1.02 KB
/
door-open.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse();
// 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 ( (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
twiml.pause({length:1})
twiml.play('http://demo.twilio.com/docs/classic.mp3')
// Also send me a text on this
twiml.redirect('/text-me?Method=code')
callback(null, twiml)
} else {
twiml.redirect('/call-residents')
callback(null, twiml)
}
}