Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jlian committed Jan 30, 2018
0 parents commit e285197
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
25 changes: 25 additions & 0 deletions buzzer-activated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Simple call box routine
*
* This function is meant for the apartment building callbox
* It gives the user a couple of seconds to produce the password
* Then dials all the residents to grant manual entry
*/
exports.handler = function(context, event, callback) {

let twiml = new Twilio.twiml.VoiceResponse();

// Gather both speech and digit entry from user
twiml.gather({
action: '/door-open',
hints: context.PASSPHRASE,
input: 'speech dtmf',
numDigits: '4',
speechTimeout: 'auto',
timeout: 2,
})
.say({voice: 'woman'}, 'Please wait')

twiml.redirect('/call-residents')
callback(null, twiml)
}
11 changes: 11 additions & 0 deletions call-residents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse();

// If no valid answer after timeout, dial all residents until someone picks up
let dial = twiml.dial({action: '/text-me?Method=call'});
// dial.number(context.SKYLER_PHONE); // Skyler
// dial.number(context.CHAYA_PHONE); // Chaya
dial.number(context.JOHN_PHONE); // John

callback(null, twiml)
}
21 changes: 21 additions & 0 deletions door-open.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse();

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

if ( (event.SpeechResult == 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)
}
}
19 changes: 19 additions & 0 deletions text-me.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse();

var bodyText;

if (event.Method == 'code') {bodyText = 'Someone used the password to get in the building.'}
else {bodyText = 'Somebody buzzed the door but didn\'t know the passcode.'}

context.getTwilioClient().messages.create({
to: context.JOHN_PHONE,
from: context.TWILIO_PHONE,
body: bodyText,
})
.then((message) => {
console.log(message.sid);
callback(null, twiml);
})
.catch((err) => callback(err, null));
};

0 comments on commit e285197

Please sign in to comment.