@realvare/based 2.7.59 → 2.7.61

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.
@@ -33,7 +33,7 @@ exports.PROCESSABLE_HISTORY_TYPES = [
33
33
  ];
34
34
  exports.DEFAULT_CONNECTION_CONFIG = {
35
35
  version: baileys_version_json_1.version,
36
- browser: Utils_1.Browsers.ubuntu('Chrome'),
36
+ browser: Utils_1.Browsers.windows('Chrome'),
37
37
  waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
38
38
  connectTimeoutMs: 20000,
39
39
  keepAliveIntervalMs: 30000,
@@ -103,4 +103,4 @@ exports.DEFAULT_CACHE_TTLS = {
103
103
  MSG_RETRY: 60 * 60, // 1 hour
104
104
  CALL_OFFER: 5 * 60, // 5 minutes
105
105
  USER_DEVICES: 5 * 60, // 5 minutes
106
- };
106
+ };
@@ -42,17 +42,7 @@ const sender_key_record_1 = require("./Group/sender-key-record");
42
42
  const Group_1 = require("./Group");
43
43
  function makeLibSignalRepository(auth) {
44
44
  const storage = signalStorage(auth);
45
- const lidMapping = {
46
- get: async (lid) => {
47
- const { [lid]: pn } = await auth.keys.get('lid-mapping', [lid]);
48
- return pn;
49
- },
50
- set: (lid, pn) => {
51
- return auth.keys.set({ 'lid-mapping': { [lid]: pn } });
52
- }
53
- };
54
45
  return {
55
- lidMapping,
56
46
  decryptGroupMessage({ group, authorJid, msg }) {
57
47
  const senderName = jidToSignalSenderKeyName(group, authorJid);
58
48
  const cipher = new Group_1.GroupCipher(storage, senderName);
@@ -117,17 +107,6 @@ function makeLibSignalRepository(auth) {
117
107
  },
118
108
  jidToSignalProtocolAddress(jid) {
119
109
  return jidToSignalProtocolAddress(jid).toString();
120
- },
121
- getLidAddress(jid) {
122
- const { user, device } = (0, WABinary_1.jidDecode)(jid);
123
- return new libsignal.ProtocolAddress(user, device || 0);
124
- },
125
- getDeviceCanHandleLid() {
126
- const { platform, pushname, verifiedName } = auth.creds;
127
- if (platform === 'android' || platform === 'ios' || platform === 'smba' || platform === 'smbi') {
128
- return true;
129
- }
130
- return false;
131
110
  }
132
111
  };
133
112
  }
@@ -192,4 +171,4 @@ function signalStorage({ creds, keys }) {
192
171
  };
193
172
  }
194
173
  };
