mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-27 17:11:46 +00:00
refactor(slack): dedupe allowlist match selection
This commit is contained in:
@@ -115,6 +115,27 @@ function scoreSlackUser(user: SlackUserLookup, match: { name?: string; email?: s
|
||||
return score;
|
||||
}
|
||||
|
||||
function resolveSlackUserFromMatches(
|
||||
input: string,
|
||||
matches: SlackUserLookup[],
|
||||
parsed: { name?: string; email?: string },
|
||||
): SlackUserResolution {
|
||||
const scored = matches
|
||||
.map((user) => ({ user, score: scoreSlackUser(user, parsed) }))
|
||||
.toSorted((a, b) => b.score - a.score);
|
||||
const best = scored[0]?.user ?? matches[0];
|
||||
return {
|
||||
input,
|
||||
resolved: true,
|
||||
id: best.id,
|
||||
name: best.displayName ?? best.realName ?? best.name,
|
||||
email: best.email,
|
||||
deleted: best.deleted,
|
||||
isBot: best.isBot,
|
||||
note: matches.length > 1 ? "multiple matches; chose best" : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
export async function resolveSlackUserAllowlist(params: {
|
||||
token: string;
|
||||
entries: string[];
|
||||
@@ -142,20 +163,7 @@ export async function resolveSlackUserAllowlist(params: {
|
||||
if (parsed.email) {
|
||||
const matches = users.filter((user) => user.email === parsed.email);
|
||||
if (matches.length > 0) {
|
||||
const scored = matches
|
||||
.map((user) => ({ user, score: scoreSlackUser(user, parsed) }))
|
||||
.toSorted((a, b) => b.score - a.score);
|
||||
const best = scored[0]?.user ?? matches[0];
|
||||
results.push({
|
||||
input,
|
||||
resolved: true,
|
||||
id: best.id,
|
||||
name: best.displayName ?? best.realName ?? best.name,
|
||||
email: best.email,
|
||||
deleted: best.deleted,
|
||||
isBot: best.isBot,
|
||||
note: matches.length > 1 ? "multiple matches; chose best" : undefined,
|
||||
});
|
||||
results.push(resolveSlackUserFromMatches(input, matches, parsed));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -168,20 +176,7 @@ export async function resolveSlackUserAllowlist(params: {
|
||||
return candidates.includes(target);
|
||||
});
|
||||
if (matches.length > 0) {
|
||||
const scored = matches
|
||||
.map((user) => ({ user, score: scoreSlackUser(user, parsed) }))
|
||||
.toSorted((a, b) => b.score - a.score);
|
||||
const best = scored[0]?.user ?? matches[0];
|
||||
results.push({
|
||||
input,
|
||||
resolved: true,
|
||||
id: best.id,
|
||||
name: best.displayName ?? best.realName ?? best.name,
|
||||
email: best.email,
|
||||
deleted: best.deleted,
|
||||
isBot: best.isBot,
|
||||
note: matches.length > 1 ? "multiple matches; chose best" : undefined,
|
||||
});
|
||||
results.push(resolveSlackUserFromMatches(input, matches, parsed));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user