@genuxofficial/baileys 1.0.0 → 2.0.0

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 (99) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +5 -1
  3. package/WAProto/index.d.ts +19244 -2787
  4. package/WAProto/index.js +138202 -74217
  5. package/engine-requirements.js +10 -0
  6. package/lib/Defaults/baileys-version.json +1 -1
  7. package/lib/Defaults/index.d.ts +3 -5
  8. package/lib/Defaults/index.js +7 -6
  9. package/lib/Signal/libsignal.js +18 -9
  10. package/lib/Socket/Client/types.d.ts +0 -2
  11. package/lib/Socket/Client/websocket.js +1 -1
  12. package/lib/Socket/business.d.ts +65 -37
  13. package/lib/Socket/chats.d.ts +22 -18
  14. package/lib/Socket/chats.js +110 -6
  15. package/lib/Socket/groups.d.ts +30 -26
  16. package/lib/Socket/groups.js +20 -6
  17. package/lib/Socket/index.d.ts +66 -38
  18. package/lib/Socket/messages-recv.d.ts +63 -33
  19. package/lib/Socket/messages-recv.js +174 -27
  20. package/lib/Socket/messages-send.d.ts +55 -29
  21. package/lib/Socket/messages-send.js +190 -26
  22. package/lib/Socket/newsletter.d.ts +140 -0
  23. package/lib/Socket/newsletter.js +252 -0
  24. package/lib/Socket/socket.d.ts +8 -10
  25. package/lib/Socket/socket.js +26 -13
  26. package/lib/Socket/usync.d.ts +10 -12
  27. package/lib/Socket/usync.js +10 -15
  28. package/lib/Store/index.d.ts +1 -2
  29. package/lib/Store/index.js +1 -3
  30. package/lib/Store/make-in-memory-store.d.ts +1 -1
  31. package/lib/Store/make-in-memory-store.js +14 -5
  32. package/lib/Store/make-ordered-dictionary.d.ts +1 -1
  33. package/lib/Types/Auth.d.ts +0 -2
  34. package/lib/Types/Chat.d.ts +7 -0
  35. package/lib/Types/Contact.d.ts +5 -0
  36. package/lib/Types/Events.d.ts +27 -0
  37. package/lib/Types/GroupMetadata.d.ts +7 -0
  38. package/lib/Types/Label.js +1 -1
  39. package/lib/Types/LabelAssociation.js +1 -1
  40. package/lib/Types/Message.d.ts +129 -16
  41. package/lib/Types/Message.js +0 -2
  42. package/lib/Types/Newsletter.d.ts +79 -0
  43. package/lib/Types/Newsletter.js +18 -0
  44. package/lib/Types/Socket.d.ts +8 -5
  45. package/lib/Types/index.d.ts +1 -0
  46. package/lib/Types/index.js +2 -1
  47. package/lib/Utils/auth-utils.d.ts +1 -1
  48. package/lib/Utils/auth-utils.js +6 -7
  49. package/lib/Utils/business.js +2 -2
  50. package/lib/Utils/chat-utils.d.ts +8 -10
  51. package/lib/Utils/chat-utils.js +11 -0
  52. package/lib/Utils/crypto.d.ts +14 -16
  53. package/lib/Utils/crypto.js +40 -26
  54. package/lib/Utils/decode-wa-message.d.ts +5 -3
  55. package/lib/Utils/decode-wa-message.js +171 -29
  56. package/lib/Utils/event-buffer.js +1 -3
  57. package/lib/Utils/generics.d.ts +35 -9
  58. package/lib/Utils/generics.js +93 -27
  59. package/lib/Utils/history.d.ts +2 -2
  60. package/lib/Utils/link-preview.d.ts +1 -1
  61. package/lib/Utils/link-preview.js +17 -7
  62. package/lib/Utils/make-mutex.d.ts +2 -2
  63. package/lib/Utils/make-mutex.js +0 -1
  64. package/lib/Utils/messages-media.d.ts +35 -16
  65. package/lib/Utils/messages-media.js +168 -43
  66. package/lib/Utils/messages.d.ts +6 -9
  67. package/lib/Utils/messages.js +297 -37
  68. package/lib/Utils/noise-handler.d.ts +5 -7
  69. package/lib/Utils/process-message.js +2 -3
  70. package/lib/Utils/use-multi-file-auth-state.js +44 -13
  71. package/lib/Utils/validate-connection.d.ts +2 -2
  72. package/lib/Utils/validate-connection.js +1 -3
  73. package/lib/WABinary/decode.d.ts +2 -4
  74. package/lib/WABinary/decode.js +20 -9
  75. package/lib/WABinary/encode.d.ts +1 -3
  76. package/lib/WABinary/encode.js +30 -12
  77. package/lib/WABinary/generic-utils.d.ts +1 -3
  78. package/lib/WABinary/generic-utils.js +2 -2
  79. package/lib/WABinary/jid-utils.d.ts +9 -4
  80. package/lib/WABinary/jid-utils.js +25 -4
  81. package/lib/WAM/BinaryInfo.d.ts +2 -12
  82. package/lib/WAM/encode.d.ts +1 -3
  83. package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
  84. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +2 -2
  85. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
  86. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +5 -5
  87. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
  88. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
  89. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
  90. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
  91. package/lib/WAUSync/USyncQuery.d.ts +2 -0
  92. package/lib/WAUSync/USyncQuery.js +27 -13
  93. package/lib/WAUSync/USyncUser.d.ts +2 -0
  94. package/lib/WAUSync/USyncUser.js +4 -0
  95. package/lib/index.d.ts +2 -1
  96. package/lib/index.js +3 -1
  97. package/package.json +59 -57
  98. package/WAProto/GenerateStatics.sh +0 -4
  99. package/WAProto/WAProto.proto +0 -3344
