@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
package/src/shared.ts DELETED
@@ -1,291 +0,0 @@
1
- import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk/account-core";
2
- import { describeAccountSnapshot } from "openclaw/plugin-sdk/account-helpers";
3
- import { normalizeE164 } from "openclaw/plugin-sdk/account-resolution";
4
- import {
5
- adaptScopedAccountAccessor,
6
- createScopedChannelConfigAdapter,
7
- createScopedDmSecurityResolver,
8
- } from "openclaw/plugin-sdk/channel-config-helpers";
9
- import {
10
- collectOpenGroupPolicyRouteAllowlistWarnings,
11
- createAllowlistProviderGroupPolicyWarningCollector,
12
- } from "openclaw/plugin-sdk/channel-policy";
13
- import type { ChannelPlugin } from "openclaw/plugin-sdk/core";
14
- import { createChannelPluginBase, getChatChannelMeta } from "openclaw/plugin-sdk/core";
15
- import {
16
- createDelegatedSetupWizardProxy,
17
- type ChannelSetupWizard,
18
- } from "openclaw/plugin-sdk/setup-runtime";
19
- import {
20
- hasAnyWhatsAppAuth,
21
- listWhatsAppAccountIds,
22
- resolveDefaultWhatsAppAccountId,
23
- resolveWhatsAppAccount,
24
- type ResolvedWhatsAppAccount,
25
- } from "./accounts.js";
26
- import { formatWhatsAppConfigAllowFromEntries } from "./config-accessors.js";
27
- import { WhatsAppChannelConfigSchema } from "./config-schema.js";
28
- import { whatsappDoctor } from "./doctor.js";
29
- import { resolveLegacyGroupSessionKey } from "./group-session-contract.js";
30
- import {
31
- collectUnsupportedSecretRefConfigCandidates,
32
- unsupportedSecretRefSurfacePatterns,
33
- } from "./security-contract.js";
34
- import { applyWhatsAppSecurityConfigFixes } from "./security-fix.js";
35
- import {
36
- canonicalizeLegacySessionKey,
37
- deriveLegacySessionChatType,
38
- isLegacyGroupSessionKey,
39
- } from "./session-contract.js";
40
-
41
- const WHATSAPP_CHANNEL = "whatsapp" as const;
42
-
43
- const WHATSAPP_GROUP_SCOPE_FIELDS = ["groupPolicy", "groupAllowFrom", "groups"] as const;
44
-
45
- type WhatsAppGroupScopeField = (typeof WHATSAPP_GROUP_SCOPE_FIELDS)[number];
46
-
47
- function resolveWhatsAppAccountKey(
48
- accounts: Record<string, unknown> | undefined,
49
- accountId: string,
50
- ): string | undefined {
51
- if (!accounts) {
52
- return undefined;
53
- }
54
- if (Object.hasOwn(accounts, accountId)) {
55
- return accountId;
56
- }
57
- const normalizedAccountId = accountId.trim().toLowerCase();
58
- return Object.keys(accounts).find((key) => key.trim().toLowerCase() === normalizedAccountId);
59
- }
60
-
61
- function resolveWhatsAppGroupScopeBasePath(params: {
62
- cfg: Parameters<typeof resolveWhatsAppAccount>[0]["cfg"];
63
- accountId?: string | null;
64
- }): string {
65
- const accountId =
66
- typeof params.accountId === "string"
67
- ? params.accountId.trim() || DEFAULT_ACCOUNT_ID
68
- : DEFAULT_ACCOUNT_ID;
69
- const accounts = params.cfg.channels?.whatsapp?.accounts;
70
- const accountKey = resolveWhatsAppAccountKey(accounts, accountId);
71
- const defaultAccountKey = resolveWhatsAppAccountKey(accounts, DEFAULT_ACCOUNT_ID);
72
- const accountConfig = accountKey ? accounts?.[accountKey] : undefined;
73
- const defaultAccountConfig = defaultAccountKey ? accounts?.[defaultAccountKey] : undefined;
74
- const matchesAnyGroupScopeField = (config: Record<string, unknown> | undefined): boolean =>
75
- WHATSAPP_GROUP_SCOPE_FIELDS.some((field) => config?.[field] !== undefined);
76
- if (matchesAnyGroupScopeField(accountConfig)) {
77
- return `channels.whatsapp.accounts.${accountKey}`;
78
- }
79
- if (accountId !== DEFAULT_ACCOUNT_ID && matchesAnyGroupScopeField(defaultAccountConfig)) {
80
- return `channels.whatsapp.accounts.${defaultAccountKey}`;
81
- }
82
- return "channels.whatsapp";
83
- }
84
-
85
- function resolveWhatsAppConfigPath(params: {
86
- cfg: Parameters<typeof resolveWhatsAppAccount>[0]["cfg"];
87
- accountId?: string | null;
88
- field: WhatsAppGroupScopeField;
89
- }): string {
90
- return `${resolveWhatsAppGroupScopeBasePath(params)}.${params.field}`;
91
- }
92
-
93
- export async function loadWhatsAppChannelRuntime() {
94
- return await import("./channel.runtime.js");
95
- }
96
-
97
- async function loadWhatsAppSetupSurface() {
98
- return await import("./setup-surface.js");
99
- }
100
-
101
- export const whatsappSetupWizardProxy = createWhatsAppSetupWizardProxy(
102
- async () => (await loadWhatsAppSetupSurface()).whatsappSetupWizard,
103
- );
104
-
105
- const whatsappConfigAdapter = createScopedChannelConfigAdapter<ResolvedWhatsAppAccount>({
106
- sectionKey: WHATSAPP_CHANNEL,
107
- listAccountIds: listWhatsAppAccountIds,
108
- resolveAccount: adaptScopedAccountAccessor(resolveWhatsAppAccount),
109
- defaultAccountId: resolveDefaultWhatsAppAccountId,
110
- clearBaseFields: [],
111
- allowTopLevel: false,
112
- resolveAllowFrom: (account) => account.allowFrom,
113
- formatAllowFrom: (allowFrom) => formatWhatsAppConfigAllowFromEntries(allowFrom),
114
- resolveDefaultTo: (account) => account.defaultTo,
115
- });
116
-
117
- const whatsappResolveDmPolicy = createScopedDmSecurityResolver<ResolvedWhatsAppAccount>({
118
- channelKey: WHATSAPP_CHANNEL,
119
- resolvePolicy: (account) => account.dmPolicy,
120
- resolveAllowFrom: (account) => account.allowFrom,
121
- policyPathSuffix: "dmPolicy",
122
- normalizeEntry: (raw) => normalizeE164(raw),
123
- inheritSharedDefaultsFromDefaultAccount: true,
124
- });
125
-
126
- function createWhatsAppSetupWizardProxy(
127
- loadWizard: () => Promise<ChannelSetupWizard>,
128
- ): ChannelSetupWizard {
129
- return createDelegatedSetupWizardProxy({
130
- channel: WHATSAPP_CHANNEL,
131
- loadWizard,
132
- status: {
133
- configuredLabel: "linked",
134
- unconfiguredLabel: "not linked",
135
- configuredHint: "linked",
136
- unconfiguredHint: "not linked",
137
- configuredScore: 5,
138
- unconfiguredScore: 4,
139
- },
140
- resolveShouldPromptAccountIds: (params) => params.shouldPromptAccountIds,
141
- credentials: [],
142
- delegateFinalize: true,
143
- disable: (cfg) => ({
144
- ...cfg,
145
- channels: {
146
- ...cfg.channels,
147
- whatsapp: {
148
- ...cfg.channels?.whatsapp,
149
- enabled: false,
150
- },
151
- },
152
- }),
153
- onAccountRecorded: (accountId, options) => {
154
- options?.onAccountId?.(WHATSAPP_CHANNEL, accountId);
155
- },
156
- });
157
- }
158
-
159
- export function createWhatsAppPluginBase(params: {
160
- groups: NonNullable<ChannelPlugin<ResolvedWhatsAppAccount>["groups"]>;
161
- setupWizard: NonNullable<ChannelPlugin<ResolvedWhatsAppAccount>["setupWizard"]>;
162
- setup: NonNullable<ChannelPlugin<ResolvedWhatsAppAccount>["setup"]>;
163
- isConfigured: NonNullable<ChannelPlugin<ResolvedWhatsAppAccount>["config"]>["isConfigured"];
164
- }) {
165
- const collectWhatsAppSecurityWarnings = createAllowlistProviderGroupPolicyWarningCollector<{
166
- account: ResolvedWhatsAppAccount;
167
- cfg: Parameters<typeof resolveWhatsAppAccount>[0]["cfg"];
168
- accountId?: string | null;
169
- }>({
170
- providerConfigPresent: (cfg) => cfg.channels?.whatsapp !== undefined,
171
- resolveGroupPolicy: ({ account }) => account.groupPolicy,
172
- collect: ({ account, accountId, cfg, groupPolicy }) =>
173
- collectOpenGroupPolicyRouteAllowlistWarnings({
174
- groupPolicy,
175
- routeAllowlistConfigured:
176
- Boolean(account.groups) && Object.keys(account.groups ?? {}).length > 0,
177
- restrictSenders: {
178
- surface: "WhatsApp groups",
179
- openScope: "any member in allowed groups",
180
- groupPolicyPath: resolveWhatsAppConfigPath({ cfg, accountId, field: "groupPolicy" }),
181
- groupAllowFromPath: resolveWhatsAppConfigPath({
182
- cfg,
183
- accountId,
184
- field: "groupAllowFrom",
185
- }),
186
- },
187
- noRouteAllowlist: {
188
- surface: "WhatsApp groups",
189
- routeAllowlistPath: resolveWhatsAppConfigPath({ cfg, accountId, field: "groups" }),
190
- routeScope: "group",
191
- groupPolicyPath: resolveWhatsAppConfigPath({ cfg, accountId, field: "groupPolicy" }),
192
- groupAllowFromPath: resolveWhatsAppConfigPath({
193
- cfg,
194
- accountId,
195
- field: "groupAllowFrom",
196
- }),
197
- },
198
- }),
199
- });
200
- const base = createChannelPluginBase({
201
- id: WHATSAPP_CHANNEL,
202
- meta: {
203
- ...getChatChannelMeta(WHATSAPP_CHANNEL),
204
- showConfigured: false,
205
- quickstartAllowFrom: true,
206
- forceAccountBinding: true,
207
- preferSessionLookupForAnnounceTarget: true,
208
- },
209
- setupWizard: params.setupWizard,
210
- capabilities: {
211
- chatTypes: ["direct", "group", "channel"],
212
- polls: true,
213
- reactions: true,
214
- media: true,
215
- tts: {
216
- voice: {
217
- synthesisTarget: "voice-note",
218
- transcodesAudio: true,
219
- },
220
- },
221
- },
222
- reload: { configPrefixes: ["web"], noopPrefixes: ["channels.whatsapp"] },
223
- gatewayMethods: ["web.login.start", "web.login.wait"],
224
- configSchema: WhatsAppChannelConfigSchema,
225
- config: {
226
- ...whatsappConfigAdapter,
227
- isEnabled: (account, cfg) => account.enabled && cfg.web?.enabled !== false,
228
- disabledReason: () => "disabled",
229
- isConfigured: params.isConfigured,
230
- hasPersistedAuthState: ({ cfg }) => hasAnyWhatsAppAuth(cfg),
231
- unconfiguredReason: () => "not linked",
232
- describeAccount: (account) =>
233
- describeAccountSnapshot({
234
- account,
235
- configured: Boolean(account.authDir),
236
- extra: {
237
- linked: Boolean(account.authDir),
238
- dmPolicy: account.dmPolicy,
239
- allowFrom: account.allowFrom,
240
- },
241
- }),
242
- },
243
- security: {
244
- applyConfigFixes: applyWhatsAppSecurityConfigFixes,
245
- resolveDmPolicy: whatsappResolveDmPolicy,
246
- collectWarnings: collectWhatsAppSecurityWarnings,
247
- },
248
- doctor: whatsappDoctor,
249
- setup: params.setup,
250
- groups: params.groups,
251
- });
252
- return {
253
- ...base,
254
- setupWizard: base.setupWizard!,
255
- capabilities: base.capabilities!,
256
- reload: base.reload!,
257
- gatewayMethods: base.gatewayMethods!,
258
- configSchema: base.configSchema!,
259
- config: base.config!,
260
- messaging: {
261
- defaultMarkdownTableMode: "bullets",
262
- deriveLegacySessionChatType,
263
- resolveLegacyGroupSessionKey,
264
- isLegacyGroupSessionKey,
265
- canonicalizeLegacySessionKey: (params) =>
266
- canonicalizeLegacySessionKey({ key: params.key, agentId: params.agentId }),
267
- },
268
- secrets: {
269
- unsupportedSecretRefSurfacePatterns,
270
- collectUnsupportedSecretRefConfigCandidates,
271
- },
272
- security: base.security!,
273
- groups: base.groups!,
274
- } satisfies Pick<
275
- ChannelPlugin<ResolvedWhatsAppAccount>,
276
- | "id"
277
- | "meta"
278
- | "setupWizard"
279
- | "capabilities"
280
- | "reload"
281
- | "gatewayMethods"
282
- | "configSchema"
283
- | "config"
284
- | "messaging"
285
- | "secrets"
286
- | "security"
287
- | "doctor"
288
- | "setup"
289
- | "groups"
290
- >;
291
- }
@@ -1,49 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { DEFAULT_WHATSAPP_SOCKET_TIMING, resolveWhatsAppSocketTiming } from "./socket-timing.js";
3
-
4
- describe("resolveWhatsAppSocketTiming", () => {
5
- it("uses OpenClaw's explicit WhatsApp Web socket defaults", () => {
6
- expect(resolveWhatsAppSocketTiming({})).toEqual(DEFAULT_WHATSAPP_SOCKET_TIMING);
7
- });
8
-
9
- it("reads Baileys timing values from web.whatsapp config", () => {
10
- expect(
11
- resolveWhatsAppSocketTiming({
12
- web: {
13
- whatsapp: {
14
- keepAliveIntervalMs: 10_000,
15
- connectTimeoutMs: 90_000,
16
- defaultQueryTimeoutMs: 120_000,
17
- },
18
- },
19
- }),
20
- ).toEqual({
21
- keepAliveIntervalMs: 10_000,
22
- connectTimeoutMs: 90_000,
23
- defaultQueryTimeoutMs: 120_000,
24
- });
25
- });
26
-
27
- it("lets call-site overrides take precedence over config", () => {
28
- expect(
29
- resolveWhatsAppSocketTiming(
30
- {
31
- web: {
32
- whatsapp: {
33
- keepAliveIntervalMs: 10_000,
34
- connectTimeoutMs: 90_000,
35
- defaultQueryTimeoutMs: 120_000,
36
- },
37
- },
38
- },
39
- {
40
- keepAliveIntervalMs: 20_000,
41
- },
42
- ),
43
- ).toEqual({
44
- keepAliveIntervalMs: 20_000,
45
- connectTimeoutMs: 90_000,
46
- defaultQueryTimeoutMs: 120_000,
47
- });
48
- });
49
- });
@@ -1,38 +0,0 @@
1
- import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
2
-
3
- export type WhatsAppSocketTimingOptions = {
4
- keepAliveIntervalMs?: number;
5
- connectTimeoutMs?: number;
6
- defaultQueryTimeoutMs?: number;
7
- };
8
-
9
- export const DEFAULT_WHATSAPP_SOCKET_TIMING: Required<WhatsAppSocketTimingOptions> = {
10
- keepAliveIntervalMs: 25_000,
11
- connectTimeoutMs: 60_000,
12
- defaultQueryTimeoutMs: 60_000,
13
- };
14
-
15
- function positiveInteger(value: number | undefined): number | undefined {
16
- return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : undefined;
17
- }
18
-
19
- export function resolveWhatsAppSocketTiming(
20
- cfg: OpenClawConfig,
21
- overrides?: WhatsAppSocketTimingOptions,
22
- ): Required<WhatsAppSocketTimingOptions> {
23
- const configured = cfg.web?.whatsapp;
24
- return {
25
- keepAliveIntervalMs:
26
- positiveInteger(overrides?.keepAliveIntervalMs) ??
27
- positiveInteger(configured?.keepAliveIntervalMs) ??
28
- DEFAULT_WHATSAPP_SOCKET_TIMING.keepAliveIntervalMs,
29
- connectTimeoutMs:
30
- positiveInteger(overrides?.connectTimeoutMs) ??
31
- positiveInteger(configured?.connectTimeoutMs) ??
32
- DEFAULT_WHATSAPP_SOCKET_TIMING.connectTimeoutMs,
33
- defaultQueryTimeoutMs:
34
- positiveInteger(overrides?.defaultQueryTimeoutMs) ??
35
- positiveInteger(configured?.defaultQueryTimeoutMs) ??
36
- DEFAULT_WHATSAPP_SOCKET_TIMING.defaultQueryTimeoutMs,
37
- };
38
- }
@@ -1,54 +0,0 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk/account-id";
4
- import type { ChannelLegacyStateMigrationPlan } from "openclaw/plugin-sdk/channel-contract";
5
-
6
- function fileExists(pathValue: string): boolean {
7
- try {
8
- return fs.existsSync(pathValue) && fs.statSync(pathValue).isFile();
9
- } catch {
10
- return false;
11
- }
12
- }
13
-
14
- function isLegacyWhatsAppAuthFile(name: string): boolean {
15
- if (name === "creds.json" || name === "creds.json.bak") {
16
- return true;
17
- }
18
- if (!name.endsWith(".json")) {
19
- return false;
20
- }
21
- return /^(app-state-sync|session|sender-key|pre-key)-/.test(name);
22
- }
23
-
24
- export function detectWhatsAppLegacyStateMigrations(params: {
25
- oauthDir: string;
26
- }): ChannelLegacyStateMigrationPlan[] {
27
- const targetDir = path.join(params.oauthDir, "whatsapp", DEFAULT_ACCOUNT_ID);
28
- const entries = (() => {
29
- try {
30
- return fs.readdirSync(params.oauthDir, { withFileTypes: true });
31
- } catch {
32
- return [];
33
- }
34
- })();
35
-
36
- return entries.flatMap((entry) => {
37
- if (!entry.isFile() || entry.name === "oauth.json" || !isLegacyWhatsAppAuthFile(entry.name)) {
38
- return [];
39
- }
40
- const sourcePath = path.join(params.oauthDir, entry.name);
41
- const targetPath = path.join(targetDir, entry.name);
42
- if (fileExists(targetPath)) {
43
- return [];
44
- }
45
- return [
46
- {
47
- kind: "move" as const,
48
- label: `WhatsApp auth ${entry.name}`,
49
- sourcePath,
50
- targetPath,
51
- },
52
- ];
53
- });
54
- }
@@ -1,137 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { collectWhatsAppStatusIssues } from "./status-issues.js";
3
-
4
- describe("collectWhatsAppStatusIssues", () => {
5
- it("reports unlinked enabled accounts", () => {
6
- const issues = collectWhatsAppStatusIssues([
7
- {
8
- accountId: "default",
9
- enabled: true,
10
- linked: false,
11
- },
12
- ]);
13
-
14
- expect(issues).toEqual([
15
- expect.objectContaining({
16
- channel: "whatsapp",
17
- accountId: "default",
18
- kind: "auth",
19
- }),
20
- ]);
21
- });
22
-
23
- it("reports auth reads that are still stabilizing", () => {
24
- const issues = collectWhatsAppStatusIssues([
25
- {
26
- accountId: "default",
27
- enabled: true,
28
- statusState: "unstable",
29
- },
30
- ]);
31
-
32
- expect(issues).toEqual([
33
- expect.objectContaining({
34
- channel: "whatsapp",
35
- accountId: "default",
36
- kind: "auth",
37
- message: "Auth state is still stabilizing.",
38
- }),
39
- ]);
40
- });
41
-
42
- it("reports linked but disconnected runtime state", () => {
43
- const issues = collectWhatsAppStatusIssues([
44
- {
45
- accountId: "work",
46
- enabled: true,
47
- linked: true,
48
- running: true,
49
- connected: false,
50
- reconnectAttempts: 2,
51
- lastError: "socket closed",
52
- },
53
- ]);
54
-
55
- expect(issues).toEqual([
56
- expect.objectContaining({
57
- channel: "whatsapp",
58
- accountId: "work",
59
- kind: "runtime",
60
- message: "Linked but disconnected (reconnectAttempts=2): socket closed",
61
- }),
62
- ]);
63
- });
64
-
65
- it("reports linked but stale runtime state even while connected", () => {
66
- const issues = collectWhatsAppStatusIssues([
67
- {
68
- accountId: "default",
69
- enabled: true,
70
- linked: true,
71
- running: true,
72
- connected: true,
73
- healthState: "stale",
74
- lastInboundAt: Date.now() - 2 * 60_000,
75
- },
76
- ]);
77
-
78
- expect(issues).toEqual([
79
- expect.objectContaining({
80
- channel: "whatsapp",
81
- accountId: "default",
82
- kind: "runtime",
83
- message: expect.stringContaining("Linked but stale"),
84
- }),
85
- ]);
86
- });
87
-
88
- it("reports recently reconnected accounts even when the socket is currently healthy", () => {
89
- const issues = collectWhatsAppStatusIssues([
90
- {
91
- accountId: "default",
92
- enabled: true,
93
- linked: true,
94
- running: true,
95
- connected: true,
96
- reconnectAttempts: 3,
97
- healthState: "healthy",
98
- lastDisconnect: {
99
- at: Date.now() - 2 * 60_000,
100
- status: 408,
101
- error: "status=408 Request Time-out Connection was lost",
102
- },
103
- },
104
- ]);
105
-
106
- expect(issues).toEqual([
107
- expect.objectContaining({
108
- channel: "whatsapp",
109
- accountId: "default",
110
- kind: "runtime",
111
- message:
112
- "Linked but recently reconnected (reconnectAttempts=3): status=408 Request Time-out Connection was lost",
113
- }),
114
- ]);
115
- });
116
-
117
- it("does not report old reconnect history after a stable healthy period", () => {
118
- const issues = collectWhatsAppStatusIssues([
119
- {
120
- accountId: "default",
121
- enabled: true,
122
- linked: true,
123
- running: true,
124
- connected: true,
125
- reconnectAttempts: 1,
126
- healthState: "healthy",
127
- lastDisconnect: {
128
- at: Date.now() - 60 * 60_000,
129
- status: 408,
130
- error: "old disconnect",
131
- },
132
- },
133
- ]);
134
-
135
- expect(issues).toEqual([]);
136
- });
137
- });