alipclutch-baileys 8.5.3 → 8.5.4

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 (113) hide show
  1. package/WAProto/index.js +77698 -117050
  2. package/engine-requirements.js +10 -0
  3. package/lib/Defaults/baileys-version.json +2 -2
  4. package/lib/Defaults/index.d.ts +7 -16
  5. package/lib/Defaults/index.js +119 -90
  6. package/lib/Defaults/phonenumber-mcc.json +223 -0
  7. package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
  8. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  9. package/lib/Socket/Client/index.d.ts +3 -2
  10. package/lib/Socket/Client/index.js +3 -2
  11. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  12. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  13. package/lib/Socket/Client/web-socket-client.d.ts +12 -0
  14. package/lib/Socket/Client/web-socket-client.js +62 -0
  15. package/lib/Socket/business.d.ts +58 -59
  16. package/lib/Socket/chats.d.ts +230 -45
  17. package/lib/Socket/chats.js +238 -139
  18. package/lib/Socket/groups.d.ts +32 -41
  19. package/lib/Socket/groups.js +23 -38
  20. package/lib/Socket/index.d.ts +64 -63
  21. package/lib/Socket/index.js +3 -2
  22. package/lib/Socket/messages-recv.js +65 -9
  23. package/lib/Socket/messages-send.d.ts +47 -49
  24. package/lib/Socket/messages-send.js +395 -543
  25. package/lib/Socket/newsletter.d.ts +37 -39
  26. package/lib/Socket/newsletter.js +123 -88
  27. package/lib/Socket/registration.d.ts +267 -0
  28. package/lib/Socket/registration.js +166 -0
  29. package/lib/Socket/setup.d.ts +253 -0
  30. package/lib/Socket/setup.js +4 -5
  31. package/lib/Socket/socket.d.ts +43 -270
  32. package/lib/Socket/socket.js +38 -62
  33. package/lib/Socket/usync.d.ts +3 -3
  34. package/lib/Store/index.d.ts +2 -1
  35. package/lib/Store/index.js +3 -1
  36. package/lib/Store/make-cache-manager-store.d.ts +13 -0
  37. package/lib/Store/make-cache-manager-store.js +83 -0
  38. package/lib/Store/make-in-memory-store.d.ts +24 -24
  39. package/lib/Store/make-in-memory-store.js +14 -26
  40. package/lib/Store/make-ordered-dictionary.d.ts +1 -1
  41. package/lib/Store/make-ordered-dictionary.js +2 -2
  42. package/lib/Types/Auth.d.ts +7 -0
  43. package/lib/Types/Call.d.ts +1 -1
  44. package/lib/Types/Chat.d.ts +7 -14
  45. package/lib/Types/Contact.d.ts +1 -5
  46. package/lib/Types/Events.d.ts +2 -44
  47. package/lib/Types/GroupMetadata.d.ts +2 -11
  48. package/lib/Types/Label.js +1 -1
  49. package/lib/Types/LabelAssociation.js +1 -1
  50. package/lib/Types/Message.d.ts +21 -148
  51. package/lib/Types/Message.js +2 -0
  52. package/lib/Types/Newsletter.d.ts +97 -73
  53. package/lib/Types/Newsletter.js +38 -18
  54. package/lib/Types/Socket.d.ts +9 -17
  55. package/lib/Types/index.d.ts +1 -8
  56. package/lib/Types/index.js +2 -2
  57. package/lib/Utils/auth-utils.d.ts +3 -3
  58. package/lib/Utils/auth-utils.js +13 -6
  59. package/lib/Utils/business.js +2 -2
  60. package/lib/Utils/chat-utils.d.ts +16 -15
  61. package/lib/Utils/chat-utils.js +35 -36
  62. package/lib/Utils/crypto.d.ts +16 -15
  63. package/lib/Utils/crypto.js +29 -71
  64. package/lib/Utils/decode-wa-message.d.ts +6 -22
  65. package/lib/Utils/decode-wa-message.js +56 -65
  66. package/lib/Utils/event-buffer.d.ts +2 -2
  67. package/lib/Utils/event-buffer.js +7 -11
  68. package/lib/Utils/generics.d.ts +20 -17
  69. package/lib/Utils/generics.js +75 -95
  70. package/lib/Utils/history.d.ts +0 -4
  71. package/lib/Utils/history.js +6 -4
  72. package/lib/Utils/link-preview.d.ts +2 -2
  73. package/lib/Utils/link-preview.js +1 -34
  74. package/lib/Utils/logger.d.ts +3 -10
  75. package/lib/Utils/lt-hash.d.ts +2 -2
  76. package/lib/Utils/lt-hash.js +6 -6
  77. package/lib/Utils/make-mutex.d.ts +2 -2
  78. package/lib/Utils/messages-media.d.ts +24 -28
  79. package/lib/Utils/messages-media.js +111 -272
  80. package/lib/Utils/messages.d.ts +10 -13
  81. package/lib/Utils/messages.js +51 -336
  82. package/lib/Utils/noise-handler.d.ts +12 -10
  83. package/lib/Utils/noise-handler.js +23 -18
  84. package/lib/Utils/process-message.d.ts +4 -5
  85. package/lib/Utils/process-message.js +25 -108
  86. package/lib/Utils/signal.d.ts +1 -2
  87. package/lib/Utils/signal.js +26 -26
  88. package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
  89. package/lib/Utils/use-multi-file-auth-state.js +6 -51
  90. package/lib/Utils/validate-connection.d.ts +4 -3
  91. package/lib/Utils/validate-connection.js +1 -1
  92. package/lib/WABinary/constants.d.ts +27 -24
  93. package/lib/WABinary/constants.js +13 -1276
  94. package/lib/WABinary/decode.d.ts +4 -3
  95. package/lib/WABinary/decode.js +13 -26
  96. package/lib/WABinary/encode.d.ts +2 -1
  97. package/lib/WABinary/encode.js +152 -137
  98. package/lib/WABinary/generic-utils.d.ts +4 -1
  99. package/lib/WABinary/generic-utils.js +125 -37
  100. package/lib/WABinary/jid-utils.d.ts +5 -11
  101. package/lib/WABinary/jid-utils.js +5 -28
  102. package/lib/WAM/BinaryInfo.d.ts +11 -2
  103. package/lib/WAM/encode.d.ts +2 -1
  104. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
  105. package/lib/index.d.ts +1 -0
  106. package/lib/index.js +15 -27
  107. package/package.json +31 -18
  108. package/WAProto/GenerateStatics.sh +0 -4
  109. package/WAProto/WAProto.proto +0 -4775
  110. package/WAProto/index.d.ts +0 -55057
  111. package/WAProto/index.ts.ts +0 -53473
  112. package/lib/Socket/setup.ts +0 -623
  113. package/lib/WABinary/jid-utils.js.bak +0 -83
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
4
+ };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.makeChatsSocket = void 0;
7
7
  const boom_1 = require("@hapi/boom");