@@ -4,21 +4,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.makeMessagesSocket = void 0;
7
- const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
8
7
  const boom_1 = require("@hapi/boom");
8
+ const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
9
9
  const WAProto_1 = require("../../WAProto");
10
10
  const Defaults_1 = require("../Defaults");
11
11
  const Utils_1 = require("../Utils");
12
12
  const link_preview_1 = require("../Utils/link-preview");
13
13
  const WABinary_1 = require("../WABinary");
14
14
  const WAUSync_1 = require("../WAUSync");
15
- const groups_1 = require("./groups");
15
+ const newsletter_1 = require("./newsletter");
16
+ var ListType = WAProto_1.proto.Message.ListMessage.ListType;
16
17
  const makeMessagesSocket = (config) => {
17
18
  const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: axiosOptions, patchMessageBeforeSending, cachedGroupMetadata, } = config;
18
- const sock = (0, groups_1.makeGroupsSocket)(config);
19
+ const sock = (0, newsletter_1.makeNewsletterSocket)(config);
19
20
  const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, sendNode, groupMetadata, groupToggleEphemeral, } = sock;
20
21
  const userDevicesCache = config.userDevicesCache || new node_cache_1.default({
21
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
22
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
22
23
  useClones: false
23
24
  });
24
25
  let mediaConn;
@@ -77,7 +78,7 @@ const makeMessagesSocket = (config) => {
77
78
  }
78
79
  }
79
80
  if (type) {
80
- node.attrs.type = type;
81
+ node.attrs.type = (0, WABinary_1.isJidNewsletter)(jid) ? 'read-self' : type;
81
82
  }
82
83
  const remainingMessageIds = messageIds.slice(1);
83
84
  if (remainingMessageIds.length) {
@@ -138,9 +139,7 @@ const makeMessagesSocket = (config) => {
138
139
  if (!toFetch.length) {
139
140
  return deviceResults;
140
141
  }
141
- const query = new WAUSync_1.USyncQuery()
142
- .withContext('message')
143
- .withDeviceProtocol();
142
+ const query = new WAUSync_1.USyncQuery().withContext('message').withDeviceProtocol();
144
143
  for (const jid of toFetch) {
145
144
  query.withUser(new WAUSync_1.USyncUser().withId(jid));
146
145
  }
@@ -157,6 +156,7 @@ const makeMessagesSocket = (config) => {
157
156
  userDevicesCache.set(key, deviceMap[key]);
158
157
  }
159
158
  }
159
+ logger.debug(deviceResults);
160
160
  return deviceResults;
161
161
  };
