@openclaw/whatsapp 2026.5.2-beta.2 → 2026.5.3-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (301) hide show
  1. package/dist/access-control-BQ3tCkH8.js +288 -0
  2. package/dist/account-config-CNQ33oav.js +47 -0
  3. package/dist/account-ids-DG18xddX.js +5 -0
  4. package/dist/accounts-BDqgpFEB.js +116 -0
  5. package/dist/action-runtime-DTGNgG-i.js +74 -0
  6. package/dist/action-runtime-api.js +2 -0
  7. package/dist/action-runtime.runtime.js +2 -0
  8. package/dist/active-listener-N7GFKsuN.js +11 -0
  9. package/dist/agent-tools-login-DpRxLNRB.js +89 -0
  10. package/dist/api.js +148 -0
  11. package/dist/audio-preflight.runtime-Bcdsl_ri.js +7 -0
  12. package/dist/auth-presence.js +32 -0
  13. package/dist/auth-store-BjCb50Ry.js +381 -0
  14. package/dist/channel-DQ-5Xoj9.js +542 -0
  15. package/dist/channel-config-api.js +2 -0
  16. package/dist/channel-plugin-api.js +2 -0
  17. package/dist/channel-react-action-Df20qAy9.js +42 -0
  18. package/dist/channel.runtime-DKXRnA8x.js +55 -0
  19. package/dist/channel.setup-DOHR2BGp.js +20 -0
  20. package/dist/command-policy-O8sRnqUV.js +8 -0
  21. package/dist/config-schema-Dmo66Ubb.js +27 -0
  22. package/dist/connection-controller-BiHAsTM8.js +596 -0
  23. package/dist/connection-controller-registry-D_iIGz5m.js +22 -0
  24. package/dist/constants-DLGCIbfl.js +4 -0
  25. package/dist/constants.js +2 -0
  26. package/dist/contract-api.js +19 -0
  27. package/dist/creds-files-_2V8jzQa.js +19 -0
  28. package/dist/directory-config-DVs4ffXu.js +37 -0
  29. package/dist/directory-contract-api.js +2 -0
  30. package/dist/doctor-A9tXm9Om.js +48 -0
  31. package/dist/doctor-contract-api.js +10 -0
  32. package/dist/group-session-contract-B8QBn0I2.js +15 -0
  33. package/dist/identity-QHAlV7Fu.js +75 -0
  34. package/dist/index.js +18 -0
  35. package/dist/legacy-session-surface-api.js +8 -0
  36. package/dist/legacy-state-migrations-api.js +2 -0
  37. package/dist/light-runtime-api.js +5 -0
  38. package/dist/login-DymdrKca.js +52 -0
  39. package/dist/login-qr-DIS0Iv-7.js +378 -0
  40. package/dist/login-qr-api.js +2 -0
  41. package/dist/login-qr-runtime.js +16 -0
  42. package/dist/monitor-C4Fhg_lD.js +3349 -0
  43. package/dist/normalize-CWYiGkXw.js +2 -0
  44. package/dist/normalize-target-BPVHNsM5.js +74 -0
  45. package/dist/outbound-adapter-BssVnZdz.js +29 -0
  46. package/dist/outbound-base-Bq1UYEK5.js +119 -0
  47. package/dist/outbound-media-contract-CGss_QHy.js +163 -0
  48. package/dist/outbound-payload-test-api.js +2 -0
  49. package/dist/quoted-message-TENQzyxV.js +108 -0
  50. package/dist/reaction-level-CRVEVAfi.js +16 -0
  51. package/dist/reply-resolver.runtime-BRCgoO4C.js +2 -0
  52. package/dist/resolve-outbound-target-CN-Wo6IY.js +39 -0
  53. package/dist/rolldown-runtime-RkAeH_Qm.js +27 -0
  54. package/dist/runtime-6fZ67abR.js +8 -0
  55. package/dist/runtime-api.js +15 -0
  56. package/dist/runtime-group-policy-Gp1lQ0at.js +11 -0
  57. package/dist/secret-contract-api.js +5 -0
  58. package/dist/security-contract-DqH8JDX6.js +26 -0
  59. package/dist/security-contract-api.js +2 -0
  60. package/dist/send-CIyLFxdZ.js +234 -0
  61. package/dist/session-contract-B0efQf9P.js +27 -0
  62. package/dist/session-errors-CSuKZPub.js +63 -0
  63. package/dist/session.runtime-C1eSE_KK.js +13 -0
  64. package/dist/setup-core-DZKvpzbH.js +46 -0
  65. package/dist/setup-entry.js +23 -0
  66. package/dist/setup-plugin-api.js +2 -0
  67. package/dist/setup-surface-ieFnIW4g.js +344 -0
  68. package/dist/shared-D_wzSVar.js +307 -0
  69. package/dist/state-migrations-DnCdvoYD.js +39 -0
  70. package/dist/targets.js +2 -0
  71. package/dist/test-api.js +3 -0
  72. package/dist/text-runtime-C1zNiZeO.js +116 -0
  73. package/package.json +14 -6
  74. package/action-runtime-api.ts +0 -1
  75. package/action-runtime.runtime.ts +0 -1
  76. package/api.ts +0 -213
  77. package/auth-presence.ts +0 -80
  78. package/channel-config-api.ts +0 -1
  79. package/channel-plugin-api.ts +0 -3
  80. package/config-api.ts +0 -4
  81. package/constants.ts +0 -1
  82. package/contract-api.ts +0 -29
  83. package/directory-contract-api.ts +0 -4
  84. package/doctor-contract-api.ts +0 -8
  85. package/index.test.ts +0 -13
  86. package/index.ts +0 -16
  87. package/legacy-session-surface-api.ts +0 -6
  88. package/legacy-state-migrations-api.ts +0 -1
  89. package/light-runtime-api.ts +0 -12
  90. package/login-qr-api.ts +0 -1
  91. package/login-qr-runtime.ts +0 -23
  92. package/outbound-payload-test-api.ts +0 -1
  93. package/runtime-api.ts +0 -84
  94. package/secret-contract-api.ts +0 -4
  95. package/security-contract-api.ts +0 -4
  96. package/setup-entry.test.ts +0 -21
  97. package/setup-entry.ts +0 -21
  98. package/setup-plugin-api.ts +0 -3
  99. package/src/account-config.ts +0 -77
  100. package/src/account-ids.ts +0 -13
  101. package/src/account-types.ts +0 -5
  102. package/src/accounts.test.ts +0 -182
  103. package/src/accounts.ts +0 -176
  104. package/src/accounts.whatsapp-auth.test.ts +0 -59
  105. package/src/action-runtime-target-auth.ts +0 -27
  106. package/src/action-runtime.test.ts +0 -330
  107. package/src/action-runtime.ts +0 -76
  108. package/src/active-listener.test.ts +0 -65
  109. package/src/active-listener.ts +0 -17
  110. package/src/agent-tools-login.test.ts +0 -81
  111. package/src/agent-tools-login.ts +0 -113
  112. package/src/approval-auth.test.ts +0 -24
  113. package/src/approval-auth.ts +0 -27
  114. package/src/auth-store.runtime.ts +0 -1
  115. package/src/auth-store.test.ts +0 -311
  116. package/src/auth-store.ts +0 -502
  117. package/src/auto-reply/config.runtime.ts +0 -16
  118. package/src/auto-reply/constants.ts +0 -1
  119. package/src/auto-reply/deliver-reply.test.ts +0 -843
  120. package/src/auto-reply/deliver-reply.ts +0 -279
  121. package/src/auto-reply/loggers.ts +0 -6
  122. package/src/auto-reply/mentions.ts +0 -131
  123. package/src/auto-reply/monitor/ack-reaction.test.ts +0 -170
  124. package/src/auto-reply/monitor/ack-reaction.ts +0 -99
  125. package/src/auto-reply/monitor/audio-preflight.runtime.ts +0 -9
  126. package/src/auto-reply/monitor/broadcast.ts +0 -153
  127. package/src/auto-reply/monitor/commands.ts +0 -19
  128. package/src/auto-reply/monitor/echo.ts +0 -64
  129. package/src/auto-reply/monitor/group-activation.runtime.ts +0 -1
  130. package/src/auto-reply/monitor/group-activation.test.ts +0 -189
  131. package/src/auto-reply/monitor/group-activation.ts +0 -73
  132. package/src/auto-reply/monitor/group-gating.audio-preflight.test.ts +0 -103
  133. package/src/auto-reply/monitor/group-gating.runtime.ts +0 -8
  134. package/src/auto-reply/monitor/group-gating.ts +0 -217
  135. package/src/auto-reply/monitor/group-members.test.ts +0 -56
  136. package/src/auto-reply/monitor/group-members.ts +0 -65
  137. package/src/auto-reply/monitor/inbound-context.test.ts +0 -97
  138. package/src/auto-reply/monitor/inbound-context.ts +0 -92
  139. package/src/auto-reply/monitor/inbound-dispatch.runtime.ts +0 -21
  140. package/src/auto-reply/monitor/inbound-dispatch.test.ts +0 -895
  141. package/src/auto-reply/monitor/inbound-dispatch.ts +0 -422
  142. package/src/auto-reply/monitor/last-route.test.ts +0 -37
  143. package/src/auto-reply/monitor/last-route.ts +0 -61
  144. package/src/auto-reply/monitor/message-line.runtime.ts +0 -38
  145. package/src/auto-reply/monitor/message-line.ts +0 -54
  146. package/src/auto-reply/monitor/on-message.audio-preflight.test.ts +0 -354
  147. package/src/auto-reply/monitor/on-message.ts +0 -291
  148. package/src/auto-reply/monitor/peer.ts +0 -17
  149. package/src/auto-reply/monitor/process-message.audio-preflight.test.ts +0 -420
  150. package/src/auto-reply/monitor/process-message.test.ts +0 -355
  151. package/src/auto-reply/monitor/process-message.ts +0 -531
  152. package/src/auto-reply/monitor/runtime-api.ts +0 -30
  153. package/src/auto-reply/monitor-state.test.ts +0 -64
  154. package/src/auto-reply/monitor-state.ts +0 -106
  155. package/src/auto-reply/monitor.ts +0 -600
  156. package/src/auto-reply/reply-resolver.runtime.ts +0 -1
  157. package/src/auto-reply/types.ts +0 -48
  158. package/src/auto-reply/util.ts +0 -63
  159. package/src/auto-reply/web-auto-reply-monitor.test.ts +0 -687
  160. package/src/auto-reply/web-auto-reply-utils.test.ts +0 -392
  161. package/src/auto-reply.broadcast-groups.combined.test.ts +0 -246
  162. package/src/auto-reply.broadcast-groups.test-harness.ts +0 -47
  163. package/src/auto-reply.impl.ts +0 -6
  164. package/src/auto-reply.test-harness.ts +0 -421
  165. package/src/auto-reply.ts +0 -1
  166. package/src/auto-reply.web-auto-reply.compresses-common-formats-jpeg-cap.test.ts +0 -427
  167. package/src/auto-reply.web-auto-reply.connection-and-logging.e2e.test.ts +0 -908
  168. package/src/auto-reply.web-auto-reply.last-route.test.ts +0 -184
  169. package/src/channel-actions.runtime.ts +0 -7
  170. package/src/channel-actions.test.ts +0 -216
  171. package/src/channel-actions.ts +0 -84
  172. package/src/channel-outbound.test.ts +0 -131
  173. package/src/channel-outbound.ts +0 -36
  174. package/src/channel-react-action.runtime.ts +0 -7
  175. package/src/channel-react-action.test.ts +0 -294
  176. package/src/channel-react-action.ts +0 -84
  177. package/src/channel.runtime.ts +0 -117
  178. package/src/channel.setup.test.ts +0 -461
  179. package/src/channel.setup.ts +0 -28
  180. package/src/channel.ts +0 -334
  181. package/src/command-policy.ts +0 -7
  182. package/src/config-accessors.test.ts +0 -34
  183. package/src/config-accessors.ts +0 -22
  184. package/src/config-schema.test.ts +0 -121
  185. package/src/config-schema.ts +0 -6
  186. package/src/config-ui-hints.ts +0 -24
  187. package/src/connection-controller-registry.test.ts +0 -27
  188. package/src/connection-controller-registry.ts +0 -49
  189. package/src/connection-controller.test.ts +0 -282
  190. package/src/connection-controller.ts +0 -679
  191. package/src/creds-files.ts +0 -19
  192. package/src/creds-persistence.ts +0 -102
  193. package/src/directory-config.test.ts +0 -60
  194. package/src/directory-config.ts +0 -40
  195. package/src/directory-contract.test.ts +0 -56
  196. package/src/doctor-contract.ts +0 -11
  197. package/src/doctor.test.ts +0 -74
  198. package/src/doctor.ts +0 -56
  199. package/src/group-intro.ts +0 -15
  200. package/src/group-policy.test.ts +0 -36
  201. package/src/group-policy.ts +0 -40
  202. package/src/group-session-contract.ts +0 -20
  203. package/src/group-session-key.test.ts +0 -53
  204. package/src/group-session-key.ts +0 -41
  205. package/src/heartbeat.ts +0 -34
  206. package/src/identity.ts +0 -164
  207. package/src/inbound/access-control.test-harness.ts +0 -37
  208. package/src/inbound/access-control.test.ts +0 -375
  209. package/src/inbound/access-control.ts +0 -237
  210. package/src/inbound/dedupe.ts +0 -132
  211. package/src/inbound/extract.test.ts +0 -282
  212. package/src/inbound/extract.ts +0 -488
  213. package/src/inbound/lifecycle.ts +0 -39
  214. package/src/inbound/media.node.test.ts +0 -83
  215. package/src/inbound/media.ts +0 -102
  216. package/src/inbound/monitor.ts +0 -890
  217. package/src/inbound/runtime-api.ts +0 -7
  218. package/src/inbound/save-media.runtime.ts +0 -1
  219. package/src/inbound/send-api.test.ts +0 -307
  220. package/src/inbound/send-api.ts +0 -141
  221. package/src/inbound/send-result.ts +0 -61
  222. package/src/inbound/types.ts +0 -106
  223. package/src/inbound-context.contract.test.ts +0 -32
  224. package/src/inbound-policy.ts +0 -231
  225. package/src/inbound.media.test.ts +0 -320
  226. package/src/inbound.test.ts +0 -290
  227. package/src/inbound.ts +0 -9
  228. package/src/login-qr.test.ts +0 -483
  229. package/src/login-qr.ts +0 -542
  230. package/src/login.coverage.test.ts +0 -133
  231. package/src/login.test.ts +0 -89
  232. package/src/login.ts +0 -70
  233. package/src/logout.test.ts +0 -162
  234. package/src/media.test.ts +0 -480
  235. package/src/media.ts +0 -10
  236. package/src/monitor-inbox.allows-messages-from-senders-allowfrom-list.test-support.ts +0 -400
  237. package/src/monitor-inbox.append-upsert.test-support.ts +0 -133
  238. package/src/monitor-inbox.behavior.test.ts +0 -5
  239. package/src/monitor-inbox.blocks-messages-from-unauthorized-senders-not-allowfrom.test-support.ts +0 -362
  240. package/src/monitor-inbox.captures-media-path-image-messages.test-support.ts +0 -306
  241. package/src/monitor-inbox.streams-inbound-messages.test-support.ts +0 -729
  242. package/src/monitor-inbox.test-harness.ts +0 -304
  243. package/src/normalize-target.ts +0 -112
  244. package/src/normalize.ts +0 -6
  245. package/src/outbound-adapter.poll.test.ts +0 -62
  246. package/src/outbound-adapter.sendpayload.test.ts +0 -195
  247. package/src/outbound-adapter.ts +0 -36
  248. package/src/outbound-base.test.ts +0 -560
  249. package/src/outbound-base.ts +0 -244
  250. package/src/outbound-media-contract.ts +0 -278
  251. package/src/outbound-media.runtime.ts +0 -36
  252. package/src/outbound-payload.contract.test.ts +0 -61
  253. package/src/outbound-send-deps.ts +0 -1
  254. package/src/outbound-test-support.ts +0 -16
  255. package/src/pairing-security.test-harness.ts +0 -59
  256. package/src/qr-image.ts +0 -1
  257. package/src/qr-terminal.ts +0 -1
  258. package/src/quoted-message.test.ts +0 -83
  259. package/src/quoted-message.ts +0 -184
  260. package/src/reaction-level.test.ts +0 -94
  261. package/src/reaction-level.ts +0 -21
  262. package/src/reconnect.test.ts +0 -51
  263. package/src/reconnect.ts +0 -55
  264. package/src/resolve-outbound-target.test.ts +0 -265
  265. package/src/resolve-outbound-target.ts +0 -54
  266. package/src/resolve-target.test.ts +0 -97
  267. package/src/runtime-api.ts +0 -59
  268. package/src/runtime-group-policy.ts +0 -16
  269. package/src/runtime.ts +0 -9
  270. package/src/security-contract.ts +0 -47
  271. package/src/security-fix.ts +0 -71
  272. package/src/send.test.ts +0 -515
  273. package/src/send.ts +0 -287
  274. package/src/session-contract.test.ts +0 -31
  275. package/src/session-contract.ts +0 -43
  276. package/src/session-errors.ts +0 -125
  277. package/src/session-route.ts +0 -26
  278. package/src/session.runtime.ts +0 -8
  279. package/src/session.test.ts +0 -559
  280. package/src/session.ts +0 -330
  281. package/src/setup-core.ts +0 -52
  282. package/src/setup-finalize.ts +0 -446
  283. package/src/setup-surface.test.ts +0 -367
  284. package/src/setup-surface.ts +0 -69
  285. package/src/setup-test-helpers.ts +0 -216
  286. package/src/shared.ts +0 -291
  287. package/src/socket-timing.test.ts +0 -49
  288. package/src/socket-timing.ts +0 -38
  289. package/src/state-migrations.ts +0 -54
  290. package/src/status-issues.test.ts +0 -137
  291. package/src/status-issues.ts +0 -185
  292. package/src/system-prompt.test.ts +0 -199
  293. package/src/system-prompt.ts +0 -31
  294. package/src/targets-runtime.ts +0 -180
  295. package/src/test-helpers.ts +0 -690
  296. package/src/text-runtime.test.ts +0 -162
  297. package/src/text-runtime.ts +0 -11
  298. package/src/vcard.ts +0 -84
  299. package/targets.ts +0 -5
  300. package/test-api.ts +0 -2
  301. package/tsconfig.json +0 -16
