fix: honor whatsapp default setup finalize account

This commit is contained in:
Tak Hoffman 2026-04-03 14:55:27 -05:00
parent f8a0f9ffd3
commit d44af743db
No known key found for this signature in database
2 changed files with 51 additions and 7 deletions

View File

@ -10,7 +10,11 @@ import {
} from "openclaw/plugin-sdk/setup";
import type { ChannelSetupWizard } from "openclaw/plugin-sdk/setup";
import { formatCliCommand, formatDocsLink } from "openclaw/plugin-sdk/setup-tools";
import { resolveWhatsAppAccount, resolveWhatsAppAuthDir } from "./accounts.js";
import {
resolveDefaultWhatsAppAccountId,
resolveWhatsAppAccount,
resolveWhatsAppAuthDir,
} from "./accounts.js";
import { loginWeb } from "./login.js";
import { whatsappSetupAdapter } from "./setup-core.js";
@ -333,19 +337,20 @@ export async function finalizeWhatsAppSetup(params: {
prompter: SetupPrompter;
runtime: SetupRuntime;
}) {
const accountId = params.accountId.trim() || resolveDefaultWhatsAppAccountId(params.cfg);
let next =
params.accountId === DEFAULT_ACCOUNT_ID
accountId === DEFAULT_ACCOUNT_ID
? params.cfg
: whatsappSetupAdapter.applyAccountConfig({
cfg: params.cfg,
accountId: params.accountId,
accountId,
input: {},
});
const linked = await detectWhatsAppLinked(next, params.accountId);
const linked = await detectWhatsAppLinked(next, accountId);
const { authDir } = resolveWhatsAppAuthDir({
cfg: next,
accountId: params.accountId,
accountId,
});
if (!linked) {
@ -365,7 +370,7 @@ export async function finalizeWhatsAppSetup(params: {
});
if (wantsLink) {
try {
await loginWeb(false, undefined, params.runtime, params.accountId);
await loginWeb(false, undefined, params.runtime, accountId);
} catch (error) {
params.runtime.error(`WhatsApp login failed: ${String(error)}`);
await params.prompter.note(
@ -382,7 +387,7 @@ export async function finalizeWhatsAppSetup(params: {
next = await promptWhatsAppDmAccess({
cfg: next,
accountId: params.accountId,
accountId,
forceAllowFrom: params.forceAllowFrom,
prompter: params.prompter,
});

View File

@ -248,6 +248,45 @@ describe("whatsapp setup wizard", () => {
);
});
it("uses configured defaultAccount for omitted-account finalize writes", async () => {
hoisted.pathExists.mockResolvedValue(true);
const harness = createSeparatePhoneHarness({
selectValues: ["separate", "open"],
});
const result = expectFinalizeResult(
await runFinalizeWithHarness({
harness,
accountId: "",
cfg: {
channels: {
whatsapp: {
defaultAccount: "work",
dmPolicy: "disabled",
allowFrom: ["+15555550123"],
accounts: {
work: {
authDir: "/tmp/work",
},
},
},
},
},
}),
);
expect(result.cfg.channels?.whatsapp?.dmPolicy).toBe("disabled");
expect(result.cfg.channels?.whatsapp?.allowFrom).toEqual(["+15555550123"]);
expect(result.cfg.channels?.whatsapp?.accounts?.work?.dmPolicy).toBe("open");
expect(result.cfg.channels?.whatsapp?.accounts?.work?.allowFrom).toEqual(["*", "+15555550123"]);
expect(harness.note).toHaveBeenCalledWith(
expect.stringContaining(
"`channels.whatsapp.accounts.work.dmPolicy` + `channels.whatsapp.accounts.work.allowFrom`",
),
"WhatsApp DM access",
);
});
it("normalizes allowFrom entries when list mode is selected", async () => {
const { result } = await runSeparatePhoneFlow({
selectValues: ["separate", "allowlist", "list"],