Martin Dimitrov 4cad1fbe2b
All checks were successful
Build and push Doorman UI / API / docker (push) Successful in 1m27s
discord notifications
2024-10-26 13:31:15 -07:00

34 lines
1.1 KiB
JavaScript

/**
* 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();
// should be a list of strings representing user ids in discord
let discordUsers = JSON.parse(event.config).discordUsers || [];
let bodyText;
if (event.Method == 'doorman') {
bodyText = 'Doorman buzzed someone up!';
const fingerprint = JSON.parse(event.fingerprint);
bodyText += `\n\n\`\`\`${JSON.stringify(fingerprint, null, 4)}\`\`\``;
} else if (event.Method == 'doorman-time-lock') {
bodyText = 'Doorman rejected a buzzer call due to time restriction';
} else if (event.Method == 'call') {
bodyText = 'Somebody buzzed the door and it dialed through to a phone.';
}
let promises = discordUsers.map((u) =>
fetch(context.DOORMAN_URL + `/api/door/notify?discordUser=${u}&msg=${bodyText}`)
.catch(err => console.log(err))
);
await Promise.all(promises)
.catch (e => console.log(e));
return callback(null, twiml);
};