@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,400 +0,0 @@
1
- import "./monitor-inbox.test-harness.js";
2
- import { describe, expect, it, vi } from "vitest";
3
- import {
4
- buildNotifyMessageUpsert,
5
- expectPairingPromptSent,
6
- installWebMonitorInboxUnitTestHooks,
7
- mockLoadConfig,
8
- settleInboundWork,
9
- startInboxMonitor,
10
- upsertPairingRequestMock,
11
- waitForMessageCalls,
12
- } from "./monitor-inbox.test-harness.js";
13
-
14
- const nowSeconds = (offsetMs = 0) => Math.floor((Date.now() + offsetMs) / 1000);
15
- const DEFAULT_MESSAGES_CFG = {
16
- messagePrefix: undefined,
17
- responsePrefix: undefined,
18
- } as const;
19
-
20
- function createAllowListConfig(allowFrom: string[]) {
21
- return {
22
- channels: {
23
- whatsapp: {
24
- allowFrom,
25
- },
26
- },
27
- messages: DEFAULT_MESSAGES_CFG,
28
- };
29
- }
30
-
31
- async function openInboxMonitor(onMessage = vi.fn()) {
32
- const { listener, sock } = await startInboxMonitor(onMessage);
33
- return { onMessage, listener, sock };
34
- }
35
-
36
- async function expectOutboundDmSkipsPairing(params: {
37
- selfChatMode: boolean;
38
- messageId: string;
39
- body: string;
40
- }) {
41
- mockLoadConfig.mockReturnValue({
42
- channels: {
43
- whatsapp: {
44
- dmPolicy: "pairing",
45
- selfChatMode: params.selfChatMode,
46
- },
47
- },
48
- messages: DEFAULT_MESSAGES_CFG,
49
- });
50
-
51
- const onMessage = vi.fn();
52
- const { listener, sock } = await startInboxMonitor(onMessage);
53
-
54
- try {
55
- sock.ev.emit("messages.upsert", {
56
- type: "notify",
57
- messages: [
58
- {
59
- key: {
60
- id: params.messageId,
61
- fromMe: true,
62
- remoteJid: "999@s.whatsapp.net",
63
- },
64
- message: { conversation: params.body },
65
- messageTimestamp: nowSeconds(),
66
- },
67
- ],
68
- });
69
- await settleInboundWork();
70
-
71
- expect(onMessage).not.toHaveBeenCalled();
72
- expect(upsertPairingRequestMock).not.toHaveBeenCalled();
73
- expect(sock.sendMessage).not.toHaveBeenCalled();
74
- } finally {
75
- mockLoadConfig.mockReturnValue({
76
- channels: { whatsapp: { allowFrom: ["*"] } },
77
- messages: DEFAULT_MESSAGES_CFG,
78
- });
79
- await listener.close();
80
- }
81
- }
82
-
83
- describe("web monitor inbox", () => {
84
- installWebMonitorInboxUnitTestHooks();
85
-
86
- it("allows messages from senders in allowFrom list", async () => {
87
- mockLoadConfig.mockReturnValue(createAllowListConfig(["+111", "+999"]));
88
-
89
- const { onMessage, listener, sock } = await openInboxMonitor();
90
-
91
- const upsert = buildNotifyMessageUpsert({
92
- id: "auth1",
93
- remoteJid: "999@s.whatsapp.net",
94
- text: "authorized message",
95
- timestamp: nowSeconds(60_000),
96
- });
97
-
98
- sock.ev.emit("messages.upsert", upsert);
99
- await waitForMessageCalls(onMessage, 1);
100
-
101
- // Should call onMessage for authorized senders
102
- expect(onMessage).toHaveBeenCalledWith(
103
- expect.objectContaining({
104
- body: "authorized message",
105
- from: "+999",
106
- senderE164: "+999",
107
- }),
108
- );
109
-
110
- await listener.close();
111
- });
112
-
113
- it("allows same-phone messages even if not in allowFrom", async () => {
114
- // Same-phone mode: when from === selfJid, should always be allowed
115
- // This allows users to message themselves even with restrictive allowFrom
116
- mockLoadConfig.mockReturnValue(createAllowListConfig(["+111"]));
117
-
118
- const { onMessage, listener, sock } = await openInboxMonitor();
119
-
120
- // Message from self (sock.user.id is "123@s.whatsapp.net" in mock)
121
- const upsert = buildNotifyMessageUpsert({
122
- id: "self1",
123
- remoteJid: "123@s.whatsapp.net",
124
- text: "self message",
125
- timestamp: nowSeconds(60_000),
126
- });
127
-
128
- sock.ev.emit("messages.upsert", upsert);
129
- await waitForMessageCalls(onMessage, 1);
130
-
131
- // Should allow self-messages even if not in allowFrom
132
- expect(onMessage).toHaveBeenCalledWith(
133
- expect.objectContaining({ body: "self message", from: "+123" }),
134
- );
135
-
136
- await listener.close();
137
- });
138
-
139
- it("locks down when no config is present (pairing for unknown senders)", async () => {
140
- // No config file => locked-down defaults apply (pairing for unknown senders)
141
- mockLoadConfig.mockReturnValue({});
142
- upsertPairingRequestMock
143
- .mockResolvedValueOnce({ code: "PAIRCODE", created: true })
144
- .mockResolvedValueOnce({ code: "PAIRCODE", created: false });
145
-
146
- const { onMessage, listener, sock } = await openInboxMonitor();
147
-
148
- // Message from someone else should be blocked
149
- const upsertBlocked = buildNotifyMessageUpsert({
150
- id: "no-config-1",
151
- remoteJid: "999@s.whatsapp.net",
152
- text: "ping",
153
- timestamp: nowSeconds(),
154
- });
155
-
156
- sock.ev.emit("messages.upsert", upsertBlocked);
157
- await vi.waitFor(
158
- () => {
159
- expect(sock.sendMessage).toHaveBeenCalledTimes(1);
160
- },
161
- { timeout: 5_000, interval: 5 },
162
- );
163
- expect(onMessage).not.toHaveBeenCalled();
164
- expectPairingPromptSent(sock, "999@s.whatsapp.net", "+999");
165
-
166
- const upsertBlockedAgain = buildNotifyMessageUpsert({
167
- id: "no-config-1b",
168
- remoteJid: "999@s.whatsapp.net",
169
- text: "ping again",
170
- timestamp: nowSeconds(),
171
- });
172
-
173
- sock.ev.emit("messages.upsert", upsertBlockedAgain);
174
- await settleInboundWork();
175
- expect(onMessage).not.toHaveBeenCalled();
176
- expect(sock.sendMessage).toHaveBeenCalledTimes(1);
177
-
178
- // Message from self should be allowed
179
- const upsertSelf = buildNotifyMessageUpsert({
180
- id: "no-config-2",
181
- remoteJid: "123@s.whatsapp.net",
182
- text: "self ping",
183
- timestamp: nowSeconds(),
184
- });
185
-
186
- sock.ev.emit("messages.upsert", upsertSelf);
187
- await waitForMessageCalls(onMessage, 1);
188
-
189
- expect(onMessage).toHaveBeenCalledTimes(1);
190
- expect(onMessage).toHaveBeenCalledWith(
191
- expect.objectContaining({
192
- body: "self ping",
193
- from: "+123",
194
- to: "+123",
195
- }),
196
- );
197
-
198
- await listener.close();
199
- });
200
-
201
- it("skips pairing replies for outbound DMs in same-phone mode", async () => {
202
- await expectOutboundDmSkipsPairing({
203
- selfChatMode: true,
204
- messageId: "fromme-1",
205
- body: "hello",
206
- });
207
- });
208
-
209
- it("skips pairing replies for outbound DMs when same-phone mode is disabled", async () => {
210
- await expectOutboundDmSkipsPairing({
211
- selfChatMode: false,
212
- messageId: "fromme-2",
213
- body: "hello again",
214
- });
215
- });
216
-
217
- it("allows owner fromMe group commands when they were not sent by the gateway", async () => {
218
- mockLoadConfig.mockReturnValue({
219
- channels: {
220
- whatsapp: {
221
- groupPolicy: "open",
222
- allowFrom: ["+123"],
223
- },
224
- },
225
- messages: DEFAULT_MESSAGES_CFG,
226
- });
227
-
228
- const { onMessage, listener, sock } = await openInboxMonitor();
229
-
230
- sock.ev.emit("messages.upsert", {
231
- type: "notify",
232
- messages: [
233
- {
234
- key: {
235
- id: "owner-group-1",
236
- fromMe: true,
237
- remoteJid: "120363@g.us",
238
- participant: "123@s.whatsapp.net",
239
- },
240
- message: { conversation: "/status" },
241
- messageTimestamp: nowSeconds(),
242
- pushName: "Owner",
243
- },
244
- ],
245
- });
246
- await waitForMessageCalls(onMessage, 1);
247
-
248
- expect(onMessage).toHaveBeenCalledWith(
249
- expect.objectContaining({
250
- body: "/status",
251
- chatType: "group",
252
- from: "120363@g.us",
253
- fromMe: true,
254
- senderE164: "+123",
255
- }),
256
- );
257
-
258
- await listener.close();
259
- });
260
-
261
- it("filters group fromMe echoes only when the gateway sent the matching message id", async () => {
262
- mockLoadConfig.mockReturnValue({
263
- channels: {
264
- whatsapp: {
265
- groupPolicy: "open",
266
- allowFrom: ["+123"],
267
- },
268
- },
269
- messages: DEFAULT_MESSAGES_CFG,
270
- });
271
-
272
- const onMessage = vi.fn();
273
- const { listener, sock } = await startInboxMonitor(onMessage);
274
-
275
- sock.sendMessage.mockResolvedValueOnce({ key: { id: "bot-group-echo-1" } });
276
- await listener.sendMessage("120363@g.us", "gateway echo candidate");
277
-
278
- sock.ev.emit("messages.upsert", {
279
- type: "notify",
280
- messages: [
281
- {
282
- key: {
283
- id: "bot-group-echo-1",
284
- fromMe: true,
285
- remoteJid: "120363@g.us",
286
- participant: "123@s.whatsapp.net",
287
- },
288
- message: { conversation: "gateway echo candidate" },
289
- messageTimestamp: nowSeconds(),
290
- pushName: "Owner",
291
- },
292
- ],
293
- });
294
- await settleInboundWork();
295
-
296
- expect(onMessage).not.toHaveBeenCalled();
297
-
298
- await listener.close();
299
- });
300
-
301
- it("filters self-chat DM fromMe echoes when the gateway sent the matching message id", async () => {
302
- mockLoadConfig.mockReturnValue({
303
- channels: {
304
- whatsapp: {
305
- selfChatMode: true,
306
- allowFrom: ["+123"],
307
- },
308
- },
309
- messages: DEFAULT_MESSAGES_CFG,
310
- });
311
-
312
- const onMessage = vi.fn();
313
- const { listener, sock } = await startInboxMonitor(onMessage);
314
-
315
- sock.sendMessage.mockResolvedValueOnce({ key: { id: "bot-dm-echo-1" } });
316
- await listener.sendMessage("123@s.whatsapp.net", "self-chat reply");
317
-
318
- sock.ev.emit("messages.upsert", {
319
- type: "notify",
320
- messages: [
321
- {
322
- key: {
323
- id: "bot-dm-echo-1",
324
- fromMe: true,
325
- remoteJid: "123@s.whatsapp.net",
326
- },
327
- message: { conversation: "self-chat reply" },
328
- messageTimestamp: nowSeconds(),
329
- pushName: "Owner",
330
- },
331
- ],
332
- });
333
- await settleInboundWork();
334
-
335
- expect(onMessage).not.toHaveBeenCalled();
336
-
337
- await listener.close();
338
- });
339
-
340
- it("handles append messages by marking them read but skipping auto-reply", async () => {
341
- const { onMessage, listener, sock } = await openInboxMonitor();
342
- const staleTs = Math.floor(Date.now() / 1000) - 300;
343
-
344
- const upsert = {
345
- type: "append",
346
- messages: [
347
- {
348
- key: {
349
- id: "history1",
350
- fromMe: false,
351
- remoteJid: "999@s.whatsapp.net",
352
- },
353
- message: { conversation: "old message" },
354
- messageTimestamp: staleTs,
355
- pushName: "History Sender",
356
- },
357
- ],
358
- };
359
-
360
- sock.ev.emit("messages.upsert", upsert);
361
- await vi.waitFor(
362
- () => {
363
- expect(sock.readMessages).toHaveBeenCalledWith([
364
- {
365
- remoteJid: "999@s.whatsapp.net",
366
- id: "history1",
367
- participant: undefined,
368
- fromMe: false,
369
- },
370
- ]);
371
- },
372
- { timeout: 5_000, interval: 5 },
373
- );
374
-
375
- // Verify it WAS NOT passed to onMessage
376
- expect(onMessage).not.toHaveBeenCalled();
377
-
378
- await listener.close();
379
- });
380
-
381
- it("normalizes participant phone numbers to JIDs in sendReaction", async () => {
382
- const { listener, sock } = await startInboxMonitor(vi.fn());
383
-
384
- await listener.sendReaction("12345@g.us", "msg123", "👍", false, "+6421000000");
385
-
386
- expect(sock.sendMessage).toHaveBeenCalledWith("12345@g.us", {
387
- react: {
388
- text: "👍",
389
- key: {
390
- remoteJid: "12345@g.us",
391
- id: "msg123",
392
- fromMe: false,
393
- participant: "6421000000@s.whatsapp.net",
394
- },
395
- },
396
- });
397
-
398
- await listener.close();
399
- });
400
- });
@@ -1,133 +0,0 @@
1
- import "./monitor-inbox.test-harness.js";
2
- import { describe, expect, it, vi } from "vitest";
3
- import {
4
- installWebMonitorInboxUnitTestHooks,
5
- settleInboundWork,
6
- startInboxMonitor,
7
- waitForMessageCalls,
8
- } from "./monitor-inbox.test-harness.js";
9
-
10
- describe("append upsert handling (#20952)", () => {
11
- installWebMonitorInboxUnitTestHooks();
12
-
13
- it("processes recent append messages (within 60s of connect)", async () => {
14
- const onMessage = vi.fn(async () => {});
15
- const { listener, sock } = await startInboxMonitor(onMessage);
16
-
17
- // Timestamp ~5 seconds ago — recent, should be processed.
18
- const recentTs = Math.floor(Date.now() / 1000) - 5;
19
- sock.ev.emit("messages.upsert", {
20
- type: "append",
21
- messages: [
22
- {
23
- key: { id: "recent-1", fromMe: false, remoteJid: "120363@g.us" },
24
- message: { conversation: "hello from group" },
25
- messageTimestamp: recentTs,
26
- pushName: "Tester",
27
- },
28
- ],
29
- });
30
- await waitForMessageCalls(onMessage, 1);
31
-
32
- expect(onMessage).toHaveBeenCalledTimes(1);
33
-
34
- await listener.close();
35
- });
36
-
37
- it("skips stale append messages (older than 60s before connect)", async () => {
38
- const onMessage = vi.fn(async () => {});
39
- const { listener, sock } = await startInboxMonitor(onMessage);
40
-
41
- // Timestamp 5 minutes ago — stale history sync, should be skipped.
42
- const staleTs = Math.floor(Date.now() / 1000) - 300;
43
- sock.ev.emit("messages.upsert", {
44
- type: "append",
45
- messages: [
46
- {
47
- key: { id: "stale-1", fromMe: false, remoteJid: "120363@g.us" },
48
- message: { conversation: "old history sync" },
49
- messageTimestamp: staleTs,
50
- pushName: "OldTester",
51
- },
52
- ],
53
- });
54
- await settleInboundWork();
55
-
56
- expect(onMessage).not.toHaveBeenCalled();
57
-
58
- await listener.close();
59
- });
60
-
61
- it("skips append messages with NaN/non-finite timestamps", async () => {
62
- const onMessage = vi.fn(async () => {});
63
- const { listener, sock } = await startInboxMonitor(onMessage);
64
-
65
- // NaN timestamp should be treated as 0 (stale) and skipped.
66
- sock.ev.emit("messages.upsert", {
67
- type: "append",
68
- messages: [
69
- {
70
- key: { id: "nan-1", fromMe: false, remoteJid: "120363@g.us" },
71
- message: { conversation: "bad timestamp" },
72
- messageTimestamp: Number.NaN,
73
- pushName: "BadTs",
74
- },
75
- ],
76
- });
77
- await settleInboundWork();
78
-
79
- expect(onMessage).not.toHaveBeenCalled();
80
-
81
- await listener.close();
82
- });
83
-
84
- it("handles Long-like protobuf timestamps correctly", async () => {
85
- const onMessage = vi.fn(async () => {});
86
- const { listener, sock } = await startInboxMonitor(onMessage);
87
-
88
- // Baileys can deliver messageTimestamp as a Long object (from protobufjs).
89
- // Number(longObj) calls valueOf() and returns the numeric value.
90
- const recentTs = Math.floor(Date.now() / 1000) - 5;
91
- const longLike = { low: recentTs, high: 0, unsigned: true, valueOf: () => recentTs };
92
- sock.ev.emit("messages.upsert", {
93
- type: "append",
94
- messages: [
95
- {
96
- key: { id: "long-1", fromMe: false, remoteJid: "120363@g.us" },
97
- message: { conversation: "long timestamp" },
98
- messageTimestamp: longLike,
99
- pushName: "LongTs",
100
- },
101
- ],
102
- });
103
- await waitForMessageCalls(onMessage, 1);
104
-
105
- expect(onMessage).toHaveBeenCalledTimes(1);
106
-
107
- await listener.close();
108
- });
109
-
110
- it("always processes notify messages regardless of timestamp", async () => {
111
- const onMessage = vi.fn(async () => {});
112
- const { listener, sock } = await startInboxMonitor(onMessage);
113
-
114
- // Very old timestamp but type=notify — should always be processed.
115
- const oldTs = Math.floor(Date.now() / 1000) - 86400;
116
- sock.ev.emit("messages.upsert", {
117
- type: "notify",
118
- messages: [
119
- {
120
- key: { id: "notify-1", fromMe: false, remoteJid: "999@s.whatsapp.net" },
121
- message: { conversation: "normal message" },
122
- messageTimestamp: oldTs,
123
- pushName: "User",
124
- },
125
- ],
126
- });
127
- await waitForMessageCalls(onMessage, 1);
128
-
129
- expect(onMessage).toHaveBeenCalledTimes(1);
130
-
131
- await listener.close();
132
- });
133
- });
@@ -1,5 +0,0 @@
1
- import "./monitor-inbox.allows-messages-from-senders-allowfrom-list.test-support.js";
2
- import "./monitor-inbox.append-upsert.test-support.js";
3
- import "./monitor-inbox.blocks-messages-from-unauthorized-senders-not-allowfrom.test-support.js";
4
- import "./monitor-inbox.captures-media-path-image-messages.test-support.js";
5
- import "./monitor-inbox.streams-inbound-messages.test-support.js";