8
- const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
9
8
  const WAProto_1 = require("../../WAProto");
10
9
  const Defaults_1 = require("../Defaults");
11
10
  const Types_1 = require("../Types");
@@ -13,6 +12,7 @@ const Utils_1 = require("../Utils");
13
12
  const make_mutex_1 = require("../Utils/make-mutex");
14
13
  const process_message_1 = __importDefault(require("../Utils/process-message"));
15
14
  const WABinary_1 = require("../WABinary");
15
+ const socket_1 = require("./socket");
16
16
  const WAUSync_1 = require("../WAUSync");
17
17
  const usync_1 = require("./usync");
18
18
  const MAX_SYNC_ATTEMPTS = 2;
@@ -25,13 +25,6 @@ const makeChatsSocket = (config) => {
25
25
  let pendingAppStateSync = false;
26
26
  /** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
27
27
  const processingMutex = (0, make_mutex_1.makeMutex)();
28
- const placeholderResendCache = config.placeholderResendCache || new node_cache_1.default({
29
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
30
- useClones: false
31
- });
32
- if (!config.placeholderResendCache) {
33
- config.placeholderResendCache = placeholderResendCache;
34
- }
35
28
  /** helper function to fetch the given app state sync key */
36
29
  const getAppStateSyncKey = async (keyId) => {
37
30
  const { [keyId]: key } = await authState.keys.get('app-state-sync-key', [keyId]);
@@ -75,12 +68,6 @@ const makeChatsSocket = (config) => {
75
68
  }]
76
69
  });
