@openclaw/whatsapp 2026.5.1-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/action-runtime-api.ts +1 -0
- package/action-runtime.runtime.ts +1 -0
- package/api.ts +213 -0
- package/auth-presence.ts +80 -0
- package/channel-config-api.ts +1 -0
- package/channel-plugin-api.ts +3 -0
- package/config-api.ts +4 -0
- package/constants.ts +1 -0
- package/contract-api.ts +29 -0
- package/directory-contract-api.ts +4 -0
- package/dist/.boundary-tsc.stamp +1 -0
- package/dist/.boundary-tsc.tsbuildinfo +1 -0
- package/doctor-contract-api.ts +8 -0
- package/index.test.ts +13 -0
- package/index.ts +16 -0
- package/legacy-session-surface-api.ts +6 -0
- package/legacy-state-migrations-api.ts +1 -0
- package/light-runtime-api.ts +12 -0
- package/login-qr-api.ts +1 -0
- package/login-qr-runtime.ts +23 -0
- package/openclaw.plugin.json +742 -0
- package/outbound-payload-test-api.ts +1 -0
- package/package.json +74 -0
- package/runtime-api.ts +86 -0
- package/secret-contract-api.ts +4 -0
- package/security-contract-api.ts +4 -0
- package/setup-entry.test.ts +21 -0
- package/setup-entry.ts +21 -0
- package/setup-plugin-api.ts +3 -0
- package/src/account-config.ts +77 -0
- package/src/account-ids.ts +13 -0
- package/src/account-types.ts +5 -0
- package/src/accounts.test.ts +182 -0
- package/src/accounts.ts +176 -0
- package/src/accounts.whatsapp-auth.test.ts +59 -0
- package/src/action-runtime-target-auth.ts +27 -0
- package/src/action-runtime.test.ts +330 -0
- package/src/action-runtime.ts +76 -0
- package/src/active-listener.test.ts +65 -0
- package/src/active-listener.ts +17 -0
- package/src/agent-tools-login.test.ts +81 -0
- package/src/agent-tools-login.ts +113 -0
- package/src/approval-auth.test.ts +24 -0
- package/src/approval-auth.ts +27 -0
- package/src/auth-store.runtime.ts +1 -0
- package/src/auth-store.test.ts +311 -0
- package/src/auth-store.ts +502 -0
- package/src/auto-reply/config.runtime.ts +16 -0
- package/src/auto-reply/constants.ts +1 -0
- package/src/auto-reply/deliver-reply.test.ts +843 -0
- package/src/auto-reply/deliver-reply.ts +279 -0
- package/src/auto-reply/heartbeat-runner.runtime.ts +33 -0
- package/src/auto-reply/heartbeat-runner.test.ts +214 -0
- package/src/auto-reply/heartbeat-runner.ts +330 -0
- package/src/auto-reply/loggers.ts +6 -0
- package/src/auto-reply/mentions.ts +131 -0
- package/src/auto-reply/monitor/ack-reaction.test.ts +170 -0
- package/src/auto-reply/monitor/ack-reaction.ts +99 -0
- package/src/auto-reply/monitor/audio-preflight.runtime.ts +9 -0
- package/src/auto-reply/monitor/broadcast.ts +153 -0
- package/src/auto-reply/monitor/commands.ts +19 -0
- package/src/auto-reply/monitor/echo.ts +64 -0
- package/src/auto-reply/monitor/group-activation.runtime.ts +1 -0
- package/src/auto-reply/monitor/group-activation.test.ts +189 -0
- package/src/auto-reply/monitor/group-activation.ts +73 -0
- package/src/auto-reply/monitor/group-gating.audio-preflight.test.ts +103 -0
- package/src/auto-reply/monitor/group-gating.runtime.ts +8 -0
- package/src/auto-reply/monitor/group-gating.ts +217 -0
- package/src/auto-reply/monitor/group-members.test.ts +56 -0
- package/src/auto-reply/monitor/group-members.ts +65 -0
- package/src/auto-reply/monitor/inbound-context.test.ts +97 -0
- package/src/auto-reply/monitor/inbound-context.ts +92 -0
- package/src/auto-reply/monitor/inbound-dispatch.runtime.ts +21 -0
- package/src/auto-reply/monitor/inbound-dispatch.test.ts +895 -0
- package/src/auto-reply/monitor/inbound-dispatch.ts +422 -0
- package/src/auto-reply/monitor/last-route.test.ts +37 -0
- package/src/auto-reply/monitor/last-route.ts +61 -0
- package/src/auto-reply/monitor/message-line.runtime.ts +38 -0
- package/src/auto-reply/monitor/message-line.ts +54 -0
- package/src/auto-reply/monitor/on-message.audio-preflight.test.ts +354 -0
- package/src/auto-reply/monitor/on-message.ts +291 -0
- package/src/auto-reply/monitor/peer.ts +17 -0
- package/src/auto-reply/monitor/process-message.audio-preflight.test.ts +420 -0
- package/src/auto-reply/monitor/process-message.test.ts +355 -0
- package/src/auto-reply/monitor/process-message.ts +531 -0
- package/src/auto-reply/monitor/runtime-api.ts +30 -0
- package/src/auto-reply/monitor-state.test.ts +64 -0
- package/src/auto-reply/monitor-state.ts +106 -0
- package/src/auto-reply/monitor.ts +600 -0
- package/src/auto-reply/reply-resolver.runtime.ts +1 -0
- package/src/auto-reply/session-snapshot.ts +69 -0
- package/src/auto-reply/types.ts +48 -0
- package/src/auto-reply/util.ts +63 -0
- package/src/auto-reply/web-auto-reply-monitor.test.ts +687 -0
- package/src/auto-reply/web-auto-reply-utils.test.ts +327 -0
- package/src/auto-reply.broadcast-groups.combined.test.ts +246 -0
- package/src/auto-reply.broadcast-groups.test-harness.ts +47 -0
- package/src/auto-reply.impl.ts +7 -0
- package/src/auto-reply.test-harness.ts +421 -0
- package/src/auto-reply.ts +1 -0
- package/src/auto-reply.web-auto-reply.compresses-common-formats-jpeg-cap.test.ts +427 -0
- package/src/auto-reply.web-auto-reply.connection-and-logging.e2e.test.ts +908 -0
- package/src/auto-reply.web-auto-reply.last-route.test.ts +184 -0
- package/src/channel-actions.runtime.ts +7 -0
- package/src/channel-actions.test.ts +216 -0
- package/src/channel-actions.ts +84 -0
- package/src/channel-outbound.test.ts +131 -0
- package/src/channel-outbound.ts +36 -0
- package/src/channel-react-action.runtime.ts +7 -0
- package/src/channel-react-action.test.ts +294 -0
- package/src/channel-react-action.ts +84 -0
- package/src/channel.runtime.ts +117 -0
- package/src/channel.setup.test.ts +461 -0
- package/src/channel.setup.ts +28 -0
- package/src/channel.ts +336 -0
- package/src/command-policy.ts +7 -0
- package/src/config-accessors.test.ts +34 -0
- package/src/config-accessors.ts +22 -0
- package/src/config-schema.test.ts +121 -0
- package/src/config-schema.ts +6 -0
- package/src/config-ui-hints.ts +24 -0
- package/src/connection-controller-registry.test.ts +27 -0
- package/src/connection-controller-registry.ts +49 -0
- package/src/connection-controller.test.ts +282 -0
- package/src/connection-controller.ts +679 -0
- package/src/creds-files.ts +19 -0
- package/src/creds-persistence.ts +102 -0
- package/src/directory-config.test.ts +60 -0
- package/src/directory-config.ts +40 -0
- package/src/directory-contract.test.ts +56 -0
- package/src/doctor-contract.ts +11 -0
- package/src/doctor.test.ts +74 -0
- package/src/doctor.ts +56 -0
- package/src/group-intro.ts +15 -0
- package/src/group-policy.test.ts +36 -0
- package/src/group-policy.ts +40 -0
- package/src/group-session-contract.ts +20 -0
- package/src/group-session-key.test.ts +53 -0
- package/src/group-session-key.ts +41 -0
- package/src/heartbeat-recipients.runtime.ts +6 -0
- package/src/heartbeat-recipients.test.ts +203 -0
- package/src/heartbeat-recipients.ts +104 -0
- package/src/heartbeat.ts +34 -0
- package/src/identity.ts +164 -0
- package/src/inbound/access-control.test-harness.ts +37 -0
- package/src/inbound/access-control.test.ts +375 -0
- package/src/inbound/access-control.ts +237 -0
- package/src/inbound/dedupe.ts +132 -0
- package/src/inbound/extract.test.ts +282 -0
- package/src/inbound/extract.ts +488 -0
- package/src/inbound/lifecycle.ts +39 -0
- package/src/inbound/media.node.test.ts +83 -0
- package/src/inbound/media.ts +102 -0
- package/src/inbound/monitor.ts +890 -0
- package/src/inbound/runtime-api.ts +7 -0
- package/src/inbound/save-media.runtime.ts +1 -0
- package/src/inbound/send-api.test.ts +307 -0
- package/src/inbound/send-api.ts +141 -0
- package/src/inbound/send-result.ts +61 -0
- package/src/inbound/types.ts +106 -0
- package/src/inbound-context.contract.test.ts +32 -0
- package/src/inbound-policy.ts +231 -0
- package/src/inbound.media.test.ts +320 -0
- package/src/inbound.test.ts +290 -0
- package/src/inbound.ts +9 -0
- package/src/login-qr.test.ts +483 -0
- package/src/login-qr.ts +542 -0
- package/src/login.coverage.test.ts +133 -0
- package/src/login.test.ts +89 -0
- package/src/login.ts +70 -0
- package/src/logout.test.ts +162 -0
- package/src/media.test.ts +480 -0
- package/src/media.ts +10 -0
- package/src/monitor-inbox.allows-messages-from-senders-allowfrom-list.test-support.ts +400 -0
- package/src/monitor-inbox.append-upsert.test-support.ts +133 -0
- package/src/monitor-inbox.behavior.test.ts +5 -0
- package/src/monitor-inbox.blocks-messages-from-unauthorized-senders-not-allowfrom.test-support.ts +362 -0
- package/src/monitor-inbox.captures-media-path-image-messages.test-support.ts +306 -0
- package/src/monitor-inbox.streams-inbound-messages.test-support.ts +729 -0
- package/src/monitor-inbox.test-harness.ts +304 -0
- package/src/normalize-target.ts +112 -0
- package/src/normalize.ts +6 -0
- package/src/outbound-adapter.poll.test.ts +62 -0
- package/src/outbound-adapter.sendpayload.test.ts +195 -0
- package/src/outbound-adapter.ts +36 -0
- package/src/outbound-base.test.ts +560 -0
- package/src/outbound-base.ts +244 -0
- package/src/outbound-media-contract.ts +278 -0
- package/src/outbound-media.runtime.ts +36 -0
- package/src/outbound-payload.contract.test.ts +61 -0
- package/src/outbound-send-deps.ts +1 -0
- package/src/outbound-test-support.ts +16 -0
- package/src/pairing-security.test-harness.ts +59 -0
- package/src/qr-image.ts +1 -0
- package/src/qr-terminal.ts +1 -0
- package/src/quoted-message.test.ts +83 -0
- package/src/quoted-message.ts +184 -0
- package/src/reaction-level.test.ts +94 -0
- package/src/reaction-level.ts +21 -0
- package/src/reconnect.test.ts +51 -0
- package/src/reconnect.ts +55 -0
- package/src/resolve-outbound-target.test.ts +265 -0
- package/src/resolve-outbound-target.ts +54 -0
- package/src/resolve-target.test.ts +97 -0
- package/src/runtime-api.ts +60 -0
- package/src/runtime-group-policy.ts +16 -0
- package/src/runtime.ts +9 -0
- package/src/security-contract.ts +47 -0
- package/src/security-fix.ts +71 -0
- package/src/send.test.ts +515 -0
- package/src/send.ts +287 -0
- package/src/session-contract.test.ts +31 -0
- package/src/session-contract.ts +43 -0
- package/src/session-errors.ts +125 -0
- package/src/session-route.ts +26 -0
- package/src/session.runtime.ts +8 -0
- package/src/session.test.ts +559 -0
- package/src/session.ts +330 -0
- package/src/setup-core.ts +52 -0
- package/src/setup-finalize.ts +446 -0
- package/src/setup-surface.test.ts +367 -0
- package/src/setup-surface.ts +69 -0
- package/src/setup-test-helpers.ts +216 -0
- package/src/shared.ts +291 -0
- package/src/socket-timing.test.ts +49 -0
- package/src/socket-timing.ts +38 -0
- package/src/state-migrations.ts +54 -0
- package/src/status-issues.test.ts +137 -0
- package/src/status-issues.ts +185 -0
- package/src/system-prompt.test.ts +199 -0
- package/src/system-prompt.ts +31 -0
- package/src/targets-runtime.ts +180 -0
- package/src/test-helpers.ts +690 -0
- package/src/text-runtime.test.ts +162 -0
- package/src/text-runtime.ts +11 -0
- package/src/vcard.ts +84 -0
- package/targets.ts +5 -0
- package/test-api.ts +2 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
import { createQueuedWizardPrompter } from "openclaw/plugin-sdk/plugin-test-runtime";
|
|
2
|
+
import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk/routing";
|
|
3
|
+
import type { RuntimeEnv } from "openclaw/plugin-sdk/runtime-env";
|
|
4
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
5
|
+
import { WHATSAPP_AUTH_UNSTABLE_CODE } from "./auth-store.js";
|
|
6
|
+
import { whatsappSetupPlugin } from "./channel.setup.js";
|
|
7
|
+
import { checkWhatsAppHeartbeatReady } from "./heartbeat.js";
|
|
8
|
+
import type { OpenClawConfig } from "./runtime-api.js";
|
|
9
|
+
import { finalizeWhatsAppSetup } from "./setup-finalize.js";
|
|
10
|
+
import {
|
|
11
|
+
createWhatsAppAllowlistModeInput,
|
|
12
|
+
expectWhatsAppDefaultAccountAccessNote,
|
|
13
|
+
createWhatsAppLinkingHarness,
|
|
14
|
+
createWhatsAppOwnerAllowlistHarness,
|
|
15
|
+
createWhatsAppPersonalPhoneHarness,
|
|
16
|
+
createWhatsAppRootAllowFromConfig,
|
|
17
|
+
expectNoWhatsAppLoginFollowup,
|
|
18
|
+
expectWhatsAppAllowlistModeSetup,
|
|
19
|
+
expectWhatsAppLoginFollowup,
|
|
20
|
+
expectWhatsAppOpenPolicySetup,
|
|
21
|
+
expectWhatsAppOwnerAllowlistSetup,
|
|
22
|
+
expectWhatsAppPersonalPhoneSetup,
|
|
23
|
+
expectWhatsAppSeparatePhoneDisabledSetup,
|
|
24
|
+
} from "./setup-test-helpers.js";
|
|
25
|
+
|
|
26
|
+
const hoisted = vi.hoisted(() => ({
|
|
27
|
+
loginWeb: vi.fn(async () => {}),
|
|
28
|
+
pathExists: vi.fn(async () => false),
|
|
29
|
+
readWebAuthState: vi.fn(async (): Promise<"linked" | "not-linked" | "unstable"> => "not-linked"),
|
|
30
|
+
readWebAuthExistsForDecision: vi.fn(
|
|
31
|
+
async (): Promise<{ outcome: "stable"; exists: boolean } | { outcome: "unstable" }> => ({
|
|
32
|
+
outcome: "stable",
|
|
33
|
+
exists: false,
|
|
34
|
+
}),
|
|
35
|
+
),
|
|
36
|
+
resolveWhatsAppAuthDir: vi.fn(() => ({
|
|
37
|
+
authDir: "/tmp/openclaw-whatsapp-test",
|
|
38
|
+
})),
|
|
39
|
+
}));
|
|
40
|
+
|
|
41
|
+
vi.mock("./login.js", () => ({
|
|
42
|
+
loginWeb: hoisted.loginWeb,
|
|
43
|
+
}));
|
|
44
|
+
|
|
45
|
+
vi.mock("openclaw/plugin-sdk/setup", async () => {
|
|
46
|
+
const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/setup")>(
|
|
47
|
+
"openclaw/plugin-sdk/setup",
|
|
48
|
+
);
|
|
49
|
+
const normalizeE164 = (value?: string | null) => {
|
|
50
|
+
const raw = (value ?? "").trim();
|
|
51
|
+
if (!raw) {
|
|
52
|
+
return "";
|
|
53
|
+
}
|
|
54
|
+
const digits = raw.replace(/[^\d+]/g, "");
|
|
55
|
+
return digits.startsWith("+") ? digits : `+${digits}`;
|
|
56
|
+
};
|
|
57
|
+
return {
|
|
58
|
+
...actual,
|
|
59
|
+
DEFAULT_ACCOUNT_ID,
|
|
60
|
+
normalizeAccountId: (value?: string | null) => value?.trim() || DEFAULT_ACCOUNT_ID,
|
|
61
|
+
normalizeAllowFromEntries: (entries: string[], normalize: (value: string) => string) => [
|
|
62
|
+
...new Set(entries.map((entry) => (entry === "*" ? "*" : normalize(entry))).filter(Boolean)),
|
|
63
|
+
],
|
|
64
|
+
normalizeE164,
|
|
65
|
+
pathExists: hoisted.pathExists,
|
|
66
|
+
splitSetupEntries: (raw: string) =>
|
|
67
|
+
raw
|
|
68
|
+
.split(",")
|
|
69
|
+
.map((entry) => entry.trim())
|
|
70
|
+
.filter(Boolean),
|
|
71
|
+
setSetupChannelEnabled: (cfg: OpenClawConfig, channel: string, enabled: boolean) => ({
|
|
72
|
+
...cfg,
|
|
73
|
+
channels: {
|
|
74
|
+
...cfg.channels,
|
|
75
|
+
[channel]: {
|
|
76
|
+
...(cfg.channels?.[channel as keyof NonNullable<OpenClawConfig["channels"]>] as object),
|
|
77
|
+
enabled,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
}),
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
vi.mock("./accounts.js", async () => {
|
|
85
|
+
const actual = await vi.importActual<typeof import("./accounts.js")>("./accounts.js");
|
|
86
|
+
return {
|
|
87
|
+
...actual,
|
|
88
|
+
resolveWhatsAppAuthDir: hoisted.resolveWhatsAppAuthDir,
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
vi.mock("./auth-store.js", async () => {
|
|
93
|
+
const actual = await vi.importActual<typeof import("./auth-store.js")>("./auth-store.js");
|
|
94
|
+
return {
|
|
95
|
+
...actual,
|
|
96
|
+
readWebAuthState: hoisted.readWebAuthState,
|
|
97
|
+
readWebAuthExistsForDecision: hoisted.readWebAuthExistsForDecision,
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
function createRuntime(): RuntimeEnv {
|
|
102
|
+
return {
|
|
103
|
+
error: vi.fn(),
|
|
104
|
+
} as unknown as RuntimeEnv;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async function runConfigureWithHarness(params: {
|
|
108
|
+
harness: ReturnType<typeof createQueuedWizardPrompter>;
|
|
109
|
+
cfg?: OpenClawConfig;
|
|
110
|
+
runtime?: RuntimeEnv;
|
|
111
|
+
forceAllowFrom?: boolean;
|
|
112
|
+
}) {
|
|
113
|
+
const result = await finalizeWhatsAppSetup({
|
|
114
|
+
cfg: params.cfg ?? ({} as OpenClawConfig),
|
|
115
|
+
accountId: DEFAULT_ACCOUNT_ID,
|
|
116
|
+
forceAllowFrom: params.forceAllowFrom ?? false,
|
|
117
|
+
prompter: params.harness.prompter,
|
|
118
|
+
runtime: params.runtime ?? createRuntime(),
|
|
119
|
+
});
|
|
120
|
+
return {
|
|
121
|
+
accountId: DEFAULT_ACCOUNT_ID,
|
|
122
|
+
cfg: result.cfg,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function createSeparatePhoneHarness(params: { selectValues: string[]; textValues?: string[] }) {
|
|
127
|
+
return createQueuedWizardPrompter({
|
|
128
|
+
confirmValues: [false],
|
|
129
|
+
selectValues: params.selectValues,
|
|
130
|
+
textValues: params.textValues,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async function runSeparatePhoneFlow(params: { selectValues: string[]; textValues?: string[] }) {
|
|
135
|
+
hoisted.pathExists.mockResolvedValue(true);
|
|
136
|
+
const harness = createSeparatePhoneHarness({
|
|
137
|
+
selectValues: params.selectValues,
|
|
138
|
+
textValues: params.textValues,
|
|
139
|
+
});
|
|
140
|
+
const result = await runConfigureWithHarness({
|
|
141
|
+
harness,
|
|
142
|
+
});
|
|
143
|
+
return { harness, result };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
describe("whatsapp setup wizard", () => {
|
|
147
|
+
beforeEach(() => {
|
|
148
|
+
hoisted.loginWeb.mockReset();
|
|
149
|
+
hoisted.pathExists.mockReset();
|
|
150
|
+
hoisted.pathExists.mockResolvedValue(false);
|
|
151
|
+
hoisted.readWebAuthState.mockReset();
|
|
152
|
+
hoisted.readWebAuthState.mockResolvedValue("not-linked");
|
|
153
|
+
hoisted.readWebAuthExistsForDecision.mockReset();
|
|
154
|
+
hoisted.readWebAuthExistsForDecision.mockResolvedValue({
|
|
155
|
+
outcome: "stable",
|
|
156
|
+
exists: false,
|
|
157
|
+
});
|
|
158
|
+
hoisted.resolveWhatsAppAuthDir.mockReset();
|
|
159
|
+
hoisted.resolveWhatsAppAuthDir.mockReturnValue({ authDir: "/tmp/openclaw-whatsapp-test" });
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("applies owner allowlist when forceAllowFrom is enabled", async () => {
|
|
163
|
+
const harness = createWhatsAppOwnerAllowlistHarness(createQueuedWizardPrompter);
|
|
164
|
+
|
|
165
|
+
const result = await runConfigureWithHarness({
|
|
166
|
+
harness,
|
|
167
|
+
forceAllowFrom: true,
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
expect(result.accountId).toBe(DEFAULT_ACCOUNT_ID);
|
|
171
|
+
expect(hoisted.loginWeb).not.toHaveBeenCalled();
|
|
172
|
+
expectWhatsAppOwnerAllowlistSetup(result.cfg, harness);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it("supports disabled DM policy for separate-phone setup", async () => {
|
|
176
|
+
const { harness, result } = await runSeparatePhoneFlow({
|
|
177
|
+
selectValues: ["separate", "disabled"],
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
expectWhatsAppSeparatePhoneDisabledSetup(result.cfg, harness);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it("normalizes allowFrom entries when list mode is selected", async () => {
|
|
184
|
+
const { result } = await runSeparatePhoneFlow(createWhatsAppAllowlistModeInput());
|
|
185
|
+
|
|
186
|
+
expectWhatsAppAllowlistModeSetup(result.cfg);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("throws a user-facing error instead of crashing when allowlist input is undefined", async () => {
|
|
190
|
+
const harness = createSeparatePhoneHarness({
|
|
191
|
+
selectValues: ["separate", "allowlist", "list"],
|
|
192
|
+
});
|
|
193
|
+
harness.text.mockResolvedValueOnce(undefined as never);
|
|
194
|
+
|
|
195
|
+
await expect(
|
|
196
|
+
runConfigureWithHarness({
|
|
197
|
+
harness,
|
|
198
|
+
}),
|
|
199
|
+
).rejects.toThrow("Invalid WhatsApp allowFrom list");
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("enables allowlist self-chat mode for personal-phone setup", async () => {
|
|
203
|
+
hoisted.pathExists.mockResolvedValue(true);
|
|
204
|
+
const harness = createWhatsAppPersonalPhoneHarness(createQueuedWizardPrompter);
|
|
205
|
+
|
|
206
|
+
const result = await runConfigureWithHarness({
|
|
207
|
+
harness,
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
expectWhatsAppPersonalPhoneSetup(result.cfg);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it("throws a user-facing error instead of crashing when personal-phone input is undefined", async () => {
|
|
214
|
+
hoisted.pathExists.mockResolvedValue(true);
|
|
215
|
+
const harness = createWhatsAppPersonalPhoneHarness(createQueuedWizardPrompter);
|
|
216
|
+
harness.text.mockResolvedValueOnce(undefined as never);
|
|
217
|
+
|
|
218
|
+
await expect(
|
|
219
|
+
runConfigureWithHarness({
|
|
220
|
+
harness,
|
|
221
|
+
}),
|
|
222
|
+
).rejects.toThrow("Invalid WhatsApp owner number");
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it("forces wildcard allowFrom for open policy without allowFrom follow-up prompts", async () => {
|
|
226
|
+
hoisted.pathExists.mockResolvedValue(true);
|
|
227
|
+
const harness = createSeparatePhoneHarness({
|
|
228
|
+
selectValues: ["separate", "open"],
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
const result = await runConfigureWithHarness({
|
|
232
|
+
harness,
|
|
233
|
+
cfg: createWhatsAppRootAllowFromConfig() as OpenClawConfig,
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
expectWhatsAppOpenPolicySetup(result.cfg, harness);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it("surfaces accounts.default group warning paths for named accounts", () => {
|
|
240
|
+
const warnings = whatsappSetupPlugin.security?.collectWarnings?.({
|
|
241
|
+
cfg: {
|
|
242
|
+
channels: {
|
|
243
|
+
whatsapp: {
|
|
244
|
+
accounts: {
|
|
245
|
+
default: {
|
|
246
|
+
groupPolicy: "open",
|
|
247
|
+
},
|
|
248
|
+
work: {
|
|
249
|
+
authDir: "/tmp/work",
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
} as OpenClawConfig,
|
|
255
|
+
accountId: "work",
|
|
256
|
+
account: {
|
|
257
|
+
accountId: "work",
|
|
258
|
+
enabled: true,
|
|
259
|
+
sendReadReceipts: true,
|
|
260
|
+
authDir: "/tmp/work",
|
|
261
|
+
isLegacyAuthDir: false,
|
|
262
|
+
groupPolicy: "open",
|
|
263
|
+
},
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
expect(warnings).toEqual([
|
|
267
|
+
'- WhatsApp groups: groupPolicy="open" with no channels.whatsapp.accounts.default.groups allowlist; any group can add + ping (mention-gated). Set channels.whatsapp.accounts.default.groupPolicy="allowlist" + channels.whatsapp.accounts.default.groupAllowFrom or configure channels.whatsapp.accounts.default.groups.',
|
|
268
|
+
]);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it("surfaces mixed-case default-account group warning paths for named accounts", () => {
|
|
272
|
+
const warnings = whatsappSetupPlugin.security?.collectWarnings?.({
|
|
273
|
+
cfg: {
|
|
274
|
+
channels: {
|
|
275
|
+
whatsapp: {
|
|
276
|
+
accounts: {
|
|
277
|
+
Default: {
|
|
278
|
+
groupPolicy: "open",
|
|
279
|
+
},
|
|
280
|
+
work: {
|
|
281
|
+
authDir: "/tmp/work",
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
} as OpenClawConfig,
|
|
287
|
+
accountId: "work",
|
|
288
|
+
account: {
|
|
289
|
+
accountId: "work",
|
|
290
|
+
enabled: true,
|
|
291
|
+
sendReadReceipts: true,
|
|
292
|
+
authDir: "/tmp/work",
|
|
293
|
+
isLegacyAuthDir: false,
|
|
294
|
+
groupPolicy: "open",
|
|
295
|
+
},
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
expect(warnings).toEqual([
|
|
299
|
+
'- WhatsApp groups: groupPolicy="open" with no channels.whatsapp.accounts.Default.groups allowlist; any group can add + ping (mention-gated). Set channels.whatsapp.accounts.Default.groupPolicy="allowlist" + channels.whatsapp.accounts.Default.groupAllowFrom or configure channels.whatsapp.accounts.Default.groups.',
|
|
300
|
+
]);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it("writes default-account DM config into accounts.default for multi-account setups", async () => {
|
|
304
|
+
hoisted.pathExists.mockResolvedValue(true);
|
|
305
|
+
const harness = createSeparatePhoneHarness({
|
|
306
|
+
selectValues: ["separate", "open"],
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
const result = await runConfigureWithHarness({
|
|
310
|
+
harness,
|
|
311
|
+
cfg: {
|
|
312
|
+
channels: {
|
|
313
|
+
whatsapp: {
|
|
314
|
+
accounts: {
|
|
315
|
+
work: {
|
|
316
|
+
authDir: "/tmp/work",
|
|
317
|
+
},
|
|
318
|
+
},
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
} as OpenClawConfig,
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
expect(result.cfg.channels?.whatsapp?.dmPolicy).toBeUndefined();
|
|
325
|
+
expect(result.cfg.channels?.whatsapp?.allowFrom).toBeUndefined();
|
|
326
|
+
expect(result.cfg.channels?.whatsapp?.accounts?.default?.dmPolicy).toBe("open");
|
|
327
|
+
expect(result.cfg.channels?.whatsapp?.accounts?.default?.allowFrom).toEqual(["*"]);
|
|
328
|
+
expectWhatsAppDefaultAccountAccessNote(harness);
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
it("updates an existing mixed-case default-account key during setup", async () => {
|
|
332
|
+
hoisted.pathExists.mockResolvedValue(true);
|
|
333
|
+
const harness = createSeparatePhoneHarness({
|
|
334
|
+
selectValues: ["separate", "open"],
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
const result = await runConfigureWithHarness({
|
|
338
|
+
harness,
|
|
339
|
+
cfg: {
|
|
340
|
+
channels: {
|
|
341
|
+
whatsapp: {
|
|
342
|
+
accounts: {
|
|
343
|
+
Default: {
|
|
344
|
+
authDir: "/tmp/default-auth",
|
|
345
|
+
},
|
|
346
|
+
work: {
|
|
347
|
+
authDir: "/tmp/work",
|
|
348
|
+
},
|
|
349
|
+
},
|
|
350
|
+
},
|
|
351
|
+
},
|
|
352
|
+
} as OpenClawConfig,
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
expect(result.cfg.channels?.whatsapp?.accounts?.Default?.authDir).toBe("/tmp/default-auth");
|
|
356
|
+
expect(result.cfg.channels?.whatsapp?.accounts?.Default?.dmPolicy).toBe("open");
|
|
357
|
+
expect(result.cfg.channels?.whatsapp?.accounts?.Default?.allowFrom).toEqual(["*"]);
|
|
358
|
+
expect(result.cfg.channels?.whatsapp?.accounts?.default).toBeUndefined();
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
it("runs WhatsApp login when not linked and user confirms linking", async () => {
|
|
362
|
+
hoisted.pathExists.mockResolvedValue(false);
|
|
363
|
+
const harness = createWhatsAppLinkingHarness(createQueuedWizardPrompter);
|
|
364
|
+
const runtime = createRuntime();
|
|
365
|
+
|
|
366
|
+
await runConfigureWithHarness({
|
|
367
|
+
harness,
|
|
368
|
+
runtime,
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
expect(hoisted.loginWeb).toHaveBeenCalledWith(false, undefined, runtime, DEFAULT_ACCOUNT_ID);
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
it("skips relink note when already linked and relink is declined", async () => {
|
|
375
|
+
hoisted.pathExists.mockResolvedValue(true);
|
|
376
|
+
const harness = createSeparatePhoneHarness({
|
|
377
|
+
selectValues: ["separate", "disabled"],
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
await runConfigureWithHarness({
|
|
381
|
+
harness,
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
expect(hoisted.loginWeb).not.toHaveBeenCalled();
|
|
385
|
+
expectNoWhatsAppLoginFollowup(harness);
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
it("shows follow-up login command note when not linked and linking is skipped", async () => {
|
|
389
|
+
hoisted.pathExists.mockResolvedValue(false);
|
|
390
|
+
const harness = createSeparatePhoneHarness({
|
|
391
|
+
selectValues: ["separate", "disabled"],
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
await runConfigureWithHarness({
|
|
395
|
+
harness,
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
expectWhatsAppLoginFollowup(harness);
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
it("heartbeat readiness uses configured defaultAccount for active listener checks", async () => {
|
|
402
|
+
const result = await checkWhatsAppHeartbeatReady({
|
|
403
|
+
cfg: {
|
|
404
|
+
channels: {
|
|
405
|
+
whatsapp: {
|
|
406
|
+
defaultAccount: "work",
|
|
407
|
+
accounts: {
|
|
408
|
+
work: {
|
|
409
|
+
authDir: "/tmp/work",
|
|
410
|
+
},
|
|
411
|
+
},
|
|
412
|
+
},
|
|
413
|
+
},
|
|
414
|
+
} as OpenClawConfig,
|
|
415
|
+
deps: {
|
|
416
|
+
readWebAuthExistsForDecision: async () => ({
|
|
417
|
+
outcome: "stable" as const,
|
|
418
|
+
exists: true,
|
|
419
|
+
}),
|
|
420
|
+
hasActiveWebListener: (accountId?: string) => accountId === "work",
|
|
421
|
+
},
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
expect(result).toEqual({ ok: true, reason: "ok" });
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
it("heartbeat readiness returns unstable when auth state timing is unresolved", async () => {
|
|
428
|
+
const result = await checkWhatsAppHeartbeatReady({
|
|
429
|
+
cfg: {
|
|
430
|
+
channels: {
|
|
431
|
+
whatsapp: {
|
|
432
|
+
accounts: {
|
|
433
|
+
default: {
|
|
434
|
+
authDir: "/tmp/default",
|
|
435
|
+
},
|
|
436
|
+
},
|
|
437
|
+
},
|
|
438
|
+
},
|
|
439
|
+
} as OpenClawConfig,
|
|
440
|
+
deps: {
|
|
441
|
+
readWebAuthExistsForDecision: async () => ({ outcome: "unstable" as const }),
|
|
442
|
+
hasActiveWebListener: () => true,
|
|
443
|
+
},
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
expect(result).toEqual({ ok: false, reason: WHATSAPP_AUTH_UNSTABLE_CODE });
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
it("does not treat unstable auth as configured in generic plugin config checks", async () => {
|
|
450
|
+
hoisted.readWebAuthState.mockResolvedValueOnce("unstable");
|
|
451
|
+
|
|
452
|
+
await expect(
|
|
453
|
+
whatsappSetupPlugin.config.isConfigured?.(
|
|
454
|
+
{
|
|
455
|
+
authDir: "/tmp/work",
|
|
456
|
+
} as never,
|
|
457
|
+
{} as never,
|
|
458
|
+
),
|
|
459
|
+
).resolves.toBe(false);
|
|
460
|
+
});
|
|
461
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ChannelPlugin } from "openclaw/plugin-sdk/core";
|
|
2
|
+
import { type ResolvedWhatsAppAccount } from "./accounts.js";
|
|
3
|
+
import { readWebAuthState } from "./auth-store.js";
|
|
4
|
+
import { resolveWhatsAppGroupIntroHint } from "./group-intro.js";
|
|
5
|
+
import {
|
|
6
|
+
resolveWhatsAppGroupRequireMention,
|
|
7
|
+
resolveWhatsAppGroupToolPolicy,
|
|
8
|
+
} from "./group-policy.js";
|
|
9
|
+
import { whatsappSetupAdapter } from "./setup-core.js";
|
|
10
|
+
import { createWhatsAppPluginBase, whatsappSetupWizardProxy } from "./shared.js";
|
|
11
|
+
import { detectWhatsAppLegacyStateMigrations } from "./state-migrations.js";
|
|
12
|
+
|
|
13
|
+
export const whatsappSetupPlugin: ChannelPlugin<ResolvedWhatsAppAccount> = {
|
|
14
|
+
...createWhatsAppPluginBase({
|
|
15
|
+
groups: {
|
|
16
|
+
resolveRequireMention: resolveWhatsAppGroupRequireMention,
|
|
17
|
+
resolveToolPolicy: resolveWhatsAppGroupToolPolicy,
|
|
18
|
+
resolveGroupIntroHint: resolveWhatsAppGroupIntroHint,
|
|
19
|
+
},
|
|
20
|
+
setupWizard: whatsappSetupWizardProxy,
|
|
21
|
+
setup: whatsappSetupAdapter,
|
|
22
|
+
isConfigured: async (account) => (await readWebAuthState(account.authDir)) === "linked",
|
|
23
|
+
}),
|
|
24
|
+
lifecycle: {
|
|
25
|
+
detectLegacyStateMigrations: ({ oauthDir }) =>
|
|
26
|
+
detectWhatsAppLegacyStateMigrations({ oauthDir }),
|
|
27
|
+
},
|
|
28
|
+
};
|