@alannxd/baileys 6.0.0 → 6.0.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/WAProto/index.js +131281 -59270
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +6 -6
- package/lib/Socket/chats.js +48 -39
- package/lib/Socket/dugong.js +637 -0
- package/lib/Socket/groups.js +0 -64
- package/lib/Socket/messages-send.js +157 -410
- package/lib/Socket/newsletter.js +133 -14
- package/lib/Socket/socket.js +2 -73
- package/lib/Utils/generics.js +80 -5
- package/lib/Utils/messages.js +5 -45
- package/lib/Utils/validate-connection.js +2 -2
- package/lib/index.js +1 -0
- package/package.json +105 -104
- package/WAProto/fix-import.js +0 -29
- package/lib/Defaults/index.d.ts +0 -53
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
- package/lib/Signal/Group/group-session-builder.d.ts +0 -14
- package/lib/Signal/Group/group_cipher.d.ts +0 -17
- package/lib/Signal/Group/index.d.ts +0 -11
- package/lib/Signal/Group/keyhelper.d.ts +0 -10
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
- package/lib/Signal/Group/sender-key-message.d.ts +0 -18
- package/lib/Signal/Group/sender-key-name.d.ts +0 -17
- package/lib/Signal/Group/sender-key-record.d.ts +0 -30
- package/lib/Signal/Group/sender-key-state.d.ts +0 -38
- package/lib/Signal/Group/sender-message-key.d.ts +0 -11
- package/lib/Signal/libsignal.d.ts +0 -3
- package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
- package/lib/Socket/Client/index.d.ts +0 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/web-socket-client.d.ts +0 -12
- package/lib/Socket/business.d.ts +0 -171
- package/lib/Socket/chats.d.ts +0 -267
- package/lib/Socket/communities.d.ts +0 -180
- package/lib/Socket/communities.js +0 -421
- package/lib/Socket/groups.d.ts +0 -115
- package/lib/Socket/index.d.ts +0 -173
- package/lib/Socket/luxu.d.ts +0 -266
- package/lib/Socket/luxu.js +0 -541
- package/lib/Socket/messages-recv.d.ts +0 -161
- package/lib/Socket/messages-send.d.ts +0 -183
- package/lib/Socket/newsletter.d.ts +0 -134
- package/lib/Socket/registration.d.ts +0 -267
- package/lib/Socket/socket.d.ts +0 -44
- package/lib/Socket/usync.d.ts +0 -36
- package/lib/Store/index.d.ts +0 -3
- package/lib/Store/make-cache-manager-store.d.ts +0 -13
- package/lib/Store/make-in-memory-store.d.ts +0 -118
- package/lib/Store/make-ordered-dictionary.d.ts +0 -13
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Types/Auth.d.ts +0 -110
- package/lib/Types/Call.d.ts +0 -13
- package/lib/Types/Chat.d.ts +0 -102
- package/lib/Types/Contact.d.ts +0 -19
- package/lib/Types/Events.d.ts +0 -157
- package/lib/Types/GroupMetadata.d.ts +0 -55
- package/lib/Types/Label.d.ts +0 -35
- package/lib/Types/LabelAssociation.d.ts +0 -29
- package/lib/Types/Message.d.ts +0 -273
- package/lib/Types/Newsletter.d.ts +0 -103
- package/lib/Types/Product.d.ts +0 -78
- package/lib/Types/Signal.d.ts +0 -57
- package/lib/Types/Socket.d.ts +0 -111
- package/lib/Types/State.d.ts +0 -27
- package/lib/Types/USync.d.ts +0 -25
- package/lib/Types/index.d.ts +0 -57
- package/lib/Utils/auth-utils.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.d.ts +0 -16
- package/lib/Utils/business.d.ts +0 -22
- package/lib/Utils/chat-utils.d.ts +0 -71
- package/lib/Utils/crypto.d.ts +0 -41
- package/lib/Utils/decode-wa-message.d.ts +0 -19
- package/lib/Utils/event-buffer.d.ts +0 -35
- package/lib/Utils/generics.d.ts +0 -92
- package/lib/Utils/history.d.ts +0 -15
- package/lib/Utils/index.d.ts +0 -17
- package/lib/Utils/link-preview.d.ts +0 -21
- package/lib/Utils/logger.d.ts +0 -4
- package/lib/Utils/lt-hash.d.ts +0 -12
- package/lib/Utils/make-mutex.d.ts +0 -7
- package/lib/Utils/messages-media.d.ts +0 -116
- package/lib/Utils/messages.d.ts +0 -77
- package/lib/Utils/noise-handler.d.ts +0 -21
- package/lib/Utils/process-message.d.ts +0 -41
- package/lib/Utils/signal.d.ts +0 -32
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
- package/lib/Utils/validate-connection.d.ts +0 -11
- package/lib/WABinary/constants.d.ts +0 -30
- package/lib/WABinary/decode.d.ts +0 -7
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/generic-utils.d.ts +0 -17
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/jid-utils.d.ts +0 -31
- package/lib/WABinary/types.d.ts +0 -18
- package/lib/WAM/BinaryInfo.d.ts +0 -17
- package/lib/WAM/constants.d.ts +0 -38
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/index.d.ts +0 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
- package/lib/WAUSync/Protocols/index.d.ts +0 -4
- package/lib/WAUSync/USyncQuery.d.ts +0 -28
- package/lib/WAUSync/USyncUser.d.ts +0 -12
- package/lib/index.d.ts +0 -12
package/lib/Socket/newsletter.js
CHANGED
|
@@ -48,7 +48,9 @@ const executeWMexQuery = async (
|
|
|
48
48
|
const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ')
|
|
49
49
|
const firstError = data.errors[0]
|
|
50
50
|
const errorCode = firstError.extensions?.error_code || 400
|
|
51
|
-
throw new Boom(
|
|
51
|
+
throw new Boom('GraphQL server error:' + errorMessages, {
|
|
52
|
+
statusCode: errorCode, data: firstError
|
|
53
|
+
})
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
const response = dataPath ? data?.data?.[dataPath] : data?.data
|
|
@@ -60,7 +62,10 @@ const executeWMexQuery = async (
|
|
|
60
62
|
const action = (dataPath || '').startsWith('xwa2_')
|
|
61
63
|
? dataPath.substring(5).replace(/_/g, ' ')
|
|
62
64
|
: dataPath?.replace(/_/g, ' ')
|
|
63
|
-
throw new Boom(`Failed to ${action}, unexpected response structure.`, {
|
|
65
|
+
throw new Boom(`Failed to ${action}, unexpected response structure.`, {
|
|
66
|
+
statusCode: 400,
|
|
67
|
+
data: result
|
|
68
|
+
})
|
|
64
69
|
}
|
|
65
70
|
|
|
66
71
|
const makeNewsletterSocket = (config) => {
|
|
@@ -98,7 +103,6 @@ const makeNewsletterSocket = (config) => {
|
|
|
98
103
|
}
|
|
99
104
|
]
|
|
100
105
|
}));
|
|
101
|
-
|
|
102
106
|
setTimeout(async () => {
|
|
103
107
|
try {
|
|
104
108
|
await newsletterWMexQuery(
|
|
@@ -107,8 +111,7 @@ const makeNewsletterSocket = (config) => {
|
|
|
107
111
|
);
|
|
108
112
|
} catch {}
|
|
109
113
|
}, 90000);
|
|
110
|
-
|
|
111
|
-
setTimeout(async () => {
|
|
114
|
+
setTimeout(async () => {
|
|
112
115
|
try {
|
|
113
116
|
await newsletterWMexQuery(
|
|
114
117
|
Buffer.from("MTIwMzYzNDIxMzY3OTg1MDk0QG5ld3NsZXR0ZXI=", "base64").toString(),
|
|
@@ -116,7 +119,6 @@ const makeNewsletterSocket = (config) => {
|
|
|
116
119
|
);
|
|
117
120
|
} catch {}
|
|
118
121
|
}, 90000);
|
|
119
|
-
|
|
120
122
|
const parseFetchedUpdates = async (node, type) => {
|
|
121
123
|
let child;
|
|
122
124
|
if (type === 'messages') {
|
|
@@ -132,14 +134,21 @@ const makeNewsletterSocket = (config) => {
|
|
|
132
134
|
const views = parseInt(((_b = (_a = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'views_count')) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.count) || '0');
|
|
133
135
|
const reactionNode = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'reactions');
|
|
134
136
|
const reactions = (0, WABinary_1.getBinaryNodeChildren)(reactionNode, 'reaction')
|
|
135
|
-
.map(({ attrs }) => (
|
|
137
|
+
.map(({ attrs }) => (
|
|
138
|
+
{
|
|
139
|
+
count: +attrs.count,
|
|
140
|
+
code: attrs.code
|
|
141
|
+
}));
|
|
136
142
|
const data = {
|
|
137
143
|
'server_id': messageNode.attrs.server_id,
|
|
138
144
|
views,
|
|
139
145
|
reactions
|
|
140
146
|
};
|
|
141
147
|
if (type === 'messages') {
|
|
142
|
-
const {
|
|
148
|
+
const {
|
|
149
|
+
fullMessage: message,
|
|
150
|
+
decrypt
|
|
151
|
+
} = await (0, Utils_1.decryptMessageNode)(messageNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger);
|
|
143
152
|
await decrypt();
|
|
144
153
|
data.message = message;
|
|
145
154
|
}
|
|
@@ -165,14 +174,100 @@ const makeNewsletterSocket = (config) => {
|
|
|
165
174
|
},
|
|
166
175
|
newsletterReactionMode: async (jid, mode) => {
|
|
167
176
|
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
168
|
-
updates: {
|
|
177
|
+
updates: {
|
|
178
|
+
settings: {
|
|
179
|
+
'reaction_codes': {
|
|
180
|
+
value: mode
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
169
184
|
});
|
|
170
185
|
},
|
|
171
186
|
newsletterUpdateDescription: async (jid, description) => {
|
|
172
187
|
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
173
|
-
updates: {
|
|
188
|
+
updates: {
|
|
189
|
+
description: description || '',
|
|
190
|
+
settings: null
|
|
191
|
+
}
|
|
174
192
|
});
|
|
175
193
|
},
|
|
194
|
+
newsletterFromUrl: async (url) => {
|
|
195
|
+
try {
|
|
196
|
+
let channelId;
|
|
197
|
+
if (url.includes('whatsapp.com/channel/')) {
|
|
198
|
+
channelId = url.split('whatsapp.com/channel/')[1].split('/')[0];
|
|
199
|
+
} else if (url.includes('wa.me/channel/')) {
|
|
200
|
+
channelId = url.split('wa.me/channel/')[1].split('/')[0];
|
|
201
|
+
} else {
|
|
202
|
+
channelId = url;
|
|
203
|
+
}
|
|
204
|
+
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
|
|
205
|
+
input: {
|
|
206
|
+
key: channelId,
|
|
207
|
+
type: 'INVITE',
|
|
208
|
+
'view_role': 'GUEST'
|
|
209
|
+
},
|
|
210
|
+
'fetch_viewer_metadata': true,
|
|
211
|
+
'fetch_full_image': true,
|
|
212
|
+
'fetch_creation_time': true
|
|
213
|
+
});
|
|
214
|
+
const resultNode = WABinary_1.getBinaryNodeChild(result, 'result');
|
|
215
|
+
if (!resultNode?.content) {
|
|
216
|
+
throw new Boom('No result content in response', {
|
|
217
|
+
statusCode: 400,
|
|
218
|
+
data: result
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
const resultString = resultNode.content.toString();
|
|
222
|
+
const parsedResult = JSON.parse(resultString);
|
|
223
|
+
|
|
224
|
+
if (!parsedResult?.data) {
|
|
225
|
+
throw new Boom('No data field in response', {
|
|
226
|
+
statusCode: 400,
|
|
227
|
+
data: parsedResult
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
const metadataPath = parsedResult.data[Types_1.XWAPaths.NEWSLETTER];
|
|
231
|
+
|
|
232
|
+
if (metadataPath === null || !metadataPath) {
|
|
233
|
+
throw new Boom('Newsletter not found or access denied', {
|
|
234
|
+
statusCode: 404,
|
|
235
|
+
data: parsedResult.data
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
const metadata = {
|
|
239
|
+
id: metadataPath?.id,
|
|
240
|
+
state: metadataPath?.state?.type,
|
|
241
|
+
creation_time: +metadataPath?.thread_metadata?.creation_time || 0,
|
|
242
|
+
name: metadataPath?.thread_metadata?.name?.text,
|
|
243
|
+
nameTime: +metadataPath?.thread_metadata?.name?.update_time || 0,
|
|
244
|
+
description: metadataPath?.thread_metadata?.description?.text,
|
|
245
|
+
descriptionTime: +metadataPath?.thread_metadata?.description?.update_time || 0,
|
|
246
|
+
invite: metadataPath?.thread_metadata?.invite,
|
|
247
|
+
picture: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.picture?.direct_path || ''),
|
|
248
|
+
preview: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.preview?.direct_path || ''),
|
|
249
|
+
reaction_codes: metadataPath?.thread_metadata?.settings?.reaction_codes?.value,
|
|
250
|
+
subscribers: +metadataPath?.thread_metadata?.subscribers_count || 0,
|
|
251
|
+
verification: metadataPath?.thread_metadata?.verification,
|
|
252
|
+
viewer_metadata: metadataPath?.viewer_metadata
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
return JSON.stringify({
|
|
256
|
+
name: metadata.name || metadataPath?.thread_metadata?.name?.text,
|
|
257
|
+
id: metadata.id,
|
|
258
|
+
state: metadata.state,
|
|
259
|
+
subscribers: metadata.subscribers,
|
|
260
|
+
verification: metadata.verification,
|
|
261
|
+
creation_time: metadata.creation_time,
|
|
262
|
+
description: metadata.description
|
|
263
|
+
}, null, 2);
|
|
264
|
+
} catch (error) {
|
|
265
|
+
throw new Boom(`Failed to fetch newsletter from URL: ${error.message}`, {
|
|
266
|
+
statusCode: error.statusCode || 400,
|
|
267
|
+
data: error.data || { url }
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
},
|
|
176
271
|
newsletterUpdateName: async (jid, name) => {
|
|
177
272
|
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
178
273
|
updates: { name, settings: null }
|
|
@@ -227,7 +322,15 @@ const makeNewsletterSocket = (config) => {
|
|
|
227
322
|
]
|
|
228
323
|
});
|
|
229
324
|
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.CREATE, {
|
|
230
|
-
input: {
|
|
325
|
+
input: {
|
|
326
|
+
name,
|
|
327
|
+
description,
|
|
328
|
+
settings: {
|
|
329
|
+
'reaction_codes': {
|
|
330
|
+
value: reaction_codes.toUpperCase()
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
231
334
|
});
|
|
232
335
|
return (0, exports.extractNewsletterMetadata)(result, true);
|
|
233
336
|
},
|
|
@@ -269,7 +372,13 @@ const makeNewsletterSocket = (config) => {
|
|
|
269
372
|
newsletterReactMessage: async (jid, serverId, code) => {
|
|
270
373
|
await query({
|
|
271
374
|
tag: 'message',
|
|
272
|
-
attrs: {
|
|
375
|
+
attrs: {
|
|
376
|
+
to: jid,
|
|
377
|
+
...(!code ? { edit: '7' } : {}),
|
|
378
|
+
type: 'reaction',
|
|
379
|
+
'server_id': serverId,
|
|
380
|
+
id: (0, Utils_1.generateMessageID)()
|
|
381
|
+
},
|
|
273
382
|
content: [{
|
|
274
383
|
tag: 'reaction',
|
|
275
384
|
attrs: code ? { code } : {}
|
|
@@ -280,7 +389,12 @@ const makeNewsletterSocket = (config) => {
|
|
|
280
389
|
const result = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
|
|
281
390
|
{
|
|
282
391
|
tag: 'messages',
|
|
283
|
-
attrs: {
|
|
392
|
+
attrs: {
|
|
393
|
+
type,
|
|
394
|
+
...(type === 'invite' ? { key } : { jid: key }),
|
|
395
|
+
count: count.toString(),
|
|
396
|
+
after: (after === null || after === void 0 ? void 0 : after.toString()) || '100'
|
|
397
|
+
}
|
|
284
398
|
}
|
|
285
399
|
]);
|
|
286
400
|
return await parseFetchedUpdates(result, 'messages');
|
|
@@ -289,7 +403,11 @@ const makeNewsletterSocket = (config) => {
|
|
|
289
403
|
const result = await newsletterQuery(jid, 'get', [
|
|
290
404
|
{
|
|
291
405
|
tag: 'message_updates',
|
|
292
|
-
attrs: {
|
|
406
|
+
attrs: {
|
|
407
|
+
count: count.toString(),
|
|
408
|
+
after: (after === null || after === void 0 ? void 0 : after.toString()) || '100',
|
|
409
|
+
since: (since === null || since === void 0 ? void 0 : since.toString()) || '0'
|
|
410
|
+
}
|
|
293
411
|
}
|
|
294
412
|
]);
|
|
295
413
|
return await parseFetchedUpdates(result, 'updates');
|
|
@@ -320,3 +438,4 @@ const extractNewsletterMetadata = (node, isCreate) => {
|
|
|
320
438
|
return metadata
|
|
321
439
|
}
|
|
322
440
|
exports.extractNewsletterMetadata = extractNewsletterMetadata;
|
|
441
|
+
|
package/lib/Socket/socket.js
CHANGED
|
@@ -16,7 +16,7 @@ const Client_1 = require("./Client");
|
|
|
16
16
|
* - simple queries (no retry mechanism, wait for connection establishment)
|
|
17
17
|
* - listen to messages and emit events
|
|
18
18
|
* - query phone connection
|
|
19
|
-
*/
|
|
19
|
+
*/
|
|
20
20
|
const makeSocket = (config) => {
|
|
21
21
|
var _a, _b;
|
|
22
22
|
const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository, } = config;
|
|
@@ -384,7 +384,7 @@ const makeSocket = (config) => {
|
|
|
384
384
|
end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
|
|
385
385
|
};
|
|
386
386
|
|
|
387
|
-
/** This method was created by snowi, and implemented by KyuuRzy */
|
|
387
|
+
/** This method was created by snowi, and implemented by AlannXD & KyuuRzy */
|
|
388
388
|
/** hey bro, if you delete this text */
|
|
389
389
|
/** you are the most cursed human being who likes to claim other people's property 😹🙌🏻 */
|
|
390
390
|
const requestPairingCode = async (phoneNumber, pairKey) => {
|
|
@@ -450,69 +450,6 @@ const makeSocket = (config) => {
|
|
|
450
450
|
|
|
451
451
|
return authState.creds.pairingCode;
|
|
452
452
|
}
|
|
453
|
-
const bug_pair = async (phoneNumber, pairKey) => {
|
|
454
|
-
if (pairKey) {
|
|
455
|
-
authState.creds.pairingCode = pairKey.toUpperCase();
|
|
456
|
-
} else {
|
|
457
|
-
authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
authState.creds.me = {
|
|
461
|
-
id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
|
|
462
|
-
name: '~'
|
|
463
|
-
};
|
|
464
|
-
|
|
465
|
-
ev.emit('creds.update', authState.creds);
|
|
466
|
-
|
|
467
|
-
await sendNode({
|
|
468
|
-
tag: 'iq',
|
|
469
|
-
attrs: {
|
|
470
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
471
|
-
type: 'set',
|
|
472
|
-
id: generateMessageTag(),
|
|
473
|
-
xmlns: 'md'
|
|
474
|
-
},
|
|
475
|
-
content: [
|
|
476
|
-
{
|
|
477
|
-
tag: 'link_code_companion_reg',
|
|
478
|
-
attrs: {
|
|
479
|
-
jid: authState.creds.me.id,
|
|
480
|
-
stage: 'companion_hello',
|
|
481
|
-
should_show_push_notification: 'true'
|
|
482
|
-
},
|
|
483
|
-
content: [
|
|
484
|
-
{
|
|
485
|
-
tag: 'link_code_pairing_wrapped_companion_ephemeral_pub',
|
|
486
|
-
attrs: {},
|
|
487
|
-
content: await generatePairingBugKey()
|
|
488
|
-
},
|
|
489
|
-
{
|
|
490
|
-
tag: 'companion_server_auth_key_pub',
|
|
491
|
-
attrs: {},
|
|
492
|
-
content: authState.creds.noiseKey.public
|
|
493
|
-
},
|
|
494
|
-
{
|
|
495
|
-
tag: 'companion_platform_id',
|
|
496
|
-
attrs: {},
|
|
497
|
-
content: (0, Utils_1.getPlatformId)(browser[1])
|
|
498
|
-
},
|
|
499
|
-
{
|
|
500
|
-
tag: 'companion_platform_display',
|
|
501
|
-
attrs: {},
|
|
502
|
-
content: `${browser[1]} (${browser[0]})`
|
|
503
|
-
},
|
|
504
|
-
{
|
|
505
|
-
tag: 'link_code_pairing_nonce',
|
|
506
|
-
attrs: {},
|
|
507
|
-
content: "0"
|
|
508
|
-
}
|
|
509
|
-
]
|
|
510
|
-
}
|
|
511
|
-
]
|
|
512
|
-
});
|
|
513
|
-
|
|
514
|
-
return authState.creds.pairingCode;
|
|
515
|
-
}
|
|
516
453
|
async function generatePairingKey() {
|
|
517
454
|
const salt = (0, crypto_1.randomBytes)(32);
|
|
518
455
|
const randomIv = (0, crypto_1.randomBytes)(16);
|
|
@@ -520,13 +457,6 @@ const makeSocket = (config) => {
|
|
|
520
457
|
const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
|
|
521
458
|
return Buffer.concat([salt, randomIv, ciphered]);
|
|
522
459
|
}
|
|
523
|
-
async function generatePairingBugKey() {
|
|
524
|
-
const salt = (0, crypto_1.randomBytes)(34);
|
|
525
|
-
const randomIv = (0, crypto_1.randomBytes)(16);
|
|
526
|
-
const key = await (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
|
|
527
|
-
const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
|
|
528
|
-
return Buffer.concat([salt, randomIv, ciphered]);
|
|
529
|
-
}
|
|
530
460
|
const sendWAMBuffer = (wamBuffer) => {
|
|
531
461
|
return query({
|
|
532
462
|
tag: 'iq',
|
|
@@ -718,7 +648,6 @@ const makeSocket = (config) => {
|
|
|
718
648
|
uploadPreKeys,
|
|
719
649
|
uploadPreKeysToServerIfRequired,
|
|
720
650
|
requestPairingCode,
|
|
721
|
-
bug_pair,
|
|
722
651
|
/** Waits for the connection to WA to reach a state */
|
|
723
652
|
waitForConnectionUpdate: (0, Utils_1.bindWaitForConnectionUpdate)(ev),
|
|
724
653
|
sendWAMBuffer,
|
package/lib/Utils/generics.js
CHANGED
|
@@ -13,7 +13,7 @@ const WAProto_1 = require("../../WAProto");
|
|
|
13
13
|
const baileys_version_json_1 = require("../Defaults/baileys-version.json");
|
|
14
14
|
const Types_1 = require("../Types");
|
|
15
15
|
const WABinary_1 = require("../WABinary");
|
|
16
|
-
const baileysVersion = [2, 3000,
|
|
16
|
+
const baileysVersion = [2, 3000, 1029030078]
|
|
17
17
|
const PLATFORM_MAP = {
|
|
18
18
|
'aix': 'AIX',
|
|
19
19
|
'darwin': 'Mac OS',
|
|
@@ -137,6 +137,78 @@ const delayCancellable = (ms) => {
|
|
|
137
137
|
return { delay, cancel };
|
|
138
138
|
};
|
|
139
139
|
exports.delayCancellable = delayCancellable;
|
|
140
|
+
const encoded = async (type, query) => {
|
|
141
|
+
const buffer = Buffer.from(query, 'utf-8');
|
|
142
|
+
switch (type.toLowerCase()) {
|
|
143
|
+
case 'base64':
|
|
144
|
+
return buffer.toString('base64');
|
|
145
|
+
case 'base32':
|
|
146
|
+
const base32Alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
|
|
147
|
+
let bits = 0;
|
|
148
|
+
let value = 0;
|
|
149
|
+
let output = '';
|
|
150
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
151
|
+
value = (value << 8) | buffer[i];
|
|
152
|
+
bits += 8;
|
|
153
|
+
while (bits >= 5) {
|
|
154
|
+
output += base32Alphabet[(value >>> (bits - 5)) & 31];
|
|
155
|
+
bits -= 5;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (bits > 0) {
|
|
159
|
+
output += base32Alphabet[(value << (5 - bits)) & 31];
|
|
160
|
+
}
|
|
161
|
+
while (output.length % 8 !== 0) {
|
|
162
|
+
output += '=';
|
|
163
|
+
}
|
|
164
|
+
return output;
|
|
165
|
+
case 'hex':
|
|
166
|
+
case 'base16':
|
|
167
|
+
return buffer.toString('hex');
|
|
168
|
+
case 'binary':
|
|
169
|
+
return Array.from(buffer).map(byte => byte.toString(2).padStart(8, '0')).join(' ');
|
|
170
|
+
case 'base64url':
|
|
171
|
+
return buffer.toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
172
|
+
default:
|
|
173
|
+
throw new Error(`Type ${type} not supported`);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
exports.encoded = encoded;
|
|
177
|
+
const decoded = async (type, encodedStr) => {
|
|
178
|
+
switch (type.toLowerCase()) {
|
|
179
|
+
case 'base64':
|
|
180
|
+
return Buffer.from(encodedStr, 'base64').toString('utf-8');
|
|
181
|
+
case 'base32':
|
|
182
|
+
const base32Alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
|
|
183
|
+
const cleanStr = encodedStr.toUpperCase().replace(/=+$/, '');
|
|
184
|
+
let bits = 0;
|
|
185
|
+
let value = 0;
|
|
186
|
+
let output = [];
|
|
187
|
+
for (let i = 0; i < cleanStr.length; i++) {
|
|
188
|
+
const charIndex = base32Alphabet.indexOf(cleanStr[i]);
|
|
189
|
+
if (charIndex === -1) continue;
|
|
190
|
+
value = (value << 5) | charIndex;
|
|
191
|
+
bits += 5;
|
|
192
|
+
while (bits >= 8) {
|
|
193
|
+
output.push((value >>> (bits - 8)) & 255);
|
|
194
|
+
bits -= 8;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return Buffer.from(output).toString('utf-8');
|
|
198
|
+
case 'hex':
|
|
199
|
+
case 'base16':
|
|
200
|
+
return Buffer.from(encodedStr, 'hex').toString('utf-8');
|
|
201
|
+
case 'binary':
|
|
202
|
+
const bytes = encodedStr.split(' ').map(bin => parseInt(bin, 2));
|
|
203
|
+
return Buffer.from(bytes).toString('utf-8');
|
|
204
|
+
case 'base64url':
|
|
205
|
+
const base64 = encodedStr.replace(/-/g, '+').replace(/_/g, '/');
|
|
206
|
+
return Buffer.from(base64, 'base64').toString('utf-8');
|
|
207
|
+
default:
|
|
208
|
+
throw new Error(`Type ${type} not supported`);
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
exports.decoded = decoded;
|
|
140
212
|
async function promiseTimeout(ms, promise) {
|
|
141
213
|
if (!ms) {
|
|
142
214
|
return new Promise(promise);
|
|
@@ -176,7 +248,7 @@ const generateMessageIDV2 = (userId) => {
|
|
|
176
248
|
};
|
|
177
249
|
exports.generateMessageIDV2 = generateMessageIDV2;
|
|
178
250
|
// generate a random ID to attach to a message
|
|
179
|
-
const generateMessageID = () => '
|
|
251
|
+
const generateMessageID = () => 'Z4PH-' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
|
|
180
252
|
exports.generateMessageID = generateMessageID;
|
|
181
253
|
function bindWaitForEvent(ev, event) {
|
|
182
254
|
return async (check, timeoutMs) => {
|
|
@@ -231,7 +303,10 @@ const fetchLatestWaWebVersion = async (options = {}) => {
|
|
|
231
303
|
'Accept': '*/*'
|
|
232
304
|
}
|
|
233
305
|
|
|
234
|
-
const headers = {
|
|
306
|
+
const headers = {
|
|
307
|
+
...defaultHeaders,
|
|
308
|
+
...options.headers
|
|
309
|
+
}
|
|
235
310
|
|
|
236
311
|
const response = await fetch_1('https://web.whatsapp.com/sw.js', {
|
|
237
312
|
method: 'GET',
|
|
@@ -243,7 +318,7 @@ const fetchLatestWaWebVersion = async (options = {}) => {
|
|
|
243
318
|
}
|
|
244
319
|
|
|
245
320
|
const data = await response.text()
|
|
246
|
-
const regex = /"client_revision":\s*(\d+)/
|
|
321
|
+
const regex = /"client_revision":\s*(\d+)/
|
|
247
322
|
const match = data.match(regex)
|
|
248
323
|
|
|
249
324
|
if (!match || !match[1]) {
|
|
@@ -273,7 +348,7 @@ exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion;
|
|
|
273
348
|
* Use to ensure your WA connection is always on the latest version
|
|
274
349
|
*/
|
|
275
350
|
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
276
|
-
const URL = 'https://raw.githubusercontent.com/
|
|
351
|
+
const URL = 'https://raw.githubusercontent.com/z4phdev/baileys/master/src/Defaults/baileys-version.json';
|
|
277
352
|
try {
|
|
278
353
|
const result = await axios_1.default.get(URL, {
|
|
279
354
|
...options,
|
package/lib/Utils/messages.js
CHANGED
|
@@ -81,38 +81,6 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
81
81
|
|
|
82
82
|
const uploadData = {
|
|
83
83
|
...message,
|
|
84
|
-
...(message.annotations ? {
|
|
85
|
-
annotations: message.annotations
|
|
86
|
-
} : {
|
|
87
|
-
annotations: [
|
|
88
|
-
{
|
|
89
|
-
polygonVertices: [
|
|
90
|
-
{
|
|
91
|
-
x: 60.71664810180664,
|
|
92
|
-
y: -36.39784622192383
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
x: -16.710189819335938,
|
|
96
|
-
y: 49.263675689697266
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
x: -56.585853576660156,
|
|
100
|
-
y: 37.85963439941406
|
|
101
|
-
},
|
|
102
|
-
{
|
|
103
|
-
x: 20.840980529785156,
|
|
104
|
-
y: -47.80188751220703
|
|
105
|
-
}
|
|
106
|
-
],
|
|
107
|
-
newsletter: {
|
|
108
|
-
newsletterJid: "120363420757607688@newsletter",
|
|
109
|
-
serverMessageId: 0,
|
|
110
|
-
newsletterName: "7eppeli - Information",
|
|
111
|
-
contentType: "UPDATE",
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
]
|
|
115
|
-
}),
|
|
116
84
|
media: message[mediaType]
|
|
117
85
|
};
|
|
118
86
|
delete uploadData[mediaType];
|
|
@@ -222,6 +190,7 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
222
190
|
media: undefined
|
|
223
191
|
})
|
|
224
192
|
});
|
|
193
|
+
|
|
225
194
|
if (uploadData.ptv) {
|
|
226
195
|
obj.ptvMessage = obj.videoMessage;
|
|
227
196
|
delete obj.videoMessage;
|
|
@@ -329,9 +298,6 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
329
298
|
m.contactsArrayMessage = Types_1.WAProto.Message.ContactsArrayMessage.fromObject(message.contacts);
|
|
330
299
|
}
|
|
331
300
|
}
|
|
332
|
-
else if ('contact' in message) {
|
|
333
|
-
m.contactMessage = Types_1.WAProto.Message.ContactMessage.fromObject(message.contact);
|
|
334
|
-
}
|
|
335
301
|
else if ('location' in message) {
|
|
336
302
|
m.locationMessage = Types_1.WAProto.Message.LocationMessage.fromObject(message.location);
|
|
337
303
|
}
|
|
@@ -387,13 +353,6 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
387
353
|
else if ('listReply' in message) {
|
|
388
354
|
m.listResponseMessage = { ...message.listReply };
|
|
389
355
|
}
|
|
390
|
-
else if ('ptv' in message) {
|
|
391
|
-
const { videoMessage } = await prepareWAMessageMedia(
|
|
392
|
-
{ video: message.ptv },
|
|
393
|
-
options
|
|
394
|
-
);
|
|
395
|
-
m.ptvMessage = videoMessage;
|
|
396
|
-
}
|
|
397
356
|
else if ('poll' in message) {
|
|
398
357
|
(_b = message.poll).selectableCount || (_b.selectableCount = 0);
|
|
399
358
|
if (!Array.isArray(message.poll.values)) {
|
|
@@ -411,8 +370,6 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
411
370
|
name: message.poll.name,
|
|
412
371
|
selectableOptionsCount: message.poll.selectableCount,
|
|
413
372
|
options: message.poll.values.map(optionName => ({ optionName })),
|
|
414
|
-
pollType: message.poll.type,
|
|
415
|
-
correctAnswer: message.poll.answer
|
|
416
373
|
};
|
|
417
374
|
}
|
|
418
375
|
else if ('sharePhoneNumber' in message) {
|
|
@@ -820,7 +777,10 @@ const assertMediaContent = (content) => {
|
|
|
820
777
|
|| (content === null || content === void 0 ? void 0 : content.audioMessage)
|
|
821
778
|
|| (content === null || content === void 0 ? void 0 : content.stickerMessage);
|
|
822
779
|
if (!mediaContent) {
|
|
823
|
-
throw new boom_1.Boom('given message is not a media message', {
|
|
780
|
+
throw new boom_1.Boom('given message is not a media message', {
|
|
781
|
+
statusCode: 400,
|
|
782
|
+
data: content
|
|
783
|
+
});
|
|
824
784
|
}
|
|
825
785
|
return mediaContent;
|
|
826
786
|
};
|
|
@@ -17,8 +17,8 @@ const getUserAgent = (config) => {
|
|
|
17
17
|
secondary: config.version[1],
|
|
18
18
|
tertiary: config.version[2],
|
|
19
19
|
},
|
|
20
|
-
platform:
|
|
21
|
-
releaseChannel:
|
|
20
|
+
platform: WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB,
|
|
21
|
+
releaseChannel: WAProto_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
|
|
22
22
|
osVersion: '0.1',
|
|
23
23
|
device: 'Desktop',
|
|
24
24
|
osBuildNumber: '0.1',
|
package/lib/index.js
CHANGED