fix: honor whatsapp default setup status account

This commit is contained in:
Tak Hoffman
2026-04-03 14:34:36 -05:00
parent 6f8f2a012b
commit aa983566c4
2 changed files with 40 additions and 16 deletions

View File

@@ -216,6 +216,40 @@ describe("whatsapp setup wizard", () => {
expect(status.statusLines).toEqual(["WhatsApp (work): not linked"]);
});
it("uses configured defaultAccount for omitted-account setup status", async () => {
hoisted.detectWhatsAppLinked.mockImplementation(async (_cfg, accountId) => accountId === "work");
const status = await whatsappGetStatus({
cfg: {
channels: {
whatsapp: {
defaultAccount: "work",
accounts: {
default: {
authDir: "/tmp/default",
},
work: {
authDir: "/tmp/work",
},
},
},
},
} as OpenClawConfig,
accountOverrides: {},
});
expect(status.configured).toBe(true);
expect(status.statusLines).toEqual(["WhatsApp (work): linked"]);
expect(hoisted.detectWhatsAppLinked).toHaveBeenCalledWith(
expect.any(Object),
"work",
);
expect(hoisted.detectWhatsAppLinked).not.toHaveBeenCalledWith(
expect.any(Object),
DEFAULT_ACCOUNT_ID,
);
});
it("normalizes allowFrom entries when list mode is selected", async () => {
const { result } = await runSeparatePhoneFlow({
selectValues: ["separate", "allowlist", "list"],

View File

@@ -5,7 +5,7 @@ import {
} from "openclaw/plugin-sdk/setup";
import type { ChannelSetupWizard } from "openclaw/plugin-sdk/setup";
import { formatDocsLink } from "openclaw/plugin-sdk/setup-tools";
import { listWhatsAppAccountIds } from "./accounts.js";
import { listWhatsAppAccountIds, resolveDefaultWhatsAppAccountId } from "./accounts.js";
import { detectWhatsAppLinked, finalizeWhatsAppSetup } from "./setup-finalize.js";
const channel = "whatsapp" as const;
@@ -20,23 +20,13 @@ export const whatsappSetupWizard: ChannelSetupWizard = {
configuredScore: 5,
unconfiguredScore: 4,
resolveConfigured: async ({ cfg, accountId }) => {
for (const resolvedAccountId of accountId ? [accountId] : listWhatsAppAccountIds(cfg)) {
if (await detectWhatsAppLinked(cfg, resolvedAccountId)) {
return true;
}
}
return false;
return await detectWhatsAppLinked(
cfg,
accountId || resolveDefaultWhatsAppAccountId(cfg),
);
},
resolveStatusLines: async ({ cfg, accountId, configured }) => {
const linkedAccountId = (
await Promise.all(
(accountId ? [accountId] : listWhatsAppAccountIds(cfg)).map(async (resolvedAccountId) => ({
accountId: resolvedAccountId,
linked: await detectWhatsAppLinked(cfg, resolvedAccountId),
})),
)
).find((entry) => entry.linked)?.accountId;
const labelAccountId = accountId ?? linkedAccountId;
const labelAccountId = accountId || resolveDefaultWhatsAppAccountId(cfg);
const label = labelAccountId
? `WhatsApp (${labelAccountId === DEFAULT_ACCOUNT_ID ? "default" : labelAccountId})`
: "WhatsApp";