@openclaw/whatsapp 2026.5.2 → 2026.5.3-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (302) 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 -339
  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 -319
  220. package/src/inbound/send-api.ts +0 -145
  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 -123
  244. package/src/normalize.ts +0 -7
  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 -288
  265. package/src/resolve-outbound-target.ts +0 -58
  266. package/src/resolve-target.test.ts +0 -120
  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 -534
  273. package/src/send.ts +0 -292
  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.test.ts +0 -41
  278. package/src/session-route.ts +0 -32
  279. package/src/session.runtime.ts +0 -8
  280. package/src/session.test.ts +0 -559
  281. package/src/session.ts +0 -330
  282. package/src/setup-core.ts +0 -52
  283. package/src/setup-finalize.ts +0 -446
  284. package/src/setup-surface.test.ts +0 -367
  285. package/src/setup-surface.ts +0 -69
  286. package/src/setup-test-helpers.ts +0 -216
  287. package/src/shared.ts +0 -291
  288. package/src/socket-timing.test.ts +0 -49
  289. package/src/socket-timing.ts +0 -38
  290. package/src/state-migrations.ts +0 -54
  291. package/src/status-issues.test.ts +0 -137
  292. package/src/status-issues.ts +0 -185
  293. package/src/system-prompt.test.ts +0 -199
  294. package/src/system-prompt.ts +0 -31
  295. package/src/targets-runtime.ts +0 -180
  296. package/src/test-helpers.ts +0 -690
  297. package/src/text-runtime.test.ts +0 -162
  298. package/src/text-runtime.ts +0 -11
  299. package/src/vcard.ts +0 -84
  300. package/targets.ts +0 -5
  301. package/test-api.ts +0 -2
  302. package/tsconfig.json +0 -16