162
162
  const assertSessions = async (jids, force) => {
@@ -225,10 +225,17 @@ const makeMessagesSocket = (config) => {
225
225
  return msgId;
226
226
  };
227
227
  const createParticipantNodes = async (jids, message, extraAttrs) => {
228
- const patched = await patchMessageBeforeSending(message, jids);
229
- const bytes = (0, Utils_1.encodeWAMessage)(patched);
228
+ let patched = await patchMessageBeforeSending(message, jids);
229
+ if (!Array.isArray(patched)) {
230
+ patched = jids ? jids.map(jid => ({ recipientJid: jid, ...patched })) : [patched];
231
+ }
230
232
  let shouldIncludeDeviceIdentity = false;
231
- const nodes = await Promise.all(jids.map(async (jid) => {
233
+ const nodes = await Promise.all(patched.map(async (patchedMessageWithJid) => {
234
+ const { recipientJid: jid, ...patchedMessage } = patchedMessageWithJid;
235
+ if (!jid) {
236
+ return {};
237
+ }
238
+ const bytes = (0, Utils_1.encodeWAMessage)(patchedMessage);
232
239
  const { type, ciphertext } = await signalRepository
233
240
  .encryptMessage({ jid, data: bytes });
234
241
  if (type === 'pkmsg') {
@@ -258,13 +265,14 @@ const makeMessagesSocket = (config) => {
258
265
  const { user, server } = (0, WABinary_1.jidDecode)(jid);
259
266
  const statusJid = 'status@broadcast';
260
267
  const isGroup = server === 'g.us';
268
+ const isNewsletter = server === 'newsletter';
261
269
  const isStatus = jid === statusJid;
262
270
  const isLid = server === 'lid';
263
271
  msgId = msgId || (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id);
264
272
  useUserDevicesCache = useUserDevicesCache !== false;
265
273
  useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus;
266
274
  const participants = [];
267
- const destinationJid = (!isStatus) ? (0, WABinary_1.jidEncode)(user, isLid ? 'lid' : isGroup ? 'g.us' : 's.whatsapp.net') : statusJid;
275
+ const destinationJid = (!isStatus) ? (0, WABinary_1.jidEncode)(user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net') : statusJid;
268
276
  const binaryNodeContent = [];
269
277
  const devices = [];
270
278
  const meMsg = {
@@ -285,7 +293,7 @@ const makeMessagesSocket = (config) => {
285
293
  devices.push({ user, device });
286
294
  }
287
295
  await authState.keys.transaction(async () => {
288
- var _a, _b, _c, _d, _e;
296
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
289
297
  const mediaType = getMediaType(message);
290
298
  if (mediaType) {
291
299
  extraAttrs['mediatype'] = mediaType;
@@ -318,10 +326,20 @@ const makeMessagesSocket = (config) => {
318
326
  if (isStatus && statusJidList) {
319
327
  participantsList.push(...statusJidList);
320
328
  }
329
+ if (!isStatus) {
330
+ additionalAttributes = {
331
+ ...additionalAttributes,
332
+ // eslint-disable-next-line camelcase
333
+ addressing_mode: (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) || 'pn'
334
+ };
335
+ }
321
336
  const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false);
322
337
  devices.push(...additionalDevices);
323
338
  }
324
- const patched = await patchMessageBeforeSending(message, devices.map(d => (0, WABinary_1.jidEncode)(d.user, isLid ? 'lid' : 's.whatsapp.net', d.device)));
339
+ const patched = await patchMessageBeforeSending(message);
340
+ if (Array.isArray(patched)) {
341
+ throw new boom_1.Boom('Per-jid patching is not supported in groups');
342
+ }
325
343
  const bytes = (0, Utils_1.encodeWAMessage)(patched);
326
344
  const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
327
345
  group: destinationJid,
@@ -331,7 +349,7 @@ const makeMessagesSocket = (config) => {
331
349
  const senderKeyJids = [];
332
350
  // ensure a connection is established with every device
333
351
  for (const { user, device } of devices) {
334
- const jid = (0, WABinary_1.jidEncode)(user, isLid ? 'lid' : 's.whatsapp.net', device);
352
+ const jid = (0, WABinary_1.jidEncode)(user, (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) === 'lid' ? 'lid' : 's.whatsapp.net', device);
335
353
  if (!senderKeyMap[jid] || !!participant) {
336
354
  senderKeyJids.push(jid);
337
355
  // store that this person has had the sender keys sent to them
@@ -360,6 +378,28 @@ const makeMessagesSocket = (config) => {
360
378
  });
361
379
  await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
362
380
  }
381
+ else if (isNewsletter) {
382
+ // Message edit
383
+ if ((_b = message.protocolMessage) === null || _b === void 0 ? void 0 : _b.editedMessage) {
384
+ msgId = (_c = message.protocolMessage.key) === null || _c === void 0 ? void 0 : _c.id;
385
+ message = message.protocolMessage.editedMessage;
386
+ }
387
+ // Message delete
388
+ if (((_d = message.protocolMessage) === null || _d === void 0 ? void 0 : _d.type) === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
389
+ msgId = (_e = message.protocolMessage.key) === null || _e === void 0 ? void 0 : _e.id;
390
+ message = {};
391
+ }
392
+ const patched = await patchMessageBeforeSending(message, []);
393
+ if (Array.isArray(patched)) {
394
+ throw new boom_1.Boom('Per-jid patching is not supported in channel');
395
+ }
396
+ const bytes = (0, Utils_1.encodeNewsletterMessage)(patched);
397
+ binaryNodeContent.push({
398
+ tag: 'plaintext',
399
+ attrs: mediaType ? { mediatype: mediaType } : {},
400
+ content: bytes
401
+ });
402
+ }
363
403
  else {
364
404
  const { user: meUser } = (0, WABinary_1.jidDecode)(meId);
365
405
  if (!participant) {
@@ -377,7 +417,7 @@ const makeMessagesSocket = (config) => {
377
417
  const otherJids = [];
378
418
  for (const { user, device } of devices) {
379
419
  const isMe = user === meUser;
380
- const jid = (0, WABinary_1.jidEncode)(isMe && isLid ? ((_c = (_b = authState.creds) === null || _b === void 0 ? void 0 : _b.me) === null || _c === void 0 ? void 0 : _c.lid.split(':')[0]) || user : user, isLid ? 'lid' : 's.whatsapp.net', device);
420
+ const jid = (0, WABinary_1.jidEncode)(isMe && isLid ? ((_g = (_f = authState.creds) === null || _f === void 0 ? void 0 : _f.me) === null || _g === void 0 ? void 0 : _g.lid.split(':')[0]) || user : user, isLid ? 'lid' : 's.whatsapp.net', device);
381
421
  if (isMe) {
382
422
  meJids.push(jid);
383
423
  }
@@ -397,7 +437,7 @@ const makeMessagesSocket = (config) => {
397
437
  }
398
438
  if (participants.length) {
399
439
  if ((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) === 'peer') {
400
- const peerNode = (_e = (_d = participants[0]) === null || _d === void 0 ? void 0 : _d.content) === null || _e === void 0 ? void 0 : _e[0];
440
+ const peerNode = (_j = (_h = participants[0]) === null || _h === void 0 ? void 0 : _h.content) === null || _j === void 0 ? void 0 : _j[0];
401
441
  if (peerNode) {
402
442
  binaryNodeContent.push(peerNode); // push only enc
403
443
  }
@@ -414,7 +454,7 @@ const makeMessagesSocket = (config) => {
414
454
  tag: 'message',
415
455
  attrs: {
416
456
  id: msgId,
417
- type: getMessageType(message),
457
+ type: isNewsletter ? getTypeMessage(message) : getMessageType(message),
418
458
  ...(additionalAttributes || {})
419
459
  },
420
460
  content: binaryNodeContent
@@ -446,20 +486,82 @@ const makeMessagesSocket = (config) => {
446
486
  });
447
487
  logger.debug({ jid }, 'adding device identity');
448
488
  }
489
+ const buttonType = getButtonType(message);
490
+ if (buttonType) {
491
+ stanza.content.push({
492
+ tag: 'biz',
493
+ attrs: {},
494
+ content: [
495
+ {
496
+ tag: buttonType,
497
+ attrs: getButtonArgs(message),
498
+ }
499
+ ]
500
+ });
501
+ logger.debug({ jid }, 'adding business node');
502
+ }
449
503
  if (additionalNodes && additionalNodes.length > 0) {
450
504
  stanza.content.push(...additionalNodes);
451
505
  }
506
+ else {
507
+ if (((0, WABinary_1.isJidGroup)(jid) || (0, WABinary_1.isJidUser)(jid)) && (((_l = (_k = message === null || message === void 0 ? void 0 : message.viewOnceMessage) === null || _k === void 0 ? void 0 : _k.message) === null || _l === void 0 ? void 0 : _l.interactiveMessage) || ((_o = (_m = message === null || message === void 0 ? void 0 : message.viewOnceMessageV2) === null || _m === void 0 ? void 0 : _m.message) === null || _o === void 0 ? void 0 : _o.interactiveMessage) || ((_q = (_p = message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension) === null || _p === void 0 ? void 0 : _p.message) === null || _q === void 0 ? void 0 : _q.interactiveMessage) || (message === null || message === void 0 ? void 0 : message.interactiveMessage)) || (((_s = (_r = message === null || message === void 0 ? void 0 : message.viewOnceMessage) === null || _r === void 0 ? void 0 : _r.message) === null || _s === void 0 ? void 0 : _s.buttonsMessage) || ((_u = (_t = message === null || message === void 0 ? void 0 : message.viewOnceMessageV2) === null || _t === void 0 ? void 0 : _t.message) === null || _u === void 0 ? void 0 : _u.buttonsMessage) || ((_w = (_v = message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension) === null || _v === void 0 ? void 0 : _v.message) === null || _w === void 0 ? void 0 : _w.buttonsMessage) || (message === null || message === void 0 ? void 0 : message.buttonsMessage))) {
508
+ stanza.content.push({
509
+ tag: 'biz',
510
+ attrs: {},
511
+ content: [{
512
+ tag: 'interactive',
513
+ attrs: {
514
+ type: 'native_flow',
515
+ v: '1'
516
+ },
517
+ content: [{
518
+ tag: 'native_flow',
519
+ attrs: { name: 'quick_reply' }
520
+ }]
521
+ }]
522
+ });
523
+ }
524
+ }
452
525
  logger.debug({ msgId }, `sending message to ${participants.length} devices`);
453
526
  await sendNode(stanza);
454
527
  });
455
528
  return msgId;
456
529
  };
457
530
  const getMessageType = (message) => {
458
- if (message.pollCreationMessage || message.pollCreationMessageV2 || message.pollCreationMessageV3) {
531
+ if (message.pollCreationMessage || message.pollCreationMessageV2 || message.pollCreationMessageV3 || message.pollUpdateMessage) {
459
532
  return 'poll';
460
533
  }
461
534
  return 'text';
462
535
  };
536
+ const getTypeMessage = (msg) => {
537
+ if (msg.viewOnceMessage) {
538
+ return getTypeMessage(msg.viewOnceMessage.message);
539
+ }
540
+ else if (msg.viewOnceMessageV2) {
541
+ return getTypeMessage(msg.viewOnceMessageV2.message);
542
+ }
543
+ else if (msg.viewOnceMessageV2Extension) {
544
+ return getTypeMessage(msg.viewOnceMessageV2Extension.message);
545
+ }
546
+ else if (msg.ephemeralMessage) {
547
+ return getTypeMessage(msg.ephemeralMessage.message);
548
+ }
549
+ else if (msg.documentWithCaptionMessage) {
550
+ return getTypeMessage(msg.documentWithCaptionMessage.message);
551
+ }
552
+ else if (msg.reactionMessage) {
553
+ return 'reaction';
554
+ }
555
+ else if (msg.pollCreationMessage || msg.pollCreationMessageV2 || msg.pollCreationMessageV3 || msg.pollUpdateMessage) {
556
+ return 'poll';
557
+ }
558
+ else if (getMediaType(msg)) {
559
+ return 'media';
560
+ }
561
+ else {
562
+ return 'text';
563
+ }
564
+ };
463
565
  const getMediaType = (message) => {
464
566
  if (message.imageMessage) {
465
567
  return 'image';
@@ -507,6 +609,39 @@ const makeMessagesSocket = (config) => {
507
609
  return 'url';
508
610
  }
509
611
  };
612
+ const getButtonType = (message) => {
613
+ if (message.buttonsMessage) {
614
+ return 'buttons';
615
+ }
616
+ else if (message.buttonsResponseMessage) {
617
+ return 'buttons_response';
618
+ }
619
+ else if (message.interactiveResponseMessage) {
620
+ return 'interactive_response';
621
+ }
622
+ else if (message.listMessage) {
623
+ return 'list';
624
+ }
625
+ else if (message.listResponseMessage) {
626
+ return 'list_response';
627
+ }
628
+ };
629
+ const getButtonArgs = (message) => {
630
+ if (message.templateMessage) {
631
+ // TODO: Add attributes
632
+ return {};
633
+ }
634
+ else if (message.listMessage) {
635
+ const type = message.listMessage.listType;
636
+ if (!type) {
637
+ throw new boom_1.Boom('Expected list type inside message');
638
+ }
639
+ return { v: '2', type: ListType[type].toLowerCase() };
640
+ }
641
+ else {
642
+ return {};
643
+ }
644
+ };
510
645
  const getPrivacyTokens = async (jids) => {
511
646
  const t = (0, Utils_1.unixTimestampSeconds)().toString();
512
647
  const result = await query({
@@ -542,13 +677,14 @@ const makeMessagesSocket = (config) => {
542
677
  relayMessage,
543
678
  sendReceipt,
544
679
  sendReceipts,
680
+ getButtonArgs,
545
681
  readMessages,
546
682
  refreshMediaConn,
547
683
  waUploadToServer,
548
684
  fetchPrivacySettings,
549
- sendPeerDataOperationMessage,
550
- createParticipantNodes,
551
685
  getUSyncDevices,
686
+ createParticipantNodes,
687
+ sendPeerDataOperationMessage,
552
688
  updateMediaMessage: async (message) => {
553
689
  const content = (0, Utils_1.assertMediaContent)(message.message);
554
690
  const mediaKey = content.mediaKey;
@@ -604,6 +740,10 @@ const makeMessagesSocket = (config) => {
604
740
  await groupToggleEphemeral(jid, value);
605
741
  }
606
742
  else {
743
+ if (jid.endsWith('@bot')) {
744
+ jid = (0, WABinary_1.getBotJid)(jid);
745
+ }
746
+ let mediaHandle;
607
747
  const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
608
748
  logger,
609
749
  userJid,
@@ -618,9 +758,12 @@ const makeMessagesSocket = (config) => {
618
758
  ? waUploadToServer
619
759
  : undefined
620
760
  }),
621
- //TODO: CACHE
622
761
  getProfilePicUrl: sock.profilePictureUrl,
623
- upload: waUploadToServer,
762
+ upload: async (readStream, opts) => {
763
+ const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
764
+ mediaHandle = up.handle;
765
+ return up;
766
+ },
624
767
  mediaCache: config.mediaCache,
625
768
  options: config.options,
626
769
  messageId: (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id),
@@ -629,24 +772,33 @@ const makeMessagesSocket = (config) => {
629
772
  const isDeleteMsg = 'delete' in content && !!content.delete;
630
773
  const isEditMsg = 'edit' in content && !!content.edit;
631
774
  const isPinMsg = 'pin' in content && !!content.pin;
775
+ const isKeepMsg = 'keep' in content && content.keep;
632
776
  const isPollMessage = 'poll' in content && !!content.poll;
777
+ const isAiMsg = 'ai' in content && !!content.ai;
633
778
  const additionalAttributes = {};
634
779
  const additionalNodes = [];
635
780
  // required for delete
636
781
  if (isDeleteMsg) {
637
782
  // if the chat is a group, and I am not the author, then delete the message as an admin
638
- if ((0, WABinary_1.isJidGroup)((_b = content.delete) === null || _b === void 0 ? void 0 : _b.remoteJid) && !((_c = content.delete) === null || _c === void 0 ? void 0 : _c.fromMe)) {
783
+ if (((0, WABinary_1.isJidGroup)((_b = content.delete) === null || _b === void 0 ? void 0 : _b.remoteJid) && !((_c = content.delete) === null || _c === void 0 ? void 0 : _c.fromMe)) || (0, WABinary_1.isJidNewsletter)(jid)) {
639
784
  additionalAttributes.edit = '8';
640
785
  }
641
786
  else {
642
787
  additionalAttributes.edit = '7';
643
788
  }
789
+ // required for edit message
644
790
  }
645
791
  else if (isEditMsg) {
646
- additionalAttributes.edit = '1';
792
+ additionalAttributes.edit = (0, WABinary_1.isJidNewsletter)(jid) ? '3' : '1';
793
+ // required for pin message
647
794
  }
648
795
  else if (isPinMsg) {
649
796
  additionalAttributes.edit = '2';
797
+ // required for keep message
798
+ }
799
+ else if (isKeepMsg) {
800
+ additionalAttributes.edit = '6';
801
+ // required for polling message
650
802
  }
651
803
  else if (isPollMessage) {
652
804
  additionalNodes.push({
@@ -655,11 +807,23 @@ const makeMessagesSocket = (config) => {
655
807
  polltype: 'creation'
656
808
  },
657
809
  });
810
+ // required to display AI icon on message
811
+ }
812
+ else if (isAiMsg) {
813
+ additionalNodes.push({
814
+ attrs: {
815
+ biz_bot: '1'
816
+ },
817
+ tag: "bot"
818
+ });
819
+ }
820
+ if (mediaHandle) {
821
+ additionalAttributes['media_id'] = mediaHandle;
658
822
  }
659
823
  if ('cachedGroupMetadata' in options) {
660
824
  console.warn('cachedGroupMetadata in sendMessage are deprecated, now cachedGroupMetadata is part of the socket config.');
661
825
  }
662
- await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, useCachedGroupMetadata: options.useCachedGroupMetadata, additionalAttributes, statusJidList: options.statusJidList, additionalNodes });
826
+ await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, useCachedGroupMetadata: options.useCachedGroupMetadata, additionalAttributes, additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes, statusJidList: options.statusJidList });
663
827
  if (config.emitOwnEvents) {
664
828
  process.nextTick(() => {
665
829
  processingMutex.mutex(() => (upsertMessage(fullMsg, 'append')));
@@ -0,0 +1,140 @@
1
+ import { SocketConfig, WAMediaUpload, NewsletterMetadata, NewsletterReactionMode, NewsletterViewRole, NewsletterFetchedUpdate } from '../Types';
2
+ import { BinaryNode } from '../WABinary';
3
+ export declare const makeNewsletterSocket: (config: SocketConfig) => {
4
+ subscribeNewsletterUpdates: (jid: string) => Promise<{
5
+ duration: string;
6
+ }>;
7
+ newsletterReactionMode: (jid: string, mode: NewsletterReactionMode) => Promise<void>;
8
+ newsletterUpdateDescription: (jid: string, description?: string) => Promise<void>;
9
+ newsletterUpdateName: (jid: string, name: string) => Promise<void>;
10
+ newsletterUpdatePicture: (jid: string, content: WAMediaUpload) => Promise<void>;
11
+ newsletterRemovePicture: (jid: string) => Promise<void>;
12
+ newsletterUnfollow: (jid: string) => Promise<void>;
13
+ newsletterFollow: (jid: string) => Promise<void>;
14
+ newsletterUnmute: (jid: string) => Promise<void>;
15
+ newsletterMute: (jid: string) => Promise<void>;
16
+ newsletterCreate: (name: string, description?: string, picture?: WAMediaUpload) => Promise<NewsletterMetadata>;
17
+ newsletterMetadata: (type: "invite" | "jid", key: string, role?: NewsletterViewRole) => Promise<NewsletterMetadata>;
18
+ newsletterAdminCount: (jid: string) => Promise<number>;
19
+ /**user is Lid, not Jid */
20
+ newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
21
+ /**user is Lid, not Jid */
22
+ newsletterDemote: (jid: string, user: string) => Promise<void>;
23
+ newsletterDelete: (jid: string) => Promise<void>;
24
+ /**if code wasn't passed, the reaction will be removed (if is reacted) */
25
+ newsletterReactMessage: (jid: string, server_id: string, code?: string) => Promise<void>;
26
+ newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number) => Promise<NewsletterFetchedUpdate[]>;
27
+ newsletterFetchUpdates: (jid: string, count: number, after?: number, since?: number) => Promise<NewsletterFetchedUpdate[]>;
28
+ groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
29
+ groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
30
+ groupLeave: (id: string) => Promise<void>;
31
+ groupUpdateSubject: (jid: string, subject: string) => Promise<void>;
32
+ groupRequestParticipantsList: (jid: string) => Promise<{
33
+ [key: string]: string;
34
+ }[]>;
35
+ groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "approve" | "reject") => Promise<{
36
+ status: string;
37
+ jid: string;
38
+ }[]>;
39
+ groupParticipantsUpdate: (jid: string, participants: string[], action: import("../Types").ParticipantAction) => Promise<{
40
+ status: string;
41
+ jid: string;
42
+ content: BinaryNode;
43
+ }[]>;
44
+ groupUpdateDescription: (jid: string, description?: string) => Promise<void>;
45
+ groupInviteCode: (jid: string) => Promise<string | undefined>;
46
+ groupRevokeInvite: (jid: string) => Promise<string | undefined>;
47
+ groupAcceptInvite: (code: string) => Promise<string | undefined>;
48
+ groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
49
+ groupAcceptInviteV4: (key: string | import("../Types").WAMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<any>;
50
+ groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
51
+ groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
52
+ groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
53
+ groupMemberAddMode: (jid: string, mode: "admin_add" | "all_member_add") => Promise<void>;
54
+ groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
55
+ groupFetchAllParticipating: () => Promise<{
56
+ [_: string]: import("../Types").GroupMetadata;
57
+ }>;
58
+ getBotListV2: () => Promise<import("../Types").BotListInfo[]>;
59
+ processingMutex: {
60
+ mutex<T>(code: () => Promise<T> | T): Promise<T>;
61
+ };
62
+ fetchPrivacySettings: (force?: boolean) => Promise<{
63
+ [_: string]: string;
64
+ }>;
65
+ upsertMessage: (msg: import("../Types").WAProto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>;
66
+ appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
67
+ sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string) => Promise<void>;
68
+ presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
69
+ profilePictureUrl: (jid: string, type?: "preview" | "image", timeoutMs?: number) => Promise<string | undefined>;
70
+ onWhatsApp: (...jids: string[]) => Promise<{
71
+ jid: string;
72
+ exists: unknown;
73
+ lid: unknown;
74
+ }[] | undefined>;
75
+ fetchBlocklist: () => Promise<string[]>;
76
+ fetchDisappearingDuration: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
77
+ fetchStatus: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
78
+ updateProfilePicture: (jid: string, content: WAMediaUpload) => Promise<void>;
79
+ updateProfilePictureFull: (jid: string, content: WAMediaUpload) => Promise<void>;
80
+ updateProfilePictureFull2: (jid: string, content: WAMediaUpload) => Promise<void>;
81
+ removeProfilePicture: (jid: string) => Promise<void>;
82
+ updateProfileStatus: (status: string) => Promise<void>;
83
+ updateProfileName: (name: string) => Promise<void>;
84
+ updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
85
+ updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
86
+ updateMessagesPrivacy: (value: import("../Types").WAPrivacyMessagesValue) => Promise<void>;
87
+ updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
88
+ updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
89
+ updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
90
+ updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
91
+ updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
92
+ updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
93
+ updateDefaultDisappearingMode: (duration: number) => Promise<void>;
94
+ getBusinessProfile: (jid: string) => Promise<import("../Types").WABusinessProfile | void>;
95
+ resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
96
+ chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
97
+ cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
98
+ addOrEditContact: (jid: string, contact: import("../Types").ContactAction) => Promise<void>;
99
+ removeContact: (jid: string) => Promise<void>;
100
+ addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
101
+ addChatLabel: (jid: string, labelId: string) => Promise<void>;
102
+ removeChatLabel: (jid: string, labelId: string) => Promise<void>;
103
+ addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
104
+ removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
105
+ star: (jid: string, messages: {
106
+ id: string;
107
+ fromMe?: boolean;
108
+ }[], star: boolean) => Promise<void>;
109
+ executeUSyncQuery: (usyncQuery: import("..").USyncQuery) => Promise<import("..").USyncQueryResult | undefined>;
110
+ type: "md";
111
+ ws: import("./Client").WebSocketClient;
112
+ ev: import("../Types").BaileysEventEmitter & {
113
+ process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
114
+ buffer(): void;
115
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
116
+ flush(force?: boolean): boolean;
117
+ isBuffering(): boolean;
118
+ };
119
+ authState: {
120
+ creds: import("../Types").AuthenticationCreds;
121
+ keys: import("../Types").SignalKeyStoreWithTransaction;
122
+ };
123
+ signalRepository: import("../Types").SignalRepository;
124
+ user: import("../Types").Contact | undefined;
125
+ generateMessageTag: () => string;
126
+ query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
127
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
128
+ waitForSocketOpen: () => Promise<void>;
129
+ sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
130
+ sendNode: (frame: BinaryNode) => Promise<void>;
131
+ logout: (msg?: string) => Promise<void>;
132
+ end: (error: Error | undefined) => void;
133
+ onUnexpectedError: (err: Error | import("@hapi/boom").Boom, msg: string) => void;
134
+ uploadPreKeys: (count?: number) => Promise<void>;
135
+ uploadPreKeysToServerIfRequired: () => Promise<void>;
136
+ requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
137
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
138
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
139
+ };
140
+ export declare const extractNewsletterMetadata: (node: BinaryNode, isCreate?: boolean) => NewsletterMetadata;