@@ -67,6 +67,8 @@ import { isSlackSubteamMentionForBot } from "./subteam-mentions.js";
6767import type { PreparedSlackMessage } from "./types.js" ;
6868
6969const mentionRegexCache = new WeakMap < SlackMonitorContext , Map < string , RegExp [ ] > > ( ) ;
70+ const SLACK_ANY_MENTION_RE = / < @ [ ^ > ] + > | < ! s u b t e a m \^ [ ^ > ] + > / ;
71+ const SLACK_SUBTEAM_MENTION_MARKER = "<!subteam^" ;
7072
7173function resolveCachedMentionRegexes (
7274 ctx : SlackMonitorContext ,
@@ -286,17 +288,20 @@ export async function prepareSlackMessage(params: {
286288 return null ;
287289 }
288290 const { senderId, allowFromLower } = authorization ;
289- const hasAnyMention = / < @ [ ^ > ] + > | < ! s u b t e a m \^ [ ^ > ] + > / . test ( message . text ?? "" ) ;
291+ const messageText = message . text ?? "" ;
292+ const hasAnyMention = SLACK_ANY_MENTION_RE . test ( messageText ) ;
293+ const hasSubteamMention = messageText . includes ( SLACK_SUBTEAM_MENTION_MARKER ) ;
290294 const explicitlyMentioned = Boolean (
291295 ctx . botUserId &&
292- ( message . text ?. includes ( `<@${ ctx . botUserId } >` ) ||
293- ( await isSlackSubteamMentionForBot ( {
294- client : ctx . app . client ,
295- text : message . text ,
296- botUserId : ctx . botUserId ,
297- teamId : ctx . teamId ,
298- log : logVerbose ,
299- } ) ) ) ,
296+ ( messageText . includes ( `<@${ ctx . botUserId } >` ) ||
297+ ( hasSubteamMention &&
298+ ( await isSlackSubteamMentionForBot ( {
299+ client : ctx . app . client ,
300+ text : messageText ,
301+ botUserId : ctx . botUserId ,
302+ teamId : ctx . teamId ,
303+ log : logVerbose ,
304+ } ) ) ) ) ,
300305 ) ;
301306 const seedTopLevelRoomThreadBySource =
302307 opts . source === "app_mention" || opts . wasMentioned === true || explicitlyMentioned ;
@@ -315,7 +320,7 @@ export async function prepareSlackMessage(params: {
315320 opts . wasMentioned ??
316321 ( ! isDirectMessage &&
317322 matchesMentionWithExplicit ( {
318- text : message . text ?? "" ,
323+ text : messageText ,
319324 mentionRegexes,
320325 explicit : {
321326 hasAnyMention,
0 commit comments