refactor: unify onboarding dm/group policy scaffolding

This commit is contained in:
Peter Steinberger
2026-03-07 21:38:27 +00:00
parent fecca6fd8d
commit 6b1c82c4f1
20 changed files with 239 additions and 169 deletions

View File

@@ -7,11 +7,11 @@ import type {
} from "openclaw/plugin-sdk/bluebubbles";
import {
DEFAULT_ACCOUNT_ID,
addWildcardAllowFrom,
formatDocsLink,
mergeAllowFromEntries,
normalizeAccountId,
resolveAccountIdForConfigure,
setTopLevelChannelDmPolicyWithAllowFrom,
} from "openclaw/plugin-sdk/bluebubbles";
import {
listBlueBubblesAccountIds,
@@ -26,19 +26,11 @@ import { normalizeBlueBubblesServerUrl } from "./types.js";
const channel = "bluebubbles" as const;
function setBlueBubblesDmPolicy(cfg: OpenClawConfig, dmPolicy: DmPolicy): OpenClawConfig {
const allowFrom =
dmPolicy === "open" ? addWildcardAllowFrom(cfg.channels?.bluebubbles?.allowFrom) : undefined;
return {
...cfg,
channels: {
...cfg.channels,
bluebubbles: {
...cfg.channels?.bluebubbles,
dmPolicy,
...(allowFrom ? { allowFrom } : {}),
},
},
};
return setTopLevelChannelDmPolicyWithAllowFrom({
cfg,
channel: "bluebubbles",
dmPolicy,
});
}
function setBlueBubblesAllowFrom(

View File

@@ -7,11 +7,13 @@ import type {
WizardPrompter,
} from "openclaw/plugin-sdk/feishu";
import {
addWildcardAllowFrom,
DEFAULT_ACCOUNT_ID,
formatDocsLink,
hasConfiguredSecretInput,
promptSingleChannelSecretInput,
setTopLevelChannelAllowFrom,
setTopLevelChannelDmPolicyWithAllowFrom,
setTopLevelChannelGroupPolicy,
} from "openclaw/plugin-sdk/feishu";
import { resolveFeishuCredentials } from "./accounts.js";
import { probeFeishu } from "./probe.js";
@@ -28,34 +30,19 @@ function normalizeString(value: unknown): string | undefined {
}
function setFeishuDmPolicy(cfg: ClawdbotConfig, dmPolicy: DmPolicy): ClawdbotConfig {
const allowFrom =
dmPolicy === "open"
? addWildcardAllowFrom(cfg.channels?.feishu?.allowFrom)?.map((entry) => String(entry))
: undefined;
return {
...cfg,
channels: {
...cfg.channels,
feishu: {
...cfg.channels?.feishu,
dmPolicy,
...(allowFrom ? { allowFrom } : {}),
},
},
};
return setTopLevelChannelDmPolicyWithAllowFrom({
cfg,
channel: "feishu",
dmPolicy,
}) as ClawdbotConfig;
}
function setFeishuAllowFrom(cfg: ClawdbotConfig, allowFrom: string[]): ClawdbotConfig {
return {
...cfg,
channels: {
...cfg.channels,
feishu: {
...cfg.channels?.feishu,
allowFrom,
},
},
};
return setTopLevelChannelAllowFrom({
cfg,
channel: "feishu",
allowFrom,
}) as ClawdbotConfig;
}
function parseAllowFromInput(raw: string): string[] {
@@ -137,17 +124,12 @@ function setFeishuGroupPolicy(
cfg: ClawdbotConfig,
groupPolicy: "open" | "allowlist" | "disabled",
): ClawdbotConfig {
return {
...cfg,
channels: {
...cfg.channels,
feishu: {
...cfg.channels?.feishu,
enabled: true,
groupPolicy,
},
},
};
return setTopLevelChannelGroupPolicy({
cfg,
channel: "feishu",
groupPolicy,
enabled: true,
}) as ClawdbotConfig;
}
function setFeishuGroupAllowFrom(cfg: ClawdbotConfig, groupAllowFrom: string[]): ClawdbotConfig {

View File

@@ -1,9 +1,10 @@
import {
addWildcardAllowFrom,
DEFAULT_ACCOUNT_ID,
formatDocsLink,
promptChannelAccessConfig,
resolveAccountIdForConfigure,
setTopLevelChannelAllowFrom,
setTopLevelChannelDmPolicyWithAllowFrom,
type ChannelOnboardingAdapter,
type ChannelOnboardingDmPolicy,
type DmPolicy,
@@ -90,32 +91,19 @@ function updateIrcAccountConfig(
}
function setIrcDmPolicy(cfg: CoreConfig, dmPolicy: DmPolicy): CoreConfig {
const allowFrom =
dmPolicy === "open" ? addWildcardAllowFrom(cfg.channels?.irc?.allowFrom) : undefined;
return {
...cfg,
channels: {
...cfg.channels,
irc: {
...cfg.channels?.irc,
dmPolicy,
...(allowFrom ? { allowFrom } : {}),
},
},
};
return setTopLevelChannelDmPolicyWithAllowFrom({
cfg,
channel: "irc",
dmPolicy,
}) as CoreConfig;
}
function setIrcAllowFrom(cfg: CoreConfig, allowFrom: string[]): CoreConfig {
return {
...cfg,
channels: {
...cfg.channels,
irc: {
...cfg.channels?.irc,
allowFrom,
},
},
};
return setTopLevelChannelAllowFrom({
cfg,
channel: "irc",
allowFrom,
}) as CoreConfig;
}
function setIrcNickServ(

View File

@@ -7,6 +7,7 @@ import {
mergeAllowFromEntries,
promptSingleChannelSecretInput,
promptChannelAccessConfig,
setTopLevelChannelGroupPolicy,
type SecretInput,
type ChannelOnboardingAdapter,
type ChannelOnboardingDmPolicy,
@@ -143,17 +144,12 @@ async function promptMatrixAllowFrom(params: {
}
function setMatrixGroupPolicy(cfg: CoreConfig, groupPolicy: "open" | "allowlist" | "disabled") {
return {
...cfg,
channels: {
...cfg.channels,
matrix: {
...cfg.channels?.matrix,
enabled: true,
groupPolicy,
},
},
};
return setTopLevelChannelGroupPolicy({
cfg,
channel: "matrix",
groupPolicy,
enabled: true,
}) as CoreConfig;
}
function setMatrixGroupRooms(cfg: CoreConfig, roomKeys: string[]) {

View File

@@ -7,11 +7,13 @@ import type {
MSTeamsTeamConfig,
} from "openclaw/plugin-sdk/msteams";
import {
addWildcardAllowFrom,
DEFAULT_ACCOUNT_ID,
formatDocsLink,
mergeAllowFromEntries,
promptChannelAccessConfig,
setTopLevelChannelAllowFrom,
setTopLevelChannelDmPolicyWithAllowFrom,
setTopLevelChannelGroupPolicy,
} from "openclaw/plugin-sdk/msteams";
import {
parseMSTeamsTeamEntry,
@@ -24,34 +26,19 @@ import { hasConfiguredMSTeamsCredentials, resolveMSTeamsCredentials } from "./to
const channel = "msteams" as const;
function setMSTeamsDmPolicy(cfg: OpenClawConfig, dmPolicy: DmPolicy) {
const allowFrom =
dmPolicy === "open"
? addWildcardAllowFrom(cfg.channels?.msteams?.allowFrom)?.map((entry) => String(entry))
: undefined;
return {
...cfg,
channels: {
...cfg.channels,
msteams: {
...cfg.channels?.msteams,
dmPolicy,
...(allowFrom ? { allowFrom } : {}),
},
},
};
return setTopLevelChannelDmPolicyWithAllowFrom({
cfg,
channel: "msteams",
dmPolicy,
});
}
function setMSTeamsAllowFrom(cfg: OpenClawConfig, allowFrom: string[]): OpenClawConfig {
return {
...cfg,
channels: {
...cfg.channels,
msteams: {
...cfg.channels?.msteams,
allowFrom,
},
},
};
return setTopLevelChannelAllowFrom({
cfg,
channel: "msteams",
allowFrom,
});
}
function parseAllowFromInput(raw: string): string[] {
@@ -171,17 +158,12 @@ function setMSTeamsGroupPolicy(
cfg: OpenClawConfig,
groupPolicy: "open" | "allowlist" | "disabled",
): OpenClawConfig {
return {
...cfg,
channels: {
...cfg.channels,
msteams: {
...cfg.channels?.msteams,
enabled: true,
groupPolicy,
},
},
};
return setTopLevelChannelGroupPolicy({
cfg,
channel: "msteams",
groupPolicy,
enabled: true,
});
}
function setMSTeamsTeamsAllowlist(

View File

@@ -1,5 +1,4 @@
import {
addWildcardAllowFrom,
formatDocsLink,
hasConfiguredSecretInput,
mergeAllowFromEntries,
@@ -7,6 +6,7 @@ import {
resolveAccountIdForConfigure,
DEFAULT_ACCOUNT_ID,
normalizeAccountId,
setTopLevelChannelDmPolicyWithAllowFrom,
type SecretInput,
type ChannelOnboardingAdapter,
type ChannelOnboardingDmPolicy,
@@ -23,24 +23,13 @@ import type { CoreConfig, DmPolicy } from "./types.js";
const channel = "nextcloud-talk" as const;
function setNextcloudTalkDmPolicy(cfg: CoreConfig, dmPolicy: DmPolicy): CoreConfig {
const existingConfig = cfg.channels?.["nextcloud-talk"];
const existingAllowFrom: string[] = (existingConfig?.allowFrom ?? []).map((x) => String(x));
const allowFrom: string[] =
dmPolicy === "open" ? (addWildcardAllowFrom(existingAllowFrom) as string[]) : existingAllowFrom;
const newNextcloudTalkConfig = {
...existingConfig,
return setTopLevelChannelDmPolicyWithAllowFrom({
cfg,
channel: "nextcloud-talk",
dmPolicy,
allowFrom,
};
return {
...cfg,
channels: {
...cfg.channels,
"nextcloud-talk": newNextcloudTalkConfig,
},
} as CoreConfig;
getAllowFrom: (inputCfg) =>
(inputCfg.channels?.["nextcloud-talk"]?.allowFrom ?? []).map((entry) => String(entry)),
}) as CoreConfig;
}
function setNextcloudTalkAccountConfig(

View File

@@ -6,13 +6,13 @@ import type {
WizardPrompter,
} from "openclaw/plugin-sdk/zalo";
import {
addWildcardAllowFrom,
DEFAULT_ACCOUNT_ID,
hasConfiguredSecretInput,
mergeAllowFromEntries,
normalizeAccountId,
promptSingleChannelSecretInput,
resolveAccountIdForConfigure,
setTopLevelChannelDmPolicyWithAllowFrom,
} from "openclaw/plugin-sdk/zalo";
import { listZaloAccountIds, resolveDefaultZaloAccountId, resolveZaloAccount } from "./accounts.js";
@@ -24,19 +24,11 @@ function setZaloDmPolicy(
cfg: OpenClawConfig,
dmPolicy: "pairing" | "allowlist" | "open" | "disabled",
) {
const allowFrom =
dmPolicy === "open" ? addWildcardAllowFrom(cfg.channels?.zalo?.allowFrom) : undefined;
return {
...cfg,
channels: {
...cfg.channels,
zalo: {
...cfg.channels?.zalo,
dmPolicy,
...(allowFrom ? { allowFrom } : {}),
},
},
} as OpenClawConfig;
return setTopLevelChannelDmPolicyWithAllowFrom({
cfg,
channel: "zalo",
dmPolicy,
}) as OpenClawConfig;
}
function setZaloUpdateMode(

View File

@@ -5,13 +5,13 @@ import type {
WizardPrompter,
} from "openclaw/plugin-sdk/zalouser";
import {
addWildcardAllowFrom,
DEFAULT_ACCOUNT_ID,
formatResolvedUnresolvedNote,
mergeAllowFromEntries,
normalizeAccountId,
promptChannelAccessConfig,
resolveAccountIdForConfigure,
setTopLevelChannelDmPolicyWithAllowFrom,
} from "openclaw/plugin-sdk/zalouser";
import {
listZalouserAccountIds,
@@ -73,19 +73,11 @@ function setZalouserDmPolicy(
cfg: OpenClawConfig,
dmPolicy: "pairing" | "allowlist" | "open" | "disabled",
): OpenClawConfig {
const allowFrom =
dmPolicy === "open" ? addWildcardAllowFrom(cfg.channels?.zalouser?.allowFrom) : undefined;
return {
...cfg,
channels: {
...cfg.channels,
zalouser: {
...cfg.channels?.zalouser,
dmPolicy,
...(allowFrom ? { allowFrom } : {}),
},
},
} as OpenClawConfig;
return setTopLevelChannelDmPolicyWithAllowFrom({
cfg,
channel: "zalouser",
dmPolicy,
}) as OpenClawConfig;
}
async function noteZalouserHelp(prompter: WizardPrompter): Promise<void> {