/** * Send a NTFY message with an update of what happened. If the password was used or not... */ const fetch = require('node-fetch'); exports.handler = async function(context, event, callback) { let twiml = new Twilio.twiml.VoiceResponse(); let config = JSON.parse(event.config); // should be a list of strings representing user ids in discord let discordUsers = config.discordUsers || []; let msg; let optionalJson = event.fingerprint; if (event.Method == 'doorman') { msg = '🔓 Doorman buzzed someone up'; } else if (event.Method == 'doorman-time-lock') { msg = '🔒 Doorman rejected a buzzer call due to time restriction'; } else if (event.Method == 'call') { msg = '📞 Somebody buzzed the door and it dialed through to a fallback phone number'; } msg += ` @ Door "${config.door}"`; let promises = discordUsers.map((u) => fetch(context.DOORMAN_URL + `/api/door/notify?discordUser=${u}&msg=${msg}&json=${optionalJson}`) .catch(err => console.log(err)) ); await Promise.all(promises) .catch (e => console.log(e)); return callback(null, twiml); };