@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,488 +0,0 @@
1
- import type { proto } from "@whiskeysockets/baileys";
2
- import {
3
- extractMessageContent,
4
- getContentType,
5
- normalizeMessageContent,
6
- } from "@whiskeysockets/baileys";
7
- import { formatLocationText, type NormalizedLocation } from "openclaw/plugin-sdk/channel-inbound";
8
- import { logVerbose } from "openclaw/plugin-sdk/runtime-env";
9
- import { resolveComparableIdentity, type WhatsAppReplyContext } from "../identity.js";
10
- import { jidToE164 } from "../text-runtime.js";
11
- import { parseVcard } from "../vcard.js";
12
- import type { WhatsAppStructuredContactContext } from "./types.js";
13
-
14
- const MESSAGE_WRAPPER_KEYS = [
15
- "botInvokeMessage",
16
- "ephemeralMessage",
17
- "viewOnceMessage",
18
- "viewOnceMessageV2",
19
- "viewOnceMessageV2Extension",
20
- "documentWithCaptionMessage",
21
- "groupMentionedMessage",
22
- ] as const;
23
-
24
- const MESSAGE_CONTENT_KEYS = [
25
- "conversation",
26
- "extendedTextMessage",
27
- "imageMessage",
28
- "videoMessage",
29
- "audioMessage",
30
- "documentMessage",
31
- "stickerMessage",
32
- "locationMessage",
33
- "liveLocationMessage",
34
- "contactMessage",
35
- "contactsArrayMessage",
36
- "buttonsResponseMessage",
37
- "listResponseMessage",
38
- "templateButtonReplyMessage",
39
- "interactiveResponseMessage",
40
- "buttonsMessage",
41
- "listMessage",
42
- ] as const;
43
-
44
- function fallbackNormalizeMessageContent(
45
- message: proto.IMessage | undefined,
46
- ): proto.IMessage | undefined {
47
- let current = message as unknown;
48
- while (current && typeof current === "object") {
49
- let unwrapped = false;
50
- for (const key of MESSAGE_WRAPPER_KEYS) {
51
- const candidate = (current as Record<string, unknown>)[key];
52
- if (
53
- candidate &&
54
- typeof candidate === "object" &&
55
- "message" in (candidate as Record<string, unknown>) &&
56
- (candidate as { message?: unknown }).message
57
- ) {
58
- current = (candidate as { message: unknown }).message;
59
- unwrapped = true;
60
- break;
61
- }
62
- }
63
- if (!unwrapped) {
64
- break;
65
- }
66
- }
67
- return current as proto.IMessage | undefined;
68
- }
69
-
70
- function normalizeMessage(message: proto.IMessage | undefined): proto.IMessage | undefined {
71
- if (typeof normalizeMessageContent === "function") {
72
- return normalizeMessageContent(message);
73
- }
74
- return fallbackNormalizeMessageContent(message);
75
- }
76
-
77
- function fallbackGetContentType(
78
- message: proto.IMessage | undefined,
79
- ): keyof proto.IMessage | undefined {
80
- const normalized = fallbackNormalizeMessageContent(message);
81
- if (!normalized || typeof normalized !== "object") {
82
- return undefined;
83
- }
84
- for (const key of MESSAGE_CONTENT_KEYS) {
85
- if ((normalized as Record<string, unknown>)[key] != null) {
86
- return key as keyof proto.IMessage;
87
- }
88
- }
89
- return undefined;
90
- }
91
-
92
- function getMessageContentType(
93
- message: proto.IMessage | undefined,
94
- ): keyof proto.IMessage | undefined {
95
- if (typeof getContentType === "function") {
96
- return getContentType(message);
97
- }
98
- return fallbackGetContentType(message);
99
- }
100
-
101
- function extractMessage(message: proto.IMessage | undefined): proto.IMessage | undefined {
102
- if (typeof extractMessageContent === "function") {
103
- return extractMessageContent(message);
104
- }
105
- const normalized = fallbackNormalizeMessageContent(message);
106
- const contentType = fallbackGetContentType(normalized);
107
- if (!normalized || !contentType || contentType === "conversation") {
108
- return normalized;
109
- }
110
- const candidate = (normalized as Record<string, unknown>)[contentType];
111
- return candidate && typeof candidate === "object" ? (candidate as proto.IMessage) : normalized;
112
- }
113
-
114
- function getFutureProofInnerMessage(message: proto.IMessage): proto.IMessage | undefined {
115
- const contentType = getMessageContentType(message);
116
- const candidate = contentType ? (message as Record<string, unknown>)[contentType] : undefined;
117
- if (
118
- candidate &&
119
- typeof candidate === "object" &&
120
- "message" in candidate &&
121
- (candidate as { message?: unknown }).message &&
122
- typeof (candidate as { message: unknown }).message === "object"
123
- ) {
124
- const inner = normalizeMessage((candidate as { message: proto.IMessage }).message);
125
- if (inner) {
126
- const innerType = getMessageContentType(inner);
127
- if (innerType && innerType !== contentType) {
128
- return inner;
129
- }
130
- }
131
- }
132
- return undefined;
133
- }
134
-
135
- function buildMessageChain(message: proto.IMessage | undefined): proto.IMessage[] {
136
- const chain: proto.IMessage[] = [];
137
- let current = normalizeMessage(message);
138
- while (current && chain.length < 4) {
139
- chain.push(current);
140
- current = getFutureProofInnerMessage(current);
141
- }
142
- return chain;
143
- }
144
-
145
- function unwrapMessage(message: proto.IMessage | undefined): proto.IMessage | undefined {
146
- const chain = buildMessageChain(message);
147
- return chain.at(-1);
148
- }
149
-
150
- function extractContextInfoFromMessage(message: proto.IMessage): proto.IContextInfo | undefined {
151
- const contentType = getMessageContentType(message);
152
- const candidate = contentType ? (message as Record<string, unknown>)[contentType] : undefined;
153
- const contextInfo =
154
- candidate && typeof candidate === "object" && "contextInfo" in candidate
155
- ? (candidate as { contextInfo?: proto.IContextInfo }).contextInfo
156
- : undefined;
157
- if (contextInfo) {
158
- return contextInfo;
159
- }
160
- const fallback =
161
- message.extendedTextMessage?.contextInfo ??
162
- message.imageMessage?.contextInfo ??
163
- message.videoMessage?.contextInfo ??
164
- message.documentMessage?.contextInfo ??
165
- message.audioMessage?.contextInfo ??
166
- message.stickerMessage?.contextInfo ??
167
- message.buttonsResponseMessage?.contextInfo ??
168
- message.listResponseMessage?.contextInfo ??
169
- message.templateButtonReplyMessage?.contextInfo ??
170
- message.interactiveResponseMessage?.contextInfo ??
171
- message.buttonsMessage?.contextInfo ??
172
- message.listMessage?.contextInfo;
173
- if (fallback) {
174
- return fallback;
175
- }
176
- for (const value of Object.values(message)) {
177
- if (!value || typeof value !== "object") {
178
- continue;
179
- }
180
- if ("contextInfo" in value) {
181
- const candidateContext = (value as { contextInfo?: proto.IContextInfo }).contextInfo;
182
- if (candidateContext) {
183
- return candidateContext;
184
- }
185
- }
186
- // FutureProofMessage wrapper: dig into .message to find contextInfo
187
- if ("message" in value) {
188
- const inner = (value as { message?: proto.IMessage }).message;
189
- if (inner) {
190
- const innerCtx = extractContextInfo(inner);
191
- if (innerCtx) {
192
- return innerCtx;
193
- }
194
- }
195
- }
196
- }
197
- return undefined;
198
- }
199
-
200
- export function extractContextInfo(
201
- message: proto.IMessage | undefined,
202
- ): proto.IContextInfo | undefined {
203
- for (const candidate of buildMessageChain(message)) {
204
- const contextInfo = extractContextInfoFromMessage(candidate);
205
- if (contextInfo) {
206
- return contextInfo;
207
- }
208
- }
209
- return undefined;
210
- }
211
-
212
- export function extractMentionedJids(rawMessage: proto.IMessage | undefined): string[] | undefined {
213
- const message = unwrapMessage(rawMessage);
214
- if (!message) {
215
- return undefined;
216
- }
217
-
218
- const candidates: Array<string[] | null | undefined> = [
219
- message.extendedTextMessage?.contextInfo?.mentionedJid,
220
- message.imageMessage?.contextInfo?.mentionedJid,
221
- message.videoMessage?.contextInfo?.mentionedJid,
222
- message.documentMessage?.contextInfo?.mentionedJid,
223
- message.audioMessage?.contextInfo?.mentionedJid,
224
- message.stickerMessage?.contextInfo?.mentionedJid,
225
- message.buttonsResponseMessage?.contextInfo?.mentionedJid,
226
- message.listResponseMessage?.contextInfo?.mentionedJid,
227
- ];
228
-
229
- const flattened = candidates.flatMap((arr) => arr ?? []).filter(Boolean);
230
- if (flattened.length === 0) {
231
- return undefined;
232
- }
233
- return Array.from(new Set(flattened));
234
- }
235
-
236
- export function extractText(rawMessage: proto.IMessage | undefined): string | undefined {
237
- const message = unwrapMessage(rawMessage);
238
- if (!message) {
239
- return undefined;
240
- }
241
- const extracted = extractMessage(message);
242
- const candidates = [message, extracted && extracted !== message ? extracted : undefined];
243
- for (const candidate of candidates) {
244
- if (!candidate) {
245
- continue;
246
- }
247
- if (typeof candidate.conversation === "string" && candidate.conversation.trim()) {
248
- return candidate.conversation.trim();
249
- }
250
- const extended = candidate.extendedTextMessage?.text;
251
- if (extended?.trim()) {
252
- return extended.trim();
253
- }
254
- const caption =
255
- candidate.imageMessage?.caption ??
256
- candidate.videoMessage?.caption ??
257
- candidate.documentMessage?.caption;
258
- if (caption?.trim()) {
259
- return caption.trim();
260
- }
261
- }
262
- const contactPlaceholder =
263
- extractContactPlaceholder(message) ??
264
- (extracted && extracted !== message
265
- ? extractContactPlaceholder(extracted as proto.IMessage | undefined)
266
- : undefined);
267
- if (contactPlaceholder) {
268
- return contactPlaceholder;
269
- }
270
- return undefined;
271
- }
272
-
273
- export function extractMediaPlaceholder(
274
- rawMessage: proto.IMessage | undefined,
275
- ): string | undefined {
276
- const message = unwrapMessage(rawMessage);
277
- if (!message) {
278
- return undefined;
279
- }
280
- if (message.imageMessage) {
281
- return "<media:image>";
282
- }
283
- if (message.videoMessage) {
284
- return "<media:video>";
285
- }
286
- if (message.audioMessage) {
287
- return "<media:audio>";
288
- }
289
- if (message.documentMessage) {
290
- return "<media:document>";
291
- }
292
- if (message.stickerMessage) {
293
- return "<media:sticker>";
294
- }
295
- return undefined;
296
- }
297
-
298
- function extractContactPlaceholder(rawMessage: proto.IMessage | undefined): string | undefined {
299
- const contactContext = extractContactContext(rawMessage);
300
- if (!contactContext) {
301
- return undefined;
302
- }
303
- if (contactContext.kind === "contact") {
304
- return "<contact>";
305
- }
306
- const suffix = contactContext.total === 1 ? "contact" : "contacts";
307
- return `<contacts: ${contactContext.total} ${suffix}>`;
308
- }
309
-
310
- export function extractContactContext(
311
- rawMessage: proto.IMessage | undefined,
312
- ): WhatsAppStructuredContactContext | undefined {
313
- const message = unwrapMessage(rawMessage);
314
- if (!message) {
315
- return undefined;
316
- }
317
- const contact = message.contactMessage ?? undefined;
318
- if (contact) {
319
- const { name, phones } = describeContact({
320
- displayName: contact.displayName,
321
- vcard: contact.vcard,
322
- });
323
- return {
324
- kind: "contact",
325
- total: 1,
326
- contacts: [{ name, phones }],
327
- };
328
- }
329
- const contactsArray = message.contactsArrayMessage?.contacts ?? undefined;
330
- if (!contactsArray || contactsArray.length === 0) {
331
- return undefined;
332
- }
333
- return {
334
- kind: "contacts",
335
- total: contactsArray.length,
336
- contacts: contactsArray.map((entry) =>
337
- describeContact({ displayName: entry.displayName, vcard: entry.vcard }),
338
- ),
339
- };
340
- }
341
-
342
- function describeContact(input: { displayName?: string | null; vcard?: string | null }): {
343
- name?: string;
344
- phones: string[];
345
- } {
346
- const displayName = (input.displayName ?? "").trim();
347
- const parsed = parseVcard(input.vcard ?? undefined);
348
- const name = displayName || parsed.name;
349
- return { name, phones: parsed.phones };
350
- }
351
-
352
- export function extractLocationData(
353
- rawMessage: proto.IMessage | undefined,
354
- ): NormalizedLocation | null {
355
- const message = unwrapMessage(rawMessage);
356
- if (!message) {
357
- return null;
358
- }
359
-
360
- const live = message.liveLocationMessage ?? undefined;
361
- if (live) {
362
- const latitudeRaw = live.degreesLatitude;
363
- const longitudeRaw = live.degreesLongitude;
364
- if (latitudeRaw != null && longitudeRaw != null) {
365
- const latitude = latitudeRaw;
366
- const longitude = longitudeRaw;
367
- if (Number.isFinite(latitude) && Number.isFinite(longitude)) {
368
- return {
369
- latitude,
370
- longitude,
371
- accuracy: live.accuracyInMeters ?? undefined,
372
- caption: live.caption ?? undefined,
373
- source: "live",
374
- isLive: true,
375
- };
376
- }
377
- }
378
- }
379
-
380
- const location = message.locationMessage ?? undefined;
381
- if (location) {
382
- const latitudeRaw = location.degreesLatitude;
383
- const longitudeRaw = location.degreesLongitude;
384
- if (latitudeRaw != null && longitudeRaw != null) {
385
- const latitude = latitudeRaw;
386
- const longitude = longitudeRaw;
387
- if (Number.isFinite(latitude) && Number.isFinite(longitude)) {
388
- const isLive = Boolean(location.isLive);
389
- return {
390
- latitude,
391
- longitude,
392
- accuracy: location.accuracyInMeters ?? undefined,
393
- name: location.name ?? undefined,
394
- address: location.address ?? undefined,
395
- caption: location.comment ?? undefined,
396
- source: isLive ? "live" : location.name || location.address ? "place" : "pin",
397
- isLive,
398
- };
399
- }
400
- }
401
- }
402
-
403
- return null;
404
- }
405
-
406
- export function describeReplyContext(
407
- rawMessage: proto.IMessage | undefined,
408
- ): WhatsAppReplyContext | null {
409
- const message = unwrapMessage(rawMessage);
410
- if (!message) {
411
- return null;
412
- }
413
- const contextInfo = extractContextInfo(message);
414
- const quoted = normalizeMessage(contextInfo?.quotedMessage as proto.IMessage | undefined);
415
- if (!quoted) {
416
- return null;
417
- }
418
- const location = extractLocationData(quoted);
419
- const locationText = location ? formatLocationText(location) : undefined;
420
- const text = extractText(quoted);
421
- let body: string | undefined = [text, locationText].filter(Boolean).join("\n").trim();
422
- if (!body) {
423
- body = extractMediaPlaceholder(quoted);
424
- }
425
- if (!body) {
426
- const quotedType = quoted ? getMessageContentType(quoted) : undefined;
427
- logVerbose(
428
- `Quoted message missing extractable body${quotedType ? ` (type ${quotedType})` : ""}`,
429
- );
430
- return null;
431
- }
432
- const senderJid = contextInfo?.participant ?? undefined;
433
- const sender = resolveComparableIdentity({
434
- jid: senderJid,
435
- label: senderJid ? (jidToE164(senderJid) ?? senderJid) : "unknown sender",
436
- });
437
- return {
438
- id: contextInfo?.stanzaId || undefined,
439
- body,
440
- sender,
441
- };
442
- }
443
-
444
- function hasInteractiveResponseContent(message: proto.IMessage | undefined): boolean {
445
- if (!message) {
446
- return false;
447
- }
448
- // Button/list/template/interactive selections that the existing four
449
- // extractors do not cover. Treat any presence of these keys as user
450
- // content — Baileys never delivers these as receipts or protocol
451
- // envelopes, only as explicit user choices.
452
- return Boolean(
453
- message.buttonsResponseMessage ||
454
- message.listResponseMessage ||
455
- message.templateButtonReplyMessage ||
456
- message.interactiveResponseMessage,
457
- );
458
- }
459
-
460
- /**
461
- * Fast check that a Baileys message carries user-visible inbound content
462
- * (text, media, contact, location, button/list selection). Returns false for
463
- * protocol/receipt/typing notifications that arrive on the same
464
- * `messages.upsert` stream as real messages but should not trigger pairing
465
- * access-control side effects.
466
- */
467
- export function hasInboundUserContent(rawMessage: proto.IMessage | undefined): boolean {
468
- if (!rawMessage) {
469
- return false;
470
- }
471
- if (extractText(rawMessage)) {
472
- return true;
473
- }
474
- if (extractMediaPlaceholder(rawMessage)) {
475
- return true;
476
- }
477
- if (extractLocationData(rawMessage)) {
478
- return true;
479
- }
480
- // Walk wrappers (ephemeral, viewOnce, etc.) — interactive responses
481
- // can arrive nested.
482
- for (const candidate of buildMessageChain(rawMessage)) {
483
- if (hasInteractiveResponseContent(candidate)) {
484
- return true;
485
- }
486
- }
487
- return false;
488
- }
@@ -1,39 +0,0 @@
1
- type Listener = (...args: unknown[]) => void;
2
-
3
- type OffCapableEmitter = {
4
- on: (event: string, listener: Listener) => void;
5
- off?: (event: string, listener: Listener) => void;
6
- removeListener?: (event: string, listener: Listener) => void;
7
- };
8
-
9
- type ClosableSocket = {
10
- end?: (error: Error | undefined) => void;
11
- ws?: {
12
- close?: () => void;
13
- };
14
- };
15
-
16
- export function attachEmitterListener(
17
- emitter: OffCapableEmitter,
18
- event: string,
19
- listener: Listener,
20
- ): () => void {
21
- emitter.on(event, listener);
22
- return () => {
23
- if (typeof emitter.off === "function") {
24
- emitter.off(event, listener);
25
- return;
26
- }
27
- if (typeof emitter.removeListener === "function") {
28
- emitter.removeListener(event, listener);
29
- }
30
- };
31
- }
32
-
33
- export function closeInboundMonitorSocket(sock: ClosableSocket): void {
34
- if (typeof sock.end === "function") {
35
- sock.end(new Error("OpenClaw WhatsApp listener close"));
36
- return;
37
- }
38
- sock.ws?.close?.();
39
- }
@@ -1,83 +0,0 @@
1
- import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
2
- import { mockNormalizeMessageContent } from "../../../../test/mocks/baileys.js";
3
-
4
- type MockMessageInput = Parameters<typeof mockNormalizeMessageContent>[0];
5
-
6
- const { normalizeMessageContent, downloadMediaMessage } = vi.hoisted(() => ({
7
- normalizeMessageContent: vi.fn((msg: MockMessageInput) => mockNormalizeMessageContent(msg)),
8
- downloadMediaMessage: vi.fn().mockResolvedValue(Buffer.from("fake-media-data")),
9
- }));
10
-
11
- vi.mock("@whiskeysockets/baileys", async () => {
12
- return {
13
- DisconnectReason: { loggedOut: 401 },
14
- normalizeMessageContent,
15
- downloadMediaMessage,
16
- };
17
- });
18
-
19
- let downloadInboundMedia: typeof import("./media.js").downloadInboundMedia;
20
-
21
- const mockSock = {
22
- updateMediaMessage: vi.fn(),
23
- logger: { child: () => ({}) },
24
- };
25
-
26
- async function expectMimetype(message: Record<string, unknown>, expected: string) {
27
- const result = await downloadInboundMedia({ message } as never, mockSock as never);
28
- expect(result).toBeDefined();
29
- expect(result?.mimetype).toBe(expected);
30
- }
31
-
32
- describe("downloadInboundMedia", () => {
33
- beforeAll(async () => {
34
- ({ downloadInboundMedia } = await import("./media.js"));
35
- });
36
-
37
- beforeEach(() => {
38
- normalizeMessageContent.mockClear();
39
- downloadMediaMessage.mockClear();
40
- mockSock.updateMediaMessage.mockClear();
41
- });
42
-
43
- it("returns undefined for messages without media", async () => {
44
- const msg = { message: { conversation: "hello" } } as never;
45
- const result = await downloadInboundMedia(msg, mockSock as never);
46
- expect(result).toBeUndefined();
47
- });
48
-
49
- it("uses explicit mimetype from audioMessage when present", async () => {
50
- await expectMimetype({ audioMessage: { mimetype: "audio/mp4", ptt: true } }, "audio/mp4");
51
- });
52
-
53
- it.each([
54
- { name: "voice messages without explicit MIME", audioMessage: { ptt: true } },
55
- { name: "audio messages without MIME or ptt flag", audioMessage: {} },
56
- ])("defaults to audio/ogg for $name", async ({ audioMessage }) => {
57
- await expectMimetype({ audioMessage }, "audio/ogg; codecs=opus");
58
- });
59
-
60
- it("uses explicit mimetype from imageMessage when present", async () => {
61
- await expectMimetype({ imageMessage: { mimetype: "image/png" } }, "image/png");
62
- });
63
-
64
- it.each([
65
- { name: "image", message: { imageMessage: {} }, mimetype: "image/jpeg" },
66
- { name: "video", message: { videoMessage: {} }, mimetype: "video/mp4" },
67
- { name: "sticker", message: { stickerMessage: {} }, mimetype: "image/webp" },
68
- ])("defaults MIME for $name messages without explicit MIME", async ({ message, mimetype }) => {
69
- await expectMimetype(message, mimetype);
70
- });
71
-
72
- it("preserves fileName from document messages", async () => {
73
- const msg = {
74
- message: {
75
- documentMessage: { mimetype: "application/pdf", fileName: "report.pdf" },
76
- },
77
- } as never;
78
- const result = await downloadInboundMedia(msg, mockSock as never);
79
- expect(result).toBeDefined();
80
- expect(result?.mimetype).toBe("application/pdf");
81
- expect(result?.fileName).toBe("report.pdf");
82
- });
83
- });
@@ -1,102 +0,0 @@
1
- import type { proto, WAMessage } from "@whiskeysockets/baileys";
2
- import { logVerbose } from "openclaw/plugin-sdk/runtime-env";
3
- import type { createWaSocket } from "../session.js";
4
- import { extractContextInfo } from "./extract.js";
5
- import { downloadMediaMessage, normalizeMessageContent } from "./runtime-api.js";
6
-
7
- function unwrapMessage(message: proto.IMessage | undefined): proto.IMessage | undefined {
8
- const normalized = normalizeMessageContent(message);
9
- return normalized;
10
- }
11
-
12
- /**
13
- * Resolve the MIME type for an inbound media message.
14
- * Falls back to WhatsApp's standard formats when Baileys omits the MIME.
15
- */
16
- function resolveMediaMimetype(message: proto.IMessage): string | undefined {
17
- const explicit =
18
- message.imageMessage?.mimetype ??
19
- message.videoMessage?.mimetype ??
20
- message.documentMessage?.mimetype ??
21
- message.audioMessage?.mimetype ??
22
- message.stickerMessage?.mimetype ??
23
- undefined;
24
- if (explicit) {
25
- return explicit;
26
- }
27
- // WhatsApp voice messages (PTT) and audio use OGG Opus by default
28
- if (message.audioMessage) {
29
- return "audio/ogg; codecs=opus";
30
- }
31
- if (message.imageMessage) {
32
- return "image/jpeg";
33
- }
34
- if (message.videoMessage) {
35
- return "video/mp4";
36
- }
37
- if (message.stickerMessage) {
38
- return "image/webp";
39
- }
40
- return undefined;
41
- }
42
-
43
- export async function downloadInboundMedia(
44
- msg: proto.IWebMessageInfo,
45
- sock: Awaited<ReturnType<typeof createWaSocket>>,
46
- ): Promise<{ buffer: Buffer; mimetype?: string; fileName?: string } | undefined> {
47
- const message = unwrapMessage(msg.message as proto.IMessage | undefined);
48
- if (!message) {
49
- return undefined;
50
- }
51
- const mimetype = resolveMediaMimetype(message);
52
- const fileName = message.documentMessage?.fileName ?? undefined;
53
- if (
54
- !message.imageMessage &&
55
- !message.videoMessage &&
56
- !message.documentMessage &&
57
- !message.audioMessage &&
58
- !message.stickerMessage
59
- ) {
60
- return undefined;
61
- }
62
- try {
63
- const buffer = await downloadMediaMessage(
64
- msg as WAMessage,
65
- "buffer",
66
- {},
67
- {
68
- reuploadRequest: sock.updateMediaMessage,
69
- logger: sock.logger,
70
- },
71
- );
72
- return { buffer, mimetype, fileName };
73
- } catch (err) {
74
- logVerbose(`downloadMediaMessage failed: ${String(err)}`);
75
- return undefined;
76
- }
77
- }
78
-
79
- export async function downloadQuotedInboundMedia(
80
- msg: proto.IWebMessageInfo,
81
- sock: Awaited<ReturnType<typeof createWaSocket>>,
82
- ): Promise<{ buffer: Buffer; mimetype?: string; fileName?: string } | undefined> {
83
- const message = unwrapMessage(msg.message as proto.IMessage | undefined);
84
- const contextInfo = extractContextInfo(message);
85
- if (!contextInfo?.quotedMessage) {
86
- return undefined;
87
- }
88
- const quotedMessage = contextInfo.quotedMessage;
89
- return downloadInboundMedia(
90
- {
91
- key: {
92
- id: contextInfo?.stanzaId || undefined,
93
- remoteJid: contextInfo.remoteJid ?? msg.key?.remoteJid ?? undefined,
94
- participant: contextInfo?.participant ?? undefined,
95
- fromMe: false,
96
- },
97
- message: quotedMessage,
98
- messageTimestamp: msg.messageTimestamp,
99
- },
100
- sock,
101
- );
102
- }