@codexverified/baileys 2.7.5

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 (139) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +233 -0
  3. package/WAProto/V +1 -0
  4. package/WAProto/WAProto.proto +8051 -0
  5. package/WAProto/index.js +289292 -0
  6. package/engine-requirements.js +13 -0
  7. package/lib/Defaults/index.js +158 -0
  8. package/lib/Signal/Group/ciphertext-message.js +11 -0
  9. package/lib/Signal/Group/group-session-builder.js +29 -0
  10. package/lib/Signal/Group/group_cipher.js +81 -0
  11. package/lib/Signal/Group/index.js +11 -0
  12. package/lib/Signal/Group/keyhelper.js +17 -0
  13. package/lib/Signal/Group/sender-chain-key.js +25 -0
  14. package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
  15. package/lib/Signal/Group/sender-key-message.js +65 -0
  16. package/lib/Signal/Group/sender-key-name.js +47 -0
  17. package/lib/Signal/Group/sender-key-record.js +40 -0
  18. package/lib/Signal/Group/sender-key-state.js +83 -0
  19. package/lib/Signal/Group/sender-message-key.js +25 -0
  20. package/lib/Signal/libsignal.js +428 -0
  21. package/lib/Signal/lid-mapping.js +280 -0
  22. package/lib/Socket/Client/index.js +2 -0
  23. package/lib/Socket/Client/types.js +10 -0
  24. package/lib/Socket/Client/websocket.js +53 -0
  25. package/lib/Socket/aigroups.js +315 -0
  26. package/lib/Socket/business.js +407 -0
  27. package/lib/Socket/chats.js +1831 -0
  28. package/lib/Socket/communities.js +431 -0
  29. package/lib/Socket/graphql.js +899 -0
  30. package/lib/Socket/groups.js +549 -0
  31. package/lib/Socket/index.js +79 -0
  32. package/lib/Socket/interactive-handler.js +600 -0
  33. package/lib/Socket/interop.js +563 -0
  34. package/lib/Socket/managed-account.js +208 -0
  35. package/lib/Socket/messages-recv.js +2144 -0
  36. package/lib/Socket/messages-send.js +2030 -0
  37. package/lib/Socket/mex.js +41 -0
  38. package/lib/Socket/newsletter.js +226 -0
  39. package/lib/Socket/privacy.js +446 -0
  40. package/lib/Socket/registration.js +428 -0
  41. package/lib/Socket/socket.js +1017 -0
  42. package/lib/Socket/username.js +229 -0
  43. package/lib/Store/index.js +4 -0
  44. package/lib/Store/make-cache-manager-store.js +89 -0
  45. package/lib/Store/make-in-memory-store.js +420 -0
  46. package/lib/Store/make-ordered-dictionary.js +78 -0
  47. package/lib/Store/object-repository.js +23 -0
  48. package/lib/Types/Auth.js +1 -0
  49. package/lib/Types/Bussines.js +1 -0
  50. package/lib/Types/Call.js +1 -0
  51. package/lib/Types/Chat.js +7 -0
  52. package/lib/Types/Contact.js +1 -0
  53. package/lib/Types/Events.js +1 -0
  54. package/lib/Types/GroupMetadata.js +1 -0
  55. package/lib/Types/Label.js +24 -0
  56. package/lib/Types/LabelAssociation.js +6 -0
  57. package/lib/Types/Message.js +17 -0
  58. package/lib/Types/Mex.js +39 -0
  59. package/lib/Types/Product.js +1 -0
  60. package/lib/Types/RichType.js +22 -0
  61. package/lib/Types/Signal.js +1 -0
  62. package/lib/Types/Socket.js +2 -0
  63. package/lib/Types/State.js +48 -0
  64. package/lib/Types/USync.js +1 -0
  65. package/lib/Types/index.js +25 -0
  66. package/lib/Utils/auth-utils.js +301 -0
  67. package/lib/Utils/bot-planning-replay.js +169 -0
  68. package/lib/Utils/browser-utils.js +28 -0
  69. package/lib/Utils/business.js +230 -0
  70. package/lib/Utils/chat-utils.js +885 -0
  71. package/lib/Utils/companion-reg-client-utils.js +32 -0
  72. package/lib/Utils/consumer-application.js +102 -0
  73. package/lib/Utils/crypto.js +117 -0
  74. package/lib/Utils/decode-wa-message.js +484 -0
  75. package/lib/Utils/event-buffer.js +589 -0
  76. package/lib/Utils/generics.js +388 -0
  77. package/lib/Utils/group-history.js +56 -0
  78. package/lib/Utils/history.js +130 -0
  79. package/lib/Utils/identity-change-handler.js +48 -0
  80. package/lib/Utils/index.js +34 -0
  81. package/lib/Utils/jid-display-normalization.js +209 -0
  82. package/lib/Utils/link-preview.js +84 -0
  83. package/lib/Utils/logger.js +2 -0
  84. package/lib/Utils/lt-hash.js +7 -0
  85. package/lib/Utils/make-mutex.js +32 -0
  86. package/lib/Utils/message-composer.js +467 -0
  87. package/lib/Utils/message-inspect.js +67 -0
  88. package/lib/Utils/message-retry-manager.js +241 -0
  89. package/lib/Utils/messages-media.js +1006 -0
  90. package/lib/Utils/messages.js +1851 -0
  91. package/lib/Utils/meta-ai-msmsg.js +130 -0
  92. package/lib/Utils/meta-compositing.js +194 -0
  93. package/lib/Utils/noise-handler.js +200 -0
  94. package/lib/Utils/offline-node-processor.js +39 -0
  95. package/lib/Utils/pre-key-manager.js +105 -0
  96. package/lib/Utils/process-message.js +527 -0
  97. package/lib/Utils/reporting-utils.js +257 -0
  98. package/lib/Utils/rich-message-utils.js +439 -0
  99. package/lib/Utils/signal.js +200 -0
  100. package/lib/Utils/stanza-ack.js +37 -0
  101. package/lib/Utils/sync-action-utils.js +47 -0
  102. package/lib/Utils/tc-token-utils.js +162 -0
  103. package/lib/Utils/use-multi-file-auth-state.js +120 -0
  104. package/lib/Utils/use-single-file-auth-state.js +96 -0
  105. package/lib/Utils/use-sqlite-auth-state.js +108 -0
  106. package/lib/Utils/validate-connection.js +206 -0
  107. package/lib/Utils/voip-rekey.js +20 -0
  108. package/lib/Utils/welcome-flow.js +217 -0
  109. package/lib/WABinary/constants.js +1463 -0
  110. package/lib/WABinary/decode.js +261 -0
  111. package/lib/WABinary/encode.js +219 -0
  112. package/lib/WABinary/generic-utils.js +227 -0
  113. package/lib/WABinary/index.js +5 -0
  114. package/lib/WABinary/jid-utils.js +95 -0
  115. package/lib/WABinary/types.js +1 -0
  116. package/lib/WAM/BinaryInfo.js +9 -0
  117. package/lib/WAM/constants.js +22852 -0
  118. package/lib/WAM/encode.js +149 -0
  119. package/lib/WAM/index.js +3 -0
  120. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +96 -0
  121. package/lib/WAUSync/Protocols/USyncContactProtocol.js +56 -0
  122. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
  123. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
  124. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +70 -0
  125. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +28 -0
  126. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +25 -0
  127. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
  128. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +34 -0
  129. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
  130. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
  131. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
  132. package/lib/WAUSync/Protocols/index.js +12 -0
  133. package/lib/WAUSync/USyncQuery.js +201 -0
  134. package/lib/WAUSync/USyncUser.js +54 -0
  135. package/lib/WAUSync/index.js +3 -0
  136. package/lib/antiban.cjs +4726 -0
  137. package/lib/index.d.ts +286 -0
  138. package/lib/index.js +18 -0
  139. package/package.json +121 -0
