diff --git a/extensions/feishu/src/onboarding.ts b/extensions/feishu/src/onboarding.ts index d19e20305aa..46ad40d7681 100644 --- a/extensions/feishu/src/onboarding.ts +++ b/extensions/feishu/src/onboarding.ts @@ -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); } diff --git a/extensions/googlechat/src/onboarding.ts b/extensions/googlechat/src/onboarding.ts index 20040db5631..2fadfe7661a 100644 --- a/extensions/googlechat/src/onboarding.ts +++ b/extensions/googlechat/src/onboarding.ts @@ -4,6 +4,7 @@ import { formatDocsLink, mergeAllowFromEntries, resolveAccountIdForConfigure, + splitOnboardingEntries, type ChannelOnboardingAdapter, type ChannelOnboardingDmPolicy, type WizardPrompter, @@ -42,13 +43,6 @@ function setGoogleChatDmPolicy(cfg: OpenClawConfig, policy: DmPolicy) { }; } -function parseAllowFromInput(raw: string): string[] { - return raw - .split(/[\n,;]+/g) - .map((entry) => entry.trim()) - .filter(Boolean); -} - async function promptAllowFrom(params: { cfg: OpenClawConfig; prompter: WizardPrompter; @@ -60,7 +54,7 @@ async function promptAllowFrom(params: { initialValue: current[0] ? String(current[0]) : undefined, validate: (value) => (String(value ?? "").trim() ? undefined : "Required"), }); - const parts = parseAllowFromInput(String(entry)); + const parts = splitOnboardingEntries(String(entry)); const unique = mergeAllowFromEntries(undefined, parts); return { ...params.cfg, diff --git a/extensions/msteams/src/onboarding.ts b/extensions/msteams/src/onboarding.ts index f1199d9e0e3..11207e8ee49 100644 --- a/extensions/msteams/src/onboarding.ts +++ b/extensions/msteams/src/onboarding.ts @@ -14,6 +14,7 @@ import { setTopLevelChannelAllowFrom, setTopLevelChannelDmPolicyWithAllowFrom, setTopLevelChannelGroupPolicy, + splitOnboardingEntries, } from "openclaw/plugin-sdk/msteams"; import { parseMSTeamsTeamEntry, @@ -41,13 +42,6 @@ function setMSTeamsAllowFrom(cfg: OpenClawConfig, allowFrom: string[]): OpenClaw }); } -function parseAllowFromInput(raw: string): string[] { - return raw - .split(/[\n,;]+/g) - .map((entry) => entry.trim()) - .filter(Boolean); -} - function looksLikeGuid(value: string): boolean { return /^[0-9a-fA-F-]{16,}$/.test(value); } @@ -102,7 +96,7 @@ async function promptMSTeamsAllowFrom(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.", "MS Teams allowlist"); continue; diff --git a/src/plugin-sdk/feishu.ts b/src/plugin-sdk/feishu.ts index 9ef52b14326..88703e6adc4 100644 --- a/src/plugin-sdk/feishu.ts +++ b/src/plugin-sdk/feishu.ts @@ -18,10 +18,12 @@ export type { export { buildSingleChannelSecretPromptState, addWildcardAllowFrom, + mergeAllowFromEntries, promptSingleChannelSecretInput, setTopLevelChannelAllowFrom, setTopLevelChannelDmPolicyWithAllowFrom, setTopLevelChannelGroupPolicy, + splitOnboardingEntries, } from "../channels/plugins/onboarding/helpers.js"; export { PAIRING_APPROVED_MESSAGE } from "../channels/plugins/pairing-message.js"; export type { diff --git a/src/plugin-sdk/googlechat.ts b/src/plugin-sdk/googlechat.ts index fe2b6106299..38d1594406a 100644 --- a/src/plugin-sdk/googlechat.ts +++ b/src/plugin-sdk/googlechat.ts @@ -32,6 +32,7 @@ export { mergeAllowFromEntries, promptAccountId, resolveAccountIdForConfigure, + splitOnboardingEntries, setTopLevelChannelDmPolicyWithAllowFrom, } from "../channels/plugins/onboarding/helpers.js"; export { PAIRING_APPROVED_MESSAGE } from "../channels/plugins/pairing-message.js"; diff --git a/src/plugin-sdk/msteams.ts b/src/plugin-sdk/msteams.ts index bbc1bca3b67..90d5ee1b1ac 100644 --- a/src/plugin-sdk/msteams.ts +++ b/src/plugin-sdk/msteams.ts @@ -40,6 +40,7 @@ export { setTopLevelChannelAllowFrom, setTopLevelChannelDmPolicyWithAllowFrom, setTopLevelChannelGroupPolicy, + splitOnboardingEntries, } from "../channels/plugins/onboarding/helpers.js"; export { PAIRING_APPROVED_MESSAGE } from "../channels/plugins/pairing-message.js"; export type {