dibosockets 1.0.3 → 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 +1013 -169
- package/lib/Api/Internet/growagarden.js +28 -0
- package/lib/Api/creator.json +13 -0
- package/lib/Api/downloader/tiktokdownload.js +132 -0
- package/lib/Api/index.js +38 -0
- package/lib/Api/nsfw/loli.js +79 -0
- package/lib/Api/stalker/githubstalk.js +46 -0
- package/lib/Api/stalker/stalkroblox.js +94 -0
- package/lib/Api/stalker/tiktokstalk.js +68 -0
- package/lib/Api/tools/ssweb.js +38 -0
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +50 -34
- package/lib/Defaults/phonenumber_mcc.json +223 -0
- package/lib/Socket/RHandler.js +158 -240
- package/lib/Socket/business.js +8 -2
- package/lib/Socket/chats.js +371 -142
- package/lib/Socket/communities.js +441 -0
- package/lib/Socket/index.js +43 -10
- package/lib/Socket/messages-recv.js +15 -4
- package/lib/Socket/messages-send.js +13 -35
- package/lib/Socket/newsletter.js +107 -124
- package/lib/Socket/socket.js +35 -23
- package/lib/Store/make-in-memory-store.js +2 -2
- package/lib/Types/Newsletter.js +18 -38
- package/lib/Utils/async-iterable.js +41 -0
- package/lib/Utils/baileys-event-stream.js +1 -1
- package/lib/Utils/browser-utils.js +35 -0
- package/lib/Utils/event-buffer.js +2 -2
- package/lib/Utils/generics.js +4 -0
- package/lib/Utils/index.js +3 -3
- package/lib/Utils/message-retry-manager.js +128 -0
- package/lib/Utils/messages-media.js +88 -49
- package/lib/Utils/messages.js +91 -16
- package/lib/Utils/process-message.js +19 -0
- package/lib/Utils/resolveJid.js +52 -0
- package/lib/Utils/use-multi-file-auth-state.js +0 -3
- package/lib/Utils/validate-connection.js +77 -21
- package/lib/WABinary/jid-utils.js +3 -1
- package/lib/index.js +2 -1
- package/package.json +2 -2
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.extractCommunityMetadata = exports.makeCommunitiesSocket = void 0;
|
|
7
|
+
const WAProto_1 = require("../../WAProto/index.js");
|
|
8
|
+
const Types_1 = require("../Types");
|
|
9
|
+
const Utils_1 = require("../Utils");
|
|
10
|
+
const logger_1 = __importDefault(require("../Utils/logger"));
|
|
11
|
+
const WABinary_1 = require("../WABinary");
|
|
12
|
+
const business_1 = require("./business");
|
|
13
|
+
|
|
14
|
+
const makeCommunitiesSocket = (config) => {
|
|
15
|
+
const sock = (0, business_1.makeBusinessSocket)(config);
|
|
16
|
+
const { authState, ev, query, upsertMessage } = sock;
|
|
17
|
+
const communityQuery = async (jid, type, content) => query({
|
|
18
|
+
tag: 'iq',
|
|
19
|
+
attrs: {
|
|
20
|
+
type,
|
|
21
|
+
xmlns: 'w:g2',
|
|
22
|
+
to: jid
|
|
23
|
+
},
|
|
24
|
+
content
|
|
25
|
+
});
|
|
26
|
+
const communityMetadata = async (jid) => {
|
|
27
|
+
const result = await communityQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
|
|
28
|
+
return (0, exports.extractCommunityMetadata)(result);
|
|
29
|
+
};
|
|
30
|
+
const communityFetchAllParticipating = async () => {
|
|
31
|
+
const result = await query({
|
|
32
|
+
tag: 'iq',
|
|
33
|
+
attrs: {
|
|
34
|
+
to: '@g.us',
|
|
35
|
+
xmlns: 'w:g2',
|
|
36
|
+
type: 'get'
|
|
37
|
+
},
|
|
38
|
+
content: [
|
|
39
|
+
{
|
|
40
|
+
tag: 'participating',
|
|
41
|
+
attrs: {},
|
|
42
|
+
content: [
|
|
43
|
+
{ tag: 'participants', attrs: {} },
|
|
44
|
+
{ tag: 'description', attrs: {} }
|
|
45
|
+
]
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
});
|
|
49
|
+
const data = {};
|
|
50
|
+
const communitiesChild = (0, WABinary_1.getBinaryNodeChild)(result, 'communities');
|
|
51
|
+
if (communitiesChild) {
|
|
52
|
+
const communities = (0, WABinary_1.getBinaryNodeChildren)(communitiesChild, 'community');
|
|
53
|
+
for (const communityNode of communities) {
|
|
54
|
+
const meta = (0, exports.extractCommunityMetadata)({
|
|
55
|
+
tag: 'result',
|
|
56
|
+
attrs: {},
|
|
57
|
+
content: [communityNode]
|
|
58
|
+
});
|
|
59
|
+
data[meta.id] = meta;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
sock.ev.emit('groups.update', Object.values(data));
|
|
63
|
+
return data;
|
|
64
|
+
};
|
|
65
|
+
async function parseGroupResult(node) {
|
|
66
|
+
logger_1.default.info({ node }, 'parseGroupResult');
|
|
67
|
+
const groupNode = (0, WABinary_1.getBinaryNodeChild)(node, 'group');
|
|
68
|
+
if (groupNode) {
|
|
69
|
+
try {
|
|
70
|
+
logger_1.default.info({ groupNode }, 'groupNode');
|
|
71
|
+
const metadata = await sock.groupMetadata(`${groupNode.attrs.id}@g.us`);
|
|
72
|
+
return metadata ? metadata : Optional.empty();
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
console.error('Error parsing group metadata:', error);
|
|
76
|
+
return Optional.empty();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return Optional.empty();
|
|
80
|
+
}
|
|
81
|
+
const Optional = {
|
|
82
|
+
empty: () => null,
|
|
83
|
+
of: (value) => (value !== null ? { value } : null)
|
|
84
|
+
};
|
|
85
|
+
sock.ws.on('CB:ib,,dirty', async (node) => {
|
|
86
|
+
const { attrs } = (0, WABinary_1.getBinaryNodeChild)(node, 'dirty');
|
|
87
|
+
if (attrs.type !== 'communities') {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
await communityFetchAllParticipating();
|
|
91
|
+
await sock.cleanDirtyBits('groups');
|
|
92
|
+
});
|
|
93
|
+
return {
|
|
94
|
+
...sock,
|
|
95
|
+
communityMetadata,
|
|
96
|
+
communityCreate: async (subject, body) => {
|
|
97
|
+
const descriptionId = (0, Utils_1.generateMessageID)().substring(0, 12);
|
|
98
|
+
const result = await communityQuery('@g.us', 'set', [
|
|
99
|
+
{
|
|
100
|
+
tag: 'create',
|
|
101
|
+
attrs: { subject },
|
|
102
|
+
content: [
|
|
103
|
+
{
|
|
104
|
+
tag: 'description',
|
|
105
|
+
attrs: { id: descriptionId },
|
|
106
|
+
content: [
|
|
107
|
+
{
|
|
108
|
+
tag: 'body',
|
|
109
|
+
attrs: {},
|
|
110
|
+
content: Buffer.from(body || '', 'utf-8')
|
|
111
|
+
}
|
|
112
|
+
]
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
tag: 'parent',
|
|
116
|
+
attrs: { default_membership_approval_mode: 'request_required' }
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
tag: 'allow_non_admin_sub_group_creation',
|
|
120
|
+
attrs: {}
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
tag: 'create_general_chat',
|
|
124
|
+
attrs: {}
|
|
125
|
+
}
|
|
126
|
+
]
|
|
127
|
+
}
|
|
128
|
+
]);
|
|
129
|
+
return await parseGroupResult(result);
|
|
130
|
+
},
|
|
131
|
+
communityCreateGroup: async (subject, participants, parentCommunityJid) => {
|
|
132
|
+
const key = (0, Utils_1.generateMessageIDV2)();
|
|
133
|
+
const result = await communityQuery('@g.us', 'set', [
|
|
134
|
+
{
|
|
135
|
+
tag: 'create',
|
|
136
|
+
attrs: {
|
|
137
|
+
subject,
|
|
138
|
+
key
|
|
139
|
+
},
|
|
140
|
+
content: [
|
|
141
|
+
...participants.map(jid => ({
|
|
142
|
+
tag: 'participant',
|
|
143
|
+
attrs: { jid }
|
|
144
|
+
})),
|
|
145
|
+
{ tag: 'linked_parent', attrs: { jid: parentCommunityJid } }
|
|
146
|
+
]
|
|
147
|
+
}
|
|
148
|
+
]);
|
|
149
|
+
return await parseGroupResult(result);
|
|
150
|
+
},
|
|
151
|
+
communityLeave: async (id) => {
|
|
152
|
+
await communityQuery('@g.us', 'set', [
|
|
153
|
+
{
|
|
154
|
+
tag: 'leave',
|
|
155
|
+
attrs: {},
|
|
156
|
+
content: [{ tag: 'community', attrs: { id } }]
|
|
157
|
+
}
|
|
158
|
+
]);
|
|
159
|
+
},
|
|
160
|
+
communityUpdateSubject: async (jid, subject) => {
|
|
161
|
+
await communityQuery(jid, 'set', [
|
|
162
|
+
{
|
|
163
|
+
tag: 'subject',
|
|
164
|
+
attrs: {},
|
|
165
|
+
content: Buffer.from(subject, 'utf-8')
|
|
166
|
+
}
|
|
167
|
+
]);
|
|
168
|
+
},
|
|
169
|
+
communityLinkGroup: async (groupJid, parentCommunityJid) => {
|
|
170
|
+
await communityQuery(parentCommunityJid, 'set', [
|
|
171
|
+
{
|
|
172
|
+
tag: 'links',
|
|
173
|
+
attrs: {},
|
|
174
|
+
content: [
|
|
175
|
+
{
|
|
176
|
+
tag: 'link',
|
|
177
|
+
attrs: { link_type: 'sub_group' },
|
|
178
|
+
content: [{ tag: 'group', attrs: { jid: groupJid } }]
|
|
179
|
+
}
|
|
180
|
+
]
|
|
181
|
+
}
|
|
182
|
+
]);
|
|
183
|
+
},
|
|
184
|
+
communityUnlinkGroup: async (groupJid, parentCommunityJid) => {
|
|
185
|
+
await communityQuery(parentCommunityJid, 'set', [
|
|
186
|
+
{
|
|
187
|
+
tag: 'unlink',
|
|
188
|
+
attrs: { unlink_type: 'sub_group' },
|
|
189
|
+
content: [{ tag: 'group', attrs: { jid: groupJid } }]
|
|
190
|
+
}
|
|
191
|
+
]);
|
|
192
|
+
},
|
|
193
|
+
communityFetchLinkedGroups: async (jid) => {
|
|
194
|
+
let communityJid = jid;
|
|
195
|
+
let isCommunity = false;
|
|
196
|
+
// Try to determine if it is a subgroup or a community
|
|
197
|
+
const metadata = await sock.groupMetadata(jid);
|
|
198
|
+
if (metadata.linkedParent) {
|
|
199
|
+
// It is a subgroup, get the community jid
|
|
200
|
+
communityJid = metadata.linkedParent;
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
// It is a community
|
|
204
|
+
isCommunity = true;
|
|
205
|
+
}
|
|
206
|
+
// Fetch all subgroups of the community
|
|
207
|
+
const result = await communityQuery(communityJid, 'get', [{ tag: 'sub_groups', attrs: {} }]);
|
|
208
|
+
const linkedGroupsData = [];
|
|
209
|
+
const subGroupsNode = (0, WABinary_1.getBinaryNodeChild)(result, 'sub_groups');
|
|
210
|
+
if (subGroupsNode) {
|
|
211
|
+
const groupNodes = (0, WABinary_1.getBinaryNodeChildren)(subGroupsNode, 'group');
|
|
212
|
+
for (const groupNode of groupNodes) {
|
|
213
|
+
linkedGroupsData.push({
|
|
214
|
+
id: groupNode.attrs.id ? (0, WABinary_1.jidEncode)(groupNode.attrs.id, 'g.us') : undefined,
|
|
215
|
+
subject: groupNode.attrs.subject || '',
|
|
216
|
+
creation: groupNode.attrs.creation ? Number(groupNode.attrs.creation) : undefined,
|
|
217
|
+
owner: groupNode.attrs.creator ? (0, WABinary_1.jidNormalizedUser)(groupNode.attrs.creator) : undefined,
|
|
218
|
+
size: groupNode.attrs.size ? Number(groupNode.attrs.size) : undefined
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
communityJid,
|
|
224
|
+
isCommunity,
|
|
225
|
+
linkedGroups: linkedGroupsData
|
|
226
|
+
};
|
|
227
|
+
},
|
|
228
|
+
communityRequestParticipantsList: async (jid) => {
|
|
229
|
+
const result = await communityQuery(jid, 'get', [
|
|
230
|
+
{
|
|
231
|
+
tag: 'membership_approval_requests',
|
|
232
|
+
attrs: {}
|
|
233
|
+
}
|
|
234
|
+
]);
|
|
235
|
+
const node = (0, WABinary_1.getBinaryNodeChild)(result, 'membership_approval_requests');
|
|
236
|
+
const participants = (0, WABinary_1.getBinaryNodeChildren)(node, 'membership_approval_request');
|
|
237
|
+
return participants.map(v => v.attrs);
|
|
238
|
+
},
|
|
239
|
+
communityRequestParticipantsUpdate: async (jid, participants, action) => {
|
|
240
|
+
const result = await communityQuery(jid, 'set', [
|
|
241
|
+
{
|
|
242
|
+
tag: 'membership_requests_action',
|
|
243
|
+
attrs: {},
|
|
244
|
+
content: [
|
|
245
|
+
{
|
|
246
|
+
tag: action,
|
|
247
|
+
attrs: {},
|
|
248
|
+
content: participants.map(jid => ({
|
|
249
|
+
tag: 'participant',
|
|
250
|
+
attrs: { jid }
|
|
251
|
+
}))
|
|
252
|
+
}
|
|
253
|
+
]
|
|
254
|
+
}
|
|
255
|
+
]);
|
|
256
|
+
const node = (0, WABinary_1.getBinaryNodeChild)(result, 'membership_requests_action');
|
|
257
|
+
const nodeAction = (0, WABinary_1.getBinaryNodeChild)(node, action);
|
|
258
|
+
const participantsAffected = (0, WABinary_1.getBinaryNodeChildren)(nodeAction, 'participant');
|
|
259
|
+
return participantsAffected.map(p => {
|
|
260
|
+
return { status: p.attrs.error || '200', jid: p.attrs.jid };
|
|
261
|
+
});
|
|
262
|
+
},
|
|
263
|
+
communityParticipantsUpdate: async (jid, participants, action) => {
|
|
264
|
+
const result = await communityQuery(jid, 'set', [
|
|
265
|
+
{
|
|
266
|
+
tag: action,
|
|
267
|
+
attrs: action === 'remove' ? { linked_groups: 'true' } : {},
|
|
268
|
+
content: participants.map(jid => ({
|
|
269
|
+
tag: 'participant',
|
|
270
|
+
attrs: { jid }
|
|
271
|
+
}))
|
|
272
|
+
}
|
|
273
|
+
]);
|
|
274
|
+
const node = (0, WABinary_1.getBinaryNodeChild)(result, action);
|
|
275
|
+
const participantsAffected = (0, WABinary_1.getBinaryNodeChildren)(node, 'participant');
|
|
276
|
+
return participantsAffected.map(p => {
|
|
277
|
+
return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
|
|
278
|
+
});
|
|
279
|
+
},
|
|
280
|
+
communityUpdateDescription: async (jid, description) => {
|
|
281
|
+
const metadata = await communityMetadata(jid);
|
|
282
|
+
const prev = metadata.descId ?? null;
|
|
283
|
+
await communityQuery(jid, 'set', [
|
|
284
|
+
{
|
|
285
|
+
tag: 'description',
|
|
286
|
+
attrs: {
|
|
287
|
+
...(description ? { id: (0, Utils_1.generateMessageID)() } : { delete: 'true' }),
|
|
288
|
+
...(prev ? { prev } : {})
|
|
289
|
+
},
|
|
290
|
+
content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
|
|
291
|
+
}
|
|
292
|
+
]);
|
|
293
|
+
},
|
|
294
|
+
communityInviteCode: async (jid) => {
|
|
295
|
+
const result = await communityQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
|
|
296
|
+
const inviteNode = (0, WABinary_1.getBinaryNodeChild)(result, 'invite');
|
|
297
|
+
return inviteNode === null || inviteNode === void 0 ? void 0 : inviteNode.attrs.code;
|
|
298
|
+
},
|
|
299
|
+
communityRevokeInvite: async (jid) => {
|
|
300
|
+
const result = await communityQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
|
|
301
|
+
const inviteNode = (0, WABinary_1.getBinaryNodeChild)(result, 'invite');
|
|
302
|
+
return inviteNode === null || inviteNode === void 0 ? void 0 : inviteNode.attrs.code;
|
|
303
|
+
},
|
|
304
|
+
communityAcceptInvite: async (code) => {
|
|
305
|
+
const results = await communityQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
|
|
306
|
+
const result = (0, WABinary_1.getBinaryNodeChild)(results, 'community');
|
|
307
|
+
return result === null || result === void 0 ? void 0 : result.attrs.jid;
|
|
308
|
+
},
|
|
309
|
+
/**
|
|
310
|
+
* revoke a v4 invite for someone
|
|
311
|
+
* @param communityJid community jid
|
|
312
|
+
* @param invitedJid jid of person you invited
|
|
313
|
+
* @returns true if successful
|
|
314
|
+
*/
|
|
315
|
+
communityRevokeInviteV4: async (communityJid, invitedJid) => {
|
|
316
|
+
const result = await communityQuery(communityJid, 'set', [
|
|
317
|
+
{ tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
|
|
318
|
+
]);
|
|
319
|
+
return !!result;
|
|
320
|
+
},
|
|
321
|
+
/**
|
|
322
|
+
* accept a CommunityInviteMessage
|
|
323
|
+
* @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
|
|
324
|
+
* @param inviteMessage the message to accept
|
|
325
|
+
*/
|
|
326
|
+
communityAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
|
|
327
|
+
var _a;
|
|
328
|
+
key = typeof key === 'string' ? { remoteJid: key } : key;
|
|
329
|
+
const results = await communityQuery(inviteMessage.groupJid, 'set', [
|
|
330
|
+
{
|
|
331
|
+
tag: 'accept',
|
|
332
|
+
attrs: {
|
|
333
|
+
code: inviteMessage.inviteCode,
|
|
334
|
+
expiration: inviteMessage.inviteExpiration.toString(),
|
|
335
|
+
admin: key.remoteJid
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
]);
|
|
339
|
+
// if we have the full message key
|
|
340
|
+
// update the invite message to be expired
|
|
341
|
+
if (key.id) {
|
|
342
|
+
// create new invite message that is expired
|
|
343
|
+
inviteMessage = WAProto_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage);
|
|
344
|
+
inviteMessage.inviteExpiration = 0;
|
|
345
|
+
inviteMessage.inviteCode = '';
|
|
346
|
+
ev.emit('messages.update', [
|
|
347
|
+
{
|
|
348
|
+
key,
|
|
349
|
+
update: {
|
|
350
|
+
message: {
|
|
351
|
+
groupInviteMessage: inviteMessage
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
]);
|
|
356
|
+
}
|
|
357
|
+
// generate the community add message
|
|
358
|
+
await upsertMessage({
|
|
359
|
+
key: {
|
|
360
|
+
remoteJid: inviteMessage.groupJid,
|
|
361
|
+
id: (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id),
|
|
362
|
+
fromMe: false,
|
|
363
|
+
participant: key.remoteJid // TODO: investigate if this makes any sense at all
|
|
364
|
+
},
|
|
365
|
+
messageStubType: Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD,
|
|
366
|
+
messageStubParameters: [JSON.stringify(authState.creds.me)],
|
|
367
|
+
participant: key.remoteJid,
|
|
368
|
+
messageTimestamp: (0, Utils_1.unixTimestampSeconds)()
|
|
369
|
+
}, 'notify');
|
|
370
|
+
return results.attrs.from;
|
|
371
|
+
}),
|
|
372
|
+
communityGetInviteInfo: async (code) => {
|
|
373
|
+
const results = await communityQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
|
|
374
|
+
return (0, exports.extractCommunityMetadata)(results);
|
|
375
|
+
},
|
|
376
|
+
communityToggleEphemeral: async (jid, ephemeralExpiration) => {
|
|
377
|
+
const content = ephemeralExpiration
|
|
378
|
+
? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
|
|
379
|
+
: { tag: 'not_ephemeral', attrs: {} };
|
|
380
|
+
await communityQuery(jid, 'set', [content]);
|
|
381
|
+
},
|
|
382
|
+
communitySettingUpdate: async (jid, setting) => {
|
|
383
|
+
await communityQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
|
|
384
|
+
},
|
|
385
|
+
communityMemberAddMode: async (jid, mode) => {
|
|
386
|
+
await communityQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
|
|
387
|
+
},
|
|
388
|
+
communityJoinApprovalMode: async (jid, mode) => {
|
|
389
|
+
await communityQuery(jid, 'set', [
|
|
390
|
+
{ tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'community_join', attrs: { state: mode } }] }
|
|
391
|
+
]);
|
|
392
|
+
},
|
|
393
|
+
communityFetchAllParticipating
|
|
394
|
+
};
|
|
395
|
+
};
|
|
396
|
+
exports.makeCommunitiesSocket = makeCommunitiesSocket;
|
|
397
|
+
|
|
398
|
+
const extractCommunityMetadata = (result) => {
|
|
399
|
+
var _a, _b;
|
|
400
|
+
const community = (0, WABinary_1.getBinaryNodeChild)(result, 'community');
|
|
401
|
+
const descChild = (0, WABinary_1.getBinaryNodeChild)(community, 'description');
|
|
402
|
+
let desc;
|
|
403
|
+
let descId;
|
|
404
|
+
if (descChild) {
|
|
405
|
+
desc = (0, WABinary_1.getBinaryNodeChildString)(descChild, 'body');
|
|
406
|
+
descId = descChild.attrs.id;
|
|
407
|
+
}
|
|
408
|
+
const communityId = ((_a = community.attrs.id) === null || _a === void 0 ? void 0 : _a.includes('@'))
|
|
409
|
+
? community.attrs.id
|
|
410
|
+
: (0, WABinary_1.jidEncode)(community.attrs.id || '', 'g.us');
|
|
411
|
+
const eph = (_b = (0, WABinary_1.getBinaryNodeChild)(community, 'ephemeral')) === null || _b === void 0 ? void 0 : _b.attrs.expiration;
|
|
412
|
+
const memberAddMode = (0, WABinary_1.getBinaryNodeChildString)(community, 'member_add_mode') === 'all_member_add';
|
|
413
|
+
const metadata = {
|
|
414
|
+
id: communityId,
|
|
415
|
+
subject: community.attrs.subject || '',
|
|
416
|
+
subjectOwner: community.attrs.s_o,
|
|
417
|
+
subjectTime: Number(community.attrs.s_t || 0),
|
|
418
|
+
size: (0, WABinary_1.getBinaryNodeChildren)(community, 'participant').length,
|
|
419
|
+
creation: Number(community.attrs.creation || 0),
|
|
420
|
+
owner: community.attrs.creator ? (0, WABinary_1.jidNormalizedUser)(community.attrs.creator) : undefined,
|
|
421
|
+
desc,
|
|
422
|
+
descId,
|
|
423
|
+
linkedParent: (0, WABinary_1.getBinaryNodeChild)(community, 'linked_parent')?.attrs.jid || undefined,
|
|
424
|
+
restrict: !!(0, WABinary_1.getBinaryNodeChild)(community, 'locked'),
|
|
425
|
+
announce: !!(0, WABinary_1.getBinaryNodeChild)(community, 'announcement'),
|
|
426
|
+
isCommunity: !!(0, WABinary_1.getBinaryNodeChild)(community, 'parent'),
|
|
427
|
+
isCommunityAnnounce: !!(0, WABinary_1.getBinaryNodeChild)(community, 'default_sub_community'),
|
|
428
|
+
joinApprovalMode: !!(0, WABinary_1.getBinaryNodeChild)(community, 'membership_approval_mode'),
|
|
429
|
+
memberAddMode,
|
|
430
|
+
participants: (0, WABinary_1.getBinaryNodeChildren)(community, 'participant').map(({ attrs }) => {
|
|
431
|
+
return {
|
|
432
|
+
id: attrs.jid,
|
|
433
|
+
admin: (attrs.type || null)
|
|
434
|
+
};
|
|
435
|
+
}),
|
|
436
|
+
ephemeralDuration: eph ? +eph : undefined,
|
|
437
|
+
addressingMode: (0, WABinary_1.getBinaryNodeChildString)(community, 'addressing_mode')
|
|
438
|
+
};
|
|
439
|
+
return metadata;
|
|
440
|
+
};
|
|
441
|
+
exports.extractCommunityMetadata = extractCommunityMetadata;
|
package/lib/Socket/index.js
CHANGED
|
@@ -1,10 +1,43 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
|
+
|
|
5
|
+
const { DEFAULT_CONNECTION_CONFIG } = require("../Defaults");
|
|
6
|
+
const communities_1 = require("./communities");
|
|
7
|
+
global.__SOCKET_MAP__ = global.__SOCKET_MAP__ || new Map()
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* * @param {Object} config - Konfigurasi Baileys
|
|
11
|
+
* @param {String} sessionId - ID Unik
|
|
12
|
+
*/
|
|
13
|
+
const makeWASocket = (config, sessionId = 'primary') => {
|
|
14
|
+
if (global.__SOCKET_MAP__.has(sessionId)) {
|
|
15
|
+
const oldSock = global.__SOCKET_MAP__.get(sessionId)
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
oldSock.ws?.close?.()
|
|
19
|
+
oldSock.ws?.terminate?.()
|
|
20
|
+
oldSock.ws?.removeAllListeners?.()
|
|
21
|
+
oldSock.ev?.removeAllListeners?.()
|
|
22
|
+
} catch (e) {
|
|
23
|
+
}
|
|
24
|
+
global.__SOCKET_MAP__.delete(sessionId)
|
|
25
|
+
}
|
|
26
|
+
// -----------------------------------
|
|
27
|
+
|
|
28
|
+
const sock = (0, communities_1.makeCommunitiesSocket)({
|
|
29
|
+
...DEFAULT_CONNECTION_CONFIG,
|
|
30
|
+
...config
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
global.__SOCKET_MAP__.set(sessionId, sock)
|
|
34
|
+
sock.ws.on('close', () => {
|
|
35
|
+
if (global.__SOCKET_MAP__.get(sessionId) === sock) {
|
|
36
|
+
global.__SOCKET_MAP__.delete(sessionId)
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
return sock
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
exports.default = makeWASocket
|
|
@@ -332,7 +332,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
332
332
|
break;
|
|
333
333
|
break;
|
|
334
334
|
default:
|
|
335
|
-
// console.log("
|
|
335
|
+
// console.log("RexxHayanasi-DEBUG:", JSON.stringify({ ...child, content: Buffer.isBuffer(child.content) ? child.content.toString() : child.content, participant }, null, 2))
|
|
336
336
|
}
|
|
337
337
|
};
|
|
338
338
|
const handleNewsletterNotification = (id, node) => {
|
|
@@ -747,10 +747,21 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
747
747
|
try {
|
|
748
748
|
await Promise.all([
|
|
749
749
|
processingMutex.mutex(async () => {
|
|
750
|
-
var _a, _b, _c, _d, _e, _f;
|
|
751
|
-
|
|
752
|
-
|
|
750
|
+
var _a, _b, _c, _d, _e, _f;
|
|
751
|
+
try {
|
|
752
|
+
await decrypt();
|
|
753
|
+
} catch (err) {
|
|
754
|
+
const errStr = String(err);
|
|
755
|
+
if (errStr.includes('Bad MAC') || errStr.includes('Invalid MAC')) {
|
|
756
|
+
logger.warn({ msgId: node.attrs.id, from: node.attrs.from }, '⚠️ Bad MAC detected (Node 20/24 issue) - Forcing Retry...');
|
|
757
|
+
msg.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
|
|
758
|
+
msg.messageStubParameters = [Utils_1.MISSING_KEYS_ERROR_TEXT];
|
|
759
|
+
} else {
|
|
760
|
+
throw err;
|
|
761
|
+
}
|
|
762
|
+
}
|
|
753
763
|
if (msg.messageStubType === WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT) {
|
|
764
|
+
|
|
754
765
|
if (((_a = msg === null || msg === void 0 ? void 0 : msg.messageStubParameters) === null || _a === void 0 ? void 0 : _a[0]) === Utils_1.MISSING_KEYS_ERROR_TEXT) {
|
|
755
766
|
return sendMessageAck(node, Utils_1.NACK_REASONS.ParsingError);
|
|
756
767
|
}
|
|
@@ -5,14 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.makeMessagesSocket = void 0;
|
|
7
7
|
const boom_1 = require("@hapi/boom");
|
|
8
|
-
const { audioToBuffer, getAudioWaveform } = require("../Utils")
|
|
9
8
|
const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
|
|
10
9
|
const crypto_1 = require("crypto");
|
|
11
|
-
const RexxHayanasi = require('./
|
|
10
|
+
const RexxHayanasi = require('./Rhandler');
|
|
12
11
|
const WAProto_1 = require("../../WAProto");
|
|
13
12
|
const Defaults_1 = require("../Defaults");
|
|
14
13
|
const Utils_1 = require("../Utils");
|
|
15
|
-
|
|
16
14
|
const link_preview_1 = require("../Utils/link-preview");
|
|
17
15
|
const WABinary_1 = require("../WABinary");
|
|
18
16
|
const WAUSync_1 = require("../WAUSync");
|
|
@@ -606,26 +604,6 @@ const makeMessagesSocket = (config) => {
|
|
|
606
604
|
return 'url';
|
|
607
605
|
}
|
|
608
606
|
};
|
|
609
|
-
|
|
610
|
-
const waveform = async (content, logger) => {
|
|
611
|
-
if (typeof content === 'object' && 'audio' in content) {
|
|
612
|
-
try {
|
|
613
|
-
const audioBuffer = await audioToBuffer(content.audio)
|
|
614
|
-
const wave = await getAudioWaveform(audioBuffer, logger)
|
|
615
|
-
|
|
616
|
-
if (wave) {
|
|
617
|
-
content.waveform = wave
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
console.log(`Audio buffer length: ${audioBuffer.length} bytes`)
|
|
621
|
-
} catch (err) {
|
|
622
|
-
logger?.warn
|
|
623
|
-
? logger.warn(`Gagal membuat waveform: ${err}`)
|
|
624
|
-
: console.warn(`Gagal membuat waveform: ${err}`)
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
|
|
629
607
|
const getPrivacyTokens = async (jids) => {
|
|
630
608
|
const t = (0, Utils_1.unixTimestampSeconds)().toString();
|
|
631
609
|
const result = await query({
|
|
@@ -652,7 +630,6 @@ const waveform = async (content, logger) => {
|
|
|
652
630
|
});
|
|
653
631
|
return result;
|
|
654
632
|
};
|
|
655
|
-
|
|
656
633
|
const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
|
|
657
634
|
const rexx = new RexxHayanasi(Utils_1, waUploadToServer, relayMessage);
|
|
658
635
|
const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
|
|
@@ -713,7 +690,6 @@ const waveform = async (content, logger) => {
|
|
|
713
690
|
return message;
|
|
714
691
|
},
|
|
715
692
|
sendMessage: async (jid, content, options = {}) => {
|
|
716
|
-
await waveform(content, logger);
|
|
717
693
|
var _a, _b, _c;
|
|
718
694
|
const userJid = authState.creds.me.id;
|
|
719
695
|
if (!options.ephemeralExpiration) {
|
|
@@ -739,7 +715,7 @@ const waveform = async (content, logger) => {
|
|
|
739
715
|
disappearingMessagesInChat;
|
|
740
716
|
await groupToggleEphemeral(jid, value);
|
|
741
717
|
}
|
|
742
|
-
|
|
718
|
+
if (typeof content === 'object' && 'album' in content && content.album) {
|
|
743
719
|
const { album, caption } = content;
|
|
744
720
|
if (caption && !album[0].caption) {
|
|
745
721
|
album[0].caption = caption;
|
|
@@ -807,7 +783,7 @@ const waveform = async (content, logger) => {
|
|
|
807
783
|
else if (content.groupStatusMessage) {
|
|
808
784
|
const { quoted } = options;
|
|
809
785
|
return await rexx.handleGroupStory(content, jid, quoted);
|
|
810
|
-
}
|
|
786
|
+
}
|
|
811
787
|
else {
|
|
812
788
|
let mediaHandle;
|
|
813
789
|
const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
|
|
@@ -840,7 +816,7 @@ const waveform = async (content, logger) => {
|
|
|
840
816
|
const isPinMsg = 'pin' in content && !!content.pin;
|
|
841
817
|
const isKeepMsg = 'keep' in content && content.keep;
|
|
842
818
|
const isPollMessage = 'poll' in content && !!content.poll;
|
|
843
|
-
const isAiMsg =
|
|
819
|
+
const isAiMsg = content && content.ai === true;
|
|
844
820
|
const additionalAttributes = {};
|
|
845
821
|
const additionalNodes = [];
|
|
846
822
|
// required for delete
|
|
@@ -875,14 +851,16 @@ const waveform = async (content, logger) => {
|
|
|
875
851
|
});
|
|
876
852
|
// required to display AI icon on message
|
|
877
853
|
}
|
|
854
|
+
|
|
878
855
|
else if (isAiMsg) {
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
856
|
+
fullMsg.message.messageContextInfo = {
|
|
857
|
+
...(fullMsg.message.messageContextInfo || {}),
|
|
858
|
+
businessMessageType: 3,
|
|
859
|
+
aiMessageMetadata: {
|
|
860
|
+
isAiMessage: true
|
|
861
|
+
}
|
|
862
|
+
};
|
|
863
|
+
}
|
|
886
864
|
if (mediaHandle) {
|
|
887
865
|
additionalAttributes['media_id'] = mediaHandle;
|
|
888
866
|
}
|