@@ -1,687 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import os from "node:os";
3
- import path from "node:path";
4
- import { resolveAgentRoute } from "openclaw/plugin-sdk/routing";
5
- import { afterEach, beforeEach, describe, expect, it } from "vitest";
6
- import type { WhatsAppSendResult } from "../inbound/send-result.js";
7
- import { buildMentionConfig } from "./mentions.js";
8
- import { applyGroupGating, type GroupHistoryEntry } from "./monitor/group-gating.js";
9
- import { buildInboundLine, formatReplyContext } from "./monitor/message-line.js";
10
- import type { WebInboundMsg } from "./types.js";
11
-
12
- let sessionDir: string | undefined;
13
- let sessionStorePath: string;
14
-
15
- function acceptedSendResult(kind: "media" | "text", id: string): WhatsAppSendResult {
16
- return {
17
- kind,
18
- messageId: id,
19
- messageIds: [id],
20
- keys: [{ id }],
21
- providerAccepted: true,
22
- };
23
- }
24
-
25
- beforeEach(async () => {
26
- sessionDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-group-gating-"));
27
- sessionStorePath = path.join(sessionDir, "sessions.json");
28
- await fs.writeFile(sessionStorePath, "{}");
29
- });
30
-
31
- afterEach(async () => {
32
- if (sessionDir) {
33
- await fs.rm(sessionDir, { recursive: true, force: true });
34
- sessionDir = undefined;
35
- }
36
- });
37
-
38
- const makeConfig = (overrides: Record<string, unknown>) =>
39
- ({
40
- channels: {
41
- whatsapp: {
42
- groupPolicy: "open",
43
- groups: { "*": { requireMention: true } },
44
- },
45
- },
46
- session: { store: sessionStorePath },
47
- ...overrides,
48
- }) as unknown as import("openclaw/plugin-sdk/config-types").OpenClawConfig;
49
-
50
- async function runGroupGating(params: {
51
- cfg: import("openclaw/plugin-sdk/config-types").OpenClawConfig;
52
- msg: WebInboundMsg;
53
- conversationId?: string;
54
- agentId?: string;
55
- selfChatMode?: boolean;
56
- authDir?: string;
57
- }) {
58
- const groupHistories = new Map<string, GroupHistoryEntry[]>();
59
- const conversationId = params.conversationId ?? "123@g.us";
60
- const agentId = params.agentId ?? "main";
61
- const sessionKey = `agent:${agentId}:whatsapp:group:${conversationId}`;
62
- const baseMentionConfig = buildMentionConfig(params.cfg, undefined);
63
- const result = await applyGroupGating({
64
- cfg: params.cfg,
65
- msg: params.msg,
66
- conversationId,
67
- groupHistoryKey: `whatsapp:default:group:${conversationId}`,
68
- agentId,
69
- sessionKey,
70
- baseMentionConfig,
71
- authDir: params.authDir,
72
- selfChatMode: params.selfChatMode,
73
- groupHistories,
74
- groupHistoryLimit: 10,
75
- groupMemberNames: new Map(),
76
- logVerbose: () => {},
77
- replyLogger: { debug: () => {} },
78
- });
79
- return { result, groupHistories };
80
- }
81
-
82
- function createGroupMessage(overrides: Partial<WebInboundMsg> = {}): WebInboundMsg {
83
- return {
84
- id: "g1",
85
- from: "123@g.us",
86
- conversationId: "123@g.us",
87
- chatId: "123@g.us",
88
- chatType: "group",
89
- to: "+2",
90
- accountId: "default",
91
- body: "hello group",
92
- senderE164: "+111",
93
- senderName: "Alice",
94
- selfE164: "+999",
95
- sendComposing: async () => {},
96
- reply: async (_text, _options) => acceptedSendResult("text", "r1"),
97
- sendMedia: async (_payload, _options) => acceptedSendResult("media", "m1"),
98
- ...overrides,
99
- };
100
- }
101
-
102
- function makeOwnerGroupConfig() {
103
- return makeConfig({
104
- channels: {
105
- whatsapp: {
106
- allowFrom: ["+111"],
107
- groups: { "*": { requireMention: true } },
108
- },
109
- },
110
- });
111
- }
112
-
113
- function makeInboundCfg(messagePrefix = "") {
114
- return {
115
- agents: { defaults: { workspace: "/tmp/openclaw" } },
116
- channels: { whatsapp: { messagePrefix } },
117
- } as never;
118
- }
119
-
120
- describe("applyGroupGating", () => {
121
- it("treats reply-to-bot as implicit mention", async () => {
122
- const cfg = makeConfig({});
123
- const { result } = await runGroupGating({
124
- cfg,
125
- msg: createGroupMessage({
126
- id: "m1",
127
- to: "+15550000",
128
- accountId: "default",
129
- body: "following up",
130
- timestamp: Date.now(),
131
- selfJid: "15551234567@s.whatsapp.net",
132
- selfE164: "+15551234567",
133
- replyToId: "m0",
134
- replyToBody: "bot said hi",
135
- replyToSender: "+15551234567",
136
- replyToSenderJid: "15551234567@s.whatsapp.net",
137
- replyToSenderE164: "+15551234567",
138
- }),
139
- });
140
-
141
- expect(result.shouldProcess).toBe(true);
142
- });
143
-
144
- it("does not treat self-number quoted replies as implicit mention in selfChatMode groups", async () => {
145
- const cfg = makeConfig({
146
- channels: {
147
- whatsapp: {
148
- selfChatMode: true,
149
- groupPolicy: "open",
150
- groups: { "*": { requireMention: true } },
151
- },
152
- },
153
- });
154
- const { result } = await runGroupGating({
155
- cfg,
156
- selfChatMode: true,
157
- msg: createGroupMessage({
158
- id: "m-self-reply",
159
- to: "+15550000",
160
- accountId: "default",
161
- body: "following up on my own message",
162
- timestamp: Date.now(),
163
- senderE164: "+15551234567",
164
- senderJid: "15551234567@s.whatsapp.net",
165
- selfJid: "15551234567@s.whatsapp.net",
166
- selfE164: "+15551234567",
167
- replyToId: "m0",
168
- replyToBody: "my earlier message",
169
- replyToSender: "+15551234567",
170
- replyToSenderJid: "15551234567@s.whatsapp.net",
171
- replyToSenderE164: "+15551234567",
172
- }),
173
- });
174
-
175
- expect(result.shouldProcess).toBe(false);
176
- });
177
-
178
- it("still treats reply-to-bot as implicit mention in selfChatMode when sender is a different user", async () => {
179
- const cfg = makeConfig({
180
- channels: {
181
- whatsapp: {
182
- selfChatMode: true,
183
- groupPolicy: "open",
184
- groups: { "*": { requireMention: true } },
185
- },
186
- },
187
- });
188
- const { result } = await runGroupGating({
189
- cfg,
190
- selfChatMode: true,
191
- msg: createGroupMessage({
192
- id: "m-other-reply",
193
- to: "+15550000",
194
- accountId: "default",
195
- body: "following up on bot reply",
196
- timestamp: Date.now(),
197
- senderE164: "+15559999999",
198
- senderJid: "15559999999@s.whatsapp.net",
199
- selfJid: "15551234567@s.whatsapp.net",
200
- selfE164: "+15551234567",
201
- replyToId: "m0",
202
- replyToBody: "bot earlier response",
203
- replyToSender: "+15551234567",
204
- replyToSenderJid: "15551234567@s.whatsapp.net",
205
- replyToSenderE164: "+15551234567",
206
- }),
207
- });
208
-
209
- expect(result.shouldProcess).toBe(true);
210
- });
211
-
212
- it("processes explicit group @mentions when self is in allowFrom (#49317)", async () => {
213
- if (!sessionDir) {
214
- throw new Error("sessionDir not initialized");
215
- }
216
- await fs.writeFile(
217
- path.join(sessionDir, "lid-mapping-216372600647751_reverse.json"),
218
- JSON.stringify("+15551234567"),
219
- );
220
- const cfg = makeConfig({
221
- channels: {
222
- whatsapp: {
223
- allowFrom: ["+15551234567"],
224
- groupPolicy: "open",
225
- groups: { "*": { requireMention: true } },
226
- },
227
- },
228
- });
229
- const msg = createGroupMessage({
230
- id: "g-self-lid-mention",
231
- accountId: "default",
232
- body: "@216372600647751 can you see this?",
233
- mentionedJids: ["216372600647751@lid"],
234
- senderE164: "+15550001111",
235
- senderName: "Alice",
236
- selfE164: "+15551234567",
237
- selfJid: "15551234567@s.whatsapp.net",
238
- });
239
-
240
- const { result, groupHistories } = await runGroupGating({
241
- cfg,
242
- authDir: sessionDir,
243
- msg,
244
- });
245
-
246
- expect(result.shouldProcess).toBe(true);
247
- expect(msg.wasMentioned).toBe(true);
248
- expect(groupHistories.get("whatsapp:default:group:123@g.us")).toBeUndefined();
249
- });
250
-
251
- it("honors per-account selfChatMode overrides before suppressing implicit mentions", async () => {
252
- const cfg = makeConfig({
253
- channels: {
254
- whatsapp: {
255
- selfChatMode: true,
256
- groupPolicy: "open",
257
- groups: { "*": { requireMention: true } },
258
- accounts: {
259
- work: {
260
- selfChatMode: false,
261
- },
262
- },
263
- },
264
- },
265
- });
266
- // Per-account override: work account has selfChatMode: false despite root being true
267
- const { result } = await runGroupGating({
268
- cfg,
269
- selfChatMode: false,
270
- msg: createGroupMessage({
271
- id: "m-account-override",
272
- to: "+15550000",
273
- accountId: "work",
274
- body: "following up on bot reply",
275
- timestamp: Date.now(),
276
- senderE164: "+15551234567",
277
- senderJid: "15551234567@s.whatsapp.net",
278
- selfJid: "15551234567@s.whatsapp.net",
279
- selfE164: "+15551234567",
280
- replyToId: "m0",
281
- replyToBody: "bot earlier response",
282
- replyToSender: "+15551234567",
283
- replyToSenderJid: "15551234567@s.whatsapp.net",
284
- replyToSenderE164: "+15551234567",
285
- }),
286
- });
287
-
288
- expect(result.shouldProcess).toBe(true);
289
- });
290
-
291
- it("uses account-scoped groupPolicy and groupAllowFrom for named-account group gating", async () => {
292
- const cfg = makeConfig({
293
- channels: {
294
- whatsapp: {
295
- groupPolicy: "allowlist",
296
- accounts: {
297
- work: {
298
- groupPolicy: "allowlist",
299
- groupAllowFrom: ["+111"],
300
- },
301
- },
302
- },
303
- },
304
- });
305
-
306
- const { result } = await runGroupGating({
307
- cfg,
308
- msg: createGroupMessage({
309
- id: "g-account-policy",
310
- accountId: "work",
311
- body: "following up",
312
- senderE164: "+111",
313
- senderJid: "111@s.whatsapp.net",
314
- selfJid: "15551234567@s.whatsapp.net",
315
- selfE164: "+15551234567",
316
- replyToId: "m0",
317
- replyToBody: "bot said hi",
318
- replyToSender: "+15551234567",
319
- replyToSenderJid: "15551234567@s.whatsapp.net",
320
- replyToSenderE164: "+15551234567",
321
- }),
322
- });
323
-
324
- expect(result.shouldProcess).toBe(true);
325
- });
326
-
327
- it("inherits group gating defaults from accounts.default for named accounts", async () => {
328
- const cfg = makeConfig({
329
- channels: {
330
- whatsapp: {
331
- groupPolicy: "allowlist",
332
- accounts: {
333
- default: {
334
- groupPolicy: "open",
335
- groups: {
336
- "*": {
337
- requireMention: false,
338
- },
339
- },
340
- },
341
- work: {},
342
- },
343
- },
344
- },
345
- });
346
-
347
- const { result } = await runGroupGating({
348
- cfg,
349
- msg: createGroupMessage({
350
- id: "g-default-inheritance",
351
- accountId: "work",
352
- body: "plain group message",
353
- senderE164: "+111",
354
- senderJid: "111@s.whatsapp.net",
355
- selfJid: "15551234567@s.whatsapp.net",
356
- selfE164: "+15551234567",
357
- }),
358
- });
359
-
360
- expect(result.shouldProcess).toBe(true);
361
- });
362
-
363
- it("preserves allowFrom fallback for named-account group gating when groupAllowFrom is empty", async () => {
364
- const cfg = makeConfig({
365
- channels: {
366
- whatsapp: {
367
- groupPolicy: "allowlist",
368
- accounts: {
369
- work: {
370
- groupPolicy: "allowlist",
371
- allowFrom: ["+111"],
372
- groupAllowFrom: [],
373
- groups: {
374
- "*": {
375
- requireMention: false,
376
- },
377
- },
378
- },
379
- },
380
- },
381
- },
382
- });
383
-
384
- const { result } = await runGroupGating({
385
- cfg,
386
- msg: createGroupMessage({
387
- id: "g-empty-group-allow-fallback",
388
- accountId: "work",
389
- body: "plain group message",
390
- senderE164: "+111",
391
- senderJid: "111@s.whatsapp.net",
392
- selfJid: "15551234567@s.whatsapp.net",
393
- selfE164: "+15551234567",
394
- }),
395
- });
396
-
397
- expect(result.shouldProcess).toBe(true);
398
- });
399
-
400
- it("uses account-scoped allowFrom when bypassing mention gating for owner commands", async () => {
401
- const cfg = makeConfig({
402
- channels: {
403
- whatsapp: {
404
- allowFrom: ["+999"],
405
- accounts: {
406
- work: {
407
- allowFrom: ["+111"],
408
- },
409
- },
410
- },
411
- },
412
- });
413
-
414
- const { result } = await runGroupGating({
415
- cfg,
416
- msg: createGroupMessage({
417
- id: "g-account-owner",
418
- accountId: "work",
419
- body: "/new",
420
- senderE164: "+111",
421
- senderName: "Owner",
422
- }),
423
- });
424
-
425
- expect(result.shouldProcess).toBe(true);
426
- });
427
-
428
- it("does not treat group mention gating as self-chat under implicit self fallback", async () => {
429
- const cfg = makeConfig({
430
- channels: {
431
- whatsapp: {
432
- groups: { "*": { requireMention: true } },
433
- },
434
- },
435
- messages: { groupChat: { mentionPatterns: ["@openclaw"] } },
436
- });
437
-
438
- const { result, groupHistories } = await runGroupGating({
439
- cfg,
440
- msg: createGroupMessage({
441
- id: "g-other-mention",
442
- body: "@openclaw please check this",
443
- mentionedJids: ["15550000000@s.whatsapp.net"],
444
- selfE164: "+15551234567",
445
- selfJid: "15551234567@s.whatsapp.net",
446
- }),
447
- });
448
-
449
- expect(result.shouldProcess).toBe(false);
450
- expect(groupHistories.get("whatsapp:default:group:123@g.us")?.length).toBe(1);
451
- });
452
-
453
- it.each([
454
- { id: "g-new", command: "/new" },
455
- { id: "g-status", command: "/status" },
456
- ])("bypasses mention gating for owner $command in group chats", async ({ id, command }) => {
457
- const { result } = await runGroupGating({
458
- cfg: makeOwnerGroupConfig(),
459
- msg: createGroupMessage({
460
- id,
461
- body: command,
462
- senderE164: "+111",
463
- senderName: "Owner",
464
- }),
465
- });
466
-
467
- expect(result.shouldProcess).toBe(true);
468
- });
469
-
470
- it("does not bypass mention gating for non-owner /new in group chats", async () => {
471
- const cfg = makeConfig({
472
- channels: {
473
- whatsapp: {
474
- allowFrom: ["+999"],
475
- groups: { "*": { requireMention: true } },
476
- },
477
- },
478
- });
479
-
480
- const { result, groupHistories } = await runGroupGating({
481
- cfg,
482
- msg: createGroupMessage({
483
- id: "g-new-unauth",
484
- body: "/new",
485
- senderE164: "+111",
486
- senderName: "NotOwner",
487
- }),
488
- });
489
-
490
- expect(result.shouldProcess).toBe(false);
491
- expect(groupHistories.get("whatsapp:default:group:123@g.us")?.length).toBe(1);
492
- });
493
-
494
- it("uses per-agent mention patterns for group gating (routing + mentionPatterns)", async () => {
495
- const cfg = makeConfig({
496
- channels: {
497
- whatsapp: {
498
- allowFrom: ["*"],
499
- groups: { "*": { requireMention: true } },
500
- },
501
- },
502
- messages: {
503
- groupChat: { mentionPatterns: ["@global"] },
504
- },
505
- agents: {
506
- list: [
507
- {
508
- id: "work",
509
- groupChat: { mentionPatterns: ["@workbot"] },
510
- },
511
- ],
512
- },
513
- bindings: [
514
- {
515
- agentId: "work",
516
- match: {
517
- provider: "whatsapp",
518
- peer: { kind: "group", id: "123@g.us" },
519
- },
520
- },
521
- ],
522
- });
523
-
524
- const route = resolveAgentRoute({
525
- cfg,
526
- channel: "whatsapp",
527
- peer: { kind: "group", id: "123@g.us" },
528
- });
529
- expect(route.agentId).toBe("work");
530
-
531
- const { result: globalMention } = await runGroupGating({
532
- cfg,
533
- agentId: route.agentId,
534
- msg: createGroupMessage({
535
- id: "g1",
536
- body: "@global ping",
537
- senderE164: "+111",
538
- senderName: "Alice",
539
- }),
540
- });
541
- expect(globalMention.shouldProcess).toBe(false);
542
-
543
- const { result: workMention } = await runGroupGating({
544
- cfg,
545
- agentId: route.agentId,
546
- msg: createGroupMessage({
547
- id: "g2",
548
- body: "@workbot ping",
549
- senderE164: "+222",
550
- senderName: "Bob",
551
- }),
552
- });
553
- expect(workMention.shouldProcess).toBe(true);
554
- });
555
-
556
- it("allows group messages when whatsapp groups default disables mention gating", async () => {
557
- const cfg = makeConfig({
558
- channels: {
559
- whatsapp: {
560
- allowFrom: ["*"],
561
- groups: { "*": { requireMention: false } },
562
- },
563
- },
564
- messages: { groupChat: { mentionPatterns: ["@openclaw"] } },
565
- });
566
-
567
- const { result } = await runGroupGating({
568
- cfg,
569
- msg: createGroupMessage(),
570
- });
571
-
572
- expect(result.shouldProcess).toBe(true);
573
- });
574
-
575
- it("blocks group messages when whatsapp groups is set without a wildcard", async () => {
576
- const cfg = makeConfig({
577
- channels: {
578
- whatsapp: {
579
- allowFrom: ["*"],
580
- groups: {
581
- "999@g.us": { requireMention: false },
582
- },
583
- },
584
- },
585
- });
586
-
587
- const { result } = await runGroupGating({
588
- cfg,
589
- msg: createGroupMessage({
590
- body: "@workbot ping",
591
- mentionedJids: ["999@s.whatsapp.net"],
592
- selfJid: "999@s.whatsapp.net",
593
- }),
594
- });
595
-
596
- expect(result.shouldProcess).toBe(false);
597
- });
598
- });
599
-
600
- describe("buildInboundLine", () => {
601
- it("prefixes group messages with sender", () => {
602
- const line = buildInboundLine({
603
- cfg: makeInboundCfg(""),
604
- agentId: "main",
605
- msg: createGroupMessage({
606
- to: "+15550009999",
607
- accountId: "default",
608
- body: "ping",
609
- timestamp: 1700000000000,
610
- senderJid: "111@s.whatsapp.net",
611
- senderE164: "+15550001111",
612
- senderName: "Bob",
613
- }) as never,
614
- });
615
-
616
- expect(line).toContain("Bob (+15550001111):");
617
- expect(line).toContain("ping");
618
- });
619
-
620
- it("includes reply-to context blocks when replyToBody is present", () => {
621
- const line = buildInboundLine({
622
- cfg: makeInboundCfg(""),
623
- agentId: "main",
624
- msg: {
625
- from: "+1555",
626
- to: "+1555",
627
- body: "hello",
628
- chatType: "direct",
629
- replyToId: "q1",
630
- replyToBody: "original",
631
- replyToSender: "+1999",
632
- } as never,
633
- envelope: { includeTimestamp: false },
634
- });
635
-
636
- expect(line).toContain("[Replying to +1999 id:q1]");
637
- expect(line).toContain("original");
638
- expect(line).toContain("[/Replying]");
639
- });
640
-
641
- it("applies the WhatsApp messagePrefix when configured", () => {
642
- const line = buildInboundLine({
643
- cfg: makeInboundCfg("[PFX]"),
644
- agentId: "main",
645
- msg: {
646
- from: "+1555",
647
- to: "+2666",
648
- body: "ping",
649
- chatType: "direct",
650
- } as never,
651
- envelope: { includeTimestamp: false },
652
- });
653
-
654
- expect(line).toContain("[PFX] ping");
655
- });
656
-
657
- it("normalizes direct from labels by stripping whatsapp: prefix", () => {
658
- const line = buildInboundLine({
659
- cfg: makeInboundCfg(""),
660
- agentId: "main",
661
- msg: {
662
- from: "whatsapp:+15550001111",
663
- to: "+2666",
664
- body: "ping",
665
- chatType: "direct",
666
- } as never,
667
- envelope: { includeTimestamp: false },
668
- });
669
-
670
- expect(line).toContain("+15550001111");
671
- expect(line).not.toContain("whatsapp:+15550001111");
672
- });
673
- });
674
-
675
- describe("formatReplyContext", () => {
676
- it("returns null when replyToBody is missing", () => {
677
- expect(formatReplyContext({} as never)).toBeNull();
678
- });
679
-
680
- it("uses unknown sender label when reply sender is absent", () => {
681
- expect(
682
- formatReplyContext({
683
- replyToBody: "original",
684
- } as never),
685
- ).toBe("[Replying to unknown sender]\noriginal\n[/Replying]");
686
- });
687
- });