@realvare/based 2.7.56 → 2.7.58

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.
@@ -43,7 +43,7 @@ exports.DEFAULT_CONNECTION_CONFIG = {
43
43
  defaultQueryTimeoutMs: 60000,
44
44
  customUploadHosts: [],
45
45
  retryRequestDelayMs: 250,
46
- maxMsgRetryCount: 10,
46
+ maxMsgRetryCount: 5,
47
47
  fireInitQueries: true,
48
48
  auth: undefined,
49
49
  markOnlineOnConnect: false,
@@ -59,7 +59,7 @@ exports.DEFAULT_CONNECTION_CONFIG = {
59
59
  patch: false,
60
60
  snapshot: false,
61
61
  },
62
- countryCode: 'IT',
62
+ countryCode: 'US',
63
63
  getMessage: async () => undefined,
64
64
  cachedGroupMetadata: async () => undefined,
65
65
  makeSignalRepository: libsignal_1.makeLibSignalRepository
@@ -32,6 +32,12 @@ const makeChatsSocket = (config) => {
32
32
  if (!config.placeholderResendCache) {
33
33
  config.placeholderResendCache = placeholderResendCache;
34
34
  }
35
+ const resolveJid = (jid) => {
36
+ if (typeof jid === 'string' && jid.endsWith('@lid')) {
37
+ return (0, WABinary_1.lidToJid)(jid);
38
+ }
39
+ return jid;
40
+ };
35
41
  /** helper function to fetch the given app state sync key */
36
42
  const getAppStateSyncKey = async (keyId) => {
37
43
  const { [keyId]: key } = await authState.keys.get('app-state-sync-key', [keyId]);
@@ -136,7 +142,7 @@ const makeChatsSocket = (config) => {
136
142
  if (section.attrs.type === 'all') {
137
143
  for (const bot of (0, WABinary_1.getBinaryNodeChildren)(section, 'bot')) {
138
144
  botList.push({
139
- jid: bot.attrs.jid,
145
+ jid: resolveJid(bot.attrs.jid),
140
146
  personaId: bot.attrs['persona_id']
141
147
  });
142
148
  }
@@ -149,15 +155,20 @@ const makeChatsSocket = (config) => {
149
155
  .withContactProtocol()
150
156
  .withLIDProtocol();
151
157
  for (const jid of jids) {
152
- const phone = `+${jid.replace('+', '').split('@')[0].split(':')[0]}`;
153
- usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone));
158
+ if (jid.includes('@')) {
159
+ usyncQuery.withUser(new WAUSync_1.USyncUser().withId(resolveJid(jid)));
160
+ } else {
161
+ const phone = `+${jid}`;
162
+ usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone));
163
+ }
154
164
  }
155
165
  const results = await sock.executeUSyncQuery(usyncQuery);
156
166
  if (results) {
157
- return results.list.filter((a) => !!a.contact).map(({ contact, id, lid }) => ({ jid: id, exists: contact, lid }));
167
+ return results.list.filter((a) => !!a.contact).map(({ contact, id, lid }) => ({ jid: resolveJid(id), exists: contact, lid }));
158
168
  }
159
169
  };
160
170
  const fetchStatus = async (...jids) => {
171
+ jids = jids.map(resolveJid);
161
172
  const usyncQuery = new WAUSync_1.USyncQuery()
162
173
  .withStatusProtocol();
163
174
  for (const jid of jids) {
@@ -169,6 +180,7 @@ const makeChatsSocket = (config) => {
169
180
  }
170
181
  };
171
182
  const fetchDisappearingDuration = async (...jids) => {
183
+ jids = jids.map(resolveJid);
172
184
  const usyncQuery = new WAUSync_1.USyncQuery()
173
185
  .withDisappearingModeProtocol();
174
186
  for (const jid of jids) {
@@ -181,6 +193,7 @@ const makeChatsSocket = (config) => {
181
193
  };
182
194
  /** update the profile picture for yourself or a group */
183
195
  const updateProfilePicture = async (jid, content) => {
196
+ jid = resolveJid(jid);
184
197
  let targetJid;
185
198
  if (!jid) {
186
199
  throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
@@ -208,6 +221,7 @@ const makeChatsSocket = (config) => {
208
221
  };
209
222
  /** remove the profile picture for yourself or a group */
210
223
  const removeProfilePicture = async (jid) => {
224
+ jid = resolveJid(jid);
211
225
  let targetJid;
212
226
  if (!jid) {
213
227
  throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
@@ -257,9 +271,10 @@ const makeChatsSocket = (config) => {
257
271
  });
258
272
  const listNode = (0, WABinary_1.getBinaryNodeChild)(result, 'list');
259
273
  return (0, WABinary_1.getBinaryNodeChildren)(listNode, 'item')
260
- .map(n => n.attrs.jid);
274
+ .map(n => resolveJid(n.attrs.jid));
261
275
  };
262
276
  const updateBlockStatus = async (jid, action) => {
277
+ jid = resolveJid(jid);
263
278
  await query({
264
279
  tag: 'iq',
265
280
  attrs: {
@@ -279,6 +294,7 @@ const makeChatsSocket = (config) => {
279
294
  });
280
295
  };
281
296
  const getBusinessProfile = async (jid) => {
297
+ jid = resolveJid(jid);
282
298
  var _a, _b, _c, _d, _e, _f, _g;
283
299
  const results = await query({
284
300
  tag: 'iq',
@@ -462,6 +478,7 @@ const makeChatsSocket = (config) => {
462
478
  * type = "image for the high res picture"
463
479
  */
464
480
  const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
481
+ jid = resolveJid(jid);
465
482
  var _a;
466
483
  jid = (0, WABinary_1.jidNormalizedUser)(jid);
467
484
  const result = await query({
@@ -480,6 +497,7 @@ const makeChatsSocket = (config) => {
480
497
  return (_a = child === null || child === void 0 ? void 0 : child.attrs) === null || _a === void 0 ? void 0 : _a.url;
481
498
  };
482
499
  const sendPresenceUpdate = async (type, toJid) => {
500
+ toJid = resolveJid(toJid);
483
501
  const me = authState.creds.me;
484
502
  if (type === 'available' || type === 'unavailable') {
485
503
  if (!me.name) {
@@ -520,7 +538,7 @@ const makeChatsSocket = (config) => {
520
538
  const presenceSubscribe = (toJid, tcToken) => (sendNode({
521
539
  tag: 'presence',
522
540
  attrs: {
523
- to: toJid,
541
+ to: resolveJid(toJid),
524
542
  id: generateMessageTag(),
525
543
  type: 'subscribe'
526
544
  },
@@ -537,8 +555,8 @@ const makeChatsSocket = (config) => {
537
555
  const handlePresenceUpdate = ({ tag, attrs, content }) => {
538
556
  var _a;
539
557
  let presence;
540
- const jid = attrs.from;
541
- const participant = attrs.participant || attrs.from;
558
+ const jid = resolveJid(attrs.from);
559
+ const participant = resolveJid(attrs.participant || attrs.from);
542
560
  if (shouldIgnoreJid(jid) && jid != '@s.whatsapp.net') {
543
561
  return;
544
562
  }
@@ -660,6 +678,7 @@ const makeChatsSocket = (config) => {
660
678
  * requires the last messages till the last message received; required for archive & unread
661
679
  */
662
680
  const chatModify = (mod, jid) => {
681
+ jid = resolveJid(jid);
663
682
  const patch = (0, Utils_1.chatModificationToAppPatch)(mod, jid);
664
683
  return appPatch(patch);
665
684
  };
@@ -667,6 +686,7 @@ const makeChatsSocket = (config) => {
667
686
  * Star or Unstar a message
668
687
  */
669
688
  const star = (jid, messages, star) => {
689
+ jid = resolveJid(jid);
670
690
  return chatModify({
671
691
  star: {
672
692
  messages,
@@ -678,6 +698,7 @@ const makeChatsSocket = (config) => {
678
698
  * Adds label for the chats
679
699
  */
680
700
  const addChatLabel = (jid, labelId) => {
701
+ jid = resolveJid(jid);
681
702
  return chatModify({
682
703
  addChatLabel: {
683
704
  labelId
@@ -688,6 +709,7 @@ const makeChatsSocket = (config) => {
688
709
  * Removes label for the chat
689
710
  */
690
711
  const removeChatLabel = (jid, labelId) => {
712
+ jid = resolveJid(jid);
691
713
  return chatModify({
692
714
  removeChatLabel: {
693
715
  labelId
@@ -698,6 +720,7 @@ const makeChatsSocket = (config) => {
698
720
  * Adds label for the message
699
721
  */
700
722
  const addMessageLabel = (jid, messageId, labelId) => {
723
+ jid = resolveJid(jid);
701
724
  return chatModify({
702
725
  addMessageLabel: {
703
726
  messageId,
@@ -709,6 +732,7 @@ const makeChatsSocket = (config) => {
709
732
  * Removes label for the message
710
733
  */
711
734
  const removeMessageLabel = (jid, messageId, labelId) => {
735
+ jid = resolveJid(jid);
712
736
  return chatModify({
713
737
  removeMessageLabel: {
714
738
  messageId,
@@ -830,7 +854,7 @@ const makeChatsSocket = (config) => {
830
854
  break;
831
855
  }
832
856
  });
833
- ev.on('connection.update', ({ connection, receivedPendingNotifications }) => {
857
+ ev.on('connection.update', ({ connection, receivedPendingNotifications, isOnline }) => {
834
858
  var _a;
835
859
  if (connection === 'open') {
836
860
  if (fireInitQueries) {
@@ -847,6 +871,9 @@ const makeChatsSocket = (config) => {
847
871
  ev.buffer();
848
872
  needToFlushWithAppStateSync = true;
849
873
  }
874
+ if (typeof isOnline !== 'undefined' && isOnline) {
875
+ sendPresenceUpdate('available').catch(error => onUnexpectedError(error, 'presence update on online'));
876
+ }
850
877
  });
851
878
  return {
852
879
  ...sock,
@@ -887,4 +914,4 @@ const makeChatsSocket = (config) => {
887
914
  star
888
915
  };
889
916
  };
890
- exports.makeChatsSocket = makeChatsSocket;
917
+ exports.makeChatsSocket = makeChatsSocket;
@@ -9,6 +9,12 @@ const chats_1 = require("./chats");
9
9
  const makeGroupsSocket = (config) => {
10
10
  const sock = (0, chats_1.makeChatsSocket)(config);
11
11
  const { authState, ev, query, upsertMessage } = sock;
12
+ const resolveJid = (jid) => {
13
+ if (typeof jid === 'string' && jid.endsWith('@lid')) {
14
+ return (0, WABinary_1.lidToJid)(jid);
15
+ }
16
+ return jid;
17
+ };
12
18
  const groupQuery = async (jid, type, content) => (query({
13
19
  tag: 'iq',
14
20
  attrs: {
@@ -70,6 +76,7 @@ const makeGroupsSocket = (config) => {
70
76
  groupQuery,
71
77
  groupMetadata,
72
78
  groupCreate: async (subject, participants) => {
79
+ participants = participants.map(resolveJid);
73
80
  const key = (0, Utils_1.generateMessageIDV2)();
74
81
  const result = await groupQuery('@g.us', 'set', [
75
82
  {
@@ -118,6 +125,7 @@ const makeGroupsSocket = (config) => {
118
125
  return participants.map(v => v.attrs);
119
126
  },
120
127
  groupRequestParticipantsUpdate: async (jid, participants, action) => {
128
+ participants = participants.map(resolveJid);
121
129
  const result = await groupQuery(jid, 'set', [{
122
130
  tag: 'membership_requests_action',
123
131
  attrs: {},
@@ -140,6 +148,7 @@ const makeGroupsSocket = (config) => {
140
148
  });
141
149
  },
142
150
  groupParticipantsUpdate: async (jid, participants, action) => {
151
+ participants = participants.map(resolveJid);
143
152
  const result = await groupQuery(jid, 'set', [
144
153
  {
145
154
  tag: action,
@@ -195,6 +204,7 @@ const makeGroupsSocket = (config) => {
195
204
  * @returns true if successful
196
205
  */
197
206
  groupRevokeInviteV4: async (groupJid, invitedJid) => {
207
+ invitedJid = resolveJid(invitedJid);
198
208
  const result = await groupQuery(groupJid, 'set', [{ tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }]);
199
209
  return !!result;
200
210
  },
@@ -206,6 +216,7 @@ const makeGroupsSocket = (config) => {
206
216
  groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
207
217
  var _a;
208
218
  key = typeof key === 'string' ? { remoteJid: key } : key;
219
+ key.remoteJid = resolveJid(key.remoteJid);
209
220
  const results = await groupQuery(inviteMessage.groupJid, 'set', [{
210
221
  tag: 'accept',
211
222
  attrs: {
@@ -329,4 +340,4 @@ const extractGroupMetadata = (result) => {
329
340
  };
330
341
  return metadata;
331
342
  };
332
- exports.extractGroupMetadata = extractGroupMetadata;
343
+ exports.extractGroupMetadata = extractGroupMetadata;
@@ -68,7 +68,6 @@ const makeMessagesRecvSocket = (config) => {
68
68
  logger.debug({ recv: { tag, attrs }, sent: stanza.attrs }, 'sent ack');
69
69
  await sendNode(stanza);
70
70
  };
71
-
72
71
  // Add withAck wrapper for guaranteed acknowledgments
73
72
  const withAck = (processFn) => async (node) => {
74
73
  try {
@@ -253,6 +252,14 @@ const makeMessagesRecvSocket = (config) => {
253
252
  }
254
253
  }
255
254
  };
255
+ const toLidIfNecessary = (jid) => {
256
+ if (typeof jid !== 'string') return jid;
257
+ const [user, server] = jid.split('@');
258
+ if (server === 's.whatsapp.net' && /^[0-9]+$/.test(user) && user.length >= 15) {
259
+ return `${user}@lid`;
260
+ }
261
+ return jid;
262
+ };
256
263
  const handleGroupNotification = async (participant, child, groupJid, msg) => {
257
264
  var _a, _b, _c, _d;
258
265
  const participantJid = (((_b = (_a = (0, WABinary_1.getBinaryNodeChild)(child, 'participant')) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.jid) || participant);
@@ -362,16 +369,28 @@ const makeMessagesRecvSocket = (config) => {
362
369
  default:
363
370
  // console.log("BAILEYS-DEBUG:", JSON.stringify({ ...child, content: Buffer.isBuffer(child.content) ? child.content.toString() : child.content, participant }, null, 2))
364
371
  }
365
- const needsResolving = (msg.messageStubParameters && msg.messageStubParameters.some(p => typeof p === 'string' && (0, WABinary_1.isLid)(p))) ||
372
+ // Apply LID fix before checking needsResolving
373
+ if (msg.messageStubParameters) {
374
+ msg.messageStubParameters = msg.messageStubParameters.map(toLidIfNecessary);
375
+ }
376
+ participant = toLidIfNecessary(participant);
377
+ if (msg.key?.participant) {
378
+ msg.key.participant = toLidIfNecessary(msg.key.participant);
379
+ }
380
+ const needsResolving = (msg.messageStubParameters && msg.messageStubParameters.some(p => typeof p === 'string')) ||
366
381
  (participant && (0, WABinary_1.isLid)(participant)) ||
367
382
  (msg.key?.participant && (0, WABinary_1.isLid)(msg.key.participant));
368
383
  if(needsResolving) {
369
384
  const metadata = await groupMetadata(groupJid);
370
385
  if (msg.messageStubParameters) {
371
386
  msg.messageStubParameters = await Promise.all(msg.messageStubParameters.map(async (param) => {
372
- if (typeof param === 'string' && (0, WABinary_1.isLid)(param)) {
373
- const found = metadata.participants.find(p => p.id === param);
374
- return found?.jid || (0, WABinary_1.lidToJid)(param);
387
+ if (typeof param === 'string') {
388
+ if ((0, WABinary_1.isLid)(param)) {
389
+ const found = metadata.participants.find(p => p.id === param);
390
+ return found?.jid || (0, WABinary_1.lidToJid)(param);
391
+ } else {
392
+ return param;
393
+ }
375
394
  }
376
395
  return param;
377
396
  }));
@@ -379,10 +398,16 @@ const makeMessagesRecvSocket = (config) => {
379
398
  if(participant && (0, WABinary_1.isLid)(participant)) {
380
399
  const found = metadata.participants.find(p => p.id === participant);
381
400
  msg.participant = found?.jid || (0, WABinary_1.lidToJid)(participant);
401
+ } else if (participant) {
402
+ //If it's a JID, treat it as a JID. Do not convert back to LID. *smh brah
403
+ msg.participant = participant;
382
404
  }
383
405
  if (msg.key?.participant && (0, WABinary_1.isLid)(msg.key.participant)) {
384
406
  const found = metadata.participants.find(p => p.id === msg.key.participant);
385
407
  msg.key.participant = found?.jid || (0, WABinary_1.lidToJid)(msg.key.participant);
408
+ } else if (msg.key?.participant) {
409
+ // If it's a JID, treat it as a JID. Do not convert back to LID. *smh brahpt2
410
+ msg.key.participant = msg.key.participant;
386
411
  }
387
412
  }
388
413
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@realvare/based",
3
- "version": "2.7.56",
3
+ "version": "2.7.58",
4
4
  "description": "whatsapp api by sam",
5
5
  "keywords": [
6
6
  "baileys",
@@ -60,7 +60,7 @@
60
60
  "protobufjs": "^7.5.4",
61
61
  "sharp": "^0.33.5",
62
62
  "uuid": "^13.0.0",
63
- "ws": "^8.18.3"
63
+ "ws": "^8.18.0"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@adiwajshing/eslint-config": "github:adiwajshing/eslint-config",