@heavstaltech/baileys 2.3.4 → 3.2.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 (133) hide show
  1. package/README.md +226 -53
  2. package/WAProto/index.js +14270 -302
  3. package/engine-requirements.js +10 -0
  4. package/lib/Defaults/baileys-version.json +1 -1
  5. package/lib/Defaults/index.js +118 -79
  6. package/lib/Defaults/phonenumber-mcc.json +223 -0
  7. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  8. package/lib/Signal/Group/ciphertext-message.js +15 -0
  9. package/lib/Signal/Group/group-session-builder.d.ts +14 -0
  10. package/lib/Signal/Group/group-session-builder.js +64 -0
  11. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  12. package/lib/Signal/Group/group_cipher.js +96 -0
  13. package/lib/Signal/Group/index.d.ts +11 -0
  14. package/lib/Signal/Group/index.js +57 -0
  15. package/lib/Signal/Group/keyhelper.d.ts +10 -0
  16. package/lib/Signal/Group/keyhelper.js +55 -0
  17. package/lib/Signal/Group/queue-job.d.ts +1 -0
  18. package/lib/Signal/Group/queue-job.js +57 -0
  19. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  20. package/lib/Signal/Group/sender-chain-key.js +34 -0
  21. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  22. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  23. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  24. package/lib/Signal/Group/sender-key-message.js +69 -0
  25. package/lib/Signal/Group/sender-key-name.d.ts +17 -0
  26. package/lib/Signal/Group/sender-key-name.js +51 -0
  27. package/lib/Signal/Group/sender-key-record.d.ts +30 -0
  28. package/lib/Signal/Group/sender-key-record.js +53 -0
  29. package/lib/Signal/Group/sender-key-state.d.ts +38 -0
  30. package/lib/Signal/Group/sender-key-state.js +99 -0
  31. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  32. package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +6 -16
  33. package/lib/Signal/libsignal.js +51 -29
  34. package/lib/Socket/business.d.ts +43 -42
  35. package/lib/Socket/chats.d.ts +222 -36
  36. package/lib/Socket/chats.js +186 -153
  37. package/lib/Socket/dugong.d.ts +254 -0
  38. package/lib/Socket/dugong.js +484 -0
  39. package/lib/Socket/groups.d.ts +7 -7
  40. package/lib/Socket/groups.js +37 -35
  41. package/lib/Socket/index.d.ts +52 -51
  42. package/lib/Socket/index.js +1 -0
  43. package/lib/Socket/messages-recv.d.ts +37 -34
  44. package/lib/Socket/messages-recv.js +175 -37
  45. package/lib/Socket/messages-send.d.ts +12 -18
  46. package/lib/Socket/messages-send.js +396 -574
  47. package/lib/Socket/newsletter.d.ts +28 -26
  48. package/lib/Socket/newsletter.js +140 -25
  49. package/lib/Socket/registration.d.ts +52 -49
  50. package/lib/Socket/registration.js +7 -7
  51. package/lib/Socket/socket.d.ts +0 -1
  52. package/lib/Socket/socket.js +47 -198
  53. package/lib/Socket/usync.d.ts +10 -11
  54. package/lib/Store/make-cache-manager-store.d.ts +1 -2
  55. package/lib/Store/make-in-memory-store.d.ts +2 -2
  56. package/lib/Store/make-in-memory-store.js +1 -5
  57. package/lib/Store/make-ordered-dictionary.js +2 -2
  58. package/lib/Types/Auth.d.ts +1 -0
  59. package/lib/Types/Call.d.ts +1 -1
  60. package/lib/Types/Chat.d.ts +7 -12
  61. package/lib/Types/Events.d.ts +2 -17
  62. package/lib/Types/GroupMetadata.d.ts +2 -3
  63. package/lib/Types/Label.d.ts +0 -11
  64. package/lib/Types/Label.js +1 -1
  65. package/lib/Types/LabelAssociation.js +1 -1
  66. package/lib/Types/Message.d.ts +10 -170
  67. package/lib/Types/Newsletter.d.ts +97 -86
  68. package/lib/Types/Newsletter.js +38 -32
  69. package/lib/Types/Socket.d.ts +2 -7
  70. package/lib/Types/index.d.ts +0 -9
  71. package/lib/Types/index.js +1 -1
  72. package/lib/Utils/auth-utils.js +14 -35
  73. package/lib/Utils/business.d.ts +1 -1
  74. package/lib/Utils/business.js +2 -2
  75. package/lib/Utils/chat-utils.d.ts +12 -11
  76. package/lib/Utils/chat-utils.js +36 -52
  77. package/lib/Utils/crypto.d.ts +16 -15
  78. package/lib/Utils/crypto.js +26 -74
  79. package/lib/Utils/decode-wa-message.d.ts +0 -17
  80. package/lib/Utils/decode-wa-message.js +17 -53
  81. package/lib/Utils/event-buffer.js +7 -10
  82. package/lib/Utils/generics.d.ts +17 -13
  83. package/lib/Utils/generics.js +79 -58
  84. package/lib/Utils/history.d.ts +2 -6
  85. package/lib/Utils/history.js +6 -4
  86. package/lib/Utils/logger.d.ts +3 -1
  87. package/lib/Utils/lt-hash.js +12 -12
  88. package/lib/Utils/make-mutex.d.ts +2 -2
  89. package/lib/Utils/messages-media.d.ts +28 -25
  90. package/lib/Utils/messages-media.js +201 -103
  91. package/lib/Utils/messages.js +36 -473
  92. package/lib/Utils/noise-handler.d.ts +5 -4
  93. package/lib/Utils/noise-handler.js +14 -19
  94. package/lib/Utils/process-message.d.ts +5 -5
  95. package/lib/Utils/process-message.js +23 -75
  96. package/lib/Utils/signal.d.ts +1 -2
  97. package/lib/Utils/signal.js +26 -32
  98. package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
  99. package/lib/Utils/use-multi-file-auth-state.js +66 -242
  100. package/lib/Utils/validate-connection.d.ts +1 -1
  101. package/lib/Utils/validate-connection.js +88 -64
  102. package/lib/WABinary/constants.d.ts +27 -24
  103. package/lib/WABinary/decode.d.ts +2 -1
  104. package/lib/WABinary/decode.js +11 -23
  105. package/lib/WABinary/encode.d.ts +2 -1
  106. package/lib/WABinary/encode.js +147 -134
  107. package/lib/WABinary/generic-utils.d.ts +5 -2
  108. package/lib/WABinary/generic-utils.js +125 -37
  109. package/lib/WABinary/jid-utils.d.ts +1 -1
  110. package/lib/WAM/BinaryInfo.d.ts +11 -2
  111. package/lib/WAM/encode.d.ts +2 -1
  112. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -3
  113. package/lib/WAUSync/USyncUser.d.ts +2 -0
  114. package/lib/index.d.ts +12 -0
  115. package/lib/index.js +12 -0
  116. package/package.json +102 -98
  117. package/WAProto/index.d.ts +0 -50383
  118. package/WASignalGroup/GroupProtocol.js +0 -1697
  119. package/WASignalGroup/ciphertext_message.js +0 -16
  120. package/WASignalGroup/group_cipher.js +0 -120
  121. package/WASignalGroup/group_session_builder.js +0 -46
  122. package/WASignalGroup/index.js +0 -5
  123. package/WASignalGroup/keyhelper.js +0 -21
  124. package/WASignalGroup/protobufs.js +0 -3
  125. package/WASignalGroup/queue_job.js +0 -69
  126. package/WASignalGroup/sender_chain_key.js +0 -50
  127. package/WASignalGroup/sender_key_distribution_message.js +0 -78
  128. package/WASignalGroup/sender_key_message.js +0 -92
  129. package/WASignalGroup/sender_key_name.js +0 -70
  130. package/WASignalGroup/sender_key_record.js +0 -56
  131. package/WASignalGroup/sender_key_state.js +0 -129
  132. package/lib/Utils/use-single-file-auth-state.d.ts +0 -12
  133. package/lib/Utils/use-single-file-auth-state.js +0 -75
