angularsockets 1.0.2 → 1.4.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 (156) hide show
  1. package/LICENSE +21 -0
  2. package/README.MD +170 -0
  3. package/README.md +1 -1900
  4. package/WAProto/GenerateStatics.sh +4 -0
  5. package/WAProto/WAProto.proto +4775 -0
  6. package/WAProto/index.d.ts +4798 -124
  7. package/WAProto/index.js +14270 -302
  8. package/WAProto/index.ts.ts +53473 -0
  9. package/engine-requirements.js +10 -0
  10. package/lib/Defaults/baileys-version.json +1 -1
  11. package/lib/Defaults/index.d.ts +4 -6
  12. package/lib/Defaults/index.js +4 -6
  13. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  14. package/lib/Signal/Group/ciphertext-message.js +15 -0
  15. package/lib/Signal/Group/group-session-builder.d.ts +14 -0
  16. package/lib/Signal/Group/group-session-builder.js +64 -0
  17. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  18. package/lib/Signal/Group/group_cipher.js +96 -0
  19. package/lib/Signal/Group/index.d.ts +11 -0
  20. package/lib/Signal/Group/index.js +57 -0
  21. package/lib/Signal/Group/keyhelper.d.ts +10 -0
  22. package/lib/Signal/Group/keyhelper.js +55 -0
  23. package/lib/Signal/Group/queue-job.d.ts +1 -0
  24. package/lib/Signal/Group/queue-job.js +57 -0
  25. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  26. package/lib/Signal/Group/sender-chain-key.js +34 -0
  27. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  28. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  29. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  30. package/lib/Signal/Group/sender-key-message.js +69 -0
  31. package/lib/Signal/Group/sender-key-name.d.ts +17 -0
  32. package/lib/Signal/Group/sender-key-name.js +51 -0
  33. package/lib/Signal/Group/sender-key-record.d.ts +30 -0
  34. package/lib/Signal/Group/sender-key-record.js +53 -0
  35. package/lib/Signal/Group/sender-key-state.d.ts +38 -0
  36. package/lib/Signal/Group/sender-key-state.js +99 -0
  37. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  38. package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +6 -16
  39. package/lib/Signal/libsignal.js +51 -29
  40. package/lib/Socket/Client/index.d.ts +2 -3
  41. package/lib/Socket/Client/index.js +2 -3
  42. package/lib/Socket/Client/{abstract-socket-client.d.ts → types.d.ts} +1 -2
  43. package/lib/Socket/Client/{web-socket-client.d.ts → websocket.d.ts} +2 -1
  44. package/lib/Socket/Client/{web-socket-client.js → websocket.js} +54 -5
  45. package/lib/Socket/RHandler.d.ts +416 -0
  46. package/lib/Socket/RHandler.js +530 -0
  47. package/lib/Socket/business.d.ts +39 -37
  48. package/lib/Socket/chats.d.ts +36 -23
  49. package/lib/Socket/chats.js +74 -116
  50. package/lib/Socket/groups.d.ts +42 -33
  51. package/lib/Socket/groups.js +26 -9
  52. package/lib/Socket/index.d.ts +39 -39
  53. package/lib/Socket/index.js +2 -2
  54. package/lib/Socket/messages-recv.d.ts +37 -34
  55. package/lib/Socket/messages-recv.js +111 -29
  56. package/lib/Socket/messages-send.d.ts +50 -53
  57. package/lib/Socket/messages-send.js +213 -397
  58. package/lib/Socket/newsletter.d.ts +25 -21
  59. package/lib/Socket/newsletter.js +92 -25
  60. package/lib/Socket/socket.d.ts +10 -11
  61. package/lib/Socket/socket.js +34 -23
  62. package/lib/Socket/usync.d.ts +11 -12
  63. package/lib/Store/index.d.ts +1 -2
  64. package/lib/Store/index.js +1 -3
  65. package/lib/Store/make-in-memory-store.d.ts +22 -22
  66. package/lib/Store/make-in-memory-store.js +21 -13
  67. package/lib/Store/make-ordered-dictionary.d.ts +1 -1
  68. package/lib/Types/Auth.d.ts +0 -6
  69. package/lib/Types/Chat.d.ts +6 -4
  70. package/lib/Types/Contact.d.ts +5 -1
  71. package/lib/Types/Events.d.ts +27 -0
  72. package/lib/Types/GroupMetadata.d.ts +8 -0
  73. package/lib/Types/Label.d.ts +0 -11
  74. package/lib/Types/Message.d.ts +59 -90
  75. package/lib/Types/Message.js +0 -2
  76. package/lib/Types/Newsletter.d.ts +97 -86
  77. package/lib/Types/Newsletter.js +38 -32
  78. package/lib/Types/Socket.d.ts +10 -7
  79. package/lib/Types/index.d.ts +1 -3
  80. package/lib/Types/index.js +1 -1
  81. package/lib/Utils/audioToBuffer.js +29 -0
  82. package/lib/Utils/auth-utils.d.ts +3 -3
  83. package/lib/Utils/auth-utils.js +13 -41
  84. package/lib/Utils/business.d.ts +1 -1
  85. package/lib/Utils/chat-utils.d.ts +12 -12
  86. package/lib/Utils/chat-utils.js +4 -19
  87. package/lib/Utils/crypto.d.ts +15 -15
  88. package/lib/Utils/crypto.js +6 -12
  89. package/lib/Utils/decode-wa-message.d.ts +5 -6
  90. package/lib/Utils/decode-wa-message.js +28 -55
  91. package/lib/Utils/event-buffer.d.ts +2 -2
  92. package/lib/Utils/event-buffer.js +2 -1
  93. package/lib/Utils/generics.d.ts +12 -11
  94. package/lib/Utils/generics.js +64 -38
  95. package/lib/Utils/history.d.ts +2 -2
  96. package/lib/Utils/history.js +1 -1
  97. package/lib/Utils/index.d.ts +2 -0
  98. package/lib/Utils/index.js +3 -0
  99. package/lib/Utils/link-preview.d.ts +2 -2
  100. package/lib/Utils/link-preview.js +34 -1
  101. package/lib/Utils/logger.d.ts +10 -1
  102. package/lib/Utils/lt-hash.d.ts +2 -2
  103. package/lib/Utils/lt-hash.js +6 -6
  104. package/lib/Utils/messages-media.d.ts +40 -29
  105. package/lib/Utils/messages-media.js +276 -110
  106. package/lib/Utils/messages.d.ts +8 -10
  107. package/lib/Utils/messages.js +126 -317
  108. package/lib/Utils/noise-handler.d.ts +10 -11
  109. package/lib/Utils/noise-handler.js +3 -13
  110. package/lib/Utils/process-message.d.ts +3 -2
  111. package/lib/Utils/process-message.js +17 -5
  112. package/lib/Utils/signal.js +2 -8
  113. package/lib/Utils/streamToBuffer.js +15 -0
  114. package/lib/Utils/use-multi-file-auth-state.js +72 -242
  115. package/lib/Utils/validate-connection.d.ts +2 -3
  116. package/lib/Utils/validate-connection.js +19 -51
  117. package/lib/WABinary/constants.d.ts +4 -4
  118. package/lib/WABinary/constants.js +1276 -13
  119. package/lib/WABinary/decode.d.ts +2 -2
  120. package/lib/WABinary/decode.js +3 -2
  121. package/lib/WABinary/encode.js +5 -7
  122. package/lib/WABinary/generic-utils.d.ts +2 -2
  123. package/lib/WABinary/jid-utils.d.ts +9 -4
  124. package/lib/WABinary/jid-utils.js +26 -5
  125. package/lib/WABinary/jid-utils.js.bak +83 -0
  126. package/lib/WAM/encode.d.ts +1 -1
  127. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
  128. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -3
  129. package/lib/WAUSync/USyncUser.d.ts +2 -0
  130. package/lib/index.d.ts +16 -0
  131. package/lib/index.js +48 -4
  132. package/lib/index.js.bak +56 -0
  133. package/package.json +43 -35
  134. package/WASignalGroup/GroupProtocol.js +0 -1697
  135. package/WASignalGroup/ciphertext_message.js +0 -16
  136. package/WASignalGroup/group_cipher.js +0 -120
  137. package/WASignalGroup/group_session_builder.js +0 -46
  138. package/WASignalGroup/index.js +0 -5
  139. package/WASignalGroup/keyhelper.js +0 -21
  140. package/WASignalGroup/protobufs.js +0 -3
  141. package/WASignalGroup/queue_job.js +0 -69
  142. package/WASignalGroup/sender_chain_key.js +0 -50
  143. package/WASignalGroup/sender_key_distribution_message.js +0 -78
  144. package/WASignalGroup/sender_key_message.js +0 -92
  145. package/WASignalGroup/sender_key_name.js +0 -70
  146. package/WASignalGroup/sender_key_record.js +0 -56
  147. package/WASignalGroup/sender_key_state.js +0 -129
  148. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
  149. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  150. package/lib/Socket/registration.d.ts +0 -264
  151. package/lib/Socket/registration.js +0 -166
  152. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  153. package/lib/Store/make-cache-manager-store.js +0 -83
  154. package/lib/Utils/use-single-file-auth-state.d.ts +0 -12
  155. package/lib/Utils/use-single-file-auth-state.js +0 -75
  156. /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.makeChatsSocket = void 0;
