(event: SlackMemberJoinedChannelEvent)
| 339 | * Also auto-adds users to working groups (chapters/events) when they join linked Slack channels |
| 340 | */ |
| 341 | export 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 |
no test coverage detected