@fhynella/baileys 1.2.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 +21 -0
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +4775 -0
- package/WAProto/index.js +169661 -0
- package/WAProto/p.html +1 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/index.js +118 -0
- package/lib/Defaults/wileys-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 +174 -0
- package/lib/Socket/Client/index.js +18 -0
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/websocket.js +111 -0
- package/lib/Socket/business.js +260 -0
- package/lib/Socket/chats.js +915 -0
- package/lib/Socket/groups.js +332 -0
- package/lib/Socket/index.js +10 -0
- package/lib/Socket/messages-recv.js +1054 -0
- package/lib/Socket/messages-send.js +949 -0
- package/lib/Socket/newsletter.js +250 -0
- package/lib/Socket/socket.js +654 -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 +207 -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 +128 -0
- package/lib/Utils/messages-media.js +957 -0
- package/lib/Utils/messages.js +1049 -0
- package/lib/Utils/noise-handler.js +150 -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 +125 -0
- package/lib/Utils/validate-connection.js +229 -0
- package/lib/Utils/wileys-event-stream.js +63 -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 +49 -0
- package/package.json +115 -0
|
@@ -0,0 +1,250 @@
|
|
|
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
|
+
var QueryIds;
|
|
9
|
+
(function (QueryIds) {
|
|
10
|
+
QueryIds["JOB_MUTATION"] = "7150902998257522";
|
|
11
|
+
QueryIds["METADATA"] = "6620195908089573";
|
|
12
|
+
QueryIds["UNFOLLOW"] = "7238632346214362";
|
|
13
|
+
QueryIds["FOLLOW"] = "7871414976211147";
|
|
14
|
+
QueryIds["UNMUTE"] = "7337137176362961";
|
|
15
|
+
QueryIds["MUTE"] = "25151904754424642";
|
|
16
|
+
QueryIds["CREATE"] = "6996806640408138";
|
|
17
|
+
QueryIds["ADMIN_COUNT"] = "7130823597031706";
|
|
18
|
+
QueryIds["CHANGE_OWNER"] = "7341777602580933";
|
|
19
|
+
QueryIds["DELETE"] = "8316537688363079";
|
|
20
|
+
QueryIds["DEMOTE"] = "6551828931592903";
|
|
21
|
+
})(QueryIds || (QueryIds = {}));
|
|
22
|
+
const makeNewsletterSocket = (config) => {
|
|
23
|
+
const sock = (0, groups_1.makeGroupsSocket)(config);
|
|
24
|
+
const { authState, signalRepository, query, generateMessageTag } = sock;
|
|
25
|
+
const encoder = new TextEncoder();
|
|
26
|
+
const newsletterQuery = async (jid, type, content) => (query({
|
|
27
|
+
tag: 'iq',
|
|
28
|
+
attrs: {
|
|
29
|
+
id: generateMessageTag(),
|
|
30
|
+
type,
|
|
31
|
+
xmlns: 'newsletter',
|
|
32
|
+
to: jid,
|
|
33
|
+
},
|
|
34
|
+
content
|
|
35
|
+
}));
|
|
36
|
+
const newsletterWMexQuery = async (jid, query_id, content) => (query({
|
|
37
|
+
tag: 'iq',
|
|
38
|
+
attrs: {
|
|
39
|
+
id: generateMessageTag(),
|
|
40
|
+
type: 'get',
|
|
41
|
+
xmlns: 'w:mex',
|
|
42
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
43
|
+
},
|
|
44
|
+
content: [
|
|
45
|
+
{
|
|
46
|
+
tag: 'query',
|
|
47
|
+
attrs: { query_id },
|
|
48
|
+
content: encoder.encode(JSON.stringify({
|
|
49
|
+
variables: {
|
|
50
|
+
'newsletter_id': jid,
|
|
51
|
+
...content
|
|
52
|
+
}
|
|
53
|
+
}))
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
}));
|
|
57
|
+
const parseFetchedUpdates = async (node, type) => {
|
|
58
|
+
let child;
|
|
59
|
+
if (type === 'messages')
|
|
60
|
+
child = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
|
|
61
|
+
else {
|
|
62
|
+
const parent = (0, WABinary_1.getBinaryNodeChild)(node, 'message_updates');
|
|
63
|
+
child = (0, WABinary_1.getBinaryNodeChild)(parent, 'messages');
|
|
64
|
+
}
|
|
65
|
+
return await Promise.all((0, WABinary_1.getAllBinaryNodeChildren)(child).map(async (messageNode) => {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
messageNode.attrs.from = child === null || child === void 0 ? void 0 : child.attrs.jid;
|
|
68
|
+
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');
|
|
69
|
+
const reactionNode = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'reactions');
|
|
70
|
+
const reactions = (0, WABinary_1.getBinaryNodeChildren)(reactionNode, 'reaction')
|
|
71
|
+
.map(({ attrs }) => ({ count: +attrs.count, code: attrs.code }));
|
|
72
|
+
const data = {
|
|
73
|
+
'server_id': messageNode.attrs.server_id,
|
|
74
|
+
views,
|
|
75
|
+
reactions
|
|
76
|
+
};
|
|
77
|
+
if (type === 'messages') {
|
|
78
|
+
const { fullMessage: message, decrypt } = await (0, Utils_1.decryptMessageNode)(messageNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger);
|
|
79
|
+
await decrypt();
|
|
80
|
+
data.message = message;
|
|
81
|
+
}
|
|
82
|
+
return data;
|
|
83
|
+
}));
|
|
84
|
+
};
|
|
85
|
+
return {
|
|
86
|
+
...sock,
|
|
87
|
+
subscribeNewsletterUpdates: async (jid) => {
|
|
88
|
+
var _a;
|
|
89
|
+
const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
|
|
90
|
+
return (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'live_updates')) === null || _a === void 0 ? void 0 : _a.attrs;
|
|
91
|
+
},
|
|
92
|
+
newsletterReactionMode: async (jid, mode) => {
|
|
93
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
94
|
+
updates: { settings: { reaction_codes: { value: mode } } }
|
|
95
|
+
});
|
|
96
|
+
},
|
|
97
|
+
newsletterUpdateDescription: async (jid, description) => {
|
|
98
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
99
|
+
updates: { description: description || '', settings: null }
|
|
100
|
+
});
|
|
101
|
+
},
|
|
102
|
+
newsletterUpdateName: async (jid, name) => {
|
|
103
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
104
|
+
updates: { name, settings: null }
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
newsletterUpdatePicture: async (jid, content) => {
|
|
108
|
+
const { img } = await (0, Utils_1.generateProfilePicture)(content);
|
|
109
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
110
|
+
updates: { picture: img.toString('base64'), settings: null }
|
|
111
|
+
});
|
|
112
|
+
},
|
|
113
|
+
newsletterRemovePicture: async (jid) => {
|
|
114
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
115
|
+
updates: { picture: '', settings: null }
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
newsletterUnfollow: async (jid) => {
|
|
119
|
+
await newsletterWMexQuery(jid, QueryIds.UNFOLLOW);
|
|
120
|
+
},
|
|
121
|
+
newsletterFollow: async (jid) => {
|
|
122
|
+
await newsletterWMexQuery(jid, QueryIds.FOLLOW);
|
|
123
|
+
},
|
|
124
|
+
newsletterUnmute: async (jid) => {
|
|
125
|
+
await newsletterWMexQuery(jid, QueryIds.UNMUTE);
|
|
126
|
+
},
|
|
127
|
+
newsletterMute: async (jid) => {
|
|
128
|
+
await newsletterWMexQuery(jid, QueryIds.MUTE);
|
|
129
|
+
},
|
|
130
|
+
newsletterCreate: async (name, description, picture) => {
|
|
131
|
+
await query({
|
|
132
|
+
tag: 'iq',
|
|
133
|
+
attrs: {
|
|
134
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
135
|
+
xmlns: 'tos',
|
|
136
|
+
id: generateMessageTag(),
|
|
137
|
+
type: 'set'
|
|
138
|
+
},
|
|
139
|
+
content: [
|
|
140
|
+
{
|
|
141
|
+
tag: 'notice',
|
|
142
|
+
attrs: {
|
|
143
|
+
id: '20601218',
|
|
144
|
+
stage: '5'
|
|
145
|
+
},
|
|
146
|
+
content: []
|
|
147
|
+
}
|
|
148
|
+
]
|
|
149
|
+
});
|
|
150
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.CREATE, {
|
|
151
|
+
input: {
|
|
152
|
+
name,
|
|
153
|
+
description: description !== null && description !== void 0 ? description : null,
|
|
154
|
+
picture: picture ? (await (0, Utils_1.generateProfilePicture)(picture)).img.toString('base64') : null,
|
|
155
|
+
settings: null
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
return (0, exports.extractNewsletterMetadata)(result, true);
|
|
159
|
+
},
|
|
160
|
+
newsletterMetadata: async (type, key, role) => {
|
|
161
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
|
|
162
|
+
input: {
|
|
163
|
+
key,
|
|
164
|
+
type: type.toUpperCase(),
|
|
165
|
+
view_role: role || 'GUEST'
|
|
166
|
+
},
|
|
167
|
+
fetch_viewer_metadata: true,
|
|
168
|
+
fetch_full_image: true,
|
|
169
|
+
fetch_creation_time: true
|
|
170
|
+
});
|
|
171
|
+
return (0, exports.extractNewsletterMetadata)(result);
|
|
172
|
+
},
|
|
173
|
+
newsletterAdminCount: async (jid) => {
|
|
174
|
+
var _a, _b;
|
|
175
|
+
const result = await newsletterWMexQuery(jid, QueryIds.ADMIN_COUNT);
|
|
176
|
+
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();
|
|
177
|
+
return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
|
|
178
|
+
},
|
|
179
|
+
/**user is Lid, not Jid */
|
|
180
|
+
newsletterChangeOwner: async (jid, user) => {
|
|
181
|
+
await newsletterWMexQuery(jid, QueryIds.CHANGE_OWNER, {
|
|
182
|
+
user_id: user
|
|
183
|
+
});
|
|
184
|
+
},
|
|
185
|
+
/**user is Lid, not Jid */
|
|
186
|
+
newsletterDemote: async (jid, user) => {
|
|
187
|
+
await newsletterWMexQuery(jid, QueryIds.DEMOTE, {
|
|
188
|
+
user_id: user
|
|
189
|
+
});
|
|
190
|
+
},
|
|
191
|
+
newsletterDelete: async (jid) => {
|
|
192
|
+
await newsletterWMexQuery(jid, QueryIds.DELETE);
|
|
193
|
+
},
|
|
194
|
+
/**if code wasn't passed, the reaction will be removed (if is reacted) */
|
|
195
|
+
newsletterReactMessage: async (jid, server_id, code) => {
|
|
196
|
+
await query({
|
|
197
|
+
tag: 'message',
|
|
198
|
+
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', server_id, id: (0, Utils_1.generateMessageID)() },
|
|
199
|
+
content: [{
|
|
200
|
+
tag: 'reaction',
|
|
201
|
+
attrs: code ? { code } : {}
|
|
202
|
+
}]
|
|
203
|
+
});
|
|
204
|
+
},
|
|
205
|
+
newsletterFetchMessages: async (type, key, count, after) => {
|
|
206
|
+
const afterStr = after === null || after === void 0 ? void 0 : after.toString();
|
|
207
|
+
const result = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
|
|
208
|
+
{
|
|
209
|
+
tag: 'messages',
|
|
210
|
+
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: afterStr || '100' }
|
|
211
|
+
}
|
|
212
|
+
]);
|
|
213
|
+
return await parseFetchedUpdates(result, 'messages');
|
|
214
|
+
},
|
|
215
|
+
newsletterFetchUpdates: async (jid, count, after, since) => {
|
|
216
|
+
const result = await newsletterQuery(jid, 'get', [
|
|
217
|
+
{
|
|
218
|
+
tag: 'message_updates',
|
|
219
|
+
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' }
|
|
220
|
+
}
|
|
221
|
+
]);
|
|
222
|
+
return await parseFetchedUpdates(result, 'updates');
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
exports.makeNewsletterSocket = makeNewsletterSocket;
|
|
227
|
+
const extractNewsletterMetadata = (node, isCreate) => {
|
|
228
|
+
var _a, _b, _c, _d;
|
|
229
|
+
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();
|
|
230
|
+
const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER];
|
|
231
|
+
const metadata = {
|
|
232
|
+
id: metadataPath.id,
|
|
233
|
+
state: metadataPath.state.type,
|
|
234
|
+
creation_time: +metadataPath.thread_metadata.creation_time,
|
|
235
|
+
name: metadataPath.thread_metadata.name.text,
|
|
236
|
+
nameTime: +metadataPath.thread_metadata.name.update_time,
|
|
237
|
+
description: metadataPath.thread_metadata.description.text,
|
|
238
|
+
descriptionTime: +metadataPath.thread_metadata.description.update_time,
|
|
239
|
+
invite: metadataPath.thread_metadata.invite,
|
|
240
|
+
handle: metadataPath.thread_metadata.handle,
|
|
241
|
+
picture: ((_c = metadataPath.thread_metadata.picture) === null || _c === void 0 ? void 0 : _c.direct_path) || null,
|
|
242
|
+
preview: ((_d = metadataPath.thread_metadata.preview) === null || _d === void 0 ? void 0 : _d.direct_path) || null,
|
|
243
|
+
reaction_codes: metadataPath.thread_metadata.settings.reaction_codes.value,
|
|
244
|
+
subscribers: +metadataPath.thread_metadata.subscribers_count,
|
|
245
|
+
verification: metadataPath.thread_metadata.verification,
|
|
246
|
+
viewer_metadata: metadataPath.viewer_metadata
|
|
247
|
+
};
|
|
248
|
+
return metadata;
|
|
249
|
+
};
|
|
250
|
+
exports.extractNewsletterMetadata = extractNewsletterMetadata;
|