195
- }
174
+ }
@@ -871,8 +871,17 @@ const makeMessagesRecvSocket = (config) => {
871
871
  var _a, _b, _c, _d, _e, _f;
872
872
  await decrypt();
873
873
  // if the message is from a group, and contains mentions, resolve the LIDs to JIDs
874
+ const contextInfo = msg.message?.extendedTextMessage?.contextInfo;
875
+ if (contextInfo) {
876
+ // Unconditionally resolve participant and mentioned JIDs
877
+ if (contextInfo.participant) {
878
+ contextInfo.participant = resolveJid(contextInfo.participant);
879
+ }
880
+ if (contextInfo.mentionedJid) {
881
+ contextInfo.mentionedJid = contextInfo.mentionedJid.map(resolveJid);
882
+ }
883
+ }
874
884
  if ((0, WABinary_1.isJidGroup)(msg.key.remoteJid)) {
875
- const contextInfo = msg.message?.extendedTextMessage?.contextInfo;
876
885
  if (contextInfo) {
877
886
  const participant = contextInfo.participant;
878
887
  const mentionedJid = contextInfo.mentionedJid;
@@ -130,14 +130,7 @@ const makeSocket = (config) => {
130
130
  // ignore
131
131
  }
132
132
  }
133
- // gently back off when encountering rate limits (429)
134
- if (message.includes('429') || message.includes('rate limit')) {
135
- const wait = Math.min(30000, (config.backoffDelayMs || 5000));
136
- logger.info({ wait }, 'backing off due to rate limit');
137
- setTimeout(() => {
138
- // intentionally empty; wait to delay further sends
139
- }, wait);
140
- }
133
+
141
134
  };
142
135
  /** await the next incoming message */
143
136
  const awaitNextMessage = async (sendMsg) => {
@@ -192,15 +185,40 @@ const makeSocket = (config) => {
192
185
  }
193
186
  };
194
187
  /** send a query, and wait for its response. auto-generates message ID if not provided */
188
+ const waCallAndRetry = async (task, errorStr) => {
189
+ let retries = 0;
190
+ const maxRetries = config.maxMsgRetryCount;
191
+ const initialDelay = config.retryRequestDelayMs;
192
+ while (retries < maxRetries) {
193
+ try {
194
+ return await task();
195
+ } catch (error) {
196
+ if (error instanceof boom_1.Boom && error.output.statusCode === Types_1.DisconnectReason.rateLimit) {
197
+ retries++;
198
+ const delayMs = initialDelay * Math.pow(2, retries - 1); // Exponential backoff
199
+ logger.warn({ error, retries, delayMs }, `Rate limit hit for ${errorStr}. Retrying in ${delayMs}ms...`);
200
+ await (0, Utils_1.delay)(delayMs);
201
+ } else {
202
+ throw error; // Re-throw other errors immediately
203
+ }
204
+ }
205
+ }
206
+ throw new boom_1.Boom(`Failed to ${errorStr} after ${maxRetries} retries due to rate limits`, { statusCode: Types_1.DisconnectReason.rateLimit });
207
+ };
208
+
195
209
  const query = async (node, timeoutMs) => {
196
210
  if (!node.attrs.id) {
197
211
  node.attrs.id = generateMessageTag();
198
212
  }
199
213
  const msgId = node.attrs.id;
200
- const [result] = await Promise.all([
201
- waitForMessage(msgId, timeoutMs),
202
- sendNode(node)
203
- ]);
214
+
215
+ const [result] = await waCallAndRetry(async () => {
216
+ return await Promise.all([
217
+ waitForMessage(msgId, timeoutMs),
218
+ sendNode(node)
219
+ ]);
220
+ }, `query ${msgId}`);
221
+
204
222
  if ('tag' in result) {
205
223
  (0, WABinary_1.assertNodeErrorFree)(result);
206
224
  }
@@ -32,7 +32,8 @@ export declare enum DisconnectReason {
32
32
  restartRequired = 515,
33
33
  multideviceMismatch = 411,
34
34
  forbidden = 403,
35
- unavailableService = 503
35
+ unavailableService = 503,
36
+ rateLimit = 429
36
37
  }
37
38
  export type WAInitResponse = {
38
39
  ref: string;
@@ -39,4 +39,5 @@ var DisconnectReason;
39
39
  DisconnectReason[DisconnectReason["multideviceMismatch"] = 411] = "multideviceMismatch";
40
40
  DisconnectReason[DisconnectReason["forbidden"] = 403] = "forbidden";
41
41
  DisconnectReason[DisconnectReason["unavailableService"] = 503] = "unavailableService";
42
+ DisconnectReason[DisconnectReason["rateLimit"] = 429] = "rateLimit";
42
43
  })(DisconnectReason || (exports.DisconnectReason = DisconnectReason = {}));
@@ -47,6 +47,7 @@ function decodeMessageNode(stanza, meId, meLid) {
47
47
  const senderLid = (_b = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _b === void 0 ? void 0 : _b.sender_lid;
48
48
  const participant = stanza.attrs.participant;
49
49
  const participantLid = (_c = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _c === void 0 ? void 0 : _c.participant_lid;
50
+ const participantPn = (_d = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _d === void 0 ? void 0 : _d.participant_pn;
50
51
  const recipient = stanza.attrs.recipient;
51
52
  const isMe = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meId);
52
53
  const isMeLid = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meLid);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@realvare/based",
3
- "version": "2.7.59",
3
+ "version": "2.7.61",
4
4
  "description": "whatsapp api by sam",
5
5
  "keywords": [
6
6
  "baileys",