diff --git a/src/auto-reply/reply/commands-allowlist.ts b/src/auto-reply/reply/commands-allowlist.ts index fd5fa8ad7f..3b1b887766 100644 --- a/src/auto-reply/reply/commands-allowlist.ts +++ b/src/auto-reply/reply/commands-allowlist.ts @@ -29,6 +29,11 @@ import type { CommandHandler } from "./commands-types.js"; type AllowlistScope = "dm" | "group" | "all"; type AllowlistAction = "list" | "add" | "remove"; type AllowlistTarget = "both" | "config" | "store"; +type ResolvedAllowlistName = { + input: string; + resolved: boolean; + name?: string | null; +}; type AllowlistCommand = | { @@ -249,6 +254,11 @@ function resolveChannelAllowFromPaths( channelId: ChannelId, scope: AllowlistScope, ): string[] | null { + const supportsGroupAllowlist = + channelId === "telegram" || + channelId === "whatsapp" || + channelId === "signal" || + channelId === "imessage"; if (scope === "all") { return null; } @@ -257,23 +267,13 @@ function resolveChannelAllowFromPaths( // Canonical DM allowlist location for Slack/Discord. Legacy: dm.allowFrom. return ["allowFrom"]; } - if ( - channelId === "telegram" || - channelId === "whatsapp" || - channelId === "signal" || - channelId === "imessage" - ) { + if (supportsGroupAllowlist) { return ["allowFrom"]; } return null; } if (scope === "group") { - if ( - channelId === "telegram" || - channelId === "whatsapp" || - channelId === "signal" || - channelId === "imessage" - ) { + if (supportsGroupAllowlist) { return ["groupAllowFrom"]; } return null; @@ -281,6 +281,16 @@ function resolveChannelAllowFromPaths( return null; } +function mapResolvedAllowlistNames(entries: ResolvedAllowlistName[]): Map { + const map = new Map(); + for (const entry of entries) { + if (entry.resolved && entry.name) { + map.set(entry.input, entry.name); + } + } + return map; +} + async function resolveSlackNames(params: { cfg: OpenClawConfig; accountId?: string | null; @@ -292,13 +302,7 @@ async function resolveSlackNames(params: { return new Map(); } const resolved = await resolveSlackUserAllowlist({ token, entries: params.entries }); - const map = new Map(); - for (const entry of resolved) { - if (entry.resolved && entry.name) { - map.set(entry.input, entry.name); - } - } - return map; + return mapResolvedAllowlistNames(resolved); } async function resolveDiscordNames(params: { @@ -312,13 +316,7 @@ async function resolveDiscordNames(params: { return new Map(); } const resolved = await resolveDiscordUserAllowlist({ token, entries: params.entries }); - const map = new Map(); - for (const entry of resolved) { - if (entry.resolved && entry.name) { - map.set(entry.input, entry.name); - } - } - return map; + return mapResolvedAllowlistNames(resolved); } export const handleAllowlistCommand: CommandHandler = async (params, allowTextCommands) => {