7
- const node_cache_1 = __importDefault(require("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 Types_1 = require("../Types");
@@ -19,7 +19,7 @@ const MAX_SYNC_ATTEMPTS = 2;
19
19
  const makeChatsSocket = (config) => {
20
20
  const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage, } = config;
21
21
  const sock = (0, usync_1.makeUSyncSocket)(config);
22
- const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError } = sock;
22
+ const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError, } = sock;
23
23
  let privacySettings;
24
24
  let needToFlushWithAppStateSync = false;
25
25
  let pendingAppStateSync = false;
@@ -144,60 +144,6 @@ const makeChatsSocket = (config) => {
144
144
  }
145
145
  return botList;
146
146
  };
147
- /** helper function to run a generic IQ query */
148
- const interactiveQuery = async (userNodes, queryNode) => {
149
- const result = await query({
150
- tag: 'iq',
151
- attrs: {
152
- to: WABinary_1.S_WHATSAPP_NET,
153
- type: 'get',
154
- xmlns: 'usync',
155
- },
156
- content: [
157
- {
158
- tag: 'usync',
159
- attrs: {
160
- sid: generateMessageTag(),
161
- mode: 'query',
162
- last: 'true',
163
- index: '0',
164
- context: 'interactive',
165
- },
166
- content: [
167
- {
168
- tag: 'query',
169
- attrs: {},
170
- content: [queryNode]
171
- },
172
- {
173
- tag: 'list',
174
- attrs: {},
175
- content: userNodes
176
- }
177
- ]
178
- }
179
- ],
180
- });
181
- const usyncNode = (0, WABinary_1.getBinaryNodeChild)(result, 'usync');
182
- const listNode = (0, WABinary_1.getBinaryNodeChild)(usyncNode, 'list');
183
- const users = (0, WABinary_1.getBinaryNodeChildren)(listNode, 'user');
184
- return users;
185
- };
186
- const fetchUserLid = async (jid) => {
187
- const [result] = await interactiveQuery([
188
- {
189
- tag: 'user',
190
- attrs: { jid }
191
- }
192
- ], {
193
- tag: 'lid',
194
- attrs: {}
195
- });
196
- if (result) {
197
- const lid = (0, WABinary_1.getBinaryNodeChild)(result, 'lid');
198
- return lid.attrs.val;
199
- }
200
- };
201
147
  const onWhatsApp = async (...jids) => {
202
148
  const usyncQuery = new WAUSync_1.USyncQuery()
203
149
  .withContactProtocol()
@@ -222,6 +168,42 @@ const makeChatsSocket = (config) => {
222
168
  return result.list;
223
169
  }
224
170
  };
