fix: honor whatsapp default heartbeat account

This commit is contained in:
Tak Hoffman
2026-04-03 14:42:31 -05:00
parent 2247089381
commit 314512ae14
3 changed files with 32 additions and 4 deletions

View File

@@ -3,6 +3,7 @@ import type { RuntimeEnv } from "openclaw/plugin-sdk/runtime-env";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { createQueuedWizardPrompter } from "../../../test/helpers/plugins/setup-wizard.js";
import type { OpenClawConfig } from "./runtime-api.js";
import { whatsappPlugin } from "./channel.js";
import { finalizeWhatsAppSetup } from "./setup-finalize.js";
const hoisted = vi.hoisted(() => ({
@@ -17,7 +18,10 @@ vi.mock("./login.js", () => ({
loginWeb: hoisted.loginWeb,
}));
vi.mock("openclaw/plugin-sdk/setup", () => {
vi.mock("openclaw/plugin-sdk/setup", async () => {
const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/setup")>(
"openclaw/plugin-sdk/setup",
);
const normalizeE164 = (value?: string | null) => {
const raw = `${value ?? ""}`.trim();
if (!raw) {
@@ -27,6 +31,7 @@ vi.mock("openclaw/plugin-sdk/setup", () => {
return digits.startsWith("+") ? digits : `+${digits}`;
};
return {
...actual,
DEFAULT_ACCOUNT_ID,
normalizeAccountId: (value?: string | null) => value?.trim() || DEFAULT_ACCOUNT_ID,
normalizeAllowFromEntries: (entries: string[], normalize: (value: string) => string) => [
@@ -248,4 +253,27 @@ describe("whatsapp setup wizard", () => {
"WhatsApp",
);
});
it("heartbeat readiness uses configured defaultAccount for active listener checks", async () => {
const result = await whatsappPlugin.heartbeat?.checkReady?.({
cfg: {
channels: {
whatsapp: {
defaultAccount: "work",
accounts: {
work: {
authDir: "/tmp/work",
},
},
},
},
} as OpenClawConfig,
deps: {
webAuthExists: async () => true,
hasActiveWebListener: (accountId?: string) => accountId === "work",
},
});
expect(result).toEqual({ ok: true, reason: "ok" });
});
});

View File

@@ -158,8 +158,8 @@ export const whatsappPlugin: ChannelPlugin<ResolvedWhatsAppAccount> =
return { ok: false, reason: "whatsapp-not-linked" };
}
const listenerActive = deps?.hasActiveWebListener
? deps.hasActiveWebListener()
: Boolean((await loadWhatsAppChannelRuntime()).getActiveWebListener());
? deps.hasActiveWebListener(account.accountId)
: Boolean((await loadWhatsAppChannelRuntime()).getActiveWebListener(account.accountId));
if (!listenerActive) {
return { ok: false, reason: "whatsapp-not-running" };
}

View File

@@ -117,7 +117,7 @@ export type ChannelAccountState =
export type ChannelHeartbeatDeps = {
webAuthExists?: () => Promise<boolean>;
hasActiveWebListener?: () => boolean;
hasActiveWebListener?: (accountId?: string) => boolean;
};
/** User-facing metadata used in docs, pickers, and setup surfaces. */