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 2791f52
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 15 deletions.
77 changes: 77 additions & 0 deletions functions/handle-participant-joined-background/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
require('dotenv').config();

const crypto = require('crypto');

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

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

const EVENT_MEETING_STARTED = 'meeting.started';
const EVENT_MEETING_ENDED = 'meeting.ended';
const EVENT_PARTICIPANT_JOINED = 'meeting.participant_joined';
const EVENT_PARTICIPANT_LEFT = 'meeting.participant_left';

const ZOOM_SECRET =
process.env.TEST_ZOOM_WEBHOOK_SECRET_TOKEN ||
process.env.ZOOM_WEBHOOK_SECRET_TOKEN;

const ZOOM_AUTH =
process.env.TEST_ZOOM_WEBHOOK_AUTH || process.env.ZOOM_WEBHOOK_AUTH;

const handler = async function (event, context) {
try {
console.log(event)

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 };
24 changes: 9 additions & 15 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
);

if (roomInstance) {
// create room event record
console.log(`found room instance ${roomInstance.getId()}`);
console.log('CALLING handle-participant-joined-background')

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('RETURNED FROM handle-participant-joined-background')

break;

Expand Down Expand Up @@ -175,6 +168,7 @@ const handler = async function (event, context) {
console.log('meeting ID is not co-working meeting');
}

console.log('EXITING IMMEDIATELY FROM zoom-meeting-webhook-handler')
return {
statusCode: 200,
body: '',
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 2791f52

Please sign in to comment.