@@ -96,6 +96,18 @@ function isSlashCommand(event) {
9696}
9797
9898
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+
99111async function getActiveParticipants ( ) {
100112 const resp = await slack . conversations . history ( { channel : SLACK_COWORKING_CHANNEL_ID , limit : 1 } ) ;
101113 return resp ?. messages ?. [ 0 ] ?. blocks ?. [ 0 ] ?. call ?. v1 ?. active_participants ?? [ ] ;
@@ -110,17 +122,27 @@ async function endCall() {
110122
111123exports . handler = async function ( event ) {
112124 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+ }
116134 }
117135
118136 // Zoom webhooks
119137 const zoomEvent = parseBody ( event ) ;
120138 const zoomEventName = zoomEvent ?. event ;
121139
122140 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+ }
124146 }
125147
126148 else if ( zoomEventName === "meeting.participant_joined" ) {
@@ -132,7 +154,7 @@ exports.handler = async function(event) {
132154 await removeParticipantFromCall ( zoomEvent ) ;
133155 const active = await getActiveParticipants ( ) ;
134156 if ( active . length === 0 ) {
135- endCall ( ) ;
157+ await endCall ( ) ;
136158 }
137159 return { statusCode : 204 } ;
138160 }
0 commit comments