@@ -96,6 +96,18 @@ function isSlashCommand(event) {
96
96
}
97
97
98
98
99
+ function getSlashCommand ( event ) {
100
+ const body = parseBody ( event ) ;
101
+ return typeof body ?. command === "string" && body . command ;
102
+ }
103
+
104
+
105
+ function getSlashText ( event ) {
106
+ const body = parseBody ( event ) ;
107
+ return typeof body ?. text === "string" && body . text ;
108
+ }
109
+
110
+
99
111
async function getActiveParticipants ( ) {
100
112
const resp = await slack . conversations . history ( { channel : SLACK_COWORKING_CHANNEL_ID , limit : 1 } ) ;
101
113
return resp ?. messages ?. [ 0 ] ?. blocks ?. [ 0 ] ?. call ?. v1 ?. active_participants ?? [ ] ;
@@ -110,17 +122,27 @@ async function endCall() {
110
122
111
123
exports . handler = async function ( event ) {
112
124
if ( isSlashCommand ( event ) ) {
113
- // FIXME: Check for /co-working-room end
114
- const call_id = await handleStartCall ( ) ;
115
- return { statusCode : 200 , body : JSON . stringify ( call_id ) }
125
+ const slashCommand = getSlashCommand ( event ) ;
126
+ if ( slashCommand === "/co-working-room" ) {
127
+ const slashText = getSlashText ( event ) ;
128
+ if ( slashText == "end" ) {
129
+ await endCall ( ) ;
130
+ }
131
+ const call_id = await handleStartCall ( ) ;
132
+ return { statusCode : 200 , body : JSON . stringify ( call_id ) }
133
+ }
116
134
}
117
135
118
136
// Zoom webhooks
119
137
const zoomEvent = parseBody ( event ) ;
120
138
const zoomEventName = zoomEvent ?. event ;
121
139
122
140
if ( zoomEventName === "endpoint.url_validation" ) {
123
- return json ( 200 , handleValidation ( zoomEvent ) ) ; // FIXME: Define `json`
141
+ return {
142
+ statusCode : 200 ,
143
+ headers : { "Content-Type" : "application/json" } ,
144
+ body : JSON . stringify ( handleValidation ( zoomEvent ) )
145
+ }
124
146
}
125
147
126
148
else if ( zoomEventName === "meeting.participant_joined" ) {
@@ -132,7 +154,7 @@ exports.handler = async function(event) {
132
154
await removeParticipantFromCall ( zoomEvent ) ;
133
155
const active = await getActiveParticipants ( ) ;
134
156
if ( active . length === 0 ) {
135
- endCall ( ) ;
157
+ await endCall ( ) ;
136
158
}
137
159
return { statusCode : 204 } ;
138
160
}
0 commit comments