refactor: share onboarding allowlist entry parsing

This commit is contained in:
Peter Steinberger
2026-03-07 23:34:42 +00:00
parent 766d76ef9a
commit f319ec2dac
6 changed files with 13 additions and 31 deletions

View File

@@ -11,10 +11,12 @@ import {
DEFAULT_ACCOUNT_ID,
formatDocsLink,
hasConfiguredSecretInput,
mergeAllowFromEntries,
promptSingleChannelSecretInput,
setTopLevelChannelAllowFrom,
setTopLevelChannelDmPolicyWithAllowFrom,
setTopLevelChannelGroupPolicy,
splitOnboardingEntries,
} from "openclaw/plugin-sdk/feishu";
import { resolveFeishuCredentials } from "./accounts.js";
import { probeFeishu } from "./probe.js";
@@ -46,13 +48,6 @@ function setFeishuAllowFrom(cfg: ClawdbotConfig, allowFrom: string[]): ClawdbotC
}) as ClawdbotConfig;
}
function parseAllowFromInput(raw: string): string[] {
return raw
.split(/[\n,;]+/g)
.map((entry) => entry.trim())
.filter(Boolean);
}
async function promptFeishuAllowFrom(params: {
cfg: ClawdbotConfig;
prompter: WizardPrompter;
@@ -76,18 +71,13 @@ async function promptFeishuAllowFrom(params: {
initialValue: existing[0] ? String(existing[0]) : undefined,
validate: (value) => (String(value ?? "").trim() ? undefined : "Required"),
});
const parts = parseAllowFromInput(String(entry));
const parts = splitOnboardingEntries(String(entry));
if (parts.length === 0) {
await params.prompter.note("Enter at least one user.", "Feishu allowlist");
continue;
}
const unique = [
...new Set([
...existing.map((v: string | number) => String(v).trim()).filter(Boolean),
...parts,
]),
];
const unique = mergeAllowFromEntries(existing, parts);
return setFeishuAllowFrom(params.cfg, unique);
}
}
@@ -446,7 +436,7 @@ export const feishuOnboardingAdapter: ChannelOnboardingAdapter = {
initialValue: existing.length > 0 ? existing.map(String).join(", ") : undefined,
});
if (entry) {
const parts = parseAllowFromInput(String(entry));
const parts = splitOnboardingEntries(String(entry));
if (parts.length > 0) {
next = setFeishuGroupAllowFrom(next, parts);
}