@openclaw/whatsapp 2026.5.2 → 2026.5.3-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/dist/access-control-BQ3tCkH8.js +288 -0
- package/dist/account-config-CNQ33oav.js +47 -0
- package/dist/account-ids-DG18xddX.js +5 -0
- package/dist/accounts-BDqgpFEB.js +116 -0
- package/dist/action-runtime-DTGNgG-i.js +74 -0
- package/dist/action-runtime-api.js +2 -0
- package/dist/action-runtime.runtime.js +2 -0
- package/dist/active-listener-N7GFKsuN.js +11 -0
- package/dist/agent-tools-login-DpRxLNRB.js +89 -0
- package/dist/api.js +148 -0
- package/dist/audio-preflight.runtime-Bcdsl_ri.js +7 -0
- package/dist/auth-presence.js +32 -0
- package/dist/auth-store-BjCb50Ry.js +381 -0
- package/dist/channel-DQ-5Xoj9.js +542 -0
- package/dist/channel-config-api.js +2 -0
- package/dist/channel-plugin-api.js +2 -0
- package/dist/channel-react-action-Df20qAy9.js +42 -0
- package/dist/channel.runtime-DKXRnA8x.js +55 -0
- package/dist/channel.setup-DOHR2BGp.js +20 -0
- package/dist/command-policy-O8sRnqUV.js +8 -0
- package/dist/config-schema-Dmo66Ubb.js +27 -0
- package/dist/connection-controller-BiHAsTM8.js +596 -0
- package/dist/connection-controller-registry-D_iIGz5m.js +22 -0
- package/dist/constants-DLGCIbfl.js +4 -0
- package/dist/constants.js +2 -0
- package/dist/contract-api.js +19 -0
- package/dist/creds-files-_2V8jzQa.js +19 -0
- package/dist/directory-config-DVs4ffXu.js +37 -0
- package/dist/directory-contract-api.js +2 -0
- package/dist/doctor-A9tXm9Om.js +48 -0
- package/dist/doctor-contract-api.js +10 -0
- package/dist/group-session-contract-B8QBn0I2.js +15 -0
- package/dist/identity-QHAlV7Fu.js +75 -0
- package/dist/index.js +18 -0
- package/dist/legacy-session-surface-api.js +8 -0
- package/dist/legacy-state-migrations-api.js +2 -0
- package/dist/light-runtime-api.js +5 -0
- package/dist/login-DymdrKca.js +52 -0
- package/dist/login-qr-DIS0Iv-7.js +378 -0
- package/dist/login-qr-api.js +2 -0
- package/dist/login-qr-runtime.js +16 -0
- package/dist/monitor-C4Fhg_lD.js +3349 -0
- package/dist/normalize-CWYiGkXw.js +2 -0
- package/dist/normalize-target-BPVHNsM5.js +74 -0
- package/dist/outbound-adapter-BssVnZdz.js +29 -0
- package/dist/outbound-base-Bq1UYEK5.js +119 -0
- package/dist/outbound-media-contract-CGss_QHy.js +163 -0
- package/dist/outbound-payload-test-api.js +2 -0
- package/dist/quoted-message-TENQzyxV.js +108 -0
- package/dist/reaction-level-CRVEVAfi.js +16 -0
- package/dist/reply-resolver.runtime-BRCgoO4C.js +2 -0
- package/dist/resolve-outbound-target-CN-Wo6IY.js +39 -0
- package/dist/rolldown-runtime-RkAeH_Qm.js +27 -0
- package/dist/runtime-6fZ67abR.js +8 -0
- package/dist/runtime-api.js +15 -0
- package/dist/runtime-group-policy-Gp1lQ0at.js +11 -0
- package/dist/secret-contract-api.js +5 -0
- package/dist/security-contract-DqH8JDX6.js +26 -0
- package/dist/security-contract-api.js +2 -0
- package/dist/send-CIyLFxdZ.js +234 -0
- package/dist/session-contract-B0efQf9P.js +27 -0
- package/dist/session-errors-CSuKZPub.js +63 -0
- package/dist/session.runtime-C1eSE_KK.js +13 -0
- package/dist/setup-core-DZKvpzbH.js +46 -0
- package/dist/setup-entry.js +23 -0
- package/dist/setup-plugin-api.js +2 -0
- package/dist/setup-surface-ieFnIW4g.js +344 -0
- package/dist/shared-D_wzSVar.js +307 -0
- package/dist/state-migrations-DnCdvoYD.js +39 -0
- package/dist/targets.js +2 -0
- package/dist/test-api.js +3 -0
- package/dist/text-runtime-C1zNiZeO.js +116 -0
- package/package.json +14 -6
- package/action-runtime-api.ts +0 -1
- package/action-runtime.runtime.ts +0 -1
- package/api.ts +0 -213
- package/auth-presence.ts +0 -80
- package/channel-config-api.ts +0 -1
- package/channel-plugin-api.ts +0 -3
- package/config-api.ts +0 -4
- package/constants.ts +0 -1
- package/contract-api.ts +0 -29
- package/directory-contract-api.ts +0 -4
- package/doctor-contract-api.ts +0 -8
- package/index.test.ts +0 -13
- package/index.ts +0 -16
- package/legacy-session-surface-api.ts +0 -6
- package/legacy-state-migrations-api.ts +0 -1
- package/light-runtime-api.ts +0 -12
- package/login-qr-api.ts +0 -1
- package/login-qr-runtime.ts +0 -23
- package/outbound-payload-test-api.ts +0 -1
- package/runtime-api.ts +0 -84
- package/secret-contract-api.ts +0 -4
- package/security-contract-api.ts +0 -4
- package/setup-entry.test.ts +0 -21
- package/setup-entry.ts +0 -21
- package/setup-plugin-api.ts +0 -3
- package/src/account-config.ts +0 -77
- package/src/account-ids.ts +0 -13
- package/src/account-types.ts +0 -5
- package/src/accounts.test.ts +0 -182
- package/src/accounts.ts +0 -176
- package/src/accounts.whatsapp-auth.test.ts +0 -59
- package/src/action-runtime-target-auth.ts +0 -27
- package/src/action-runtime.test.ts +0 -330
- package/src/action-runtime.ts +0 -76
- package/src/active-listener.test.ts +0 -65
- package/src/active-listener.ts +0 -17
- package/src/agent-tools-login.test.ts +0 -81
- package/src/agent-tools-login.ts +0 -113
- package/src/approval-auth.test.ts +0 -24
- package/src/approval-auth.ts +0 -27
- package/src/auth-store.runtime.ts +0 -1
- package/src/auth-store.test.ts +0 -311
- package/src/auth-store.ts +0 -502
- package/src/auto-reply/config.runtime.ts +0 -16
- package/src/auto-reply/constants.ts +0 -1
- package/src/auto-reply/deliver-reply.test.ts +0 -843
- package/src/auto-reply/deliver-reply.ts +0 -279
- package/src/auto-reply/loggers.ts +0 -6
- package/src/auto-reply/mentions.ts +0 -131
- package/src/auto-reply/monitor/ack-reaction.test.ts +0 -170
- package/src/auto-reply/monitor/ack-reaction.ts +0 -99
- package/src/auto-reply/monitor/audio-preflight.runtime.ts +0 -9
- package/src/auto-reply/monitor/broadcast.ts +0 -153
- package/src/auto-reply/monitor/commands.ts +0 -19
- package/src/auto-reply/monitor/echo.ts +0 -64
- package/src/auto-reply/monitor/group-activation.runtime.ts +0 -1
- package/src/auto-reply/monitor/group-activation.test.ts +0 -189
- package/src/auto-reply/monitor/group-activation.ts +0 -73
- package/src/auto-reply/monitor/group-gating.audio-preflight.test.ts +0 -103
- package/src/auto-reply/monitor/group-gating.runtime.ts +0 -8
- package/src/auto-reply/monitor/group-gating.ts +0 -217
- package/src/auto-reply/monitor/group-members.test.ts +0 -56
- package/src/auto-reply/monitor/group-members.ts +0 -65
- package/src/auto-reply/monitor/inbound-context.test.ts +0 -97
- package/src/auto-reply/monitor/inbound-context.ts +0 -92
- package/src/auto-reply/monitor/inbound-dispatch.runtime.ts +0 -21
- package/src/auto-reply/monitor/inbound-dispatch.test.ts +0 -895
- package/src/auto-reply/monitor/inbound-dispatch.ts +0 -422
- package/src/auto-reply/monitor/last-route.test.ts +0 -37
- package/src/auto-reply/monitor/last-route.ts +0 -61
- package/src/auto-reply/monitor/message-line.runtime.ts +0 -38
- package/src/auto-reply/monitor/message-line.ts +0 -54
- package/src/auto-reply/monitor/on-message.audio-preflight.test.ts +0 -354
- package/src/auto-reply/monitor/on-message.ts +0 -291
- package/src/auto-reply/monitor/peer.ts +0 -17
- package/src/auto-reply/monitor/process-message.audio-preflight.test.ts +0 -420
- package/src/auto-reply/monitor/process-message.test.ts +0 -355
- package/src/auto-reply/monitor/process-message.ts +0 -531
- package/src/auto-reply/monitor/runtime-api.ts +0 -30
- package/src/auto-reply/monitor-state.test.ts +0 -64
- package/src/auto-reply/monitor-state.ts +0 -106
- package/src/auto-reply/monitor.ts +0 -600
- package/src/auto-reply/reply-resolver.runtime.ts +0 -1
- package/src/auto-reply/types.ts +0 -48
- package/src/auto-reply/util.ts +0 -63
- package/src/auto-reply/web-auto-reply-monitor.test.ts +0 -687
- package/src/auto-reply/web-auto-reply-utils.test.ts +0 -392
- package/src/auto-reply.broadcast-groups.combined.test.ts +0 -246
- package/src/auto-reply.broadcast-groups.test-harness.ts +0 -47
- package/src/auto-reply.impl.ts +0 -6
- package/src/auto-reply.test-harness.ts +0 -421
- package/src/auto-reply.ts +0 -1
- package/src/auto-reply.web-auto-reply.compresses-common-formats-jpeg-cap.test.ts +0 -427
- package/src/auto-reply.web-auto-reply.connection-and-logging.e2e.test.ts +0 -908
- package/src/auto-reply.web-auto-reply.last-route.test.ts +0 -184
- package/src/channel-actions.runtime.ts +0 -7
- package/src/channel-actions.test.ts +0 -216
- package/src/channel-actions.ts +0 -84
- package/src/channel-outbound.test.ts +0 -131
- package/src/channel-outbound.ts +0 -36
- package/src/channel-react-action.runtime.ts +0 -7
- package/src/channel-react-action.test.ts +0 -294
- package/src/channel-react-action.ts +0 -84
- package/src/channel.runtime.ts +0 -117
- package/src/channel.setup.test.ts +0 -461
- package/src/channel.setup.ts +0 -28
- package/src/channel.ts +0 -339
- package/src/command-policy.ts +0 -7
- package/src/config-accessors.test.ts +0 -34
- package/src/config-accessors.ts +0 -22
- package/src/config-schema.test.ts +0 -121
- package/src/config-schema.ts +0 -6
- package/src/config-ui-hints.ts +0 -24
- package/src/connection-controller-registry.test.ts +0 -27
- package/src/connection-controller-registry.ts +0 -49
- package/src/connection-controller.test.ts +0 -282
- package/src/connection-controller.ts +0 -679
- package/src/creds-files.ts +0 -19
- package/src/creds-persistence.ts +0 -102
- package/src/directory-config.test.ts +0 -60
- package/src/directory-config.ts +0 -40
- package/src/directory-contract.test.ts +0 -56
- package/src/doctor-contract.ts +0 -11
- package/src/doctor.test.ts +0 -74
- package/src/doctor.ts +0 -56
- package/src/group-intro.ts +0 -15
- package/src/group-policy.test.ts +0 -36
- package/src/group-policy.ts +0 -40
- package/src/group-session-contract.ts +0 -20
- package/src/group-session-key.test.ts +0 -53
- package/src/group-session-key.ts +0 -41
- package/src/heartbeat.ts +0 -34
- package/src/identity.ts +0 -164
- package/src/inbound/access-control.test-harness.ts +0 -37
- package/src/inbound/access-control.test.ts +0 -375
- package/src/inbound/access-control.ts +0 -237
- package/src/inbound/dedupe.ts +0 -132
- package/src/inbound/extract.test.ts +0 -282
- package/src/inbound/extract.ts +0 -488
- package/src/inbound/lifecycle.ts +0 -39
- package/src/inbound/media.node.test.ts +0 -83
- package/src/inbound/media.ts +0 -102
- package/src/inbound/monitor.ts +0 -890
- package/src/inbound/runtime-api.ts +0 -7
- package/src/inbound/save-media.runtime.ts +0 -1
- package/src/inbound/send-api.test.ts +0 -319
- package/src/inbound/send-api.ts +0 -145
- package/src/inbound/send-result.ts +0 -61
- package/src/inbound/types.ts +0 -106
- package/src/inbound-context.contract.test.ts +0 -32
- package/src/inbound-policy.ts +0 -231
- package/src/inbound.media.test.ts +0 -320
- package/src/inbound.test.ts +0 -290
- package/src/inbound.ts +0 -9
- package/src/login-qr.test.ts +0 -483
- package/src/login-qr.ts +0 -542
- package/src/login.coverage.test.ts +0 -133
- package/src/login.test.ts +0 -89
- package/src/login.ts +0 -70
- package/src/logout.test.ts +0 -162
- package/src/media.test.ts +0 -480
- package/src/media.ts +0 -10
- package/src/monitor-inbox.allows-messages-from-senders-allowfrom-list.test-support.ts +0 -400
- package/src/monitor-inbox.append-upsert.test-support.ts +0 -133
- package/src/monitor-inbox.behavior.test.ts +0 -5
- package/src/monitor-inbox.blocks-messages-from-unauthorized-senders-not-allowfrom.test-support.ts +0 -362
- package/src/monitor-inbox.captures-media-path-image-messages.test-support.ts +0 -306
- package/src/monitor-inbox.streams-inbound-messages.test-support.ts +0 -729
- package/src/monitor-inbox.test-harness.ts +0 -304
- package/src/normalize-target.ts +0 -123
- package/src/normalize.ts +0 -7
- package/src/outbound-adapter.poll.test.ts +0 -62
- package/src/outbound-adapter.sendpayload.test.ts +0 -195
- package/src/outbound-adapter.ts +0 -36
- package/src/outbound-base.test.ts +0 -560
- package/src/outbound-base.ts +0 -244
- package/src/outbound-media-contract.ts +0 -278
- package/src/outbound-media.runtime.ts +0 -36
- package/src/outbound-payload.contract.test.ts +0 -61
- package/src/outbound-send-deps.ts +0 -1
- package/src/outbound-test-support.ts +0 -16
- package/src/pairing-security.test-harness.ts +0 -59
- package/src/qr-image.ts +0 -1
- package/src/qr-terminal.ts +0 -1
- package/src/quoted-message.test.ts +0 -83
- package/src/quoted-message.ts +0 -184
- package/src/reaction-level.test.ts +0 -94
- package/src/reaction-level.ts +0 -21
- package/src/reconnect.test.ts +0 -51
- package/src/reconnect.ts +0 -55
- package/src/resolve-outbound-target.test.ts +0 -288
- package/src/resolve-outbound-target.ts +0 -58
- package/src/resolve-target.test.ts +0 -120
- package/src/runtime-api.ts +0 -59
- package/src/runtime-group-policy.ts +0 -16
- package/src/runtime.ts +0 -9
- package/src/security-contract.ts +0 -47
- package/src/security-fix.ts +0 -71
- package/src/send.test.ts +0 -534
- package/src/send.ts +0 -292
- package/src/session-contract.test.ts +0 -31
- package/src/session-contract.ts +0 -43
- package/src/session-errors.ts +0 -125
- package/src/session-route.test.ts +0 -41
- package/src/session-route.ts +0 -32
- package/src/session.runtime.ts +0 -8
- package/src/session.test.ts +0 -559
- package/src/session.ts +0 -330
- package/src/setup-core.ts +0 -52
- package/src/setup-finalize.ts +0 -446
- package/src/setup-surface.test.ts +0 -367
- package/src/setup-surface.ts +0 -69
- package/src/setup-test-helpers.ts +0 -216
- package/src/shared.ts +0 -291
- package/src/socket-timing.test.ts +0 -49
- package/src/socket-timing.ts +0 -38
- package/src/state-migrations.ts +0 -54
- package/src/status-issues.test.ts +0 -137
- package/src/status-issues.ts +0 -185
- package/src/system-prompt.test.ts +0 -199
- package/src/system-prompt.ts +0 -31
- package/src/targets-runtime.ts +0 -180
- package/src/test-helpers.ts +0 -690
- package/src/text-runtime.test.ts +0 -162
- package/src/text-runtime.ts +0 -11
- package/src/vcard.ts +0 -84
- package/targets.ts +0 -5
- package/test-api.ts +0 -2
- package/tsconfig.json +0 -16
|
@@ -1,461 +0,0 @@
|
|
|
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
|
-
});
|
package/src/channel.setup.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
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
|
-
};
|