@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,330 +0,0 @@
1
- import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
2
- import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk/routing";
3
- import { beforeEach, describe, expect, it, vi } from "vitest";
4
- import { handleWhatsAppAction, whatsAppActionRuntime } from "./action-runtime.js";
5
-
6
- const originalWhatsAppActionRuntime = { ...whatsAppActionRuntime };
7
- const sendReactionWhatsApp = vi.fn(async () => undefined);
8
-
9
- const enabledConfig = {
10
- channels: { whatsapp: { actions: { reactions: true } } },
11
- } as OpenClawConfig;
12
-
13
- describe("handleWhatsAppAction", () => {
14
- function reactionConfig(reactionLevel: "minimal" | "extensive" | "off" | "ack"): OpenClawConfig {
15
- return {
16
- channels: { whatsapp: { actions: { reactions: true }, reactionLevel } },
17
- } as OpenClawConfig;
18
- }
19
-
20
- beforeEach(() => {
21
- vi.clearAllMocks();
22
- Object.assign(whatsAppActionRuntime, originalWhatsAppActionRuntime, {
23
- sendReactionWhatsApp,
24
- });
25
- });
26
-
27
- it("adds reactions", async () => {
28
- await handleWhatsAppAction(
29
- {
30
- action: "react",
31
- chatJid: "123@s.whatsapp.net",
32
- messageId: "msg1",
33
- emoji: "✅",
34
- },
35
- enabledConfig,
36
- );
37
- expect(sendReactionWhatsApp).toHaveBeenLastCalledWith(
38
- "+123",
39
- "msg1",
40
- "✅",
41
- expect.objectContaining({
42
- verbose: false,
43
- fromMe: undefined,
44
- participant: undefined,
45
- accountId: DEFAULT_ACCOUNT_ID,
46
- }),
47
- );
48
- });
49
-
50
- it("adds reactions when reactionLevel is minimal", async () => {
51
- await handleWhatsAppAction(
52
- {
53
- action: "react",
54
- chatJid: "123@s.whatsapp.net",
55
- messageId: "msg1",
56
- emoji: "✅",
57
- },
58
- reactionConfig("minimal"),
59
- );
60
- expect(sendReactionWhatsApp).toHaveBeenLastCalledWith(
61
- "+123",
62
- "msg1",
63
- "✅",
64
- expect.objectContaining({
65
- verbose: false,
66
- fromMe: undefined,
67
- participant: undefined,
68
- accountId: DEFAULT_ACCOUNT_ID,
69
- }),
70
- );
71
- });
72
-
73
- it("adds reactions when reactionLevel is extensive", async () => {
74
- await handleWhatsAppAction(
75
- {
76
- action: "react",
77
- chatJid: "123@s.whatsapp.net",
78
- messageId: "msg1",
79
- emoji: "✅",
80
- },
81
- reactionConfig("extensive"),
82
- );
83
- expect(sendReactionWhatsApp).toHaveBeenLastCalledWith(
84
- "+123",
85
- "msg1",
86
- "✅",
87
- expect.objectContaining({
88
- verbose: false,
89
- fromMe: undefined,
90
- participant: undefined,
91
- accountId: DEFAULT_ACCOUNT_ID,
92
- }),
93
- );
94
- });
95
-
96
- it("removes reactions on empty emoji", async () => {
97
- await handleWhatsAppAction(
98
- {
99
- action: "react",
100
- chatJid: "123@s.whatsapp.net",
101
- messageId: "msg1",
102
- emoji: "",
103
- },
104
- enabledConfig,
105
- );
106
- expect(sendReactionWhatsApp).toHaveBeenLastCalledWith(
107
- "+123",
108
- "msg1",
109
- "",
110
- expect.objectContaining({
111
- verbose: false,
112
- fromMe: undefined,
113
- participant: undefined,
114
- accountId: DEFAULT_ACCOUNT_ID,
115
- }),
116
- );
117
- });
118
-
119
- it("removes reactions when remove flag set", async () => {
120
- await handleWhatsAppAction(
121
- {
122
- action: "react",
123
- chatJid: "123@s.whatsapp.net",
124
- messageId: "msg1",
125
- emoji: "✅",
126
- remove: true,
127
- },
128
- enabledConfig,
129
- );
130
- expect(sendReactionWhatsApp).toHaveBeenLastCalledWith(
131
- "+123",
132
- "msg1",
133
- "",
134
- expect.objectContaining({
135
- verbose: false,
136
- fromMe: undefined,
137
- participant: undefined,
138
- accountId: DEFAULT_ACCOUNT_ID,
139
- }),
140
- );
141
- });
142
-
143
- it("passes account scope and sender flags", async () => {
144
- await handleWhatsAppAction(
145
- {
146
- action: "react",
147
- chatJid: "123@s.whatsapp.net",
148
- messageId: "msg1",
149
- emoji: "🎉",
150
- accountId: "work",
151
- fromMe: true,
152
- participant: "999@s.whatsapp.net",
153
- },
154
- enabledConfig,
155
- );
156
- expect(sendReactionWhatsApp).toHaveBeenLastCalledWith(
157
- "+123",
158
- "msg1",
159
- "🎉",
160
- expect.objectContaining({
161
- verbose: false,
162
- fromMe: true,
163
- participant: "999@s.whatsapp.net",
164
- accountId: "work",
165
- }),
166
- );
167
- });
168
-
169
- it("preserves LID participant ids when forwarding reactions", async () => {
170
- await handleWhatsAppAction(
171
- {
172
- action: "react",
173
- chatJid: "12345@g.us",
174
- messageId: "msg1",
175
- emoji: "🎉",
176
- participant: "123@lid",
177
- },
178
- enabledConfig,
179
- );
180
- expect(sendReactionWhatsApp).toHaveBeenLastCalledWith(
181
- "12345@g.us",
182
- "msg1",
183
- "🎉",
184
- expect.objectContaining({
185
- verbose: false,
186
- fromMe: undefined,
187
- participant: "123@lid",
188
- accountId: DEFAULT_ACCOUNT_ID,
189
- }),
190
- );
191
- });
192
-
193
- it("respects reaction gating", async () => {
194
- const cfg = {
195
- channels: { whatsapp: { actions: { reactions: false } } },
196
- } as OpenClawConfig;
197
- await expect(
198
- handleWhatsAppAction(
199
- {
200
- action: "react",
201
- chatJid: "123@s.whatsapp.net",
202
- messageId: "msg1",
203
- emoji: "✅",
204
- },
205
- cfg,
206
- ),
207
- ).rejects.toThrow(/WhatsApp reactions are disabled/);
208
- });
209
-
210
- it("disables reactions when WhatsApp is not configured", async () => {
211
- await expect(
212
- handleWhatsAppAction(
213
- {
214
- action: "react",
215
- chatJid: "123@s.whatsapp.net",
216
- messageId: "msg1",
217
- emoji: "✅",
218
- },
219
- {} as OpenClawConfig,
220
- ),
221
- ).rejects.toThrow(/WhatsApp reactions are disabled/);
222
- });
223
-
224
- it("prefers the action gate error when both actions.reactions and reactionLevel disable reactions", async () => {
225
- const cfg = {
226
- channels: { whatsapp: { actions: { reactions: false }, reactionLevel: "ack" } },
227
- } as OpenClawConfig;
228
-
229
- await expect(
230
- handleWhatsAppAction(
231
- {
232
- action: "react",
233
- chatJid: "123@s.whatsapp.net",
234
- messageId: "msg1",
235
- emoji: "✅",
236
- },
237
- cfg,
238
- ),
239
- ).rejects.toThrow(/WhatsApp reactions are disabled/);
240
- expect(sendReactionWhatsApp).not.toHaveBeenCalled();
241
- });
242
-
243
- it.each(["off", "ack"] as const)(
244
- "blocks agent reactions when reactionLevel is %s",
245
- async (reactionLevel) => {
246
- await expect(
247
- handleWhatsAppAction(
248
- {
249
- action: "react",
250
- chatJid: "123@s.whatsapp.net",
251
- messageId: "msg1",
252
- emoji: "✅",
253
- },
254
- reactionConfig(reactionLevel),
255
- ),
256
- ).rejects.toThrow(
257
- new RegExp(`WhatsApp agent reactions disabled \\(reactionLevel="${reactionLevel}"\\)`),
258
- );
259
- expect(sendReactionWhatsApp).not.toHaveBeenCalled();
260
- },
261
- );
262
-
263
- it("applies default account allowFrom when accountId is omitted", async () => {
264
- const cfg = {
265
- channels: {
266
- whatsapp: {
267
- actions: { reactions: true },
268
- allowFrom: ["111@s.whatsapp.net"],
269
- accounts: {
270
- [DEFAULT_ACCOUNT_ID]: {
271
- allowFrom: ["222@s.whatsapp.net"],
272
- },
273
- },
274
- },
275
- },
276
- } as OpenClawConfig;
277
-
278
- await expect(
279
- handleWhatsAppAction(
280
- {
281
- action: "react",
282
- chatJid: "111@s.whatsapp.net",
283
- messageId: "msg1",
284
- emoji: "✅",
285
- },
286
- cfg,
287
- ),
288
- ).rejects.toMatchObject({
289
- name: "ToolAuthorizationError",
290
- status: 403,
291
- });
292
- });
293
-
294
- it("routes to resolved default account when no accountId is provided", async () => {
295
- const cfg = {
296
- channels: {
297
- whatsapp: {
298
- actions: { reactions: true },
299
- accounts: {
300
- work: {
301
- allowFrom: ["123@s.whatsapp.net"],
302
- },
303
- },
304
- },
305
- },
306
- } as OpenClawConfig;
307
-
308
- await handleWhatsAppAction(
309
- {
310
- action: "react",
311
- chatJid: "123@s.whatsapp.net",
312
- messageId: "msg1",
313
- emoji: "✅",
314
- },
315
- cfg,
316
- );
317
-
318
- expect(sendReactionWhatsApp).toHaveBeenLastCalledWith(
319
- "+123",
320
- "msg1",
321
- "✅",
322
- expect.objectContaining({
323
- verbose: false,
324
- fromMe: undefined,
325
- participant: undefined,
326
- accountId: "work",
327
- }),
328
- );
329
- });
330
- });
@@ -1,76 +0,0 @@
1
- import type { AgentToolResult } from "@mariozechner/pi-agent-core";
2
- import {
3
- createActionGate,
4
- jsonResult,
5
- readReactionParams,
6
- readStringParam,
7
- } from "openclaw/plugin-sdk/channel-actions";
8
- import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
9
- import { resolveAuthorizedWhatsAppOutboundTarget } from "./action-runtime-target-auth.js";
10
- import { resolveWhatsAppReactionLevel } from "./reaction-level.js";
11
- import { sendReactionWhatsApp } from "./send.js";
12
-
13
- export const whatsAppActionRuntime = {
14
- resolveAuthorizedWhatsAppOutboundTarget,
15
- sendReactionWhatsApp,
16
- };
17
-
18
- export async function handleWhatsAppAction(
19
- params: Record<string, unknown>,
20
- cfg: OpenClawConfig,
21
- ): Promise<AgentToolResult<unknown>> {
22
- const action = readStringParam(params, "action", { required: true });
23
- const whatsAppConfig = cfg.channels?.whatsapp;
24
- const isActionEnabled = createActionGate(whatsAppConfig?.actions);
25
-
26
- if (action === "react") {
27
- const accountId = readStringParam(params, "accountId");
28
- if (!whatsAppConfig) {
29
- throw new Error("WhatsApp reactions are disabled.");
30
- }
31
- if (!isActionEnabled("reactions")) {
32
- throw new Error("WhatsApp reactions are disabled.");
33
- }
34
- const reactionLevelInfo = resolveWhatsAppReactionLevel({
35
- cfg,
36
- accountId: accountId ?? undefined,
37
- });
38
- if (!reactionLevelInfo.agentReactionsEnabled) {
39
- throw new Error(
40
- `WhatsApp agent reactions disabled (reactionLevel="${reactionLevelInfo.level}"). ` +
41
- `Set channels.whatsapp.reactionLevel to "minimal" or "extensive" to enable.`,
42
- );
43
- }
44
- const chatJid = readStringParam(params, "chatJid", { required: true });
45
- const messageId = readStringParam(params, "messageId", { required: true });
46
- const { emoji, remove, isEmpty } = readReactionParams(params, {
47
- removeErrorMessage: "Emoji is required to remove a WhatsApp reaction.",
48
- });
49
- const participant = readStringParam(params, "participant");
50
- const fromMeRaw = params.fromMe;
51
- const fromMe = typeof fromMeRaw === "boolean" ? fromMeRaw : undefined;
52
-
53
- // Resolve account + allowFrom via shared account logic so auth and routing stay aligned.
54
- const resolved = whatsAppActionRuntime.resolveAuthorizedWhatsAppOutboundTarget({
55
- cfg,
56
- chatJid,
57
- accountId,
58
- actionLabel: "reaction",
59
- });
60
-
61
- const resolvedEmoji = remove ? "" : emoji;
62
- await whatsAppActionRuntime.sendReactionWhatsApp(resolved.to, messageId, resolvedEmoji, {
63
- verbose: false,
64
- fromMe,
65
- participant: participant ?? undefined,
66
- accountId: resolved.accountId,
67
- cfg,
68
- });
69
- if (!remove && !isEmpty) {
70
- return jsonResult({ ok: true, added: emoji });
71
- }
72
- return jsonResult({ ok: true, removed: true });
73
- }
74
-
75
- throw new Error(`Unsupported WhatsApp action: ${action}`);
76
- }
@@ -1,65 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from "vitest";
2
- import { getActiveWebListener, resolveWebAccountId } from "./active-listener.js";
3
-
4
- const registryMocks = vi.hoisted(() => ({
5
- getRegisteredWhatsAppConnectionController: vi.fn(),
6
- }));
7
-
8
- vi.mock("./connection-controller-registry.js", () => ({
9
- getRegisteredWhatsAppConnectionController:
10
- registryMocks.getRegisteredWhatsAppConnectionController,
11
- }));
12
-
13
- const WHATSAPP_ACTIVE_LISTENER_TEST_CFG = {
14
- channels: { whatsapp: { accounts: { work: { enabled: true } }, defaultAccount: "work" } },
15
- };
16
-
17
- function makeListener() {
18
- return {
19
- sendMessage: vi.fn(async () => ({ messageId: "msg-1" })),
20
- sendPoll: vi.fn(async () => ({ messageId: "poll-1" })),
21
- sendReaction: vi.fn(async () => {}),
22
- sendComposingTo: vi.fn(async () => {}),
23
- };
24
- }
25
-
26
- beforeEach(() => {
27
- registryMocks.getRegisteredWhatsAppConnectionController.mockReset();
28
- });
29
-
30
- describe("active WhatsApp listener view", () => {
31
- it("reads controller-backed state", () => {
32
- const listener = makeListener();
33
- registryMocks.getRegisteredWhatsAppConnectionController.mockImplementation(
34
- (accountId: string) =>
35
- accountId === "work"
36
- ? {
37
- getActiveListener: () => listener,
38
- }
39
- : null,
40
- );
41
-
42
- expect(getActiveWebListener("work")).toBe(listener);
43
- });
44
-
45
- it("resolves the configured default account when accountId is omitted", () => {
46
- const listener = makeListener();
47
- registryMocks.getRegisteredWhatsAppConnectionController.mockImplementation(
48
- (accountId: string) =>
49
- accountId === "work"
50
- ? {
51
- getActiveListener: () => listener,
52
- }
53
- : null,
54
- );
55
-
56
- expect(resolveWebAccountId({ cfg: WHATSAPP_ACTIVE_LISTENER_TEST_CFG })).toBe("work");
57
- expect(getActiveWebListener("work")).toBe(listener);
58
- });
59
-
60
- it("returns null when the controller has no active listener for the account", () => {
61
- registryMocks.getRegisteredWhatsAppConnectionController.mockReturnValue(null);
62
-
63
- expect(getActiveWebListener("work")).toBeNull();
64
- });
65
- });
@@ -1,17 +0,0 @@
1
- import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
2
- import { resolveDefaultWhatsAppAccountId } from "./account-ids.js";
3
- import { getRegisteredWhatsAppConnectionController } from "./connection-controller-registry.js";
4
- import type { ActiveWebListener, ActiveWebSendOptions } from "./inbound/types.js";
5
-
6
- export type { ActiveWebListener, ActiveWebSendOptions } from "./inbound/types.js";
7
-
8
- export function resolveWebAccountId(params: {
9
- cfg: OpenClawConfig;
10
- accountId?: string | null;
11
- }): string {
12
- return (params.accountId ?? "").trim() || resolveDefaultWhatsAppAccountId(params.cfg);
13
- }
14
-
15
- export function getActiveWebListener(accountId: string): ActiveWebListener | null {
16
- return getRegisteredWhatsAppConnectionController(accountId)?.getActiveListener() ?? null;
17
- }
@@ -1,81 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from "vitest";
2
- import { startWebLoginWithQr, waitForWebLogin } from "../login-qr-api.js";
3
- import { createWhatsAppLoginTool } from "./agent-tools-login.js";
4
-
5
- vi.mock("../login-qr-api.js", () => ({
6
- startWebLoginWithQr: vi.fn(),
7
- waitForWebLogin: vi.fn(),
8
- }));
9
-
10
- const startWebLoginWithQrMock = vi.mocked(startWebLoginWithQr);
11
- const waitForWebLoginMock = vi.mocked(waitForWebLogin);
12
-
13
- describe("createWhatsAppLoginTool", () => {
14
- beforeEach(() => {
15
- vi.clearAllMocks();
16
- });
17
-
18
- it("passes the caller's current QR back into wait actions", async () => {
19
- const accountId = "account-1";
20
- waitForWebLoginMock.mockResolvedValueOnce({
21
- connected: false,
22
- message: "QR refreshed. Scan the latest code in WhatsApp → Linked Devices.",
23
- qrDataUrl: "data:image/png;base64,next-qr",
24
- });
25
-
26
- const tool = createWhatsAppLoginTool();
27
- const result = await tool.execute("tool-call-1", {
28
- action: "wait",
29
- timeoutMs: 5000,
30
- accountId,
31
- currentQrDataUrl: "data:image/png;base64,current-qr",
32
- });
33
-
34
- expect(waitForWebLoginMock).toHaveBeenCalledWith({
35
- accountId,
36
- timeoutMs: 5000,
37
- currentQrDataUrl: "data:image/png;base64,current-qr",
38
- });
39
- expect(result).toEqual({
40
- content: [
41
- {
42
- type: "text",
43
- text: [
44
- "QR refreshed. Scan the latest code in WhatsApp → Linked Devices.",
45
- "",
46
- "Open WhatsApp → Linked Devices and scan:",
47
- "",
48
- "![whatsapp-qr](data:image/png;base64,next-qr)",
49
- ].join("\n"),
50
- },
51
- ],
52
- details: {
53
- connected: false,
54
- qr: true,
55
- },
56
- });
57
- });
58
-
59
- it("does not retain QR state across tool actions", async () => {
60
- const accountId = "account-2";
61
- startWebLoginWithQrMock.mockResolvedValueOnce({
62
- connected: false,
63
- message: "Scan this QR in WhatsApp → Linked Devices.",
64
- qrDataUrl: "data:image/png;base64,current-qr",
65
- });
66
- waitForWebLoginMock.mockResolvedValueOnce({
67
- connected: true,
68
- message: "✅ Linked! WhatsApp is ready.",
69
- });
70
-
71
- const tool = createWhatsAppLoginTool();
72
- await tool.execute("tool-call-start", { action: "start", accountId });
73
- await tool.execute("tool-call-wait", { action: "wait", timeoutMs: 5000, accountId });
74
-
75
- expect(waitForWebLoginMock).toHaveBeenCalledWith({
76
- accountId,
77
- timeoutMs: 5000,
78
- currentQrDataUrl: undefined,
79
- });
80
- });
81
- });
@@ -1,113 +0,0 @@
1
- import type { ChannelAgentTool } from "openclaw/plugin-sdk/channel-contract";
2
- import { Type } from "typebox";
3
- import { startWebLoginWithQr, waitForWebLogin } from "../login-qr-api.js";
4
-
5
- const QR_DATA_URL_MAX_LENGTH = 16_384;
6
-
7
- function readOptionalString(value: unknown): string | undefined {
8
- return typeof value === "string" && value.trim() ? value : undefined;
9
- }
10
-
11
- export function createWhatsAppLoginTool(): ChannelAgentTool {
12
- return {
13
- label: "WhatsApp Login",
14
- name: "whatsapp_login",
15
- ownerOnly: true,
16
- description: "Generate a WhatsApp QR code for linking, or wait for the scan to complete.",
17
- // NOTE: Using Type.Unsafe for action enum instead of Type.Union([Type.Literal(...)]
18
- // because Claude API on Vertex AI rejects nested anyOf schemas as invalid JSON Schema.
19
- parameters: Type.Object({
20
- action: Type.Unsafe<"start" | "wait">({
21
- type: "string",
22
- enum: ["start", "wait"],
23
- }),
24
- timeoutMs: Type.Optional(Type.Number()),
25
- force: Type.Optional(Type.Boolean()),
26
- accountId: Type.Optional(Type.String()),
27
- currentQrDataUrl: Type.Optional(
28
- Type.String({
29
- maxLength: QR_DATA_URL_MAX_LENGTH,
30
- pattern: "^data:image/png;base64,",
31
- }),
32
- ),
33
- }),
34
- execute: async (_toolCallId, args) => {
35
- const renderQrReply = (params: {
36
- message: string;
37
- qrDataUrl: string;
38
- connected?: boolean;
39
- }) => {
40
- const text = [
41
- params.message,
42
- "",
43
- "Open WhatsApp → Linked Devices and scan:",
44
- "",
45
- `![whatsapp-qr](${params.qrDataUrl})`,
46
- ].join("\n");
47
- return {
48
- content: [{ type: "text" as const, text }],
49
- details: {
50
- connected: params.connected ?? false,
51
- qr: true,
52
- },
53
- };
54
- };
55
-
56
- const action = (args as { action?: string })?.action ?? "start";
57
- const accountId = readOptionalString((args as { accountId?: unknown }).accountId);
58
- if (action === "wait") {
59
- const result = await waitForWebLogin({
60
- accountId,
61
- timeoutMs:
62
- typeof (args as { timeoutMs?: unknown }).timeoutMs === "number"
63
- ? (args as { timeoutMs?: number }).timeoutMs
64
- : undefined,
65
- currentQrDataUrl: readOptionalString(
66
- (args as { currentQrDataUrl?: unknown }).currentQrDataUrl,
67
- ),
68
- });
69
- if (result.qrDataUrl) {
70
- return renderQrReply({
71
- message: result.message,
72
- qrDataUrl: result.qrDataUrl,
73
- connected: result.connected,
74
- });
75
- }
76
- return {
77
- content: [{ type: "text", text: result.message }],
78
- details: { connected: result.connected },
79
- };
80
- }
81
-
82
- const result = await startWebLoginWithQr({
83
- accountId,
84
- timeoutMs:
85
- typeof (args as { timeoutMs?: unknown }).timeoutMs === "number"
86
- ? (args as { timeoutMs?: number }).timeoutMs
87
- : undefined,
88
- force:
89
- typeof (args as { force?: unknown }).force === "boolean"
90
- ? (args as { force?: boolean }).force
91
- : false,
92
- });
93
-
94
- if (!result.qrDataUrl) {
95
- return {
96
- content: [
97
- {
98
- type: "text",
99
- text: result.message,
100
- },
101
- ],
102
- details: { qr: false },
103
- };
104
- }
105
-
106
- return renderQrReply({
107
- message: result.message,
108
- qrDataUrl: result.qrDataUrl,
109
- connected: result.connected,
110
- });
111
- },
112
- };
113
- }