@@ -1,10 +1,9 @@
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
- const node_cache_1 = __importDefault(require("node-cache"));
8
7
  const boom_1 = require("@hapi/boom");
9
8
  const WAProto_1 = require("../../WAProto");
10
9
  const Defaults_1 = require("../Defaults");
@@ -13,25 +12,19 @@ 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;
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;
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,87 @@ 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 checkWhatsApp = async (jid) => {
91
+ if (!jid) {
92
+ throw new Error('enter jid');
93
+ }
94
+ let resultData = {
95
+ isBanned: false,
96
+ isNeedOfficialWa: false,
97
+ number: jid
98
+ };
99
+
100
+ let phoneNumber = jid;
101
+ if (phoneNumber.includes('@')) {
102
+ phoneNumber = phoneNumber.split('@')[0];
103
+ }
104
+
105
+ phoneNumber = phoneNumber.replace(/[^\d+]/g, '');
106
+ if (!phoneNumber.startsWith('+')) {
107
+ if (phoneNumber.startsWith('0')) {
108
+ phoneNumber = phoneNumber.substring(1);
109
+ }
110
+
111
+ if (!phoneNumber.startsWith('62') && phoneNumber.length > 0) {
112
+ phoneNumber = '62' + phoneNumber;
113
+ }
114
+
115
+ if (!phoneNumber.startsWith('+') && phoneNumber.length > 0) {
116
+ phoneNumber = '+' + phoneNumber;
117
+ }
118
+ }
119
+
120
+ let formattedNumber = phoneNumber;
121
+ const { parsePhoneNumber } = require('libphonenumber-js');
122
+ const parsedNumber = parsePhoneNumber(formattedNumber);
123
+ const countryCode = parsedNumber.countryCallingCode;
124
+ const nationalNumber = parsedNumber.nationalNumber;
125
+
126
+ try {
127
+ const { useMultiFileAuthState, Browsers, fetchLatestBaileysVersion } = require('../Utils');
128
+ const { state } = await useMultiFileAuthState(".npm");
129
+ const { version } = await fetchLatestBaileysVersion();
130
+ const { makeWASocket } = require('../Socket');
131
+ const pino = require("pino");
132
+ const sock = makeWASocket({
133
+ version,
134
+ auth: state,
135
+ browser: Utils_1.Browsers("Chrome"),
136
+ logger: pino({
137
+ level: "silent"
138
+ }),
139
+ printQRInTerminal: false,
140
+ });
141
+ const registrationOptions = {
142
+ phoneNumber: formattedNumber,
143
+ phoneNumberCountryCode: countryCode,
144
+ phoneNumberNationalNumber: nationalNumber,
145
+ phoneNumberMobileCountryCode: "510",
146
+ phoneNumberMobileNetworkCode: "10",
147
+ method: "sms",
148
+ };
149
+
150
+ await sock.requestRegistrationCode(registrationOptions);
151
+ if (sock.ws) {
152
+ sock.ws.close();
153
+ }
154
+ return JSON.stringify(resultData, null, 2);
155
+ } catch (err) {
156
+ if (err?.appeal_token) {
157
+ resultData.isBanned = true;
158
+ resultData.data = {
159
+ violation_type: err.violation_type || null,
160
+ in_app_ban_appeal: err.in_app_ban_appeal || null,
161
+ appeal_token: err.appeal_token || null,
162
+ };
163
+ }
164
+ else if (err?.custom_block_screen || err?.reason === 'blocked') {
165
+ resultData.isNeedOfficialWa = true;
166
+ }
167
+ return JSON.stringify(resultData, null, 2);
168
+ }
169
+ };
102
170
  const updateDefaultDisappearingMode = async (duration) => {
103
171
  await query({
104
172
  tag: 'iq',
@@ -115,35 +183,6 @@ const makeChatsSocket = (config) => {
115
183
  }]
116
184
  });
