From 067509fa44d7d405937e2b72110f2a697f8ba85d Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 16 Feb 2026 01:05:27 +0000 Subject: [PATCH] refactor(onboarding): dedupe WhatsApp owner allowlist --- src/channels/plugins/onboarding/whatsapp.ts | 52 ++++++++++++--------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/src/channels/plugins/onboarding/whatsapp.ts b/src/channels/plugins/onboarding/whatsapp.ts index 3a140ee49..e640c8a39 100644 --- a/src/channels/plugins/onboarding/whatsapp.ts +++ b/src/channels/plugins/onboarding/whatsapp.ts @@ -79,6 +79,27 @@ async function promptWhatsAppOwnerAllowFrom(params: { return { normalized, allowFrom }; } +async function applyWhatsAppOwnerAllowlist(params: { + cfg: OpenClawConfig; + prompter: WizardPrompter; + existingAllowFrom: string[]; + title: string; + messageLines: string[]; +}): Promise { + 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( cfg: OpenClawConfig, _runtime: RuntimeEnv, @@ -90,18 +111,13 @@ async function promptWhatsAppAllowFrom( const existingLabel = existingAllowFrom.length > 0 ? existingAllowFrom.join(", ") : "unset"; if (options?.forceAllowlist) { - const { normalized, allowFrom } = await promptWhatsAppOwnerAllowFrom({ + return await applyWhatsAppOwnerAllowlist({ + cfg, prompter, 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( @@ -127,22 +143,16 @@ async function promptWhatsAppAllowFrom( }); if (phoneMode === "personal") { - const { normalized, allowFrom } = await promptWhatsAppOwnerAllowFrom({ + return await applyWhatsAppOwnerAllowlist({ + cfg, prompter, existingAllowFrom, - }); - let next = setWhatsAppSelfChatMode(cfg, true); - next = setWhatsAppDmPolicy(next, "allowlist"); - next = setWhatsAppAllowFrom(next, allowFrom); - await prompter.note( - [ + title: "WhatsApp personal phone", + messageLines: [ "Personal phone mode enabled.", "- dmPolicy set to allowlist (pairing skipped)", - `- allowFrom includes ${normalized}`, - ].join("\n"), - "WhatsApp personal phone", - ); - return next; + ], + }); } const policy = (await prompter.select({