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

Function syncUserToChaptersFromSlackChannels

server/src/slack/sync.ts:351–470  ·  view source on GitHub ↗
(
  workosUserId: string,
  slackUserId: string
)

Source from the content-addressed store, hash-verified

349 * Checks which channels they're in and adds them to corresponding committees.
350 */
351export async function syncUserToChaptersFromSlackChannels(
352 workosUserId: string,
353 slackUserId: string
354): Promise<SyncUserChaptersResult> {
355 const result: SyncUserChaptersResult = {
356 workos_user_id: workosUserId,
357 slack_user_id: slackUserId,
358 channels_checked: 0,
359 chapters_joined: 0,
360 chapters_already_member: 0,
361 chapters: [],
362 errors: [],
363 };
364
365 if (!isSlackConfigured()) {
366 result.errors.push('Slack is not configured (ADDIE_BOT_TOKEN missing)');
367 return result;
368 }
369
370 try {
371 logger.info(
372 { workosUserId, slackUserId },
373 'Starting user committee sync from Slack channels'
374 );
375
376 // Get all channels the user is a member of
377 let userChannelIds: string[];
378 try {
379 userChannelIds = await getUserChannels(slackUserId);
380 } catch (error) {
381 const errorMessage = error instanceof Error ? error.message : 'Unknown error';
382
383 // If Slack says the user doesn't exist, mark them deleted so we don't keep trying
384 if (errorMessage.includes('user_not_found')) {
385 logger.warn({ slackUserId }, 'Slack user no longer exists — marking as deleted');
386 await slackDb.markSlackUserDeleted(slackUserId);
387 result.errors.push('Slack user no longer exists');
388 return result;
389 }
390
391 result.errors.push(`Failed to fetch user channels: ${errorMessage}`);
392 logger.error({ error, slackUserId }, 'Failed to fetch user channels from Slack');
393 return result;
394 }
395 result.channels_checked = userChannelIds.length;
396
397 if (userChannelIds.length === 0) {
398 logger.info({ slackUserId }, 'User is not a member of any channels');
399 return result;
400 }
401
402 // Get all committees that have Slack channels configured
403 const workingGroups = await workingGroupDb.listWorkingGroupsWithSlackChannel();
404
405 // Get user's Slack info for membership record
406 const slackMapping = await slackDb.getBySlackUserId(slackUserId);
407
408 // Check each group with a Slack channel

Callers 4

createAdminSlackRouterFunction · 0.85
tryAutoMapByEmailFunction · 0.85

Calls 9

isSlackConfiguredFunction · 0.85
getUserChannelsFunction · 0.85
warnMethod · 0.80
markSlackUserDeletedMethod · 0.80
getBySlackUserIdMethod · 0.80
isMemberMethod · 0.80

Tested by

no test coverage detected