forked from jlian/smart-door-buzzer-twilio-functions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e285197
Showing
4 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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) | ||
} |
This file contains 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
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) | ||
} |
This file contains 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
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) | ||
} | ||
} |
This file contains 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
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)); | ||
}; |