mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-23 16:01:17 +00:00
Matrix: scope onboarding config to selected account
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user