171
+ const checkStatusWA = async (numberOrJid) => {
172
+ try {
173
+ const jid = numberOrJid.includes('@s.whatsapp.net')
174
+ ? numberOrJid
175
+ : numberOrJid.replace(/[^0-9]/g, '') + '@s.whatsapp.net'
176
+
177
+ const exists = await onWhatsApp(jid)
178
+ if (!exists || !exists[0]?.exists) {
179
+ return {
180
+ jid,
181
+ IsBanned: true,
182
+ Statusbio: null,
183
+ setAt: null
184
+ }
185
+ }
186
+
187
+ const fetched = await fetchStatus(jid).catch(() => [])
188
+ const status = fetched?.[0]?.status?.status || null
189
+ const setAt = fetched?.[0]?.status?.setAt || null
190
+
191
+ return {
192
+ jid,
193
+ IsBanned: false,
194
+ Statusbio: status,
195
+ setAt
196
+ }
197
+ } catch (e) {
198
+ return {
199
+ jid: numberOrJid,
200
+ IsBanned: true,
201
+ Statusbio: null,
202
+ setAt: null,
203
+ error: e.message
204
+ }
205
+ }
206
+ }
225
207
  const fetchDisappearingDuration = async (...jids) => {
226
208
  const usyncQuery = new WAUSync_1.USyncQuery()
227
209
  .withDisappearingModeProtocol();
@@ -359,9 +341,9 @@ const makeChatsSocket = (config) => {
359
341
  const email = (0, WABinary_1.getBinaryNodeChild)(profiles, 'email');
360
342
  const category = (0, WABinary_1.getBinaryNodeChild)((0, WABinary_1.getBinaryNodeChild)(profiles, 'categories'), 'category');
361
343
  const businessHours = (0, WABinary_1.getBinaryNodeChild)(profiles, 'business_hours');
362
- const businessHoursConfig = businessHours ?
363
- (0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config') :
364
- undefined;
344
+ const businessHoursConfig = businessHours
345
+ ? (0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config')
346
+ : undefined;
365
347
  const websiteStr = (_a = website === null || website === void 0 ? void 0 : website.content) === null || _a === void 0 ? void 0 : _a.toString();
366
348
  return {
367
349
  wid: (_b = profiles.attrs) === null || _b === void 0 ? void 0 : _b.jid,
@@ -470,16 +452,12 @@ const makeChatsSocket = (config) => {
470
452
  states[name] = newState;
471
453
  Object.assign(globalMutationMap, mutationMap);
472
454
  logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
473
- await authState.keys.set({ 'app-state-sync-version': {
474
- [name]: newState
475
- } });
455
+ await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
476
456
  }
477
457
  // only process if there are syncd patches
478
458
  if (patches.length) {
479
459
  const { state: newState, mutationMap } = await (0, Utils_1.decodePatches)(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
480
- await authState.keys.set({ 'app-state-sync-version': {
481
- [name]: newState
482
- } });
460
+ await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
483
461
  logger.info(`synced ${name} to v${newState.version}`);
484
462
  initialVersionMap[name] = newState.version;
485
463
  Object.assign(globalMutationMap, mutationMap);
@@ -494,13 +472,11 @@ const makeChatsSocket = (config) => {
494
472
  catch (error) {
495
473
  // if retry attempts overshoot
496
474
  // or key not found
497
- const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS ||
498
- ((_a = error.output) === null || _a === void 0 ? void 0 : _a.statusCode) === 404 ||
499
- error.name === 'TypeError';
475
+ const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS
476
+ || ((_a = error.output) === null || _a === void 0 ? void 0 : _a.statusCode) === 404
477
+ || error.name === 'TypeError';
500
478
  logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
501
- await authState.keys.set({ 'app-state-sync-version': {
502
- [name]: null
503
- } });
479
+ await authState.keys.set({ 'app-state-sync-version': { [name]: null } });
504
480
  // increment number of retries
505
481
  attemptsMap[name] = (attemptsMap[name] || 0) + 1;
506
482
  if (isIrrecoverableError) {
@@ -520,7 +496,7 @@ const makeChatsSocket = (config) => {
520
496
  * fetch the profile picture of a user/group
521
497
  * type = "preview" for a low res picture
522
498
  * type = "image for the high res picture"
523
- */;
499
+ */
524
500
  const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
525
501
  var _a;
526
502
  jid = (0, WABinary_1.jidNormalizedUser)(jid);
@@ -550,16 +526,18 @@ const makeChatsSocket = (config) => {
550
526
  await sendNode({
551
527
  tag: 'presence',
552
528
  attrs: {
553
- name: me.name,
529
+ name: me.name.replace(/@/g, ''),
554
530
  type
555
531
  }
556
532
  });
557
533
  }
558
534
  else {
535
+ const { server } = (0, WABinary_1.jidDecode)(toJid);
536
+ const isLid = server === 'lid';
559
537
  await sendNode({
560
538
  tag: 'chatstate',
561
539
  attrs: {
562
- from: me.id,
540
+ from: isLid ? me.lid : me.id,
563
541
  to: toJid,
564
542
  },
565
543
  content: [
@@ -582,22 +560,22 @@ const makeChatsSocket = (config) => {
582
560
  id: generateMessageTag(),
583
561
  type: 'subscribe'
584
562
  },
585
- content: tcToken ?
586
- [
563
+ content: tcToken
564
+ ? [
587
565
  {
588
566
  tag: 'tctoken',
589
567
  attrs: {},
590
568
  content: tcToken
591
569
  }
592
- ] :
593
- undefined
570
+ ]
571
+ : undefined
594
572
  }));
595
573
  const handlePresenceUpdate = ({ tag, attrs, content }) => {
596
574
  var _a;
597
575
  let presence;
598
576
  const jid = attrs.from;
599
577
  const participant = attrs.participant || attrs.from;
600
- if (shouldIgnoreJid(jid) && jid !== '@s.whatsapp.net') {
578
+ if (shouldIgnoreJid(jid) && jid != '@s.whatsapp.net') {
601
579
  return;
602
580
  }
603
581
  if (tag === 'presence') {
@@ -621,9 +599,7 @@ const makeChatsSocket = (config) => {
621
599
  logger.error({ tag, attrs, content }, 'recv invalid presence node');
622
600
  }
623
601
  if (presence) {
624
- ev.emit('presence.update', { id: jid, presences: {
625
- [participant]: presence
626
- } });
602
+ ev.emit('presence.update', { id: jid, presences: { [participant]: presence } });
627
603
  }
628
604
  };
629
605
  const appPatch = async (patchCreate) => {
@@ -674,9 +650,7 @@ const makeChatsSocket = (config) => {
674
650
  ]
675
651
  };
676
652
  await query(node);
677
- await authState.keys.set({ 'app-state-sync-version': {
678
- [name]: state
679
- } });
653
+ await authState.keys.set({ 'app-state-sync-version': { [name]: state } });
680
654
  });
681
655
  });
682
656
  if (config.emitOwnEvents) {
@@ -689,7 +663,7 @@ const makeChatsSocket = (config) => {
689
663
  };
690
664
  /** sending non-abt props may fix QR scan fail if server expects */
691
665
  const fetchProps = async () => {
692
- var _a, _b;
666
+ var _a, _b, _c;
693
667
  const resultNode = await query({
694
668
  tag: 'iq',
695
669
  attrs: {
@@ -698,13 +672,10 @@ const makeChatsSocket = (config) => {
698
672
  type: 'get',
699
673
  },
700
674
  content: [
701
- {
702
- tag: 'props',
703
- attrs: {
675
+ { tag: 'props', attrs: {
704
676
  protocol: '2',
705
677
  hash: ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.lastPropHash) || ''
706
- }
707
- }
678
+ } }
708
679
  ]
709
680
  });
710
681
  const propsNode = (0, WABinary_1.getBinaryNodeChild)(resultNode, 'props');
@@ -723,7 +694,7 @@ const makeChatsSocket = (config) => {
723
694
  * modify a chat -- mark unread, read etc.
724
695
  * lastMessages must be sorted in reverse chronologically
725
696
  * requires the last messages till the last message received; required for archive & unread
726
- */
697
+ */
727
698
  const chatModify = (mod, jid) => {
728
699
  const patch = (0, Utils_1.chatModificationToAppPatch)(mod, jid);
729
700
  return appPatch(patch);
@@ -739,16 +710,6 @@ const makeChatsSocket = (config) => {
739
710
  }
740
711
  }, jid);
741
712
  };
742
- /**
743
- * Adds label
744
- */
745
- const addLabel = (jid, labels) => {
746
- return chatModify({
747
- addLabel: {
748
- ...labels
749
- }
750
- }, jid);
751
- };
752
713
  /**
753
714
  * Adds label for the chats
754
715
  */
@@ -817,18 +778,18 @@ const makeChatsSocket = (config) => {
817
778
  }
818
779
  }
819
780
  const historyMsg = (0, Utils_1.getHistoryMsg)(msg.message);
820
- const shouldProcessHistoryMsg = historyMsg ?
821
- (shouldSyncHistoryMessage(historyMsg) &&
822
- Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType)) :
823
- false;
781
+ const shouldProcessHistoryMsg = historyMsg
782
+ ? (shouldSyncHistoryMessage(historyMsg)
783
+ && Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType))
784
+ : false;
824
785
  if (historyMsg && !authState.creds.myAppStateKeyId) {
825
786
  logger.warn('skipping app state sync, as myAppStateKeyId is not set');
826
787
  pendingAppStateSync = true;
827
788
  }
828
789
  await Promise.all([
829
790
  (async () => {
830
- if (historyMsg &&
831
- authState.creds.myAppStateKeyId) {
791
+ if (historyMsg
792
+ && authState.creds.myAppStateKeyId) {
832
793
  pendingAppStateSync = false;
833
794
  await doAppStateSync();
834
795
  }
@@ -844,8 +805,8 @@ const makeChatsSocket = (config) => {
844
805
  getMessage: config.getMessage,
845
806
  })
846
807
  ]);
847
- if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare) &&
848
- pendingAppStateSync) {
808
+ if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare)
809
+ && pendingAppStateSync) {
849
810
  await doAppStateSync();
850
811
  pendingAppStateSync = false;
851
812
  }
@@ -899,7 +860,6 @@ const makeChatsSocket = (config) => {
899
860
  if (receivedPendingNotifications && // if we don't have the app state key
900
861
  // we keep buffering events until we finally have
901
862
  // the key and can sync the messages
902
- // todo scrutinize
903
863
  !((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId)) {
904
864
  ev.buffer();
905
865
  needToFlushWithAppStateSync = true;
@@ -907,20 +867,18 @@ const makeChatsSocket = (config) => {
907
867
  });
908
868
  return {
909
869
  ...sock,
910
- interactiveQuery,
911
870
  getBotListV2,
912
871
  processingMutex,
913
872
  fetchPrivacySettings,
914
873
  upsertMessage,
915
874
  appPatch,
916
- fetchUserLid,
917
875
  sendPresenceUpdate,
918
876
  presenceSubscribe,
919
877
  profilePictureUrl,
920
878
  onWhatsApp,
921
879
  fetchBlocklist,
922
- fetchStatus,
923
880
  fetchDisappearingDuration,
881
+ fetchStatus,
924
882
  updateProfilePicture,
925
883
  removeProfilePicture,
926
884
  updateProfileStatus,
@@ -939,12 +897,12 @@ const makeChatsSocket = (config) => {
939
897
  resyncAppState,
940
898
  chatModify,
941
899
  cleanDirtyBits,
942
- addLabel,
943
900
  addChatLabel,
944
901
  removeChatLabel,
945
902
  addMessageLabel,
946
903
  removeMessageLabel,
947
- star
904
+ star,
905
+ checkStatusWA
948
906
  };
949
907
  };
950
908
  exports.makeChatsSocket = makeChatsSocket;
@@ -1,9 +1,8 @@
1
- /// <reference types="node" />
2
1
  import { proto } from '../../WAProto';
3
- import { GroupMetadata, ParticipantAction, SocketConfig } from '../Types';
2
+ import { GroupMetadata, ParticipantAction, SocketConfig, WAMessageKey } from '../Types';
4
3
  import { BinaryNode } from '../WABinary';
5
4
  export declare const makeGroupsSocket: (config: SocketConfig) => {
6
- groupQuery: (jid: string, type: 'get' | 'set', content: BinaryNode[]) => Promise<BinaryNode>;
5
+ groupQuery: (jid: string, type: "get" | "set", content: BinaryNode[]) => Promise<any>;
7
6
  groupMetadata: (jid: string) => Promise<GroupMetadata>;
8
7
  groupCreate: (subject: string, participants: string[]) => Promise<GroupMetadata>;
9
8
  groupLeave: (id: string) => Promise<void>;
@@ -11,7 +10,7 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
11
10
  groupRequestParticipantsList: (jid: string) => Promise<{
12
11
  [key: string]: string;
13
12
  }[]>;
14
- groupRequestParticipantsUpdate: (jid: string, participants: string[], action: 'approve' | 'reject') => Promise<{
13
+ groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "approve" | "reject") => Promise<{
15
14
  status: string;
16
15
  jid: string;
17
16
  }[]>;
@@ -24,71 +23,81 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
24
23
  groupInviteCode: (jid: string) => Promise<string | undefined>;
25
24
  groupRevokeInvite: (jid: string) => Promise<string | undefined>;
26
25
  groupAcceptInvite: (code: string) => Promise<string | undefined>;
26
+ /**
27
+ * revoke a v4 invite for someone
28
+ * @param groupJid group jid
29
+ * @param invitedJid jid of person you invited
30
+ * @returns true if successful
31
+ */
32
+ groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
27
33
  /**
28
34
  * accept a GroupInviteMessage
29
35
  * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
30
36
  * @param inviteMessage the message to accept
31
37
  */
32
- groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<string>;
38
+ groupAcceptInviteV4: (key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<any>;
33
39
  groupGetInviteInfo: (code: string) => Promise<GroupMetadata>;
34
40
  groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
35
- groupSettingUpdate: (jid: string, setting: 'announcement' | 'not_announcement' | 'locked' | 'unlocked') => Promise<void>;
36
- groupMemberAddMode: (jid: string, mode: 'admin_add' | 'all_member_add') => Promise<void>;
37
- groupJoinApprovalMode: (jid: string, mode: 'on' | 'off') => Promise<void>;
41
+ groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
42
+ groupMemberAddMode: (jid: string, mode: "admin_add" | "all_member_add") => Promise<void>;
43
+ groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
38
44
  groupFetchAllParticipating: () => Promise<{
39
45
  [_: string]: GroupMetadata;
40
46
  }>;
41
- interactiveQuery: (userNodes: BinaryNode[], queryNode: BinaryNode) => Promise<BinaryNode[]>;
47
+ getBotListV2: () => Promise<import("../Types").BotListInfo[]>;
42
48
  processingMutex: {
43
- mutex<T>(code: () => T | Promise<T>): Promise<T>;
49
+ mutex<T>(code: () => Promise<T> | T): Promise<T>;
44
50
  };
45
51
  fetchPrivacySettings: (force?: boolean) => Promise<{
46
52
  [_: string]: string;
47
53
  }>;
48
- upsertMessage: (msg: proto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>;
54
+ upsertMessage: (msg: import("../Types").WAMessage, type: import("../Types").MessageUpsertType) => Promise<void>;
49
55
  appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
50
- fetchUserLid: (jid: string) => Promise<string | undefined>;
51
- sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string | undefined) => Promise<void>;
52
- presenceSubscribe: (toJid: string, tcToken?: Buffer | undefined) => Promise<void>;
56
+ sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string) => Promise<void>;
57
+ presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
58
+ profilePictureUrl: (jid: string, type?: "preview" | "image", timeoutMs?: number) => Promise<string | undefined>;
53
59
  onWhatsApp: (...jids: string[]) => Promise<{
54
60
  jid: string;
55
61
  exists: unknown;
62
+ lid: unknown;
56
63
  }[] | undefined>;
57
64
  fetchBlocklist: () => Promise<string[]>;
58
- fetchStatus: (...jids: string[]) => Promise<import("../index").USyncQueryResultList[] | undefined>;
59
- fetchDisappearingDuration: (...jids: string[]) => Promise<import("../index").USyncQueryResultList[] | undefined>;
65
+ fetchDisappearingDuration: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
66
+ fetchStatus: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
60
67
  updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
61
68
  removeProfilePicture: (jid: string) => Promise<void>;
62
69
  updateProfileStatus: (status: string) => Promise<void>;
63
70
  updateProfileName: (name: string) => Promise<void>;
64
71
  updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
72
+ updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
73
+ updateMessagesPrivacy: (value: import("../Types").WAPrivacyMessagesValue) => Promise<void>;
65
74
  updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
66
75
  updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
67
76
  updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
68
77
  updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
69
78
  updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
70
- updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
79
+ updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
71
80
  updateDefaultDisappearingMode: (duration: number) => Promise<void>;
72
- getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>;
73
- resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
81
+ getBusinessProfile: (jid: string) => Promise<import("../Types").WABusinessProfile | void>;
82
+ resyncAppState: (collections: readonly ("critical_unblock_low" | "regular_high" | "regular_low" | "critical_block" | "regular")[], isInitialSync: boolean) => Promise<void>;
74
83
  chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
75
- cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
84
+ cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
76
85
  addChatLabel: (jid: string, labelId: string) => Promise<void>;
77
86
  removeChatLabel: (jid: string, labelId: string) => Promise<void>;
78
87
  addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
79
88
  removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
80
89
  star: (jid: string, messages: {
81
90
  id: string;
82
- fromMe?: boolean | undefined;
91
+ fromMe?: boolean;
83
92
  }[], star: boolean) => Promise<void>;
84
- executeUSyncQuery: (usyncQuery: import("../index").USyncQuery) => Promise<import("../index").USyncQueryResult | undefined>;
93
+ executeUSyncQuery: (usyncQuery: import("..").USyncQuery) => Promise<import("..").USyncQueryResult | undefined>;
85
94
  type: "md";
86
- ws: any;
95
+ ws: import("./Client").WebSocketClient;
87
96
  ev: import("../Types").BaileysEventEmitter & {
88
- process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
97
+ process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
89
98
  buffer(): void;
90
- createBufferedFunction<A extends any[], T_1>(work: (...args: A) => Promise<T_1>): (...args: A) => Promise<T_1>;
91
- flush(force?: boolean | undefined): boolean;
99
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
100
+ flush(force?: boolean): boolean;
92
101
  isBuffering(): boolean;
93
102
  };
94
103
  authState: {
@@ -98,18 +107,18 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
98
107
  signalRepository: import("../Types").SignalRepository;
99
108
  user: import("../Types").Contact | undefined;
100
109
  generateMessageTag: () => string;
101
- query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>;
102
- waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>;
110
+ query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
111
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
103
112
  waitForSocketOpen: () => Promise<void>;
104
113
  sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
105
114
  sendNode: (frame: BinaryNode) => Promise<void>;
106
- logout: (msg?: string | undefined) => Promise<void>;
115
+ logout: (msg?: string) => Promise<void>;
107
116
  end: (error: Error | undefined) => void;
108
- onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void;
117
+ onUnexpectedError: (err: Error | import("@hapi/boom").Boom, msg: string) => void;
109
118
  uploadPreKeys: (count?: number) => Promise<void>;
110
119
  uploadPreKeysToServerIfRequired: () => Promise<void>;
111
- requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
112
- waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
113
- sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
120
+ requestPairingCode: (phoneNumber: any, pairKey?: string) => Promise<string>;
121
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
122
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
114
123
  };
115
124
  export declare const extractGroupMetadata: (result: BinaryNode) => GroupMetadata;
@@ -70,7 +70,7 @@ const makeGroupsSocket = (config) => {
70
70
  groupQuery,
71
71
  groupMetadata,
72
72
  groupCreate: async (subject, participants) => {
73
- const key = await config.generateMessageID() ?? (0, Utils_1.generateMessageID)();
73
+ const key = (0, Utils_1.generateMessageIDV2)();
74
74
  const result = await groupQuery('@g.us', 'set', [
75
75
  {
76
76
  tag: 'create',
@@ -164,7 +164,7 @@ const makeGroupsSocket = (config) => {
164
164
  {
165
165
  tag: 'description',
166
166
  attrs: {
167
- ...(description ? { id: await config.generateMessageID() ?? (0, Utils_1.generateMessageID)() } : { delete: 'true' }),
167
+ ...(description ? { id: (0, Utils_1.generateMessageIDV2)() } : { delete: 'true' }),
168
168
  ...(prev ? { prev } : {})
169
169
  },
170
170
  content: description ? [
@@ -236,7 +236,7 @@ const makeGroupsSocket = (config) => {
236
236
  await upsertMessage({
237
237
  key: {
238
238
  remoteJid: inviteMessage.groupJid,
239
- id: await config.generateMessageIDV2((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id) ?? (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id),
239
+ id: (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id),
240
240
  fromMe: false,
241
241
  participant: key.remoteJid,
242
242
  },
@@ -278,23 +278,38 @@ const extractGroupMetadata = (result) => {
278
278
  const descChild = (0, WABinary_1.getBinaryNodeChild)(group, 'description');
279
279
  let desc;
280
280
  let descId;
281
+ let descOwner;
282
+ let descOwnerLid;
283
+ let descTime;
281
284
  if (descChild) {
282
285
  desc = (0, WABinary_1.getBinaryNodeChildString)(descChild, 'body');
286
+ descOwner = (0, WABinary_1.jidNormalizedUser)(descChild.attrs.participant_pn || descChild.attrs.participant);
287
+ if (group.attrs.addressing_mode === 'lid') {
288
+ descOwnerLid = (0, WABinary_1.jidNormalizedUser)(descChild.attrs.participant);
289
+ }
283
290
  descId = descChild.attrs.id;
291
+ descTime = descChild.attrs.t ? +descChild.attrs.t : undefined;
284
292
  }
293
+ const groupSize = group.attrs.size ? Number(group.attrs.size) : undefined;
285
294
  const groupId = group.attrs.id.includes('@') ? group.attrs.id : (0, WABinary_1.jidEncode)(group.attrs.id, 'g.us');
286
295
  const eph = (_a = (0, WABinary_1.getBinaryNodeChild)(group, 'ephemeral')) === null || _a === void 0 ? void 0 : _a.attrs.expiration;
287
296
  const memberAddMode = (0, WABinary_1.getBinaryNodeChildString)(group, 'member_add_mode') === 'all_member_add';
288
297
  const metadata = {
289
298
  id: groupId,
299
+ addressingMode: group.attrs.addressing_mode,
290
300
  subject: group.attrs.subject,
291
- subjectOwner: group.attrs.s_o,
292
- subjectTime: +group.attrs.s_t,
293
- size: (0, WABinary_1.getBinaryNodeChildren)(group, 'participant').length,
294
- creation: +group.attrs.creation,
295
- owner: group.attrs.creator ? (0, WABinary_1.jidNormalizedUser)(group.attrs.creator) : undefined,
301
+ subjectOwner: (0, WABinary_1.jidNormalizedUser)(group.attrs.s_o_pn || group.attrs.s_o),
302
+ ...(group.attrs.addressing_mode === 'lid' ? { subjectOwnerLid: (0, WABinary_1.jidNormalizedUser)(group.attrs.s_o) } : {}),
303
+ subjectTime: group.attrs.s_t ? +group.attrs.s_t : undefined,
304
+ size: groupSize || (0, WABinary_1.getBinaryNodeChildren)(group, 'participant').length,
305
+ creation: group.attrs.creation ? +group.attrs.creation : undefined,
306
+ owner: (0, WABinary_1.jidNormalizedUser)(group.attrs.creator_pn || group.attrs.creator),
307
+ ...(group.attrs.addressing_mode === 'lid' ? { ownerLid: (0, WABinary_1.jidNormalizedUser)(group.attrs.creator) } : {}),
296
308
  desc,
297
309
  descId,
310
+ descOwner,
311
+ descOwnerLid,
312
+ descTime,
298
313
  linkedParent: ((_b = (0, WABinary_1.getBinaryNodeChild)(group, 'linked_parent')) === null || _b === void 0 ? void 0 : _b.attrs.jid) || undefined,
299
314
  restrict: !!(0, WABinary_1.getBinaryNodeChild)(group, 'locked'),
300
315
  announce: !!(0, WABinary_1.getBinaryNodeChild)(group, 'announcement'),
@@ -304,7 +319,9 @@ const extractGroupMetadata = (result) => {
304
319
  memberAddMode,
305
320
  participants: (0, WABinary_1.getBinaryNodeChildren)(group, 'participant').map(({ attrs }) => {
306
321
  return {
307
- id: attrs.phone_number ?? attrs.jid,
322
+ id: attrs.jid,
323
+ jid: attrs.phone_number || attrs.jid,
324
+ lid: attrs.lid || attrs.jid,
308
325
  admin: (attrs.type || null),
309
326
  };
310
327
  }),