dibosockets 1.0.3 → 1.0.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.
- package/WAProto/WAProto.proto +1013 -169
- package/lib/Api/Internet/growagarden.js +28 -0
- package/lib/Api/creator.json +13 -0
- package/lib/Api/downloader/tiktokdownload.js +132 -0
- package/lib/Api/index.js +38 -0
- package/lib/Api/nsfw/loli.js +79 -0
- package/lib/Api/stalker/githubstalk.js +46 -0
- package/lib/Api/stalker/stalkroblox.js +94 -0
- package/lib/Api/stalker/tiktokstalk.js +68 -0
- package/lib/Api/tools/ssweb.js +38 -0
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +50 -34
- package/lib/Defaults/phonenumber_mcc.json +223 -0
- package/lib/Socket/RHandler.js +158 -240
- package/lib/Socket/business.js +8 -2
- package/lib/Socket/chats.js +371 -142
- package/lib/Socket/communities.js +441 -0
- package/lib/Socket/index.js +43 -10
- package/lib/Socket/messages-recv.js +15 -4
- package/lib/Socket/messages-send.js +13 -35
- package/lib/Socket/newsletter.js +107 -124
- package/lib/Socket/socket.js +35 -23
- package/lib/Store/make-in-memory-store.js +2 -2
- package/lib/Types/Newsletter.js +18 -38
- package/lib/Utils/async-iterable.js +41 -0
- package/lib/Utils/baileys-event-stream.js +1 -1
- package/lib/Utils/browser-utils.js +35 -0
- package/lib/Utils/event-buffer.js +2 -2
- package/lib/Utils/generics.js +4 -0
- package/lib/Utils/index.js +3 -3
- package/lib/Utils/message-retry-manager.js +128 -0
- package/lib/Utils/messages-media.js +88 -49
- package/lib/Utils/messages.js +91 -16
- package/lib/Utils/process-message.js +19 -0
- package/lib/Utils/resolveJid.js +52 -0
- package/lib/Utils/use-multi-file-auth-state.js +0 -3
- package/lib/Utils/validate-connection.js +77 -21
- package/lib/WABinary/jid-utils.js +3 -1
- package/lib/index.js +2 -1
- package/package.json +2 -2
package/lib/Socket/chats.js
CHANGED
|
@@ -15,24 +15,38 @@ const process_message_1 = __importDefault(require("../Utils/process-message"));
|
|
|
15
15
|
const WABinary_1 = require("../WABinary");
|
|
16
16
|
const WAUSync_1 = require("../WAUSync");
|
|
17
17
|
const usync_1 = require("./usync");
|
|
18
|
+
const chalk = require('chalk');
|
|
18
19
|
const MAX_SYNC_ATTEMPTS = 2;
|
|
20
|
+
const SyncState = {
|
|
21
|
+
Connecting: 'connecting',
|
|
22
|
+
AwaitingInitialSync: 'awaiting_initial_sync',
|
|
23
|
+
Syncing: 'syncing',
|
|
24
|
+
Online: 'online'
|
|
25
|
+
};
|
|
19
26
|
const makeChatsSocket = (config) => {
|
|
20
|
-
const
|
|
27
|
+
const {
|
|
28
|
+
logger,
|
|
29
|
+
markOnlineOnConnect,
|
|
30
|
+
fireInitQueries,
|
|
31
|
+
appStateMacVerification,
|
|
32
|
+
shouldIgnoreJid,
|
|
33
|
+
shouldSyncHistoryMessage,
|
|
34
|
+
relayMessage, } = config;
|
|
21
35
|
const sock = (0, usync_1.makeUSyncSocket)(config);
|
|
22
|
-
const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError, } = sock;
|
|
36
|
+
const { ev, ws, authState, generateMessageTag, sendNode, query, signalRepository, onUnexpectedError, } = sock;
|
|
23
37
|
let privacySettings;
|
|
38
|
+
let syncState = SyncState.Connecting;
|
|
24
39
|
let needToFlushWithAppStateSync = false;
|
|
25
40
|
let pendingAppStateSync = false;
|
|
26
|
-
|
|
41
|
+
let awaitingSyncTimeout;
|
|
27
42
|
const processingMutex = (0, make_mutex_1.makeMutex)();
|
|
28
43
|
const placeholderResendCache = config.placeholderResendCache || new node_cache_1.default({
|
|
29
|
-
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
|
|
44
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
|
|
30
45
|
useClones: false
|
|
31
46
|
});
|
|
32
47
|
if (!config.placeholderResendCache) {
|
|
33
48
|
config.placeholderResendCache = placeholderResendCache;
|
|
34
49
|
}
|
|
35
|
-
/** helper function to fetch the given app state sync key */
|
|
36
50
|
const getAppStateSyncKey = async (keyId) => {
|
|
37
51
|
const { [keyId]: key } = await authState.keys.get('app-state-sync-key', [keyId]);
|
|
38
52
|
return key;
|
|
@@ -54,7 +68,6 @@ const makeChatsSocket = (config) => {
|
|
|
54
68
|
}
|
|
55
69
|
return privacySettings;
|
|
56
70
|
};
|
|
57
|
-
/** helper function to run a privacy IQ query */
|
|
58
71
|
const privacyQuery = async (name, value) => {
|
|
59
72
|
await query({
|
|
60
73
|
tag: 'iq',
|
|
@@ -99,6 +112,9 @@ const makeChatsSocket = (config) => {
|
|
|
99
112
|
const updateGroupsAddPrivacy = async (value) => {
|
|
100
113
|
await privacyQuery('groupadd', value);
|
|
101
114
|
};
|
|
115
|
+
const updateDisableLinkPreviewsPrivacy = async (isPreviewsDisabled) => {
|
|
116
|
+
return chatModify({ disableLinkPreviews: { isPreviewsDisabled } }, '');
|
|
117
|
+
};
|
|
102
118
|
const updateDefaultDisappearingMode = async (duration) => {
|
|
103
119
|
await query({
|
|
104
120
|
tag: 'iq',
|
|
@@ -168,7 +184,100 @@ const makeChatsSocket = (config) => {
|
|
|
168
184
|
return result.list;
|
|
169
185
|
}
|
|
170
186
|
};
|
|
171
|
-
const
|
|
187
|
+
const cekid = async (link) => {
|
|
188
|
+
try {
|
|
189
|
+
let url;
|
|
190
|
+
try {
|
|
191
|
+
url = new URL(link);
|
|
192
|
+
} catch {
|
|
193
|
+
return {
|
|
194
|
+
link,
|
|
195
|
+
jid: "-",
|
|
196
|
+
exists: false,
|
|
197
|
+
IsBanned: true,
|
|
198
|
+
metadata: "-",
|
|
199
|
+
error: "Invalid link format"
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const isChannel =
|
|
204
|
+
url.hostname === "whatsapp.com" &&
|
|
205
|
+
url.pathname.startsWith("/channel/");
|
|
206
|
+
|
|
207
|
+
if (!isChannel) {
|
|
208
|
+
return {
|
|
209
|
+
link,
|
|
210
|
+
jid: "-",
|
|
211
|
+
exists: false,
|
|
212
|
+
IsBanned: true,
|
|
213
|
+
metadata: "-",
|
|
214
|
+
error: "Link bukan link channel WhatsApp"
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const code = url.pathname.split("/channel/")[1]?.split("/")[0];
|
|
219
|
+
|
|
220
|
+
if (!code) {
|
|
221
|
+
return {
|
|
222
|
+
link,
|
|
223
|
+
jid: "-",
|
|
224
|
+
exists: false,
|
|
225
|
+
IsBanned: true,
|
|
226
|
+
metadata: "-",
|
|
227
|
+
error: "Invalid channel code"
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
let data = null;
|
|
232
|
+
|
|
233
|
+
try {
|
|
234
|
+
data = await conn.newsletterMetadata("invite", code);
|
|
235
|
+
} catch {
|
|
236
|
+
data = await conn.newsletterMetadata(code).catch(() => null);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (!data?.id) {
|
|
240
|
+
return {
|
|
241
|
+
link,
|
|
242
|
+
jid: "-",
|
|
243
|
+
exists: false,
|
|
244
|
+
IsBanned: true,
|
|
245
|
+
metadata: "-",
|
|
246
|
+
error: "Gagal mengambil metadata channel"
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return {
|
|
251
|
+
link,
|
|
252
|
+
jid: data.id,
|
|
253
|
+
exists: true,
|
|
254
|
+
IsBanned: false,
|
|
255
|
+
metadata: {
|
|
256
|
+
id: data.id || "-",
|
|
257
|
+
name: data.name || "-",
|
|
258
|
+
description: data.description || "-",
|
|
259
|
+
subscribers: data.subscribers || "-",
|
|
260
|
+
ownerJid: data.ownerJid || "-",
|
|
261
|
+
invite: data.invite || "-",
|
|
262
|
+
verification: data.verification || "-",
|
|
263
|
+
state: data.state || "-",
|
|
264
|
+
creation: data.creation || "-"
|
|
265
|
+
},
|
|
266
|
+
error: null
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
} catch (e) {
|
|
270
|
+
return {
|
|
271
|
+
link,
|
|
272
|
+
jid: "-",
|
|
273
|
+
exists: false,
|
|
274
|
+
IsBanned: true,
|
|
275
|
+
metadata: "-",
|
|
276
|
+
error: e.message
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
const checkStatusWA = async (numberOrJid) => {
|
|
172
281
|
try {
|
|
173
282
|
const jid = numberOrJid.includes('@s.whatsapp.net')
|
|
174
283
|
? numberOrJid
|
|
@@ -179,31 +288,117 @@ const checkStatusWA = async (numberOrJid) => {
|
|
|
179
288
|
return {
|
|
180
289
|
jid,
|
|
181
290
|
IsBanned: true,
|
|
182
|
-
Statusbio:
|
|
183
|
-
setAt:
|
|
291
|
+
Statusbio: "-",
|
|
292
|
+
setAt: "-",
|
|
293
|
+
businessProfile: {
|
|
294
|
+
wid: "-",
|
|
295
|
+
address: "-",
|
|
296
|
+
description: "-",
|
|
297
|
+
website: "-",
|
|
298
|
+
email: "-",
|
|
299
|
+
category: "-",
|
|
300
|
+
business_hours: "-"
|
|
301
|
+
}
|
|
184
302
|
}
|
|
185
303
|
}
|
|
186
304
|
|
|
187
305
|
const fetched = await fetchStatus(jid).catch(() => [])
|
|
188
|
-
const status = fetched?.[0]?.status?.status ||
|
|
189
|
-
const setAt = fetched?.[0]?.status?.setAt ||
|
|
306
|
+
const status = fetched?.[0]?.status?.status || "-"
|
|
307
|
+
const setAt = fetched?.[0]?.status?.setAt || "-"
|
|
308
|
+
|
|
309
|
+
const business = await getBusinessProfile(jid).catch(() => null)
|
|
310
|
+
|
|
311
|
+
const businessProfile = business ? {
|
|
312
|
+
wid: business.wid || "-",
|
|
313
|
+
address: business.address || "-",
|
|
314
|
+
description: business.description || "-",
|
|
315
|
+
website: business.website?.[0] || "-",
|
|
316
|
+
email: business.email || "-",
|
|
317
|
+
category: business.category || "-",
|
|
318
|
+
business_hours: business.business_hours || "-"
|
|
319
|
+
} : {
|
|
320
|
+
wid: "-",
|
|
321
|
+
address: "-",
|
|
322
|
+
description: "-",
|
|
323
|
+
website: "-",
|
|
324
|
+
email: "-",
|
|
325
|
+
category: "-",
|
|
326
|
+
business_hours: "-"
|
|
327
|
+
}
|
|
190
328
|
|
|
191
329
|
return {
|
|
192
330
|
jid,
|
|
193
331
|
IsBanned: false,
|
|
194
332
|
Statusbio: status,
|
|
195
|
-
setAt
|
|
333
|
+
setAt,
|
|
334
|
+
businessProfile
|
|
196
335
|
}
|
|
197
336
|
} catch (e) {
|
|
198
337
|
return {
|
|
199
338
|
jid: numberOrJid,
|
|
200
339
|
IsBanned: true,
|
|
201
|
-
Statusbio:
|
|
202
|
-
setAt:
|
|
340
|
+
Statusbio: "-",
|
|
341
|
+
setAt: "-",
|
|
342
|
+
businessProfile: {
|
|
343
|
+
wid: "-",
|
|
344
|
+
address: "-",
|
|
345
|
+
description: "-",
|
|
346
|
+
website: "-",
|
|
347
|
+
email: "-",
|
|
348
|
+
category: "-",
|
|
349
|
+
business_hours: "-"
|
|
350
|
+
},
|
|
203
351
|
error: e.message
|
|
204
352
|
}
|
|
205
353
|
}
|
|
206
|
-
}
|
|
354
|
+
};
|
|
355
|
+
const getBusinessProfile = async (jid) => {
|
|
356
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
357
|
+
const results = await query({
|
|
358
|
+
tag: 'iq',
|
|
359
|
+
attrs: {
|
|
360
|
+
to: 's.whatsapp.net',
|
|
361
|
+
xmlns: 'w:biz',
|
|
362
|
+
type: 'get'
|
|
363
|
+
},
|
|
364
|
+
content: [{
|
|
365
|
+
tag: 'business_profile',
|
|
366
|
+
attrs: { v: '244' },
|
|
367
|
+
content: [{
|
|
368
|
+
tag: 'profile',
|
|
369
|
+
attrs: { jid }
|
|
370
|
+
}]
|
|
371
|
+
}]
|
|
372
|
+
});
|
|
373
|
+
const profileNode = (0, WABinary_1.getBinaryNodeChild)(results, 'business_profile');
|
|
374
|
+
const profiles = (0, WABinary_1.getBinaryNodeChild)(profileNode, 'profile');
|
|
375
|
+
if (profiles) {
|
|
376
|
+
const address = (0, WABinary_1.getBinaryNodeChild)(profiles, 'address');
|
|
377
|
+
const description = (0, WABinary_1.getBinaryNodeChild)(profiles, 'description');
|
|
378
|
+
const website = (0, WABinary_1.getBinaryNodeChild)(profiles, 'website');
|
|
379
|
+
const email = (0, WABinary_1.getBinaryNodeChild)(profiles, 'email');
|
|
380
|
+
const category = (0, WABinary_1.getBinaryNodeChild)((0, WABinary_1.getBinaryNodeChild)(profiles, 'categories'), 'category');
|
|
381
|
+
const businessHours = (0, WABinary_1.getBinaryNodeChild)(profiles, 'business_hours');
|
|
382
|
+
const businessHoursConfig = businessHours ?
|
|
383
|
+
(0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config') :
|
|
384
|
+
undefined;
|
|
385
|
+
const websiteStr = (_a = website === null || website === void 0 ? void 0 : website.content) === null || _a === void 0 ? void 0 : _a.toString();
|
|
386
|
+
return {
|
|
387
|
+
wid: (_b = profiles.attrs) === null || _b === void 0 ? void 0 : _b.jid,
|
|
388
|
+
address: (_c = address === null || address === void 0 ? void 0 : address.content) === null || _c === void 0 ? void 0 : _c.toString(),
|
|
389
|
+
description: ((_d = description === null || description === void 0 ? void 0 : description.content) === null || _d === void 0 ? void 0 : _d.toString()) || '',
|
|
390
|
+
website: websiteStr ? [websiteStr] : [],
|
|
391
|
+
email: (_e = email === null || email === void 0 ? void 0 : email.content) === null || _e === void 0 ? void 0 : _e.toString(),
|
|
392
|
+
category: (_f = category === null || category === void 0 ? void 0 : category.content) === null || _f === void 0 ? void 0 : _f.toString(),
|
|
393
|
+
'business_hours': {
|
|
394
|
+
timezone: (_g = businessHours === null || businessHours === void 0 ? void 0 : businessHours.attrs) === null || _g === void 0 ? void 0 : _g.timezone,
|
|
395
|
+
'business_config': businessHoursConfig === null || businessHoursConfig === void 0 ? void 0 : businessHoursConfig.map(({ attrs }) => attrs)
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
|
|
207
402
|
const fetchDisappearingDuration = async (...jids) => {
|
|
208
403
|
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
209
404
|
.withDisappearingModeProtocol();
|
|
@@ -215,16 +410,15 @@ const checkStatusWA = async (numberOrJid) => {
|
|
|
215
410
|
return result.list;
|
|
216
411
|
}
|
|
217
412
|
};
|
|
218
|
-
|
|
219
|
-
const updateProfilePicture = async (jid, content) => {
|
|
413
|
+
const updateProfilePicture = async (jid, content, dimensions) => {
|
|
220
414
|
let targetJid;
|
|
221
415
|
if (!jid) {
|
|
222
416
|
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');
|
|
223
417
|
}
|
|
224
418
|
if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
|
|
225
|
-
targetJid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
419
|
+
targetJid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
226
420
|
}
|
|
227
|
-
const { img } = await (0, Utils_1.generateProfilePicture)(content);
|
|
421
|
+
const { img } = await (0, Utils_1.generateProfilePicture)(content, dimensions);
|
|
228
422
|
await query({
|
|
229
423
|
tag: 'iq',
|
|
230
424
|
attrs: {
|
|
@@ -242,14 +436,13 @@ const checkStatusWA = async (numberOrJid) => {
|
|
|
242
436
|
]
|
|
243
437
|
});
|
|
244
438
|
};
|
|
245
|
-
/** remove the profile picture for yourself or a group */
|
|
246
439
|
const removeProfilePicture = async (jid) => {
|
|
247
440
|
let targetJid;
|
|
248
441
|
if (!jid) {
|
|
249
442
|
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');
|
|
250
443
|
}
|
|
251
444
|
if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
|
|
252
|
-
targetJid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
445
|
+
targetJid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
253
446
|
}
|
|
254
447
|
await query({
|
|
255
448
|
tag: 'iq',
|
|
@@ -261,7 +454,6 @@ const checkStatusWA = async (numberOrJid) => {
|
|
|
261
454
|
}
|
|
262
455
|
});
|
|
263
456
|
};
|
|
264
|
-
/** update the profile status for yourself */
|
|
265
457
|
const updateProfileStatus = async (status) => {
|
|
266
458
|
await query({
|
|
267
459
|
tag: 'iq',
|
|
@@ -314,51 +506,7 @@ const checkStatusWA = async (numberOrJid) => {
|
|
|
314
506
|
]
|
|
315
507
|
});
|
|
316
508
|
};
|
|
317
|
-
|
|
318
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
319
|
-
const results = await query({
|
|
320
|
-
tag: 'iq',
|
|
321
|
-
attrs: {
|
|
322
|
-
to: 's.whatsapp.net',
|
|
323
|
-
xmlns: 'w:biz',
|
|
324
|
-
type: 'get'
|
|
325
|
-
},
|
|
326
|
-
content: [{
|
|
327
|
-
tag: 'business_profile',
|
|
328
|
-
attrs: { v: '244' },
|
|
329
|
-
content: [{
|
|
330
|
-
tag: 'profile',
|
|
331
|
-
attrs: { jid }
|
|
332
|
-
}]
|
|
333
|
-
}]
|
|
334
|
-
});
|
|
335
|
-
const profileNode = (0, WABinary_1.getBinaryNodeChild)(results, 'business_profile');
|
|
336
|
-
const profiles = (0, WABinary_1.getBinaryNodeChild)(profileNode, 'profile');
|
|
337
|
-
if (profiles) {
|
|
338
|
-
const address = (0, WABinary_1.getBinaryNodeChild)(profiles, 'address');
|
|
339
|
-
const description = (0, WABinary_1.getBinaryNodeChild)(profiles, 'description');
|
|
340
|
-
const website = (0, WABinary_1.getBinaryNodeChild)(profiles, 'website');
|
|
341
|
-
const email = (0, WABinary_1.getBinaryNodeChild)(profiles, 'email');
|
|
342
|
-
const category = (0, WABinary_1.getBinaryNodeChild)((0, WABinary_1.getBinaryNodeChild)(profiles, 'categories'), 'category');
|
|
343
|
-
const businessHours = (0, WABinary_1.getBinaryNodeChild)(profiles, 'business_hours');
|
|
344
|
-
const businessHoursConfig = businessHours
|
|
345
|
-
? (0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config')
|
|
346
|
-
: undefined;
|
|
347
|
-
const websiteStr = (_a = website === null || website === void 0 ? void 0 : website.content) === null || _a === void 0 ? void 0 : _a.toString();
|
|
348
|
-
return {
|
|
349
|
-
wid: (_b = profiles.attrs) === null || _b === void 0 ? void 0 : _b.jid,
|
|
350
|
-
address: (_c = address === null || address === void 0 ? void 0 : address.content) === null || _c === void 0 ? void 0 : _c.toString(),
|
|
351
|
-
description: ((_d = description === null || description === void 0 ? void 0 : description.content) === null || _d === void 0 ? void 0 : _d.toString()) || '',
|
|
352
|
-
website: websiteStr ? [websiteStr] : [],
|
|
353
|
-
email: (_e = email === null || email === void 0 ? void 0 : email.content) === null || _e === void 0 ? void 0 : _e.toString(),
|
|
354
|
-
category: (_f = category === null || category === void 0 ? void 0 : category.content) === null || _f === void 0 ? void 0 : _f.toString(),
|
|
355
|
-
'business_hours': {
|
|
356
|
-
timezone: (_g = businessHours === null || businessHours === void 0 ? void 0 : businessHours.attrs) === null || _g === void 0 ? void 0 : _g.timezone,
|
|
357
|
-
'business_config': businessHoursConfig === null || businessHoursConfig === void 0 ? void 0 : businessHoursConfig.map(({ attrs }) => attrs)
|
|
358
|
-
}
|
|
359
|
-
};
|
|
360
|
-
}
|
|
361
|
-
};
|
|
509
|
+
|
|
362
510
|
const cleanDirtyBits = async (type, fromTimestamp) => {
|
|
363
511
|
logger.info({ fromTimestamp }, 'clean dirty bits ' + type);
|
|
364
512
|
await sendNode({
|
|
@@ -388,18 +536,12 @@ const checkStatusWA = async (numberOrJid) => {
|
|
|
388
536
|
};
|
|
389
537
|
};
|
|
390
538
|
const resyncAppState = ev.createBufferedFunction(async (collections, isInitialSync) => {
|
|
391
|
-
// we use this to determine which events to fire
|
|
392
|
-
// otherwise when we resync from scratch -- all notifications will fire
|
|
393
539
|
const initialVersionMap = {};
|
|
394
540
|
const globalMutationMap = {};
|
|
395
541
|
await authState.keys.transaction(async () => {
|
|
396
542
|
var _a;
|
|
397
543
|
const collectionsToHandle = new Set(collections);
|
|
398
|
-
// in case something goes wrong -- ensure we don't enter a loop that cannot be exited from
|
|
399
544
|
const attemptsMap = {};
|
|
400
|
-
// keep executing till all collections are done
|
|
401
|
-
// sometimes a single patch request will not return all the patches (God knows why)
|
|
402
|
-
// so we fetch till they're all done (this is determined by the "has_more_patches" flag)
|
|
403
545
|
while (collectionsToHandle.size) {
|
|
404
546
|
const states = {};
|
|
405
547
|
const nodes = [];
|
|
@@ -421,7 +563,6 @@ const checkStatusWA = async (numberOrJid) => {
|
|
|
421
563
|
attrs: {
|
|
422
564
|
name,
|
|
423
565
|
version: state.version.toString(),
|
|
424
|
-
// return snapshot if being synced from scratch
|
|
425
566
|
'return_snapshot': (!state.version).toString()
|
|
426
567
|
}
|
|
427
568
|
});
|
|
@@ -441,7 +582,6 @@ const checkStatusWA = async (numberOrJid) => {
|
|
|
441
582
|
}
|
|
442
583
|
]
|
|
443
584
|
});
|
|
444
|
-
// extract from binary node
|
|
445
585
|
const decoded = await (0, Utils_1.extractSyncdPatches)(result, config === null || config === void 0 ? void 0 : config.options);
|
|
446
586
|
for (const key in decoded) {
|
|
447
587
|
const name = key;
|
|
@@ -454,7 +594,6 @@ const checkStatusWA = async (numberOrJid) => {
|
|
|
454
594
|
logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
|
|
455
595
|
await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
|
|
456
596
|
}
|
|
457
|
-
// only process if there are syncd patches
|
|
458
597
|
if (patches.length) {
|
|
459
598
|
const { state: newState, mutationMap } = await (0, Utils_1.decodePatches)(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
|
|
460
599
|
await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
|
|
@@ -465,22 +604,18 @@ const checkStatusWA = async (numberOrJid) => {
|
|
|
465
604
|
if (hasMorePatches) {
|
|
466
605
|
logger.info(`${name} has more patches...`);
|
|
467
606
|
}
|
|
468
|
-
else {
|
|
607
|
+
else {
|
|
469
608
|
collectionsToHandle.delete(name);
|
|
470
609
|
}
|
|
471
610
|
}
|
|
472
611
|
catch (error) {
|
|
473
|
-
// if retry attempts overshoot
|
|
474
|
-
// or key not found
|
|
475
612
|
const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS
|
|
476
613
|
|| ((_a = error.output) === null || _a === void 0 ? void 0 : _a.statusCode) === 404
|
|
477
614
|
|| error.name === 'TypeError';
|
|
478
615
|
logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
|
|
479
616
|
await authState.keys.set({ 'app-state-sync-version': { [name]: null } });
|
|
480
|
-
// increment number of retries
|
|
481
617
|
attemptsMap[name] = (attemptsMap[name] || 0) + 1;
|
|
482
618
|
if (isIrrecoverableError) {
|
|
483
|
-
// stop retrying
|
|
484
619
|
collectionsToHandle.delete(name);
|
|
485
620
|
}
|
|
486
621
|
}
|
|
@@ -492,28 +627,56 @@ const checkStatusWA = async (numberOrJid) => {
|
|
|
492
627
|
onMutation(globalMutationMap[key]);
|
|
493
628
|
}
|
|
494
629
|
});
|
|
495
|
-
/**
|
|
496
|
-
* fetch the profile picture of a user/group
|
|
497
|
-
* type = "preview" for a low res picture
|
|
498
|
-
* type = "image for the high res picture"
|
|
499
|
-
*/
|
|
500
630
|
const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
|
|
501
631
|
var _a;
|
|
502
632
|
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
633
|
+
try {
|
|
634
|
+
const result = await query({
|
|
635
|
+
tag: 'iq',
|
|
636
|
+
attrs: {
|
|
637
|
+
target: jid,
|
|
638
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
639
|
+
type: 'get',
|
|
640
|
+
xmlns: 'w:profile:picture'
|
|
641
|
+
},
|
|
642
|
+
content: [
|
|
643
|
+
{ tag: 'picture', attrs: { type, query: 'url' } }
|
|
644
|
+
]
|
|
645
|
+
}, timeoutMs);
|
|
646
|
+
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'picture');
|
|
647
|
+
return (_a = child === null || child === void 0 ? void 0 : child.attrs) === null || _a === void 0 ? void 0 : _a.url;
|
|
648
|
+
} catch (error) {
|
|
649
|
+
if (error.message?.includes('item-not-found') ||
|
|
650
|
+
error.output?.payload?.statusCode === 404 ||
|
|
651
|
+
error.statusCode === 404) {
|
|
652
|
+
logger.info(chalk.gray(`[INFO] Profile pic not found for ${jid}, using fallback`));
|
|
653
|
+
return {
|
|
654
|
+
eurl: undefined,
|
|
655
|
+
id: jid.split('@')[0],
|
|
656
|
+
status: null,
|
|
657
|
+
img: null
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
throw error;
|
|
661
|
+
}
|
|
662
|
+
};
|
|
663
|
+
const createCallLink = async (type, event, timeoutMs) => {
|
|
503
664
|
const result = await query({
|
|
504
|
-
tag: '
|
|
665
|
+
tag: 'call',
|
|
505
666
|
attrs: {
|
|
506
|
-
|
|
507
|
-
to:
|
|
508
|
-
type: 'get',
|
|
509
|
-
xmlns: 'w:profile:picture'
|
|
667
|
+
id: generateMessageTag(),
|
|
668
|
+
to: '@call'
|
|
510
669
|
},
|
|
511
670
|
content: [
|
|
512
|
-
{
|
|
671
|
+
{
|
|
672
|
+
tag: 'link_create',
|
|
673
|
+
attrs: { media: type },
|
|
674
|
+
content: event ? [{ tag: 'event', attrs: { start_time: String(event.startTime) } }] : undefined
|
|
675
|
+
}
|
|
513
676
|
]
|
|
514
677
|
}, timeoutMs);
|
|
515
|
-
const child = (0, WABinary_1.getBinaryNodeChild)(result, '
|
|
516
|
-
return
|
|
678
|
+
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'link_create');
|
|
679
|
+
return child?.attrs?.token;
|
|
517
680
|
};
|
|
518
681
|
const sendPresenceUpdate = async (type, toJid) => {
|
|
519
682
|
const me = authState.creds.me;
|
|
@@ -549,10 +712,6 @@ const checkStatusWA = async (numberOrJid) => {
|
|
|
549
712
|
});
|
|
550
713
|
}
|
|
551
714
|
};
|
|
552
|
-
/**
|
|
553
|
-
* @param toJid the jid to subscribe to
|
|
554
|
-
* @param tcToken token for subscription, use if present
|
|
555
|
-
*/
|
|
556
715
|
const presenceSubscribe = (toJid, tcToken) => (sendNode({
|
|
557
716
|
tag: 'presence',
|
|
558
717
|
attrs: {
|
|
@@ -661,7 +820,6 @@ const checkStatusWA = async (numberOrJid) => {
|
|
|
661
820
|
}
|
|
662
821
|
}
|
|
663
822
|
};
|
|
664
|
-
/** sending non-abt props may fix QR scan fail if server expects */
|
|
665
823
|
const fetchProps = async () => {
|
|
666
824
|
var _a, _b, _c;
|
|
667
825
|
const resultNode = await query({
|
|
@@ -681,7 +839,7 @@ const checkStatusWA = async (numberOrJid) => {
|
|
|
681
839
|
const propsNode = (0, WABinary_1.getBinaryNodeChild)(resultNode, 'props');
|
|
682
840
|
let props = {};
|
|
683
841
|
if (propsNode) {
|
|
684
|
-
if ((_b = propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash) {
|
|
842
|
+
if ((_b = propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash) {
|
|
685
843
|
authState.creds.lastPropHash = (_c = propsNode === null || propsNode === void 0 ? void 0 : propsNode.attrs) === null || _c === void 0 ? void 0 : _c.hash;
|
|
686
844
|
ev.emit('creds.update', authState.creds);
|
|
687
845
|
}
|
|
@@ -690,18 +848,10 @@ const checkStatusWA = async (numberOrJid) => {
|
|
|
690
848
|
logger.debug('fetched props');
|
|
691
849
|
return props;
|
|
692
850
|
};
|
|
693
|
-
/**
|
|
694
|
-
* modify a chat -- mark unread, read etc.
|
|
695
|
-
* lastMessages must be sorted in reverse chronologically
|
|
696
|
-
* requires the last messages till the last message received; required for archive & unread
|
|
697
|
-
*/
|
|
698
851
|
const chatModify = (mod, jid) => {
|
|
699
852
|
const patch = (0, Utils_1.chatModificationToAppPatch)(mod, jid);
|
|
700
853
|
return appPatch(patch);
|
|
701
854
|
};
|
|
702
|
-
/**
|
|
703
|
-
* Star or Unstar a message
|
|
704
|
-
*/
|
|
705
855
|
const star = (jid, messages, star) => {
|
|
706
856
|
return chatModify({
|
|
707
857
|
star: {
|
|
@@ -710,9 +860,56 @@ const checkStatusWA = async (numberOrJid) => {
|
|
|
710
860
|
}
|
|
711
861
|
}, jid);
|
|
712
862
|
};
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
863
|
+
const addOrEditContact = (jid, contact) => {
|
|
864
|
+
return chatModify({ contact }, jid);
|
|
865
|
+
};
|
|
866
|
+
const removeContact = (jid) => {
|
|
867
|
+
return chatModify({ contact: null }, jid);
|
|
868
|
+
};
|
|
869
|
+
|
|
870
|
+
const addLabelMember = async (jid, label, timestamp = Date.now()) => {
|
|
871
|
+
try {
|
|
872
|
+
return await relayMessage(
|
|
873
|
+
jid,
|
|
874
|
+
{
|
|
875
|
+
protocolMessage: {
|
|
876
|
+
type: 30,
|
|
877
|
+
memberLabel: {
|
|
878
|
+
label,
|
|
879
|
+
labelTimestamp: timestamp
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
},
|
|
883
|
+
{}
|
|
884
|
+
)
|
|
885
|
+
} catch (e) {
|
|
886
|
+
logger.error('Failed addLabelMember: ' + e)
|
|
887
|
+
throw e
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
const removeLabelMember = async (jid) => {
|
|
892
|
+
try {
|
|
893
|
+
return await relayMessage(
|
|
894
|
+
jid,
|
|
895
|
+
{
|
|
896
|
+
protocolMessage: {
|
|
897
|
+
type: 30,
|
|
898
|
+
memberLabel: {
|
|
899
|
+
label: ''
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
},
|
|
903
|
+
{}
|
|
904
|
+
)
|
|
905
|
+
} catch (e) {
|
|
906
|
+
logger.error('Failed removeLabelMember: ' + e)
|
|
907
|
+
throw e
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
const addLabel = (jid, labels) => {
|
|
911
|
+
return chatModify({ addLabel: { ...labels } }, jid);
|
|
912
|
+
};
|
|
716
913
|
const addChatLabel = (jid, labelId) => {
|
|
717
914
|
return chatModify({
|
|
718
915
|
addChatLabel: {
|
|
@@ -720,9 +917,6 @@ const checkStatusWA = async (numberOrJid) => {
|
|
|
720
917
|
}
|
|
721
918
|
}, jid);
|
|
722
919
|
};
|
|
723
|
-
/**
|
|
724
|
-
* Removes label for the chat
|
|
725
|
-
*/
|
|
726
920
|
const removeChatLabel = (jid, labelId) => {
|
|
727
921
|
return chatModify({
|
|
728
922
|
removeChatLabel: {
|
|
@@ -730,9 +924,6 @@ const checkStatusWA = async (numberOrJid) => {
|
|
|
730
924
|
}
|
|
731
925
|
}, jid);
|
|
732
926
|
};
|
|
733
|
-
/**
|
|
734
|
-
* Adds label for the message
|
|
735
|
-
*/
|
|
736
927
|
const addMessageLabel = (jid, messageId, labelId) => {
|
|
737
928
|
return chatModify({
|
|
738
929
|
addMessageLabel: {
|
|
@@ -741,9 +932,6 @@ const checkStatusWA = async (numberOrJid) => {
|
|
|
741
932
|
}
|
|
742
933
|
}, jid);
|
|
743
934
|
};
|
|
744
|
-
/**
|
|
745
|
-
* Removes label for the message
|
|
746
|
-
*/
|
|
747
935
|
const removeMessageLabel = (jid, messageId, labelId) => {
|
|
748
936
|
return chatModify({
|
|
749
937
|
removeMessageLabel: {
|
|
@@ -752,10 +940,6 @@ const checkStatusWA = async (numberOrJid) => {
|
|
|
752
940
|
}
|
|
753
941
|
}, jid);
|
|
754
942
|
};
|
|
755
|
-
/**
|
|
756
|
-
* queries need to be fired on connection open
|
|
757
|
-
* help ensure parity with WA Web
|
|
758
|
-
* */
|
|
759
943
|
const executeInitQueries = async () => {
|
|
760
944
|
await Promise.all([
|
|
761
945
|
fetchProps(),
|
|
@@ -772,7 +956,6 @@ const checkStatusWA = async (numberOrJid) => {
|
|
|
772
956
|
if (!msg.key.fromMe) {
|
|
773
957
|
ev.emit('contacts.update', [{ id: jid, notify: msg.pushName, verifiedName: msg.verifiedBizName }]);
|
|
774
958
|
}
|
|
775
|
-
// update our pushname too
|
|
776
959
|
if (msg.key.fromMe && msg.pushName && ((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.name) !== msg.pushName) {
|
|
777
960
|
ev.emit('creds.update', { me: { ...authState.creds.me, name: msg.pushName } });
|
|
778
961
|
}
|
|
@@ -782,6 +965,31 @@ const checkStatusWA = async (numberOrJid) => {
|
|
|
782
965
|
? (shouldSyncHistoryMessage(historyMsg)
|
|
783
966
|
&& Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType))
|
|
784
967
|
: false;
|
|
968
|
+
if (historyMsg && syncState === SyncState.AwaitingInitialSync) {
|
|
969
|
+
if (awaitingSyncTimeout) {
|
|
970
|
+
clearTimeout(awaitingSyncTimeout);
|
|
971
|
+
awaitingSyncTimeout = undefined;
|
|
972
|
+
}
|
|
973
|
+
if (shouldProcessHistoryMsg) {
|
|
974
|
+
syncState = SyncState.Syncing;
|
|
975
|
+
logger.info('Transitioned to Syncing state');
|
|
976
|
+
} else {
|
|
977
|
+
syncState = SyncState.Online;
|
|
978
|
+
logger.info('History sync skipped, transitioning to Online state and flushing buffer');
|
|
979
|
+
ev.flush();
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
const doAppStateSync = async () => {
|
|
983
|
+
if (syncState === SyncState.Syncing) {
|
|
984
|
+
logger.info('Doing app state sync');
|
|
985
|
+
await resyncAppState(Types_1.ALL_WA_PATCH_NAMES, true);
|
|
986
|
+
syncState = SyncState.Online;
|
|
987
|
+
logger.info('App state sync complete, transitioning to Online state and flushing buffer');
|
|
988
|
+
ev.flush();
|
|
989
|
+
const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
|
|
990
|
+
ev.emit('creds.update', { accountSyncCounter });
|
|
991
|
+
}
|
|
992
|
+
};
|
|
785
993
|
if (historyMsg && !authState.creds.myAppStateKeyId) {
|
|
786
994
|
logger.warn('skipping app state sync, as myAppStateKeyId is not set');
|
|
787
995
|
pendingAppStateSync = true;
|
|
@@ -795,6 +1003,7 @@ const checkStatusWA = async (numberOrJid) => {
|
|
|
795
1003
|
}
|
|
796
1004
|
})(),
|
|
797
1005
|
(0, process_message_1.default)(msg, {
|
|
1006
|
+
signalRepository,
|
|
798
1007
|
shouldProcessHistoryMsg,
|
|
799
1008
|
placeholderResendCache,
|
|
800
1009
|
ev,
|
|
@@ -810,18 +1019,6 @@ const checkStatusWA = async (numberOrJid) => {
|
|
|
810
1019
|
await doAppStateSync();
|
|
811
1020
|
pendingAppStateSync = false;
|
|
812
1021
|
}
|
|
813
|
-
async function doAppStateSync() {
|
|
814
|
-
if (!authState.creds.accountSyncCounter) {
|
|
815
|
-
logger.info('doing initial app state sync');
|
|
816
|
-
await resyncAppState(Types_1.ALL_WA_PATCH_NAMES, true);
|
|
817
|
-
const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
|
|
818
|
-
ev.emit('creds.update', { accountSyncCounter });
|
|
819
|
-
if (needToFlushWithAppStateSync) {
|
|
820
|
-
logger.debug('flushing with app state sync');
|
|
821
|
-
ev.flush();
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
1022
|
});
|
|
826
1023
|
ws.on('CB:presence', handlePresenceUpdate);
|
|
827
1024
|
ws.on('CB:chatstate', handlePresenceUpdate);
|
|
@@ -840,7 +1037,6 @@ const checkStatusWA = async (numberOrJid) => {
|
|
|
840
1037
|
}
|
|
841
1038
|
break;
|
|
842
1039
|
case 'groups':
|
|
843
|
-
// handled in groups.ts
|
|
844
1040
|
break;
|
|
845
1041
|
default:
|
|
846
1042
|
logger.info({ node }, 'received unknown sync');
|
|
@@ -857,16 +1053,43 @@ const checkStatusWA = async (numberOrJid) => {
|
|
|
857
1053
|
sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
|
|
858
1054
|
.catch(error => onUnexpectedError(error, 'presence update requests'));
|
|
859
1055
|
}
|
|
860
|
-
if (receivedPendingNotifications &&
|
|
861
|
-
// we keep buffering events until we finally have
|
|
862
|
-
// the key and can sync the messages
|
|
1056
|
+
if (receivedPendingNotifications &&
|
|
863
1057
|
!((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId)) {
|
|
864
1058
|
ev.buffer();
|
|
865
1059
|
needToFlushWithAppStateSync = true;
|
|
866
1060
|
}
|
|
1061
|
+
if (!receivedPendingNotifications || syncState !== SyncState.Connecting) {
|
|
1062
|
+
return;
|
|
1063
|
+
}
|
|
1064
|
+
syncState = SyncState.AwaitingInitialSync;
|
|
1065
|
+
logger.info('Connection is now AwaitingInitialSync, buffering events');
|
|
1066
|
+
ev.buffer();
|
|
1067
|
+
const willSyncHistory = shouldSyncHistoryMessage(
|
|
1068
|
+
WAProto_1.proto.Message.HistorySyncNotification.create({
|
|
1069
|
+
syncType: WAProto_1.proto.HistorySync.HistorySyncType.RECENT
|
|
1070
|
+
})
|
|
1071
|
+
);
|
|
1072
|
+
if (!willSyncHistory) {
|
|
1073
|
+
logger.info('History sync is disabled by config, not waiting for notification. Transitioning to Online.');
|
|
1074
|
+
syncState = SyncState.Online;
|
|
1075
|
+
setTimeout(() => ev.flush(), 0);
|
|
1076
|
+
return;
|
|
1077
|
+
}
|
|
1078
|
+
logger.info('History sync is enabled, awaiting notification with a 20s timeout.');
|
|
1079
|
+
if (awaitingSyncTimeout) {
|
|
1080
|
+
clearTimeout(awaitingSyncTimeout);
|
|
1081
|
+
}
|
|
1082
|
+
awaitingSyncTimeout = setTimeout(() => {
|
|
1083
|
+
if (syncState === SyncState.AwaitingInitialSync) {
|
|
1084
|
+
logger.warn('Timeout in AwaitingInitialSync, forcing state to Online and flushing buffer');
|
|
1085
|
+
syncState = SyncState.Online;
|
|
1086
|
+
ev.flush();
|
|
1087
|
+
}
|
|
1088
|
+
}, 20000);
|
|
867
1089
|
});
|
|
868
1090
|
return {
|
|
869
1091
|
...sock,
|
|
1092
|
+
createCallLink,
|
|
870
1093
|
getBotListV2,
|
|
871
1094
|
processingMutex,
|
|
872
1095
|
fetchPrivacySettings,
|
|
@@ -876,6 +1099,7 @@ const checkStatusWA = async (numberOrJid) => {
|
|
|
876
1099
|
presenceSubscribe,
|
|
877
1100
|
profilePictureUrl,
|
|
878
1101
|
onWhatsApp,
|
|
1102
|
+
checkStatusWA,
|
|
879
1103
|
fetchBlocklist,
|
|
880
1104
|
fetchDisappearingDuration,
|
|
881
1105
|
fetchStatus,
|
|
@@ -884,6 +1108,7 @@ const checkStatusWA = async (numberOrJid) => {
|
|
|
884
1108
|
updateProfileStatus,
|
|
885
1109
|
updateProfileName,
|
|
886
1110
|
updateBlockStatus,
|
|
1111
|
+
updateDisableLinkPreviewsPrivacy,
|
|
887
1112
|
updateCallPrivacy,
|
|
888
1113
|
updateMessagesPrivacy,
|
|
889
1114
|
updateLastSeenPrivacy,
|
|
@@ -897,12 +1122,16 @@ const checkStatusWA = async (numberOrJid) => {
|
|
|
897
1122
|
resyncAppState,
|
|
898
1123
|
chatModify,
|
|
899
1124
|
cleanDirtyBits,
|
|
1125
|
+
addOrEditContact,
|
|
1126
|
+
removeContact,
|
|
1127
|
+
addLabel,
|
|
900
1128
|
addChatLabel,
|
|
901
1129
|
removeChatLabel,
|
|
902
1130
|
addMessageLabel,
|
|
903
1131
|
removeMessageLabel,
|
|
904
1132
|
star,
|
|
905
|
-
|
|
1133
|
+
addLabelMember,
|
|
1134
|
+
removeLabelMember
|
|
906
1135
|
};
|
|
907
1136
|
};
|
|
908
1137
|
exports.makeChatsSocket = makeChatsSocket;
|