@@ -6,12 +6,16 @@ type RouterDeps = {
66 resolveWorkspaceAuth : (
77 teamId ?: string ,
88 enterpriseId ?: string
9- ) => { workspaceName ?: string ; botToken ?: string ; [ key : string ] : unknown } | undefined ;
9+ ) => { workspaceId ?: string ; workspaceName ?: string ; botToken ?: string ; [ key : string ] : unknown } | undefined ;
10+ syncWorkspaceForChannel : (
11+ channelId : string ,
12+ workspaceAuth : { workspaceId ?: string ; workspaceName ?: string ; botToken ?: string ; [ key : string ] : unknown } | undefined
13+ ) => Promise < boolean > ;
1014 getChannelWorkspaceName : ( channelId : string ) => string | undefined ;
1115 setChannelWorkspaceName : ( channelId : string , workspaceName : string ) => void ;
1216 setChannelWorkspaceAuth : (
1317 channelId : string ,
14- auth : { workspaceName ?: string ; botToken ?: string ; [ key : string ] : unknown } | undefined
18+ auth : { workspaceId ?: string ; workspaceName ?: string ; botToken ?: string ; [ key : string ] : unknown } | undefined
1519 ) => void ;
1620 isThreadActive : ( channelId : string , threadId : string ) => boolean ;
1721 markThreadActive : ( channelId : string , threadId : string ) => void ;
@@ -100,6 +104,18 @@ async function maybeHandleStopCommand(
100104 return true ;
101105}
102106
107+ async function maybeRefreshWorkspaceForMention ( params : {
108+ deps : RouterDeps ;
109+ channelId : string ;
110+ isMention : boolean ;
111+ workspaceAuth : WorkspaceAuth ;
112+ } ) : Promise < void > {
113+ const { deps, channelId, isMention, workspaceAuth } = params ;
114+ if ( ! isMention ) return ;
115+ if ( deps . isAuthorizedChannel ( channelId ) ) return ;
116+ await deps . syncWorkspaceForChannel ( channelId , workspaceAuth ) ;
117+ }
118+
103119async function maybeNotifySettingsIssues (
104120 deps : RouterDeps ,
105121 channelId : string ,
@@ -155,14 +171,9 @@ export function registerSlackMessageRouter(deps: RouterDeps): void {
155171
156172 const { channelId, userId, text, threadId, messageId } = incoming ;
157173
158- if ( ! deps . isAuthorizedChannel ( channelId ) ) {
159- log . info ( "[DROP] Unauthorized channel" , { channelId } ) ;
160- return ;
161- }
162-
163174 const authResult = await client . auth . test ( ) ;
164175 const currentBotUserId = authResult . user_id as string ;
165- syncWorkspaceAuth (
176+ const workspaceAuth = syncWorkspaceAuth (
166177 deps ,
167178 channelId ,
168179 authResult . team_id ,
@@ -174,11 +185,22 @@ export function registerSlackMessageRouter(deps: RouterDeps): void {
174185 return ;
175186 }
176187
177- if ( await maybeHandleStopCommand ( deps , text , channelId , threadId , say ) ) {
188+ const isMention = currentBotUserId ? text . includes ( `<@${ currentBotUserId } >` ) : false ;
189+ await maybeRefreshWorkspaceForMention ( {
190+ deps,
191+ channelId,
192+ isMention,
193+ workspaceAuth,
194+ } ) ;
195+
196+ if ( ! deps . isAuthorizedChannel ( channelId ) ) {
197+ log . info ( "[DROP] Unauthorized channel" , { channelId, isMention } ) ;
178198 return ;
179199 }
180200
181- const isMention = currentBotUserId ? text . includes ( `<@${ currentBotUserId } >` ) : false ;
201+ if ( await maybeHandleStopCommand ( deps , text , channelId , threadId , say ) ) {
202+ return ;
203+ }
182204 const threadActive = deps . isThreadActive ( channelId , threadId ) ;
183205
184206 if ( shouldDropForThreadContext ( isMention , threadActive ) ) {
0 commit comments