Matrix: scope onboarding config to selected account

This commit is contained in:
Gustavo Madeira Santana
2026-03-09 04:56:16 -04:00
parent 5fcc468b7e
commit 02ffd358b6
6 changed files with 314 additions and 80 deletions

View File

@@ -75,8 +75,8 @@ export type ChannelOnboardingDmPolicy = {
channel: ChannelId;
policyKey: string;
allowFromKey: string;
getCurrent: (cfg: OpenClawConfig) => DmPolicy;
setPolicy: (cfg: OpenClawConfig, policy: DmPolicy) => OpenClawConfig;
getCurrent: (cfg: OpenClawConfig, accountId?: string) => DmPolicy;
setPolicy: (cfg: OpenClawConfig, policy: DmPolicy, accountId?: string) => OpenClawConfig;
promptAllowFrom?: (params: {
cfg: OpenClawConfig;
prompter: WizardPrompter;

View File

@@ -246,6 +246,7 @@ async function maybeConfigureDmPolicies(params: {
let cfg = params.cfg;
const selectPolicy = async (policy: ChannelOnboardingDmPolicy) => {
const accountId = accountIdsByChannel?.get(policy.channel);
await prompter.note(
[
"Default: pairing (unknown DMs get a pairing code).",
@@ -259,28 +260,31 @@ async function maybeConfigureDmPolicies(params: {
].join("\n"),
`${policy.label} DM access`,
);
return (await prompter.select({
message: `${policy.label} DM policy`,
options: [
{ value: "pairing", label: "Pairing (recommended)" },
{ value: "allowlist", label: "Allowlist (specific users only)" },
{ value: "open", label: "Open (public inbound DMs)" },
{ value: "disabled", label: "Disabled (ignore DMs)" },
],
})) as DmPolicy;
return {
accountId,
nextPolicy: (await prompter.select({
message: `${policy.label} DM policy`,
options: [
{ value: "pairing", label: "Pairing (recommended)" },
{ value: "allowlist", label: "Allowlist (specific users only)" },
{ value: "open", label: "Open (public inbound DMs)" },
{ value: "disabled", label: "Disabled (ignore DMs)" },
],
})) as DmPolicy,
};
};
for (const policy of dmPolicies) {
const current = policy.getCurrent(cfg);
const nextPolicy = await selectPolicy(policy);
const { accountId, nextPolicy } = await selectPolicy(policy);
const current = policy.getCurrent(cfg, accountId);
if (nextPolicy !== current) {
cfg = policy.setPolicy(cfg, nextPolicy);
cfg = policy.setPolicy(cfg, nextPolicy, accountId);
}
if (nextPolicy === "allowlist" && policy.promptAllowFrom) {
cfg = await policy.promptAllowFrom({
cfg,
prompter,
accountId: accountIdsByChannel?.get(policy.channel),
accountId,
});
}
}