Skip to content

Commit

Permalink
Rough draft working
Browse files Browse the repository at this point in the history
  • Loading branch information
ebanner committed Apr 30, 2024
1 parent e1a469a commit ad548db
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 14 deletions.
61 changes: 61 additions & 0 deletions functions/handle-participant-joined-background/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
require('dotenv').config();

const { updateMeetingAttendence } = require('../zoom-meeting-webhook-handler/slack.js');

const rooms = require('../../data/rooms.json');

const handler = async function (event, context) {
try {
const request = JSON.parse(event.body);

console.log('PRINTING REQUEST FROM handle-participant-joined-background')
console.log(JSON.stringify(request, null, 2))

// check our meeting ID. The meeting ID never changes, but the uuid is different for each instance

const room = rooms.find(
(room) => room.ZoomMeetingId === request.payload.object.id
);

if (room) {
const Airtable = require('airtable');
const base = new Airtable().base(process.env.AIRTABLE_COWORKING_BASE);

const { findRoomInstance } = require('../zoom-meeting-webhook-handler/airtable');

let roomInstance = await findRoomInstance(
room,
base,
request.payload.object.uuid
);

if (roomInstance) {
// create room event record
console.log(`found room instance ${roomInstance.getId()}`);

const updatedMeeting = await updateMeetingAttendence(
room,
roomInstance.get('slack_thread_timestamp'),
request
);
}
} else {
console.log('meeting ID is not co-working meeting');
}

return {
statusCode: 200,
body: '',
};
} catch (error) {
// output to netlify function log
console.log(error);
return {
statusCode: 500,
// Could be a custom message or object i.e. JSON.stringify(err)
body: JSON.stringify({ msg: error.message }),
};
}
};

module.exports = { handler };
21 changes: 7 additions & 14 deletions functions/zoom-meeting-webhook-handler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,15 @@ const handler = async function (event, context) {
switch (request.event) {
case EVENT_PARTICIPANT_JOINED:
case EVENT_PARTICIPANT_LEFT:
let roomInstance = await findRoomInstance(
room,
base,
request.payload.object.uuid
);
console.log('CALLING handle-participant-joined-background')

if (roomInstance) {
// create room event record
console.log(`found room instance ${roomInstance.getId()}`);
APP_HOST = 'https://4990a465--capable-gecko-a354d1.netlify.live'
response = await fetch(`${APP_HOST}/handle-participant-joined-background`, {
method: 'POST',
body: event.body,
});

const updatedMeeting = await updateMeetingAttendence(
room,
roomInstance.get('slack_thread_timestamp'),
request
);
}
console.log('EXITING IMMEDIATELY FROM zoom-meeting-webhook-handler')

break;

Expand Down
5 changes: 5 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@
from = "/event-reminders"
to = "/.netlify/functions/event-reminders-background"
status = 200

[[redirects]]
from = "/handle-participant-joined-background"
to = "/.netlify/functions/handle-participant-joined-background"
status = 200

0 comments on commit ad548db

Please sign in to comment.