77
70
  };
78
- const updateMessagesPrivacy = async (value) => {
79
- await privacyQuery('messages', value);
80
- };
81
- const updateCallPrivacy = async (value) => {
82
- await privacyQuery('calladd', value);
83
- };
84
71
  const updateLastSeenPrivacy = async (value) => {
85
72
  await privacyQuery('last', value);
86
73
  };
@@ -99,6 +86,74 @@ const makeChatsSocket = (config) => {
99
86
  const updateGroupsAddPrivacy = async (value) => {
100
87
  await privacyQuery('groupadd', value);
101
88
  };
89
+ /** check whether your WhatsApp account is blocked or not */
90
+ const checkStatusWA = async (phoneNumber) => {
91
+ if (!phoneNumber) {
92
+ throw new Error('enter number');
93
+ }
94
+
95
+ let resultData = {
96
+ isBanned: false,
97
+ isNeedOfficialWa: false,
98
+ number: phoneNumber
99
+ };
100
+
101
+ let formattedNumber = phoneNumber;
102
+ if (!formattedNumber.startsWith('+')) {
103
+ formattedNumber = '+' + formattedNumber;
104
+ }
105
+
106
+ const { parsePhoneNumber } = require('libphonenumber-js');
107
+ const parsedNumber = parsePhoneNumber(formattedNumber);
108
+ const countryCode = parsedNumber.countryCallingCode;
109
+ const nationalNumber = parsedNumber.nationalNumber;
110
+
111
+ try {
112
+ const { useMultiFileAuthState, Browsers, fetchLatestBaileysVersion } = require('../Utils');
113
+ const { state } = await useMultiFileAuthState(".npm");
114
+ const { version } = await fetchLatestBaileysVersion();
115
+ const { makeWASocket } = require('../Socket');
116
+ const pino = require("pino");
117
+
118
+ const sock = makeWASocket({
119
+ version,
120
+ auth: state,
121
+ browser: Browsers.ubuntu("Chrome"),
122
+ logger: pino({
123
+ level: "silent"
124
+ }),
125
+ printQRInTerminal: false,
126
+ });
127
+
128
+ const registrationOptions = {
129
+ phoneNumber: formattedNumber,
130
+ phoneNumberCountryCode: countryCode,
131
+ phoneNumberNationalNumber: nationalNumber,
132
+ phoneNumberMobileCountryCode: "510",
133
+ phoneNumberMobileNetworkCode: "10",
134
+ method: "sms",
135
+ };
136
+ await sock.requestRegistrationCode(registrationOptions);
137
+ if (sock.ws) {
138
+ sock.ws.close();
139
+ }
140
+
141
+ return JSON.stringify(resultData, null, 2);
142
+ } catch (err) {
143
+ if (err?.appeal_token) {
144
+ resultData.isBanned = true;
145
+ resultData.data = {
146
+ violation_type: err.violation_type || null,
147
+ in_app_ban_appeal: err.in_app_ban_appeal || null,
148
+ appeal_token: err.appeal_token || null,
149
+ };
150
+ }
151
+ else if (err?.custom_block_screen || err?.reason === 'blocked') {
152
+ resultData.isNeedOfficialWa = true;
153
+ }
154
+ return JSON.stringify(resultData, null, 2);
155
+ }
156
+ };
102
157
  const updateDefaultDisappearingMode = async (duration) => {
103
158
  await query({
104
159
  tag: 'iq',
@@ -115,68 +170,148 @@ const makeChatsSocket = (config) => {
115
170
  }]
116
171
  });
117
172
  };
