Skip to content

Commit 6f56703

Browse files
committed
Rough draft working
1 parent e1a469a commit 6f56703

File tree

3 files changed

+86
-15
lines changed

3 files changed

+86
-15
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
require('dotenv').config();
2+
3+
const crypto = require('crypto');
4+
5+
const { updateMeetingStatus, updateMeetingAttendence } = require('../zoom-meeting-webhook-handler/slack.js');
6+
7+
const rooms = require('../../data/rooms.json');
8+
9+
const EVENT_MEETING_STARTED = 'meeting.started';
10+
const EVENT_MEETING_ENDED = 'meeting.ended';
11+
const EVENT_PARTICIPANT_JOINED = 'meeting.participant_joined';
12+
const EVENT_PARTICIPANT_LEFT = 'meeting.participant_left';
13+
14+
const ZOOM_SECRET =
15+
process.env.TEST_ZOOM_WEBHOOK_SECRET_TOKEN ||
16+
process.env.ZOOM_WEBHOOK_SECRET_TOKEN;
17+
18+
const ZOOM_AUTH =
19+
process.env.TEST_ZOOM_WEBHOOK_AUTH || process.env.ZOOM_WEBHOOK_AUTH;
20+
21+
const handler = async function (event, context) {
22+
try {
23+
const request = JSON.parse(event.body);
24+
25+
// check our meeting ID. The meeting ID never changes, but the uuid is different for each instance
26+
27+
const room = rooms.find(
28+
(room) => room.ZoomMeetingId === request.payload.object.id
29+
);
30+
31+
if (room) {
32+
const Airtable = require('airtable');
33+
const base = new Airtable().base(process.env.AIRTABLE_COWORKING_BASE);
34+
35+
const { findRoomInstance } = require('../zoom-meeting-webhook-handler/airtable');
36+
37+
let roomInstance = await findRoomInstance(
38+
room,
39+
base,
40+
request.payload.object.uuid
41+
);
42+
43+
if (roomInstance) {
44+
// create room event record
45+
console.log(`found room instance ${roomInstance.getId()}`);
46+
47+
const updatedMeeting = await updateMeetingAttendence(
48+
room,
49+
roomInstance.get('slack_thread_timestamp'),
50+
request
51+
);
52+
}
53+
} else {
54+
console.log('meeting ID is not co-working meeting');
55+
}
56+
57+
return {
58+
statusCode: 200,
59+
body: '',
60+
};
61+
} catch (error) {
62+
// output to netlify function log
63+
console.log(error);
64+
return {
65+
statusCode: 500,
66+
// Could be a custom message or object i.e. JSON.stringify(err)
67+
body: JSON.stringify({ msg: error.message }),
68+
};
69+
}
70+
};
71+
72+
module.exports = { handler };

functions/zoom-meeting-webhook-handler/index.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const ZOOM_SECRET =
1818
const ZOOM_AUTH =
1919
process.env.TEST_ZOOM_WEBHOOK_AUTH || process.env.ZOOM_WEBHOOK_AUTH;
2020

21+
const APP_HOST = process.env.TEST_APP_HOST || process.env.APP_HOST;
22+
2123
const handler = async function (event, context) {
2224
try {
2325
/**
@@ -96,22 +98,14 @@ const handler = async function (event, context) {
9698
switch (request.event) {
9799
case EVENT_PARTICIPANT_JOINED:
98100
case EVENT_PARTICIPANT_LEFT:
99-
let roomInstance = await findRoomInstance(
100-
room,
101-
base,
102-
request.payload.object.uuid
103-
);
101+
console.log('CALLING handle-participant-joined-left-background')
104102

105-
if (roomInstance) {
106-
// create room event record
107-
console.log(`found room instance ${roomInstance.getId()}`);
103+
response = await fetch(`${APP_HOST}/handle-participant-joined-left-background`, {
104+
method: 'POST',
105+
body: event.body,
106+
});
108107

109-
const updatedMeeting = await updateMeetingAttendence(
110-
room,
111-
roomInstance.get('slack_thread_timestamp'),
112-
request
113-
);
114-
}
108+
console.log('EXITING IMMEDIATELY FROM zoom-meeting-webhook-handler')
115109

116110
break;
117111

@@ -190,4 +184,4 @@ const handler = async function (event, context) {
190184
}
191185
};
192186

193-
module.exports = { handler };
187+
module.exports = { handler };

netlify.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@
2626
from = "/event-reminders"
2727
to = "/.netlify/functions/event-reminders-background"
2828
status = 200
29+
30+
[[redirects]]
31+
from = "/handle-participant-joined-left-background"
32+
to = "/.netlify/functions/handle-participant-joined-left-background"
33+
status = 200

0 commit comments

Comments
 (0)