@@ -1,531 +0,0 @@
1
- import {
2
- logAckFailure,
3
- removeAckReactionHandleAfterReply,
4
- type AckReactionHandle,
5
- } from "openclaw/plugin-sdk/channel-feedback";
6
- import { recordInboundSession } from "openclaw/plugin-sdk/conversation-runtime";
7
- import {
8
- createInternalHookEvent,
9
- deriveInboundMessageHookContext,
10
- fireAndForgetBoundedHook,
11
- toInternalMessageReceivedContext,
12
- toPluginMessageContext,
13
- toPluginMessageReceivedEvent,
14
- triggerInternalHook,
15
- } from "openclaw/plugin-sdk/hook-runtime";
16
- import { runInboundReplyTurn } from "openclaw/plugin-sdk/inbound-reply-dispatch";
17
- import { getGlobalHookRunner } from "openclaw/plugin-sdk/plugin-runtime";
18
- import { resolveBatchedReplyThreadingPolicy } from "openclaw/plugin-sdk/reply-reference";
19
- import { getPrimaryIdentityId, getSelfIdentity, getSenderIdentity } from "../../identity.js";
20
- import {
21
- resolveWhatsAppCommandAuthorized,
22
- resolveWhatsAppInboundPolicy,
23
- } from "../../inbound-policy.js";
24
- import { newConnectionId } from "../../reconnect.js";
25
- import { formatError } from "../../session.js";
26
- import {
27
- resolveWhatsAppDirectSystemPrompt,
28
- resolveWhatsAppGroupSystemPrompt,
29
- } from "../../system-prompt.js";
30
- import { deliverWebReply } from "../deliver-reply.js";
31
- import { whatsappInboundLog } from "../loggers.js";
32
- import type { WebInboundMsg } from "../types.js";
33
- import { elide } from "../util.js";
34
- import { maybeSendAckReaction } from "./ack-reaction.js";
35
- import {
36
- resolveVisibleWhatsAppGroupHistory,
37
- resolveVisibleWhatsAppReplyContext,
38
- type GroupHistoryEntry,
39
- } from "./inbound-context.js";
40
- import {
41
- buildWhatsAppInboundContext,
42
- dispatchWhatsAppBufferedReply,
43
- resolveWhatsAppDmRouteTarget,
44
- resolveWhatsAppResponsePrefix,
45
- updateWhatsAppMainLastRoute,
46
- } from "./inbound-dispatch.js";
47
- import { trackBackgroundTask, updateLastRouteInBackground } from "./last-route.js";
48
- import { buildInboundLine } from "./message-line.js";
49
- import {
50
- buildHistoryContextFromEntries,
51
- createChannelReplyPipeline,
52
- formatInboundEnvelope,
53
- logVerbose,
54
- normalizeE164,
55
- resolveChannelContextVisibilityMode,
56
- resolveInboundSessionEnvelopeContext,
57
- resolvePinnedMainDmOwnerFromAllowlist,
58
- shouldComputeCommandAuthorized,
59
- shouldLogVerbose,
60
- type getChildLogger,
61
- type getReplyFromConfig,
62
- type HistoryEntry,
63
- type LoadConfigFn,
64
- type resolveAgentRoute,
65
- } from "./runtime-api.js";
66
-
67
- const WHATSAPP_MESSAGE_RECEIVED_HOOK_LIMITS = {
68
- maxConcurrency: 8,
69
- maxQueue: 128,
70
- timeoutMs: 2_000,
71
- };
72
-
73
- type WhatsAppMessageReceivedHookConfig = {
74
- pluginHooks?: {
75
- messageReceived?: unknown;
76
- };
77
- accounts?: Record<string, unknown>;
78
- };
79
-
80
- function readWhatsAppMessageReceivedHookOptIn(value: unknown): boolean | undefined {
81
- if (!value || typeof value !== "object") {
82
- return undefined;
83
- }
84
- const pluginHooks = (value as WhatsAppMessageReceivedHookConfig).pluginHooks;
85
- return pluginHooks?.messageReceived === true ? true : undefined;
86
- }
87
-
88
- function shouldEmitWhatsAppMessageReceivedHooks(params: {
89
- cfg: ReturnType<LoadConfigFn>;
90
- accountId?: string;
91
- }): boolean {
92
- const channelConfig = params.cfg.channels?.whatsapp as
93
- | WhatsAppMessageReceivedHookConfig
94
- | undefined;
95
- const accountConfig =
96
- params.accountId && channelConfig?.accounts
97
- ? channelConfig.accounts[params.accountId]
98
- : undefined;
99
- return (
100
- readWhatsAppMessageReceivedHookOptIn(accountConfig) ??
101
- readWhatsAppMessageReceivedHookOptIn(channelConfig) ??
102
- false
103
- );
104
- }
105
-
106
- function emitWhatsAppMessageReceivedHooks(params: {
107
- ctx: ReturnType<typeof buildWhatsAppInboundContext>;
108
- sessionKey: string;
109
- }): void {
110
- const canonical = deriveInboundMessageHookContext(params.ctx);
111
- const hookRunner = getGlobalHookRunner();
112
- if (hookRunner?.hasHooks("message_received")) {
113
- fireAndForgetBoundedHook(
114
- () =>
115
- hookRunner.runMessageReceived(
116
- toPluginMessageReceivedEvent(canonical),
117
- toPluginMessageContext(canonical),
118
- ),
119
- "whatsapp: message_received plugin hook failed",
120
- undefined,
121
- WHATSAPP_MESSAGE_RECEIVED_HOOK_LIMITS,
122
- );
123
- }
124
- fireAndForgetBoundedHook(
125
- () =>
126
- triggerInternalHook(
127
- createInternalHookEvent(
128
- "message",
129
- "received",
130
- params.sessionKey,
131
- toInternalMessageReceivedContext(canonical),
132
- ),
133
- ),
134
- "whatsapp: message_received internal hook failed",
135
- undefined,
136
- WHATSAPP_MESSAGE_RECEIVED_HOOK_LIMITS,
137
- );
138
- }
139
-
140
- function emitWhatsAppMessageReceivedHooksIfEnabled(params: {
141
- cfg: ReturnType<LoadConfigFn>;
142
- ctx: ReturnType<typeof buildWhatsAppInboundContext>;
143
- accountId?: string;
144
- sessionKey: string;
145
- }): void {
146
- if (
147
- !shouldEmitWhatsAppMessageReceivedHooks({
148
- cfg: params.cfg,
149
- accountId: params.accountId,
150
- })
151
- ) {
152
- return;
153
- }
154
-
155
- emitWhatsAppMessageReceivedHooks({
156
- ctx: params.ctx,
157
- sessionKey: params.sessionKey,
158
- });
159
- }
160
-
161
- function resolvePinnedMainDmRecipient(params: {
162
- cfg: ReturnType<LoadConfigFn>;
163
- allowFrom?: string[];
164
- }): string | null {
165
- return resolvePinnedMainDmOwnerFromAllowlist({
166
- dmScope: params.cfg.session?.dmScope,
167
- allowFrom: params.allowFrom,
168
- normalizeEntry: (entry) => normalizeE164(entry),
169
- });
170
- }
171
-
172
- export async function processMessage(params: {
173
- cfg: ReturnType<LoadConfigFn>;
174
- msg: WebInboundMsg;
175
- route: ReturnType<typeof resolveAgentRoute>;
176
- groupHistoryKey: string;
177
- groupHistories: Map<string, GroupHistoryEntry[]>;
178
- groupMemberNames: Map<string, Map<string, string>>;
179
- connectionId: string;
180
- verbose: boolean;
181
- maxMediaBytes: number;
182
- replyResolver: typeof getReplyFromConfig;
183
- replyLogger: ReturnType<typeof getChildLogger>;
184
- backgroundTasks: Set<Promise<unknown>>;
185
- rememberSentText: (
186
- text: string | undefined,
187
- opts: {
188
- combinedBody?: string;
189
- combinedBodySessionKey?: string;
190
- logVerboseMessage?: boolean;
191
- },
192
- ) => void;
193
- echoHas: (key: string) => boolean;
194
- echoForget: (key: string) => void;
195
- buildCombinedEchoKey: (p: { sessionKey: string; combinedBody: string }) => string;
196
- maxMediaTextChunkLimit?: number;
197
- groupHistory?: GroupHistoryEntry[];
198
- suppressGroupHistoryClear?: boolean;
199
- ackAlreadySent?: boolean;
200
- ackReaction?: AckReactionHandle | null;
201
- /** Pre-computed audio transcript from a caller-level preflight, used to avoid
202
- * re-transcribing the same voice note once per broadcast agent.
203
- * - string → transcript obtained; use it directly, skip internal STT
204
- * - null → preflight was attempted but failed / returned nothing; skip internal STT
205
- * - undefined (omitted) → caller did not attempt preflight; run internal STT as normal */
206
- preflightAudioTranscript?: string | null;
207
- }) {
208
- const conversationId = params.msg.conversationId ?? params.msg.from;
209
- const self = getSelfIdentity(params.msg);
210
- const inboundPolicy = resolveWhatsAppInboundPolicy({
211
- cfg: params.cfg,
212
- accountId: params.route.accountId ?? params.msg.accountId,
213
- selfE164: self.e164 ?? null,
214
- });
215
- const account = inboundPolicy.account;
216
- const contextVisibilityMode = resolveChannelContextVisibilityMode({
217
- cfg: params.cfg,
218
- channel: "whatsapp",
219
- accountId: account.accountId,
220
- });
221
- const { storePath, envelopeOptions, previousTimestamp } = resolveInboundSessionEnvelopeContext({
222
- cfg: params.cfg,
223
- agentId: params.route.agentId,
224
- sessionKey: params.route.sessionKey,
225
- });
226
- // Preflight audio transcription: transcribe voice notes before building the
227
- // inbound context so the agent receives the transcript instead of <media:audio>.
228
- // Mirrors the preflight step added for Telegram in #61008.
229
- // When the caller already performed transcription (e.g. on-message.ts before
230
- // broadcast fan-out) the pre-computed result is reused to avoid N STT calls
231
- // for N broadcast agents on the same voice note.
232
- // preflightAudioTranscript semantics:
233
- // string → transcript ready, use it
234
- // null → caller attempted but got nothing; skip internal STT to avoid retry
235
- // undefined → caller did not attempt; run internal STT
236
- let audioTranscript: string | undefined = params.preflightAudioTranscript ?? undefined;
237
- const hasAudioBody =
238
- params.msg.mediaType?.startsWith("audio/") === true && params.msg.body === "<media:audio>";
239
- if (params.preflightAudioTranscript === undefined && hasAudioBody && params.msg.mediaPath) {
240
- try {
241
- const { transcribeFirstAudio } = await import("./audio-preflight.runtime.js");
242
- audioTranscript = await transcribeFirstAudio({
243
- ctx: {
244
- MediaPaths: [params.msg.mediaPath],
245
- MediaTypes: params.msg.mediaType ? [params.msg.mediaType] : undefined,
246
- },
247
- cfg: params.cfg,
248
- });
249
- } catch {
250
- // Transcription failure is non-fatal: fall back to <media:audio> placeholder.
251
- if (shouldLogVerbose()) {
252
- logVerbose("whatsapp: audio preflight transcription failed, using placeholder");
253
- }
254
- }
255
- }
256
-
257
- // If we have a transcript, replace the agent-facing body so the agent sees the spoken text.
258
- // mediaPath and mediaType are intentionally preserved so that inboundAudio detection
259
- // (used by features such as messages.tts.auto: "inbound") still sees this as an
260
- // audio message. The transcript and transcribed media index are also stored on
261
- // context so downstream media understanding does not transcribe it again.
262
- const msgForAgent =
263
- audioTranscript !== undefined ? { ...params.msg, body: audioTranscript } : params.msg;
264
-
265
- let combinedBody = buildInboundLine({
266
- cfg: params.cfg,
267
- msg: msgForAgent,
268
- agentId: params.route.agentId,
269
- previousTimestamp,
270
- envelope: envelopeOptions,
271
- });
272
- let shouldClearGroupHistory = false;
273
- const visibleGroupHistory =
274
- params.msg.chatType === "group"
275
- ? resolveVisibleWhatsAppGroupHistory({
276
- history: params.groupHistory ?? params.groupHistories.get(params.groupHistoryKey) ?? [],
277
- mode: contextVisibilityMode,
278
- groupPolicy: inboundPolicy.groupPolicy,
279
- groupAllowFrom: inboundPolicy.groupAllowFrom,
280
- })
281
- : undefined;
282
-
283
- if (params.msg.chatType === "group") {
284
- const history = visibleGroupHistory ?? [];
285
- if (history.length > 0) {
286
- const historyEntries: HistoryEntry[] = history.map((m) => ({
287
- sender: m.sender,
288
- body: m.body,
289
- timestamp: m.timestamp,
290
- }));
291
- combinedBody = buildHistoryContextFromEntries({
292
- entries: historyEntries,
293
- currentMessage: combinedBody,
294
- excludeLast: false,
295
- formatEntry: (entry) => {
296
- return formatInboundEnvelope({
297
- channel: "WhatsApp",
298
- from: conversationId,
299
- timestamp: entry.timestamp,
300
- body: entry.body,
301
- chatType: "group",
302
- senderLabel: entry.sender,
303
- envelope: envelopeOptions,
304
- });
305
- },
306
- });
307
- }
308
- shouldClearGroupHistory = !(params.suppressGroupHistoryClear ?? false);
309
- }
310
-
311
- // Echo detection uses combined body so we don't respond twice.
312
- const combinedEchoKey = params.buildCombinedEchoKey({
313
- sessionKey: params.route.sessionKey,
314
- combinedBody,
315
- });
316
- if (params.echoHas(combinedEchoKey)) {
317
- logVerbose("Skipping auto-reply: detected echo for combined message");
318
- params.echoForget(combinedEchoKey);
319
- return false;
320
- }
321
-
322
- // Send ack reaction immediately upon message receipt (post-gating). Callers
323
- // that do preflight work before processMessage can send it first and set
324
- // ackAlreadySent so slow STT does not delay user-visible receipt feedback.
325
- let ackReaction = params.ackReaction ?? null;
326
- if (!ackReaction && params.ackAlreadySent !== true) {
327
- ackReaction = await maybeSendAckReaction({
328
- cfg: params.cfg,
329
- msg: params.msg,
330
- agentId: params.route.agentId,
331
- sessionKey: params.route.sessionKey,
332
- conversationId,
333
- verbose: params.verbose,
334
- accountId: account.accountId,
335
- info: params.replyLogger.info.bind(params.replyLogger),
336
- warn: params.replyLogger.warn.bind(params.replyLogger),
337
- });
338
- }
339
-
340
- const correlationId = params.msg.id ?? newConnectionId();
341
- params.replyLogger.info(
342
- {
343
- connectionId: params.connectionId,
344
- correlationId,
345
- from: params.msg.chatType === "group" ? conversationId : params.msg.from,
346
- to: params.msg.to,
347
- body: elide(combinedBody, 240),
348
- mediaType: params.msg.mediaType ?? null,
349
- mediaPath: params.msg.mediaPath ?? null,
350
- },
351
- "inbound web message",
352
- );
353
-
354
- const fromDisplay = params.msg.chatType === "group" ? conversationId : params.msg.from;
355
- const kindLabel = params.msg.mediaType ? `, ${params.msg.mediaType}` : "";
356
- whatsappInboundLog.info(
357
- `Inbound message ${fromDisplay} -> ${params.msg.to} (${params.msg.chatType}${kindLabel}, ${combinedBody.length} chars)`,
358
- );
359
- if (shouldLogVerbose()) {
360
- whatsappInboundLog.debug(`Inbound body: ${elide(combinedBody, 400)}`);
361
- }
362
-
363
- const sender = getSenderIdentity(params.msg);
364
- const visibleReplyTo = resolveVisibleWhatsAppReplyContext({
365
- msg: params.msg,
366
- authDir: account.authDir,
367
- mode: contextVisibilityMode,
368
- groupPolicy: inboundPolicy.groupPolicy,
369
- groupAllowFrom: inboundPolicy.groupAllowFrom,
370
- });
371
- const dmRouteTarget = resolveWhatsAppDmRouteTarget({
372
- msg: params.msg,
373
- senderE164: sender.e164 ?? undefined,
374
- normalizeE164,
375
- });
376
- const commandAuthorized = shouldComputeCommandAuthorized(params.msg.body, params.cfg)
377
- ? await resolveWhatsAppCommandAuthorized({
378
- cfg: params.cfg,
379
- msg: params.msg,
380
- policy: inboundPolicy,
381
- })
382
- : undefined;
383
- const { onModelSelected, ...replyPipeline } = createChannelReplyPipeline({
384
- cfg: params.cfg,
385
- agentId: params.route.agentId,
386
- channel: "whatsapp",
387
- accountId: params.route.accountId,
388
- });
389
- const responsePrefix = resolveWhatsAppResponsePrefix({
390
- cfg: params.cfg,
391
- agentId: params.route.agentId,
392
- isSelfChat: params.msg.chatType !== "group" && inboundPolicy.isSelfChat,
393
- pipelineResponsePrefix: replyPipeline.responsePrefix,
394
- });
395
- const replyThreading = resolveBatchedReplyThreadingPolicy(
396
- account.replyToMode ?? "off",
397
- params.msg.isBatched === true,
398
- );
399
-
400
- // Resolve combined conversation system prompt using the group or direct surface.
401
- const conversationSystemPrompt =
402
- params.msg.chatType === "group"
403
- ? resolveWhatsAppGroupSystemPrompt({
404
- accountConfig: account,
405
- groupId: conversationId,
406
- })
407
- : resolveWhatsAppDirectSystemPrompt({
408
- accountConfig: account,
409
- peerId: dmRouteTarget ?? params.msg.from,
410
- });
411
-
412
- const ctxPayload = buildWhatsAppInboundContext({
413
- bodyForAgent: msgForAgent.body,
414
- combinedBody,
415
- commandBody: params.msg.body,
416
- commandAuthorized,
417
- conversationId,
418
- groupHistory: visibleGroupHistory,
419
- groupMemberRoster: params.groupMemberNames.get(params.groupHistoryKey),
420
- groupSystemPrompt: conversationSystemPrompt,
421
- msg: params.msg,
422
- rawBody: params.msg.body,
423
- route: params.route,
424
- sender: {
425
- id: getPrimaryIdentityId(sender) ?? undefined,
426
- name: sender.name ?? undefined,
427
- e164: sender.e164 ?? undefined,
428
- },
429
- ...(audioTranscript !== undefined ? { transcript: audioTranscript } : {}),
430
- ...(audioTranscript !== undefined ? { mediaTranscribedIndexes: [0] } : {}),
431
- replyThreading,
432
- visibleReplyTo: visibleReplyTo ?? undefined,
433
- });
434
- emitWhatsAppMessageReceivedHooksIfEnabled({
435
- cfg: params.cfg,
436
- ctx: ctxPayload,
437
- accountId: params.route.accountId,
438
- sessionKey: params.route.sessionKey,
439
- });
440
-
441
- const pinnedMainDmRecipient = resolvePinnedMainDmRecipient({
442
- cfg: params.cfg,
443
- allowFrom: inboundPolicy.configuredAllowFrom,
444
- });
445
- updateWhatsAppMainLastRoute({
446
- backgroundTasks: params.backgroundTasks,
447
- cfg: params.cfg,
448
- ctx: ctxPayload,
449
- dmRouteTarget,
450
- pinnedMainDmRecipient,
451
- route: params.route,
452
- updateLastRoute: updateLastRouteInBackground,
453
- warn: params.replyLogger.warn.bind(params.replyLogger),
454
- });
455
-
456
- const turnResult = await runInboundReplyTurn({
457
- channel: "whatsapp",
458
- accountId: params.route.accountId,
459
- raw: params.msg,
460
- adapter: {
461
- ingest: () => ({
462
- id: params.msg.id ?? `${conversationId}:${Date.now()}`,
463
- timestamp: params.msg.timestamp,
464
- rawText: ctxPayload.RawBody ?? "",
465
- textForAgent: ctxPayload.BodyForAgent,
466
- textForCommands: ctxPayload.CommandBody,
467
- raw: params.msg,
468
- }),
469
- resolveTurn: () => ({
470
- channel: "whatsapp",
471
- accountId: params.route.accountId,
472
- routeSessionKey: params.route.sessionKey,
473
- storePath,
474
- ctxPayload,
475
- recordInboundSession,
476
- record: {
477
- onRecordError: (err) => {
478
- params.replyLogger.warn(
479
- {
480
- error: formatError(err),
481
- storePath,
482
- sessionKey: params.route.sessionKey,
483
- },
484
- "failed updating session meta",
485
- );
486
- },
487
- trackSessionMetaTask: (task) => {
488
- trackBackgroundTask(params.backgroundTasks, task);
489
- },
490
- },
491
- runDispatch: () =>
492
- dispatchWhatsAppBufferedReply({
493
- cfg: params.cfg,
494
- connectionId: params.connectionId,
495
- context: ctxPayload,
496
- conversationId,
497
- deliverReply: deliverWebReply,
498
- groupHistories: params.groupHistories,
499
- groupHistoryKey: params.groupHistoryKey,
500
- maxMediaBytes: params.maxMediaBytes,
501
- maxMediaTextChunkLimit: params.maxMediaTextChunkLimit,
502
- msg: params.msg,
503
- onModelSelected,
504
- rememberSentText: params.rememberSentText,
505
- replyLogger: params.replyLogger,
506
- replyPipeline: {
507
- ...replyPipeline,
508
- responsePrefix,
509
- },
510
- replyResolver: params.replyResolver,
511
- route: params.route,
512
- shouldClearGroupHistory,
513
- }),
514
- }),
515
- },
516
- });
517
- const didSendReply = turnResult.dispatched ? turnResult.dispatchResult : false;
518
- removeAckReactionHandleAfterReply({
519
- removeAfterReply: Boolean(params.cfg.messages?.removeAckAfterReply && didSendReply),
520
- ackReaction,
521
- onError: (err) => {
522
- logAckFailure({
523
- log: logVerbose,
524
- channel: "whatsapp",
525
- target: `${params.msg.chatId ?? conversationId}/${params.msg.id ?? "unknown"}`,
526
- error: err,
527
- });
528
- },
529
- });
530
- return didSendReply;
531
- }
@@ -1,30 +0,0 @@
1
- export { resolveIdentityNamePrefix } from "openclaw/plugin-sdk/agent-runtime";
2
- export { formatInboundEnvelope } from "openclaw/plugin-sdk/channel-envelope";
3
- export { resolveInboundSessionEnvelopeContext } from "openclaw/plugin-sdk/channel-inbound";
4
- export { toLocationContext } from "openclaw/plugin-sdk/channel-location";
5
- export { createChannelReplyPipeline } from "openclaw/plugin-sdk/channel-reply-pipeline";
6
- export { shouldComputeCommandAuthorized } from "openclaw/plugin-sdk/command-detection";
7
- export { resolveChannelContextVisibilityMode } from "../config.runtime.js";
8
- export { getAgentScopedMediaLocalRoots } from "openclaw/plugin-sdk/media-runtime";
9
- export type LoadConfigFn = typeof import("../config.runtime.js").getRuntimeConfig;
10
- export {
11
- buildHistoryContextFromEntries,
12
- type HistoryEntry,
13
- } from "openclaw/plugin-sdk/reply-history";
14
- export { resolveSendableOutboundReplyParts } from "openclaw/plugin-sdk/reply-payload";
15
- export {
16
- dispatchReplyWithBufferedBlockDispatcher,
17
- finalizeInboundContext,
18
- resolveChunkMode,
19
- resolveTextChunkLimit,
20
- type getReplyFromConfig,
21
- type ReplyPayload,
22
- } from "openclaw/plugin-sdk/reply-runtime";
23
- export {
24
- resolveInboundLastRouteSessionKey,
25
- type resolveAgentRoute,
26
- } from "openclaw/plugin-sdk/routing";
27
- export { logVerbose, shouldLogVerbose, type getChildLogger } from "openclaw/plugin-sdk/runtime-env";
28
- export { resolvePinnedMainDmOwnerFromAllowlist } from "openclaw/plugin-sdk/security-runtime";
29
- export { resolveMarkdownTableMode } from "openclaw/plugin-sdk/markdown-table-runtime";
30
- export { jidToE164, normalizeE164 } from "../../text-runtime.js";
@@ -1,64 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { createWebChannelStatusController } from "./monitor-state.js";
3
-
4
- describe("createWebChannelStatusController", () => {
5
- it("sets lastTransportActivityAt on noteConnected", () => {
6
- const patches: Record<string, unknown>[] = [];
7
- const controller = createWebChannelStatusController((s) => patches.push({ ...s }));
8
-
9
- controller.noteConnected(1000);
10
-
11
- const last = patches.at(-1)!;
12
- expect(last.connected).toBe(true);
13
- expect(last.lastTransportActivityAt).toBe(1000);
14
- });
15
-
16
- it("updates lastTransportActivityAt on noteInbound", () => {
17
- const patches: Record<string, unknown>[] = [];
18
- const controller = createWebChannelStatusController((s) => patches.push({ ...s }));
19
-
20
- controller.noteConnected(1000);
21
- controller.noteInbound(2000);
22
-
23
- const last = patches.at(-1)!;
24
- expect(last.lastTransportActivityAt).toBe(2000);
25
- });
26
-
27
- it("updates lastTransportActivityAt from explicit transport activity", () => {
28
- const patches: Record<string, unknown>[] = [];
29
- const controller = createWebChannelStatusController((s) => patches.push({ ...s }));
30
-
31
- controller.noteConnected(1000);
32
- controller.noteTransportActivity(3000);
33
-
34
- const last = patches.at(-1)!;
35
- expect(last.lastTransportActivityAt).toBe(3000);
36
- });
37
-
38
- it("does not set lastTransportActivityAt on noteWatchdogStale", () => {
39
- const patches: Record<string, unknown>[] = [];
40
- const controller = createWebChannelStatusController((s) => patches.push({ ...s }));
41
-
42
- controller.noteConnected(1000);
43
- controller.noteWatchdogStale(5000);
44
-
45
- const last = patches.at(-1)!;
46
- // Watchdog staleness should not refresh transport activity — it means
47
- // the check loop is running but the socket itself is idle/stale.
48
- expect(last.lastTransportActivityAt).toBe(1000);
49
- });
50
-
51
- it("produces snapshots that enable stale-socket health detection", () => {
52
- const patches: Record<string, unknown>[] = [];
53
- const controller = createWebChannelStatusController((s) => patches.push({ ...s }));
54
-
55
- controller.noteConnected(1000);
56
-
57
- const last = patches.at(-1)!;
58
- // The gateway health policy checks `connected === true && lastTransportActivityAt != null`
59
- // to decide whether to run stale-socket detection. Both must be present.
60
- expect(last.connected).toBe(true);
61
- expect(last.lastTransportActivityAt).not.toBeNull();
62
- expect(typeof last.lastTransportActivityAt).toBe("number");
63
- });
64
- });