forked from jlian/smart-door-buzzer-twilio-functions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
text-me.js
32 lines (29 loc) · 1 KB
/
text-me.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
28
29
30
31
32
exports.handler = function (context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse();
var bodyText;
switch (event.Method) {
case 'code':
bodyText = 'Someone used the code to open the gate.';
break;
case 'voice':
bodyText = 'Someone used the voice password to open the gate.';
break;
case 'call':
bodyText = 'Someone called the gate and was passed through to the backup number.';
break;
default:
bodyText = 'Somebody called the gate but didn\'t know the passcode.';
}
if (context.ENABLED.toLowerCase() == 'true') {
context.getTwilioClient().messages.create({
to: context.BACKUP_PHONE,
from: context.TWILIO_PHONE,
body: bodyText,
})
.then((message) => {
console.log(message.sid);
callback(null, twiml);
})
.catch((err) => callback(err, null));
}
};