@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,354 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from "vitest";
2
-
3
- const events: string[] = [];
4
- const transcribeFirstAudioMock = vi.fn();
5
- const maybeSendAckReactionMock = vi.fn();
6
- const processMessageMock = vi.fn();
7
- const maybeBroadcastMessageMock = vi.fn();
8
- const ackReactionHandle = {
9
- ackReactionPromise: Promise.resolve(true),
10
- ackReactionValue: "👀",
11
- remove: vi.fn(async () => undefined),
12
- };
13
- const applyGroupGatingMock = vi.fn();
14
-
15
- vi.mock("./audio-preflight.runtime.js", () => ({
16
- transcribeFirstAudio: (...args: unknown[]) => transcribeFirstAudioMock(...args),
17
- }));
18
-
19
- vi.mock("./ack-reaction.js", () => ({
20
- maybeSendAckReaction: (...args: unknown[]) => maybeSendAckReactionMock(...args),
21
- }));
22
-
23
- vi.mock("./process-message.js", () => ({
24
- processMessage: (...args: unknown[]) => processMessageMock(...args),
25
- }));
26
-
27
- vi.mock("./broadcast.js", () => ({
28
- maybeBroadcastMessage: (...args: unknown[]) => maybeBroadcastMessageMock(...args),
29
- }));
30
-
31
- vi.mock("./group-gating.js", () => ({
32
- applyGroupGating: (...args: unknown[]) => applyGroupGatingMock(...args),
33
- }));
34
-
35
- vi.mock("./last-route.js", () => ({
36
- updateLastRouteInBackground: () => {},
37
- }));
38
-
39
- vi.mock("./peer.js", () => ({
40
- resolvePeerId: (msg: { from: string }) => msg.from,
41
- }));
42
-
43
- vi.mock("../config.runtime.js", () => ({
44
- getRuntimeConfig: () => ({
45
- channels: {
46
- whatsapp: {
47
- ackReaction: { enabled: true },
48
- },
49
- },
50
- }),
51
- }));
52
-
53
- vi.mock("../../group-session-key.js", () => ({
54
- resolveWhatsAppGroupSessionRoute: (route: unknown) => route,
55
- }));
56
-
57
- vi.mock("../../identity.js", () => ({
58
- getPrimaryIdentityId: () => undefined,
59
- getSenderIdentity: () => ({ e164: "+15550000002", name: "Alice" }),
60
- }));
61
-
62
- vi.mock("../../text-runtime.js", () => ({
63
- normalizeE164: (value: string) => value,
64
- }));
65
-
66
- vi.mock("openclaw/plugin-sdk/routing", () => ({
67
- buildGroupHistoryKey: () => "group-key",
68
- resolveAgentRoute: () => ({
69
- agentId: "main",
70
- accountId: "default",
71
- sessionKey: "agent:main:whatsapp:+15550000002",
72
- mainSessionKey: "agent:main:main",
73
- }),
74
- }));
75
-
76
- import type { WebInboundMsg } from "../types.js";
77
- import { createWebOnMessageHandler } from "./on-message.js";
78
-
79
- function makeAudioMsg(): WebInboundMsg {
80
- return {
81
- id: "msg-1",
82
- from: "+15550000002",
83
- to: "+15550000001",
84
- accessControlPassed: true,
85
- body: "<media:audio>",
86
- chatType: "direct",
87
- mediaType: "audio/ogg; codecs=opus",
88
- mediaPath: "/tmp/voice.ogg",
89
- timestamp: 1700000000,
90
- accountId: "default",
91
- } as WebInboundMsg;
92
- }
93
-
94
- function makeGroupAudioMsg(): WebInboundMsg {
95
- return {
96
- ...makeAudioMsg(),
97
- from: "1203630@g.us",
98
- chatId: "1203630@g.us",
99
- chatType: "group",
100
- conversationId: "1203630@g.us",
101
- wasMentioned: false,
102
- } as WebInboundMsg;
103
- }
104
-
105
- function makeEchoTracker() {
106
- return {
107
- has: () => false,
108
- forget: () => {},
109
- rememberText: () => {},
110
- buildCombinedKey: (p: { combinedBody: string }) => p.combinedBody,
111
- };
112
- }
113
-
114
- describe("createWebOnMessageHandler audio preflight", () => {
115
- beforeEach(() => {
116
- events.length = 0;
117
- maybeBroadcastMessageMock.mockReset();
118
- maybeBroadcastMessageMock.mockImplementation(async () => false);
119
- maybeSendAckReactionMock.mockReset();
120
- maybeSendAckReactionMock.mockImplementation(async () => {
121
- events.push("ack");
122
- return ackReactionHandle;
123
- });
124
- transcribeFirstAudioMock.mockReset();
125
- transcribeFirstAudioMock.mockImplementation(async () => {
126
- events.push("stt");
127
- return "transcribed voice note";
128
- });
129
- processMessageMock.mockReset();
130
- processMessageMock.mockResolvedValue(true);
131
- applyGroupGatingMock.mockReset();
132
- applyGroupGatingMock.mockResolvedValue({ shouldProcess: true });
133
- });
134
-
135
- it("sends ack reaction before audio preflight for voice notes", async () => {
136
- const handler = createWebOnMessageHandler({
137
- cfg: {
138
- channels: {
139
- whatsapp: {
140
- ackReaction: { enabled: true },
141
- },
142
- },
143
- } as never,
144
- verbose: false,
145
- connectionId: "conn-1",
146
- maxMediaBytes: 1024 * 1024,
147
- groupHistoryLimit: 20,
148
- groupHistories: new Map(),
149
- groupMemberNames: new Map(),
150
- echoTracker: makeEchoTracker() as never,
151
- backgroundTasks: new Set(),
152
- replyResolver: vi.fn() as never,
153
- replyLogger: {
154
- info: () => {},
155
- warn: () => {},
156
- debug: () => {},
157
- error: () => {},
158
- } as never,
159
- baseMentionConfig: {} as never,
160
- account: { authDir: "/tmp/auth", accountId: "default" },
161
- });
162
-
163
- await handler(makeAudioMsg());
164
-
165
- expect(events).toEqual(["ack", "stt"]);
166
- expect(processMessageMock).toHaveBeenCalledWith(
167
- expect.objectContaining({
168
- preflightAudioTranscript: "transcribed voice note",
169
- ackAlreadySent: true,
170
- ackReaction: ackReactionHandle,
171
- }),
172
- );
173
- });
174
-
175
- it("skips early DM ack/preflight when access-control was not explicitly passed through", async () => {
176
- const handler = createWebOnMessageHandler({
177
- cfg: {
178
- channels: {
179
- whatsapp: {
180
- ackReaction: { enabled: true },
181
- },
182
- },
183
- } as never,
184
- verbose: false,
185
- connectionId: "conn-1",
186
- maxMediaBytes: 1024 * 1024,
187
- groupHistoryLimit: 20,
188
- groupHistories: new Map(),
189
- groupMemberNames: new Map(),
190
- echoTracker: makeEchoTracker() as never,
191
- backgroundTasks: new Set(),
192
- replyResolver: vi.fn() as never,
193
- replyLogger: {
194
- info: () => {},
195
- warn: () => {},
196
- debug: () => {},
197
- error: () => {},
198
- } as never,
199
- baseMentionConfig: {} as never,
200
- account: { authDir: "/tmp/auth", accountId: "default" },
201
- });
202
-
203
- await handler({ ...makeAudioMsg(), accessControlPassed: undefined });
204
-
205
- expect(events).toEqual([]);
206
- expect(transcribeFirstAudioMock).not.toHaveBeenCalled();
207
- expect(maybeSendAckReactionMock).not.toHaveBeenCalled();
208
- expect(processMessageMock).toHaveBeenCalledWith(
209
- expect.not.objectContaining({
210
- preflightAudioTranscript: expect.anything(),
211
- ackAlreadySent: true,
212
- }),
213
- );
214
- });
215
-
216
- it("preserves per-agent ack checks for group broadcast voice notes", async () => {
217
- maybeBroadcastMessageMock.mockImplementation(
218
- async (params: {
219
- ackAlreadySent?: boolean;
220
- ackReaction?: unknown;
221
- preflightAudioTranscript?: string | null;
222
- }) => {
223
- expect(params.preflightAudioTranscript).toBe("transcribed voice note");
224
- expect(params.ackAlreadySent).toBeUndefined();
225
- expect(params.ackReaction).toBeUndefined();
226
- return true;
227
- },
228
- );
229
- const handler = createWebOnMessageHandler({
230
- cfg: {
231
- channels: {
232
- whatsapp: {
233
- ackReaction: { enabled: true },
234
- },
235
- },
236
- broadcast: {
237
- "1203630@g.us": ["main", "backup"],
238
- },
239
- } as never,
240
- verbose: false,
241
- connectionId: "conn-1",
242
- maxMediaBytes: 1024 * 1024,
243
- groupHistoryLimit: 20,
244
- groupHistories: new Map(),
245
- groupMemberNames: new Map(),
246
- echoTracker: makeEchoTracker() as never,
247
- backgroundTasks: new Set(),
248
- replyResolver: vi.fn() as never,
249
- replyLogger: {
250
- info: () => {},
251
- warn: () => {},
252
- debug: () => {},
253
- error: () => {},
254
- } as never,
255
- baseMentionConfig: {} as never,
256
- account: { authDir: "/tmp/auth", accountId: "default" },
257
- });
258
-
259
- await handler(makeGroupAudioMsg());
260
-
261
- expect(events).toEqual(["ack", "stt"]);
262
- expect(processMessageMock).not.toHaveBeenCalled();
263
- });
264
-
265
- it("uses group voice transcript for mention gating before dispatch", async () => {
266
- applyGroupGatingMock
267
- .mockResolvedValueOnce({ shouldProcess: false, needsMentionText: true })
268
- .mockResolvedValueOnce({ shouldProcess: true });
269
- const handler = createWebOnMessageHandler({
270
- cfg: {
271
- channels: {
272
- whatsapp: {
273
- ackReaction: { enabled: true },
274
- },
275
- },
276
- } as never,
277
- verbose: false,
278
- connectionId: "conn-1",
279
- maxMediaBytes: 1024 * 1024,
280
- groupHistoryLimit: 20,
281
- groupHistories: new Map(),
282
- groupMemberNames: new Map(),
283
- echoTracker: makeEchoTracker() as never,
284
- backgroundTasks: new Set(),
285
- replyResolver: vi.fn() as never,
286
- replyLogger: {
287
- info: () => {},
288
- warn: () => {},
289
- debug: () => {},
290
- error: () => {},
291
- } as never,
292
- baseMentionConfig: {} as never,
293
- account: { authDir: "/tmp/auth", accountId: "default" },
294
- });
295
-
296
- await handler(makeGroupAudioMsg());
297
-
298
- expect(applyGroupGatingMock).toHaveBeenNthCalledWith(
299
- 1,
300
- expect.objectContaining({
301
- deferMissingMention: true,
302
- }),
303
- );
304
- expect(events).toEqual(["ack", "stt"]);
305
- expect(applyGroupGatingMock).toHaveBeenNthCalledWith(
306
- 2,
307
- expect.objectContaining({
308
- mentionText: "transcribed voice note",
309
- }),
310
- );
311
- expect(processMessageMock).toHaveBeenCalledWith(
312
- expect.objectContaining({
313
- preflightAudioTranscript: "transcribed voice note",
314
- ackAlreadySent: true,
315
- }),
316
- );
317
- });
318
-
319
- it("does not transcribe group voice when policy gating rejects before mention", async () => {
320
- applyGroupGatingMock.mockResolvedValueOnce({ shouldProcess: false });
321
- const handler = createWebOnMessageHandler({
322
- cfg: {
323
- channels: {
324
- whatsapp: {
325
- ackReaction: { enabled: true },
326
- },
327
- },
328
- } as never,
329
- verbose: false,
330
- connectionId: "conn-1",
331
- maxMediaBytes: 1024 * 1024,
332
- groupHistoryLimit: 20,
333
- groupHistories: new Map(),
334
- groupMemberNames: new Map(),
335
- echoTracker: makeEchoTracker() as never,
336
- backgroundTasks: new Set(),
337
- replyResolver: vi.fn() as never,
338
- replyLogger: {
339
- info: () => {},
340
- warn: () => {},
341
- debug: () => {},
342
- error: () => {},
343
- } as never,
344
- baseMentionConfig: {} as never,
345
- account: { authDir: "/tmp/auth", accountId: "default" },
346
- });
347
-
348
- await handler(makeGroupAudioMsg());
349
-
350
- expect(transcribeFirstAudioMock).not.toHaveBeenCalled();
351
- expect(maybeSendAckReactionMock).not.toHaveBeenCalled();
352
- expect(processMessageMock).not.toHaveBeenCalled();
353
- });
354
- });
@@ -1,291 +0,0 @@
1
- import type { AckReactionHandle } from "openclaw/plugin-sdk/channel-feedback";
2
- import type { getReplyFromConfig } from "openclaw/plugin-sdk/reply-runtime";
3
- import type { MsgContext } from "openclaw/plugin-sdk/reply-runtime";
4
- import { resolveAgentRoute } from "openclaw/plugin-sdk/routing";
5
- import { buildGroupHistoryKey } from "openclaw/plugin-sdk/routing";
6
- import { logVerbose } from "openclaw/plugin-sdk/runtime-env";
7
- import { resolveWhatsAppGroupSessionRoute } from "../../group-session-key.js";
8
- import { getPrimaryIdentityId, getSenderIdentity } from "../../identity.js";
9
- import { normalizeE164 } from "../../text-runtime.js";
10
- import { getRuntimeConfig } from "../config.runtime.js";
11
- import type { MentionConfig } from "../mentions.js";
12
- import type { WebInboundMsg } from "../types.js";
13
- import { maybeSendAckReaction } from "./ack-reaction.js";
14
- import { maybeBroadcastMessage } from "./broadcast.js";
15
- import type { EchoTracker } from "./echo.js";
16
- import type { GroupHistoryEntry } from "./group-gating.js";
17
- import { applyGroupGating } from "./group-gating.js";
18
- import { updateLastRouteInBackground } from "./last-route.js";
19
- import { resolvePeerId } from "./peer.js";
20
- import { processMessage } from "./process-message.js";
21
-
22
- export function createWebOnMessageHandler(params: {
23
- cfg: ReturnType<typeof getRuntimeConfig>;
24
- verbose: boolean;
25
- connectionId: string;
26
- maxMediaBytes: number;
27
- groupHistoryLimit: number;
28
- groupHistories: Map<string, GroupHistoryEntry[]>;
29
- groupMemberNames: Map<string, Map<string, string>>;
30
- echoTracker: EchoTracker;
31
- backgroundTasks: Set<Promise<unknown>>;
32
- replyResolver: typeof getReplyFromConfig;
33
- replyLogger: ReturnType<(typeof import("openclaw/plugin-sdk/runtime-env"))["getChildLogger"]>;
34
- baseMentionConfig: MentionConfig;
35
- account: { authDir?: string; accountId?: string; selfChatMode?: boolean };
36
- }) {
37
- const processForRoute = async (
38
- msg: WebInboundMsg,
39
- route: ReturnType<typeof resolveAgentRoute>,
40
- groupHistoryKey: string,
41
- opts?: {
42
- groupHistory?: GroupHistoryEntry[];
43
- suppressGroupHistoryClear?: boolean;
44
- preflightAudioTranscript?: string | null;
45
- ackAlreadySent?: boolean;
46
- ackReaction?: AckReactionHandle | null;
47
- },
48
- ) => {
49
- const processParams: Parameters<typeof processMessage>[0] = {
50
- cfg: params.cfg,
51
- msg,
52
- route,
53
- groupHistoryKey,
54
- groupHistories: params.groupHistories,
55
- groupMemberNames: params.groupMemberNames,
56
- connectionId: params.connectionId,
57
- verbose: params.verbose,
58
- maxMediaBytes: params.maxMediaBytes,
59
- replyResolver: params.replyResolver,
60
- replyLogger: params.replyLogger,
61
- backgroundTasks: params.backgroundTasks,
62
- rememberSentText: params.echoTracker.rememberText,
63
- echoHas: params.echoTracker.has,
64
- echoForget: params.echoTracker.forget,
65
- buildCombinedEchoKey: params.echoTracker.buildCombinedKey,
66
- };
67
- if (opts?.groupHistory !== undefined) {
68
- processParams.groupHistory = opts.groupHistory;
69
- }
70
- if (opts?.suppressGroupHistoryClear !== undefined) {
71
- processParams.suppressGroupHistoryClear = opts.suppressGroupHistoryClear;
72
- }
73
- if (opts?.preflightAudioTranscript !== undefined) {
74
- processParams.preflightAudioTranscript = opts.preflightAudioTranscript;
75
- }
76
- if (opts?.ackAlreadySent === true) {
77
- processParams.ackAlreadySent = true;
78
- }
79
- if (opts?.ackReaction !== undefined) {
80
- processParams.ackReaction = opts.ackReaction;
81
- }
82
- return processMessage(processParams);
83
- };
84
-
85
- return async (msg: WebInboundMsg) => {
86
- const conversationId = msg.conversationId ?? msg.from;
87
- const peerId = resolvePeerId(msg);
88
- // Fresh config for bindings lookup; other routing inputs are payload-derived.
89
- const baseRoute = resolveAgentRoute({
90
- cfg: getRuntimeConfig(),
91
- channel: "whatsapp",
92
- accountId: msg.accountId,
93
- peer: {
94
- kind: msg.chatType === "group" ? "group" : "direct",
95
- id: peerId,
96
- },
97
- });
98
- const route =
99
- msg.chatType === "group" ? resolveWhatsAppGroupSessionRoute(baseRoute) : baseRoute;
100
- const groupHistoryKey =
101
- msg.chatType === "group"
102
- ? buildGroupHistoryKey({
103
- channel: "whatsapp",
104
- accountId: route.accountId,
105
- peerKind: "group",
106
- peerId,
107
- })
108
- : route.sessionKey;
109
-
110
- // Same-phone mode logging retained
111
- if (msg.from === msg.to) {
112
- logVerbose(`📱 Same-phone mode detected (from === to: ${msg.from})`);
113
- }
114
-
115
- // Skip if this is a message we just sent (echo detection)
116
- if (params.echoTracker.has(msg.body)) {
117
- logVerbose("Skipping auto-reply: detected echo (message matches recently sent text)");
118
- params.echoTracker.forget(msg.body);
119
- return;
120
- }
121
-
122
- // Preflight audio transcription: run once before broadcast fan-out so all
123
- // agents share the same transcript instead of each making a separate STT call.
124
- // For DMs, only do this on the real inbound path after access-control/pairing
125
- // checks have already passed in inbound/monitor.ts. For groups, the first
126
- // gating pass must approve the group/sender before STT is attempted.
127
- // null = preflight was attempted but produced no transcript (failed / disabled / no audio);
128
- // undefined = preflight was not attempted (non-audio message).
129
- let preflightAudioTranscript: string | null | undefined;
130
- const hasAudioBody =
131
- msg.mediaType?.startsWith("audio/") === true && msg.body === "<media:audio>";
132
- const canRunEarlyAudioPreflight = msg.chatType === "group" || msg.accessControlPassed === true;
133
- let ackAlreadySent = false;
134
- let ackReaction: AckReactionHandle | null = null;
135
- const runAudioPreflightOnce = async () => {
136
- if (
137
- preflightAudioTranscript !== undefined ||
138
- !canRunEarlyAudioPreflight ||
139
- !hasAudioBody ||
140
- !msg.mediaPath
141
- ) {
142
- return;
143
- }
144
- ackReaction = await maybeSendAckReaction({
145
- cfg: params.cfg,
146
- msg,
147
- agentId: route.agentId,
148
- sessionKey: route.sessionKey,
149
- conversationId,
150
- verbose: params.verbose,
151
- accountId: route.accountId,
152
- info: params.replyLogger.info.bind(params.replyLogger),
153
- warn: params.replyLogger.warn.bind(params.replyLogger),
154
- });
155
- ackAlreadySent = ackReaction !== null;
156
- try {
157
- const { transcribeFirstAudio } = await import("./audio-preflight.runtime.js");
158
- // transcribeFirstAudio returns undefined on failure/disabled; store null so
159
- // processMessage knows the attempt was already made and does not retry.
160
- preflightAudioTranscript =
161
- (await transcribeFirstAudio({
162
- ctx: {
163
- MediaPaths: [msg.mediaPath],
164
- MediaTypes: msg.mediaType ? [msg.mediaType] : undefined,
165
- },
166
- cfg: params.cfg,
167
- })) ?? null;
168
- } catch {
169
- // Non-fatal: store null so per-agent retries are suppressed.
170
- preflightAudioTranscript = null;
171
- }
172
- };
173
-
174
- if (msg.chatType === "group") {
175
- const sender = getSenderIdentity(msg);
176
- const metaCtx = {
177
- From: msg.from,
178
- To: msg.to,
179
- SessionKey: route.sessionKey,
180
- AccountId: route.accountId,
181
- ChatType: msg.chatType,
182
- ConversationLabel: conversationId,
183
- GroupSubject: msg.groupSubject,
184
- SenderName: sender.name ?? undefined,
185
- SenderId: getPrimaryIdentityId(sender) ?? undefined,
186
- SenderE164: sender.e164 ?? undefined,
187
- Provider: "whatsapp",
188
- Surface: "whatsapp",
189
- OriginatingChannel: "whatsapp",
190
- OriginatingTo: conversationId,
191
- } satisfies MsgContext;
192
- updateLastRouteInBackground({
193
- cfg: params.cfg,
194
- backgroundTasks: params.backgroundTasks,
195
- storeAgentId: route.agentId,
196
- sessionKey: route.sessionKey,
197
- channel: "whatsapp",
198
- to: conversationId,
199
- accountId: route.accountId,
200
- ctx: metaCtx,
201
- warn: params.replyLogger.warn.bind(params.replyLogger),
202
- });
203
-
204
- let gating = await applyGroupGating({
205
- cfg: params.cfg,
206
- msg,
207
- deferMissingMention: hasAudioBody && Boolean(msg.mediaPath),
208
- conversationId,
209
- groupHistoryKey,
210
- agentId: route.agentId,
211
- sessionKey: route.sessionKey,
212
- baseMentionConfig: params.baseMentionConfig,
213
- authDir: params.account.authDir,
214
- selfChatMode: params.account.selfChatMode,
215
- groupHistories: params.groupHistories,
216
- groupHistoryLimit: params.groupHistoryLimit,
217
- groupMemberNames: params.groupMemberNames,
218
- logVerbose,
219
- replyLogger: params.replyLogger,
220
- });
221
- if (
222
- !gating.shouldProcess &&
223
- "needsMentionText" in gating &&
224
- gating.needsMentionText === true
225
- ) {
226
- await runAudioPreflightOnce();
227
- gating = await applyGroupGating({
228
- cfg: params.cfg,
229
- msg,
230
- ...(typeof preflightAudioTranscript === "string"
231
- ? { mentionText: preflightAudioTranscript }
232
- : {}),
233
- conversationId,
234
- groupHistoryKey,
235
- agentId: route.agentId,
236
- sessionKey: route.sessionKey,
237
- baseMentionConfig: params.baseMentionConfig,
238
- authDir: params.account.authDir,
239
- selfChatMode: params.account.selfChatMode,
240
- groupHistories: params.groupHistories,
241
- groupHistoryLimit: params.groupHistoryLimit,
242
- groupMemberNames: params.groupMemberNames,
243
- logVerbose,
244
- replyLogger: params.replyLogger,
245
- });
246
- }
247
- if (!gating.shouldProcess) {
248
- return;
249
- }
250
- } else {
251
- // Ensure `peerId` for DMs is stable and stored as E.164 when possible.
252
- if (!msg.sender?.e164 && !msg.senderE164 && peerId && peerId.startsWith("+")) {
253
- const normalized = normalizeE164(peerId);
254
- if (normalized) {
255
- msg.sender = { ...msg.sender, e164: normalized };
256
- msg.senderE164 = normalized;
257
- }
258
- }
259
- }
260
-
261
- await runAudioPreflightOnce();
262
-
263
- // Broadcast groups: when we'd reply anyway, run multiple agents.
264
- // Does not bypass group mention/activation gating above.
265
- if (
266
- await maybeBroadcastMessage({
267
- cfg: params.cfg,
268
- msg,
269
- peerId,
270
- route,
271
- groupHistoryKey,
272
- groupHistories: params.groupHistories,
273
- ...(preflightAudioTranscript !== undefined ? { preflightAudioTranscript } : {}),
274
- // Group ack eligibility depends on the target agent/session, so a
275
- // preflight ack attempt on the base route must not suppress downstream
276
- // per-agent checks during broadcast fan-out.
277
- ...(ackAlreadySent && msg.chatType !== "group" ? { ackAlreadySent: true } : {}),
278
- ...(ackReaction && msg.chatType !== "group" ? { ackReaction } : {}),
279
- processMessage: (m, r, k, opts) => processForRoute(m, r, k, opts),
280
- })
281
- ) {
282
- return;
283
- }
284
-
285
- await processForRoute(msg, route, groupHistoryKey, {
286
- ...(preflightAudioTranscript !== undefined ? { preflightAudioTranscript } : {}),
287
- ...(ackAlreadySent ? { ackAlreadySent: true } : {}),
288
- ...(ackReaction ? { ackReaction } : {}),
289
- });
290
- };
291
- }
@@ -1,17 +0,0 @@
1
- import { getSenderIdentity } from "../../identity.js";
2
- import { jidToE164, normalizeE164 } from "../../text-runtime.js";
3
- import type { WebInboundMsg } from "../types.js";
4
-
5
- export function resolvePeerId(msg: WebInboundMsg) {
6
- if (msg.chatType === "group") {
7
- return msg.conversationId ?? msg.from;
8
- }
9
- const sender = getSenderIdentity(msg);
10
- if (sender.e164) {
11
- return normalizeE164(sender.e164) ?? sender.e164;
12
- }
13
- if (msg.from.includes("@")) {
14
- return jidToE164(msg.from) ?? msg.from;
15
- }
16
- return normalizeE164(msg.from) ?? msg.from;
17
- }