@@ -352,35 +352,46 @@ async function postGitHubLauncher(
352352 } ) ;
353353}
354354
355- function syncWorkspaceInBackground ( workspace : WorkspaceAuth , channelId : string ) : void {
355+ async function syncWorkspaceAfterMention (
356+ channelId : string ,
357+ workspace : { workspaceId ?: string ; workspaceName ?: string } | undefined
358+ ) : Promise < boolean > {
359+ if ( ! workspace ?. workspaceId ) {
360+ log . warn ( "Skipping Slack workspace sync; workspace id missing" , {
361+ channelId,
362+ workspaceName : workspace ?. workspaceName ,
363+ } ) ;
364+ return false ;
365+ }
366+
356367 if ( backgroundWorkspaceSyncInFlight . has ( workspace . workspaceId ) ) {
357368 log . debug ( "Skipping Slack workspace sync; already in flight" , {
358369 workspaceId : workspace . workspaceId ,
359370 channelId,
360371 } ) ;
361- return ;
372+ return false ;
362373 }
363374
364375 backgroundWorkspaceSyncInFlight . add ( workspace . workspaceId ) ;
365- void syncSlackWorkspace ( workspace . workspaceId )
366- . then ( ( updatedWorkspace ) => {
367- invalidateOdeConfigCache ( ) ;
368- log . info ( "Slack workspace synced after bot joined channel" , {
369- workspaceId : workspace . workspaceId ,
370- workspaceName : updatedWorkspace . name ,
371- channelId,
372- } ) ;
373- } )
374- . catch ( ( error ) => {
375- log . warn ( "Slack workspace sync failed after bot joined channel" , {
376- workspaceId : workspace . workspaceId ,
377- channelId,
378- error : String ( error ) ,
379- } ) ;
380- } )
381- . finally ( ( ) => {
382- backgroundWorkspaceSyncInFlight . delete ( workspace . workspaceId ) ;
376+ try {
377+ const updatedWorkspace = await syncSlackWorkspace ( workspace . workspaceId ) ;
378+ invalidateOdeConfigCache ( ) ;
379+ log . info ( "Slack workspace synced after mention in unseen channel" , {
380+ workspaceId : workspace . workspaceId ,
381+ workspaceName : updatedWorkspace . name ,
382+ channelId,
383+ } ) ;
384+ return true ;
385+ } catch ( error ) {
386+ log . warn ( "Slack workspace sync failed after mention in unseen channel" , {
387+ workspaceId : workspace . workspaceId ,
388+ channelId,
389+ error : String ( error ) ,
383390 } ) ;
391+ return false ;
392+ } finally {
393+ backgroundWorkspaceSyncInFlight . delete ( workspace . workspaceId ) ;
394+ }
384395}
385396
386397async function fetchWorkspaceAuth (
@@ -583,6 +594,7 @@ export function setupMessageHandlers(): void {
583594 app : slackApp ,
584595 isAuthorizedChannel,
585596 resolveWorkspaceAuth,
597+ syncWorkspaceForChannel : syncWorkspaceAfterMention ,
586598 getChannelWorkspaceName : ( channelId ) => channelWorkspaceMap . get ( channelId ) ,
587599 setChannelWorkspaceName : ( channelId , workspaceName ) => {
588600 channelWorkspaceMap . set ( channelId , workspaceName ) ;
@@ -607,37 +619,6 @@ export function setupMessageHandlers(): void {
607619 handleIncomingMessage : ( context , text ) => coreRuntime . handleIncomingMessage ( context , text ) ,
608620 } ) ;
609621
610- slackApp . event ( "member_joined_channel" , async ( { event, context } : any ) => {
611- const channelId = event ?. channel as string | undefined ;
612- const memberId = event ?. user as string | undefined ;
613- if ( ! channelId || ! memberId ) return ;
614-
615- const workspaceAuth = resolveWorkspaceAuth (
616- event ?. team as string | undefined ,
617- ( event ?. enterprise_id as string | undefined ) ?? ( context ?. enterpriseId as string | undefined )
618- ) ;
619- if ( ! workspaceAuth || memberId !== workspaceAuth . botUserId ) return ;
620-
621- channelWorkspaceAuthMap . set ( channelId , workspaceAuth ) ;
622- if ( workspaceAuth . workspaceName ) {
623- channelWorkspaceMap . set ( channelId , workspaceAuth . workspaceName ) ;
624- }
625-
626- if ( ! workspaceAuth . workspaceId ) {
627- log . warn ( "Bot added to channel but workspace id is missing; skipping sync" , {
628- workspaceName : workspaceAuth . workspaceName ,
629- channelId,
630- } ) ;
631- return ;
632- }
633-
634- log . info ( "Bot added to channel; syncing Slack workspace" , {
635- workspaceId : workspaceAuth . workspaceId ,
636- workspaceName : workspaceAuth . workspaceName ,
637- channelId,
638- } ) ;
639- syncWorkspaceInBackground ( workspaceAuth , channelId ) ;
640- } ) ;
641622 }
642623
643624}
0 commit comments