zeroz-baileys 0.0.1-security → 1.0.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.

Potentially problematic release.


This version of zeroz-baileys might be problematic. Click here for more details.

Files changed (102) hide show
  1. package/LICENSE +21 -0
  2. package/WAProto/index.js +169661 -0
  3. package/engine-requirements.js +10 -0
  4. package/lib/Defaults/baileys-version.json +3 -0
  5. package/lib/Defaults/constants.js +1 -0
  6. package/lib/Defaults/index.js +149 -0
  7. package/lib/Defaults/phonenumber-mcc.json +223 -0
  8. package/lib/Signal/Group/ciphertext-message.js +15 -0
  9. package/lib/Signal/Group/group-session-builder.js +64 -0
  10. package/lib/Signal/Group/group_cipher.js +96 -0
  11. package/lib/Signal/Group/index.js +57 -0
  12. package/lib/Signal/Group/keyhelper.js +55 -0
  13. package/lib/Signal/Group/queue-job.js +57 -0
  14. package/lib/Signal/Group/sender-chain-key.js +34 -0
  15. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  16. package/lib/Signal/Group/sender-key-message.js +69 -0
  17. package/lib/Signal/Group/sender-key-name.js +51 -0
  18. package/lib/Signal/Group/sender-key-record.js +53 -0
  19. package/lib/Signal/Group/sender-key-state.js +99 -0
  20. package/lib/Signal/Group/sender-message-key.js +29 -0
  21. package/lib/Signal/libsignal.js +174 -0
  22. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  23. package/lib/Socket/Client/index.js +19 -0
  24. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  25. package/lib/Socket/Client/web-socket-client.js +62 -0
  26. package/lib/Socket/business.js +260 -0
  27. package/lib/Socket/chats.js +1002 -0
  28. package/lib/Socket/dugong.js +776 -0
  29. package/lib/Socket/groups.js +317 -0
  30. package/lib/Socket/index.js +11 -0
  31. package/lib/Socket/messages-recv.js +1104 -0
  32. package/lib/Socket/messages-send.js +1022 -0
  33. package/lib/Socket/newsletter.js +441 -0
  34. package/lib/Socket/registration.js +166 -0
  35. package/lib/Socket/socket.js +665 -0
  36. package/lib/Socket/usync.js +70 -0
  37. package/lib/Store/index.js +10 -0
  38. package/lib/Store/make-cache-manager-store.js +83 -0
  39. package/lib/Store/make-in-memory-store.js +427 -0
  40. package/lib/Store/make-ordered-dictionary.js +81 -0
  41. package/lib/Store/object-repository.js +27 -0
  42. package/lib/Types/Auth.js +2 -0
  43. package/lib/Types/Call.js +2 -0
  44. package/lib/Types/Chat.js +4 -0
  45. package/lib/Types/Contact.js +2 -0
  46. package/lib/Types/Events.js +2 -0
  47. package/lib/Types/GroupMetadata.js +2 -0
  48. package/lib/Types/Label.js +27 -0
  49. package/lib/Types/LabelAssociation.js +9 -0
  50. package/lib/Types/Message.js +9 -0
  51. package/lib/Types/Newsletter.js +38 -0
  52. package/lib/Types/Product.js +2 -0
  53. package/lib/Types/Signal.js +2 -0
  54. package/lib/Types/Socket.js +2 -0
  55. package/lib/Types/State.js +2 -0
  56. package/lib/Types/USync.js +2 -0
  57. package/lib/Types/index.js +42 -0
  58. package/lib/Utils/auth-utils.js +206 -0
  59. package/lib/Utils/baileys-event-stream.js +63 -0
  60. package/lib/Utils/business.js +234 -0
  61. package/lib/Utils/chat-utils.js +729 -0
  62. package/lib/Utils/crypto.js +167 -0
  63. package/lib/Utils/decode-wa-message.js +199 -0
  64. package/lib/Utils/event-buffer.js +514 -0
  65. package/lib/Utils/generics.js +498 -0
  66. package/lib/Utils/history.js +96 -0
  67. package/lib/Utils/index.js +33 -0
  68. package/lib/Utils/link-preview.js +93 -0
  69. package/lib/Utils/logger.js +7 -0
  70. package/lib/Utils/lt-hash.js +51 -0
  71. package/lib/Utils/make-mutex.js +43 -0
  72. package/lib/Utils/messages-media.js +865 -0
  73. package/lib/Utils/messages.js +960 -0
  74. package/lib/Utils/noise-handler.js +155 -0
  75. package/lib/Utils/process-message.js +321 -0
  76. package/lib/Utils/signal.js +153 -0
  77. package/lib/Utils/use-multi-file-auth-state.js +119 -0
  78. package/lib/Utils/validate-connection.js +229 -0
  79. package/lib/WABinary/constants.js +40 -0
  80. package/lib/WABinary/decode.js +252 -0
  81. package/lib/WABinary/encode.js +265 -0
  82. package/lib/WABinary/generic-utils.js +198 -0
  83. package/lib/WABinary/index.js +21 -0
  84. package/lib/WABinary/jid-utils.js +62 -0
  85. package/lib/WABinary/types.js +2 -0
  86. package/lib/WAM/BinaryInfo.js +13 -0
  87. package/lib/WAM/constants.js +15350 -0
  88. package/lib/WAM/encode.js +155 -0
  89. package/lib/WAM/index.js +19 -0
  90. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  91. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  92. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  93. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  94. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
  95. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
  96. package/lib/WAUSync/Protocols/index.js +20 -0
  97. package/lib/WAUSync/USyncQuery.js +89 -0
  98. package/lib/WAUSync/USyncUser.js +26 -0
  99. package/lib/WAUSync/index.js +19 -0
  100. package/lib/index.js +65 -0
  101. package/package.json +103 -4
  102. package/README.md +0 -5
