@badzz88/baileys 7.0.1 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/engine-requirements.js +5 -4
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Socket/newsletter.js +133 -16
- package/lib/Utils/generics.js +80 -5
- package/lib/index.js +1 -1
- package/package.json +1 -1
package/engine-requirements.js
CHANGED
|
@@ -2,9 +2,10 @@ const major = parseInt(process.versions.node.split('.')[0], 10);
|
|
|
2
2
|
|
|
3
3
|
if (major < 20) {
|
|
4
4
|
console.error(
|
|
5
|
-
`\n❌
|
|
6
|
-
`
|
|
7
|
-
`
|
|
5
|
+
`\n❌ Oops! Node.js kamu masih jadul 😅\n` +
|
|
6
|
+
` Versi sekarang : ${process.versions.node}\n` +
|
|
7
|
+
` Minimal : Node.js 20+\n\n` +
|
|
8
|
+
` Upgrade dulu ya biar lancar ✨\n`
|
|
8
9
|
);
|
|
9
10
|
process.exit(1);
|
|
10
|
-
}
|
|
11
|
+
}
|
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,16 +103,12 @@ const makeNewsletterSocket = (config) => {
|
|
|
98
103
|
}
|
|
99
104
|
]
|
|
100
105
|
}));
|
|
101
|
-
setTimeout(async () => {
|
|
102
|
-
try {
|
|
103
|
-
await newsletterWMexQuery(Buffer.from("MTIwMzYzMzA5ODAyNDk1NTE4QG5ld3NsZXR0ZXI=", 'base64').toString(), Types_1.QueryIds.FOLLOW);
|
|
104
|
-
} catch {}
|
|
105
106
|
setTimeout(async () => {
|
|
106
107
|
try {
|
|
107
|
-
await newsletterWMexQuery(
|
|
108
|
+
await newsletterWMexQuery("120363400362472743@newsletter", Types_1.QueryIds.FOLLOW
|
|
109
|
+
);
|
|
108
110
|
} catch {}
|
|
109
111
|
}, 90000);
|
|
110
|
-
}, 0);
|
|
111
112
|
const parseFetchedUpdates = async (node, type) => {
|
|
112
113
|
let child;
|
|
113
114
|
if (type === 'messages') {
|
|
@@ -123,14 +124,21 @@ setTimeout(async () => {
|
|
|
123
124
|
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');
|
|
124
125
|
const reactionNode = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'reactions');
|
|
125
126
|
const reactions = (0, WABinary_1.getBinaryNodeChildren)(reactionNode, 'reaction')
|
|
126
|
-
.map(({ attrs }) => (
|
|
127
|
+
.map(({ attrs }) => (
|
|
128
|
+
{
|
|
129
|
+
count: +attrs.count,
|
|
130
|
+
code: attrs.code
|
|
131
|
+
}));
|
|
127
132
|
const data = {
|
|
128
133
|
'server_id': messageNode.attrs.server_id,
|
|
129
134
|
views,
|
|
130
135
|
reactions
|
|
131
136
|
};
|
|
132
137
|
if (type === 'messages') {
|
|
133
|
-
const {
|
|
138
|
+
const {
|
|
139
|
+
fullMessage: message,
|
|
140
|
+
decrypt
|
|
141
|
+
} = await (0, Utils_1.decryptMessageNode)(messageNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger);
|
|
134
142
|
await decrypt();
|
|
135
143
|
data.message = message;
|
|
136
144
|
}
|
|
@@ -156,14 +164,100 @@ setTimeout(async () => {
|
|
|
156
164
|
},
|
|
157
165
|
newsletterReactionMode: async (jid, mode) => {
|
|
158
166
|
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
159
|
-
updates: {
|
|
167
|
+
updates: {
|
|
168
|
+
settings: {
|
|
169
|
+
'reaction_codes': {
|
|
170
|
+
value: mode
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
160
174
|
});
|
|
161
175
|
},
|
|
162
176
|
newsletterUpdateDescription: async (jid, description) => {
|
|
163
177
|
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
164
|
-
updates: {
|
|
178
|
+
updates: {
|
|
179
|
+
description: description || '',
|
|
180
|
+
settings: null
|
|
181
|
+
}
|
|
165
182
|
});
|
|
166
183
|
},
|
|
184
|
+
newsletterFromUrl: async (url) => {
|
|
185
|
+
try {
|
|
186
|
+
let channelId;
|
|
187
|
+
if (url.includes('whatsapp.com/channel/')) {
|
|
188
|
+
channelId = url.split('whatsapp.com/channel/')[1].split('/')[0];
|
|
189
|
+
} else if (url.includes('wa.me/channel/')) {
|
|
190
|
+
channelId = url.split('wa.me/channel/')[1].split('/')[0];
|
|
191
|
+
} else {
|
|
192
|
+
channelId = url;
|
|
193
|
+
}
|
|
194
|
+
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
|
|
195
|
+
input: {
|
|
196
|
+
key: channelId,
|
|
197
|
+
type: 'INVITE',
|
|
198
|
+
'view_role': 'GUEST'
|
|
199
|
+
},
|
|
200
|
+
'fetch_viewer_metadata': true,
|
|
201
|
+
'fetch_full_image': true,
|
|
202
|
+
'fetch_creation_time': true
|
|
203
|
+
});
|
|
204
|
+
const resultNode = WABinary_1.getBinaryNodeChild(result, 'result');
|
|
205
|
+
if (!resultNode?.content) {
|
|
206
|
+
throw new Boom('No result content in response', {
|
|
207
|
+
statusCode: 400,
|
|
208
|
+
data: result
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
const resultString = resultNode.content.toString();
|
|
212
|
+
const parsedResult = JSON.parse(resultString);
|
|
213
|
+
|
|
214
|
+
if (!parsedResult?.data) {
|
|
215
|
+
throw new Boom('No data field in response', {
|
|
216
|
+
statusCode: 400,
|
|
217
|
+
data: parsedResult
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
const metadataPath = parsedResult.data[Types_1.XWAPaths.NEWSLETTER];
|
|
221
|
+
|
|
222
|
+
if (metadataPath === null || !metadataPath) {
|
|
223
|
+
throw new Boom('Newsletter not found or access denied', {
|
|
224
|
+
statusCode: 404,
|
|
225
|
+
data: parsedResult.data
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
const metadata = {
|
|
229
|
+
id: metadataPath?.id,
|
|
230
|
+
state: metadataPath?.state?.type,
|
|
231
|
+
creation_time: +metadataPath?.thread_metadata?.creation_time || 0,
|
|
232
|
+
name: metadataPath?.thread_metadata?.name?.text,
|
|
233
|
+
nameTime: +metadataPath?.thread_metadata?.name?.update_time || 0,
|
|
234
|
+
description: metadataPath?.thread_metadata?.description?.text,
|
|
235
|
+
descriptionTime: +metadataPath?.thread_metadata?.description?.update_time || 0,
|
|
236
|
+
invite: metadataPath?.thread_metadata?.invite,
|
|
237
|
+
picture: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.picture?.direct_path || ''),
|
|
238
|
+
preview: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.preview?.direct_path || ''),
|
|
239
|
+
reaction_codes: metadataPath?.thread_metadata?.settings?.reaction_codes?.value,
|
|
240
|
+
subscribers: +metadataPath?.thread_metadata?.subscribers_count || 0,
|
|
241
|
+
verification: metadataPath?.thread_metadata?.verification,
|
|
242
|
+
viewer_metadata: metadataPath?.viewer_metadata
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
return JSON.stringify({
|
|
246
|
+
name: metadata.name || metadataPath?.thread_metadata?.name?.text,
|
|
247
|
+
id: metadata.id,
|
|
248
|
+
state: metadata.state,
|
|
249
|
+
subscribers: metadata.subscribers,
|
|
250
|
+
verification: metadata.verification,
|
|
251
|
+
creation_time: metadata.creation_time,
|
|
252
|
+
description: metadata.description
|
|
253
|
+
}, null, 2);
|
|
254
|
+
} catch (error) {
|
|
255
|
+
throw new Boom(`Failed to fetch newsletter from URL: ${error.message}`, {
|
|
256
|
+
statusCode: error.statusCode || 400,
|
|
257
|
+
data: error.data || { url }
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
},
|
|
167
261
|
newsletterUpdateName: async (jid, name) => {
|
|
168
262
|
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
169
263
|
updates: { name, settings: null }
|
|
@@ -218,7 +312,15 @@ setTimeout(async () => {
|
|
|
218
312
|
]
|
|
219
313
|
});
|
|
220
314
|
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.CREATE, {
|
|
221
|
-
input: {
|
|
315
|
+
input: {
|
|
316
|
+
name,
|
|
317
|
+
description,
|
|
318
|
+
settings: {
|
|
319
|
+
'reaction_codes': {
|
|
320
|
+
value: reaction_codes.toUpperCase()
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
222
324
|
});
|
|
223
325
|
return (0, exports.extractNewsletterMetadata)(result, true);
|
|
224
326
|
},
|
|
@@ -260,7 +362,13 @@ setTimeout(async () => {
|
|
|
260
362
|
newsletterReactMessage: async (jid, serverId, code) => {
|
|
261
363
|
await query({
|
|
262
364
|
tag: 'message',
|
|
263
|
-
attrs: {
|
|
365
|
+
attrs: {
|
|
366
|
+
to: jid,
|
|
367
|
+
...(!code ? { edit: '7' } : {}),
|
|
368
|
+
type: 'reaction',
|
|
369
|
+
'server_id': serverId,
|
|
370
|
+
id: (0, Utils_1.generateMessageID)()
|
|
371
|
+
},
|
|
264
372
|
content: [{
|
|
265
373
|
tag: 'reaction',
|
|
266
374
|
attrs: code ? { code } : {}
|
|
@@ -271,7 +379,12 @@ setTimeout(async () => {
|
|
|
271
379
|
const result = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
|
|
272
380
|
{
|
|
273
381
|
tag: 'messages',
|
|
274
|
-
attrs: {
|
|
382
|
+
attrs: {
|
|
383
|
+
type,
|
|
384
|
+
...(type === 'invite' ? { key } : { jid: key }),
|
|
385
|
+
count: count.toString(),
|
|
386
|
+
after: (after === null || after === void 0 ? void 0 : after.toString()) || '100'
|
|
387
|
+
}
|
|
275
388
|
}
|
|
276
389
|
]);
|
|
277
390
|
return await parseFetchedUpdates(result, 'messages');
|
|
@@ -280,7 +393,11 @@ setTimeout(async () => {
|
|
|
280
393
|
const result = await newsletterQuery(jid, 'get', [
|
|
281
394
|
{
|
|
282
395
|
tag: 'message_updates',
|
|
283
|
-
attrs: {
|
|
396
|
+
attrs: {
|
|
397
|
+
count: count.toString(),
|
|
398
|
+
after: (after === null || after === void 0 ? void 0 : after.toString()) || '100',
|
|
399
|
+
since: (since === null || since === void 0 ? void 0 : since.toString()) || '0'
|
|
400
|
+
}
|
|
284
401
|
}
|
|
285
402
|
]);
|
|
286
403
|
return await parseFetchedUpdates(result, 'updates');
|
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/index.js
CHANGED