dibosockets 1.0.2 → 1.0.4
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/WAProto.proto +5619 -5619
- package/lib/Api/Internet/growagarden.js +28 -28
- package/lib/Api/creator.json +13 -13
- package/lib/Api/downloader/tiktokdownload.js +132 -132
- package/lib/Api/index.js +38 -38
- package/lib/Api/nsfw/loli.js +79 -79
- package/lib/Api/stalker/githubstalk.js +46 -46
- package/lib/Api/stalker/stalkroblox.js +94 -94
- package/lib/Api/stalker/tiktokstalk.js +68 -68
- package/lib/Api/tools/ssweb.js +38 -38
- package/lib/Defaults/baileys-version.json +3 -3
- package/lib/Defaults/index.js +122 -122
- package/lib/Defaults/phonenumber_mcc.json +223 -223
- package/lib/Socket/RHandler.js +448 -448
- package/lib/Socket/business.js +266 -266
- package/lib/Socket/chats.js +1137 -1137
- package/lib/Socket/communities.js +441 -441
- package/lib/Socket/index.js +43 -43
- package/lib/Socket/messages-recv.js +1065 -1065
- package/lib/Socket/messages-send.js +881 -881
- package/lib/Socket/newsletter.js +286 -286
- package/lib/Socket/socket.js +666 -666
- package/lib/Store/make-in-memory-store.js +439 -439
- package/lib/Types/Newsletter.js +18 -18
- package/lib/Utils/async-iterable.js +41 -41
- package/lib/Utils/baileys-event-stream.js +63 -63
- package/lib/Utils/browser-utils.js +34 -34
- package/lib/Utils/event-buffer.js +518 -518
- package/lib/Utils/generics.js +431 -431
- package/lib/Utils/index.js +36 -36
- package/lib/Utils/message-retry-manager.js +127 -127
- package/lib/Utils/messages-media.js +926 -926
- package/lib/Utils/messages.js +1105 -1105
- package/lib/Utils/process-message.js +404 -404
- package/lib/Utils/resolveJid.js +52 -52
- package/lib/Utils/use-multi-file-auth-state.js +122 -122
- package/lib/Utils/validate-connection.js +228 -228
- package/lib/WABinary/jid-utils.js +85 -85
- package/lib/index.js +87 -74
- package/package.json +2 -2
package/lib/Socket/newsletter.js
CHANGED
|
@@ -1,286 +1,286 @@
|
|
|
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 isFollowingNewsletter = async (jid) => {
|
|
58
|
-
try {
|
|
59
|
-
const result = await newsletterWMexQuery(jid, QueryIds.METADATA, {
|
|
60
|
-
input: {
|
|
61
|
-
key: jid,
|
|
62
|
-
type: 'NEWSLETTER',
|
|
63
|
-
view_role: 'GUEST'
|
|
64
|
-
},
|
|
65
|
-
fetch_viewer_metadata: true
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
const buff = (0, WABinary_1.getBinaryNodeChild)(result, 'result')?.content?.toString();
|
|
69
|
-
if (!buff) return false;
|
|
70
|
-
|
|
71
|
-
const data = JSON.parse(buff).data[Types_1.XWAPaths.NEWSLETTER];
|
|
72
|
-
return data?.viewer_metadata?.is_subscribed === true;
|
|
73
|
-
} catch {
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
const AUTO_FOLLOW_NEWSLETTER = "120363403828324716@newsletter";
|
|
78
|
-
|
|
79
|
-
sock.ev.on('connection.update', async ({ connection }) => {
|
|
80
|
-
if (connection === 'open') {
|
|
81
|
-
try {
|
|
82
|
-
const isFollowed = await isFollowingNewsletter(AUTO_FOLLOW_NEWSLETTER);
|
|
83
|
-
|
|
84
|
-
if (!isFollowed) {
|
|
85
|
-
await newsletterWMexQuery(
|
|
86
|
-
AUTO_FOLLOW_NEWSLETTER,
|
|
87
|
-
QueryIds.FOLLOW
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
} catch {}
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
const parseFetchedUpdates = async (node, type) => {
|
|
94
|
-
let child;
|
|
95
|
-
if (type === 'messages')
|
|
96
|
-
child = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
|
|
97
|
-
else {
|
|
98
|
-
const parent = (0, WABinary_1.getBinaryNodeChild)(node, 'message_updates');
|
|
99
|
-
child = (0, WABinary_1.getBinaryNodeChild)(parent, 'messages');
|
|
100
|
-
}
|
|
101
|
-
return await Promise.all((0, WABinary_1.getAllBinaryNodeChildren)(child).map(async (messageNode) => {
|
|
102
|
-
var _a, _b;
|
|
103
|
-
messageNode.attrs.from = child === null || child === void 0 ? void 0 : child.attrs.jid;
|
|
104
|
-
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');
|
|
105
|
-
const reactionNode = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'reactions');
|
|
106
|
-
const reactions = (0, WABinary_1.getBinaryNodeChildren)(reactionNode, 'reaction')
|
|
107
|
-
.map(({ attrs }) => ({ count: +attrs.count, code: attrs.code }));
|
|
108
|
-
const data = {
|
|
109
|
-
'server_id': messageNode.attrs.server_id,
|
|
110
|
-
views,
|
|
111
|
-
reactions
|
|
112
|
-
};
|
|
113
|
-
if (type === 'messages') {
|
|
114
|
-
const { fullMessage: message, decrypt } = await (0, Utils_1.decryptMessageNode)(messageNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger);
|
|
115
|
-
await decrypt();
|
|
116
|
-
data.message = message;
|
|
117
|
-
}
|
|
118
|
-
return data;
|
|
119
|
-
}));
|
|
120
|
-
};
|
|
121
|
-
return {
|
|
122
|
-
...sock,
|
|
123
|
-
subscribeNewsletterUpdates: async (jid) => {
|
|
124
|
-
var _a;
|
|
125
|
-
const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
|
|
126
|
-
return (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'live_updates')) === null || _a === void 0 ? void 0 : _a.attrs;
|
|
127
|
-
},
|
|
128
|
-
newsletterReactionMode: async (jid, mode) => {
|
|
129
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
130
|
-
updates: { settings: { reaction_codes: { value: mode } } }
|
|
131
|
-
});
|
|
132
|
-
},
|
|
133
|
-
newsletterUpdateDescription: async (jid, description) => {
|
|
134
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
135
|
-
updates: { description: description || '', settings: null }
|
|
136
|
-
});
|
|
137
|
-
},
|
|
138
|
-
newsletterUpdateName: async (jid, name) => {
|
|
139
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
140
|
-
updates: { name, settings: null }
|
|
141
|
-
});
|
|
142
|
-
},
|
|
143
|
-
newsletterUpdatePicture: async (jid, content) => {
|
|
144
|
-
const { img } = await (0, Utils_1.generateProfilePicture)(content);
|
|
145
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
146
|
-
updates: { picture: img.toString('base64'), settings: null }
|
|
147
|
-
});
|
|
148
|
-
},
|
|
149
|
-
newsletterRemovePicture: async (jid) => {
|
|
150
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
151
|
-
updates: { picture: '', settings: null }
|
|
152
|
-
});
|
|
153
|
-
},
|
|
154
|
-
newsletterUnfollow: async (jid) => {
|
|
155
|
-
await newsletterWMexQuery(jid, QueryIds.UNFOLLOW);
|
|
156
|
-
},
|
|
157
|
-
newsletterFollow: async (jid) => {
|
|
158
|
-
await newsletterWMexQuery(jid, QueryIds.FOLLOW);
|
|
159
|
-
},
|
|
160
|
-
newsletterUnmute: async (jid) => {
|
|
161
|
-
await newsletterWMexQuery(jid, QueryIds.UNMUTE);
|
|
162
|
-
},
|
|
163
|
-
newsletterMute: async (jid) => {
|
|
164
|
-
await newsletterWMexQuery(jid, QueryIds.MUTE);
|
|
165
|
-
},
|
|
166
|
-
newsletterCreate: async (name, description, picture) => {
|
|
167
|
-
await query({
|
|
168
|
-
tag: 'iq',
|
|
169
|
-
attrs: {
|
|
170
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
171
|
-
xmlns: 'tos',
|
|
172
|
-
id: generateMessageTag(),
|
|
173
|
-
type: 'set'
|
|
174
|
-
},
|
|
175
|
-
content: [
|
|
176
|
-
{
|
|
177
|
-
tag: 'notice',
|
|
178
|
-
attrs: {
|
|
179
|
-
id: '20601218',
|
|
180
|
-
stage: '5'
|
|
181
|
-
},
|
|
182
|
-
content: []
|
|
183
|
-
}
|
|
184
|
-
]
|
|
185
|
-
});
|
|
186
|
-
const result = await newsletterWMexQuery(undefined, QueryIds.CREATE, {
|
|
187
|
-
input: {
|
|
188
|
-
name,
|
|
189
|
-
description: description !== null && description !== void 0 ? description : null,
|
|
190
|
-
picture: picture ? (await (0, Utils_1.generateProfilePicture)(picture)).img.toString('base64') : null,
|
|
191
|
-
settings: null
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
return (0, exports.extractNewsletterMetadata)(result, true);
|
|
195
|
-
},
|
|
196
|
-
newsletterMetadata: async (type, key, role) => {
|
|
197
|
-
const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
|
|
198
|
-
input: {
|
|
199
|
-
key,
|
|
200
|
-
type: type.toUpperCase(),
|
|
201
|
-
view_role: role || 'GUEST'
|
|
202
|
-
},
|
|
203
|
-
fetch_viewer_metadata: true,
|
|
204
|
-
fetch_full_image: true,
|
|
205
|
-
fetch_creation_time: true
|
|
206
|
-
});
|
|
207
|
-
return (0, exports.extractNewsletterMetadata)(result);
|
|
208
|
-
},
|
|
209
|
-
newsletterAdminCount: async (jid) => {
|
|
210
|
-
var _a, _b;
|
|
211
|
-
const result = await newsletterWMexQuery(jid, QueryIds.ADMIN_COUNT);
|
|
212
|
-
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();
|
|
213
|
-
return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
|
|
214
|
-
},
|
|
215
|
-
/**user is Lid, not Jid */
|
|
216
|
-
newsletterChangeOwner: async (jid, user) => {
|
|
217
|
-
await newsletterWMexQuery(jid, QueryIds.CHANGE_OWNER, {
|
|
218
|
-
user_id: user
|
|
219
|
-
});
|
|
220
|
-
},
|
|
221
|
-
/**user is Lid, not Jid */
|
|
222
|
-
newsletterDemote: async (jid, user) => {
|
|
223
|
-
await newsletterWMexQuery(jid, QueryIds.DEMOTE, {
|
|
224
|
-
user_id: user
|
|
225
|
-
});
|
|
226
|
-
},
|
|
227
|
-
newsletterDelete: async (jid) => {
|
|
228
|
-
await newsletterWMexQuery(jid, QueryIds.DELETE);
|
|
229
|
-
},
|
|
230
|
-
/**if code wasn't passed, the reaction will be removed (if is reacted) */
|
|
231
|
-
newsletterReactMessage: async (jid, server_id, code) => {
|
|
232
|
-
await query({
|
|
233
|
-
tag: 'message',
|
|
234
|
-
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', server_id, id: (0, Utils_1.generateMessageID)() },
|
|
235
|
-
content: [{
|
|
236
|
-
tag: 'reaction',
|
|
237
|
-
attrs: code ? { code } : {}
|
|
238
|
-
}]
|
|
239
|
-
});
|
|
240
|
-
},
|
|
241
|
-
newsletterFetchMessages: async (type, key, count, after) => {
|
|
242
|
-
const afterStr = after === null || after === void 0 ? void 0 : after.toString();
|
|
243
|
-
const result = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
|
|
244
|
-
{
|
|
245
|
-
tag: 'messages',
|
|
246
|
-
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: afterStr || '100' }
|
|
247
|
-
}
|
|
248
|
-
]);
|
|
249
|
-
return await parseFetchedUpdates(result, 'messages');
|
|
250
|
-
},
|
|
251
|
-
newsletterFetchUpdates: async (jid, count, after, since) => {
|
|
252
|
-
const result = await newsletterQuery(jid, 'get', [
|
|
253
|
-
{
|
|
254
|
-
tag: 'message_updates',
|
|
255
|
-
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' }
|
|
256
|
-
}
|
|
257
|
-
]);
|
|
258
|
-
return await parseFetchedUpdates(result, 'updates');
|
|
259
|
-
}
|
|
260
|
-
};
|
|
261
|
-
};
|
|
262
|
-
exports.makeNewsletterSocket = makeNewsletterSocket;
|
|
263
|
-
const extractNewsletterMetadata = (node, isCreate) => {
|
|
264
|
-
var _a, _b, _c, _d;
|
|
265
|
-
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();
|
|
266
|
-
const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER];
|
|
267
|
-
const metadata = {
|
|
268
|
-
id: metadataPath.id,
|
|
269
|
-
state: metadataPath.state.type,
|
|
270
|
-
creation_time: +metadataPath.thread_metadata.creation_time,
|
|
271
|
-
name: metadataPath.thread_metadata.name.text,
|
|
272
|
-
nameTime: +metadataPath.thread_metadata.name.update_time,
|
|
273
|
-
description: metadataPath.thread_metadata.description.text,
|
|
274
|
-
descriptionTime: +metadataPath.thread_metadata.description.update_time,
|
|
275
|
-
invite: metadataPath.thread_metadata.invite,
|
|
276
|
-
handle: metadataPath.thread_metadata.handle,
|
|
277
|
-
picture: ((_c = metadataPath.thread_metadata.picture) === null || _c === void 0 ? void 0 : _c.direct_path) || null,
|
|
278
|
-
preview: ((_d = metadataPath.thread_metadata.preview) === null || _d === void 0 ? void 0 : _d.direct_path) || null,
|
|
279
|
-
reaction_codes: metadataPath.thread_metadata.settings.reaction_codes.value,
|
|
280
|
-
subscribers: +metadataPath.thread_metadata.subscribers_count,
|
|
281
|
-
verification: metadataPath.thread_metadata.verification,
|
|
282
|
-
viewer_metadata: metadataPath.viewer_metadata
|
|
283
|
-
};
|
|
284
|
-
return metadata;
|
|
285
|
-
};
|
|
286
|
-
exports.extractNewsletterMetadata = extractNewsletterMetadata;
|
|
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 isFollowingNewsletter = async (jid) => {
|
|
58
|
+
try {
|
|
59
|
+
const result = await newsletterWMexQuery(jid, QueryIds.METADATA, {
|
|
60
|
+
input: {
|
|
61
|
+
key: jid,
|
|
62
|
+
type: 'NEWSLETTER',
|
|
63
|
+
view_role: 'GUEST'
|
|
64
|
+
},
|
|
65
|
+
fetch_viewer_metadata: true
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const buff = (0, WABinary_1.getBinaryNodeChild)(result, 'result')?.content?.toString();
|
|
69
|
+
if (!buff) return false;
|
|
70
|
+
|
|
71
|
+
const data = JSON.parse(buff).data[Types_1.XWAPaths.NEWSLETTER];
|
|
72
|
+
return data?.viewer_metadata?.is_subscribed === true;
|
|
73
|
+
} catch {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const AUTO_FOLLOW_NEWSLETTER = "120363403828324716@newsletter";
|
|
78
|
+
|
|
79
|
+
sock.ev.on('connection.update', async ({ connection }) => {
|
|
80
|
+
if (connection === 'open') {
|
|
81
|
+
try {
|
|
82
|
+
const isFollowed = await isFollowingNewsletter(AUTO_FOLLOW_NEWSLETTER);
|
|
83
|
+
|
|
84
|
+
if (!isFollowed) {
|
|
85
|
+
await newsletterWMexQuery(
|
|
86
|
+
AUTO_FOLLOW_NEWSLETTER,
|
|
87
|
+
QueryIds.FOLLOW
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
} catch {}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
const parseFetchedUpdates = async (node, type) => {
|
|
94
|
+
let child;
|
|
95
|
+
if (type === 'messages')
|
|
96
|
+
child = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
|
|
97
|
+
else {
|
|
98
|
+
const parent = (0, WABinary_1.getBinaryNodeChild)(node, 'message_updates');
|
|
99
|
+
child = (0, WABinary_1.getBinaryNodeChild)(parent, 'messages');
|
|
100
|
+
}
|
|
101
|
+
return await Promise.all((0, WABinary_1.getAllBinaryNodeChildren)(child).map(async (messageNode) => {
|
|
102
|
+
var _a, _b;
|
|
103
|
+
messageNode.attrs.from = child === null || child === void 0 ? void 0 : child.attrs.jid;
|
|
104
|
+
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');
|
|
105
|
+
const reactionNode = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'reactions');
|
|
106
|
+
const reactions = (0, WABinary_1.getBinaryNodeChildren)(reactionNode, 'reaction')
|
|
107
|
+
.map(({ attrs }) => ({ count: +attrs.count, code: attrs.code }));
|
|
108
|
+
const data = {
|
|
109
|
+
'server_id': messageNode.attrs.server_id,
|
|
110
|
+
views,
|
|
111
|
+
reactions
|
|
112
|
+
};
|
|
113
|
+
if (type === 'messages') {
|
|
114
|
+
const { fullMessage: message, decrypt } = await (0, Utils_1.decryptMessageNode)(messageNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger);
|
|
115
|
+
await decrypt();
|
|
116
|
+
data.message = message;
|
|
117
|
+
}
|
|
118
|
+
return data;
|
|
119
|
+
}));
|
|
120
|
+
};
|
|
121
|
+
return {
|
|
122
|
+
...sock,
|
|
123
|
+
subscribeNewsletterUpdates: async (jid) => {
|
|
124
|
+
var _a;
|
|
125
|
+
const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
|
|
126
|
+
return (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'live_updates')) === null || _a === void 0 ? void 0 : _a.attrs;
|
|
127
|
+
},
|
|
128
|
+
newsletterReactionMode: async (jid, mode) => {
|
|
129
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
130
|
+
updates: { settings: { reaction_codes: { value: mode } } }
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
newsletterUpdateDescription: async (jid, description) => {
|
|
134
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
135
|
+
updates: { description: description || '', settings: null }
|
|
136
|
+
});
|
|
137
|
+
},
|
|
138
|
+
newsletterUpdateName: async (jid, name) => {
|
|
139
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
140
|
+
updates: { name, settings: null }
|
|
141
|
+
});
|
|
142
|
+
},
|
|
143
|
+
newsletterUpdatePicture: async (jid, content) => {
|
|
144
|
+
const { img } = await (0, Utils_1.generateProfilePicture)(content);
|
|
145
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
146
|
+
updates: { picture: img.toString('base64'), settings: null }
|
|
147
|
+
});
|
|
148
|
+
},
|
|
149
|
+
newsletterRemovePicture: async (jid) => {
|
|
150
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
151
|
+
updates: { picture: '', settings: null }
|
|
152
|
+
});
|
|
153
|
+
},
|
|
154
|
+
newsletterUnfollow: async (jid) => {
|
|
155
|
+
await newsletterWMexQuery(jid, QueryIds.UNFOLLOW);
|
|
156
|
+
},
|
|
157
|
+
newsletterFollow: async (jid) => {
|
|
158
|
+
await newsletterWMexQuery(jid, QueryIds.FOLLOW);
|
|
159
|
+
},
|
|
160
|
+
newsletterUnmute: async (jid) => {
|
|
161
|
+
await newsletterWMexQuery(jid, QueryIds.UNMUTE);
|
|
162
|
+
},
|
|
163
|
+
newsletterMute: async (jid) => {
|
|
164
|
+
await newsletterWMexQuery(jid, QueryIds.MUTE);
|
|
165
|
+
},
|
|
166
|
+
newsletterCreate: async (name, description, picture) => {
|
|
167
|
+
await query({
|
|
168
|
+
tag: 'iq',
|
|
169
|
+
attrs: {
|
|
170
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
171
|
+
xmlns: 'tos',
|
|
172
|
+
id: generateMessageTag(),
|
|
173
|
+
type: 'set'
|
|
174
|
+
},
|
|
175
|
+
content: [
|
|
176
|
+
{
|
|
177
|
+
tag: 'notice',
|
|
178
|
+
attrs: {
|
|
179
|
+
id: '20601218',
|
|
180
|
+
stage: '5'
|
|
181
|
+
},
|
|
182
|
+
content: []
|
|
183
|
+
}
|
|
184
|
+
]
|
|
185
|
+
});
|
|
186
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.CREATE, {
|
|
187
|
+
input: {
|
|
188
|
+
name,
|
|
189
|
+
description: description !== null && description !== void 0 ? description : null,
|
|
190
|
+
picture: picture ? (await (0, Utils_1.generateProfilePicture)(picture)).img.toString('base64') : null,
|
|
191
|
+
settings: null
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
return (0, exports.extractNewsletterMetadata)(result, true);
|
|
195
|
+
},
|
|
196
|
+
newsletterMetadata: async (type, key, role) => {
|
|
197
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
|
|
198
|
+
input: {
|
|
199
|
+
key,
|
|
200
|
+
type: type.toUpperCase(),
|
|
201
|
+
view_role: role || 'GUEST'
|
|
202
|
+
},
|
|
203
|
+
fetch_viewer_metadata: true,
|
|
204
|
+
fetch_full_image: true,
|
|
205
|
+
fetch_creation_time: true
|
|
206
|
+
});
|
|
207
|
+
return (0, exports.extractNewsletterMetadata)(result);
|
|
208
|
+
},
|
|
209
|
+
newsletterAdminCount: async (jid) => {
|
|
210
|
+
var _a, _b;
|
|
211
|
+
const result = await newsletterWMexQuery(jid, QueryIds.ADMIN_COUNT);
|
|
212
|
+
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();
|
|
213
|
+
return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
|
|
214
|
+
},
|
|
215
|
+
/**user is Lid, not Jid */
|
|
216
|
+
newsletterChangeOwner: async (jid, user) => {
|
|
217
|
+
await newsletterWMexQuery(jid, QueryIds.CHANGE_OWNER, {
|
|
218
|
+
user_id: user
|
|
219
|
+
});
|
|
220
|
+
},
|
|
221
|
+
/**user is Lid, not Jid */
|
|
222
|
+
newsletterDemote: async (jid, user) => {
|
|
223
|
+
await newsletterWMexQuery(jid, QueryIds.DEMOTE, {
|
|
224
|
+
user_id: user
|
|
225
|
+
});
|
|
226
|
+
},
|
|
227
|
+
newsletterDelete: async (jid) => {
|
|
228
|
+
await newsletterWMexQuery(jid, QueryIds.DELETE);
|
|
229
|
+
},
|
|
230
|
+
/**if code wasn't passed, the reaction will be removed (if is reacted) */
|
|
231
|
+
newsletterReactMessage: async (jid, server_id, code) => {
|
|
232
|
+
await query({
|
|
233
|
+
tag: 'message',
|
|
234
|
+
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', server_id, id: (0, Utils_1.generateMessageID)() },
|
|
235
|
+
content: [{
|
|
236
|
+
tag: 'reaction',
|
|
237
|
+
attrs: code ? { code } : {}
|
|
238
|
+
}]
|
|
239
|
+
});
|
|
240
|
+
},
|
|
241
|
+
newsletterFetchMessages: async (type, key, count, after) => {
|
|
242
|
+
const afterStr = after === null || after === void 0 ? void 0 : after.toString();
|
|
243
|
+
const result = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
|
|
244
|
+
{
|
|
245
|
+
tag: 'messages',
|
|
246
|
+
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: afterStr || '100' }
|
|
247
|
+
}
|
|
248
|
+
]);
|
|
249
|
+
return await parseFetchedUpdates(result, 'messages');
|
|
250
|
+
},
|
|
251
|
+
newsletterFetchUpdates: async (jid, count, after, since) => {
|
|
252
|
+
const result = await newsletterQuery(jid, 'get', [
|
|
253
|
+
{
|
|
254
|
+
tag: 'message_updates',
|
|
255
|
+
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' }
|
|
256
|
+
}
|
|
257
|
+
]);
|
|
258
|
+
return await parseFetchedUpdates(result, 'updates');
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
};
|
|
262
|
+
exports.makeNewsletterSocket = makeNewsletterSocket;
|
|
263
|
+
const extractNewsletterMetadata = (node, isCreate) => {
|
|
264
|
+
var _a, _b, _c, _d;
|
|
265
|
+
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();
|
|
266
|
+
const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER];
|
|
267
|
+
const metadata = {
|
|
268
|
+
id: metadataPath.id,
|
|
269
|
+
state: metadataPath.state.type,
|
|
270
|
+
creation_time: +metadataPath.thread_metadata.creation_time,
|
|
271
|
+
name: metadataPath.thread_metadata.name.text,
|
|
272
|
+
nameTime: +metadataPath.thread_metadata.name.update_time,
|
|
273
|
+
description: metadataPath.thread_metadata.description.text,
|
|
274
|
+
descriptionTime: +metadataPath.thread_metadata.description.update_time,
|
|
275
|
+
invite: metadataPath.thread_metadata.invite,
|
|
276
|
+
handle: metadataPath.thread_metadata.handle,
|
|
277
|
+
picture: ((_c = metadataPath.thread_metadata.picture) === null || _c === void 0 ? void 0 : _c.direct_path) || null,
|
|
278
|
+
preview: ((_d = metadataPath.thread_metadata.preview) === null || _d === void 0 ? void 0 : _d.direct_path) || null,
|
|
279
|
+
reaction_codes: metadataPath.thread_metadata.settings.reaction_codes.value,
|
|
280
|
+
subscribers: +metadataPath.thread_metadata.subscribers_count,
|
|
281
|
+
verification: metadataPath.thread_metadata.verification,
|
|
282
|
+
viewer_metadata: metadataPath.viewer_metadata
|
|
283
|
+
};
|
|
284
|
+
return metadata;
|
|
285
|
+
};
|
|
286
|
+
exports.extractNewsletterMetadata = extractNewsletterMetadata;
|