@openclaw/whatsapp 2026.5.2 → 2026.5.3-beta.2

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,237 +0,0 @@
1
- import { createChannelPairingChallengeIssuer } from "openclaw/plugin-sdk/channel-pairing";
2
- import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
3
- import { upsertChannelPairingRequest } from "openclaw/plugin-sdk/conversation-runtime";
4
- import { defaultRuntime } from "openclaw/plugin-sdk/runtime-env";
5
- import { warnMissingProviderGroupPolicyFallbackOnce } from "openclaw/plugin-sdk/runtime-group-policy";
6
- import {
7
- expandAllowFromWithAccessGroups,
8
- readStoreAllowFromForDmPolicy,
9
- resolveDmGroupAccessWithLists,
10
- } from "openclaw/plugin-sdk/security-runtime";
11
- import { resolveWhatsAppInboundPolicy } from "../inbound-policy.js";
12
-
13
- export type InboundAccessControlResult = {
14
- allowed: boolean;
15
- shouldMarkRead: boolean;
16
- isSelfChat: boolean;
17
- resolvedAccountId: string;
18
- };
19
-
20
- const PAIRING_REPLY_HISTORY_GRACE_MS = 30_000;
21
-
22
- function logWhatsAppVerbose(enabled: boolean | undefined, message: string) {
23
- if (!enabled) {
24
- return;
25
- }
26
- defaultRuntime.log(message);
27
- }
28
-
29
- export async function checkInboundAccessControl(params: {
30
- cfg: OpenClawConfig;
31
- accountId: string;
32
- from: string;
33
- selfE164: string | null;
34
- senderE164: string | null;
35
- group: boolean;
36
- pushName?: string;
37
- isFromMe: boolean;
38
- messageTimestampMs?: number;
39
- connectedAtMs?: number;
40
- pairingGraceMs?: number;
41
- verbose?: boolean;
42
- sock: {
43
- sendMessage: (jid: string, content: { text: string }) => Promise<unknown>;
44
- };
45
- remoteJid: string;
46
- }): Promise<InboundAccessControlResult> {
47
- const policy = resolveWhatsAppInboundPolicy({
48
- cfg: params.cfg,
49
- accountId: params.accountId,
50
- selfE164: params.selfE164,
51
- });
52
- const storeAllowFrom = params.group
53
- ? []
54
- : await readStoreAllowFromForDmPolicy({
55
- provider: "whatsapp",
56
- accountId: policy.account.accountId,
57
- dmPolicy: policy.dmPolicy,
58
- shouldRead: policy.shouldReadStorePairingApprovals,
59
- });
60
- const pairingGraceMs =
61
- typeof params.pairingGraceMs === "number" && params.pairingGraceMs > 0
62
- ? params.pairingGraceMs
63
- : PAIRING_REPLY_HISTORY_GRACE_MS;
64
- const suppressPairingReply =
65
- typeof params.connectedAtMs === "number" &&
66
- typeof params.messageTimestampMs === "number" &&
67
- params.messageTimestampMs < params.connectedAtMs - pairingGraceMs;
68
-
69
- // Group policy filtering:
70
- // - "open": groups bypass allowFrom, only mention-gating applies
71
- // - "disabled": block all group messages entirely
72
- // - "allowlist": only allow group messages from senders in groupAllowFrom/allowFrom
73
- warnMissingProviderGroupPolicyFallbackOnce({
74
- providerMissingFallbackApplied: policy.providerMissingFallbackApplied,
75
- providerKey: "whatsapp",
76
- accountId: policy.account.accountId,
77
- log: (message) => logWhatsAppVerbose(params.verbose, message),
78
- });
79
- const accessGroupSenderId = params.group ? (params.senderE164 ?? params.from) : params.from;
80
- const isAccessGroupSenderAllowed = (senderId: string, allowEntries: string[]) => {
81
- return params.group
82
- ? policy.isGroupSenderAllowed(allowEntries, senderId)
83
- : policy.isDmSenderAllowed(allowEntries, senderId);
84
- };
85
- const [allowFrom, groupAllowFrom] = await Promise.all([
86
- expandAllowFromWithAccessGroups({
87
- cfg: params.cfg,
88
- allowFrom: params.group ? policy.configuredAllowFrom : policy.dmAllowFrom,
89
- channel: "whatsapp",
90
- accountId: policy.account.accountId,
91
- senderId: accessGroupSenderId,
92
- isSenderAllowed: isAccessGroupSenderAllowed,
93
- }),
94
- expandAllowFromWithAccessGroups({
95
- cfg: params.cfg,
96
- allowFrom: policy.groupAllowFrom,
97
- channel: "whatsapp",
98
- accountId: policy.account.accountId,
99
- senderId: accessGroupSenderId,
100
- isSenderAllowed: isAccessGroupSenderAllowed,
101
- }),
102
- ]);
103
- const dmStoreAllowFrom = params.group
104
- ? []
105
- : await expandAllowFromWithAccessGroups({
106
- cfg: params.cfg,
107
- allowFrom: storeAllowFrom,
108
- channel: "whatsapp",
109
- accountId: policy.account.accountId,
110
- senderId: accessGroupSenderId,
111
- isSenderAllowed: isAccessGroupSenderAllowed,
112
- });
113
- const access = resolveDmGroupAccessWithLists({
114
- isGroup: params.group,
115
- dmPolicy: policy.dmPolicy,
116
- groupPolicy: policy.groupPolicy,
117
- allowFrom,
118
- groupAllowFrom,
119
- storeAllowFrom: dmStoreAllowFrom,
120
- isSenderAllowed: (allowEntries) => {
121
- return params.group
122
- ? policy.isGroupSenderAllowed(allowEntries, params.senderE164)
123
- : policy.isDmSenderAllowed(allowEntries, params.from);
124
- },
125
- });
126
- if (params.group && access.decision !== "allow") {
127
- if (access.reason === "groupPolicy=disabled") {
128
- logWhatsAppVerbose(params.verbose, "Blocked group message (groupPolicy: disabled)");
129
- } else if (access.reason === "groupPolicy=allowlist (empty allowlist)") {
130
- logWhatsAppVerbose(
131
- params.verbose,
132
- "Blocked group message (groupPolicy: allowlist, no groupAllowFrom)",
133
- );
134
- } else {
135
- logWhatsAppVerbose(
136
- params.verbose,
137
- `Blocked group message from ${params.senderE164 ?? "unknown sender"} (groupPolicy: allowlist)`,
138
- );
139
- }
140
- return {
141
- allowed: false,
142
- shouldMarkRead: false,
143
- isSelfChat: policy.isSelfChat,
144
- resolvedAccountId: policy.account.accountId,
145
- };
146
- }
147
-
148
- // DM access control (secure defaults): "pairing" (default) / "allowlist" / "open" / "disabled".
149
- if (!params.group) {
150
- if (params.isFromMe && !policy.isSamePhone(params.from)) {
151
- logWhatsAppVerbose(params.verbose, "Skipping outbound DM (fromMe); no pairing reply needed.");
152
- return {
153
- allowed: false,
154
- shouldMarkRead: false,
155
- isSelfChat: policy.isSelfChat,
156
- resolvedAccountId: policy.account.accountId,
157
- };
158
- }
159
- if (access.decision === "block" && access.reason === "dmPolicy=disabled") {
160
- logWhatsAppVerbose(params.verbose, "Blocked dm (dmPolicy: disabled)");
161
- return {
162
- allowed: false,
163
- shouldMarkRead: false,
164
- isSelfChat: policy.isSelfChat,
165
- resolvedAccountId: policy.account.accountId,
166
- };
167
- }
168
- if (access.decision === "pairing" && !policy.isSamePhone(params.from)) {
169
- const candidate = params.from;
170
- if (suppressPairingReply) {
171
- logWhatsAppVerbose(
172
- params.verbose,
173
- `Skipping pairing reply for historical DM from ${candidate}.`,
174
- );
175
- } else {
176
- await createChannelPairingChallengeIssuer({
177
- channel: "whatsapp",
178
- upsertPairingRequest: async ({ id, meta }) =>
179
- await upsertChannelPairingRequest({
180
- channel: "whatsapp",
181
- id,
182
- accountId: policy.account.accountId,
183
- meta,
184
- }),
185
- })({
186
- senderId: candidate,
187
- senderIdLine: `Your WhatsApp phone number: ${candidate}`,
188
- meta: { name: (params.pushName ?? "").trim() || undefined },
189
- onCreated: () => {
190
- logWhatsAppVerbose(
191
- params.verbose,
192
- `whatsapp pairing request sender=${candidate} name=${params.pushName ?? "unknown"}`,
193
- );
194
- },
195
- sendPairingReply: async (text) => {
196
- await params.sock.sendMessage(params.remoteJid, { text });
197
- },
198
- onReplyError: (err) => {
199
- logWhatsAppVerbose(
200
- params.verbose,
201
- `whatsapp pairing reply failed for ${candidate}: ${String(err)}`,
202
- );
203
- },
204
- });
205
- }
206
- return {
207
- allowed: false,
208
- shouldMarkRead: false,
209
- isSelfChat: policy.isSelfChat,
210
- resolvedAccountId: policy.account.accountId,
211
- };
212
- }
213
- if (access.decision !== "allow") {
214
- logWhatsAppVerbose(
215
- params.verbose,
216
- `Blocked unauthorized sender ${params.from} (dmPolicy=${policy.dmPolicy})`,
217
- );
218
- return {
219
- allowed: false,
220
- shouldMarkRead: false,
221
- isSelfChat: policy.isSelfChat,
222
- resolvedAccountId: policy.account.accountId,
223
- };
224
- }
225
- }
226
-
227
- return {
228
- allowed: true,
229
- shouldMarkRead: true,
230
- isSelfChat: policy.isSelfChat,
231
- resolvedAccountId: policy.account.accountId,
232
- };
233
- }
234
-
235
- export const __testing = {
236
- resolveWhatsAppInboundPolicy,
237
- };
@@ -1,132 +0,0 @@
1
- import { createClaimableDedupe } from "openclaw/plugin-sdk/persistent-dedupe";
2
-
3
- const RECENT_WEB_MESSAGE_TTL_MS = 20 * 60_000;
4
- const RECENT_WEB_MESSAGE_MAX = 5000;
5
- const RECENT_OUTBOUND_MESSAGE_TTL_MS = 20 * 60_000;
6
- const RECENT_OUTBOUND_MESSAGE_MAX = 5000;
7
-
8
- const claimableInboundMessages = createClaimableDedupe({
9
- ttlMs: RECENT_WEB_MESSAGE_TTL_MS,
10
- memoryMaxSize: RECENT_WEB_MESSAGE_MAX,
11
- });
12
- const recentOutboundMessages = createRecentMessageCache({
13
- ttlMs: RECENT_OUTBOUND_MESSAGE_TTL_MS,
14
- maxSize: RECENT_OUTBOUND_MESSAGE_MAX,
15
- });
16
-
17
- function createRecentMessageCache(options: { ttlMs: number; maxSize: number }) {
18
- const ttlMs = Math.max(0, options.ttlMs);
19
- const maxSize = Math.max(0, Math.floor(options.maxSize));
20
- const cache = new Map<string, number>();
21
-
22
- const prune = (now: number) => {
23
- if (ttlMs > 0) {
24
- const cutoff = now - ttlMs;
25
- for (const [key, timestamp] of cache) {
26
- if (timestamp < cutoff) {
27
- cache.delete(key);
28
- }
29
- }
30
- }
31
- while (cache.size > maxSize) {
32
- const oldest = cache.keys().next().value;
33
- if (!oldest) {
34
- break;
35
- }
36
- cache.delete(oldest);
37
- }
38
- };
39
-
40
- const peek = (key: string | null, now = Date.now()): boolean => {
41
- if (!key) {
42
- return false;
43
- }
44
- const timestamp = cache.get(key);
45
- if (timestamp === undefined) {
46
- return false;
47
- }
48
- if (ttlMs > 0 && now - timestamp >= ttlMs) {
49
- cache.delete(key);
50
- return false;
51
- }
52
- return true;
53
- };
54
-
55
- return {
56
- check: (key: string | null, now = Date.now()): boolean => {
57
- if (!key) {
58
- return false;
59
- }
60
- const existed = peek(key, now);
61
- cache.delete(key);
62
- cache.set(key, now);
63
- prune(now);
64
- return existed;
65
- },
66
- peek,
67
- clear: () => cache.clear(),
68
- };
69
- }
70
-
71
- export class WhatsAppRetryableInboundError extends Error {
72
- constructor(message: string, options?: ErrorOptions) {
73
- super(message, options);
74
- this.name = "WhatsAppRetryableInboundError";
75
- }
76
- }
77
-
78
- function buildMessageKey(params: {
79
- accountId: string;
80
- remoteJid: string;
81
- messageId: string;
82
- }): string | null {
83
- const accountId = params.accountId.trim();
84
- const remoteJid = params.remoteJid.trim();
85
- const messageId = params.messageId.trim();
86
- if (!accountId || !remoteJid || !messageId || messageId === "unknown") {
87
- return null;
88
- }
89
- return `${accountId}:${remoteJid}:${messageId}`;
90
- }
91
-
92
- export function resetWebInboundDedupe(): void {
93
- claimableInboundMessages.clearMemory();
94
- recentOutboundMessages.clear();
95
- }
96
-
97
- export async function claimRecentInboundMessage(key: string): Promise<boolean> {
98
- const claim = await claimableInboundMessages.claim(key);
99
- return claim.kind === "claimed";
100
- }
101
-
102
- export async function commitRecentInboundMessage(key: string): Promise<void> {
103
- await claimableInboundMessages.commit(key);
104
- }
105
-
106
- export function releaseRecentInboundMessage(key: string, error?: unknown): void {
107
- claimableInboundMessages.release(key, { error });
108
- }
109
-
110
- export function rememberRecentOutboundMessage(params: {
111
- accountId: string;
112
- remoteJid: string;
113
- messageId: string;
114
- }): void {
115
- const key = buildMessageKey(params);
116
- if (!key) {
117
- return;
118
- }
119
- recentOutboundMessages.check(key);
120
- }
121
-
122
- export function isRecentOutboundMessage(params: {
123
- accountId: string;
124
- remoteJid: string;
125
- messageId: string;
126
- }): boolean {
127
- const key = buildMessageKey(params);
128
- if (!key) {
129
- return false;
130
- }
131
- return recentOutboundMessages.peek(key);
132
- }
@@ -1,282 +0,0 @@
1
- import type { proto } from "@whiskeysockets/baileys";
2
- import { describe, expect, it } from "vitest";
3
- import { extractMentionedJids, hasInboundUserContent } from "./extract.js";
4
-
5
- describe("extractMentionedJids", () => {
6
- const botJid = "5511999999999@s.whatsapp.net";
7
- const otherJid = "5511888888888@s.whatsapp.net";
8
-
9
- it("returns direct mentions from the current message", () => {
10
- const message: proto.IMessage = {
11
- extendedTextMessage: {
12
- text: "Hey @bot",
13
- contextInfo: {
14
- mentionedJid: [botJid],
15
- },
16
- },
17
- };
18
- expect(extractMentionedJids(message)).toEqual([botJid]);
19
- });
20
-
21
- it("ignores mentionedJids from quoted messages", () => {
22
- const message: proto.IMessage = {
23
- extendedTextMessage: {
24
- text: "I agree",
25
- contextInfo: {
26
- // The quoted message originally @mentioned the bot, but the
27
- // current message does not — this should NOT leak through.
28
- quotedMessage: {
29
- extendedTextMessage: {
30
- text: "Hey @bot what do you think?",
31
- contextInfo: {
32
- mentionedJid: [botJid],
33
- },
34
- },
35
- },
36
- },
37
- },
38
- };
39
- expect(extractMentionedJids(message)).toBeUndefined();
40
- });
41
-
42
- it("returns direct mentions even when quoted message also has mentions", () => {
43
- const message: proto.IMessage = {
44
- extendedTextMessage: {
45
- text: "Hey @other",
46
- contextInfo: {
47
- mentionedJid: [otherJid],
48
- quotedMessage: {
49
- extendedTextMessage: {
50
- text: "Hey @bot",
51
- contextInfo: {
52
- mentionedJid: [botJid],
53
- },
54
- },
55
- },
56
- },
57
- },
58
- };
59
- // Should return only the direct mention, not the quoted one.
60
- expect(extractMentionedJids(message)).toEqual([otherJid]);
61
- });
62
-
63
- it("returns mentions from media message types", () => {
64
- const message: proto.IMessage = {
65
- imageMessage: {
66
- contextInfo: {
67
- mentionedJid: [botJid],
68
- },
69
- },
70
- };
71
- expect(extractMentionedJids(message)).toEqual([botJid]);
72
- });
73
-
74
- it("returns undefined for messages with no mentions", () => {
75
- const message: proto.IMessage = {
76
- extendedTextMessage: {
77
- text: "Just a regular message",
78
- },
79
- };
80
- expect(extractMentionedJids(message)).toBeUndefined();
81
- });
82
-
83
- it("returns undefined for undefined input", () => {
84
- expect(extractMentionedJids(undefined)).toBeUndefined();
85
- });
86
-
87
- it("deduplicates mentions across message types", () => {
88
- const message: proto.IMessage = {
89
- extendedTextMessage: {
90
- text: "Hey @bot",
91
- contextInfo: {
92
- mentionedJid: [botJid],
93
- },
94
- },
95
- imageMessage: {
96
- contextInfo: {
97
- mentionedJid: [botJid],
98
- },
99
- },
100
- };
101
- expect(extractMentionedJids(message)).toEqual([botJid]);
102
- });
103
- });
104
-
105
- describe("hasInboundUserContent", () => {
106
- it("returns true for plain text conversation", () => {
107
- expect(hasInboundUserContent({ conversation: "hello" })).toBe(true);
108
- });
109
-
110
- it("returns true for extendedTextMessage", () => {
111
- expect(
112
- hasInboundUserContent({ extendedTextMessage: { text: "hello" } } as proto.IMessage),
113
- ).toBe(true);
114
- });
115
-
116
- it("returns true for image message", () => {
117
- expect(
118
- hasInboundUserContent({ imageMessage: { mimetype: "image/png" } } as proto.IMessage),
119
- ).toBe(true);
120
- });
121
-
122
- it("returns true for video message", () => {
123
- expect(
124
- hasInboundUserContent({ videoMessage: { mimetype: "video/mp4" } } as proto.IMessage),
125
- ).toBe(true);
126
- });
127
-
128
- it("returns true for audio message", () => {
129
- expect(
130
- hasInboundUserContent({ audioMessage: { mimetype: "audio/ogg" } } as proto.IMessage),
131
- ).toBe(true);
132
- });
133
-
134
- it("returns true for document message", () => {
135
- expect(
136
- hasInboundUserContent({
137
- documentMessage: { fileName: "x.pdf" },
138
- } as proto.IMessage),
139
- ).toBe(true);
140
- });
141
-
142
- it("returns true for sticker message", () => {
143
- expect(
144
- hasInboundUserContent({ stickerMessage: { mimetype: "image/webp" } } as proto.IMessage),
145
- ).toBe(true);
146
- });
147
-
148
- it("returns true for location message with valid coords", () => {
149
- expect(
150
- hasInboundUserContent({
151
- locationMessage: { degreesLatitude: 1, degreesLongitude: 2 },
152
- } as proto.IMessage),
153
- ).toBe(true);
154
- });
155
-
156
- it("returns true for live location message with valid coords", () => {
157
- expect(
158
- hasInboundUserContent({
159
- liveLocationMessage: { degreesLatitude: 1, degreesLongitude: 2 },
160
- } as proto.IMessage),
161
- ).toBe(true);
162
- });
163
-
164
- it("returns true for contact message", () => {
165
- expect(
166
- hasInboundUserContent({
167
- contactMessage: { displayName: "Alice", vcard: "BEGIN:VCARD\nEND:VCARD" },
168
- } as proto.IMessage),
169
- ).toBe(true);
170
- });
171
-
172
- it("returns true for contactsArrayMessage via contact placeholder extraction", () => {
173
- expect(
174
- hasInboundUserContent({
175
- contactsArrayMessage: {
176
- contacts: [{ displayName: "Alice", vcard: "BEGIN:VCARD\nEND:VCARD" }],
177
- },
178
- } as proto.IMessage),
179
- ).toBe(true);
180
- });
181
-
182
- it("returns true for buttons response (user button click)", () => {
183
- expect(
184
- hasInboundUserContent({
185
- buttonsResponseMessage: {
186
- selectedButtonId: "yes",
187
- selectedDisplayText: "Yes",
188
- },
189
- } as proto.IMessage),
190
- ).toBe(true);
191
- });
192
-
193
- it("returns true for list response (user list selection)", () => {
194
- expect(
195
- hasInboundUserContent({
196
- listResponseMessage: {
197
- title: "Option A",
198
- singleSelectReply: { selectedRowId: "a" },
199
- } as unknown as proto.Message.IListResponseMessage,
200
- } as proto.IMessage),
201
- ).toBe(true);
202
- });
203
-
204
- it("returns true for template button reply", () => {
205
- expect(
206
- hasInboundUserContent({
207
- templateButtonReplyMessage: {
208
- selectedId: "btn-1",
209
- selectedDisplayText: "Click",
210
- } as unknown as proto.Message.ITemplateButtonReplyMessage,
211
- } as proto.IMessage),
212
- ).toBe(true);
213
- });
214
-
215
- it("returns true for interactive response", () => {
216
- expect(
217
- hasInboundUserContent({
218
- interactiveResponseMessage: {
219
- body: { text: "x" },
220
- nativeFlowResponseMessage: { name: "n", paramsJson: "{}" },
221
- } as unknown as proto.Message.IInteractiveResponseMessage,
222
- } as proto.IMessage),
223
- ).toBe(true);
224
- });
225
-
226
- it("returns true for buttons response wrapped in ephemeralMessage (regression for #73797 + greptile review)", () => {
227
- expect(
228
- hasInboundUserContent({
229
- ephemeralMessage: {
230
- message: {
231
- buttonsResponseMessage: {
232
- selectedButtonId: "ok",
233
- selectedDisplayText: "OK",
234
- },
235
- },
236
- },
237
- } as proto.IMessage),
238
- ).toBe(true);
239
- });
240
-
241
- it("returns false for undefined message (regression for #73797)", () => {
242
- expect(hasInboundUserContent(undefined)).toBe(false);
243
- });
244
-
245
- it("returns false for empty message object (no content keys)", () => {
246
- expect(hasInboundUserContent({} as proto.IMessage)).toBe(false);
247
- });
248
-
249
- it("returns false for protocol message envelope without inner content (regression for #73797)", () => {
250
- expect(
251
- hasInboundUserContent({
252
- protocolMessage: {
253
- type: 0,
254
- } as unknown as proto.Message.IProtocolMessage,
255
- } as proto.IMessage),
256
- ).toBe(false);
257
- });
258
-
259
- it("returns false for receipt-style senderKeyDistribution-only payload (regression for #73797)", () => {
260
- expect(
261
- hasInboundUserContent({
262
- senderKeyDistributionMessage: {
263
- groupId: "g@example",
264
- } as unknown as proto.Message.ISenderKeyDistributionMessage,
265
- } as proto.IMessage),
266
- ).toBe(false);
267
- });
268
-
269
- it("returns false when location coords are missing (incomplete event, regression for #73797)", () => {
270
- expect(
271
- hasInboundUserContent({
272
- locationMessage: { name: "no coords" },
273
- } as proto.IMessage),
274
- ).toBe(false);
275
- });
276
-
277
- it("returns false when extendedTextMessage has only empty text", () => {
278
- expect(hasInboundUserContent({ extendedTextMessage: { text: " " } } as proto.IMessage)).toBe(
279
- false,
280
- );
281
- });
282
- });