Skip to content

Commit 06bd5af

Browse files
Edward BannerEdward Banner
authored andcommitted
Clean up code
1 parent fb0112f commit 06bd5af

File tree

1 file changed

+21
-12
lines changed
  • functions/zoom-meeting-webhook-handler

1 file changed

+21
-12
lines changed

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,25 @@ async function getCallIdFromChannel() {
6767
}
6868

6969

70-
async function addParticipant(user) {
70+
async function addParticipantToCall(zoomEvent) {
71+
const slackUser = toSlackUser(zoomEvent);
7172
const call_id = await getCallIdFromChannel();
72-
await slack.calls.participants.add({ id: call_id, users: [user] });
73+
await slack.calls.participants.add({ id: call_id, users: [slackUser] });
7374
}
7475

7576

76-
async function removeParticipant(user) {
77+
async function removeParticipantFromCall(zoomEvent) {
78+
const slackUser = toSlackUser(zoomEvent);
7779
const call_id = await getCallIdFromChannel();
78-
await slack.calls.participants.remove({ id: call_id, users: [user] });
80+
await slack.calls.participants.remove({ id: call_id, users: [slackUser] });
7981
}
8082

8183

8284
function toSlackUser(zoomEvent) {
83-
const zoomName = zoomEvent?.payload?.object?.participant?.user_name;
85+
const zoomDisplayName = zoomEvent?.payload?.object?.participant?.user_name;
8486
return {
85-
external_id: zoomName,
86-
display_name: zoomName,
87+
external_id: zoomDisplayName,
88+
display_name: zoomDisplayName,
8789
};
8890
}
8991

@@ -100,30 +102,37 @@ async function getActiveParticipants() {
100102
}
101103

102104

105+
async function endCall() {
106+
const call_id = await getCallIdFromChannel();
107+
await slack.calls.end({ id: call_id });
108+
}
109+
110+
103111
exports.handler = async function(event) {
104112
if (isSlashCommand(event)) {
113+
// FIXME: Check for /co-working-room end
105114
const call_id = await handleStartCall();
106115
return { statusCode: 200, body: JSON.stringify(call_id) }
107116
}
108117

109118
// Zoom webhooks
110119
const zoomEvent = parseBody(event);
111120
const zoomEventName = zoomEvent?.event;
121+
112122
if (zoomEventName === "endpoint.url_validation") {
113-
return json(200, handleValidation(zoomEvent));
123+
return json(200, handleValidation(zoomEvent)); // FIXME: Define `json`
114124
}
115125

116126
else if (zoomEventName === "meeting.participant_joined") {
117-
await addParticipant(toSlackUser(zoomEvent));
127+
await addParticipantToCall(zoomEvent);
118128
return { statusCode: 204 };
119129
}
120130

121131
else if (zoomEventName === "meeting.participant_left") {
122-
await removeParticipant(toSlackUser(zoomEvent));
132+
await removeParticipantFromCall(zoomEvent);
123133
const active = await getActiveParticipants();
124134
if (active.length === 0) {
125-
const call_id = await getCallIdFromChannel();
126-
await slack.calls.end({ id: call_id });
135+
endCall();
127136
}
128137
return { statusCode: 204 };
129138
}

0 commit comments

Comments
 (0)