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