alipclutch-baileys 8.3.0 → 8.4.1
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 +3 -1
- package/README.md +10 -9
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +4775 -0
- package/WAProto/index.d.ts +55057 -0
- package/WAProto/index.js +56887 -17535
- package/WAProto/index.ts.ts +53473 -0
- package/lib/Defaults/baileys-version.json +2 -2
- package/lib/Defaults/index.d.ts +16 -7
- package/lib/Defaults/index.js +90 -119
- package/lib/Socket/Client/index.d.ts +2 -3
- package/lib/Socket/Client/index.js +2 -3
- package/lib/Socket/Client/types.d.ts +0 -1
- package/lib/Socket/Client/types.js +0 -1
- package/lib/Socket/Client/websocket.d.ts +0 -1
- package/lib/Socket/Client/websocket.js +0 -1
- package/lib/Socket/business.d.ts +59 -58
- package/lib/Socket/chats.d.ts +45 -230
- package/lib/Socket/chats.js +139 -238
- package/lib/Socket/groups.d.ts +41 -32
- package/lib/Socket/groups.js +38 -23
- package/lib/Socket/index.d.ts +63 -64
- package/lib/Socket/index.js +2 -3
- package/lib/Socket/messages-recv.js +9 -65
- package/lib/Socket/messages-send.d.ts +49 -47
- package/lib/Socket/messages-send.js +584 -395
- package/lib/Socket/newsletter.d.ts +39 -37
- package/lib/Socket/newsletter.js +88 -123
- package/lib/Socket/setup.js +433 -0
- package/lib/Socket/{dugong.d.ts → setup.ts} +17 -52
- package/lib/Socket/socket.d.ts +10 -10
- package/lib/Socket/socket.js +62 -38
- package/lib/Socket/usync.d.ts +3 -4
- package/lib/Socket/usync.js +0 -1
- package/lib/Store/index.d.ts +1 -2
- package/lib/Store/index.js +1 -3
- package/lib/Store/make-in-memory-store.d.ts +24 -24
- package/lib/Store/make-in-memory-store.js +26 -14
- 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 +0 -7
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +14 -7
- package/lib/Types/Contact.d.ts +5 -1
- package/lib/Types/Events.d.ts +44 -2
- package/lib/Types/GroupMetadata.d.ts +11 -2
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +148 -21
- package/lib/Types/Message.js +0 -2
- package/lib/Types/Newsletter.d.ts +73 -97
- package/lib/Types/Newsletter.js +18 -38
- package/lib/Types/Socket.d.ts +17 -9
- package/lib/Types/index.d.ts +8 -1
- package/lib/Types/index.js +2 -2
- package/lib/Utils/auth-utils.d.ts +3 -3
- package/lib/Utils/auth-utils.js +6 -13
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +15 -16
- package/lib/Utils/chat-utils.js +36 -35
- package/lib/Utils/crypto.d.ts +15 -16
- package/lib/Utils/crypto.js +71 -29
- package/lib/Utils/decode-wa-message.d.ts +22 -6
- package/lib/Utils/decode-wa-message.js +65 -56
- package/lib/Utils/event-buffer.d.ts +2 -2
- package/lib/Utils/event-buffer.js +11 -7
- package/lib/Utils/generics.d.ts +17 -20
- package/lib/Utils/generics.js +95 -75
- package/lib/Utils/history.d.ts +4 -0
- package/lib/Utils/history.js +4 -6
- package/lib/Utils/link-preview.d.ts +2 -2
- package/lib/Utils/link-preview.js +34 -1
- package/lib/Utils/logger.d.ts +10 -3
- 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 +28 -24
- package/lib/Utils/messages-media.js +272 -111
- package/lib/Utils/messages.d.ts +13 -10
- package/lib/Utils/messages.js +323 -50
- package/lib/Utils/noise-handler.d.ts +10 -12
- package/lib/Utils/noise-handler.js +18 -23
- package/lib/Utils/process-message.d.ts +5 -4
- package/lib/Utils/process-message.js +108 -25
- package/lib/Utils/signal.d.ts +2 -1
- package/lib/Utils/signal.js +26 -26
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -1
- package/lib/Utils/use-multi-file-auth-state.js +51 -6
- package/lib/Utils/validate-connection.d.ts +3 -4
- package/lib/Utils/validate-connection.js +90 -66
- package/lib/WABinary/constants.d.ts +24 -27
- package/lib/WABinary/constants.js +1276 -13
- package/lib/WABinary/decode.d.ts +3 -4
- package/lib/WABinary/decode.js +26 -13
- package/lib/WABinary/encode.d.ts +1 -2
- package/lib/WABinary/encode.js +137 -152
- package/lib/WABinary/generic-utils.d.ts +1 -4
- package/lib/WABinary/generic-utils.js +37 -125
- package/lib/WABinary/jid-utils.d.ts +11 -5
- package/lib/WABinary/jid-utils.js +28 -5
- package/lib/WABinary/jid-utils.js.bak +83 -0
- package/lib/WAM/BinaryInfo.d.ts +2 -11
- package/lib/WAM/encode.d.ts +1 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.js +27 -15
- package/package.json +18 -31
- package/engine-requirements.js +0 -10
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.d.ts +0 -12
- package/lib/Socket/Client/web-socket-client.js +0 -62
- package/lib/Socket/dugong.js +0 -483
- package/lib/Socket/registration.d.ts +0 -267
- package/lib/Socket/registration.js +0 -166
- package/lib/Store/make-cache-manager-store.d.ts +0 -13
- package/lib/Store/make-cache-manager-store.js +0 -83
package/lib/Socket/chats.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
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"));
|
|
8
9
|
const WAProto_1 = require("../../WAProto");
|
|
9
10
|
const Defaults_1 = require("../Defaults");
|
|
10
11
|
const Types_1 = require("../Types");
|
|
@@ -12,7 +13,6 @@ const Utils_1 = require("../Utils");
|
|
|
12
13
|
const make_mutex_1 = require("../Utils/make-mutex");
|
|
13
14
|
const process_message_1 = __importDefault(require("../Utils/process-message"));
|
|
14
15
|
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,6 +25,13 @@ 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
|
+
}
|
|
28
35
|
/** helper function to fetch the given app state sync key */
|
|
29
36
|
const getAppStateSyncKey = async (keyId) => {
|
|
30
37
|
const { [keyId]: key } = await authState.keys.get('app-state-sync-key', [keyId]);
|
|
@@ -68,6 +75,12 @@ const makeChatsSocket = (config) => {
|
|
|
68
75
|
}]
|
|
69
76
|
});
|
|
70
77
|
};
|
|
78
|
+
const updateMessagesPrivacy = async (value) => {
|
|
79
|
+
await privacyQuery('messages', value);
|
|
80
|
+
};
|
|
81
|
+
const updateCallPrivacy = async (value) => {
|
|
82
|
+
await privacyQuery('calladd', value);
|
|
83
|
+
};
|
|
71
84
|
const updateLastSeenPrivacy = async (value) => {
|
|
72
85
|
await privacyQuery('last', value);
|
|
73
86
|
};
|
|
@@ -86,74 +99,6 @@ const makeChatsSocket = (config) => {
|
|
|
86
99
|
const updateGroupsAddPrivacy = async (value) => {
|
|
87
100
|
await privacyQuery('groupadd', value);
|
|
88
101
|
};
|
|
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
102
|
const updateDefaultDisappearingMode = async (duration) => {
|
|
158
103
|
await query({
|
|
159
104
|
tag: 'iq',
|
|
@@ -170,148 +115,68 @@ const makeChatsSocket = (config) => {
|
|
|
170
115
|
}]
|
|
171
116
|
});
|
|
172
117
|
};
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const result = await query({
|
|
118
|
+
const getBotListV2 = async () => {
|
|
119
|
+
const resp = await query({
|
|
176
120
|
tag: 'iq',
|
|
177
121
|
attrs: {
|
|
122
|
+
xmlns: 'bot',
|
|
178
123
|
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
124
|
type: 'get'
|
|
220
125
|
},
|
|
221
126
|
content: [{
|
|
222
|
-
tag: '
|
|
223
|
-
attrs: {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
attrs: { jid }
|
|
227
|
-
}]
|
|
127
|
+
tag: 'bot',
|
|
128
|
+
attrs: {
|
|
129
|
+
v: '2'
|
|
130
|
+
}
|
|
228
131
|
}]
|
|
229
132
|
});
|
|
230
|
-
const
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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)
|
|
133
|
+
const botNode = (0, WABinary_1.getBinaryNodeChild)(resp, 'bot');
|
|
134
|
+
const botList = [];
|
|
135
|
+
for (const section of (0, WABinary_1.getBinaryNodeChildren)(botNode, 'section')) {
|
|
136
|
+
if (section.attrs.type === 'all') {
|
|
137
|
+
for (const bot of (0, WABinary_1.getBinaryNodeChildren)(section, 'bot')) {
|
|
138
|
+
botList.push({
|
|
139
|
+
jid: bot.attrs.jid,
|
|
140
|
+
personaId: bot.attrs['persona_id']
|
|
141
|
+
});
|
|
253
142
|
}
|
|
254
|
-
}
|
|
143
|
+
}
|
|
255
144
|
}
|
|
145
|
+
return botList;
|
|
256
146
|
};
|
|
257
147
|
const onWhatsApp = async (...jids) => {
|
|
258
148
|
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
149
|
+
.withContactProtocol()
|
|
150
|
+
.withLIDProtocol();
|
|
262
151
|
for (const jid of jids) {
|
|
263
152
|
const phone = `+${jid.replace('+', '').split('@')[0].split(':')[0]}`;
|
|
264
153
|
usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone));
|
|
265
154
|
}
|
|
266
|
-
|
|
267
155
|
const results = await sock.executeUSyncQuery(usyncQuery);
|
|
268
156
|
if (results) {
|
|
269
|
-
|
|
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;
|
|
157
|
+
return results.list.filter((a) => !!a.contact).map(({ contact, id, lid }) => ({ jid: id, exists: contact, lid }));
|
|
305
158
|
}
|
|
306
159
|
};
|
|
307
|
-
const fetchStatus = async (
|
|
308
|
-
const
|
|
160
|
+
const fetchStatus = async (...jids) => {
|
|
161
|
+
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
162
|
+
.withStatusProtocol();
|
|
163
|
+
for (const jid of jids) {
|
|
164
|
+
usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
|
|
165
|
+
}
|
|
166
|
+
const result = await sock.executeUSyncQuery(usyncQuery);
|
|
309
167
|
if (result) {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
168
|
+
return result.list;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
const fetchDisappearingDuration = async (...jids) => {
|
|
172
|
+
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
173
|
+
.withDisappearingModeProtocol();
|
|
174
|
+
for (const jid of jids) {
|
|
175
|
+
usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
|
|
176
|
+
}
|
|
177
|
+
const result = await sock.executeUSyncQuery(usyncQuery);
|
|
178
|
+
if (result) {
|
|
179
|
+
return result.list;
|
|
315
180
|
}
|
|
316
181
|
};
|
|
317
182
|
/** update the profile picture for yourself or a group */
|
|
@@ -413,6 +278,51 @@ const makeChatsSocket = (config) => {
|
|
|
413
278
|
]
|
|
414
279
|
});
|
|
415
280
|
};
|
|
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
|
+
};
|
|
416
326
|
const cleanDirtyBits = async (type, fromTimestamp) => {
|
|
417
327
|
logger.info({ fromTimestamp }, 'clean dirty bits ' + type);
|
|
418
328
|
await sendNode({
|
|
@@ -506,16 +416,12 @@ const makeChatsSocket = (config) => {
|
|
|
506
416
|
states[name] = newState;
|
|
507
417
|
Object.assign(globalMutationMap, mutationMap);
|
|
508
418
|
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
|
-
} });
|
|
419
|
+
await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
|
|
512
420
|
}
|
|
513
421
|
// only process if there are syncd patches
|
|
514
422
|
if (patches.length) {
|
|
515
423
|
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
|
-
} });
|
|
424
|
+
await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
|
|
519
425
|
logger.info(`synced ${name} to v${newState.version}`);
|
|
520
426
|
initialVersionMap[name] = newState.version;
|
|
521
427
|
Object.assign(globalMutationMap, mutationMap);
|
|
@@ -530,13 +436,11 @@ const makeChatsSocket = (config) => {
|
|
|
530
436
|
catch (error) {
|
|
531
437
|
// if retry attempts overshoot
|
|
532
438
|
// 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';
|
|
439
|
+
const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS
|
|
440
|
+
|| ((_a = error.output) === null || _a === void 0 ? void 0 : _a.statusCode) === 404
|
|
441
|
+
|| error.name === 'TypeError';
|
|
536
442
|
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
|
-
} });
|
|
443
|
+
await authState.keys.set({ 'app-state-sync-version': { [name]: null } });
|
|
540
444
|
// increment number of retries
|
|
541
445
|
attemptsMap[name] = (attemptsMap[name] || 0) + 1;
|
|
542
446
|
if (isIrrecoverableError) {
|
|
@@ -586,7 +490,7 @@ const makeChatsSocket = (config) => {
|
|
|
586
490
|
await sendNode({
|
|
587
491
|
tag: 'presence',
|
|
588
492
|
attrs: {
|
|
589
|
-
name: me.name,
|
|
493
|
+
name: me.name.replace(/@/g, ''),
|
|
590
494
|
type
|
|
591
495
|
}
|
|
592
496
|
});
|
|
@@ -620,22 +524,22 @@ const makeChatsSocket = (config) => {
|
|
|
620
524
|
id: generateMessageTag(),
|
|
621
525
|
type: 'subscribe'
|
|
622
526
|
},
|
|
623
|
-
content: tcToken
|
|
624
|
-
[
|
|
527
|
+
content: tcToken
|
|
528
|
+
? [
|
|
625
529
|
{
|
|
626
530
|
tag: 'tctoken',
|
|
627
531
|
attrs: {},
|
|
628
532
|
content: tcToken
|
|
629
533
|
}
|
|
630
|
-
]
|
|
631
|
-
undefined
|
|
534
|
+
]
|
|
535
|
+
: undefined
|
|
632
536
|
}));
|
|
633
537
|
const handlePresenceUpdate = ({ tag, attrs, content }) => {
|
|
634
538
|
var _a;
|
|
635
539
|
let presence;
|
|
636
540
|
const jid = attrs.from;
|
|
637
541
|
const participant = attrs.participant || attrs.from;
|
|
638
|
-
if (shouldIgnoreJid(jid) && jid
|
|
542
|
+
if (shouldIgnoreJid(jid) && jid != '@s.whatsapp.net') {
|
|
639
543
|
return;
|
|
640
544
|
}
|
|
641
545
|
if (tag === 'presence') {
|
|
@@ -659,9 +563,7 @@ const makeChatsSocket = (config) => {
|
|
|
659
563
|
logger.error({ tag, attrs, content }, 'recv invalid presence node');
|
|
660
564
|
}
|
|
661
565
|
if (presence) {
|
|
662
|
-
ev.emit('presence.update', { id: jid, presences: {
|
|
663
|
-
[participant]: presence
|
|
664
|
-
} });
|
|
566
|
+
ev.emit('presence.update', { id: jid, presences: { [participant]: presence } });
|
|
665
567
|
}
|
|
666
568
|
};
|
|
667
569
|
const appPatch = async (patchCreate) => {
|
|
@@ -712,9 +614,7 @@ const makeChatsSocket = (config) => {
|
|
|
712
614
|
]
|
|
713
615
|
};
|
|
714
616
|
await query(node);
|
|
715
|
-
await authState.keys.set({ 'app-state-sync-version': {
|
|
716
|
-
[name]: state
|
|
717
|
-
} });
|
|
617
|
+
await authState.keys.set({ 'app-state-sync-version': { [name]: state } });
|
|
718
618
|
});
|
|
719
619
|
});
|
|
720
620
|
if (config.emitOwnEvents) {
|
|
@@ -727,7 +627,7 @@ const makeChatsSocket = (config) => {
|
|
|
727
627
|
};
|
|
728
628
|
/** sending non-abt props may fix QR scan fail if server expects */
|
|
729
629
|
const fetchProps = async () => {
|
|
730
|
-
var _a, _b;
|
|
630
|
+
var _a, _b, _c;
|
|
731
631
|
const resultNode = await query({
|
|
732
632
|
tag: 'iq',
|
|
733
633
|
attrs: {
|
|
@@ -736,20 +636,19 @@ const makeChatsSocket = (config) => {
|
|
|
736
636
|
type: 'get',
|
|
737
637
|
},
|
|
738
638
|
content: [
|
|
739
|
-
{
|
|
740
|
-
tag: 'props',
|
|
741
|
-
attrs: {
|
|
639
|
+
{ tag: 'props', attrs: {
|
|
742
640
|
protocol: '2',
|
|
743
641
|
hash: ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.lastPropHash) || ''
|
|
744
|
-
}
|
|
745
|
-
}
|
|
642
|
+
} }
|
|
746
643
|
]
|
|
747
644
|
});
|
|
748
645
|
const propsNode = (0, WABinary_1.getBinaryNodeChild)(resultNode, 'props');
|
|
749
646
|
let props = {};
|
|
750
647
|
if (propsNode) {
|
|
751
|
-
|
|
752
|
-
|
|
648
|
+
if ((_b = propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash) { // on some clients, the hash is returning as undefined
|
|
649
|
+
authState.creds.lastPropHash = (_c = propsNode === null || propsNode === void 0 ? void 0 : propsNode.attrs) === null || _c === void 0 ? void 0 : _c.hash;
|
|
650
|
+
ev.emit('creds.update', authState.creds);
|
|
651
|
+
}
|
|
753
652
|
props = (0, WABinary_1.reduceBinaryNodeToDictionary)(propsNode, 'prop');
|
|
754
653
|
}
|
|
755
654
|
logger.debug('fetched props');
|
|
@@ -759,7 +658,7 @@ const makeChatsSocket = (config) => {
|
|
|
759
658
|
* modify a chat -- mark unread, read etc.
|
|
760
659
|
* lastMessages must be sorted in reverse chronologically
|
|
761
660
|
* requires the last messages till the last message received; required for archive & unread
|
|
762
|
-
|
|
661
|
+
*/
|
|
763
662
|
const chatModify = (mod, jid) => {
|
|
764
663
|
const patch = (0, Utils_1.chatModificationToAppPatch)(mod, jid);
|
|
765
664
|
return appPatch(patch);
|
|
@@ -843,24 +742,25 @@ const makeChatsSocket = (config) => {
|
|
|
843
742
|
}
|
|
844
743
|
}
|
|
845
744
|
const historyMsg = (0, Utils_1.getHistoryMsg)(msg.message);
|
|
846
|
-
const shouldProcessHistoryMsg = historyMsg
|
|
847
|
-
(shouldSyncHistoryMessage(historyMsg)
|
|
848
|
-
Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType))
|
|
849
|
-
false;
|
|
745
|
+
const shouldProcessHistoryMsg = historyMsg
|
|
746
|
+
? (shouldSyncHistoryMessage(historyMsg)
|
|
747
|
+
&& Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType))
|
|
748
|
+
: false;
|
|
850
749
|
if (historyMsg && !authState.creds.myAppStateKeyId) {
|
|
851
750
|
logger.warn('skipping app state sync, as myAppStateKeyId is not set');
|
|
852
751
|
pendingAppStateSync = true;
|
|
853
752
|
}
|
|
854
753
|
await Promise.all([
|
|
855
754
|
(async () => {
|
|
856
|
-
if (historyMsg
|
|
857
|
-
authState.creds.myAppStateKeyId) {
|
|
755
|
+
if (historyMsg
|
|
756
|
+
&& authState.creds.myAppStateKeyId) {
|
|
858
757
|
pendingAppStateSync = false;
|
|
859
758
|
await doAppStateSync();
|
|
860
759
|
}
|
|
861
760
|
})(),
|
|
862
761
|
(0, process_message_1.default)(msg, {
|
|
863
762
|
shouldProcessHistoryMsg,
|
|
763
|
+
placeholderResendCache,
|
|
864
764
|
ev,
|
|
865
765
|
creds: authState.creds,
|
|
866
766
|
keyStore: authState.keys,
|
|
@@ -869,8 +769,8 @@ const makeChatsSocket = (config) => {
|
|
|
869
769
|
getMessage: config.getMessage,
|
|
870
770
|
})
|
|
871
771
|
]);
|
|
872
|
-
if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare)
|
|
873
|
-
pendingAppStateSync) {
|
|
772
|
+
if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare)
|
|
773
|
+
&& pendingAppStateSync) {
|
|
874
774
|
await doAppStateSync();
|
|
875
775
|
pendingAppStateSync = false;
|
|
876
776
|
}
|
|
@@ -921,18 +821,17 @@ const makeChatsSocket = (config) => {
|
|
|
921
821
|
sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
|
|
922
822
|
.catch(error => onUnexpectedError(error, 'presence update requests'));
|
|
923
823
|
}
|
|
924
|
-
if (receivedPendingNotifications
|
|
925
|
-
// if we don't have the app state key
|
|
824
|
+
if (receivedPendingNotifications && // if we don't have the app state key
|
|
926
825
|
// we keep buffering events until we finally have
|
|
927
826
|
// the key and can sync the messages
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
}
|
|
827
|
+
!((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId)) {
|
|
828
|
+
ev.buffer();
|
|
829
|
+
needToFlushWithAppStateSync = true;
|
|
932
830
|
}
|
|
933
831
|
});
|
|
934
832
|
return {
|
|
935
833
|
...sock,
|
|
834
|
+
getBotListV2,
|
|
936
835
|
processingMutex,
|
|
937
836
|
fetchPrivacySettings,
|
|
938
837
|
upsertMessage,
|
|
@@ -942,12 +841,15 @@ const makeChatsSocket = (config) => {
|
|
|
942
841
|
profilePictureUrl,
|
|
943
842
|
onWhatsApp,
|
|
944
843
|
fetchBlocklist,
|
|
844
|
+
fetchDisappearingDuration,
|
|
945
845
|
fetchStatus,
|
|
946
846
|
updateProfilePicture,
|
|
947
847
|
removeProfilePicture,
|
|
948
848
|
updateProfileStatus,
|
|
949
849
|
updateProfileName,
|
|
950
850
|
updateBlockStatus,
|
|
851
|
+
updateCallPrivacy,
|
|
852
|
+
updateMessagesPrivacy,
|
|
951
853
|
updateLastSeenPrivacy,
|
|
952
854
|
updateOnlinePrivacy,
|
|
953
855
|
updateProfilePicturePrivacy,
|
|
@@ -962,7 +864,6 @@ const makeChatsSocket = (config) => {
|
|
|
962
864
|
addChatLabel,
|
|
963
865
|
removeChatLabel,
|
|
964
866
|
addMessageLabel,
|
|
965
|
-
checkStatusWA,
|
|
966
867
|
removeMessageLabel,
|
|
967
868
|
star
|
|
968
869
|
};
|