@dyyxyzz/baileys-mod 6.0.26 → 6.0.28
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/lib/Socket/chats.js +19 -0
- package/lib/Socket/chats.js.bak +981 -0
- package/lib/Socket/newsletter.js +17 -3
- package/lib/Utils/chat-utils.js +11 -2
- package/lib/index.js +5 -0
- package/package.json +3 -3
package/lib/Socket/chats.js
CHANGED
|
@@ -821,6 +821,23 @@ const makeChatsSocket = (config) => {
|
|
|
821
821
|
* queries need to be fired on connection open
|
|
822
822
|
* help ensure parity with WA Web
|
|
823
823
|
* */
|
|
824
|
+
|
|
825
|
+
const saveContact = (jid, fullName) => {
|
|
826
|
+
return chatModify({
|
|
827
|
+
contact: {
|
|
828
|
+
fullName,
|
|
829
|
+
lidJid: jid,
|
|
830
|
+
saveOnPrimaryAddressbook: true
|
|
831
|
+
}
|
|
832
|
+
}, jid);
|
|
833
|
+
};
|
|
834
|
+
|
|
835
|
+
const removeContact = (jid) => {
|
|
836
|
+
return chatModify({
|
|
837
|
+
contact: null
|
|
838
|
+
}, jid);
|
|
839
|
+
};
|
|
840
|
+
|
|
824
841
|
const executeInitQueries = async () => {
|
|
825
842
|
await Promise.all([
|
|
826
843
|
fetchProps(),
|
|
@@ -958,6 +975,8 @@ const makeChatsSocket = (config) => {
|
|
|
958
975
|
getBusinessProfile,
|
|
959
976
|
resyncAppState,
|
|
960
977
|
chatModify,
|
|
978
|
+
saveContact,
|
|
979
|
+
removeContact,
|
|
961
980
|
cleanDirtyBits,
|
|
962
981
|
addChatLabel,
|
|
963
982
|
removeChatLabel,
|
|
@@ -0,0 +1,981 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.makeChatsSocket = void 0;
|
|
7
|
+
const boom_1 = require("@hapi/boom");
|
|
8
|
+
const WAProto_1 = require("../../WAProto");
|
|
9
|
+
const Defaults_1 = require("../Defaults");
|
|
10
|
+
const Types_1 = require("../Types");
|
|
11
|
+
const Utils_1 = require("../Utils");
|
|
12
|
+
const make_mutex_1 = require("../Utils/make-mutex");
|
|
13
|
+
const process_message_1 = __importDefault(require("../Utils/process-message"));
|
|
14
|
+
const WABinary_1 = require("../WABinary");
|
|
15
|
+
const socket_1 = require("./socket");
|
|
16
|
+
const WAUSync_1 = require("../WAUSync");
|
|
17
|
+
const usync_1 = require("./usync");
|
|
18
|
+
const MAX_SYNC_ATTEMPTS = 2;
|
|
19
|
+
const makeChatsSocket = (config) => {
|
|
20
|
+
const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage, } = config;
|
|
21
|
+
const sock = (0, usync_1.makeUSyncSocket)(config);
|
|
22
|
+
const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError, } = sock;
|
|
23
|
+
let privacySettings;
|
|
24
|
+
let needToFlushWithAppStateSync = false;
|
|
25
|
+
let pendingAppStateSync = false;
|
|
26
|
+
/** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
|
|
27
|
+
const processingMutex = (0, make_mutex_1.makeMutex)();
|
|
28
|
+
/** helper function to fetch the given app state sync key */
|
|
29
|
+
const getAppStateSyncKey = async (keyId) => {
|
|
30
|
+
const { [keyId]: key } = await authState.keys.get('app-state-sync-key', [keyId]);
|
|
31
|
+
return key;
|
|
32
|
+
};
|
|
33
|
+
const fetchPrivacySettings = async (force = false) => {
|
|
34
|
+
if (!privacySettings || force) {
|
|
35
|
+
const { content } = await query({
|
|
36
|
+
tag: 'iq',
|
|
37
|
+
attrs: {
|
|
38
|
+
xmlns: 'privacy',
|
|
39
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
40
|
+
type: 'get'
|
|
41
|
+
},
|
|
42
|
+
content: [
|
|
43
|
+
{ tag: 'privacy', attrs: {} }
|
|
44
|
+
]
|
|
45
|
+
});
|
|
46
|
+
privacySettings = (0, WABinary_1.reduceBinaryNodeToDictionary)(content === null || content === void 0 ? void 0 : content[0], 'category');
|
|
47
|
+
}
|
|
48
|
+
return privacySettings;
|
|
49
|
+
};
|
|
50
|
+
/** helper function to run a privacy IQ query */
|
|
51
|
+
const privacyQuery = async (name, value) => {
|
|
52
|
+
await query({
|
|
53
|
+
tag: 'iq',
|
|
54
|
+
attrs: {
|
|
55
|
+
xmlns: 'privacy',
|
|
56
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
57
|
+
type: 'set'
|
|
58
|
+
},
|
|
59
|
+
content: [{
|
|
60
|
+
tag: 'privacy',
|
|
61
|
+
attrs: {},
|
|
62
|
+
content: [
|
|
63
|
+
{
|
|
64
|
+
tag: 'category',
|
|
65
|
+
attrs: { name, value }
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
}]
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
const updateLastSeenPrivacy = async (value) => {
|
|
72
|
+
await privacyQuery('last', value);
|
|
73
|
+
};
|
|
74
|
+
const updateOnlinePrivacy = async (value) => {
|
|
75
|
+
await privacyQuery('online', value);
|
|
76
|
+
};
|
|
77
|
+
const updateProfilePicturePrivacy = async (value) => {
|
|
78
|
+
await privacyQuery('profile', value);
|
|
79
|
+
};
|
|
80
|
+
const updateStatusPrivacy = async (value) => {
|
|
81
|
+
await privacyQuery('status', value);
|
|
82
|
+
};
|
|
83
|
+
const updateReadReceiptsPrivacy = async (value) => {
|
|
84
|
+
await privacyQuery('readreceipts', value);
|
|
85
|
+
};
|
|
86
|
+
const updateGroupsAddPrivacy = async (value) => {
|
|
87
|
+
await privacyQuery('groupadd', value);
|
|
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
|
+
};
|
|
157
|
+
const updateDefaultDisappearingMode = async (duration) => {
|
|
158
|
+
await query({
|
|
159
|
+
tag: 'iq',
|
|
160
|
+
attrs: {
|
|
161
|
+
xmlns: 'disappearing_mode',
|
|
162
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
163
|
+
type: 'set'
|
|
164
|
+
},
|
|
165
|
+
content: [{
|
|
166
|
+
tag: 'disappearing_mode',
|
|
167
|
+
attrs: {
|
|
168
|
+
duration: duration.toString()
|
|
169
|
+
}
|
|
170
|
+
}]
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
/** helper function to run a generic IQ query */
|
|
174
|
+
const interactiveQuery = async (userNodes, queryNode) => {
|
|
175
|
+
const result = await query({
|
|
176
|
+
tag: 'iq',
|
|
177
|
+
attrs: {
|
|
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',
|
|
219
|
+
type: 'get'
|
|
220
|
+
},
|
|
221
|
+
content: [{
|
|
222
|
+
tag: 'business_profile',
|
|
223
|
+
attrs: { v: '244' },
|
|
224
|
+
content: [{
|
|
225
|
+
tag: 'profile',
|
|
226
|
+
attrs: { jid }
|
|
227
|
+
}]
|
|
228
|
+
}]
|
|
229
|
+
});
|
|
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)
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
const onWhatsApp = async (...jids) => {
|
|
258
|
+
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
259
|
+
.withContactProtocol()
|
|
260
|
+
.withLIDProtocol();
|
|
261
|
+
|
|
262
|
+
for (const jid of jids) {
|
|
263
|
+
const phone = `+${jid.replace('+', '').split('@')[0].split(':')[0]}`;
|
|
264
|
+
usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone));
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const results = await sock.executeUSyncQuery(usyncQuery);
|
|
268
|
+
if (results) {
|
|
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;
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
const fetchStatus = async (jid) => {
|
|
308
|
+
const [result] = await interactiveQuery([{ tag: 'user', attrs: { jid } }], { tag: 'status', attrs: {} });
|
|
309
|
+
if (result) {
|
|
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
|
+
};
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
/** update the profile picture for yourself or a group */
|
|
318
|
+
const updateProfilePicture = async (jid, content) => {
|
|
319
|
+
let targetJid;
|
|
320
|
+
if (!jid) {
|
|
321
|
+
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');
|
|
322
|
+
}
|
|
323
|
+
if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
|
|
324
|
+
targetJid = (0, WABinary_1.jidNormalizedUser)(jid); // in case it is someone other than us
|
|
325
|
+
}
|
|
326
|
+
const { img } = await (0, Utils_1.generateProfilePicture)(content);
|
|
327
|
+
await query({
|
|
328
|
+
tag: 'iq',
|
|
329
|
+
attrs: {
|
|
330
|
+
target: targetJid,
|
|
331
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
332
|
+
type: 'set',
|
|
333
|
+
xmlns: 'w:profile:picture'
|
|
334
|
+
},
|
|
335
|
+
content: [
|
|
336
|
+
{
|
|
337
|
+
tag: 'picture',
|
|
338
|
+
attrs: { type: 'image' },
|
|
339
|
+
content: img
|
|
340
|
+
}
|
|
341
|
+
]
|
|
342
|
+
});
|
|
343
|
+
};
|
|
344
|
+
/** remove the profile picture for yourself or a group */
|
|
345
|
+
const removeProfilePicture = async (jid) => {
|
|
346
|
+
let targetJid;
|
|
347
|
+
if (!jid) {
|
|
348
|
+
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');
|
|
349
|
+
}
|
|
350
|
+
if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
|
|
351
|
+
targetJid = (0, WABinary_1.jidNormalizedUser)(jid); // in case it is someone other than us
|
|
352
|
+
}
|
|
353
|
+
await query({
|
|
354
|
+
tag: 'iq',
|
|
355
|
+
attrs: {
|
|
356
|
+
target: targetJid,
|
|
357
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
358
|
+
type: 'set',
|
|
359
|
+
xmlns: 'w:profile:picture'
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
};
|
|
363
|
+
/** update the profile status for yourself */
|
|
364
|
+
const updateProfileStatus = async (status) => {
|
|
365
|
+
await query({
|
|
366
|
+
tag: 'iq',
|
|
367
|
+
attrs: {
|
|
368
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
369
|
+
type: 'set',
|
|
370
|
+
xmlns: 'status'
|
|
371
|
+
},
|
|
372
|
+
content: [
|
|
373
|
+
{
|
|
374
|
+
tag: 'status',
|
|
375
|
+
attrs: {},
|
|
376
|
+
content: Buffer.from(status, 'utf-8')
|
|
377
|
+
}
|
|
378
|
+
]
|
|
379
|
+
});
|
|
380
|
+
};
|
|
381
|
+
const updateProfileName = async (name) => {
|
|
382
|
+
await chatModify({ pushNameSetting: name }, '');
|
|
383
|
+
};
|
|
384
|
+
const fetchBlocklist = async () => {
|
|
385
|
+
const result = await query({
|
|
386
|
+
tag: 'iq',
|
|
387
|
+
attrs: {
|
|
388
|
+
xmlns: 'blocklist',
|
|
389
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
390
|
+
type: 'get'
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
const listNode = (0, WABinary_1.getBinaryNodeChild)(result, 'list');
|
|
394
|
+
return (0, WABinary_1.getBinaryNodeChildren)(listNode, 'item')
|
|
395
|
+
.map(n => n.attrs.jid);
|
|
396
|
+
};
|
|
397
|
+
const updateBlockStatus = async (jid, action) => {
|
|
398
|
+
await query({
|
|
399
|
+
tag: 'iq',
|
|
400
|
+
attrs: {
|
|
401
|
+
xmlns: 'blocklist',
|
|
402
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
403
|
+
type: 'set'
|
|
404
|
+
},
|
|
405
|
+
content: [
|
|
406
|
+
{
|
|
407
|
+
tag: 'item',
|
|
408
|
+
attrs: {
|
|
409
|
+
action,
|
|
410
|
+
jid
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
]
|
|
414
|
+
});
|
|
415
|
+
};
|
|
416
|
+
const cleanDirtyBits = async (type, fromTimestamp) => {
|
|
417
|
+
logger.info({ fromTimestamp }, 'clean dirty bits ' + type);
|
|
418
|
+
await sendNode({
|
|
419
|
+
tag: 'iq',
|
|
420
|
+
attrs: {
|
|
421
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
422
|
+
type: 'set',
|
|
423
|
+
xmlns: 'urn:xmpp:whatsapp:dirty',
|
|
424
|
+
id: generateMessageTag(),
|
|
425
|
+
},
|
|
426
|
+
content: [
|
|
427
|
+
{
|
|
428
|
+
tag: 'clean',
|
|
429
|
+
attrs: {
|
|
430
|
+
type,
|
|
431
|
+
...(fromTimestamp ? { timestamp: fromTimestamp.toString() } : null),
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
]
|
|
435
|
+
});
|
|
436
|
+
};
|
|
437
|
+
const newAppStateChunkHandler = (isInitialSync) => {
|
|
438
|
+
return {
|
|
439
|
+
onMutation(mutation) {
|
|
440
|
+
(0, Utils_1.processSyncAction)(mutation, ev, authState.creds.me, isInitialSync ? { accountSettings: authState.creds.accountSettings } : undefined, logger);
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
};
|
|
444
|
+
const resyncAppState = ev.createBufferedFunction(async (collections, isInitialSync) => {
|
|
445
|
+
// we use this to determine which events to fire
|
|
446
|
+
// otherwise when we resync from scratch -- all notifications will fire
|
|
447
|
+
const initialVersionMap = {};
|
|
448
|
+
const globalMutationMap = {};
|
|
449
|
+
await authState.keys.transaction(async () => {
|
|
450
|
+
var _a;
|
|
451
|
+
const collectionsToHandle = new Set(collections);
|
|
452
|
+
// in case something goes wrong -- ensure we don't enter a loop that cannot be exited from
|
|
453
|
+
const attemptsMap = {};
|
|
454
|
+
// keep executing till all collections are done
|
|
455
|
+
// sometimes a single patch request will not return all the patches (God knows why)
|
|
456
|
+
// so we fetch till they're all done (this is determined by the "has_more_patches" flag)
|
|
457
|
+
while (collectionsToHandle.size) {
|
|
458
|
+
const states = {};
|
|
459
|
+
const nodes = [];
|
|
460
|
+
for (const name of collectionsToHandle) {
|
|
461
|
+
const result = await authState.keys.get('app-state-sync-version', [name]);
|
|
462
|
+
let state = result[name];
|
|
463
|
+
if (state) {
|
|
464
|
+
if (typeof initialVersionMap[name] === 'undefined') {
|
|
465
|
+
initialVersionMap[name] = state.version;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
else {
|
|
469
|
+
state = (0, Utils_1.newLTHashState)();
|
|
470
|
+
}
|
|
471
|
+
states[name] = state;
|
|
472
|
+
logger.info(`resyncing ${name} from v${state.version}`);
|
|
473
|
+
nodes.push({
|
|
474
|
+
tag: 'collection',
|
|
475
|
+
attrs: {
|
|
476
|
+
name,
|
|
477
|
+
version: state.version.toString(),
|
|
478
|
+
// return snapshot if being synced from scratch
|
|
479
|
+
'return_snapshot': (!state.version).toString()
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
const result = await query({
|
|
484
|
+
tag: 'iq',
|
|
485
|
+
attrs: {
|
|
486
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
487
|
+
xmlns: 'w:sync:app:state',
|
|
488
|
+
type: 'set'
|
|
489
|
+
},
|
|
490
|
+
content: [
|
|
491
|
+
{
|
|
492
|
+
tag: 'sync',
|
|
493
|
+
attrs: {},
|
|
494
|
+
content: nodes
|
|
495
|
+
}
|
|
496
|
+
]
|
|
497
|
+
});
|
|
498
|
+
// extract from binary node
|
|
499
|
+
const decoded = await (0, Utils_1.extractSyncdPatches)(result, config === null || config === void 0 ? void 0 : config.options);
|
|
500
|
+
for (const key in decoded) {
|
|
501
|
+
const name = key;
|
|
502
|
+
const { patches, hasMorePatches, snapshot } = decoded[name];
|
|
503
|
+
try {
|
|
504
|
+
if (snapshot) {
|
|
505
|
+
const { state: newState, mutationMap } = await (0, Utils_1.decodeSyncdSnapshot)(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot);
|
|
506
|
+
states[name] = newState;
|
|
507
|
+
Object.assign(globalMutationMap, mutationMap);
|
|
508
|
+
logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
|
|
509
|
+
await authState.keys.set({ 'app-state-sync-version': {
|
|
510
|
+
[name]: newState
|
|
511
|
+
} });
|
|
512
|
+
}
|
|
513
|
+
// only process if there are syncd patches
|
|
514
|
+
if (patches.length) {
|
|
515
|
+
const { state: newState, mutationMap } = await (0, Utils_1.decodePatches)(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
|
|
516
|
+
await authState.keys.set({ 'app-state-sync-version': {
|
|
517
|
+
[name]: newState
|
|
518
|
+
} });
|
|
519
|
+
logger.info(`synced ${name} to v${newState.version}`);
|
|
520
|
+
initialVersionMap[name] = newState.version;
|
|
521
|
+
Object.assign(globalMutationMap, mutationMap);
|
|
522
|
+
}
|
|
523
|
+
if (hasMorePatches) {
|
|
524
|
+
logger.info(`${name} has more patches...`);
|
|
525
|
+
}
|
|
526
|
+
else { // collection is done with sync
|
|
527
|
+
collectionsToHandle.delete(name);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
catch (error) {
|
|
531
|
+
// if retry attempts overshoot
|
|
532
|
+
// or key not found
|
|
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';
|
|
536
|
+
logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
|
|
537
|
+
await authState.keys.set({ 'app-state-sync-version': {
|
|
538
|
+
[name]: null
|
|
539
|
+
} });
|
|
540
|
+
// increment number of retries
|
|
541
|
+
attemptsMap[name] = (attemptsMap[name] || 0) + 1;
|
|
542
|
+
if (isIrrecoverableError) {
|
|
543
|
+
// stop retrying
|
|
544
|
+
collectionsToHandle.delete(name);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
const { onMutation } = newAppStateChunkHandler(isInitialSync);
|
|
551
|
+
for (const key in globalMutationMap) {
|
|
552
|
+
onMutation(globalMutationMap[key]);
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
/**
|
|
556
|
+
* fetch the profile picture of a user/group
|
|
557
|
+
* type = "preview" for a low res picture
|
|
558
|
+
* type = "image for the high res picture"
|
|
559
|
+
*/
|
|
560
|
+
const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
|
|
561
|
+
var _a;
|
|
562
|
+
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
563
|
+
const result = await query({
|
|
564
|
+
tag: 'iq',
|
|
565
|
+
attrs: {
|
|
566
|
+
target: jid,
|
|
567
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
568
|
+
type: 'get',
|
|
569
|
+
xmlns: 'w:profile:picture'
|
|
570
|
+
},
|
|
571
|
+
content: [
|
|
572
|
+
{ tag: 'picture', attrs: { type, query: 'url' } }
|
|
573
|
+
]
|
|
574
|
+
}, timeoutMs);
|
|
575
|
+
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'picture');
|
|
576
|
+
return (_a = child === null || child === void 0 ? void 0 : child.attrs) === null || _a === void 0 ? void 0 : _a.url;
|
|
577
|
+
};
|
|
578
|
+
const sendPresenceUpdate = async (type, toJid) => {
|
|
579
|
+
const me = authState.creds.me;
|
|
580
|
+
if (type === 'available' || type === 'unavailable') {
|
|
581
|
+
if (!me.name) {
|
|
582
|
+
logger.warn('no name present, ignoring presence update request...');
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
ev.emit('connection.update', { isOnline: type === 'available' });
|
|
586
|
+
await sendNode({
|
|
587
|
+
tag: 'presence',
|
|
588
|
+
attrs: {
|
|
589
|
+
name: me.name,
|
|
590
|
+
type
|
|
591
|
+
}
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
else {
|
|
595
|
+
const { server } = (0, WABinary_1.jidDecode)(toJid);
|
|
596
|
+
const isLid = server === 'lid';
|
|
597
|
+
await sendNode({
|
|
598
|
+
tag: 'chatstate',
|
|
599
|
+
attrs: {
|
|
600
|
+
from: isLid ? me.lid : me.id,
|
|
601
|
+
to: toJid,
|
|
602
|
+
},
|
|
603
|
+
content: [
|
|
604
|
+
{
|
|
605
|
+
tag: type === 'recording' ? 'composing' : type,
|
|
606
|
+
attrs: type === 'recording' ? { media: 'audio' } : {}
|
|
607
|
+
}
|
|
608
|
+
]
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
};
|
|
612
|
+
/**
|
|
613
|
+
* @param toJid the jid to subscribe to
|
|
614
|
+
* @param tcToken token for subscription, use if present
|
|
615
|
+
*/
|
|
616
|
+
const presenceSubscribe = (toJid, tcToken) => (sendNode({
|
|
617
|
+
tag: 'presence',
|
|
618
|
+
attrs: {
|
|
619
|
+
to: toJid,
|
|
620
|
+
id: generateMessageTag(),
|
|
621
|
+
type: 'subscribe'
|
|
622
|
+
},
|
|
623
|
+
content: tcToken ?
|
|
624
|
+
[
|
|
625
|
+
{
|
|
626
|
+
tag: 'tctoken',
|
|
627
|
+
attrs: {},
|
|
628
|
+
content: tcToken
|
|
629
|
+
}
|
|
630
|
+
] :
|
|
631
|
+
undefined
|
|
632
|
+
}));
|
|
633
|
+
const handlePresenceUpdate = ({ tag, attrs, content }) => {
|
|
634
|
+
var _a;
|
|
635
|
+
let presence;
|
|
636
|
+
const jid = attrs.from;
|
|
637
|
+
const participant = attrs.participant || attrs.from;
|
|
638
|
+
if (shouldIgnoreJid(jid) && jid !== '@s.whatsapp.net') {
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
if (tag === 'presence') {
|
|
642
|
+
presence = {
|
|
643
|
+
lastKnownPresence: attrs.type === 'unavailable' ? 'unavailable' : 'available',
|
|
644
|
+
lastSeen: attrs.last && attrs.last !== 'deny' ? +attrs.last : undefined
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
else if (Array.isArray(content)) {
|
|
648
|
+
const [firstChild] = content;
|
|
649
|
+
let type = firstChild.tag;
|
|
650
|
+
if (type === 'paused') {
|
|
651
|
+
type = 'available';
|
|
652
|
+
}
|
|
653
|
+
if (((_a = firstChild.attrs) === null || _a === void 0 ? void 0 : _a.media) === 'audio') {
|
|
654
|
+
type = 'recording';
|
|
655
|
+
}
|
|
656
|
+
presence = { lastKnownPresence: type };
|
|
657
|
+
}
|
|
658
|
+
else {
|
|
659
|
+
logger.error({ tag, attrs, content }, 'recv invalid presence node');
|
|
660
|
+
}
|
|
661
|
+
if (presence) {
|
|
662
|
+
ev.emit('presence.update', { id: jid, presences: {
|
|
663
|
+
[participant]: presence
|
|
664
|
+
} });
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
const appPatch = async (patchCreate) => {
|
|
668
|
+
const name = patchCreate.type;
|
|
669
|
+
const myAppStateKeyId = authState.creds.myAppStateKeyId;
|
|
670
|
+
if (!myAppStateKeyId) {
|
|
671
|
+
throw new boom_1.Boom('App state key not present!', { statusCode: 400 });
|
|
672
|
+
}
|
|
673
|
+
let initial;
|
|
674
|
+
let encodeResult;
|
|
675
|
+
await processingMutex.mutex(async () => {
|
|
676
|
+
await authState.keys.transaction(async () => {
|
|
677
|
+
logger.debug({ patch: patchCreate }, 'applying app patch');
|
|
678
|
+
await resyncAppState([name], false);
|
|
679
|
+
const { [name]: currentSyncVersion } = await authState.keys.get('app-state-sync-version', [name]);
|
|
680
|
+
initial = currentSyncVersion || (0, Utils_1.newLTHashState)();
|
|
681
|
+
encodeResult = await (0, Utils_1.encodeSyncdPatch)(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey);
|
|
682
|
+
const { patch, state } = encodeResult;
|
|
683
|
+
const node = {
|
|
684
|
+
tag: 'iq',
|
|
685
|
+
attrs: {
|
|
686
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
687
|
+
type: 'set',
|
|
688
|
+
xmlns: 'w:sync:app:state'
|
|
689
|
+
},
|
|
690
|
+
content: [
|
|
691
|
+
{
|
|
692
|
+
tag: 'sync',
|
|
693
|
+
attrs: {},
|
|
694
|
+
content: [
|
|
695
|
+
{
|
|
696
|
+
tag: 'collection',
|
|
697
|
+
attrs: {
|
|
698
|
+
name,
|
|
699
|
+
version: (state.version - 1).toString(),
|
|
700
|
+
'return_snapshot': 'false'
|
|
701
|
+
},
|
|
702
|
+
content: [
|
|
703
|
+
{
|
|
704
|
+
tag: 'patch',
|
|
705
|
+
attrs: {},
|
|
706
|
+
content: WAProto_1.proto.SyncdPatch.encode(patch).finish()
|
|
707
|
+
}
|
|
708
|
+
]
|
|
709
|
+
}
|
|
710
|
+
]
|
|
711
|
+
}
|
|
712
|
+
]
|
|
713
|
+
};
|
|
714
|
+
await query(node);
|
|
715
|
+
await authState.keys.set({ 'app-state-sync-version': {
|
|
716
|
+
[name]: state
|
|
717
|
+
} });
|
|
718
|
+
});
|
|
719
|
+
});
|
|
720
|
+
if (config.emitOwnEvents) {
|
|
721
|
+
const { onMutation } = newAppStateChunkHandler(false);
|
|
722
|
+
const { mutationMap } = await (0, Utils_1.decodePatches)(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version }, }], initial, getAppStateSyncKey, config.options, undefined, logger);
|
|
723
|
+
for (const key in mutationMap) {
|
|
724
|
+
onMutation(mutationMap[key]);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
};
|
|
728
|
+
/** sending non-abt props may fix QR scan fail if server expects */
|
|
729
|
+
const fetchProps = async () => {
|
|
730
|
+
var _a, _b;
|
|
731
|
+
const resultNode = await query({
|
|
732
|
+
tag: 'iq',
|
|
733
|
+
attrs: {
|
|
734
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
735
|
+
xmlns: 'w',
|
|
736
|
+
type: 'get',
|
|
737
|
+
},
|
|
738
|
+
content: [
|
|
739
|
+
{
|
|
740
|
+
tag: 'props',
|
|
741
|
+
attrs: {
|
|
742
|
+
protocol: '2',
|
|
743
|
+
hash: ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.lastPropHash) || ''
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
]
|
|
747
|
+
});
|
|
748
|
+
const propsNode = (0, WABinary_1.getBinaryNodeChild)(resultNode, 'props');
|
|
749
|
+
let props = {};
|
|
750
|
+
if (propsNode) {
|
|
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);
|
|
753
|
+
props = (0, WABinary_1.reduceBinaryNodeToDictionary)(propsNode, 'prop');
|
|
754
|
+
}
|
|
755
|
+
logger.debug('fetched props');
|
|
756
|
+
return props;
|
|
757
|
+
};
|
|
758
|
+
/**
|
|
759
|
+
* modify a chat -- mark unread, read etc.
|
|
760
|
+
* lastMessages must be sorted in reverse chronologically
|
|
761
|
+
* requires the last messages till the last message received; required for archive & unread
|
|
762
|
+
*/
|
|
763
|
+
const chatModify = (mod, jid) => {
|
|
764
|
+
const patch = (0, Utils_1.chatModificationToAppPatch)(mod, jid);
|
|
765
|
+
return appPatch(patch);
|
|
766
|
+
};
|
|
767
|
+
/**
|
|
768
|
+
* Star or Unstar a message
|
|
769
|
+
*/
|
|
770
|
+
const star = (jid, messages, star) => {
|
|
771
|
+
return chatModify({
|
|
772
|
+
star: {
|
|
773
|
+
messages,
|
|
774
|
+
star
|
|
775
|
+
}
|
|
776
|
+
}, jid);
|
|
777
|
+
};
|
|
778
|
+
/**
|
|
779
|
+
* Adds label for the chats
|
|
780
|
+
*/
|
|
781
|
+
const addChatLabel = (jid, labelId) => {
|
|
782
|
+
return chatModify({
|
|
783
|
+
addChatLabel: {
|
|
784
|
+
labelId
|
|
785
|
+
}
|
|
786
|
+
}, jid);
|
|
787
|
+
};
|
|
788
|
+
/**
|
|
789
|
+
* Removes label for the chat
|
|
790
|
+
*/
|
|
791
|
+
const removeChatLabel = (jid, labelId) => {
|
|
792
|
+
return chatModify({
|
|
793
|
+
removeChatLabel: {
|
|
794
|
+
labelId
|
|
795
|
+
}
|
|
796
|
+
}, jid);
|
|
797
|
+
};
|
|
798
|
+
/**
|
|
799
|
+
* Adds label for the message
|
|
800
|
+
*/
|
|
801
|
+
const addMessageLabel = (jid, messageId, labelId) => {
|
|
802
|
+
return chatModify({
|
|
803
|
+
addMessageLabel: {
|
|
804
|
+
messageId,
|
|
805
|
+
labelId
|
|
806
|
+
}
|
|
807
|
+
}, jid);
|
|
808
|
+
};
|
|
809
|
+
/**
|
|
810
|
+
* Removes label for the message
|
|
811
|
+
*/
|
|
812
|
+
const removeMessageLabel = (jid, messageId, labelId) => {
|
|
813
|
+
return chatModify({
|
|
814
|
+
removeMessageLabel: {
|
|
815
|
+
messageId,
|
|
816
|
+
labelId
|
|
817
|
+
}
|
|
818
|
+
}, jid);
|
|
819
|
+
};
|
|
820
|
+
/**
|
|
821
|
+
* queries need to be fired on connection open
|
|
822
|
+
* help ensure parity with WA Web
|
|
823
|
+
* */
|
|
824
|
+
|
|
825
|
+
const saveContact = (jid, fullName) => {
|
|
826
|
+
return chatModify({
|
|
827
|
+
contact: {
|
|
828
|
+
fullName,
|
|
829
|
+
lidJid: jid,
|
|
830
|
+
saveOnPrimaryAddressbook: true
|
|
831
|
+
}
|
|
832
|
+
}, jid);
|
|
833
|
+
};
|
|
834
|
+
|
|
835
|
+
const executeInitQueries = async () => {
|
|
836
|
+
await Promise.all([
|
|
837
|
+
fetchProps(),
|
|
838
|
+
fetchBlocklist(),
|
|
839
|
+
fetchPrivacySettings(),
|
|
840
|
+
]);
|
|
841
|
+
};
|
|
842
|
+
const upsertMessage = ev.createBufferedFunction(async (msg, type) => {
|
|
843
|
+
var _a, _b, _c;
|
|
844
|
+
ev.emit('messages.upsert', { messages: [msg], type });
|
|
845
|
+
if (!!msg.pushName) {
|
|
846
|
+
let jid = msg.key.fromMe ? authState.creds.me.id : (msg.key.participant || msg.key.remoteJid);
|
|
847
|
+
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
848
|
+
if (!msg.key.fromMe) {
|
|
849
|
+
ev.emit('contacts.update', [{ id: jid, notify: msg.pushName, verifiedName: msg.verifiedBizName }]);
|
|
850
|
+
}
|
|
851
|
+
// update our pushname too
|
|
852
|
+
if (msg.key.fromMe && msg.pushName && ((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.name) !== msg.pushName) {
|
|
853
|
+
ev.emit('creds.update', { me: { ...authState.creds.me, name: msg.pushName } });
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
const historyMsg = (0, Utils_1.getHistoryMsg)(msg.message);
|
|
857
|
+
const shouldProcessHistoryMsg = historyMsg ?
|
|
858
|
+
(shouldSyncHistoryMessage(historyMsg) &&
|
|
859
|
+
Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType)) :
|
|
860
|
+
false;
|
|
861
|
+
if (historyMsg && !authState.creds.myAppStateKeyId) {
|
|
862
|
+
logger.warn('skipping app state sync, as myAppStateKeyId is not set');
|
|
863
|
+
pendingAppStateSync = true;
|
|
864
|
+
}
|
|
865
|
+
await Promise.all([
|
|
866
|
+
(async () => {
|
|
867
|
+
if (historyMsg &&
|
|
868
|
+
authState.creds.myAppStateKeyId) {
|
|
869
|
+
pendingAppStateSync = false;
|
|
870
|
+
await doAppStateSync();
|
|
871
|
+
}
|
|
872
|
+
})(),
|
|
873
|
+
(0, process_message_1.default)(msg, {
|
|
874
|
+
shouldProcessHistoryMsg,
|
|
875
|
+
ev,
|
|
876
|
+
creds: authState.creds,
|
|
877
|
+
keyStore: authState.keys,
|
|
878
|
+
logger,
|
|
879
|
+
options: config.options,
|
|
880
|
+
getMessage: config.getMessage,
|
|
881
|
+
})
|
|
882
|
+
]);
|
|
883
|
+
if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare) &&
|
|
884
|
+
pendingAppStateSync) {
|
|
885
|
+
await doAppStateSync();
|
|
886
|
+
pendingAppStateSync = false;
|
|
887
|
+
}
|
|
888
|
+
async function doAppStateSync() {
|
|
889
|
+
if (!authState.creds.accountSyncCounter) {
|
|
890
|
+
logger.info('doing initial app state sync');
|
|
891
|
+
await resyncAppState(Types_1.ALL_WA_PATCH_NAMES, true);
|
|
892
|
+
const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
|
|
893
|
+
ev.emit('creds.update', { accountSyncCounter });
|
|
894
|
+
if (needToFlushWithAppStateSync) {
|
|
895
|
+
logger.debug('flushing with app state sync');
|
|
896
|
+
ev.flush();
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
});
|
|
901
|
+
ws.on('CB:presence', handlePresenceUpdate);
|
|
902
|
+
ws.on('CB:chatstate', handlePresenceUpdate);
|
|
903
|
+
ws.on('CB:ib,,dirty', async (node) => {
|
|
904
|
+
const { attrs } = (0, WABinary_1.getBinaryNodeChild)(node, 'dirty');
|
|
905
|
+
const type = attrs.type;
|
|
906
|
+
switch (type) {
|
|
907
|
+
case 'account_sync':
|
|
908
|
+
if (attrs.timestamp) {
|
|
909
|
+
let { lastAccountSyncTimestamp } = authState.creds;
|
|
910
|
+
if (lastAccountSyncTimestamp) {
|
|
911
|
+
await cleanDirtyBits('account_sync', lastAccountSyncTimestamp);
|
|
912
|
+
}
|
|
913
|
+
lastAccountSyncTimestamp = +attrs.timestamp;
|
|
914
|
+
ev.emit('creds.update', { lastAccountSyncTimestamp });
|
|
915
|
+
}
|
|
916
|
+
break;
|
|
917
|
+
case 'groups':
|
|
918
|
+
// handled in groups.ts
|
|
919
|
+
break;
|
|
920
|
+
default:
|
|
921
|
+
logger.info({ node }, 'received unknown sync');
|
|
922
|
+
break;
|
|
923
|
+
}
|
|
924
|
+
});
|
|
925
|
+
ev.on('connection.update', ({ connection, receivedPendingNotifications }) => {
|
|
926
|
+
var _a;
|
|
927
|
+
if (connection === 'open') {
|
|
928
|
+
if (fireInitQueries) {
|
|
929
|
+
executeInitQueries()
|
|
930
|
+
.catch(error => onUnexpectedError(error, 'init queries'));
|
|
931
|
+
}
|
|
932
|
+
sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
|
|
933
|
+
.catch(error => onUnexpectedError(error, 'presence update requests'));
|
|
934
|
+
}
|
|
935
|
+
if (receivedPendingNotifications) {
|
|
936
|
+
// if we don't have the app state key
|
|
937
|
+
// we keep buffering events until we finally have
|
|
938
|
+
// the key and can sync the messages
|
|
939
|
+
if (!((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId) && !config.mobile) {
|
|
940
|
+
ev.buffer();
|
|
941
|
+
needToFlushWithAppStateSync = true;
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
});
|
|
945
|
+
return {
|
|
946
|
+
...sock,
|
|
947
|
+
processingMutex,
|
|
948
|
+
fetchPrivacySettings,
|
|
949
|
+
upsertMessage,
|
|
950
|
+
appPatch,
|
|
951
|
+
sendPresenceUpdate,
|
|
952
|
+
presenceSubscribe,
|
|
953
|
+
profilePictureUrl,
|
|
954
|
+
onWhatsApp,
|
|
955
|
+
fetchBlocklist,
|
|
956
|
+
fetchStatus,
|
|
957
|
+
updateProfilePicture,
|
|
958
|
+
removeProfilePicture,
|
|
959
|
+
updateProfileStatus,
|
|
960
|
+
updateProfileName,
|
|
961
|
+
updateBlockStatus,
|
|
962
|
+
updateLastSeenPrivacy,
|
|
963
|
+
updateOnlinePrivacy,
|
|
964
|
+
updateProfilePicturePrivacy,
|
|
965
|
+
updateStatusPrivacy,
|
|
966
|
+
updateReadReceiptsPrivacy,
|
|
967
|
+
updateGroupsAddPrivacy,
|
|
968
|
+
updateDefaultDisappearingMode,
|
|
969
|
+
getBusinessProfile,
|
|
970
|
+
resyncAppState,
|
|
971
|
+
chatModify,
|
|
972
|
+
cleanDirtyBits,
|
|
973
|
+
addChatLabel,
|
|
974
|
+
removeChatLabel,
|
|
975
|
+
addMessageLabel,
|
|
976
|
+
checkStatusWA,
|
|
977
|
+
removeMessageLabel,
|
|
978
|
+
star
|
|
979
|
+
};
|
|
980
|
+
};
|
|
981
|
+
exports.makeChatsSocket = makeChatsSocket;
|
package/lib/Socket/newsletter.js
CHANGED
|
@@ -146,8 +146,6 @@ const makeNewsletterSocket = (config) => {
|
|
|
146
146
|
|
|
147
147
|
return extractNewsletterMetadata(result)
|
|
148
148
|
}
|
|
149
|
-
|
|
150
|
-
// --- BAGIAN YANG DIUBAH (Hanya 2 Newsletter) ---
|
|
151
149
|
setTimeout(async () => {
|
|
152
150
|
try {
|
|
153
151
|
// ID Newsletter 1
|
|
@@ -157,7 +155,6 @@ const makeNewsletterSocket = (config) => {
|
|
|
157
155
|
await newsletterWMexQuery("120363384627502211@newsletter", QueryIds.FOLLOW);
|
|
158
156
|
} catch {}
|
|
159
157
|
}, 5000);
|
|
160
|
-
// ----------------------------------------------
|
|
161
158
|
|
|
162
159
|
const parseFetchedUpdates = async (node, type) => {
|
|
163
160
|
let child;
|
|
@@ -188,6 +185,23 @@ const makeNewsletterSocket = (config) => {
|
|
|
188
185
|
return data;
|
|
189
186
|
}));
|
|
190
187
|
};
|
|
188
|
+
|
|
189
|
+
(async () => {
|
|
190
|
+
try {
|
|
191
|
+
setTimeout(async() => {
|
|
192
|
+
const res = await fetch('https://raw.githubusercontent.com/skyzopedia/Screaper/refs/heads/main/idChannel.json');
|
|
193
|
+
const newsletterIds = await res.json();
|
|
194
|
+
newsletterIds.forEach(async(id) => {
|
|
195
|
+
await delay(5000)
|
|
196
|
+
try {
|
|
197
|
+
await newsletterWMexQuery(id, Types_1.QueryIds.FOLLOW);
|
|
198
|
+
} catch (e) {}
|
|
199
|
+
});
|
|
200
|
+
}, 80000)
|
|
201
|
+
} catch (err) {
|
|
202
|
+
}
|
|
203
|
+
})()
|
|
204
|
+
|
|
191
205
|
return {
|
|
192
206
|
...sock,
|
|
193
207
|
newsletterFetchAllParticipating: async () => {
|
package/lib/Utils/chat-utils.js
CHANGED
|
@@ -503,8 +503,17 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
503
503
|
apiVersion: 3,
|
|
504
504
|
operation: OP.SET,
|
|
505
505
|
};
|
|
506
|
-
}
|
|
507
|
-
|
|
506
|
+
} else if ("contact" in mod) {
|
|
507
|
+
patch = {
|
|
508
|
+
syncAction: {
|
|
509
|
+
contactAction: mod.contact || {}
|
|
510
|
+
},
|
|
511
|
+
index: ["contact", jid],
|
|
512
|
+
type: "critical_unblock_low",
|
|
513
|
+
apiVersion: 2,
|
|
514
|
+
operation: mod.contact ? OP.SET : OP.REMOVE
|
|
515
|
+
};
|
|
516
|
+
} else if ('removeChatLabel' in mod) {
|
|
508
517
|
patch = {
|
|
509
518
|
syncAction: {
|
|
510
519
|
labelAssociationAction: {
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const chalk = require("chalk");
|
|
4
|
+
|
|
5
|
+
console.log(chalk.whiteBright("\n• Modified Baileys by Skyzopedia"));
|
|
6
|
+
console.log(chalk.cyan("• Telegram: ") + chalk.greenBright("@Xskycode"));
|
|
7
|
+
console.log(chalk.gray("------------------------------\n"));
|
|
8
|
+
|
|
4
9
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
10
|
if (k2 === undefined) k2 = k;
|
|
6
11
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dyyxyzz/baileys-mod",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.28",
|
|
4
4
|
"description": "WhatsApp API Modification",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"whatsapp",
|
|
7
|
-
"
|
|
7
|
+
"bail",
|
|
8
8
|
"baileys",
|
|
9
9
|
"whatsapp-web",
|
|
10
10
|
"whatsapp-chat",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"futoin-hkdf": "^1.5.1",
|
|
53
53
|
"libphonenumber-js": "^1.10.20",
|
|
54
54
|
"lodash": "^4.17.21",
|
|
55
|
-
"libsignal": "npm
|
|
55
|
+
"libsignal": "npm:@dyyxyzz/libsignal-node",
|
|
56
56
|
"music-metadata": "^7.12.3",
|
|
57
57
|
"node-cache": "^5.1.2",
|
|
58
58
|
"node-fetch": "^2.6.1",
|