mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 17:54:58 +00:00
perf(core): speed up routing, pairing, slack, and security scans
This commit is contained in:
@@ -254,6 +254,7 @@ export async function authorizeSlackSystemEventSender(params: {
|
||||
channelId,
|
||||
channelName,
|
||||
channels: params.ctx.channelsConfig,
|
||||
channelKeys: params.ctx.channelsConfigKeys,
|
||||
defaultRequireMention: params.ctx.defaultRequireMention,
|
||||
});
|
||||
const channelUsersAllowlistConfigured =
|
||||
|
||||
@@ -89,11 +89,12 @@ export function resolveSlackChannelConfig(params: {
|
||||
channelId: string;
|
||||
channelName?: string;
|
||||
channels?: SlackChannelConfigEntries;
|
||||
channelKeys?: string[];
|
||||
defaultRequireMention?: boolean;
|
||||
}): SlackChannelConfigResolved | null {
|
||||
const { channelId, channelName, channels, defaultRequireMention } = params;
|
||||
const { channelId, channelName, channels, channelKeys, defaultRequireMention } = params;
|
||||
const entries = channels ?? {};
|
||||
const keys = Object.keys(entries);
|
||||
const keys = channelKeys ?? Object.keys(entries);
|
||||
const normalizedName = channelName ? normalizeSlackSlug(channelName) : "";
|
||||
const directName = channelName ? channelName.trim() : "";
|
||||
// Slack always delivers channel IDs in uppercase (e.g. C0ABC12345) but
|
||||
|
||||
@@ -78,6 +78,7 @@ export type SlackMonitorContext = {
|
||||
groupDmChannels: string[];
|
||||
defaultRequireMention: boolean;
|
||||
channelsConfig?: SlackChannelConfigEntries;
|
||||
channelsConfigKeys: string[];
|
||||
groupPolicy: GroupPolicy;
|
||||
useAccessGroups: boolean;
|
||||
reactionMode: SlackReactionNotificationMode;
|
||||
@@ -173,6 +174,7 @@ export function createSlackMonitorContext(params: {
|
||||
const groupDmChannelsLower = normalizeAllowListLower(groupDmChannels);
|
||||
const defaultRequireMention = params.defaultRequireMention ?? true;
|
||||
const hasChannelAllowlistConfig = Object.keys(params.channelsConfig ?? {}).length > 0;
|
||||
const channelsConfigKeys = Object.keys(params.channelsConfig ?? {});
|
||||
|
||||
const markMessageSeen = (channelId: string | undefined, ts?: string) => {
|
||||
if (!channelId || !ts) {
|
||||
@@ -331,6 +333,7 @@ export function createSlackMonitorContext(params: {
|
||||
channelId: p.channelId,
|
||||
channelName: p.channelName,
|
||||
channels: params.channelsConfig,
|
||||
channelKeys: channelsConfigKeys,
|
||||
defaultRequireMention,
|
||||
});
|
||||
const channelMatchMeta = formatAllowlistMatchMeta(channelConfig);
|
||||
@@ -413,6 +416,7 @@ export function createSlackMonitorContext(params: {
|
||||
groupDmChannels,
|
||||
defaultRequireMention,
|
||||
channelsConfig: params.channelsConfig,
|
||||
channelsConfigKeys,
|
||||
groupPolicy: params.groupPolicy,
|
||||
useAccessGroups: params.useAccessGroups,
|
||||
reactionMode: params.reactionMode,
|
||||
|
||||
@@ -108,6 +108,7 @@ export async function prepareSlackMessage(params: {
|
||||
channelId: message.channel,
|
||||
channelName,
|
||||
channels: ctx.channelsConfig,
|
||||
channelKeys: ctx.channelsConfigKeys,
|
||||
defaultRequireMention: ctx.defaultRequireMention,
|
||||
})
|
||||
: null;
|
||||
@@ -251,15 +252,29 @@ export async function prepareSlackMessage(params: {
|
||||
hasSlackThreadParticipation(account.accountId, message.channel, message.thread_ts)),
|
||||
);
|
||||
|
||||
const sender = message.user ? await ctx.resolveUserName(message.user) : null;
|
||||
const senderName =
|
||||
sender?.name ?? message.username?.trim() ?? message.user ?? message.bot_id ?? "unknown";
|
||||
let resolvedSenderName = message.username?.trim() || undefined;
|
||||
const resolveSenderName = async (): Promise<string> => {
|
||||
if (resolvedSenderName) {
|
||||
return resolvedSenderName;
|
||||
}
|
||||
if (message.user) {
|
||||
const sender = await ctx.resolveUserName(message.user);
|
||||
const normalized = sender?.name?.trim();
|
||||
if (normalized) {
|
||||
resolvedSenderName = normalized;
|
||||
return resolvedSenderName;
|
||||
}
|
||||
}
|
||||
resolvedSenderName = message.user ?? message.bot_id ?? "unknown";
|
||||
return resolvedSenderName;
|
||||
};
|
||||
const senderNameForAuth = ctx.allowNameMatching ? await resolveSenderName() : undefined;
|
||||
|
||||
const channelUserAuthorized = isRoom
|
||||
? resolveSlackUserAllowed({
|
||||
allowList: channelConfig?.users,
|
||||
userId: senderId,
|
||||
userName: senderName,
|
||||
userName: senderNameForAuth,
|
||||
allowNameMatching: ctx.allowNameMatching,
|
||||
})
|
||||
: true;
|
||||
@@ -279,7 +294,7 @@ export async function prepareSlackMessage(params: {
|
||||
const ownerAuthorized = resolveSlackAllowListMatch({
|
||||
allowList: allowFromLower,
|
||||
id: senderId,
|
||||
name: senderName,
|
||||
name: senderNameForAuth,
|
||||
allowNameMatching: ctx.allowNameMatching,
|
||||
}).allowed;
|
||||
const channelUsersAllowlistConfigured =
|
||||
@@ -289,7 +304,7 @@ export async function prepareSlackMessage(params: {
|
||||
? resolveSlackUserAllowed({
|
||||
allowList: channelConfig?.users,
|
||||
userId: senderId,
|
||||
userName: senderName,
|
||||
userName: senderNameForAuth,
|
||||
allowNameMatching: ctx.allowNameMatching,
|
||||
})
|
||||
: false;
|
||||
@@ -350,7 +365,7 @@ export async function prepareSlackMessage(params: {
|
||||
limit: ctx.historyLimit,
|
||||
entry: pendingBody
|
||||
? {
|
||||
sender: senderName,
|
||||
sender: await resolveSenderName(),
|
||||
body: pendingBody,
|
||||
timestamp: message.ts ? Math.round(Number(message.ts) * 1000) : undefined,
|
||||
messageId: message.ts,
|
||||
@@ -455,6 +470,7 @@ export async function prepareSlackMessage(params: {
|
||||
: null;
|
||||
|
||||
const roomLabel = channelName ? `#${channelName}` : `#${message.channel}`;
|
||||
const senderName = await resolveSenderName();
|
||||
const preview = rawBody.replace(/\s+/g, " ").slice(0, 160);
|
||||
const inboundLabel = isDirectMessage
|
||||
? `Slack DM from ${senderName}`
|
||||
|
||||
@@ -385,11 +385,11 @@ export async function registerSlackMonitorSlashCommands(params: {
|
||||
channelId: command.channel_id,
|
||||
channelName: channelInfo?.name,
|
||||
channels: ctx.channelsConfig,
|
||||
channelKeys: ctx.channelsConfigKeys,
|
||||
defaultRequireMention: ctx.defaultRequireMention,
|
||||
});
|
||||
if (ctx.useAccessGroups) {
|
||||
const channelAllowlistConfigured =
|
||||
Boolean(ctx.channelsConfig) && Object.keys(ctx.channelsConfig ?? {}).length > 0;
|
||||
const channelAllowlistConfigured = (ctx.channelsConfigKeys?.length ?? 0) > 0;
|
||||
const channelAllowed = channelConfig?.allowed !== false;
|
||||
if (
|
||||
!isSlackChannelAllowedByPolicy({
|
||||
|
||||
Reference in New Issue
Block a user