
























@@ -101,7 +101,7 @@ type SlackConversationContext = {
101101isRoom: boolean;
102102isRoomish: boolean;
103103channelConfig: ReturnType<typeof resolveSlackChannelConfig> | null;
104-allowBots: boolean;
104+allowBotsMode: "off" | "all" | "mentions";
105105isBotMessage: boolean;
106106};
107107@@ -149,11 +149,13 @@ async function resolveSlackConversationContext(params: {
149149allowNameMatching: ctx.allowNameMatching,
150150})
151151 : null;
152-const allowBots =
152+const allowBotsSetting =
153153channelConfig?.allowBots ??
154154account.config?.allowBots ??
155155cfg.channels?.slack?.allowBots ??
156156false;
157+const allowBotsMode: "off" | "all" | "mentions" =
158+allowBotsSetting === "mentions" ? "mentions" : allowBotsSetting ? "all" : "off";
157159158160return {
159161 channelInfo,
@@ -164,7 +166,7 @@ async function resolveSlackConversationContext(params: {
164166 isRoom,
165167 isRoomish,
166168 channelConfig,
167-allowBots,
169+allowBotsMode,
168170isBotMessage: Boolean(message.bot_id),
169171};
170172}
@@ -176,14 +178,14 @@ async function authorizeSlackInboundMessage(params: {
176178conversation: SlackConversationContext;
177179}): Promise<SlackAuthorizationContext | null> {
178180const { ctx, account, message, conversation } = params;
179-const { isDirectMessage, channelName, resolvedChannelType, isBotMessage, allowBots } =
181+const { isDirectMessage, channelName, resolvedChannelType, isBotMessage, allowBotsMode } =
180182conversation;
181183182184if (isBotMessage) {
183185if (message.user && ctx.botUserId && message.user === ctx.botUserId) {
184186return null;
185187}
186-if (!allowBots) {
188+if (allowBotsMode === "off") {
187189logVerbose(`slack: drop bot message ${message.bot_id ?? "unknown"} (allowBots=false)`);
188190return null;
189191}
@@ -273,7 +275,7 @@ export async function prepareSlackMessage(params: {
273275 isRoom,
274276 isRoomish,
275277 channelConfig,
276-allowBots,
278+allowBotsMode,
277279 isBotMessage,
278280} = conversation;
279281const authorization = await authorizeSlackInboundMessage({
@@ -463,6 +465,8 @@ export async function prepareSlackMessage(params: {
463465 ...(ctx.threadRequireExplicitMention ? { allowedImplicitMentionKinds: [] } : {}),
464466},
465467});
468+const effectiveWasMentioned = messageIngress.activationAccess.effectiveWasMentioned ?? false;
469+const shouldBypassMention = messageIngress.activationAccess.shouldBypassMention ?? false;
466470const senderGate = messageIngress.senderAccess.gate;
467471if (isRoom && senderGate?.allowed === false) {
468472logVerbose(`Blocked unauthorized slack sender ${senderId} (not in channel users)`);
@@ -471,7 +475,7 @@ export async function prepareSlackMessage(params: {
471475if (
472476isRoom &&
473477isBotMessage &&
474-allowBots &&
478+allowBotsMode !== "off" &&
475479!(await authorizeSlackBotRoomMessage({
476480 ctx,
477481channelId: message.channel,
@@ -484,6 +488,14 @@ export async function prepareSlackMessage(params: {
484488return null;
485489}
486490491+if (isBotMessage && allowBotsMode === "mentions") {
492+const botMentioned = isDirectMessage || effectiveWasMentioned || shouldBypassMention;
493+if (!botMentioned) {
494+logVerbose("slack: drop bot message (allowBots=mentions, missing mention)");
495+return null;
496+}
497+}
498+487499const threadContextAllowFromLower = isRoom
488500 ? channelUsersAllowlistConfigured
489501 ? normalizeAllowListLower(channelConfig?.users)
@@ -508,8 +520,6 @@ export async function prepareSlackMessage(params: {
508520return null;
509521}
510522511-const effectiveWasMentioned = messageIngress.activationAccess.effectiveWasMentioned ?? false;
512-const shouldBypassMention = messageIngress.activationAccess.shouldBypassMention ?? false;
513523if (isRoom && shouldRequireMention && messageIngress.activationAccess.shouldSkip) {
514524ctx.logger.info({ channel: message.channel, reason: "no-mention" }, "skipping channel message");
515525const pendingText = (message.text ?? "").trim();
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。