Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make participant.joined and participant.left retry logic into a background function #20

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions functions/handle-participant-joined-left-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-left-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 };
22 changes: 8 additions & 14 deletions functions/zoom-meeting-webhook-handler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const ZOOM_SECRET =
const ZOOM_AUTH =
process.env.TEST_ZOOM_WEBHOOK_AUTH || process.env.ZOOM_WEBHOOK_AUTH;

const APP_HOST = process.env.TEST_APP_HOST || process.env.APP_HOST;

const handler = async function (event, context) {
try {
/**
Expand Down Expand Up @@ -96,22 +98,14 @@ 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-left-background')

if (roomInstance) {
// create room event record
console.log(`found room instance ${roomInstance.getId()}`);
response = await fetch(`${APP_HOST}/handle-participant-joined-left-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-left-background"
to = "/.netlify/functions/handle-participant-joined-left-background"
status = 200