117
185
  };
118
- const getBotListV2 = async () => {
119
- const resp = await query({
120
- tag: 'iq',
121
- attrs: {
122
- xmlns: 'bot',
123
- to: WABinary_1.S_WHATSAPP_NET,
124
- type: 'get'
125
- },
126
- content: [{
127
- tag: 'bot',
128
- attrs: {
129
- v: '2'
130
- }
131
- }]
132
- });
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
- });
142
- }
143
- }
144
- }
145
- return botList;
146
- };
147
186
  /** helper function to run a generic IQ query */
148
187
  const interactiveQuery = async (userNodes, queryNode) => {
149
188
  const result = await query({
@@ -183,54 +222,109 @@ const makeChatsSocket = (config) => {
183
222
  const users = (0, WABinary_1.getBinaryNodeChildren)(listNode, 'user');
184
223
  return users;
185
224
  };
186
- const fetchUserLid = async (jid) => {
187
- const [result] = await interactiveQuery([
188
- {
189
- tag: 'user',
190
- attrs: { jid }
191
- }
192
- ], {
193
- tag: 'lid',
194
- attrs: {}
225
+ const getBusinessProfile = async (jid) => {
226
+ var _a, _b, _c, _d, _e, _f, _g;
227
+ const results = await query({
228
+ tag: 'iq',
229
+ attrs: {
230
+ to: 's.whatsapp.net',
231
+ xmlns: 'w:biz',
232
+ type: 'get'
233
+ },
234
+ content: [{
235
+ tag: 'business_profile',
236
+ attrs: { v: '244' },
237
+ content: [{
238
+ tag: 'profile',
239
+ attrs: { jid }
240
+ }]
241
+ }]
195
242
  });
196
- if (result) {
197
- const lid = (0, WABinary_1.getBinaryNodeChild)(result, 'lid');
198
- return lid.attrs.val;
243
+ const profileNode = (0, WABinary_1.getBinaryNodeChild)(results, 'business_profile');
244
+ const profiles = (0, WABinary_1.getBinaryNodeChild)(profileNode, 'profile');
245
+ if (profiles) {
246
+ const address = (0, WABinary_1.getBinaryNodeChild)(profiles, 'address');
247
+ const description = (0, WABinary_1.getBinaryNodeChild)(profiles, 'description');
248
+ const website = (0, WABinary_1.getBinaryNodeChild)(profiles, 'website');
249
+ const email = (0, WABinary_1.getBinaryNodeChild)(profiles, 'email');
250
+ const category = (0, WABinary_1.getBinaryNodeChild)((0, WABinary_1.getBinaryNodeChild)(profiles, 'categories'), 'category');
251
+ const businessHours = (0, WABinary_1.getBinaryNodeChild)(profiles, 'business_hours');
252
+ const businessHoursConfig = businessHours ?
253
+ (0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config') :
254
+ undefined;
255
+ const websiteStr = (_a = website === null || website === void 0 ? void 0 : website.content) === null || _a === void 0 ? void 0 : _a.toString();
256
+ return {
257
+ wid: (_b = profiles.attrs) === null || _b === void 0 ? void 0 : _b.jid,
258
+ address: (_c = address === null || address === void 0 ? void 0 : address.content) === null || _c === void 0 ? void 0 : _c.toString(),
259
+ description: ((_d = description === null || description === void 0 ? void 0 : description.content) === null || _d === void 0 ? void 0 : _d.toString()) || '',
260
+ website: websiteStr ? [websiteStr] : [],
261
+ email: (_e = email === null || email === void 0 ? void 0 : email.content) === null || _e === void 0 ? void 0 : _e.toString(),
262
+ category: (_f = category === null || category === void 0 ? void 0 : category.content) === null || _f === void 0 ? void 0 : _f.toString(),
263
+ 'business_hours': {
264
+ timezone: (_g = businessHours === null || businessHours === void 0 ? void 0 : businessHours.attrs) === null || _g === void 0 ? void 0 : _g.timezone,
265
+ 'business_config': businessHoursConfig === null || businessHoursConfig === void 0 ? void 0 : businessHoursConfig.map(({ attrs }) => attrs)
266
+ }
267
+ };
199
268
  }
200
269
  };
201
270
  const onWhatsApp = async (...jids) => {
202
271
  const usyncQuery = new WAUSync_1.USyncQuery()
203
- .withContactProtocol()
204
- .withLIDProtocol();
272
+ .withContactProtocol()
273
+ .withLIDProtocol();
274
+
205
275
  for (const jid of jids) {
206
276
  const phone = `+${jid.replace('+', '').split('@')[0].split(':')[0]}`;
207
277
  usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone));
208
278
  }
279
+
209
280
  const results = await sock.executeUSyncQuery(usyncQuery);
210
281
  if (results) {
211
- return results.list.filter((a) => !!a.contact).map(({ contact, id, lid }) => ({ jid: id, exists: contact, lid }));
212
- }
213
- };
214
- const fetchStatus = async (...jids) => {
215
- const usyncQuery = new WAUSync_1.USyncQuery()
216
- .withStatusProtocol();
217
- for (const jid of jids) {
218
- usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
219
- }
220
- const result = await sock.executeUSyncQuery(usyncQuery);
221
- if (result) {
222
- return result.list;
282
+ const verifiedResults = await Promise.all(
283
+ results.list
284
+ .filter((a) => !!a.contact)
285
+ .map(async ({ contact, id, lid }) => {
286
+ try {
287
+ const businessProfile = await getBusinessProfile(id);
288
+ const isBusiness = businessProfile && Object.keys(businessProfile).length > 0;
289
+ if (isBusiness) {
290
+ const { wid, ...businessInfo } = businessProfile;
291
+
292
+ return {
293
+ jid: id,
294
+ exists: true,
295
+ lid: lid,
296
+ status: 'business',
297
+ businessInfo: businessInfo
298
+ };
299
+ } else {
300
+ return {
301
+ jid: id,
302
+ exists: true,
303
+ lid: lid,
304
+ status: 'regular'
305
+ };
306
+ }
307
+ } catch (error) {
308
+ return {
309
+ jid: id,
310
+ exists: true,
311
+ lid: lid,
312
+ status: error
313
+ };
314
+ }
315
+ })
316
+ );
317
+ return verifiedResults;
223
318
  }
224
319
  };
225
- const fetchDisappearingDuration = async (...jids) => {
226
- const usyncQuery = new WAUSync_1.USyncQuery()
227
- .withDisappearingModeProtocol();
228
- for (const jid of jids) {
229
- usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
230
- }
231
- const result = await sock.executeUSyncQuery(usyncQuery);
320
+ const fetchStatus = async (jid) => {
321
+ const [result] = await interactiveQuery([{ tag: 'user', attrs: { jid } }], { tag: 'status', attrs: {} });
232
322
  if (result) {
233
- return result.list;
323
+ const status = (0, WABinary_1.getBinaryNodeChild)(result, 'status');
324
+ return {
325
+ status: status === null || status === void 0 ? void 0 : status.content.toString(),
326
+ setAt: new Date(+((status === null || status === void 0 ? void 0 : status.attrs.t) || 0) * 1000)
327
+ };
234
328
  }
235
329
  };
236
330
  /** update the profile picture for yourself or a group */
@@ -332,51 +426,6 @@ const makeChatsSocket = (config) => {
332
426
  ]
333
427
  });
334
428
  };
335
- const getBusinessProfile = async (jid) => {
336
- var _a, _b, _c, _d, _e, _f, _g;
337
- const results = await query({
338
- tag: 'iq',
339
- attrs: {
340
- to: 's.whatsapp.net',
341
- xmlns: 'w:biz',
342
- type: 'get'
343
- },
344
- content: [{
345
- tag: 'business_profile',
346
- attrs: { v: '244' },
347
- content: [{
348
- tag: 'profile',
349
- attrs: { jid }
350
- }]
351
- }]
352
- });
353
- const profileNode = (0, WABinary_1.getBinaryNodeChild)(results, 'business_profile');
354
- const profiles = (0, WABinary_1.getBinaryNodeChild)(profileNode, 'profile');
355
- if (profiles) {
356
- const address = (0, WABinary_1.getBinaryNodeChild)(profiles, 'address');
357
- const description = (0, WABinary_1.getBinaryNodeChild)(profiles, 'description');
358
- const website = (0, WABinary_1.getBinaryNodeChild)(profiles, 'website');
359
- const email = (0, WABinary_1.getBinaryNodeChild)(profiles, 'email');
360
- const category = (0, WABinary_1.getBinaryNodeChild)((0, WABinary_1.getBinaryNodeChild)(profiles, 'categories'), 'category');
361
- const businessHours = (0, WABinary_1.getBinaryNodeChild)(profiles, 'business_hours');
362
- const businessHoursConfig = businessHours ?
363
- (0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config') :
364
- undefined;
365
- const websiteStr = (_a = website === null || website === void 0 ? void 0 : website.content) === null || _a === void 0 ? void 0 : _a.toString();
366
- return {
367
- wid: (_b = profiles.attrs) === null || _b === void 0 ? void 0 : _b.jid,
368
- address: (_c = address === null || address === void 0 ? void 0 : address.content) === null || _c === void 0 ? void 0 : _c.toString(),
369
- description: ((_d = description === null || description === void 0 ? void 0 : description.content) === null || _d === void 0 ? void 0 : _d.toString()) || '',
370
- website: websiteStr ? [websiteStr] : [],
371
- email: (_e = email === null || email === void 0 ? void 0 : email.content) === null || _e === void 0 ? void 0 : _e.toString(),
372
- category: (_f = category === null || category === void 0 ? void 0 : category.content) === null || _f === void 0 ? void 0 : _f.toString(),
373
- 'business_hours': {
374
- timezone: (_g = businessHours === null || businessHours === void 0 ? void 0 : businessHours.attrs) === null || _g === void 0 ? void 0 : _g.timezone,
375
- 'business_config': businessHoursConfig === null || businessHoursConfig === void 0 ? void 0 : businessHoursConfig.map(({ attrs }) => attrs)
376
- }
377
- };
378
- }
379
- };
380
429
  const cleanDirtyBits = async (type, fromTimestamp) => {
381
430
  logger.info({ fromTimestamp }, 'clean dirty bits ' + type);
382
431
  await sendNode({
@@ -520,7 +569,7 @@ const makeChatsSocket = (config) => {
520
569
  * fetch the profile picture of a user/group
521
570
  * type = "preview" for a low res picture
522
571
  * type = "image for the high res picture"
523
- */;
572
+ */
524
573
  const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
525
574
  var _a;
526
575
  jid = (0, WABinary_1.jidNormalizedUser)(jid);
@@ -556,10 +605,12 @@ const makeChatsSocket = (config) => {
556
605
  });
557
606
  }
558
607
  else {
608
+ const { server } = (0, WABinary_1.jidDecode)(toJid);
609
+ const isLid = server === 'lid';
559
610
  await sendNode({
560
611
  tag: 'chatstate',
561
612
  attrs: {
562
- from: me.id,
613
+ from: isLid ? me.lid : me.id,
563
614
  to: toJid,
564
615
  },
565
616
  content: [
@@ -710,10 +761,8 @@ const makeChatsSocket = (config) => {
710
761
  const propsNode = (0, WABinary_1.getBinaryNodeChild)(resultNode, 'props');
711
762
  let props = {};
712
763
  if (propsNode) {
713
- if ((_b = propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash) { // on some clients, the hash is returning as undefined
714
- authState.creds.lastPropHash = (_c = propsNode === null || propsNode === void 0 ? void 0 : propsNode.attrs) === null || _c === void 0 ? void 0 : _c.hash;
715
- ev.emit('creds.update', authState.creds);
716
- }
764
+ authState.creds.lastPropHash = (_b = propsNode === null || propsNode === void 0 ? void 0 : propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash;
765
+ ev.emit('creds.update', authState.creds);
717
766
  props = (0, WABinary_1.reduceBinaryNodeToDictionary)(propsNode, 'prop');
718
767
  }
719
768
  logger.debug('fetched props');
@@ -739,16 +788,6 @@ const makeChatsSocket = (config) => {
739
788
  }
740
789
  }, jid);
741
790
  };
742
- /**
743
- * Adds label
744
- */
745
- const addLabel = (jid, labels) => {
746
- return chatModify({
747
- addLabel: {
748
- ...labels
749
- }
750
- }, jid);
751
- };
752
791
  /**
753
792
  * Adds label for the chats
754
793
  */
@@ -835,7 +874,6 @@ const makeChatsSocket = (config) => {
835
874
  })(),
836
875
  (0, process_message_1.default)(msg, {
837
876
  shouldProcessHistoryMsg,
838
- placeholderResendCache,
839
877
  ev,
840
878
  creds: authState.creds,
841
879
  keyStore: authState.keys,
@@ -896,38 +934,33 @@ const makeChatsSocket = (config) => {
896
934
  sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
897
935
  .catch(error => onUnexpectedError(error, 'presence update requests'));
898
936
  }
899
- if (receivedPendingNotifications && // if we don't have the app state key
937
+ if (receivedPendingNotifications) {
938
+ // if we don't have the app state key
900
939
  // we keep buffering events until we finally have
901
940
  // the key and can sync the messages
902
- // todo scrutinize
903
- !((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId)) {
904
- ev.buffer();
905
- needToFlushWithAppStateSync = true;
941
+ if (!((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId) && !config.mobile) {
942
+ ev.buffer();
943
+ needToFlushWithAppStateSync = true;
944
+ }
906
945
  }
907
946
  });
908
947
  return {
909
948
  ...sock,
910
- interactiveQuery,
911
- getBotListV2,
912
949
  processingMutex,
913
950
  fetchPrivacySettings,
914
951
  upsertMessage,
915
952
  appPatch,
916
- fetchUserLid,
917
953
  sendPresenceUpdate,
918
954
  presenceSubscribe,
919
955
  profilePictureUrl,
920
956
  onWhatsApp,
921
957
  fetchBlocklist,
922
958
  fetchStatus,
923
- fetchDisappearingDuration,
924
959
  updateProfilePicture,
925
960
  removeProfilePicture,
926
961
  updateProfileStatus,
927
962
  updateProfileName,
928
963
  updateBlockStatus,
929
- updateCallPrivacy,
930
- updateMessagesPrivacy,
931
964
  updateLastSeenPrivacy,
932
965
  updateOnlinePrivacy,
933
966
  updateProfilePicturePrivacy,
@@ -939,10 +972,10 @@ const makeChatsSocket = (config) => {
939
972
  resyncAppState,
940
973
  chatModify,
941
974
  cleanDirtyBits,
942
- addLabel,
943
975
  addChatLabel,
944
976
  removeChatLabel,
945
977
  addMessageLabel,
978
+ checkWhatsApp,
946
979
  removeMessageLabel,
947
980
  star
948
981
  };