@@ -0,0 +1,467 @@
1
+ import { proto } from '../../WAProto/index.js';
2
+ import { generateMessageIDV2 } from './generics.js';
3
+
4
+ // NOTE: tokenizeCode / CodeHighlightType / RichSubMessageType are intentionally
5
+ // kept module-local here @codexverified/baileys already exports these from
6
+ // lib/Utils/rich-message-utils.js and lib/Types/RichType.js. The baron composer
7
+ // implementation is preserved internally so the generator helpers stay faithful.
8
+
9
+ const JS_KEYWORDS = new Set([
10
+ 'import',
11
+ 'export',
12
+ 'from',
13
+ 'default',
14
+ 'as',
15
+ 'const',
16
+ 'let',
17
+ 'var',
18
+ 'function',
19
+ 'class',
20
+ 'extends',
21
+ 'new',
22
+ 'return',
23
+ 'if',
24
+ 'else',
25
+ 'for',
26
+ 'while',
27
+ 'do',
28
+ 'switch',
29
+ 'case',
30
+ 'break',
31
+ 'continue',
32
+ 'try',
33
+ 'catch',
34
+ 'finally',
35
+ 'throw',
36
+ 'async',
37
+ 'await',
38
+ 'yield',
39
+ 'typeof',
40
+ 'instanceof',
41
+ 'in',
42
+ 'of',
43
+ 'delete',
44
+ 'void',
45
+ 'true',
46
+ 'false',
47
+ 'null',
48
+ 'undefined',
49
+ 'NaN',
50
+ 'Infinity',
51
+ 'this',
52
+ 'super',
53
+ 'static',
54
+ 'get',
55
+ 'set',
56
+ 'debugger',
57
+ 'with'
58
+ ]);
59
+
60
+ const PYTHON_KEYWORDS = new Set([
61
+ 'import',
62
+ 'from',
63
+ 'as',
64
+ 'def',
65
+ 'class',
66
+ 'return',
67
+ 'if',
68
+ 'elif',
69
+ 'else',
70
+ 'for',
71
+ 'while',
72
+ 'break',
73
+ 'continue',
74
+ 'try',
75
+ 'except',
76
+ 'finally',
77
+ 'raise',
78
+ 'with',
79
+ 'yield',
80
+ 'lambda',
81
+ 'pass',
82
+ 'del',
83
+ 'global',
84
+ 'nonlocal',
85
+ 'assert',
86
+ 'True',
87
+ 'False',
88
+ 'None',
89
+ 'and',
90
+ 'or',
91
+ 'not',
92
+ 'in',
93
+ 'is',
94
+ 'async',
95
+ 'await',
96
+ 'self',
97
+ 'print'
98
+ ]);
99
+
100
+ const LANGUAGE_KEYWORDS = {
101
+ javascript: JS_KEYWORDS,
102
+ typescript: JS_KEYWORDS,
103
+ js: JS_KEYWORDS,
104
+ ts: JS_KEYWORDS,
105
+ python: PYTHON_KEYWORDS,
106
+ py: PYTHON_KEYWORDS
107
+ };
108
+
109
+ const CodeHighlightType = {
110
+ DEFAULT: 0,
111
+ KEYWORD: 1,
112
+ METHOD: 2,
113
+ STRING: 3,
114
+ NUMBER: 4,
115
+ COMMENT: 5
116
+ };
117
+
118
+ const RichSubMessageType = {
119
+ UNKNOWN: 0,
120
+ GRID_IMAGE: 1,
121
+ TEXT: 2,
122
+ INLINE_IMAGE: 3,
123
+ TABLE: 4,
124
+ CODE: 5,
125
+ DYNAMIC: 6,
126
+ MAP: 7,
127
+ LATEX: 8,
128
+ CONTENT_ITEMS: 9
129
+ };
130
+
131
+ const tokenizeCode = (codeStr, language = 'javascript') => {
132
+ const keywords = LANGUAGE_KEYWORDS[language] || JS_KEYWORDS;
133
+ const blocks = [];
134
+ const lines = codeStr.split('\n');
135
+ for (let li = 0; li < lines.length; li++) {
136
+ const line = lines[li];
137
+ const isLast = li === lines.length - 1;
138
+ const nl = isLast ? '' : '\n';
139
+ if (!line.trim()) {
140
+ blocks.push({
141
+ highlightType: CodeHighlightType.DEFAULT,
142
+ codeContent: line + nl
143
+ });
144
+ continue;
145
+ }
146
+ if (line.trim().startsWith('//') || line.trim().startsWith('#')) {
147
+ blocks.push({
148
+ highlightType: CodeHighlightType.COMMENT,
149
+ codeContent: line + nl
150
+ });
151
+ continue;
152
+ }
153
+ const regex =
154
+ /(\/\/.*$|#.*$)|(["'`](?:[^"'`\\]|\\.)*["'`])|(\b\d+(?:\.\d+)?\b)|(\b[a-zA-Z_$][\w$]*\b)|([^\s\w$"'`]+)|(\s+)/g;
155
+ let match;
156
+ const tokens = [];
157
+ while ((match = regex.exec(line)) !== null) {
158
+ const val = match[0];
159
+ if (match[1]) {
160
+ tokens.push({
161
+ highlightType: CodeHighlightType.COMMENT,
162
+ codeContent: val
163
+ });
164
+ }
165
+ else if (match[2]) {
166
+ tokens.push({
167
+ highlightType: CodeHighlightType.STRING,
168
+ codeContent: val
169
+ });
170
+ }
171
+ else if (match[3]) {
172
+ tokens.push({
173
+ highlightType: CodeHighlightType.NUMBER,
174
+ codeContent: val
175
+ });
176
+ }
177
+ else if (match[4]) {
178
+ if (keywords.has(val)) {
179
+ tokens.push({
180
+ highlightType: CodeHighlightType.KEYWORD,
181
+ codeContent: val
182
+ });
183
+ }
184
+ else {
185
+ const after = line.slice(regex.lastIndex).trimStart();
186
+ if (after.startsWith('(')) {
187
+ tokens.push({
188
+ highlightType: CodeHighlightType.METHOD,
189
+ codeContent: val
190
+ });
191
+ }
192
+ else {
193
+ tokens.push({
194
+ highlightType: CodeHighlightType.DEFAULT,
195
+ codeContent: val
196
+ });
197
+ }
198
+ }
199
+ }
200
+ else {
201
+ tokens.push({
202
+ highlightType: CodeHighlightType.DEFAULT,
203
+ codeContent: val
204
+ });
205
+ }
206
+ }
207
+ if (tokens.length === 0) {
208
+ blocks.push({
209
+ highlightType: CodeHighlightType.DEFAULT,
210
+ codeContent: line + nl
211
+ });
212
+ continue;
213
+ }
214
+ const merged = [];
215
+ for (const t of tokens) {
216
+ const prev = merged.length > 0 ? merged[merged.length - 1] : undefined;
217
+ if (prev && prev.highlightType === t.highlightType) {
218
+ prev.codeContent += t.codeContent;
219
+ }
220
+ else {
221
+ merged.push({ ...t });
222
+ }
223
+ }
224
+ if (merged.length > 0) {
225
+ merged[merged.length - 1].codeContent += nl;
226
+ }
227
+ blocks.push(...merged);
228
+ }
229
+ return blocks;
230
+ };
231
+
232
+ const buildRichContextInfo = (quoted, options = {}) => {
233
+ const ctxInfo = {
234
+ forwardingScore: 1,
235
+ isForwarded: true,
236
+ forwardedAiBotMessageInfo: { botJid: options.botJid ? options.botJid : '867051314767696@bot' },
237
+ forwardOrigin: 4,
238
+ ...(options.mentions ? { mentionedJid: options.mentions } : {})
239
+ };
240
+ if (quoted?.key) {
241
+ ctxInfo.stanzaId = quoted.key.id;
242
+ ctxInfo.participant = quoted.key.participant || quoted.sender || quoted.key.remoteJid;
243
+ ctxInfo.quotedMessage = quoted.message;
244
+ }
245
+ return ctxInfo;
246
+ };
247
+
248
+ const buildBotForwardedMessage = (submessages, contextInfo, unifiedResponse) => {
249
+ const richResponse = {
250
+ messageType: 1,
251
+ submessages,
252
+ contextInfo
253
+ };
254
+ if (unifiedResponse) {
255
+ richResponse.unifiedResponse = unifiedResponse;
256
+ }
257
+ return {
258
+ botForwardedMessage: {
259
+ message: {
260
+ richResponseMessage: richResponse
261
+ }
262
+ }
263
+ };
264
+ };
265
+
266
+ export const generateTableContent = (title, headers, rows, quoted, options = {}) => {
267
+ const { footer, headerText } = options;
268
+ const tableRows = [{ items: headers, isHeading: true }, ...rows.map(row => ({ items: row.map(String) }))];
269
+ const submessages = [];
270
+ if (headerText) {
271
+ submessages.push({ messageType: 2, messageText: headerText });
272
+ }
273
+ submessages.push({
274
+ messageType: 4,
275
+ tableMetadata: { title, rows: tableRows }
276
+ });
277
+ if (footer) {
278
+ submessages.push({ messageType: 2, messageText: footer });
279
+ }
280
+ const ctxInfo = buildRichContextInfo(quoted);
281
+ return {
282
+ message: buildBotForwardedMessage(submessages, ctxInfo),
283
+ messageId: generateMessageIDV2()
284
+ };
285
+ };
286
+
287
+ export const generateListContent = (title, items, quoted, options = {}) => {
288
+ const { footer, headerText } = options;
289
+ const tableRows = items.map(item => ({
290
+ items: Array.isArray(item) ? item.map(String) : [String(item)]
291
+ }));
292
+ const submessages = [];
293
+ if (headerText) {
294
+ submessages.push({ messageType: 2, messageText: headerText });
295
+ }
296
+ submessages.push({
297
+ messageType: 4,
298
+ tableMetadata: { title, rows: tableRows }
299
+ });
300
+ if (footer) {
301
+ submessages.push({ messageType: 2, messageText: footer });
302
+ }
303
+ const ctxInfo = buildRichContextInfo(quoted);
304
+ return {
305
+ message: buildBotForwardedMessage(submessages, ctxInfo),
306
+ messageId: generateMessageIDV2()
307
+ };
308
+ };
309
+
310
+ export const generateCodeBlockContent = (code, quoted, options = {}) => {
311
+ const { title, footer, language = 'javascript' } = options;
312
+ const submessages = [];
313
+ if (title) {
314
+ submessages.push({ messageType: 2, messageText: title });
315
+ }
316
+ submessages.push({
317
+ messageType: 5,
318
+ codeMetadata: {
319
+ codeLanguage: language,
320
+ codeBlocks: tokenizeCode(code, language)
321
+ }
322
+ });
323
+ if (footer) {
324
+ submessages.push({ messageType: 2, messageText: footer });
325
+ }
326
+ const ctxInfo = buildRichContextInfo(quoted);
327
+ return {
328
+ message: buildBotForwardedMessage(submessages, ctxInfo),
329
+ messageId: generateMessageIDV2()
330
+ };
331
+ };
332
+
333
+ export const generateLatexContent = (quoted, options) => {
334
+ const { text, expressions, headerText, footer } = options;
335
+ const submessages = [];
336
+ if (headerText) {
337
+ submessages.push({ messageType: 2, messageText: headerText });
338
+ }
339
+ const latexExpressions = expressions.map(expr => {
340
+ const entry = {
341
+ latexExpression: expr.latexExpression,
342
+ url: expr.url,
343
+ width: expr.width,
344
+ height: expr.height
345
+ };
346
+ if (expr.fontHeight !== undefined) entry.fontHeight = expr.fontHeight;
347
+ if (expr.imageTopPadding !== undefined) entry.imageTopPadding = expr.imageTopPadding;
348
+ if (expr.imageLeadingPadding !== undefined) entry.imageLeadingPadding = expr.imageLeadingPadding;
349
+ if (expr.imageBottomPadding !== undefined) entry.imageBottomPadding = expr.imageBottomPadding;
350
+ if (expr.imageTrailingPadding !== undefined) entry.imageTrailingPadding = expr.imageTrailingPadding;
351
+ return entry;
352
+ });
353
+ submessages.push({
354
+ messageType: 8,
355
+ latexMetadata: {
356
+ text: text || '',
357
+ expressions: latexExpressions
358
+ }
359
+ });
360
+ if (footer) {
361
+ submessages.push({ messageType: 2, messageText: footer });
362
+ }
363
+ const ctxInfo = buildRichContextInfo(quoted);
364
+ return {
365
+ message: buildBotForwardedMessage(submessages, ctxInfo),
366
+ messageId: generateMessageIDV2()
367
+ };
368
+ };
369
+
370
+ export const generateLatexImageContent = async (quoted, options, uploadFn, renderLatexToPng) => {
371
+ const { text, expressions, headerText, footer } = options;
372
+ const submessages = [];
373
+ if (headerText) {
374
+ submessages.push({ messageType: 2, messageText: headerText });
375
+ }
376
+ const latexExpressions = await Promise.all(
377
+ expressions.map(async expr => {
378
+ const { buffer, width, height } = await renderLatexToPng(expr.latexExpression);
379
+ const uploadResult = await uploadFn(buffer, 'image');
380
+ const imageUrl = uploadResult.url || uploadResult.directPath;
381
+ return {
382
+ latexExpression: expr.latexExpression,
383
+ url: imageUrl,
384
+ width,
385
+ height
386
+ };
387
+ })
388
+ );
389
+ submessages.push({
390
+ messageType: 8,
391
+ latexMetadata: {
392
+ text: text || '',
393
+ expressions: latexExpressions
394
+ }
395
+ });
396
+ if (footer) {
397
+ submessages.push({ messageType: 2, messageText: footer });
398
+ }
399
+ const ctxInfo = buildRichContextInfo(quoted);
400
+ return {
401
+ message: buildBotForwardedMessage(submessages, ctxInfo),
402
+ messageId: generateMessageIDV2()
403
+ };
404
+ };
405
+
406
+ export const generateLatexInlineImageContent = async (quoted, options, uploadFn, renderLatexToPng) => {
407
+ const { text, expressions, headerText, footer } = options;
408
+ const submessages = [];
409
+ if (headerText) {
410
+ submessages.push({ messageType: 2, messageText: headerText });
411
+ }
412
+ if (text) {
413
+ submessages.push({ messageType: 2, messageText: text });
414
+ }
415
+ for (const expr of expressions) {
416
+ const { buffer, width, height } = await renderLatexToPng(expr.latexExpression);
417
+ const uploadResult = await uploadFn(buffer, 'image');
418
+ const imageUrl = uploadResult.url || uploadResult.directPath;
419
+ submessages.push({
420
+ messageType: 3,
421
+ imageMetadata: {
422
+ imageUrl: {
423
+ imagePreviewUrl: imageUrl,
424
+ imageHighResUrl: imageUrl
425
+ },
426
+ imageText: expr.latexExpression,
427
+ alignment: 2
428
+ }
429
+ });
430
+ }
431
+ if (footer) {
432
+ submessages.push({ messageType: 2, messageText: footer });
433
+ }
434
+ const ctxInfo = buildRichContextInfo(quoted);
435
+ return {
436
+ message: buildBotForwardedMessage(submessages, ctxInfo),
437
+ messageId: generateMessageIDV2()
438
+ };
439
+ };
440
+
441
+ export const captureUnifiedResponse = (msg) => {
442
+ const botFwd = msg?.botForwardedMessage?.message;
443
+ if (!botFwd) return null;
444
+ const rich = botFwd.richResponseMessage;
445
+ if (!rich?.unifiedResponse?.data) return null;
446
+ return {
447
+ unifiedResponse: { data: rich.unifiedResponse.data },
448
+ submessages: rich.submessages || [],
449
+ contextInfo: rich.contextInfo || {}
450
+ };
451
+ };
452
+
453
+ export const generateUnifiedResponseContent = (quoted, captured) => {
454
+ const ctxInfo = buildRichContextInfo(quoted);
455
+ return {
456
+ message: buildBotForwardedMessage(captured.submessages, ctxInfo, captured.unifiedResponse),
457
+ messageId: generateMessageIDV2()
458
+ };
459
+ };
460
+
461
+ export const generateRichMessageContent = (submessages, quoted, options) => {
462
+ const ctxInfo = buildRichContextInfo(quoted, options);
463
+ return {
464
+ message: buildBotForwardedMessage(submessages, ctxInfo),
465
+ messageId: generateMessageIDV2()
466
+ };
467
+ };
@@ -0,0 +1,67 @@
1
+ import { proto } from '../../WAProto/index.js';
2
+ import { isLidUser, jidEncode } from '../WABinary/index.js';
3
+
4
+ // Message inspection helpers
5
+ // Ported from baron-baileys-v2 Utils/message-inspect.js. Only the helpers that
6
+ // were not already present in lib/Utils/messages.js are exported here the
7
+ // shared ones (getContentType, normalizeMessageContent, extractMessageContent,
8
+ // downloadMediaMessage, assertMediaContent, getDevice, ) live in messages.js.
9
+
10
+ /** Check if a WebMessageInfo has a scheduled reveal time (ConditionalRevealMessage) */
11
+ export const isScheduledMessage = (msg) => !!msg?.scheduledMessageMetadata?.scheduledTime;
12
+
13
+ /** Get scheduled reveal time of a message as a Date, or null */
14
+ export const getScheduledMessageTime = (msg) => {
15
+ const t = msg?.scheduledMessageMetadata?.scheduledTime;
16
+ if (!t) return null;
17
+ return new Date(Number(t) * 1000);
18
+ };
19
+
20
+ /** Extract PaymentInfo from a WebMessageInfo (the payment status field, not the message content) */
21
+ export const getMessagePaymentInfo = (msg) => msg?.paymentInfo || msg?.quotedPaymentInfo || null;
22
+
23
+ /** Get all comment metadata from a WebMessageInfo */
24
+ export const getMessageCommentMetadata = (msg) => msg?.commentMetadata || null;
25
+
26
+ /** Get all message add-ons (reactions, poll updates, pins) from a WebMessageInfo */
27
+ export const getMessageAddOns = (msg) => msg?.messageAddOns || [];
28
+
29
+ /** Get the quiz correct answer from a poll creation message, if it's a quiz */
30
+ export const getPollCorrectAnswer = (pollMsg) => {
31
+ const poll =
32
+ pollMsg?.pollCreationMessage ||
33
+ pollMsg?.pollCreationMessageV2 ||
34
+ pollMsg?.pollCreationMessageV3 ||
35
+ pollMsg?.pollCreationMessageV5 ||
36
+ pollMsg?.pollCreationMessageV6;
37
+ if (!poll) return null;
38
+ const isQuiz = poll.pollType === proto.Message.PollType?.QUIZ || poll.pollType === 1;
39
+ return isQuiz ? poll.correctAnswer?.optionName || null : null;
40
+ };
41
+
42
+ /** Normalizes a bare user id to @s.whatsapp.net. Does not convert LIDPN; use lidMapping / PN in key.remoteJidAlt when needed. */
43
+ export const toJid = (id) => {
44
+ if (!id) return '';
45
+ if (id.includes('@')) return id;
46
+ return `${id}@s.whatsapp.net`;
47
+ };
48
+
49
+ /** Returns the peer LID JID when the key is LID-primary (decode sets remoteJid/participant to @lid when WA sends LID). */
50
+ export const getSenderLid = (message) => {
51
+ const k = message.key;
52
+ if (!k) {
53
+ return { jid: '', lid: '' };
54
+ }
55
+ const jid = k.participant || k.remoteJid || '';
56
+ if (jid.endsWith('@lid') || jid.endsWith('@hosted.lid')) {
57
+ return { jid, lid: jid };
58
+ }
59
+ if (k.lid && typeof k.lid === 'string') {
60
+ const lid = k.lid.includes('@') ? k.lid : jidEncode(k.lid, 'lid');
61
+ return { jid, lid };
62
+ }
63
+ if (k.participantLid && isLidUser(k.participantLid)) {
64
+ return { jid, lid: k.participantLid };
65
+ }
66
+ return { jid, lid: '' };
67
+ };