@openclaw/whatsapp 2026.5.2-beta.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.
Files changed (301) hide show
  1. package/dist/access-control-BQ3tCkH8.js +288 -0
  2. package/dist/account-config-CNQ33oav.js +47 -0
  3. package/dist/account-ids-DG18xddX.js +5 -0
  4. package/dist/accounts-BDqgpFEB.js +116 -0
  5. package/dist/action-runtime-DTGNgG-i.js +74 -0
  6. package/dist/action-runtime-api.js +2 -0
  7. package/dist/action-runtime.runtime.js +2 -0
  8. package/dist/active-listener-N7GFKsuN.js +11 -0
  9. package/dist/agent-tools-login-DpRxLNRB.js +89 -0
  10. package/dist/api.js +148 -0
  11. package/dist/audio-preflight.runtime-Bcdsl_ri.js +7 -0
  12. package/dist/auth-presence.js +32 -0
  13. package/dist/auth-store-BjCb50Ry.js +381 -0
  14. package/dist/channel-DQ-5Xoj9.js +542 -0
  15. package/dist/channel-config-api.js +2 -0
  16. package/dist/channel-plugin-api.js +2 -0
  17. package/dist/channel-react-action-Df20qAy9.js +42 -0
  18. package/dist/channel.runtime-DKXRnA8x.js +55 -0
  19. package/dist/channel.setup-DOHR2BGp.js +20 -0
  20. package/dist/command-policy-O8sRnqUV.js +8 -0
  21. package/dist/config-schema-Dmo66Ubb.js +27 -0
  22. package/dist/connection-controller-BiHAsTM8.js +596 -0
  23. package/dist/connection-controller-registry-D_iIGz5m.js +22 -0
  24. package/dist/constants-DLGCIbfl.js +4 -0
  25. package/dist/constants.js +2 -0
  26. package/dist/contract-api.js +19 -0
  27. package/dist/creds-files-_2V8jzQa.js +19 -0
  28. package/dist/directory-config-DVs4ffXu.js +37 -0
  29. package/dist/directory-contract-api.js +2 -0
  30. package/dist/doctor-A9tXm9Om.js +48 -0
  31. package/dist/doctor-contract-api.js +10 -0
  32. package/dist/group-session-contract-B8QBn0I2.js +15 -0
  33. package/dist/identity-QHAlV7Fu.js +75 -0
  34. package/dist/index.js +18 -0
  35. package/dist/legacy-session-surface-api.js +8 -0
  36. package/dist/legacy-state-migrations-api.js +2 -0
  37. package/dist/light-runtime-api.js +5 -0
  38. package/dist/login-DymdrKca.js +52 -0
  39. package/dist/login-qr-DIS0Iv-7.js +378 -0
  40. package/dist/login-qr-api.js +2 -0
  41. package/dist/login-qr-runtime.js +16 -0
  42. package/dist/monitor-C4Fhg_lD.js +3349 -0
  43. package/dist/normalize-CWYiGkXw.js +2 -0
  44. package/dist/normalize-target-BPVHNsM5.js +74 -0
  45. package/dist/outbound-adapter-BssVnZdz.js +29 -0
  46. package/dist/outbound-base-Bq1UYEK5.js +119 -0
  47. package/dist/outbound-media-contract-CGss_QHy.js +163 -0
  48. package/dist/outbound-payload-test-api.js +2 -0
  49. package/dist/quoted-message-TENQzyxV.js +108 -0
  50. package/dist/reaction-level-CRVEVAfi.js +16 -0
  51. package/dist/reply-resolver.runtime-BRCgoO4C.js +2 -0
  52. package/dist/resolve-outbound-target-CN-Wo6IY.js +39 -0
  53. package/dist/rolldown-runtime-RkAeH_Qm.js +27 -0
  54. package/dist/runtime-6fZ67abR.js +8 -0
  55. package/dist/runtime-api.js +15 -0
  56. package/dist/runtime-group-policy-Gp1lQ0at.js +11 -0
  57. package/dist/secret-contract-api.js +5 -0
  58. package/dist/security-contract-DqH8JDX6.js +26 -0
  59. package/dist/security-contract-api.js +2 -0
  60. package/dist/send-CIyLFxdZ.js +234 -0
  61. package/dist/session-contract-B0efQf9P.js +27 -0
  62. package/dist/session-errors-CSuKZPub.js +63 -0
  63. package/dist/session.runtime-C1eSE_KK.js +13 -0
  64. package/dist/setup-core-DZKvpzbH.js +46 -0
  65. package/dist/setup-entry.js +23 -0
  66. package/dist/setup-plugin-api.js +2 -0
  67. package/dist/setup-surface-ieFnIW4g.js +344 -0
  68. package/dist/shared-D_wzSVar.js +307 -0
  69. package/dist/state-migrations-DnCdvoYD.js +39 -0
  70. package/dist/targets.js +2 -0
  71. package/dist/test-api.js +3 -0
  72. package/dist/text-runtime-C1zNiZeO.js +116 -0
  73. package/package.json +14 -6
  74. package/action-runtime-api.ts +0 -1
  75. package/action-runtime.runtime.ts +0 -1
  76. package/api.ts +0 -213
  77. package/auth-presence.ts +0 -80
  78. package/channel-config-api.ts +0 -1
  79. package/channel-plugin-api.ts +0 -3
  80. package/config-api.ts +0 -4
  81. package/constants.ts +0 -1
  82. package/contract-api.ts +0 -29
  83. package/directory-contract-api.ts +0 -4
  84. package/doctor-contract-api.ts +0 -8
  85. package/index.test.ts +0 -13
  86. package/index.ts +0 -16
  87. package/legacy-session-surface-api.ts +0 -6
  88. package/legacy-state-migrations-api.ts +0 -1
  89. package/light-runtime-api.ts +0 -12
  90. package/login-qr-api.ts +0 -1
  91. package/login-qr-runtime.ts +0 -23
  92. package/outbound-payload-test-api.ts +0 -1
  93. package/runtime-api.ts +0 -84
  94. package/secret-contract-api.ts +0 -4
  95. package/security-contract-api.ts +0 -4
  96. package/setup-entry.test.ts +0 -21
  97. package/setup-entry.ts +0 -21
  98. package/setup-plugin-api.ts +0 -3
  99. package/src/account-config.ts +0 -77
  100. package/src/account-ids.ts +0 -13
  101. package/src/account-types.ts +0 -5
  102. package/src/accounts.test.ts +0 -182
  103. package/src/accounts.ts +0 -176
  104. package/src/accounts.whatsapp-auth.test.ts +0 -59
  105. package/src/action-runtime-target-auth.ts +0 -27
  106. package/src/action-runtime.test.ts +0 -330
  107. package/src/action-runtime.ts +0 -76
  108. package/src/active-listener.test.ts +0 -65
  109. package/src/active-listener.ts +0 -17
  110. package/src/agent-tools-login.test.ts +0 -81
  111. package/src/agent-tools-login.ts +0 -113
  112. package/src/approval-auth.test.ts +0 -24
  113. package/src/approval-auth.ts +0 -27
  114. package/src/auth-store.runtime.ts +0 -1
  115. package/src/auth-store.test.ts +0 -311
  116. package/src/auth-store.ts +0 -502
  117. package/src/auto-reply/config.runtime.ts +0 -16
  118. package/src/auto-reply/constants.ts +0 -1
  119. package/src/auto-reply/deliver-reply.test.ts +0 -843
  120. package/src/auto-reply/deliver-reply.ts +0 -279
  121. package/src/auto-reply/loggers.ts +0 -6
  122. package/src/auto-reply/mentions.ts +0 -131
  123. package/src/auto-reply/monitor/ack-reaction.test.ts +0 -170
  124. package/src/auto-reply/monitor/ack-reaction.ts +0 -99
  125. package/src/auto-reply/monitor/audio-preflight.runtime.ts +0 -9
  126. package/src/auto-reply/monitor/broadcast.ts +0 -153
  127. package/src/auto-reply/monitor/commands.ts +0 -19
  128. package/src/auto-reply/monitor/echo.ts +0 -64
  129. package/src/auto-reply/monitor/group-activation.runtime.ts +0 -1
  130. package/src/auto-reply/monitor/group-activation.test.ts +0 -189
  131. package/src/auto-reply/monitor/group-activation.ts +0 -73
  132. package/src/auto-reply/monitor/group-gating.audio-preflight.test.ts +0 -103
  133. package/src/auto-reply/monitor/group-gating.runtime.ts +0 -8
  134. package/src/auto-reply/monitor/group-gating.ts +0 -217
  135. package/src/auto-reply/monitor/group-members.test.ts +0 -56
  136. package/src/auto-reply/monitor/group-members.ts +0 -65
  137. package/src/auto-reply/monitor/inbound-context.test.ts +0 -97
  138. package/src/auto-reply/monitor/inbound-context.ts +0 -92
  139. package/src/auto-reply/monitor/inbound-dispatch.runtime.ts +0 -21
  140. package/src/auto-reply/monitor/inbound-dispatch.test.ts +0 -895
  141. package/src/auto-reply/monitor/inbound-dispatch.ts +0 -422
  142. package/src/auto-reply/monitor/last-route.test.ts +0 -37
  143. package/src/auto-reply/monitor/last-route.ts +0 -61
  144. package/src/auto-reply/monitor/message-line.runtime.ts +0 -38
  145. package/src/auto-reply/monitor/message-line.ts +0 -54
  146. package/src/auto-reply/monitor/on-message.audio-preflight.test.ts +0 -354
  147. package/src/auto-reply/monitor/on-message.ts +0 -291
  148. package/src/auto-reply/monitor/peer.ts +0 -17
  149. package/src/auto-reply/monitor/process-message.audio-preflight.test.ts +0 -420
  150. package/src/auto-reply/monitor/process-message.test.ts +0 -355
  151. package/src/auto-reply/monitor/process-message.ts +0 -531
  152. package/src/auto-reply/monitor/runtime-api.ts +0 -30
  153. package/src/auto-reply/monitor-state.test.ts +0 -64
  154. package/src/auto-reply/monitor-state.ts +0 -106
  155. package/src/auto-reply/monitor.ts +0 -600
  156. package/src/auto-reply/reply-resolver.runtime.ts +0 -1
  157. package/src/auto-reply/types.ts +0 -48
  158. package/src/auto-reply/util.ts +0 -63
  159. package/src/auto-reply/web-auto-reply-monitor.test.ts +0 -687
  160. package/src/auto-reply/web-auto-reply-utils.test.ts +0 -392
  161. package/src/auto-reply.broadcast-groups.combined.test.ts +0 -246
  162. package/src/auto-reply.broadcast-groups.test-harness.ts +0 -47
  163. package/src/auto-reply.impl.ts +0 -6
  164. package/src/auto-reply.test-harness.ts +0 -421
  165. package/src/auto-reply.ts +0 -1
  166. package/src/auto-reply.web-auto-reply.compresses-common-formats-jpeg-cap.test.ts +0 -427
  167. package/src/auto-reply.web-auto-reply.connection-and-logging.e2e.test.ts +0 -908
  168. package/src/auto-reply.web-auto-reply.last-route.test.ts +0 -184
  169. package/src/channel-actions.runtime.ts +0 -7
  170. package/src/channel-actions.test.ts +0 -216
  171. package/src/channel-actions.ts +0 -84
  172. package/src/channel-outbound.test.ts +0 -131
  173. package/src/channel-outbound.ts +0 -36
  174. package/src/channel-react-action.runtime.ts +0 -7
  175. package/src/channel-react-action.test.ts +0 -294
  176. package/src/channel-react-action.ts +0 -84
  177. package/src/channel.runtime.ts +0 -117
  178. package/src/channel.setup.test.ts +0 -461
  179. package/src/channel.setup.ts +0 -28
  180. package/src/channel.ts +0 -334
  181. package/src/command-policy.ts +0 -7
  182. package/src/config-accessors.test.ts +0 -34
  183. package/src/config-accessors.ts +0 -22
  184. package/src/config-schema.test.ts +0 -121
  185. package/src/config-schema.ts +0 -6
  186. package/src/config-ui-hints.ts +0 -24
  187. package/src/connection-controller-registry.test.ts +0 -27
  188. package/src/connection-controller-registry.ts +0 -49
  189. package/src/connection-controller.test.ts +0 -282
  190. package/src/connection-controller.ts +0 -679
  191. package/src/creds-files.ts +0 -19
  192. package/src/creds-persistence.ts +0 -102
  193. package/src/directory-config.test.ts +0 -60
  194. package/src/directory-config.ts +0 -40
  195. package/src/directory-contract.test.ts +0 -56
  196. package/src/doctor-contract.ts +0 -11
  197. package/src/doctor.test.ts +0 -74
  198. package/src/doctor.ts +0 -56
  199. package/src/group-intro.ts +0 -15
  200. package/src/group-policy.test.ts +0 -36
  201. package/src/group-policy.ts +0 -40
  202. package/src/group-session-contract.ts +0 -20
  203. package/src/group-session-key.test.ts +0 -53
  204. package/src/group-session-key.ts +0 -41
  205. package/src/heartbeat.ts +0 -34
  206. package/src/identity.ts +0 -164
  207. package/src/inbound/access-control.test-harness.ts +0 -37
  208. package/src/inbound/access-control.test.ts +0 -375
  209. package/src/inbound/access-control.ts +0 -237
  210. package/src/inbound/dedupe.ts +0 -132
  211. package/src/inbound/extract.test.ts +0 -282
  212. package/src/inbound/extract.ts +0 -488
  213. package/src/inbound/lifecycle.ts +0 -39
  214. package/src/inbound/media.node.test.ts +0 -83
  215. package/src/inbound/media.ts +0 -102
  216. package/src/inbound/monitor.ts +0 -890
  217. package/src/inbound/runtime-api.ts +0 -7
  218. package/src/inbound/save-media.runtime.ts +0 -1
  219. package/src/inbound/send-api.test.ts +0 -307
  220. package/src/inbound/send-api.ts +0 -141
  221. package/src/inbound/send-result.ts +0 -61
  222. package/src/inbound/types.ts +0 -106
  223. package/src/inbound-context.contract.test.ts +0 -32
  224. package/src/inbound-policy.ts +0 -231
  225. package/src/inbound.media.test.ts +0 -320
  226. package/src/inbound.test.ts +0 -290
  227. package/src/inbound.ts +0 -9
  228. package/src/login-qr.test.ts +0 -483
  229. package/src/login-qr.ts +0 -542
  230. package/src/login.coverage.test.ts +0 -133
  231. package/src/login.test.ts +0 -89
  232. package/src/login.ts +0 -70
  233. package/src/logout.test.ts +0 -162
  234. package/src/media.test.ts +0 -480
  235. package/src/media.ts +0 -10
  236. package/src/monitor-inbox.allows-messages-from-senders-allowfrom-list.test-support.ts +0 -400
  237. package/src/monitor-inbox.append-upsert.test-support.ts +0 -133
  238. package/src/monitor-inbox.behavior.test.ts +0 -5
  239. package/src/monitor-inbox.blocks-messages-from-unauthorized-senders-not-allowfrom.test-support.ts +0 -362
  240. package/src/monitor-inbox.captures-media-path-image-messages.test-support.ts +0 -306
  241. package/src/monitor-inbox.streams-inbound-messages.test-support.ts +0 -729
  242. package/src/monitor-inbox.test-harness.ts +0 -304
  243. package/src/normalize-target.ts +0 -112
  244. package/src/normalize.ts +0 -6
  245. package/src/outbound-adapter.poll.test.ts +0 -62
  246. package/src/outbound-adapter.sendpayload.test.ts +0 -195
  247. package/src/outbound-adapter.ts +0 -36
  248. package/src/outbound-base.test.ts +0 -560
  249. package/src/outbound-base.ts +0 -244
  250. package/src/outbound-media-contract.ts +0 -278
  251. package/src/outbound-media.runtime.ts +0 -36
  252. package/src/outbound-payload.contract.test.ts +0 -61
  253. package/src/outbound-send-deps.ts +0 -1
  254. package/src/outbound-test-support.ts +0 -16
  255. package/src/pairing-security.test-harness.ts +0 -59
  256. package/src/qr-image.ts +0 -1
  257. package/src/qr-terminal.ts +0 -1
  258. package/src/quoted-message.test.ts +0 -83
  259. package/src/quoted-message.ts +0 -184
  260. package/src/reaction-level.test.ts +0 -94
  261. package/src/reaction-level.ts +0 -21
  262. package/src/reconnect.test.ts +0 -51
  263. package/src/reconnect.ts +0 -55
  264. package/src/resolve-outbound-target.test.ts +0 -265
  265. package/src/resolve-outbound-target.ts +0 -54
  266. package/src/resolve-target.test.ts +0 -97
  267. package/src/runtime-api.ts +0 -59
  268. package/src/runtime-group-policy.ts +0 -16
  269. package/src/runtime.ts +0 -9
  270. package/src/security-contract.ts +0 -47
  271. package/src/security-fix.ts +0 -71
  272. package/src/send.test.ts +0 -515
  273. package/src/send.ts +0 -287
  274. package/src/session-contract.test.ts +0 -31
  275. package/src/session-contract.ts +0 -43
  276. package/src/session-errors.ts +0 -125
  277. package/src/session-route.ts +0 -26
  278. package/src/session.runtime.ts +0 -8
  279. package/src/session.test.ts +0 -559
  280. package/src/session.ts +0 -330
  281. package/src/setup-core.ts +0 -52
  282. package/src/setup-finalize.ts +0 -446
  283. package/src/setup-surface.test.ts +0 -367
  284. package/src/setup-surface.ts +0 -69
  285. package/src/setup-test-helpers.ts +0 -216
  286. package/src/shared.ts +0 -291
  287. package/src/socket-timing.test.ts +0 -49
  288. package/src/socket-timing.ts +0 -38
  289. package/src/state-migrations.ts +0 -54
  290. package/src/status-issues.test.ts +0 -137
  291. package/src/status-issues.ts +0 -185
  292. package/src/system-prompt.test.ts +0 -199
  293. package/src/system-prompt.ts +0 -31
  294. package/src/targets-runtime.ts +0 -180
  295. package/src/test-helpers.ts +0 -690
  296. package/src/text-runtime.test.ts +0 -162
  297. package/src/text-runtime.ts +0 -11
  298. package/src/vcard.ts +0 -84
  299. package/targets.ts +0 -5
  300. package/test-api.ts +0 -2
  301. package/tsconfig.json +0 -16
