MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / handleMemberJoinedChannel

Function handleMemberJoinedChannel

server/src/slack/events.ts:341–378  ·  view source on GitHub ↗
(event: SlackMemberJoinedChannelEvent)

Source from the content-addressed store, hash-verified

339 * Also auto-adds users to working groups (chapters/events) when they join linked Slack channels
340 */
341export async function handleMemberJoinedChannel(event: SlackMemberJoinedChannelEvent): Promise<void> {
342 logger.debug(
343 { userId: event.user, channel: event.channel },
344 'User joined channel'
345 );
346
347 try {
348 // Get user's org mapping if they're linked
349 const mapping = await slackDb.getBySlackUserId(event.user);
350 let organizationId: string | undefined;
351
352 if (mapping?.workos_user_id) {
353 // Note: Would need to lookup org from WorkOS - for now just record without org
354 // This could be enhanced with a cache or join table
355 }
356
357 await slackDb.recordActivity({
358 slack_user_id: event.user,
359 activity_type: 'channel_join',
360 channel_id: event.channel,
361 activity_timestamp: new Date(),
362 organization_id: organizationId,
363 metadata: {
364 channel_type: event.channel_type,
365 inviter: event.inviter,
366 },
367 });
368
369 // Check if this channel is linked to a working group (chapter or event)
370 // and auto-add the user if they have a WorkOS mapping
371 if (mapping?.workos_user_id) {
372 const isPrivateChannel = event.channel_type === 'G';
373 await autoAddToWorkingGroup(event.channel, mapping.workos_user_id, mapping, isPrivateChannel);
374 }
375 } catch (error) {
376 logger.error({ error, userId: event.user }, 'Failed to record channel join activity');
377 }
378}
379
380/**
381 * Auto-add user to a working group when they join its Slack channel

Callers 1

handleSlackEventFunction · 0.85

Calls 3

autoAddToWorkingGroupFunction · 0.85
getBySlackUserIdMethod · 0.80
recordActivityMethod · 0.80

Tested by

no test coverage detected