@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,600 @@
1
+ import { randomBytes } from 'crypto';
2
+ import { proto } from '../../WAProto/index.js';
3
+ import {
4
+ delay,
5
+ generateMessageID,
6
+ generateWAMessage,
7
+ generateWAMessageContent,
8
+ generateWAMessageFromContent,
9
+ getUrlFromDirectPath,
10
+ normalizeMessageContent,
11
+ prepareWAMessageMedia
12
+ } from '../Utils/index.js';
13
+ import { getUrlInfo } from '../Utils/link-preview.js';
14
+ import { isJidGroup, isPnUser, jidNormalizedUser, STORIES_JID } from '../WABinary/index.js';
15
+
16
+ export class Baron {
17
+ constructor(waUploadToServer, relayMessageFn, config, sock) {
18
+ this.relayMessage = relayMessageFn;
19
+ this.waUploadToServer = waUploadToServer;
20
+ this.config = config;
21
+ this.sock = sock;
22
+ }
23
+
24
+ detectType(content) {
25
+ if (content.requestPaymentMessage) return 'PAYMENT';
26
+ if (content.productMessage) return 'PRODUCT';
27
+ if (content.interactiveButtons) return 'INTERACTIVE_BUTTONS';
28
+ if (content.interactiveMessage) return 'INTERACTIVE';
29
+ if (content.albumMessage || content.album) return 'ALBUM';
30
+ if (content.eventMessage) return 'EVENT';
31
+ if (content.pollResultMessage) return 'POLL_RESULT';
32
+ if (content.groupStatusMessage) return 'GROUP_STORY';
33
+ return null;
34
+ }
35
+
36
+ async handlePayment(content, quoted) {
37
+ const data = content.requestPaymentMessage;
38
+ let notes = {};
39
+ if (data.sticker?.stickerMessage) {
40
+ notes = {
41
+ stickerMessage: {
42
+ ...data.sticker.stickerMessage,
43
+ contextInfo: {
44
+ stanzaId: quoted?.key?.id,
45
+ participant: quoted?.key?.participant || content.sender,
46
+ quotedMessage: quoted?.message
47
+ }
48
+ }
49
+ };
50
+ }
51
+ else if (data.note) {
52
+ notes = {
53
+ extendedTextMessage: {
54
+ text: data.note,
55
+ contextInfo: {
56
+ stanzaId: quoted?.key?.id,
57
+ participant: quoted?.key?.participant || content.sender,
58
+ quotedMessage: quoted?.message
59
+ }
60
+ }
61
+ };
62
+ }
63
+ return {
64
+ requestPaymentMessage: proto.Message.RequestPaymentMessage.fromObject({
65
+ expiryTimestamp: data.expiry || 0,
66
+ amount1000: data.amount || 0,
67
+ currencyCodeIso4217: data.currency || 'IDR',
68
+ requestFrom: data.from || '0@s.whatsapp.net',
69
+ noteMessage: notes,
70
+ background: data.background ?? {
71
+ id: 'DEFAULT',
72
+ placeholderArgb: 0xfff0f0f0
73
+ }
74
+ })
75
+ };
76
+ }
77
+
78
+ async handleProduct(content, _jid, _quoted) {
79
+ const {
80
+ title,
81
+ description,
82
+ thumbnail,
83
+ productId,
84
+ retailerId,
85
+ url,
86
+ body = '',
87
+ footer = '',
88
+ buttons = [],
89
+ priceAmount1000 = null,
90
+ currencyCode = 'IDR'
91
+ } = content.productMessage;
92
+ let productImage;
93
+ if (Buffer.isBuffer(thumbnail)) {
94
+ const { imageMessage } = await generateWAMessageContent({ image: thumbnail }, { upload: this.waUploadToServer });
95
+ productImage = imageMessage;
96
+ }
97
+ else if (typeof thumbnail === 'object' && thumbnail.url) {
98
+ const { imageMessage } = await generateWAMessageContent(
99
+ { image: { url: thumbnail.url } },
100
+ { upload: this.waUploadToServer }
101
+ );
102
+ productImage = imageMessage;
103
+ }
104
+ return {
105
+ viewOnceMessage: {
106
+ message: {
107
+ interactiveMessage: {
108
+ body: { text: body },
109
+ footer: { text: footer },
110
+ header: {
111
+ title,
112
+ hasMediaAttachment: true,
113
+ productMessage: {
114
+ product: {
115
+ productImage,
116
+ productId,
117
+ title,
118
+ description,
119
+ currencyCode,
120
+ priceAmount1000,
121
+ retailerId,
122
+ url,
123
+ productImageCount: 1
124
+ },
125
+ businessOwnerJid: '0@s.whatsapp.net'
126
+ }
127
+ },
128
+ nativeFlowMessage: { buttons }
129
+ }
130
+ }
131
+ }
132
+ };
133
+ }
134
+
135
+ async handleInteractive(content, _jid, _quoted) {
136
+ const {
137
+ title,
138
+ footer,
139
+ thumbnail,
140
+ image,
141
+ video,
142
+ document,
143
+ mimetype,
144
+ fileName,
145
+ jpegThumbnail,
146
+ contextInfo,
147
+ externalAdReply,
148
+ buttons = [],
149
+ nativeFlowMessage,
150
+ header
151
+ } = content.interactiveMessage;
152
+ let media = null;
153
+ let _mediaType = null;
154
+ if (thumbnail) {
155
+ media = await prepareWAMessageMedia({ image: { url: thumbnail } }, { upload: this.waUploadToServer });
156
+ _mediaType = 'image';
157
+ }
158
+ else if (image) {
159
+ const src = typeof image === 'object' && image.url ? { image: { url: image.url } } : { image };
160
+ media = await prepareWAMessageMedia(src, { upload: this.waUploadToServer });
161
+ _mediaType = 'image';
162
+ }
163
+ else if (video) {
164
+ const src = typeof video === 'object' && video.url ? { video: { url: video.url } } : { video };
165
+ media = await prepareWAMessageMedia(src, { upload: this.waUploadToServer });
166
+ _mediaType = 'video';
167
+ }
168
+ else if (document) {
169
+ const docPayload = { document };
170
+ if (jpegThumbnail) {
171
+ docPayload.jpegThumbnail =
172
+ typeof jpegThumbnail === 'object' && jpegThumbnail.url ? { url: jpegThumbnail.url } : jpegThumbnail;
173
+ }
174
+ media = await prepareWAMessageMedia(docPayload, { upload: this.waUploadToServer });
175
+ if (fileName) media.documentMessage.fileName = fileName;
176
+ if (mimetype) media.documentMessage.mimetype = mimetype;
177
+ _mediaType = 'document';
178
+ }
179
+ const interactiveMessage = {
180
+ body: { text: title || '' },
181
+ footer: { text: footer || '' }
182
+ };
183
+ if (buttons && buttons.length > 0) {
184
+ interactiveMessage.nativeFlowMessage = { buttons };
185
+ if (nativeFlowMessage) {
186
+ interactiveMessage.nativeFlowMessage = {
187
+ ...interactiveMessage.nativeFlowMessage,
188
+ ...nativeFlowMessage
189
+ };
190
+ }
191
+ }
192
+ else if (nativeFlowMessage) {
193
+ interactiveMessage.nativeFlowMessage = nativeFlowMessage;
194
+ }
195
+ if (media) {
196
+ interactiveMessage.header = {
197
+ title: header || '',
198
+ hasMediaAttachment: true,
199
+ ...media
200
+ };
201
+ }
202
+ else {
203
+ interactiveMessage.header = {
204
+ title: header || '',
205
+ hasMediaAttachment: false
206
+ };
207
+ }
208
+ const finalContextInfo = {};
209
+ if (contextInfo) {
210
+ Object.assign(finalContextInfo, {
211
+ mentionedJid: contextInfo.mentionedJid || [],
212
+ forwardingScore: contextInfo.forwardingScore || 0,
213
+ isForwarded: contextInfo.isForwarded || false,
214
+ ...contextInfo
215
+ });
216
+ }
217
+ if (externalAdReply) {
218
+ finalContextInfo.externalAdReply = {
219
+ title: externalAdReply.title || '',
220
+ body: externalAdReply.body || '',
221
+ mediaType: externalAdReply.mediaType || 1,
222
+ thumbnailUrl: externalAdReply.thumbnailUrl || '',
223
+ mediaUrl: externalAdReply.mediaUrl || '',
224
+ sourceUrl: externalAdReply.sourceUrl || '',
225
+ showAdAttribution: externalAdReply.showAdAttribution || false,
226
+ renderLargerThumbnail: externalAdReply.renderLargerThumbnail || false,
227
+ ...externalAdReply
228
+ };
229
+ }
230
+ if (Object.keys(finalContextInfo).length > 0) {
231
+ interactiveMessage.contextInfo = finalContextInfo;
232
+ }
233
+ return { interactiveMessage };
234
+ }
235
+
236
+ async handleInteractiveButtons(content, _jid, _quoted) {
237
+ const {
238
+ text,
239
+ caption,
240
+ title,
241
+ subtitle,
242
+ footer,
243
+ interactiveButtons,
244
+ hasMediaAttachment,
245
+ image,
246
+ video,
247
+ document,
248
+ mimetype,
249
+ jpegThumbnail,
250
+ location,
251
+ product,
252
+ businessOwnerJid
253
+ } = content;
254
+ const bodyText = text || caption || '';
255
+ const buttons = interactiveButtons.map(btn => ({
256
+ name: btn.name,
257
+ buttonParamsJson:
258
+ typeof btn.buttonParamsJson === 'string' ? btn.buttonParamsJson : JSON.stringify(btn.buttonParamsJson)
259
+ }));
260
+ let headerContent = {};
261
+ let mediaAttached = typeof hasMediaAttachment === 'boolean' ? hasMediaAttachment : false;
262
+ if (image) {
263
+ const src = typeof image === 'object' && image.url ? { image: { url: image.url } } : { image };
264
+ const uploaded = await prepareWAMessageMedia(src, { upload: this.waUploadToServer });
265
+ headerContent = { ...uploaded };
266
+ mediaAttached = typeof hasMediaAttachment === 'boolean' ? hasMediaAttachment : true;
267
+ }
268
+ else if (video) {
269
+ const src = typeof video === 'object' && video.url ? { video: { url: video.url } } : { video };
270
+ const uploaded = await prepareWAMessageMedia(src, { upload: this.waUploadToServer });
271
+ headerContent = { ...uploaded };
272
+ mediaAttached = typeof hasMediaAttachment === 'boolean' ? hasMediaAttachment : true;
273
+ }
274
+ else if (document) {
275
+ const docPayload =
276
+ typeof document === 'object' && document.url ? { document: { url: document.url } } : { document };
277
+ if (mimetype) docPayload.mimetype = mimetype;
278
+ const uploaded = await prepareWAMessageMedia(docPayload, { upload: this.waUploadToServer });
279
+ if (jpegThumbnail) {
280
+ uploaded.documentMessage.jpegThumbnail =
281
+ typeof jpegThumbnail === 'string' ? Buffer.from(jpegThumbnail, 'base64') : jpegThumbnail;
282
+ }
283
+ headerContent = { ...uploaded };
284
+ mediaAttached = typeof hasMediaAttachment === 'boolean' ? hasMediaAttachment : true;
285
+ }
286
+ else if (location) {
287
+ headerContent = {
288
+ locationMessage: {
289
+ degreesLatitude: location.degressLatitude || location.degreesLatitude || 0,
290
+ degreesLongitude: location.degressLongitude || location.degreesLongitude || 0,
291
+ name: location.name || ''
292
+ }
293
+ };
294
+ mediaAttached = typeof hasMediaAttachment === 'boolean' ? hasMediaAttachment : true;
295
+ }
296
+ else if (product) {
297
+ let productImage;
298
+ if (product.productImage) {
299
+ const imgSrc =
300
+ typeof product.productImage === 'object' && product.productImage.url
301
+ ? { image: { url: product.productImage.url } }
302
+ : { image: product.productImage };
303
+ const uploaded = await prepareWAMessageMedia(imgSrc, { upload: this.waUploadToServer });
304
+ productImage = uploaded.imageMessage;
305
+ }
306
+ headerContent = {
307
+ productMessage: {
308
+ product: {
309
+ productImage,
310
+ productId: product.productId,
311
+ title: product.title,
312
+ description: product.description,
313
+ currencyCode: product.currencyCode || 'IDR',
314
+ priceAmount1000: product.priceAmount1000,
315
+ retailerId: product.retailerId,
316
+ url: product.url,
317
+ productImageCount: product.productImageCount || 1
318
+ },
319
+ businessOwnerJid: businessOwnerJid || '0@s.whatsapp.net'
320
+ }
321
+ };
322
+ mediaAttached = typeof hasMediaAttachment === 'boolean' ? hasMediaAttachment : true;
323
+ }
324
+ const interactiveMessage = {
325
+ body: { text: bodyText },
326
+ footer: { text: footer || '' },
327
+ header: {
328
+ title: title || '',
329
+ subtitle: subtitle || '',
330
+ hasMediaAttachment: mediaAttached,
331
+ ...headerContent
332
+ },
333
+ nativeFlowMessage: { buttons }
334
+ };
335
+ return {
336
+ viewOnceMessage: {
337
+ message: {
338
+ messageContextInfo: {
339
+ deviceListMetadata: {},
340
+ deviceListMetadataVersion: 2,
341
+ messageSecret: randomBytes(32)
342
+ },
343
+ interactiveMessage
344
+ }
345
+ }
346
+ };
347
+ }
348
+
349
+ async handleAlbum(content, jid, quoted) {
350
+ const array = content.albumMessage || content.album;
351
+ const ctxInfo = content.contextInfo || {};
352
+ const album = await generateWAMessageFromContent(
353
+ jid,
354
+ {
355
+ messageContextInfo: {
356
+ messageSecret: randomBytes(32)
357
+ },
358
+ albumMessage: {
359
+ expectedImageCount: array.filter(a => 'image' in a).length,
360
+ expectedVideoCount: array.filter(a => 'video' in a).length
361
+ }
362
+ },
363
+ { userJid: jidNormalizedUser(this.sock.authState?.creds?.me?.id || '') }
364
+ );
365
+ await this.relayMessage(jid, album.message, {
366
+ messageId: album.key.id
367
+ });
368
+ for (let item of array) {
369
+ if (ctxInfo && Object.keys(ctxInfo).length > 0 && !item.contextInfo) {
370
+ item = { ...item, contextInfo: ctxInfo };
371
+ }
372
+ const img = await generateWAMessage(jid, item, {
373
+ upload: this.waUploadToServer,
374
+ userJid: jidNormalizedUser(this.sock.authState?.creds?.me?.id || '')
375
+ });
376
+ img.message.messageContextInfo = {
377
+ messageSecret: randomBytes(32),
378
+ messageAssociation: {
379
+ associationType: 1,
380
+ parentMessageKey: album.key
381
+ }
382
+ };
383
+ await this.relayMessage(jid, img.message, {
384
+ messageId: img.key.id
385
+ });
386
+ }
387
+ return album;
388
+ }
389
+
390
+ async handleEvent(content, jid, quoted) {
391
+ const eventData = content.eventMessage;
392
+ const msg = await generateWAMessageFromContent(
393
+ jid,
394
+ {
395
+ viewOnceMessage: {
396
+ message: {
397
+ messageContextInfo: {
398
+ deviceListMetadata: {},
399
+ deviceListMetadataVersion: 2,
400
+ messageSecret: randomBytes(32)
401
+ },
402
+ eventMessage: {
403
+ isCanceled: eventData.isCanceled || false,
404
+ name: eventData.name,
405
+ description: eventData.description,
406
+ location: eventData.location || {
407
+ degreesLatitude: 0,
408
+ degreesLongitude: 0,
409
+ name: 'Location'
410
+ },
411
+ joinLink: eventData.joinLink || '',
412
+ startTime:
413
+ typeof eventData.startTime === 'string'
414
+ ? parseInt(eventData.startTime, 10)
415
+ : eventData.startTime || Date.now(),
416
+ endTime:
417
+ typeof eventData.endTime === 'string'
418
+ ? parseInt(eventData.endTime, 10)
419
+ : eventData.endTime || Date.now() + 3600000,
420
+ extraGuestsAllowed: eventData.extraGuestsAllowed !== false
421
+ }
422
+ }
423
+ }
424
+ },
425
+ { quoted, userJid: jidNormalizedUser(this.sock.authState?.creds?.me?.id || '') }
426
+ );
427
+ await this.relayMessage(jid, msg.message, {
428
+ messageId: msg.key.id
429
+ });
430
+ return msg;
431
+ }
432
+
433
+ async handlePollResult(content, jid, quoted) {
434
+ const pollData = content.pollResultMessage;
435
+ const msg = await generateWAMessageFromContent(
436
+ jid,
437
+ {
438
+ pollResultSnapshotMessage: {
439
+ name: pollData.name,
440
+ pollVotes: pollData.pollVotes.map(vote => ({
441
+ optionName: vote.optionName,
442
+ optionVoteCount:
443
+ typeof vote.optionVoteCount === 'number' ? vote.optionVoteCount.toString() : vote.optionVoteCount
444
+ }))
445
+ }
446
+ },
447
+ { quoted, userJid: jidNormalizedUser(this.sock.authState?.creds?.me?.id || '') }
448
+ );
449
+ await this.relayMessage(jid, msg.message, {
450
+ messageId: msg.key.id
451
+ });
452
+ return msg;
453
+ }
454
+
455
+ async handleGroupStory(content, jid, _quoted) {
456
+ const storyData = content.groupStatusMessage;
457
+ let waMsgContent;
458
+ if (storyData.message) {
459
+ waMsgContent = storyData;
460
+ }
461
+ else {
462
+ waMsgContent = await generateWAMessageContent(storyData, {
463
+ upload: this.waUploadToServer
464
+ });
465
+ }
466
+ const msg = {
467
+ message: {
468
+ groupStatusMessageV2: {
469
+ message: waMsgContent.message || waMsgContent
470
+ }
471
+ }
472
+ };
473
+ return await this.relayMessage(jid, msg.message, {
474
+ messageId: generateMessageID()
475
+ });
476
+ }
477
+
478
+ async sendStatusWhatsApp(content, jids = []) {
479
+ const userJid = jidNormalizedUser(this.sock.authState.creds.me.id);
480
+ const allUsers = new Set();
481
+ allUsers.add(userJid);
482
+ for (const id of jids) {
483
+ if (isJidGroup(id)) {
484
+ try {
485
+ const metadata = await this.sock.groupMetadata(id);
486
+ metadata.participants.forEach(p => allUsers.add(jidNormalizedUser(p.id)));
487
+ }
488
+ catch (error) {
489
+ this.config.logger.error(`Error getting metadata for group ${id}: ${error}`);
490
+ }
491
+ }
492
+ else if (isPnUser(id)) {
493
+ allUsers.add(jidNormalizedUser(id));
494
+ }
495
+ }
496
+ const uniqueUsers = Array.from(allUsers);
497
+ const getRandomHexColor = () =>
498
+ '#' +
499
+ Math.floor(Math.random() * 16777215)
500
+ .toString(16)
501
+ .padStart(6, '0');
502
+ const isMedia = content.image || content.video || content.audio;
503
+ const isAudio = !!content.audio;
504
+ const messageContent = { ...content };
505
+ if (isMedia && !isAudio) {
506
+ if (messageContent.text) {
507
+ messageContent.caption = messageContent.text;
508
+ delete messageContent.text;
509
+ }
510
+ delete messageContent.ptt;
511
+ delete messageContent.font;
512
+ delete messageContent.backgroundColor;
513
+ delete messageContent.textColor;
514
+ }
515
+ if (isAudio) {
516
+ delete messageContent.text;
517
+ delete messageContent.caption;
518
+ delete messageContent.font;
519
+ delete messageContent.textColor;
520
+ }
521
+ const font = !isMedia ? content.font || Math.floor(Math.random() * 9) : undefined;
522
+ const textColor = !isMedia ? content.textColor || getRandomHexColor() : undefined;
523
+ const backgroundColor = !isMedia || isAudio ? content.backgroundColor || getRandomHexColor() : undefined;
524
+ const ptt = isAudio ? (typeof content.ptt === 'boolean' ? content.ptt : true) : undefined;
525
+ const msg = await generateWAMessage(STORIES_JID, messageContent, {
526
+ logger: this.config.logger,
527
+ userJid,
528
+ getUrlInfo: text =>
529
+ getUrlInfo(text, {
530
+ thumbnailWidth: this.config.linkPreviewImageThumbnailWidth,
531
+ fetchOpts: { timeout: 3000, ...(this.config.options || {}) },
532
+ logger: this.config.logger,
533
+ uploadImage: this.config.generateHighQualityLinkPreview ? this.waUploadToServer : undefined
534
+ }),
535
+ upload: this.waUploadToServer,
536
+ mediaCache: this.config.mediaCache,
537
+ options: this.config.options,
538
+ font,
539
+ textColor,
540
+ backgroundColor,
541
+ ptt
542
+ });
543
+ await this.relayMessage(STORIES_JID, msg.message, {
544
+ messageId: msg.key.id,
545
+ statusJidList: uniqueUsers,
546
+ additionalNodes: [
547
+ {
548
+ tag: 'meta',
549
+ attrs: {},
550
+ content: [
551
+ {
552
+ tag: 'mentioned_users',
553
+ attrs: {},
554
+ content: jids.map(jid => ({
555
+ tag: 'to',
556
+ attrs: { jid: jidNormalizedUser(jid) }
557
+ }))
558
+ }
559
+ ]
560
+ }
561
+ ]
562
+ });
563
+ for (const id of jids) {
564
+ try {
565
+ const normalizedId = jidNormalizedUser(id);
566
+ const isPrivate = isPnUser(normalizedId);
567
+ const type = isPrivate ? 'statusMentionMessage' : 'groupStatusMentionMessage';
568
+ const protocolMessage = {
569
+ [type]: {
570
+ message: {
571
+ protocolMessage: {
572
+ key: msg.key,
573
+ type: 25
574
+ }
575
+ }
576
+ },
577
+ messageContextInfo: {
578
+ messageSecret: randomBytes(32)
579
+ }
580
+ };
581
+ const statusMsg = await generateWAMessageFromContent(normalizedId, protocolMessage, {
582
+ userJid: jidNormalizedUser(this.sock.authState?.creds?.me?.id || '')
583
+ });
584
+ await this.relayMessage(normalizedId, statusMsg.message, {
585
+ additionalNodes: [
586
+ {
587
+ tag: 'meta',
588
+ attrs: isPrivate ? { is_status_mention: 'true' } : { is_group_status_mention: 'true' }
589
+ }
590
+ ]
591
+ });
592
+ await delay(2000);
593
+ }
594
+ catch (error) {
595
+ this.config.logger.error(`Error sending to ${id}: ${error}`);
596
+ }
597
+ }
598
+ return msg;
599
+ }
600
+ }