@@ -1,265 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from "vitest";
2
- import * as normalize from "./normalize-target.js";
3
-
4
- vi.mock("./normalize-target.js");
5
- vi.mock("openclaw/plugin-sdk/channel-feedback", () => ({
6
- missingTargetError: (platform: string, format: string) => new Error(`${platform}: ${format}`),
7
- }));
8
-
9
- let resolveWhatsAppOutboundTarget: typeof import("./resolve-outbound-target.js").resolveWhatsAppOutboundTarget;
10
-
11
- type ResolveParams = Parameters<typeof resolveWhatsAppOutboundTarget>[0];
12
- const PRIMARY_TARGET = "+11234567890";
13
- const SECONDARY_TARGET = "+19876543210";
14
-
15
- function expectResolutionError(params: ResolveParams) {
16
- const result = resolveWhatsAppOutboundTarget(params);
17
- expect(result.ok).toBe(false);
18
- if (result.ok) {
19
- throw new Error("expected resolution to fail");
20
- }
21
- expect(result.error.message).toContain("WhatsApp");
22
- }
23
-
24
- function expectResolutionErrorMessage(params: ResolveParams, expectedMessage: string) {
25
- const result = resolveWhatsAppOutboundTarget(params);
26
- expect(result.ok).toBe(false);
27
- if (result.ok) {
28
- throw new Error("expected resolution to fail");
29
- }
30
- expect(result.error.message).toBe(expectedMessage);
31
- }
32
-
33
- function expectResolutionOk(params: ResolveParams, expectedTarget: string) {
34
- const result = resolveWhatsAppOutboundTarget(params);
35
- expect(result).toEqual({ ok: true, to: expectedTarget });
36
- }
37
-
38
- function mockNormalizedDirectMessage(...values: Array<string | null>) {
39
- const normalizeMock = vi.mocked(normalize.normalizeWhatsAppTarget);
40
- for (const value of values) {
41
- normalizeMock.mockReturnValueOnce(value);
42
- }
43
- vi.mocked(normalize.isWhatsAppGroupJid).mockReturnValueOnce(false);
44
- }
45
-
46
- function expectAllowedForTarget(params: {
47
- allowFrom: ResolveParams["allowFrom"];
48
- mode: ResolveParams["mode"];
49
- to?: string;
50
- }) {
51
- const to = params.to ?? PRIMARY_TARGET;
52
- expectResolutionOk(
53
- {
54
- to,
55
- allowFrom: params.allowFrom,
56
- mode: params.mode,
57
- },
58
- to,
59
- );
60
- }
61
-
62
- function expectDeniedForTarget(params: {
63
- allowFrom: ResolveParams["allowFrom"];
64
- mode: ResolveParams["mode"];
65
- to?: string;
66
- }) {
67
- expectResolutionError({
68
- to: params.to ?? PRIMARY_TARGET,
69
- allowFrom: params.allowFrom,
70
- mode: params.mode,
71
- });
72
- }
73
-
74
- describe("resolveWhatsAppOutboundTarget", () => {
75
- beforeEach(async () => {
76
- vi.resetModules();
77
- vi.resetAllMocks();
78
- ({ resolveWhatsAppOutboundTarget } = await import("./resolve-outbound-target.js"));
79
- });
80
-
81
- describe("empty/missing to parameter", () => {
82
- it.each([
83
- ["null", null],
84
- ["undefined", undefined],
85
- ["empty string", ""],
86
- ["whitespace only", " "],
87
- ])("returns error when to is %s", (_label, to) => {
88
- expectResolutionError({ to, allowFrom: undefined, mode: undefined });
89
- });
90
- });
91
-
92
- describe("normalization failures", () => {
93
- it("returns error when normalizeWhatsAppTarget returns null/undefined", () => {
94
- vi.mocked(normalize.normalizeWhatsAppTarget).mockReturnValueOnce(null);
95
- expectResolutionError({
96
- to: "+1234567890",
97
- allowFrom: undefined,
98
- mode: undefined,
99
- });
100
- });
101
- });
102
-
103
- describe("group JID handling", () => {
104
- it("returns success for valid group JID regardless of mode", () => {
105
- vi.mocked(normalize.normalizeWhatsAppTarget).mockReturnValueOnce("120363123456789@g.us");
106
- vi.mocked(normalize.isWhatsAppGroupJid).mockReturnValueOnce(true);
107
-
108
- expectResolutionOk(
109
- {
110
- to: "120363123456789@g.us",
111
- allowFrom: undefined,
112
- mode: "implicit",
113
- },
114
- "120363123456789@g.us",
115
- );
116
- });
117
-
118
- it("returns success for group JID in heartbeat mode", () => {
119
- vi.mocked(normalize.normalizeWhatsAppTarget).mockReturnValueOnce("120363999888777@g.us");
120
- vi.mocked(normalize.isWhatsAppGroupJid).mockReturnValueOnce(true);
121
-
122
- expectResolutionOk(
123
- {
124
- to: "120363999888777@g.us",
125
- allowFrom: undefined,
126
- mode: "heartbeat",
127
- },
128
- "120363999888777@g.us",
129
- );
130
- });
131
- });
132
-
133
- describe("implicit/heartbeat mode with allowList", () => {
134
- it("allows message when wildcard is present", () => {
135
- mockNormalizedDirectMessage(PRIMARY_TARGET, PRIMARY_TARGET);
136
- expectAllowedForTarget({ allowFrom: ["*"], mode: "implicit" });
137
- });
138
-
139
- it("allows message when allowList is empty", () => {
140
- mockNormalizedDirectMessage(PRIMARY_TARGET, PRIMARY_TARGET);
141
- expectAllowedForTarget({ allowFrom: [], mode: "implicit" });
142
- });
143
-
144
- it("allows message when target is in allowList", () => {
145
- mockNormalizedDirectMessage(PRIMARY_TARGET, PRIMARY_TARGET);
146
- expectAllowedForTarget({ allowFrom: [PRIMARY_TARGET], mode: "implicit" });
147
- });
148
-
149
- it("denies message when target is not in allowList", () => {
150
- mockNormalizedDirectMessage(PRIMARY_TARGET, SECONDARY_TARGET);
151
- expectResolutionErrorMessage(
152
- {
153
- to: PRIMARY_TARGET,
154
- allowFrom: [SECONDARY_TARGET],
155
- mode: "implicit",
156
- },
157
- `Target "${SECONDARY_TARGET}" is not listed in the configured WhatsApp allowFrom policy.`,
158
- );
159
- });
160
-
161
- it("uses the normalized target in the allowFrom error message", () => {
162
- vi.mocked(normalize.normalizeWhatsAppTarget)
163
- .mockReturnValueOnce(SECONDARY_TARGET)
164
- .mockReturnValueOnce(PRIMARY_TARGET);
165
- vi.mocked(normalize.isWhatsAppGroupJid).mockReturnValueOnce(false);
166
-
167
- expectResolutionErrorMessage(
168
- {
169
- to: "(123) 456-7890",
170
- allowFrom: [SECONDARY_TARGET],
171
- mode: "implicit",
172
- },
173
- `Target "${PRIMARY_TARGET}" is not listed in the configured WhatsApp allowFrom policy.`,
174
- );
175
- });
176
-
177
- it("handles mixed numeric and string allowList entries", () => {
178
- vi.mocked(normalize.normalizeWhatsAppTarget)
179
- .mockReturnValueOnce("+11234567890")
180
- .mockReturnValueOnce("+11234567890")
181
- .mockReturnValueOnce("+11234567890");
182
- vi.mocked(normalize.isWhatsAppGroupJid).mockReturnValueOnce(false);
183
-
184
- expectAllowedForTarget({
185
- allowFrom: [1234567890, PRIMARY_TARGET],
186
- mode: "implicit",
187
- });
188
- });
189
-
190
- it("filters out invalid normalized entries from allowList", () => {
191
- vi.mocked(normalize.normalizeWhatsAppTarget)
192
- .mockReturnValueOnce(null)
193
- .mockReturnValueOnce("+11234567890")
194
- .mockReturnValueOnce("+11234567890");
195
- vi.mocked(normalize.isWhatsAppGroupJid).mockReturnValueOnce(false);
196
-
197
- expectAllowedForTarget({
198
- allowFrom: ["invalid", PRIMARY_TARGET],
199
- mode: "implicit",
200
- });
201
- });
202
- });
203
-
204
- describe("heartbeat mode", () => {
205
- it("allows message when target is in allowList in heartbeat mode", () => {
206
- mockNormalizedDirectMessage(PRIMARY_TARGET, PRIMARY_TARGET);
207
- expectAllowedForTarget({ allowFrom: [PRIMARY_TARGET], mode: "heartbeat" });
208
- });
209
-
210
- it("denies message when target is not in allowList in heartbeat mode", () => {
211
- mockNormalizedDirectMessage(PRIMARY_TARGET, SECONDARY_TARGET);
212
- expectDeniedForTarget({ allowFrom: [SECONDARY_TARGET], mode: "heartbeat" });
213
- });
214
- });
215
-
216
- describe("explicit/custom modes", () => {
217
- it("allows message in null mode when allowList is not set", () => {
218
- mockNormalizedDirectMessage(PRIMARY_TARGET);
219
- expectAllowedForTarget({ allowFrom: undefined, mode: null });
220
- });
221
-
222
- it("allows message in undefined mode when allowList is not set", () => {
223
- mockNormalizedDirectMessage(PRIMARY_TARGET);
224
- expectAllowedForTarget({ allowFrom: undefined, mode: undefined });
225
- });
226
-
227
- it("enforces allowList in custom mode string", () => {
228
- mockNormalizedDirectMessage(SECONDARY_TARGET, PRIMARY_TARGET);
229
- expectDeniedForTarget({ allowFrom: [SECONDARY_TARGET], mode: "broadcast" });
230
- });
231
-
232
- it("allows message in custom mode string when target is in allowList", () => {
233
- mockNormalizedDirectMessage(PRIMARY_TARGET, PRIMARY_TARGET);
234
- expectAllowedForTarget({ allowFrom: [PRIMARY_TARGET], mode: "broadcast" });
235
- });
236
- });
237
-
238
- describe("whitespace handling", () => {
239
- it("trims whitespace from to parameter", () => {
240
- mockNormalizedDirectMessage(PRIMARY_TARGET);
241
-
242
- expectResolutionOk(
243
- {
244
- to: ` ${PRIMARY_TARGET} `,
245
- allowFrom: undefined,
246
- mode: undefined,
247
- },
248
- PRIMARY_TARGET,
249
- );
250
- expect(vi.mocked(normalize.normalizeWhatsAppTarget)).toHaveBeenCalledWith(PRIMARY_TARGET);
251
- });
252
-
253
- it("trims whitespace from allowList entries", () => {
254
- mockNormalizedDirectMessage(PRIMARY_TARGET, PRIMARY_TARGET);
255
-
256
- resolveWhatsAppOutboundTarget({
257
- to: PRIMARY_TARGET,
258
- allowFrom: [` ${PRIMARY_TARGET} `],
259
- mode: undefined,
260
- });
261
-
262
- expect(vi.mocked(normalize.normalizeWhatsAppTarget)).toHaveBeenCalledWith(PRIMARY_TARGET);
263
- });
264
- });
265
- });
@@ -1,54 +0,0 @@
1
- import { missingTargetError } from "openclaw/plugin-sdk/channel-feedback";
2
- import { isWhatsAppGroupJid, normalizeWhatsAppTarget } from "./normalize-target.js";
3
-
4
- export type WhatsAppOutboundTargetResolution =
5
- | { ok: true; to: string }
6
- | { ok: false; error: Error };
7
-
8
- function whatsappAllowFromPolicyError(target: string): Error {
9
- return new Error(`Target "${target}" is not listed in the configured WhatsApp allowFrom policy.`);
10
- }
11
-
12
- export function resolveWhatsAppOutboundTarget(params: {
13
- to: string | null | undefined;
14
- allowFrom: Array<string | number> | null | undefined;
15
- mode: string | null | undefined;
16
- }): WhatsAppOutboundTargetResolution {
17
- const trimmed = params.to?.trim() ?? "";
18
- const allowListRaw = (params.allowFrom ?? [])
19
- .map((entry) => String(entry).trim())
20
- .filter(Boolean);
21
- const hasWildcard = allowListRaw.includes("*");
22
- const allowList = allowListRaw
23
- .filter((entry) => entry !== "*")
24
- .map((entry) => normalizeWhatsAppTarget(entry))
25
- .filter((entry): entry is string => Boolean(entry));
26
-
27
- if (trimmed) {
28
- const normalizedTo = normalizeWhatsAppTarget(trimmed);
29
- if (!normalizedTo) {
30
- return {
31
- ok: false,
32
- error: missingTargetError("WhatsApp", "<E.164|group JID>"),
33
- };
34
- }
35
- if (isWhatsAppGroupJid(normalizedTo)) {
36
- return { ok: true, to: normalizedTo };
37
- }
38
- if (hasWildcard || allowList.length === 0) {
39
- return { ok: true, to: normalizedTo };
40
- }
41
- if (allowList.includes(normalizedTo)) {
42
- return { ok: true, to: normalizedTo };
43
- }
44
- return {
45
- ok: false,
46
- error: whatsappAllowFromPolicyError(normalizedTo),
47
- };
48
- }
49
-
50
- return {
51
- ok: false,
52
- error: missingTargetError("WhatsApp", "<E.164|group JID>"),
53
- };
54
- }
@@ -1,97 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import {
3
- isWhatsAppGroupJid,
4
- looksLikeWhatsAppTargetId,
5
- isWhatsAppUserTarget,
6
- normalizeWhatsAppMessagingTarget,
7
- normalizeWhatsAppTarget,
8
- } from "./normalize-target.js";
9
-
10
- describe("normalizeWhatsAppTarget", () => {
11
- it("preserves group JIDs", () => {
12
- expect(normalizeWhatsAppTarget("120363401234567890@g.us")).toBe("120363401234567890@g.us");
13
- expect(normalizeWhatsAppTarget("123456789-987654321@g.us")).toBe("123456789-987654321@g.us");
14
- expect(normalizeWhatsAppTarget("whatsapp:120363401234567890@g.us")).toBe(
15
- "120363401234567890@g.us",
16
- );
17
- });
18
-
19
- it("normalizes direct JIDs to E.164", () => {
20
- expect(normalizeWhatsAppTarget("1555123@s.whatsapp.net")).toBe("+1555123");
21
- });
22
-
23
- it("normalizes user JIDs with device suffix to E.164", () => {
24
- expect(normalizeWhatsAppTarget("41796666864:0@s.whatsapp.net")).toBe("+41796666864");
25
- expect(normalizeWhatsAppTarget("1234567890:123@s.whatsapp.net")).toBe("+1234567890");
26
- expect(normalizeWhatsAppTarget("41796666864@s.whatsapp.net")).toBe("+41796666864");
27
- });
28
-
29
- it("normalizes LID JIDs to E.164", () => {
30
- expect(normalizeWhatsAppTarget("123456789@lid")).toBe("+123456789");
31
- expect(normalizeWhatsAppTarget("123456789@LID")).toBe("+123456789");
32
- });
33
-
34
- it("rejects invalid targets", () => {
35
- expect(normalizeWhatsAppTarget("wat")).toBeNull();
36
- expect(normalizeWhatsAppTarget("whatsapp:")).toBeNull();
37
- expect(normalizeWhatsAppTarget("@g.us")).toBeNull();
38
- expect(normalizeWhatsAppTarget("whatsapp:group:@g.us")).toBeNull();
39
- expect(normalizeWhatsAppTarget("whatsapp:group:120363401234567890@g.us")).toBeNull();
40
- expect(normalizeWhatsAppTarget("group:123456789-987654321@g.us")).toBeNull();
41
- expect(normalizeWhatsAppTarget(" WhatsApp:Group:123456789-987654321@G.US ")).toBeNull();
42
- expect(normalizeWhatsAppTarget("abc@s.whatsapp.net")).toBeNull();
43
- });
44
-
45
- it("rejects non-WhatsApp provider-prefixed phone-like targets", () => {
46
- expect(normalizeWhatsAppTarget("telegram:1234567890")).toBeNull();
47
- expect(normalizeWhatsAppTarget("tg:1234567890")).toBeNull();
48
- expect(normalizeWhatsAppTarget("sms:+15551234567")).toBeNull();
49
- expect(looksLikeWhatsAppTargetId("telegram:1234567890")).toBe(false);
50
- });
51
-
52
- it("handles repeated prefixes", () => {
53
- expect(normalizeWhatsAppTarget("whatsapp:whatsapp:+1555")).toBe("+1555");
54
- expect(normalizeWhatsAppTarget("group:group:120@g.us")).toBeNull();
55
- });
56
- });
57
-
58
- describe("isWhatsAppUserTarget", () => {
59
- it("detects user JIDs with various formats", () => {
60
- expect(isWhatsAppUserTarget("41796666864:0@s.whatsapp.net")).toBe(true);
61
- expect(isWhatsAppUserTarget("1234567890@s.whatsapp.net")).toBe(true);
62
- expect(isWhatsAppUserTarget("123456789@lid")).toBe(true);
63
- expect(isWhatsAppUserTarget("123456789@LID")).toBe(true);
64
- expect(isWhatsAppUserTarget("123@lid:0")).toBe(false);
65
- expect(isWhatsAppUserTarget("abc@s.whatsapp.net")).toBe(false);
66
- expect(isWhatsAppUserTarget("123456789-987654321@g.us")).toBe(false);
67
- expect(isWhatsAppUserTarget("+1555123")).toBe(false);
68
- });
69
- });
70
-
71
- describe("isWhatsAppGroupJid", () => {
72
- it("detects group JIDs with or without prefixes", () => {
73
- expect(isWhatsAppGroupJid("120363401234567890@g.us")).toBe(true);
74
- expect(isWhatsAppGroupJid("123456789-987654321@g.us")).toBe(true);
75
- expect(isWhatsAppGroupJid("whatsapp:120363401234567890@g.us")).toBe(true);
76
- expect(isWhatsAppGroupJid("whatsapp:group:120363401234567890@g.us")).toBe(false);
77
- expect(isWhatsAppGroupJid("x@g.us")).toBe(false);
78
- expect(isWhatsAppGroupJid("@g.us")).toBe(false);
79
- expect(isWhatsAppGroupJid("120@g.usx")).toBe(false);
80
- expect(isWhatsAppGroupJid("+1555123")).toBe(false);
81
- });
82
- });
83
-
84
- describe("normalizeWhatsAppMessagingTarget", () => {
85
- it("normalizes blank inputs to undefined", () => {
86
- expect(normalizeWhatsAppMessagingTarget(" ")).toBeUndefined();
87
- });
88
- });
89
-
90
- describe("looksLikeWhatsAppTargetId", () => {
91
- it("detects common WhatsApp target forms", () => {
92
- expect(looksLikeWhatsAppTargetId("whatsapp:+15555550123")).toBe(true);
93
- expect(looksLikeWhatsAppTargetId("15555550123@c.us")).toBe(true);
94
- expect(looksLikeWhatsAppTargetId("+15555550123")).toBe(true);
95
- expect(looksLikeWhatsAppTargetId("")).toBe(false);
96
- });
97
- });
@@ -1,59 +0,0 @@
1
- export { getChatChannelMeta, type ChannelPlugin } from "openclaw/plugin-sdk/core";
2
- export { buildChannelConfigSchema, WhatsAppConfigSchema } from "../config-api.js";
3
- export { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk/account-id";
4
- export {
5
- formatWhatsAppConfigAllowFromEntries,
6
- resolveWhatsAppConfigAllowFrom,
7
- resolveWhatsAppConfigDefaultTo,
8
- } from "./config-accessors.js";
9
- export {
10
- createActionGate,
11
- jsonResult,
12
- readReactionParams,
13
- readStringParam,
14
- ToolAuthorizationError,
15
- } from "openclaw/plugin-sdk/channel-actions";
16
- export { normalizeE164 } from "openclaw/plugin-sdk/account-resolution";
17
- export type { DmPolicy, GroupPolicy } from "openclaw/plugin-sdk/config-types";
18
- import type { OpenClawConfig as RuntimeOpenClawConfig } from "openclaw/plugin-sdk/config-types";
19
-
20
- export { type ChannelMessageActionName } from "openclaw/plugin-sdk/channel-contract";
21
- export { loadOutboundMediaFromUrl } from "./outbound-media.runtime.js";
22
- export {
23
- resolveWhatsAppGroupRequireMention,
24
- resolveWhatsAppGroupToolPolicy,
25
- } from "./group-policy.js";
26
- export {
27
- resolveWhatsAppGroupIntroHint,
28
- resolveWhatsAppMentionStripRegexes,
29
- } from "./group-intro.js";
30
- export { createWhatsAppOutboundBase } from "./outbound-base.js";
31
- export {
32
- isWhatsAppGroupJid,
33
- isWhatsAppUserTarget,
34
- looksLikeWhatsAppTargetId,
35
- normalizeWhatsAppAllowFromEntries,
36
- normalizeWhatsAppMessagingTarget,
37
- normalizeWhatsAppTarget,
38
- } from "./normalize-target.js";
39
- export { resolveWhatsAppOutboundTarget } from "./resolve-outbound-target.js";
40
- export { resolveWhatsAppReactionLevel } from "./reaction-level.js";
41
-
42
- export type OpenClawConfig = RuntimeOpenClawConfig;
43
- export type { WhatsAppAccountConfig } from "./account-types.js";
44
-
45
- type MonitorWebChannel = typeof import("./channel.runtime.js").monitorWebChannel;
46
-
47
- let channelRuntimePromise: Promise<typeof import("./channel.runtime.js")> | null = null;
48
-
49
- function loadChannelRuntime() {
50
- channelRuntimePromise ??= import("./channel.runtime.js");
51
- return channelRuntimePromise;
52
- }
53
-
54
- export async function monitorWebChannel(
55
- ...args: Parameters<MonitorWebChannel>
56
- ): ReturnType<MonitorWebChannel> {
57
- const { monitorWebChannel } = await loadChannelRuntime();
58
- return await monitorWebChannel(...args);
59
- }
@@ -1,16 +0,0 @@
1
- import { resolveOpenProviderRuntimeGroupPolicy } from "openclaw/plugin-sdk/runtime-group-policy";
2
-
3
- export function resolveWhatsAppRuntimeGroupPolicy(params: {
4
- providerConfigPresent: boolean;
5
- groupPolicy?: "open" | "allowlist" | "disabled";
6
- defaultGroupPolicy?: "open" | "allowlist" | "disabled";
7
- }): {
8
- groupPolicy: "open" | "allowlist" | "disabled";
9
- providerMissingFallbackApplied: boolean;
10
- } {
11
- return resolveOpenProviderRuntimeGroupPolicy({
12
- providerConfigPresent: params.providerConfigPresent,
13
- groupPolicy: params.groupPolicy,
14
- defaultGroupPolicy: params.defaultGroupPolicy,
15
- });
16
- }
package/src/runtime.ts DELETED
@@ -1,9 +0,0 @@
1
- import type { PluginRuntime } from "openclaw/plugin-sdk/core";
2
- import { createPluginRuntimeStore } from "openclaw/plugin-sdk/runtime-store";
3
-
4
- const { setRuntime: setWhatsAppRuntime, getRuntime: getWhatsAppRuntime } =
5
- createPluginRuntimeStore<PluginRuntime>({
6
- pluginId: "whatsapp",
7
- errorMessage: "WhatsApp runtime not initialized",
8
- });
9
- export { getWhatsAppRuntime, setWhatsAppRuntime };
@@ -1,47 +0,0 @@
1
- import { isRecord } from "openclaw/plugin-sdk/text-runtime";
2
-
3
- type UnsupportedSecretRefConfigCandidate = {
4
- path: string;
5
- value: unknown;
6
- };
7
-
8
- export const unsupportedSecretRefSurfacePatterns = [
9
- "channels.whatsapp.creds.json",
10
- "channels.whatsapp.accounts.*.creds.json",
11
- ] as const;
12
-
13
- export function collectUnsupportedSecretRefConfigCandidates(
14
- raw: unknown,
15
- ): UnsupportedSecretRefConfigCandidate[] {
16
- if (!isRecord(raw)) {
17
- return [];
18
- }
19
- if (!isRecord(raw.channels) || !isRecord(raw.channels.whatsapp)) {
20
- return [];
21
- }
22
-
23
- const candidates: UnsupportedSecretRefConfigCandidate[] = [];
24
- const whatsapp = raw.channels.whatsapp;
25
- const creds = isRecord(whatsapp.creds) ? whatsapp.creds : null;
26
- if (creds) {
27
- candidates.push({
28
- path: "channels.whatsapp.creds.json",
29
- value: creds.json,
30
- });
31
- }
32
-
33
- const accounts = isRecord(whatsapp.accounts) ? whatsapp.accounts : null;
34
- if (!accounts) {
35
- return candidates;
36
- }
37
- for (const [accountId, account] of Object.entries(accounts)) {
38
- if (!isRecord(account) || !isRecord(account.creds)) {
39
- continue;
40
- }
41
- candidates.push({
42
- path: `channels.whatsapp.accounts.${accountId}.creds.json`,
43
- value: account.creds.json,
44
- });
45
- }
46
- return candidates;
47
- }
@@ -1,71 +0,0 @@
1
- import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk/account-id";
2
- import type { ChannelDoctorConfigMutation } from "openclaw/plugin-sdk/channel-contract";
3
- import { readChannelAllowFromStore } from "openclaw/plugin-sdk/channel-pairing";
4
- import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
5
-
6
- function applyGroupAllowFromFromStore(params: {
7
- cfg: OpenClawConfig;
8
- storeAllowFrom: string[];
9
- changes: string[];
10
- }): OpenClawConfig {
11
- const next = structuredClone(params.cfg ?? {});
12
- const section = next.channels?.whatsapp as Record<string, unknown> | undefined;
13
- if (!section || typeof section !== "object" || params.storeAllowFrom.length === 0) {
14
- return params.cfg;
15
- }
16
-
17
- let changed = false;
18
- const maybeApply = (prefix: string, holder: Record<string, unknown>) => {
19
- if (holder.groupPolicy !== "allowlist") {
20
- return;
21
- }
22
- const allowFrom = Array.isArray(holder.allowFrom) ? holder.allowFrom : [];
23
- const groupAllowFrom = Array.isArray(holder.groupAllowFrom) ? holder.groupAllowFrom : [];
24
- if (allowFrom.length > 0 || groupAllowFrom.length > 0) {
25
- return;
26
- }
27
- holder.groupAllowFrom = params.storeAllowFrom;
28
- params.changes.push(`${prefix}groupAllowFrom=pairing-store`);
29
- changed = true;
30
- };
31
-
32
- maybeApply("channels.whatsapp.", section);
33
-
34
- const accounts = section.accounts;
35
- if (accounts && typeof accounts === "object") {
36
- for (const [accountId, accountValue] of Object.entries(accounts)) {
37
- if (!accountValue || typeof accountValue !== "object") {
38
- continue;
39
- }
40
- maybeApply(
41
- `channels.whatsapp.accounts.${accountId}.`,
42
- accountValue as Record<string, unknown>,
43
- );
44
- }
45
- }
46
-
47
- return changed ? next : params.cfg;
48
- }
49
-
50
- export async function applyWhatsAppSecurityConfigFixes(params: {
51
- cfg: OpenClawConfig;
52
- env: NodeJS.ProcessEnv;
53
- }): Promise<ChannelDoctorConfigMutation> {
54
- const fromStore = await readChannelAllowFromStore(
55
- "whatsapp",
56
- params.env,
57
- DEFAULT_ACCOUNT_ID,
58
- ).catch(() => []);
59
- const normalized = Array.from(new Set(fromStore.map((entry) => entry.trim()))).filter(Boolean);
60
- if (normalized.length === 0) {
61
- return { config: params.cfg, changes: [] };
62
- }
63
-
64
- const changes: string[] = [];
65
- const config = applyGroupAllowFromFromStore({
66
- cfg: params.cfg,
67
- storeAllowFrom: normalized,
68
- changes,
69
- });
70
- return { config, changes };
71
- }