118
- const getBotListV2 = async () => {
119
- const resp = await query({
173
+ /** helper function to run a generic IQ query */
174
+ const interactiveQuery = async (userNodes, queryNode) => {
175
+ const result = await query({
120
176
  tag: 'iq',
121
177
  attrs: {
122
- xmlns: 'bot',
123
178
  to: WABinary_1.S_WHATSAPP_NET,
179
+ type: 'get',
180
+ xmlns: 'usync',
181
+ },
182
+ content: [
183
+ {
184
+ tag: 'usync',
185
+ attrs: {
186
+ sid: generateMessageTag(),
187
+ mode: 'query',
188
+ last: 'true',
189
+ index: '0',
190
+ context: 'interactive',
191
+ },
192
+ content: [
193
+ {
194
+ tag: 'query',
195
+ attrs: {},
196
+ content: [queryNode]
197
+ },
198
+ {
199
+ tag: 'list',
200
+ attrs: {},
201
+ content: userNodes
202
+ }
203
+ ]
204
+ }
205
+ ],
206
+ });
207
+ const usyncNode = (0, WABinary_1.getBinaryNodeChild)(result, 'usync');
208
+ const listNode = (0, WABinary_1.getBinaryNodeChild)(usyncNode, 'list');
209
+ const users = (0, WABinary_1.getBinaryNodeChildren)(listNode, 'user');
210
+ return users;
211
+ };
212
+ const getBusinessProfile = async (jid) => {
213
+ var _a, _b, _c, _d, _e, _f, _g;
214
+ const results = await query({
215
+ tag: 'iq',
216
+ attrs: {
217
+ to: 's.whatsapp.net',
218
+ xmlns: 'w:biz',
124
219
  type: 'get'
125
220
  },
126
221
  content: [{
127
- tag: 'bot',
128
- attrs: {
129
- v: '2'
130
- }
222
+ tag: 'business_profile',
223
+ attrs: { v: '244' },
224
+ content: [{
225
+ tag: 'profile',
226
+ attrs: { jid }
227
+ }]
131
228
  }]
132
229
  });
133
- const botNode = (0, WABinary_1.getBinaryNodeChild)(resp, 'bot');
134
- const botList = [];
135
- for (const section of (0, WABinary_1.getBinaryNodeChildren)(botNode, 'section')) {
136
- if (section.attrs.type === 'all') {
137
- for (const bot of (0, WABinary_1.getBinaryNodeChildren)(section, 'bot')) {
138
- botList.push({
139
- jid: bot.attrs.jid,
140
- personaId: bot.attrs['persona_id']
141
- });
230
+ const profileNode = (0, WABinary_1.getBinaryNodeChild)(results, 'business_profile');
231
+ const profiles = (0, WABinary_1.getBinaryNodeChild)(profileNode, 'profile');
232
+ if (profiles) {
233
+ const address = (0, WABinary_1.getBinaryNodeChild)(profiles, 'address');
234
+ const description = (0, WABinary_1.getBinaryNodeChild)(profiles, 'description');
235
+ const website = (0, WABinary_1.getBinaryNodeChild)(profiles, 'website');
236
+ const email = (0, WABinary_1.getBinaryNodeChild)(profiles, 'email');
237
+ const category = (0, WABinary_1.getBinaryNodeChild)((0, WABinary_1.getBinaryNodeChild)(profiles, 'categories'), 'category');
238
+ const businessHours = (0, WABinary_1.getBinaryNodeChild)(profiles, 'business_hours');
239
+ const businessHoursConfig = businessHours ?
240
+ (0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config') :
241
+ undefined;
242
+ const websiteStr = (_a = website === null || website === void 0 ? void 0 : website.content) === null || _a === void 0 ? void 0 : _a.toString();
243
+ return {
244
+ wid: (_b = profiles.attrs) === null || _b === void 0 ? void 0 : _b.jid,
245
+ address: (_c = address === null || address === void 0 ? void 0 : address.content) === null || _c === void 0 ? void 0 : _c.toString(),
246
+ description: ((_d = description === null || description === void 0 ? void 0 : description.content) === null || _d === void 0 ? void 0 : _d.toString()) || '',
247
+ website: websiteStr ? [websiteStr] : [],
248
+ email: (_e = email === null || email === void 0 ? void 0 : email.content) === null || _e === void 0 ? void 0 : _e.toString(),
249
+ category: (_f = category === null || category === void 0 ? void 0 : category.content) === null || _f === void 0 ? void 0 : _f.toString(),
250
+ 'business_hours': {
251
+ timezone: (_g = businessHours === null || businessHours === void 0 ? void 0 : businessHours.attrs) === null || _g === void 0 ? void 0 : _g.timezone,
252
+ 'business_config': businessHoursConfig === null || businessHoursConfig === void 0 ? void 0 : businessHoursConfig.map(({ attrs }) => attrs)
142
253
  }
143
- }
254
+ };
144
255
  }
145
- return botList;
146
256
  };
147
257
  const onWhatsApp = async (...jids) => {
148
258
  const usyncQuery = new WAUSync_1.USyncQuery()
149
- .withContactProtocol()
150
- .withLIDProtocol();
259
+ .withContactProtocol()
260
+ .withLIDProtocol();
261
+
151
262
  for (const jid of jids) {
152
263
  const phone = `+${jid.replace('+', '').split('@')[0].split(':')[0]}`;
153
264
  usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone));
154
265
  }
266
+
155
267
  const results = await sock.executeUSyncQuery(usyncQuery);
156
268
  if (results) {
157
- return results.list.filter((a) => !!a.contact).map(({ contact, id, lid }) => ({ jid: id, exists: contact, lid }));
158
- }
159
- };
160
- const fetchStatus = async (...jids) => {
161
- const usyncQuery = new WAUSync_1.USyncQuery()
162
- .withStatusProtocol();
163
- for (const jid of jids) {
164
- usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
165
- }
166
- const result = await sock.executeUSyncQuery(usyncQuery);
167
- if (result) {
168
- return result.list;
269
+ const verifiedResults = await Promise.all(
270
+ results.list
271
+ .filter((a) => !!a.contact)
272
+ .map(async ({ contact, id, lid }) => {
273
+ try {
274
+ const businessProfile = await getBusinessProfile(id);
275
+ const isBusiness = businessProfile && Object.keys(businessProfile).length > 0;
276
+ if (isBusiness) {
277
+ const { wid, ...businessInfo } = businessProfile;
278
+
279
+ return {
280
+ jid: id,
281
+ exists: true,
282
+ lid: lid,
283
+ status: 'business',
284
+ businessInfo: businessInfo
285
+ };
286
+ } else {
287
+ return {
288
+ jid: id,
289
+ exists: true,
290
+ lid: lid,
291
+ status: 'regular'
292
+ };
293
+ }
294
+ } catch (error) {
295
+ return {
296
+ jid: id,
297
+ exists: true,
298
+ lid: lid,
299
+ status: error
300
+ };
301
+ }
302
+ })
303
+ );
304
+ return verifiedResults;
169
305
  }
170
306
  };
171
- const fetchDisappearingDuration = async (...jids) => {
172
- const usyncQuery = new WAUSync_1.USyncQuery()
173
- .withDisappearingModeProtocol();
174
- for (const jid of jids) {
175
- usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
176
- }
177
- const result = await sock.executeUSyncQuery(usyncQuery);
307
+ const fetchStatus = async (jid) => {
308
+ const [result] = await interactiveQuery([{ tag: 'user', attrs: { jid } }], { tag: 'status', attrs: {} });
178
309
  if (result) {
179
- return result.list;
310
+ const status = (0, WABinary_1.getBinaryNodeChild)(result, 'status');
311
+ return {
312
+ status: status === null || status === void 0 ? void 0 : status.content.toString(),
313
+ setAt: new Date(+((status === null || status === void 0 ? void 0 : status.attrs.t) || 0) * 1000)
314
+ };
180
315
  }
181
316
  };
182
317
  /** update the profile picture for yourself or a group */
@@ -278,51 +413,6 @@ const makeChatsSocket = (config) => {
278
413
  ]
279
414
  });
280
415
  };
281
- const getBusinessProfile = async (jid) => {
282
- var _a, _b, _c, _d, _e, _f, _g;
283
- const results = await query({
284
- tag: 'iq',
285
- attrs: {
286
- to: 's.whatsapp.net',
287
- xmlns: 'w:biz',
288
- type: 'get'
289
- },
290
- content: [{
291
- tag: 'business_profile',
292
- attrs: { v: '244' },
293
- content: [{
294
- tag: 'profile',
295
- attrs: { jid }
296
- }]
297
- }]
298
- });
299
- const profileNode = (0, WABinary_1.getBinaryNodeChild)(results, 'business_profile');
300
- const profiles = (0, WABinary_1.getBinaryNodeChild)(profileNode, 'profile');
301
- if (profiles) {
302
- const address = (0, WABinary_1.getBinaryNodeChild)(profiles, 'address');
303
- const description = (0, WABinary_1.getBinaryNodeChild)(profiles, 'description');
304
- const website = (0, WABinary_1.getBinaryNodeChild)(profiles, 'website');
305
- const email = (0, WABinary_1.getBinaryNodeChild)(profiles, 'email');
306
- const category = (0, WABinary_1.getBinaryNodeChild)((0, WABinary_1.getBinaryNodeChild)(profiles, 'categories'), 'category');
307
- const businessHours = (0, WABinary_1.getBinaryNodeChild)(profiles, 'business_hours');
308
- const businessHoursConfig = businessHours
309
- ? (0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config')
310
- : undefined;
311
- const websiteStr = (_a = website === null || website === void 0 ? void 0 : website.content) === null || _a === void 0 ? void 0 : _a.toString();
312
- return {
313
- wid: (_b = profiles.attrs) === null || _b === void 0 ? void 0 : _b.jid,
314
- address: (_c = address === null || address === void 0 ? void 0 : address.content) === null || _c === void 0 ? void 0 : _c.toString(),
315
- description: ((_d = description === null || description === void 0 ? void 0 : description.content) === null || _d === void 0 ? void 0 : _d.toString()) || '',
316
- website: websiteStr ? [websiteStr] : [],
317
- email: (_e = email === null || email === void 0 ? void 0 : email.content) === null || _e === void 0 ? void 0 : _e.toString(),
318
- category: (_f = category === null || category === void 0 ? void 0 : category.content) === null || _f === void 0 ? void 0 : _f.toString(),
319
- 'business_hours': {
320
- timezone: (_g = businessHours === null || businessHours === void 0 ? void 0 : businessHours.attrs) === null || _g === void 0 ? void 0 : _g.timezone,
321
- 'business_config': businessHoursConfig === null || businessHoursConfig === void 0 ? void 0 : businessHoursConfig.map(({ attrs }) => attrs)
322
- }
323
- };
324
- }
325
- };
326
416
  const cleanDirtyBits = async (type, fromTimestamp) => {
327
417
  logger.info({ fromTimestamp }, 'clean dirty bits ' + type);
328
418
  await sendNode({
@@ -416,12 +506,16 @@ const makeChatsSocket = (config) => {
416
506
  states[name] = newState;
417
507
  Object.assign(globalMutationMap, mutationMap);
418
508
  logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
419
- await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
509
+ await authState.keys.set({ 'app-state-sync-version': {
510
+ [name]: newState
511
+ } });
420
512
  }
421
513
  // only process if there are syncd patches
422
514
  if (patches.length) {
423
515
  const { state: newState, mutationMap } = await (0, Utils_1.decodePatches)(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
424
- await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
516
+ await authState.keys.set({ 'app-state-sync-version': {
517
+ [name]: newState
518
+ } });
425
519
  logger.info(`synced ${name} to v${newState.version}`);
426
520
  initialVersionMap[name] = newState.version;
427
521
  Object.assign(globalMutationMap, mutationMap);
@@ -436,11 +530,13 @@ const makeChatsSocket = (config) => {
436
530
  catch (error) {
437
531
  // if retry attempts overshoot
438
532
  // or key not found
439
- const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS
440
- || ((_a = error.output) === null || _a === void 0 ? void 0 : _a.statusCode) === 404
441
- || error.name === 'TypeError';
533
+ const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS ||
534
+ ((_a = error.output) === null || _a === void 0 ? void 0 : _a.statusCode) === 404 ||
535
+ error.name === 'TypeError';
442
536
  logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
443
- await authState.keys.set({ 'app-state-sync-version': { [name]: null } });
537
+ await authState.keys.set({ 'app-state-sync-version': {
538
+ [name]: null
539
+ } });
444
540
  // increment number of retries
445
541
  attemptsMap[name] = (attemptsMap[name] || 0) + 1;
446
542
  if (isIrrecoverableError) {
@@ -490,7 +586,7 @@ const makeChatsSocket = (config) => {
490
586
  await sendNode({
491
587
  tag: 'presence',
492
588
  attrs: {
493
- name: me.name.replace(/@/g, ''),
589
+ name: me.name,
494
590
  type
495
591
  }
496
592
  });
@@ -524,22 +620,22 @@ const makeChatsSocket = (config) => {
524
620
  id: generateMessageTag(),
525
621
  type: 'subscribe'
526
622
  },
527
- content: tcToken
528
- ? [
623
+ content: tcToken ?
624
+ [
529
625
  {
530
626
  tag: 'tctoken',
531
627
  attrs: {},
532
628
  content: tcToken
533
629
  }
534
- ]
535
- : undefined
630
+ ] :
631
+ undefined
536
632
  }));
537
633
  const handlePresenceUpdate = ({ tag, attrs, content }) => {
538
634
  var _a;
539
635
  let presence;
540
636
  const jid = attrs.from;
541
637
  const participant = attrs.participant || attrs.from;
542
- if (shouldIgnoreJid(jid) && jid != '@s.whatsapp.net') {
638
+ if (shouldIgnoreJid(jid) && jid !== '@s.whatsapp.net') {
543
639
  return;
544
640
  }
545
641
  if (tag === 'presence') {
@@ -563,7 +659,9 @@ const makeChatsSocket = (config) => {
563
659
  logger.error({ tag, attrs, content }, 'recv invalid presence node');
564
660
  }
565
661
  if (presence) {
566
- ev.emit('presence.update', { id: jid, presences: { [participant]: presence } });
662
+ ev.emit('presence.update', { id: jid, presences: {
663
+ [participant]: presence
664
+ } });
567
665
  }
568
666
  };
569
667
  const appPatch = async (patchCreate) => {
@@ -614,7 +712,9 @@ const makeChatsSocket = (config) => {
614
712
  ]
615
713
  };
616
714
  await query(node);
617
- await authState.keys.set({ 'app-state-sync-version': { [name]: state } });
715
+ await authState.keys.set({ 'app-state-sync-version': {
716
+ [name]: state
717
+ } });
618
718
  });
619
719
  });
620
720
  if (config.emitOwnEvents) {
@@ -627,7 +727,7 @@ const makeChatsSocket = (config) => {
627
727
  };
628
728
  /** sending non-abt props may fix QR scan fail if server expects */
629
729
  const fetchProps = async () => {
630
- var _a, _b, _c;
730
+ var _a, _b;
631
731
  const resultNode = await query({
632
732
  tag: 'iq',
633
733
  attrs: {
@@ -636,19 +736,20 @@ const makeChatsSocket = (config) => {
636
736
  type: 'get',
637
737
  },
638
738
  content: [
639
- { tag: 'props', attrs: {
739
+ {
740
+ tag: 'props',
741
+ attrs: {
640
742
  protocol: '2',
641
743
  hash: ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.lastPropHash) || ''
642
- } }
744
+ }
745
+ }
643
746
  ]
644
747
  });
645
748
  const propsNode = (0, WABinary_1.getBinaryNodeChild)(resultNode, 'props');
646
749
  let props = {};
647
750
  if (propsNode) {
648
- if ((_b = propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash) { // on some clients, the hash is returning as undefined
649
- authState.creds.lastPropHash = (_c = propsNode === null || propsNode === void 0 ? void 0 : propsNode.attrs) === null || _c === void 0 ? void 0 : _c.hash;
650
- ev.emit('creds.update', authState.creds);
651
- }
751
+ authState.creds.lastPropHash = (_b = propsNode === null || propsNode === void 0 ? void 0 : propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash;
752
+ ev.emit('creds.update', authState.creds);
652
753
  props = (0, WABinary_1.reduceBinaryNodeToDictionary)(propsNode, 'prop');
653
754
  }
654
755
  logger.debug('fetched props');
@@ -658,7 +759,7 @@ const makeChatsSocket = (config) => {
658
759
  * modify a chat -- mark unread, read etc.
659
760
  * lastMessages must be sorted in reverse chronologically
660
761
  * requires the last messages till the last message received; required for archive & unread
661
- */
762
+ */
662
763
  const chatModify = (mod, jid) => {
663
764
  const patch = (0, Utils_1.chatModificationToAppPatch)(mod, jid);
664
765
  return appPatch(patch);
@@ -742,25 +843,24 @@ const makeChatsSocket = (config) => {
742
843
  }
743
844
  }
744
845
  const historyMsg = (0, Utils_1.getHistoryMsg)(msg.message);
745
- const shouldProcessHistoryMsg = historyMsg
746
- ? (shouldSyncHistoryMessage(historyMsg)
747
- && Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType))
748
- : false;
846
+ const shouldProcessHistoryMsg = historyMsg ?
847
+ (shouldSyncHistoryMessage(historyMsg) &&
848
+ Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType)) :
849
+ false;
749
850
  if (historyMsg && !authState.creds.myAppStateKeyId) {
750
851
  logger.warn('skipping app state sync, as myAppStateKeyId is not set');
751
852
  pendingAppStateSync = true;
752
853
  }
753
854
  await Promise.all([
754
855
  (async () => {
755
- if (historyMsg
756
- && authState.creds.myAppStateKeyId) {
856
+ if (historyMsg &&
857
+ authState.creds.myAppStateKeyId) {
757
858
  pendingAppStateSync = false;
758
859
  await doAppStateSync();
759
860
  }
760
861
  })(),
761
862
  (0, process_message_1.default)(msg, {
762
863
  shouldProcessHistoryMsg,
763
- placeholderResendCache,
764
864
  ev,
765
865
  creds: authState.creds,
766
866
  keyStore: authState.keys,
@@ -769,8 +869,8 @@ const makeChatsSocket = (config) => {
769
869
  getMessage: config.getMessage,
770
870
  })
771
871
  ]);
772
- if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare)
773
- && pendingAppStateSync) {
872
+ if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare) &&
873
+ pendingAppStateSync) {
774
874
  await doAppStateSync();
775
875
  pendingAppStateSync = false;
776
876
  }
@@ -821,17 +921,18 @@ const makeChatsSocket = (config) => {
821
921
  sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
822
922
  .catch(error => onUnexpectedError(error, 'presence update requests'));
823
923
  }
824
- if (receivedPendingNotifications && // if we don't have the app state key
924
+ if (receivedPendingNotifications) {
925
+ // if we don't have the app state key
825
926
  // we keep buffering events until we finally have
826
927
  // the key and can sync the messages
827
- !((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId)) {
828
- ev.buffer();
829
- needToFlushWithAppStateSync = true;
928
+ if (!((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId) && !config.mobile) {
929
+ ev.buffer();
930
+ needToFlushWithAppStateSync = true;
931
+ }
830
932
  }
831
933
  });
832
934
  return {
833
935
  ...sock,
834
- getBotListV2,
835
936
  processingMutex,
836
937
  fetchPrivacySettings,
837
938
  upsertMessage,
@@ -841,15 +942,12 @@ const makeChatsSocket = (config) => {
841
942
  profilePictureUrl,
842
943
  onWhatsApp,
843
944
  fetchBlocklist,
844
- fetchDisappearingDuration,
845
945
  fetchStatus,
846
946
  updateProfilePicture,
847
947
  removeProfilePicture,
848
948
  updateProfileStatus,
849
949
  updateProfileName,
850
950
  updateBlockStatus,
851
- updateCallPrivacy,
852
- updateMessagesPrivacy,
853
951
  updateLastSeenPrivacy,
854
952
  updateOnlinePrivacy,
855
953
  updateProfilePicturePrivacy,
@@ -864,6 +962,7 @@ const makeChatsSocket = (config) => {
864
962
  addChatLabel,
865
963
  removeChatLabel,
866
964
  addMessageLabel,
965
+ checkStatusWA,
867
966
  removeMessageLabel,
868
967
  star
869
968
  };