@@ -0,0 +1,776 @@
1
+ const WAProto = require('../../WAProto').proto;
2
+ const crypto = require('crypto');
3
+ const Utils_1 = require("../Utils");
4
+ const WABinary_1 = require("../WABinary");
5
+
6
+ class Z {
7
+ constructor(utils, waUploadToServer, relayMessageFn, config, sock) {
8
+ this.utils = utils;
9
+ this.relayMessage = relayMessageFn;
10
+ this.waUploadToServer = waUploadToServer;
11
+ this.config = config;
12
+ this.sock = sock;
13
+
14
+ this.bail = {
15
+ generateWAMessageContent: this.utils.generateWAMessageContent || Utils_1.generateWAMessageContent,
16
+ generateMessageID: Utils_1.generateMessageID,
17
+ getContentType: (msg) => Object.keys(msg.message || {})[0]
18
+ };
19
+ }
20
+
21
+ detectType(content) {
22
+ if (content.requestPaymentMessage) return 'PAYMENT';
23
+ if (content.productMessage) return 'PRODUCT';
24
+ if (content.interactiveButtons) return 'INTERACTIVE_BUTTONS';
25
+ if (content.interactiveMessage) return 'INTERACTIVE';
26
+ if (content.albumMessage) return 'ALBUM';
27
+ if (content.eventMessage) return 'EVENT';
28
+ if (content.pollResultMessage) return 'POLL_RESULT';
29
+ if (content.groupStatusMessage) return 'GROUP_STORY';
30
+ return null;
31
+ }
32
+
33
+ async handlePayment(content, quoted) {
34
+ const data = content.requestPaymentMessage;
35
+ let notes = {};
36
+
37
+ if (data.sticker?.stickerMessage) {
38
+ notes = {
39
+ stickerMessage: {
40
+ ...data.sticker.stickerMessage,
41
+ contextInfo: {
42
+ stanzaId: quoted?.key?.id,
43
+ participant: quoted?.key?.participant || content.sender,
44
+ quotedMessage: quoted?.message
45
+ }
46
+ }
47
+ };
48
+ } else if (data.note) {
49
+ notes = {
50
+ extendedTextMessage: {
51
+ text: data.note,
52
+ contextInfo: {
53
+ stanzaId: quoted?.key?.id,
54
+ participant: quoted?.key?.participant || content.sender,
55
+ quotedMessage: quoted?.message
56
+ }
57
+ }
58
+ };
59
+ }
60
+
61
+ return {
62
+ requestPaymentMessage: WAProto.Message.RequestPaymentMessage.fromObject({
63
+ expiryTimestamp: data.expiry || 0,
64
+ amount1000: data.amount || 0,
65
+ currencyCodeIso4217: data.currency || "IDR",
66
+ requestFrom: data.from || "0@s.whatsapp.net",
67
+ noteMessage: notes,
68
+ background: data.background ?? {
69
+ id: "DEFAULT",
70
+ placeholderArgb: 0xFFF0F0F0
71
+ }
72
+ })
73
+ };
74
+ }
75
+
76
+ async handleProduct(content, jid, quoted) {
77
+ const {
78
+ title,
79
+ description,
80
+ thumbnail,
81
+ productId,
82
+ retailerId,
83
+ url,
84
+ body = "",
85
+ footer = "",
86
+ buttons = [],
87
+ priceAmount1000 = null,
88
+ currencyCode = "IDR"
89
+ } = content.productMessage;
90
+
91
+ let productImage;
92
+
93
+ if (Buffer.isBuffer(thumbnail)) {
94
+ const { imageMessage } = await this.utils.generateWAMessageContent(
95
+ { image: thumbnail },
96
+ { upload: this.waUploadToServer }
97
+ );
98
+ productImage = imageMessage;
99
+ } else if (typeof thumbnail === 'object' && thumbnail.url) {
100
+ const { imageMessage } = await this.utils.generateWAMessageContent(
101
+ { image: { url: thumbnail.url }},
102
+ { upload: this.waUploadToServer }
103
+ );
104
+ productImage = imageMessage;
105
+ }
106
+
107
+ return {
108
+ viewOnceMessage: {
109
+ message: {
110
+ interactiveMessage: {
111
+ body: { text: body },
112
+ footer: { text: footer },
113
+ header: {
114
+ title,
115
+ hasMediaAttachment: true,
116
+ productMessage: {
117
+ product: {
118
+ productImage,
119
+ productId,
120
+ title,
121
+ description,
122
+ currencyCode,
123
+ priceAmount1000,
124
+ retailerId,
125
+ url,
126
+ productImageCount: 1
127
+ },
128
+ businessOwnerJid: "0@s.whatsapp.net"
129
+ }
130
+ },
131
+ nativeFlowMessage: { buttons }
132
+ }
133
+ }
134
+ }
135
+ };
136
+ }
137
+
138
+ async handleInteractive(content, jid, quoted) {
139
+ const {
140
+ title,
141
+ footer,
142
+ thumbnail,
143
+ image,
144
+ video,
145
+ document,
146
+ mimetype,
147
+ fileName,
148
+ jpegThumbnail,
149
+ contextInfo,
150
+ externalAdReply,
151
+ buttons = [],
152
+ nativeFlowMessage,
153
+ header
154
+ } = content.interactiveMessage;
155
+
156
+ let media = null;
157
+ let mediaType = null;
158
+
159
+ if (thumbnail) {
160
+ media = await this.utils.prepareWAMessageMedia(
161
+ { image: { url: thumbnail } },
162
+ { upload: this.waUploadToServer }
163
+ );
164
+ mediaType = 'image';
165
+ } else if (image) {
166
+ if (typeof image === 'object' && image.url) {
167
+ media = await this.utils.prepareWAMessageMedia(
168
+ { image: { url: image.url } },
169
+ { upload: this.waUploadToServer }
170
+ );
171
+ } else {
172
+ media = await this.utils.prepareWAMessageMedia(
173
+ { image: image },
174
+ { upload: this.waUploadToServer }
175
+ );
176
+ }
177
+ mediaType = 'image';
178
+ } else if (video) {
179
+ if (typeof video === 'object' && video.url) {
180
+ media = await this.utils.prepareWAMessageMedia(
181
+ { video: { url: video.url } },
182
+ { upload: this.waUploadToServer }
183
+ );
184
+ } else {
185
+ media = await this.utils.prepareWAMessageMedia(
186
+ { video: video },
187
+ { upload: this.waUploadToServer }
188
+ );
189
+ }
190
+ mediaType = 'video';
191
+ } else if (document) {
192
+ let documentPayload = {
193
+ document: document
194
+ };
195
+ if (jpegThumbnail) {
196
+ if (typeof jpegThumbnail === 'object' && jpegThumbnail.url) {
197
+ documentPayload.jpegThumbnail = { url: jpegThumbnail.url };
198
+ } else {
199
+ documentPayload.jpegThumbnail = jpegThumbnail;
200
+ }
201
+ }
202
+
203
+ media = await this.utils.prepareWAMessageMedia(
204
+ documentPayload,
205
+ { upload: this.waUploadToServer }
206
+ );
207
+ if (fileName) {
208
+ media.documentMessage.fileName = fileName;
209
+ }
210
+ if (mimetype) {
211
+ media.documentMessage.mimetype = mimetype;
212
+ }
213
+ mediaType = 'document';
214
+ }
215
+ let interactiveMessage = {
216
+ body: { text: title || "" },
217
+ footer: { text: footer || "" }
218
+ };
219
+ if (buttons && buttons.length > 0) {
220
+ interactiveMessage.nativeFlowMessage = {
221
+ buttons: buttons
222
+ };
223
+ if (nativeFlowMessage) {
224
+ interactiveMessage.nativeFlowMessage = {
225
+ ...interactiveMessage.nativeFlowMessage,
226
+ ...nativeFlowMessage
227
+ };
228
+ }
229
+ } else if (nativeFlowMessage) {
230
+ interactiveMessage.nativeFlowMessage = nativeFlowMessage;
231
+ }
232
+
233
+ if (media) {
234
+ interactiveMessage.header = {
235
+ title: header || "",
236
+ hasMediaAttachment: true,
237
+ ...media
238
+ };
239
+ } else {
240
+ interactiveMessage.header = {
241
+ title: header || "",
242
+ hasMediaAttachment: false
243
+ };
244
+ }
245
+
246
+ let finalContextInfo = {};
247
+ if (contextInfo) {
248
+ finalContextInfo = {
249
+ mentionedJid: contextInfo.mentionedJid || [],
250
+ forwardingScore: contextInfo.forwardingScore || 0,
251
+ isForwarded: contextInfo.isForwarded || false,
252
+ ...contextInfo
253
+ };
254
+ }
255
+
256
+ if (externalAdReply) {
257
+ finalContextInfo.externalAdReply = {
258
+ title: externalAdReply.title || "",
259
+ body: externalAdReply.body || "",
260
+ mediaType: externalAdReply.mediaType || 1,
261
+ thumbnailUrl: externalAdReply.thumbnailUrl || "",
262
+ mediaUrl: externalAdReply.mediaUrl || "",
263
+ sourceUrl: externalAdReply.sourceUrl || "",
264
+ showAdAttribution: externalAdReply.showAdAttribution || false,
265
+ renderLargerThumbnail: externalAdReply.renderLargerThumbnail || false,
266
+ ...externalAdReply
267
+ };
268
+ }
269
+
270
+ if (Object.keys(finalContextInfo).length > 0) {
271
+ interactiveMessage.contextInfo = finalContextInfo;
272
+ }
273
+ return {
274
+ interactiveMessage: interactiveMessage
275
+ };
276
+ }
277
+
278
+ async handleInteractiveButtons(content, jid, quoted) {
279
+ const {
280
+ text,
281
+ caption,
282
+ title,
283
+ subtitle,
284
+ footer,
285
+ interactiveButtons,
286
+ hasMediaAttachment,
287
+ image,
288
+ video,
289
+ document,
290
+ mimetype,
291
+ jpegThumbnail,
292
+ location,
293
+ product,
294
+ businessOwnerJid
295
+ } = content;
296
+
297
+ const bodyText = text || caption || '';
298
+ const buttons = interactiveButtons.map(btn => ({
299
+ name: btn.name,
300
+ buttonParamsJson: typeof btn.buttonParamsJson === 'string'
301
+ ? btn.buttonParamsJson
302
+ : JSON.stringify(btn.buttonParamsJson)
303
+ }));
304
+
305
+ let headerContent = {};
306
+ let mediaAttached = typeof hasMediaAttachment === 'boolean' ? hasMediaAttachment : false;
307
+
308
+ if (image) {
309
+ const mediaSource = typeof image === 'object' && image.url
310
+ ? { image: { url: image.url } }
311
+ : { image };
312
+ const uploaded = await this.utils.prepareWAMessageMedia(
313
+ mediaSource,
314
+ { upload: this.waUploadToServer }
315
+ );
316
+ headerContent = { ...uploaded };
317
+ mediaAttached = typeof hasMediaAttachment === 'boolean' ? hasMediaAttachment : true;
318
+ } else if (video) {
319
+ const mediaSource = typeof video === 'object' && video.url
320
+ ? { video: { url: video.url } }
321
+ : { video };
322
+ const uploaded = await this.utils.prepareWAMessageMedia(
323
+ mediaSource,
324
+ { upload: this.waUploadToServer }
325
+ );
326
+ headerContent = { ...uploaded };
327
+ mediaAttached = typeof hasMediaAttachment === 'boolean' ? hasMediaAttachment : true;
328
+ } else if (document) {
329
+ const docPayload = typeof document === 'object' && document.url
330
+ ? { document: { url: document.url } }
331
+ : { document };
332
+ if (mimetype) docPayload.mimetype = mimetype;
333
+ const uploaded = await this.utils.prepareWAMessageMedia(
334
+ docPayload,
335
+ { upload: this.waUploadToServer }
336
+ );
337
+ if (jpegThumbnail) {
338
+ uploaded.documentMessage.jpegThumbnail = typeof jpegThumbnail === 'string'
339
+ ? Buffer.from(jpegThumbnail, 'base64')
340
+ : jpegThumbnail;
341
+ }
342
+ headerContent = { ...uploaded };
343
+ mediaAttached = typeof hasMediaAttachment === 'boolean' ? hasMediaAttachment : true;
344
+ } else if (location) {
345
+ headerContent = {
346
+ locationMessage: {
347
+ degreesLatitude: location.degressLatitude || location.degreesLatitude || 0,
348
+ degreesLongitude: location.degressLongitude || location.degreesLongitude || 0,
349
+ name: location.name || ''
350
+ }
351
+ };
352
+ mediaAttached = typeof hasMediaAttachment === 'boolean' ? hasMediaAttachment : true;
353
+ } else if (product) {
354
+ let productImage;
355
+ if (product.productImage) {
356
+ const imgSource = typeof product.productImage === 'object' && product.productImage.url
357
+ ? { image: { url: product.productImage.url } }
358
+ : { image: product.productImage };
359
+ const uploaded = await this.utils.prepareWAMessageMedia(
360
+ imgSource,
361
+ { upload: this.waUploadToServer }
362
+ );
363
+ productImage = uploaded.imageMessage;
364
+ }
365
+ headerContent = {
366
+ productMessage: {
367
+ product: {
368
+ productImage,
369
+ productId: product.productId,
370
+ title: product.title,
371
+ description: product.description,
372
+ currencyCode: product.currencyCode || 'IDR',
373
+ priceAmount1000: product.priceAmount1000,
374
+ retailerId: product.retailerId,
375
+ url: product.url,
376
+ productImageCount: product.productImageCount || 1
377
+ },
378
+ businessOwnerJid: businessOwnerJid || '0@s.whatsapp.net'
379
+ }
380
+ };
381
+ mediaAttached = typeof hasMediaAttachment === 'boolean' ? hasMediaAttachment : true;
382
+ }
383
+
384
+ const interactiveMessage = {
385
+ body: { text: bodyText },
386
+ footer: { text: footer || '' },
387
+ header: {
388
+ title: title || '',
389
+ subtitle: subtitle || '',
390
+ hasMediaAttachment: mediaAttached,
391
+ ...headerContent
392
+ },
393
+ nativeFlowMessage: { buttons }
394
+ };
395
+
396
+ const msg = {
397
+ viewOnceMessage: {
398
+ message: {
399
+ messageContextInfo: {
400
+ deviceListMetadata: {},
401
+ deviceListMetadataVersion: 2,
402
+ messageSecret: crypto.randomBytes(32)
403
+ },
404
+ interactiveMessage
405
+ }
406
+ }
407
+ };
408
+
409
+ return msg;
410
+ }
411
+
412
+ async handleAlbum(content, jid, quoted) {
413
+ const array = content.albumMessage || content.album;
414
+ const ctxInfo = content.contextInfo || {};
415
+ const album = await this.utils.generateWAMessageFromContent(jid, {
416
+ messageContextInfo: {
417
+ messageSecret: crypto.randomBytes(32),
418
+ },
419
+ albumMessage: {
420
+ expectedImageCount: array.filter((a) => a.hasOwnProperty("image")).length,
421
+ expectedVideoCount: array.filter((a) => a.hasOwnProperty("video")).length,
422
+ },
423
+ }, {
424
+ userJid: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net',
425
+ quoted,
426
+ upload: this.waUploadToServer
427
+ });
428
+
429
+ await this.relayMessage(jid, album.message, {
430
+ messageId: album.key.id,
431
+ });
432
+
433
+ for (let item of array) {
434
+ if (ctxInfo && Object.keys(ctxInfo).length > 0 && !item.contextInfo) {
435
+ item = { ...item, contextInfo: ctxInfo };
436
+ }
437
+ const img = await this.utils.generateWAMessage(jid, item, {
438
+ upload: this.waUploadToServer,
439
+ });
440
+
441
+ img.message.messageContextInfo = {
442
+ messageSecret: crypto.randomBytes(32),
443
+ messageAssociation: {
444
+ associationType: 1,
445
+ parentMessageKey: album.key,
446
+ },
447
+ participant: "0@s.whatsapp.net",
448
+ remoteJid: "status@broadcast",
449
+ forwardingScore: 99999,
450
+ isForwarded: true,
451
+ mentionedJid: [jid],
452
+ starred: true,
453
+ labels: ["Y", "Important"],
454
+ isHighlighted: true,
455
+ businessMessageForwardInfo: {
456
+ businessOwnerJid: jid,
457
+ },
458
+ dataSharingContext: {
459
+ showMmDisclosure: true,
460
+ },
461
+ };
462
+
463
+ img.message.forwardedNewsletterMessageInfo = {
464
+ newsletterJid: "0@newsletter",
465
+ serverMessageId: 1,
466
+ newsletterName: `WhatsApp`,
467
+ contentType: 1,
468
+ timestamp: new Date().toISOString(),
469
+ senderName: "Ourin Team",
470
+ content: "Text Message",
471
+ priority: "high",
472
+ status: "sent",
473
+ };
474
+
475
+ img.message.disappearingMode = {
476
+ initiator: 3,
477
+ trigger: 4,
478
+ initiatorDeviceJid: jid,
479
+ initiatedByExternalService: true,
480
+ initiatedByUserDevice: true,
481
+ initiatedBySystem: true,
482
+ initiatedByServer: true,
483
+ initiatedByAdmin: true,
484
+ initiatedByUser: true,
485
+ initiatedByApp: true,
486
+ initiatedByBot: true,
487
+ initiatedByMe: true,
488
+ };
489
+
490
+ await this.relayMessage(jid, img.message, {
491
+ messageId: img.key.id,
492
+ quoted: {
493
+ key: {
494
+ remoteJid: album.key.remoteJid,
495
+ id: album.key.id,
496
+ fromMe: true,
497
+ participant: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net',
498
+ },
499
+ message: album.message,
500
+ },
501
+ });
502
+ }
503
+ return album;
504
+ }
505
+
506
+ async handleEvent(content, jid, quoted) {
507
+ const eventData = content.eventMessage;
508
+
509
+ const msg = await this.utils.generateWAMessageFromContent(jid, {
510
+ viewOnceMessage: {
511
+ message: {
512
+ messageContextInfo: {
513
+ deviceListMetadata: {},
514
+ deviceListMetadataVersion: 2,
515
+ messageSecret: crypto.randomBytes(32),
516
+ supportPayload: JSON.stringify({
517
+ version: 2,
518
+ is_ai_message: true,
519
+ should_show_system_message: true,
520
+ ticket_id: crypto.randomBytes(16).toString('hex')
521
+ })
522
+ },
523
+ eventMessage: {
524
+ contextInfo: {
525
+ mentionedJid: [jid],
526
+ participant: jid,
527
+ remoteJid: "status@broadcast",
528
+ forwardedNewsletterMessageInfo: {
529
+ newsletterName: "OURIN GLITCH",
530
+ newsletterJid: "-@newsletter",
531
+ serverMessageId: 1
532
+ }
533
+ },
534
+ isCanceled: eventData.isCanceled || false,
535
+ name: eventData.name,
536
+ description: eventData.description,
537
+ location: eventData.location || {
538
+ degreesLatitude: 0,
539
+ degreesLongitude: 0,
540
+ name: "Location"
541
+ },
542
+ joinLink: eventData.joinLink || '',
543
+ startTime: typeof eventData.startTime === 'string' ? parseInt(eventData.startTime) : eventData.startTime || Date.now(),
544
+ endTime: typeof eventData.endTime === 'string' ? parseInt(eventData.endTime) : eventData.endTime || Date.now() + 3600000,
545
+ extraGuestsAllowed: eventData.extraGuestsAllowed !== false
546
+ }
547
+ }
548
+ }
549
+ }, { quoted });
550
+
551
+ await this.relayMessage(jid, msg.message, {
552
+ messageId: msg.key.id
553
+ });
554
+ return msg;
555
+ }
556
+
557
+ async handlePollResult(content, jid, quoted) {
558
+ const pollData = content.pollResultMessage;
559
+
560
+ const msg = await this.utils.generateWAMessageFromContent(jid, {
561
+ pollResultSnapshotMessage: {
562
+ name: pollData.name,
563
+ pollVotes: pollData.pollVotes.map(vote => ({
564
+ optionName: vote.optionName,
565
+ optionVoteCount: typeof vote.optionVoteCount === 'number'
566
+ ? vote.optionVoteCount.toString()
567
+ : vote.optionVoteCount
568
+ }))
569
+ }
570
+ }, {
571
+ userJid: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net',
572
+ quoted
573
+ });
574
+
575
+ await this.relayMessage(jid, msg.message, {
576
+ messageId: msg.key.id
577
+ });
578
+
579
+ return msg;
580
+ }
581
+
582
+ async handleGroupStory(content, jid, quoted) {
583
+ const storyData = content.groupStatusMessage;
584
+ let waMsgContent;
585
+
586
+ if (storyData.message) {
587
+ waMsgContent = storyData;
588
+ } else {
589
+ if (typeof this.bail?.generateWAMessageContent === "function") {
590
+ waMsgContent = await this.bail.generateWAMessageContent(storyData, {
591
+ upload: this.waUploadToServer
592
+ });
593
+ } else if (typeof this.utils?.generateWAMessageContent === "function") {
594
+ waMsgContent = await this.utils.generateWAMessageContent(storyData, {
595
+ upload: this.waUploadToServer
596
+ });
597
+ } else if (typeof this.utils?.prepareMessageContent === "function") {
598
+ waMsgContent = await this.utils.prepareMessageContent(storyData, {
599
+ upload: this.waUploadToServer
600
+ });
601
+ } else {
602
+ waMsgContent = await Utils_1.generateWAMessageContent(storyData, {
603
+ upload: this.waUploadToServer
604
+ });
605
+ }
606
+ }
607
+
608
+ let msg = {
609
+ message: {
610
+ groupStatusMessageV2: {
611
+ message: waMsgContent.message || waMsgContent
612
+ }
613
+ }
614
+ };
615
+
616
+ return await this.relayMessage(jid, msg.message, {
617
+ messageId: this.bail.generateMessageID()
618
+ });
619
+ }
620
+
621
+ async sendStatusWhatsApp(content, jids = []) {
622
+ const userJid = WABinary_1.jidNormalizedUser(this.sock.authState.creds.me.id);
623
+ let allUsers = new Set();
624
+ allUsers.add(userJid);
625
+
626
+ for (const id of jids) {
627
+ const isGroup = WABinary_1.isJidGroup(id);
628
+ const isPrivate = WABinary_1.isJidUser(id);
629
+
630
+ if (isGroup) {
631
+ try {
632
+ const metadata = await this.sock.groupMetadata(id);
633
+ const participants = metadata.participants.map(p => WABinary_1.jidNormalizedUser(p.id));
634
+ participants.forEach(jid => allUsers.add(jid));
635
+ } catch (error) {
636
+ this.config.logger.error(`Error getting metadata for group ${id}: ${error}`);
637
+ }
638
+ } else if (isPrivate) {
639
+ allUsers.add(WABinary_1.jidNormalizedUser(id));
640
+ }
641
+ }
642
+
643
+ const uniqueUsers = Array.from(allUsers);
644
+ const getRandomHexColor = () => "#" + Math.floor(Math.random() * 16777215).toString(16).padStart(6, "0");
645
+
646
+ const isMedia = content.image || content.video || content.audio;
647
+ const isAudio = !!content.audio;
648
+
649
+ const messageContent = { ...content };
650
+
651
+ if (isMedia && !isAudio) {
652
+ if (messageContent.text) {
653
+ messageContent.caption = messageContent.text;
654
+ delete messageContent.text;
655
+ }
656
+ delete messageContent.ptt;
657
+ delete messageContent.font;
658
+ delete messageContent.backgroundColor;
659
+ delete messageContent.textColor;
660
+ }
661
+
662
+ if (isAudio) {
663
+ delete messageContent.text;
664
+ delete messageContent.caption;
665
+ delete messageContent.font;
666
+ delete messageContent.textColor;
667
+ }
668
+
669
+ const font = !isMedia ? (content.font || Math.floor(Math.random() * 9)) : undefined;
670
+ const textColor = !isMedia ? (content.textColor || getRandomHexColor()) : undefined;
671
+ const backgroundColor = (!isMedia || isAudio) ? (content.backgroundColor || getRandomHexColor()) : undefined;
672
+ const ptt = isAudio ? (typeof content.ptt === 'boolean' ? content.ptt : true) : undefined;
673
+
674
+ let msg;
675
+ let mediaHandle;
676
+
677
+ try {
678
+ const link_preview_1 = require("../Utils/link-preview");
679
+
680
+ msg = await Utils_1.generateWAMessage(WABinary_1.STORIES_JID, messageContent, {
681
+ logger: this.config.logger,
682
+ userJid,
683
+ getUrlInfo: text => link_preview_1.getUrlInfo(text, {
684
+ thumbnailWidth: this.config.linkPreviewImageThumbnailWidth,
685
+ fetchOpts: { timeout: 3000, ...this.config.options || {} },
686
+ logger: this.config.logger,
687
+ uploadImage: this.config.generateHighQualityLinkPreview ? this.waUploadToServer : undefined
688
+ }),
689
+ upload: async (encFilePath, opts) => {
690
+ const up = await this.waUploadToServer(encFilePath, { ...opts });
691
+ mediaHandle = up.handle;
692
+ return up;
693
+ },
694
+ mediaCache: this.config.mediaCache,
695
+ options: this.config.options,
696
+ font,
697
+ textColor,
698
+ backgroundColor,
699
+ ptt
700
+ });
701
+ } catch (error) {
702
+ this.config.logger.error(`Error generating message: ${error}`);
703
+ throw error;
704
+ }
705
+
706
+ await this.relayMessage(WABinary_1.STORIES_JID, msg.message, {
707
+ messageId: msg.key.id,
708
+ statusJidList: uniqueUsers,
709
+ additionalNodes: [
710
+ {
711
+ tag: 'meta',
712
+ attrs: {},
713
+ content: [
714
+ {
715
+ tag: 'mentioned_users',
716
+ attrs: {},
717
+ content: jids.map(jid => ({
718
+ tag: 'to',
719
+ attrs: { jid: WABinary_1.jidNormalizedUser(jid) }
720
+ }))
721
+ }
722
+ ]
723
+ }
724
+ ]
725
+ });
726
+
727
+ for (const id of jids) {
728
+ try {
729
+ const normalizedId = WABinary_1.jidNormalizedUser(id);
730
+ const isPrivate = WABinary_1.isJidUser(normalizedId);
731
+ const type = isPrivate ? 'statusMentionMessage' : 'groupStatusMentionMessage';
732
+
733
+ const protocolMessage = {
734
+ [type]: {
735
+ message: {
736
+ protocolMessage: {
737
+ key: msg.key,
738
+ type: 25
739
+ }
740
+ }
741
+ },
742
+ messageContextInfo: {
743
+ messageSecret: crypto.randomBytes(32)
744
+ }
745
+ };
746
+
747
+ const statusMsg = await Utils_1.generateWAMessageFromContent(
748
+ normalizedId,
749
+ protocolMessage,
750
+ {}
751
+ );
752
+
753
+ await this.relayMessage(
754
+ normalizedId,
755
+ statusMsg.message,
756
+ {
757
+ additionalNodes: [{
758
+ tag: 'meta',
759
+ attrs: isPrivate ?
760
+ { is_status_mention: 'true' } :
761
+ { is_group_status_mention: 'true' }
762
+ }]
763
+ }
764
+ );
765
+
766
+ await Utils_1.delay(2000);
767
+ } catch (error) {
768
+ this.config.logger.error(`Error sending to ${id}: ${error}`);
769
+ }
770
+ }
771
+
772
+ return msg;
773
+ }
774
+ }
775
+
776
+ module.exports = Z;