From 76c048b5c9ee7c2b8a96fce77070b3692f8b059d Mon Sep 17 00:00:00 2001 From: Martin Dimitrov Date: Sat, 26 Oct 2024 14:37:14 -0700 Subject: [PATCH] unlock by discord link option --- packages/doorman-api/functions/api/door/auth.js | 15 +++++++++++++-- .../doorman-client/functions/buzzer-activated.js | 9 +++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/doorman-api/functions/api/door/auth.js b/packages/doorman-api/functions/api/door/auth.js index 9bfae80..1d42e2e 100644 --- a/packages/doorman-api/functions/api/door/auth.js +++ b/packages/doorman-api/functions/api/door/auth.js @@ -25,14 +25,25 @@ exports.handler = async function(context, event, callback) { } let correctPin = config.Item.pin.S; + let discordUsers = config.Item.discordUsers.SS; - if (correctPin !== pin) { + let method; + + if (correctPin === pin) { + method = "PIN"; + } + + if (discordUsers.includes(pin)) { + method = "DISCORD"; + } + + if (!method) { response.setStatusCode(401); return callback(null, response); } const fingerprint = { - method: "PIN", + method, userAgent: event.request.headers['user-agent'], ip: event.ip, }; diff --git a/packages/doorman-client/functions/buzzer-activated.js b/packages/doorman-client/functions/buzzer-activated.js index b079764..7ac259d 100644 --- a/packages/doorman-client/functions/buzzer-activated.js +++ b/packages/doorman-client/functions/buzzer-activated.js @@ -25,6 +25,13 @@ exports.handler = async function(context, event, callback) { let configQuery = `config=${encodeURIComponent(JSON.stringify(config))}`; + // let user know someone is currently buzzing, and allow unlock by discord user + let msg = `🔔 Someone is dialing right now @ Door "${config.door}" [Click to unlock](${context.DOORMAN_URL}/api/door/auth?door=buzzer&key=`; + config.discordUsers.forEach((u) => { + // unlock me by discord userid + fetch(context.DOORMAN_URL + `/api/door/notify?discordUser=${u}&msg=${encodeURIComponent(msg + u + ')')}`); + }); + // poll Doorman, to see if we should unlock const interval = setInterval(() => { fetch(context.DOORMAN_URL + `/api/door/status?door=${config.door}`) @@ -52,6 +59,4 @@ exports.handler = async function(context, event, callback) { twiml.redirect(`/call-residents?${configQuery}`); callback(null, twiml); }, 6000); - - // return callback(null, twiml); }; \ No newline at end of file