@denzy-official/baileys 1.0.9 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/WAProto/index.d.ts +55058 -0
- package/WAProto/index.js +169662 -0
- package/WAProto/index.ts.ts +53474 -0
- package/lib/Defaults/index.d.ts +52 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/group-session-builder.d.ts +15 -0
- package/lib/Signal/Group/group_cipher.d.ts +18 -0
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/lib/Signal/Group/queue-job.d.ts +2 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/libsignal.d.ts +4 -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 -0
- package/lib/Socket/Client/index.js +3 -3
- 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 +17 -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 +14 -0
- package/lib/Socket/business.d.ts +171 -0
- package/lib/Socket/business.js +0 -1
- package/lib/Socket/chats.d.ts +267 -0
- package/lib/Socket/chats.js +238 -140
- package/lib/Socket/dugong.d.ts +254 -0
- package/lib/Socket/dugong.js +343 -335
- package/lib/Socket/groups.d.ts +115 -0
- package/lib/Socket/groups.js +23 -39
- package/lib/Socket/index.d.ts +173 -0
- package/lib/Socket/index.js +3 -3
- package/lib/Socket/messages-recv.d.ts +161 -0
- package/lib/Socket/messages-recv.js +65 -10
- package/lib/Socket/messages-send.d.ts +149 -0
- package/lib/Socket/messages-send.js +392 -412
- package/lib/Socket/newsletter.d.ts +134 -0
- package/lib/Socket/newsletter.js +124 -72
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +43 -0
- package/lib/Socket/socket.js +38 -63
- package/lib/Socket/usync.d.ts +36 -0
- package/lib/Socket/usync.js +0 -1
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/make-in-memory-store.d.ts +119 -0
- package/lib/Store/make-ordered-dictionary.d.ts +14 -0
- package/lib/Store/object-repository.d.ts +11 -0
- package/lib/Types/Auth.d.ts +104 -0
- package/lib/Types/Call.d.ts +14 -0
- package/lib/Types/Chat.d.ts +110 -0
- package/lib/Types/Contact.d.ts +24 -0
- package/lib/Types/Events.d.ts +200 -0
- package/lib/Types/GroupMetadata.d.ts +65 -0
- package/lib/Types/Label.d.ts +36 -0
- package/lib/Types/LabelAssociation.d.ts +30 -0
- package/lib/Types/Message.d.ts +401 -0
- package/lib/Types/Newsletter.d.ts +80 -0
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Signal.d.ts +57 -0
- package/lib/Types/Socket.d.ts +119 -0
- package/lib/Types/State.d.ts +27 -0
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/index.d.ts +65 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/lib/Utils/auth-utils.js +13 -8
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/baileys-event-stream.js +0 -1
- package/lib/Utils/business.d.ts +22 -0
- package/lib/Utils/business.js +2 -3
- package/lib/Utils/chat-utils.d.ts +71 -0
- package/lib/Utils/chat-utils.js +35 -37
- package/lib/Utils/crypto.d.ts +41 -0
- package/lib/Utils/crypto.js +29 -72
- package/lib/Utils/decode-wa-message.d.ts +19 -0
- package/lib/Utils/decode-wa-message.js +56 -66
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/lib/Utils/event-buffer.js +7 -12
- package/lib/Utils/generics.d.ts +92 -0
- package/lib/Utils/generics.js +75 -96
- package/lib/Utils/history.d.ts +15 -0
- package/lib/Utils/history.js +6 -5
- package/lib/Utils/index.d.ts +17 -0
- package/lib/Utils/index.js +0 -1
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +1 -34
- package/lib/Utils/logger.d.ts +4 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/lt-hash.js +6 -6
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/messages-media.d.ts +116 -0
- package/lib/Utils/messages-media.js +235 -296
- package/lib/Utils/messages.d.ts +77 -0
- package/lib/Utils/messages.js +60 -304
- package/lib/Utils/noise-handler.d.ts +21 -0
- package/lib/Utils/noise-handler.js +23 -18
- package/lib/Utils/process-message.d.ts +41 -0
- package/lib/Utils/process-message.js +25 -89
- package/lib/Utils/signal.d.ts +32 -0
- package/lib/Utils/signal.js +26 -26
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.js +6 -51
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +52 -20
- package/lib/WABinary/constants.d.ts +28 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/generic-utils.d.ts +15 -0
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/jid-utils.d.ts +37 -0
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WAM/BinaryInfo.d.ts +9 -0
- package/lib/WAM/constants.d.ts +39 -0
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/USyncQuery.d.ts +28 -0
- package/lib/WAUSync/USyncUser.d.ts +12 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/index.d.ts +17 -0
- package/package.json +1 -1
package/lib/Socket/chats.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
// baileys by denzy
|
|
2
1
|
"use strict";
|
|
3
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
4
|
+
};
|
|
6
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
6
|
exports.makeChatsSocket = void 0;
|
|
8
7
|
const boom_1 = require("@hapi/boom");
|
|
9
|
-
const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
|
|
10
8
|
const WAProto_1 = require("../../WAProto");
|
|
11
9
|
const Defaults_1 = require("../Defaults");
|
|
12
10
|
const Types_1 = require("../Types");
|
|
@@ -14,6 +12,7 @@ const Utils_1 = require("../Utils");
|
|
|
14
12
|
const make_mutex_1 = require("../Utils/make-mutex");
|
|
15
13
|
const process_message_1 = __importDefault(require("../Utils/process-message"));
|
|
16
14
|
const WABinary_1 = require("../WABinary");
|
|
15
|
+
const socket_1 = require("./socket");
|
|
17
16
|
const WAUSync_1 = require("../WAUSync");
|
|
18
17
|
const usync_1 = require("./usync");
|
|
19
18
|
const MAX_SYNC_ATTEMPTS = 2;
|
|
@@ -26,13 +25,6 @@ const makeChatsSocket = (config) => {
|
|
|
26
25
|
let pendingAppStateSync = false;
|
|
27
26
|
/** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
|
|
28
27
|
const processingMutex = (0, make_mutex_1.makeMutex)();
|
|
29
|
-
const placeholderResendCache = config.placeholderResendCache || new node_cache_1.default({
|
|
30
|
-
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
|
|
31
|
-
useClones: false
|
|
32
|
-
});
|
|
33
|
-
if (!config.placeholderResendCache) {
|
|
34
|
-
config.placeholderResendCache = placeholderResendCache;
|
|
35
|
-
}
|
|
36
28
|
/** helper function to fetch the given app state sync key */
|
|
37
29
|
const getAppStateSyncKey = async (keyId) => {
|
|
38
30
|
const { [keyId]: key } = await authState.keys.get('app-state-sync-key', [keyId]);
|
|
@@ -76,12 +68,6 @@ const makeChatsSocket = (config) => {
|
|
|
76
68
|
}]
|
|
77
69
|
});
|
|
78
70
|
};
|
|
79
|
-
const updateMessagesPrivacy = async (value) => {
|
|
80
|
-
await privacyQuery('messages', value);
|
|
81
|
-
};
|
|
82
|
-
const updateCallPrivacy = async (value) => {
|
|
83
|
-
await privacyQuery('calladd', value);
|
|
84
|
-
};
|
|
85
71
|
const updateLastSeenPrivacy = async (value) => {
|
|
86
72
|
await privacyQuery('last', value);
|
|
87
73
|
};
|
|
@@ -100,6 +86,74 @@ const makeChatsSocket = (config) => {
|
|
|
100
86
|
const updateGroupsAddPrivacy = async (value) => {
|
|
101
87
|
await privacyQuery('groupadd', value);
|
|
102
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
|
+
};
|
|
103
157
|
const updateDefaultDisappearingMode = async (duration) => {
|
|
104
158
|
await query({
|
|
105
159
|
tag: 'iq',
|
|
@@ -116,68 +170,148 @@ const makeChatsSocket = (config) => {
|
|
|
116
170
|
}]
|
|
117
171
|
});
|
|
118
172
|
};
|
|
119
|
-
|
|
120
|
-
|
|
173
|
+
/** helper function to run a generic IQ query */
|
|
174
|
+
const interactiveQuery = async (userNodes, queryNode) => {
|
|
175
|
+
const result = await query({
|
|
121
176
|
tag: 'iq',
|
|
122
177
|
attrs: {
|
|
123
|
-
xmlns: 'bot',
|
|
124
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',
|
|
125
219
|
type: 'get'
|
|
126
220
|
},
|
|
127
221
|
content: [{
|
|
128
|
-
tag: '
|
|
129
|
-
attrs: {
|
|
130
|
-
|
|
131
|
-
|
|
222
|
+
tag: 'business_profile',
|
|
223
|
+
attrs: { v: '244' },
|
|
224
|
+
content: [{
|
|
225
|
+
tag: 'profile',
|
|
226
|
+
attrs: { jid }
|
|
227
|
+
}]
|
|
132
228
|
}]
|
|
133
229
|
});
|
|
134
|
-
const
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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)
|
|
143
253
|
}
|
|
144
|
-
}
|
|
254
|
+
};
|
|
145
255
|
}
|
|
146
|
-
return botList;
|
|
147
256
|
};
|
|
148
257
|
const onWhatsApp = async (...jids) => {
|
|
149
258
|
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
150
|
-
|
|
151
|
-
|
|
259
|
+
.withContactProtocol()
|
|
260
|
+
.withLIDProtocol();
|
|
261
|
+
|
|
152
262
|
for (const jid of jids) {
|
|
153
263
|
const phone = `+${jid.replace('+', '').split('@')[0].split(':')[0]}`;
|
|
154
264
|
usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone));
|
|
155
265
|
}
|
|
266
|
+
|
|
156
267
|
const results = await sock.executeUSyncQuery(usyncQuery);
|
|
157
268
|
if (results) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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;
|
|
170
305
|
}
|
|
171
306
|
};
|
|
172
|
-
const
|
|
173
|
-
const
|
|
174
|
-
.withDisappearingModeProtocol();
|
|
175
|
-
for (const jid of jids) {
|
|
176
|
-
usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
|
|
177
|
-
}
|
|
178
|
-
const result = await sock.executeUSyncQuery(usyncQuery);
|
|
307
|
+
const fetchStatus = async (jid) => {
|
|
308
|
+
const [result] = await interactiveQuery([{ tag: 'user', attrs: { jid } }], { tag: 'status', attrs: {} });
|
|
179
309
|
if (result) {
|
|
180
|
-
|
|
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
|
+
};
|
|
181
315
|
}
|
|
182
316
|
};
|
|
183
317
|
/** update the profile picture for yourself or a group */
|
|
@@ -279,51 +413,6 @@ const makeChatsSocket = (config) => {
|
|
|
279
413
|
]
|
|
280
414
|
});
|
|
281
415
|
};
|
|
282
|
-
const getBusinessProfile = async (jid) => {
|
|
283
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
284
|
-
const results = await query({
|
|
285
|
-
tag: 'iq',
|
|
286
|
-
attrs: {
|
|
287
|
-
to: 's.whatsapp.net',
|
|
288
|
-
xmlns: 'w:biz',
|
|
289
|
-
type: 'get'
|
|
290
|
-
},
|
|
291
|
-
content: [{
|
|
292
|
-
tag: 'business_profile',
|
|
293
|
-
attrs: { v: '244' },
|
|
294
|
-
content: [{
|
|
295
|
-
tag: 'profile',
|
|
296
|
-
attrs: { jid }
|
|
297
|
-
}]
|
|
298
|
-
}]
|
|
299
|
-
});
|
|
300
|
-
const profileNode = (0, WABinary_1.getBinaryNodeChild)(results, 'business_profile');
|
|
301
|
-
const profiles = (0, WABinary_1.getBinaryNodeChild)(profileNode, 'profile');
|
|
302
|
-
if (profiles) {
|
|
303
|
-
const address = (0, WABinary_1.getBinaryNodeChild)(profiles, 'address');
|
|
304
|
-
const description = (0, WABinary_1.getBinaryNodeChild)(profiles, 'description');
|
|
305
|
-
const website = (0, WABinary_1.getBinaryNodeChild)(profiles, 'website');
|
|
306
|
-
const email = (0, WABinary_1.getBinaryNodeChild)(profiles, 'email');
|
|
307
|
-
const category = (0, WABinary_1.getBinaryNodeChild)((0, WABinary_1.getBinaryNodeChild)(profiles, 'categories'), 'category');
|
|
308
|
-
const businessHours = (0, WABinary_1.getBinaryNodeChild)(profiles, 'business_hours');
|
|
309
|
-
const businessHoursConfig = businessHours
|
|
310
|
-
? (0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config')
|
|
311
|
-
: undefined;
|
|
312
|
-
const websiteStr = (_a = website === null || website === void 0 ? void 0 : website.content) === null || _a === void 0 ? void 0 : _a.toString();
|
|
313
|
-
return {
|
|
314
|
-
wid: (_b = profiles.attrs) === null || _b === void 0 ? void 0 : _b.jid,
|
|
315
|
-
address: (_c = address === null || address === void 0 ? void 0 : address.content) === null || _c === void 0 ? void 0 : _c.toString(),
|
|
316
|
-
description: ((_d = description === null || description === void 0 ? void 0 : description.content) === null || _d === void 0 ? void 0 : _d.toString()) || '',
|
|
317
|
-
website: websiteStr ? [websiteStr] : [],
|
|
318
|
-
email: (_e = email === null || email === void 0 ? void 0 : email.content) === null || _e === void 0 ? void 0 : _e.toString(),
|
|
319
|
-
category: (_f = category === null || category === void 0 ? void 0 : category.content) === null || _f === void 0 ? void 0 : _f.toString(),
|
|
320
|
-
'business_hours': {
|
|
321
|
-
timezone: (_g = businessHours === null || businessHours === void 0 ? void 0 : businessHours.attrs) === null || _g === void 0 ? void 0 : _g.timezone,
|
|
322
|
-
'business_config': businessHoursConfig === null || businessHoursConfig === void 0 ? void 0 : businessHoursConfig.map(({ attrs }) => attrs)
|
|
323
|
-
}
|
|
324
|
-
};
|
|
325
|
-
}
|
|
326
|
-
};
|
|
327
416
|
const cleanDirtyBits = async (type, fromTimestamp) => {
|
|
328
417
|
logger.info({ fromTimestamp }, 'clean dirty bits ' + type);
|
|
329
418
|
await sendNode({
|
|
@@ -417,12 +506,16 @@ const makeChatsSocket = (config) => {
|
|
|
417
506
|
states[name] = newState;
|
|
418
507
|
Object.assign(globalMutationMap, mutationMap);
|
|
419
508
|
logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
|
|
420
|
-
await authState.keys.set({ 'app-state-sync-version': {
|
|
509
|
+
await authState.keys.set({ 'app-state-sync-version': {
|
|
510
|
+
[name]: newState
|
|
511
|
+
} });
|
|
421
512
|
}
|
|
422
513
|
// only process if there are syncd patches
|
|
423
514
|
if (patches.length) {
|
|
424
515
|
const { state: newState, mutationMap } = await (0, Utils_1.decodePatches)(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
|
|
425
|
-
await authState.keys.set({ 'app-state-sync-version': {
|
|
516
|
+
await authState.keys.set({ 'app-state-sync-version': {
|
|
517
|
+
[name]: newState
|
|
518
|
+
} });
|
|
426
519
|
logger.info(`synced ${name} to v${newState.version}`);
|
|
427
520
|
initialVersionMap[name] = newState.version;
|
|
428
521
|
Object.assign(globalMutationMap, mutationMap);
|
|
@@ -437,11 +530,13 @@ const makeChatsSocket = (config) => {
|
|
|
437
530
|
catch (error) {
|
|
438
531
|
// if retry attempts overshoot
|
|
439
532
|
// or key not found
|
|
440
|
-
const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS
|
|
441
|
-
|
|
442
|
-
|
|
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';
|
|
443
536
|
logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
|
|
444
|
-
await authState.keys.set({ 'app-state-sync-version': {
|
|
537
|
+
await authState.keys.set({ 'app-state-sync-version': {
|
|
538
|
+
[name]: null
|
|
539
|
+
} });
|
|
445
540
|
// increment number of retries
|
|
446
541
|
attemptsMap[name] = (attemptsMap[name] || 0) + 1;
|
|
447
542
|
if (isIrrecoverableError) {
|
|
@@ -491,7 +586,7 @@ const makeChatsSocket = (config) => {
|
|
|
491
586
|
await sendNode({
|
|
492
587
|
tag: 'presence',
|
|
493
588
|
attrs: {
|
|
494
|
-
name: me.name
|
|
589
|
+
name: me.name,
|
|
495
590
|
type
|
|
496
591
|
}
|
|
497
592
|
});
|
|
@@ -525,22 +620,22 @@ const makeChatsSocket = (config) => {
|
|
|
525
620
|
id: generateMessageTag(),
|
|
526
621
|
type: 'subscribe'
|
|
527
622
|
},
|
|
528
|
-
content: tcToken
|
|
529
|
-
|
|
623
|
+
content: tcToken ?
|
|
624
|
+
[
|
|
530
625
|
{
|
|
531
626
|
tag: 'tctoken',
|
|
532
627
|
attrs: {},
|
|
533
628
|
content: tcToken
|
|
534
629
|
}
|
|
535
|
-
]
|
|
536
|
-
|
|
630
|
+
] :
|
|
631
|
+
undefined
|
|
537
632
|
}));
|
|
538
633
|
const handlePresenceUpdate = ({ tag, attrs, content }) => {
|
|
539
634
|
var _a;
|
|
540
635
|
let presence;
|
|
541
636
|
const jid = attrs.from;
|
|
542
637
|
const participant = attrs.participant || attrs.from;
|
|
543
|
-
if (shouldIgnoreJid(jid) && jid
|
|
638
|
+
if (shouldIgnoreJid(jid) && jid !== '@s.whatsapp.net') {
|
|
544
639
|
return;
|
|
545
640
|
}
|
|
546
641
|
if (tag === 'presence') {
|
|
@@ -564,7 +659,9 @@ const makeChatsSocket = (config) => {
|
|
|
564
659
|
logger.error({ tag, attrs, content }, 'recv invalid presence node');
|
|
565
660
|
}
|
|
566
661
|
if (presence) {
|
|
567
|
-
ev.emit('presence.update', { id: jid, presences: {
|
|
662
|
+
ev.emit('presence.update', { id: jid, presences: {
|
|
663
|
+
[participant]: presence
|
|
664
|
+
} });
|
|
568
665
|
}
|
|
569
666
|
};
|
|
570
667
|
const appPatch = async (patchCreate) => {
|
|
@@ -615,7 +712,9 @@ const makeChatsSocket = (config) => {
|
|
|
615
712
|
]
|
|
616
713
|
};
|
|
617
714
|
await query(node);
|
|
618
|
-
await authState.keys.set({ 'app-state-sync-version': {
|
|
715
|
+
await authState.keys.set({ 'app-state-sync-version': {
|
|
716
|
+
[name]: state
|
|
717
|
+
} });
|
|
619
718
|
});
|
|
620
719
|
});
|
|
621
720
|
if (config.emitOwnEvents) {
|
|
@@ -628,7 +727,7 @@ const makeChatsSocket = (config) => {
|
|
|
628
727
|
};
|
|
629
728
|
/** sending non-abt props may fix QR scan fail if server expects */
|
|
630
729
|
const fetchProps = async () => {
|
|
631
|
-
var _a, _b
|
|
730
|
+
var _a, _b;
|
|
632
731
|
const resultNode = await query({
|
|
633
732
|
tag: 'iq',
|
|
634
733
|
attrs: {
|
|
@@ -637,19 +736,20 @@ const makeChatsSocket = (config) => {
|
|
|
637
736
|
type: 'get',
|
|
638
737
|
},
|
|
639
738
|
content: [
|
|
640
|
-
{
|
|
739
|
+
{
|
|
740
|
+
tag: 'props',
|
|
741
|
+
attrs: {
|
|
641
742
|
protocol: '2',
|
|
642
743
|
hash: ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.lastPropHash) || ''
|
|
643
|
-
}
|
|
744
|
+
}
|
|
745
|
+
}
|
|
644
746
|
]
|
|
645
747
|
});
|
|
646
748
|
const propsNode = (0, WABinary_1.getBinaryNodeChild)(resultNode, 'props');
|
|
647
749
|
let props = {};
|
|
648
750
|
if (propsNode) {
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
ev.emit('creds.update', authState.creds);
|
|
652
|
-
}
|
|
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);
|
|
653
753
|
props = (0, WABinary_1.reduceBinaryNodeToDictionary)(propsNode, 'prop');
|
|
654
754
|
}
|
|
655
755
|
logger.debug('fetched props');
|
|
@@ -659,7 +759,7 @@ const makeChatsSocket = (config) => {
|
|
|
659
759
|
* modify a chat -- mark unread, read etc.
|
|
660
760
|
* lastMessages must be sorted in reverse chronologically
|
|
661
761
|
* requires the last messages till the last message received; required for archive & unread
|
|
662
|
-
|
|
762
|
+
*/
|
|
663
763
|
const chatModify = (mod, jid) => {
|
|
664
764
|
const patch = (0, Utils_1.chatModificationToAppPatch)(mod, jid);
|
|
665
765
|
return appPatch(patch);
|
|
@@ -743,25 +843,24 @@ const makeChatsSocket = (config) => {
|
|
|
743
843
|
}
|
|
744
844
|
}
|
|
745
845
|
const historyMsg = (0, Utils_1.getHistoryMsg)(msg.message);
|
|
746
|
-
const shouldProcessHistoryMsg = historyMsg
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
846
|
+
const shouldProcessHistoryMsg = historyMsg ?
|
|
847
|
+
(shouldSyncHistoryMessage(historyMsg) &&
|
|
848
|
+
Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType)) :
|
|
849
|
+
false;
|
|
750
850
|
if (historyMsg && !authState.creds.myAppStateKeyId) {
|
|
751
851
|
logger.warn('skipping app state sync, as myAppStateKeyId is not set');
|
|
752
852
|
pendingAppStateSync = true;
|
|
753
853
|
}
|
|
754
854
|
await Promise.all([
|
|
755
855
|
(async () => {
|
|
756
|
-
if (historyMsg
|
|
757
|
-
|
|
856
|
+
if (historyMsg &&
|
|
857
|
+
authState.creds.myAppStateKeyId) {
|
|
758
858
|
pendingAppStateSync = false;
|
|
759
859
|
await doAppStateSync();
|
|
760
860
|
}
|
|
761
861
|
})(),
|
|
762
862
|
(0, process_message_1.default)(msg, {
|
|
763
863
|
shouldProcessHistoryMsg,
|
|
764
|
-
placeholderResendCache,
|
|
765
864
|
ev,
|
|
766
865
|
creds: authState.creds,
|
|
767
866
|
keyStore: authState.keys,
|
|
@@ -770,8 +869,8 @@ const makeChatsSocket = (config) => {
|
|
|
770
869
|
getMessage: config.getMessage,
|
|
771
870
|
})
|
|
772
871
|
]);
|
|
773
|
-
if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare)
|
|
774
|
-
|
|
872
|
+
if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare) &&
|
|
873
|
+
pendingAppStateSync) {
|
|
775
874
|
await doAppStateSync();
|
|
776
875
|
pendingAppStateSync = false;
|
|
777
876
|
}
|
|
@@ -822,17 +921,18 @@ const makeChatsSocket = (config) => {
|
|
|
822
921
|
sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
|
|
823
922
|
.catch(error => onUnexpectedError(error, 'presence update requests'));
|
|
824
923
|
}
|
|
825
|
-
if (receivedPendingNotifications
|
|
924
|
+
if (receivedPendingNotifications) {
|
|
925
|
+
// if we don't have the app state key
|
|
826
926
|
// we keep buffering events until we finally have
|
|
827
927
|
// the key and can sync the messages
|
|
828
|
-
!((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId)) {
|
|
829
|
-
|
|
830
|
-
|
|
928
|
+
if (!((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId) && !config.mobile) {
|
|
929
|
+
ev.buffer();
|
|
930
|
+
needToFlushWithAppStateSync = true;
|
|
931
|
+
}
|
|
831
932
|
}
|
|
832
933
|
});
|
|
833
934
|
return {
|
|
834
935
|
...sock,
|
|
835
|
-
getBotListV2,
|
|
836
936
|
processingMutex,
|
|
837
937
|
fetchPrivacySettings,
|
|
838
938
|
upsertMessage,
|
|
@@ -842,15 +942,12 @@ const makeChatsSocket = (config) => {
|
|
|
842
942
|
profilePictureUrl,
|
|
843
943
|
onWhatsApp,
|
|
844
944
|
fetchBlocklist,
|
|
845
|
-
fetchDisappearingDuration,
|
|
846
945
|
fetchStatus,
|
|
847
946
|
updateProfilePicture,
|
|
848
947
|
removeProfilePicture,
|
|
849
948
|
updateProfileStatus,
|
|
850
949
|
updateProfileName,
|
|
851
950
|
updateBlockStatus,
|
|
852
|
-
updateCallPrivacy,
|
|
853
|
-
updateMessagesPrivacy,
|
|
854
951
|
updateLastSeenPrivacy,
|
|
855
952
|
updateOnlinePrivacy,
|
|
856
953
|
updateProfilePicturePrivacy,
|
|
@@ -865,6 +962,7 @@ const makeChatsSocket = (config) => {
|
|
|
865
962
|
addChatLabel,
|
|
866
963
|
removeChatLabel,
|
|
867
964
|
addMessageLabel,
|
|
965
|
+
checkStatusWA,
|
|
868
966
|
removeMessageLabel,
|
|
869
967
|
star
|
|
870
968
|
};
|