mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 20:34:31 +00:00
refactor(onboarding): dedupe WhatsApp owner allowlist
This commit is contained in:
@@ -79,6 +79,27 @@ async function promptWhatsAppOwnerAllowFrom(params: {
|
|||||||
return { normalized, allowFrom };
|
return { normalized, allowFrom };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function applyWhatsAppOwnerAllowlist(params: {
|
||||||
|
cfg: OpenClawConfig;
|
||||||
|
prompter: WizardPrompter;
|
||||||
|
existingAllowFrom: string[];
|
||||||
|
title: string;
|
||||||
|
messageLines: string[];
|
||||||
|
}): Promise<OpenClawConfig> {
|
||||||
|
const { normalized, allowFrom } = await promptWhatsAppOwnerAllowFrom({
|
||||||
|
prompter: params.prompter,
|
||||||
|
existingAllowFrom: params.existingAllowFrom,
|
||||||
|
});
|
||||||
|
let next = setWhatsAppSelfChatMode(params.cfg, true);
|
||||||
|
next = setWhatsAppDmPolicy(next, "allowlist");
|
||||||
|
next = setWhatsAppAllowFrom(next, allowFrom);
|
||||||
|
await params.prompter.note(
|
||||||
|
[...params.messageLines, `- allowFrom includes ${normalized}`].join("\n"),
|
||||||
|
params.title,
|
||||||
|
);
|
||||||
|
return next;
|
||||||
|
}
|
||||||
|
|
||||||
async function promptWhatsAppAllowFrom(
|
async function promptWhatsAppAllowFrom(
|
||||||
cfg: OpenClawConfig,
|
cfg: OpenClawConfig,
|
||||||
_runtime: RuntimeEnv,
|
_runtime: RuntimeEnv,
|
||||||
@@ -90,18 +111,13 @@ async function promptWhatsAppAllowFrom(
|
|||||||
const existingLabel = existingAllowFrom.length > 0 ? existingAllowFrom.join(", ") : "unset";
|
const existingLabel = existingAllowFrom.length > 0 ? existingAllowFrom.join(", ") : "unset";
|
||||||
|
|
||||||
if (options?.forceAllowlist) {
|
if (options?.forceAllowlist) {
|
||||||
const { normalized, allowFrom } = await promptWhatsAppOwnerAllowFrom({
|
return await applyWhatsAppOwnerAllowlist({
|
||||||
|
cfg,
|
||||||
prompter,
|
prompter,
|
||||||
existingAllowFrom,
|
existingAllowFrom,
|
||||||
|
title: "WhatsApp allowlist",
|
||||||
|
messageLines: ["Allowlist mode enabled."],
|
||||||
});
|
});
|
||||||
let next = setWhatsAppSelfChatMode(cfg, true);
|
|
||||||
next = setWhatsAppDmPolicy(next, "allowlist");
|
|
||||||
next = setWhatsAppAllowFrom(next, allowFrom);
|
|
||||||
await prompter.note(
|
|
||||||
["Allowlist mode enabled.", `- allowFrom includes ${normalized}`].join("\n"),
|
|
||||||
"WhatsApp allowlist",
|
|
||||||
);
|
|
||||||
return next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await prompter.note(
|
await prompter.note(
|
||||||
@@ -127,22 +143,16 @@ async function promptWhatsAppAllowFrom(
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (phoneMode === "personal") {
|
if (phoneMode === "personal") {
|
||||||
const { normalized, allowFrom } = await promptWhatsAppOwnerAllowFrom({
|
return await applyWhatsAppOwnerAllowlist({
|
||||||
|
cfg,
|
||||||
prompter,
|
prompter,
|
||||||
existingAllowFrom,
|
existingAllowFrom,
|
||||||
});
|
title: "WhatsApp personal phone",
|
||||||
let next = setWhatsAppSelfChatMode(cfg, true);
|
messageLines: [
|
||||||
next = setWhatsAppDmPolicy(next, "allowlist");
|
|
||||||
next = setWhatsAppAllowFrom(next, allowFrom);
|
|
||||||
await prompter.note(
|
|
||||||
[
|
|
||||||
"Personal phone mode enabled.",
|
"Personal phone mode enabled.",
|
||||||
"- dmPolicy set to allowlist (pairing skipped)",
|
"- dmPolicy set to allowlist (pairing skipped)",
|
||||||
`- allowFrom includes ${normalized}`,
|
],
|
||||||
].join("\n"),
|
});
|
||||||
"WhatsApp personal phone",
|
|
||||||
);
|
|
||||||
return next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const policy = (await prompter.select({
|
const policy = (await prompter.select({
|
||||||
|
|||||||
Reference in New Issue
Block a user