@lsqltmux-code/baileys 0.0.0-stage → 8.5.0
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/README.md +405 -2
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +6902 -0
- package/WAProto/fix-import.js +29 -0
- package/WAProto/fix-imports.js +85 -0
- package/WAProto/index.d.ts +79257 -0
- package/WAProto/index.js +242946 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.js +130 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.js +12 -0
- package/lib/Signal/Group/group-session-builder.js +30 -0
- package/lib/Signal/Group/group_cipher.js +82 -0
- package/lib/Signal/Group/index.js +12 -0
- package/lib/Signal/Group/keyhelper.js +18 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.js +26 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
- package/lib/Signal/Group/sender-key-message.js +66 -0
- package/lib/Signal/Group/sender-key-name.js +48 -0
- package/lib/Signal/Group/sender-key-record.js +41 -0
- package/lib/Signal/Group/sender-key-state.js +84 -0
- package/lib/Signal/Group/sender-message-key.js +26 -0
- package/lib/Signal/libsignal.js +431 -0
- package/lib/Signal/lid-mapping.js +277 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.js +3 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/Client/websocket.js +54 -0
- package/lib/Socket/business.js +379 -0
- package/lib/Socket/chats.js +1193 -0
- package/lib/Socket/communities.js +431 -0
- package/lib/Socket/community.js +392 -0
- package/lib/Socket/dugong.js +637 -0
- package/lib/Socket/groups.js +374 -0
- package/lib/Socket/index.js +12 -0
- package/lib/Socket/luxu.js +387 -0
- package/lib/Socket/messages-recv.js +1916 -0
- package/lib/Socket/messages-send.js +1435 -0
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/newsletter.js +281 -0
- package/lib/Socket/registration.js +167 -0
- package/lib/Socket/socket.js +967 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.js +10 -0
- package/lib/Store/keyed-db.js +108 -0
- package/lib/Store/make-cache-manager-store.js +85 -0
- package/lib/Store/make-in-memory-store.js +198 -0
- package/lib/Store/make-ordered-dictionary.js +75 -0
- package/lib/Store/object-repository.js +32 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +8 -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 +25 -0
- package/lib/Types/LabelAssociation.js +7 -0
- package/lib/Types/Message.js +11 -0
- package/lib/Types/Mex.js +37 -0
- package/lib/Types/Newsletter.js +38 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +3 -0
- package/lib/Types/State.js +56 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +26 -0
- package/lib/Utils/auth-utils.js +302 -0
- package/lib/Utils/baileys-event-stream.js +63 -0
- package/lib/Utils/browser-utils.js +48 -0
- package/lib/Utils/business.js +231 -0
- package/lib/Utils/chat-utils.js +872 -0
- package/lib/Utils/companion-reg-client-utils.js +35 -0
- package/lib/Utils/crypto.js +118 -0
- package/lib/Utils/decode-wa-message.js +350 -0
- package/lib/Utils/event-buffer.js +622 -0
- package/lib/Utils/generics.js +403 -0
- package/lib/Utils/history.js +134 -0
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/index.js +23 -0
- package/lib/Utils/link-preview.js +85 -0
- package/lib/Utils/logger.js +3 -0
- package/lib/Utils/lt-hash.js +8 -0
- package/lib/Utils/make-mutex.js +33 -0
- package/lib/Utils/message-composer.js +273 -0
- package/lib/Utils/message-retry-manager.js +265 -0
- package/lib/Utils/messages-media.js +788 -0
- package/lib/Utils/messages.js +1253 -0
- package/lib/Utils/noise-handler.js +201 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/process-message.js +630 -0
- package/lib/Utils/reporting-utils.js +258 -0
- package/lib/Utils/signal.js +201 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/sync-action-utils.js +49 -0
- package/lib/Utils/tc-token-utils.js +163 -0
- package/lib/Utils/use-multi-file-auth-state.js +121 -0
- package/lib/Utils/validate-connection.js +203 -0
- package/lib/WABinary/constants.js +1301 -0
- package/lib/WABinary/decode.js +262 -0
- package/lib/WABinary/encode.js +220 -0
- package/lib/WABinary/generic-utils.js +204 -0
- package/lib/WABinary/index.js +6 -0
- package/lib/WABinary/jid-utils.js +98 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +10 -0
- package/lib/WAM/constants.js +22853 -0
- package/lib/WAM/encode.js +150 -0
- package/lib/WAM/index.js +4 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +52 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +54 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
- package/lib/WAUSync/Protocols/index.js +6 -0
- package/lib/WAUSync/USyncQuery.js +98 -0
- package/lib/WAUSync/USyncUser.js +31 -0
- package/lib/WAUSync/index.js +4 -0
- package/lib/index.js +49 -0
- package/package.json +135 -5
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeCommunitiesSocket = exports.extractCommunityMetadata = void 0;
|
|
4
|
+
const { proto } = require("../../WAProto");
|
|
5
|
+
const { WAMessageStubType, WAMessageAddressingMode } = require("../Types");
|
|
6
|
+
const { generateMessageID, unixTimestampSeconds } = require("../Utils");
|
|
7
|
+
const {
|
|
8
|
+
getBinaryNodeChild,
|
|
9
|
+
getBinaryNodeChildren,
|
|
10
|
+
getBinaryNodeChildString,
|
|
11
|
+
jidEncode,
|
|
12
|
+
jidNormalizedUser,
|
|
13
|
+
} = require("../WABinary");
|
|
14
|
+
const { makeBusinessSocket } = require("./business");
|
|
15
|
+
const makeCommunitiesSocket = (config) => {
|
|
16
|
+
const conn = makeBusinessSocket(config);
|
|
17
|
+
const { authState, ev, query, groupMetadata, upsertMessage, cleanDirtyBits } = conn;
|
|
18
|
+
const communityQuery = async (jid, type, content) => query({
|
|
19
|
+
tag: 'iq',
|
|
20
|
+
attrs: { type, xmlns: 'w:g2', to: jid },
|
|
21
|
+
content
|
|
22
|
+
});
|
|
23
|
+
const communityMetadata = async (jid) => {
|
|
24
|
+
const result = await communityQuery(jid, 'get', [
|
|
25
|
+
{ tag: 'query', attrs: { request: 'interactive' } }
|
|
26
|
+
]);
|
|
27
|
+
return extractCommunityMetadata(result);
|
|
28
|
+
};
|
|
29
|
+
const communityFetchAllParticipating = async () => {
|
|
30
|
+
const result = await query({
|
|
31
|
+
tag: 'iq',
|
|
32
|
+
attrs: { to: '@g.us', xmlns: 'w:g2', type: 'get' },
|
|
33
|
+
content: [
|
|
34
|
+
{
|
|
35
|
+
tag: 'participating',
|
|
36
|
+
attrs: {},
|
|
37
|
+
content: [
|
|
38
|
+
{ tag: 'participants', attrs: {} },
|
|
39
|
+
{ tag: 'description', attrs: {} }
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
});
|
|
44
|
+
const data = {};
|
|
45
|
+
const communitiesChild = getBinaryNodeChild(result, 'communities');
|
|
46
|
+
if (communitiesChild) {
|
|
47
|
+
const communities = getBinaryNodeChildren(communitiesChild, 'community');
|
|
48
|
+
for (const communityNode of communities) {
|
|
49
|
+
const meta = extractCommunityMetadata({
|
|
50
|
+
tag: 'result',
|
|
51
|
+
attrs: {},
|
|
52
|
+
content: [communityNode]
|
|
53
|
+
});
|
|
54
|
+
data[meta.id] = meta;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
conn.ev.emit('groups.update', Object.values(data));
|
|
58
|
+
return data;
|
|
59
|
+
};
|
|
60
|
+
async function parseGroupResult(node) {
|
|
61
|
+
var _a;
|
|
62
|
+
(_a = conn.logger) === null || _a === void 0 ? void 0 : _a.info({ node }, 'parseGroupResult');
|
|
63
|
+
const groupNode = getBinaryNodeChild(node, 'group');
|
|
64
|
+
if (groupNode) {
|
|
65
|
+
try {
|
|
66
|
+
const metadata = await groupMetadata(`${groupNode.attrs.id}@g.us`);
|
|
67
|
+
return metadata || null;
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
var _b;
|
|
71
|
+
(_b = conn.logger) === null || _b === void 0 ? void 0 : _b.warn({ error }, 'Error parsing group metadata');
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
conn.ws.on('CB:ib,,dirty', async (node) => {
|
|
78
|
+
const { attrs } = getBinaryNodeChild(node, 'dirty');
|
|
79
|
+
if (attrs.type !== 'communities') {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
await communityFetchAllParticipating();
|
|
83
|
+
await cleanDirtyBits('groups');
|
|
84
|
+
});
|
|
85
|
+
return {
|
|
86
|
+
...conn,
|
|
87
|
+
communityQuery,
|
|
88
|
+
communityMetadata,
|
|
89
|
+
communityCreate: async (subject, body) => {
|
|
90
|
+
const descriptionId = generateMessageID().substring(0, 12);
|
|
91
|
+
const result = await communityQuery('@g.us', 'set', [
|
|
92
|
+
{
|
|
93
|
+
tag: 'create',
|
|
94
|
+
attrs: { subject },
|
|
95
|
+
content: [
|
|
96
|
+
{
|
|
97
|
+
tag: 'description',
|
|
98
|
+
attrs: { id: descriptionId },
|
|
99
|
+
content: [
|
|
100
|
+
{ tag: 'body', attrs: {}, content: Buffer.from(body || '', 'utf-8') }
|
|
101
|
+
]
|
|
102
|
+
},
|
|
103
|
+
{ tag: 'parent', attrs: { default_membership_approval_mode: 'request_required' } },
|
|
104
|
+
{ tag: 'allow_non_admin_sub_group_creation', attrs: {} },
|
|
105
|
+
{ tag: 'create_general_chat', attrs: {} }
|
|
106
|
+
]
|
|
107
|
+
}
|
|
108
|
+
]);
|
|
109
|
+
return await parseGroupResult(result);
|
|
110
|
+
},
|
|
111
|
+
communityCreateGroup: async (subject, participants, parentCommunityJid) => {
|
|
112
|
+
const key = generateMessageID();
|
|
113
|
+
const result = await communityQuery('@g.us', 'set', [
|
|
114
|
+
{
|
|
115
|
+
tag: 'create',
|
|
116
|
+
attrs: { subject, key },
|
|
117
|
+
content: [
|
|
118
|
+
...participants.map((jid) => ({ tag: 'participant', attrs: { jid } })),
|
|
119
|
+
{ tag: 'linked_parent', attrs: { jid: parentCommunityJid } }
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
]);
|
|
123
|
+
return await parseGroupResult(result);
|
|
124
|
+
},
|
|
125
|
+
communityLeave: async (id) => {
|
|
126
|
+
await communityQuery('@g.us', 'set', [
|
|
127
|
+
{ tag: 'leave', attrs: {}, content: [{ tag: 'community', attrs: { id } }] }
|
|
128
|
+
]);
|
|
129
|
+
},
|
|
130
|
+
communityUpdateSubject: async (jid, subject) => {
|
|
131
|
+
await communityQuery(jid, 'set', [
|
|
132
|
+
{ tag: 'subject', attrs: {}, content: Buffer.from(subject, 'utf-8') }
|
|
133
|
+
]);
|
|
134
|
+
},
|
|
135
|
+
communityLinkGroup: async (groupJid, parentCommunityJid) => {
|
|
136
|
+
await communityQuery(parentCommunityJid, 'set', [
|
|
137
|
+
{
|
|
138
|
+
tag: 'links',
|
|
139
|
+
attrs: {},
|
|
140
|
+
content: [
|
|
141
|
+
{
|
|
142
|
+
tag: 'link',
|
|
143
|
+
attrs: { link_type: 'sub_group' },
|
|
144
|
+
content: [{ tag: 'group', attrs: { jid: groupJid } }]
|
|
145
|
+
}
|
|
146
|
+
]
|
|
147
|
+
}
|
|
148
|
+
]);
|
|
149
|
+
},
|
|
150
|
+
communityUnlinkGroup: async (groupJid, parentCommunityJid) => {
|
|
151
|
+
await communityQuery(parentCommunityJid, 'set', [
|
|
152
|
+
{
|
|
153
|
+
tag: 'unlink',
|
|
154
|
+
attrs: { unlink_type: 'sub_group' },
|
|
155
|
+
content: [{ tag: 'group', attrs: { jid: groupJid } }]
|
|
156
|
+
}
|
|
157
|
+
]);
|
|
158
|
+
},
|
|
159
|
+
communityFetchLinkedGroups: async (jid) => {
|
|
160
|
+
let communityJid = jid;
|
|
161
|
+
let isCommunity = false;
|
|
162
|
+
const metadata = await groupMetadata(jid);
|
|
163
|
+
if (metadata.linkedParent) {
|
|
164
|
+
communityJid = metadata.linkedParent;
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
isCommunity = true;
|
|
168
|
+
}
|
|
169
|
+
const result = await communityQuery(communityJid, 'get', [
|
|
170
|
+
{ tag: 'sub_groups', attrs: {} }
|
|
171
|
+
]);
|
|
172
|
+
const linkedGroupsData = [];
|
|
173
|
+
const subGroupsNode = getBinaryNodeChild(result, 'sub_groups');
|
|
174
|
+
if (subGroupsNode) {
|
|
175
|
+
const groupNodes = getBinaryNodeChildren(subGroupsNode, 'group');
|
|
176
|
+
for (const groupNode of groupNodes) {
|
|
177
|
+
linkedGroupsData.push({
|
|
178
|
+
id: groupNode.attrs.id ? jidEncode(groupNode.attrs.id, 'g.us') : undefined,
|
|
179
|
+
subject: groupNode.attrs.subject || '',
|
|
180
|
+
creation: groupNode.attrs.creation ? Number(groupNode.attrs.creation) : undefined,
|
|
181
|
+
owner: groupNode.attrs.creator ? jidNormalizedUser(groupNode.attrs.creator) : undefined,
|
|
182
|
+
size: groupNode.attrs.size ? Number(groupNode.attrs.size) : undefined
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return { communityJid, isCommunity, linkedGroups: linkedGroupsData };
|
|
187
|
+
},
|
|
188
|
+
communityRequestParticipantsList: async (jid) => {
|
|
189
|
+
const result = await communityQuery(jid, 'get', [
|
|
190
|
+
{ tag: 'membership_approval_requests', attrs: {} }
|
|
191
|
+
]);
|
|
192
|
+
const node = getBinaryNodeChild(result, 'membership_approval_requests');
|
|
193
|
+
const participants = getBinaryNodeChildren(node, 'membership_approval_request');
|
|
194
|
+
return participants.map((v) => v.attrs);
|
|
195
|
+
},
|
|
196
|
+
communityRequestParticipantsUpdate: async (jid, participants, action) => {
|
|
197
|
+
const result = await communityQuery(jid, 'set', [
|
|
198
|
+
{
|
|
199
|
+
tag: 'membership_requests_action',
|
|
200
|
+
attrs: {},
|
|
201
|
+
content: [
|
|
202
|
+
{
|
|
203
|
+
tag: action,
|
|
204
|
+
attrs: {},
|
|
205
|
+
content: participants.map((jid) => ({ tag: 'participant', attrs: { jid } }))
|
|
206
|
+
}
|
|
207
|
+
]
|
|
208
|
+
}
|
|
209
|
+
]);
|
|
210
|
+
const node = getBinaryNodeChild(result, 'membership_requests_action');
|
|
211
|
+
const nodeAction = getBinaryNodeChild(node, action);
|
|
212
|
+
const participantsAffected = getBinaryNodeChildren(nodeAction, 'participant');
|
|
213
|
+
return participantsAffected.map((p) => ({ status: p.attrs.error || '200', jid: p.attrs.jid }));
|
|
214
|
+
},
|
|
215
|
+
communityParticipantsUpdate: async (jid, participants, action) => {
|
|
216
|
+
const result = await communityQuery(jid, 'set', [
|
|
217
|
+
{
|
|
218
|
+
tag: action,
|
|
219
|
+
attrs: action === 'remove' ? { linked_groups: 'true' } : {},
|
|
220
|
+
content: participants.map((jid) => ({ tag: 'participant', attrs: { jid } }))
|
|
221
|
+
}
|
|
222
|
+
]);
|
|
223
|
+
const node = getBinaryNodeChild(result, action);
|
|
224
|
+
const participantsAffected = getBinaryNodeChildren(node, 'participant');
|
|
225
|
+
return participantsAffected.map((p) => ({ status: p.attrs.error || '200', jid: p.attrs.jid, content: p }));
|
|
226
|
+
},
|
|
227
|
+
communityUpdateDescription: async (jid, description) => {
|
|
228
|
+
var _a;
|
|
229
|
+
const metadata = await communityMetadata(jid);
|
|
230
|
+
const prev = (_a = metadata.descId) !== null && _a !== void 0 ? _a : null;
|
|
231
|
+
await communityQuery(jid, 'set', [
|
|
232
|
+
{
|
|
233
|
+
tag: 'description',
|
|
234
|
+
attrs: {
|
|
235
|
+
...(description ? { id: generateMessageID() } : { delete: 'true' }),
|
|
236
|
+
...(prev ? { prev } : {})
|
|
237
|
+
},
|
|
238
|
+
content: description
|
|
239
|
+
? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }]
|
|
240
|
+
: undefined
|
|
241
|
+
}
|
|
242
|
+
]);
|
|
243
|
+
},
|
|
244
|
+
communityInviteCode: async (jid) => {
|
|
245
|
+
var _a;
|
|
246
|
+
const result = await communityQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
|
|
247
|
+
const inviteNode = getBinaryNodeChild(result, 'invite');
|
|
248
|
+
return (_a = inviteNode === null || inviteNode === void 0 ? void 0 : inviteNode.attrs) === null || _a === void 0 ? void 0 : _a.code;
|
|
249
|
+
},
|
|
250
|
+
communityRevokeInvite: async (jid) => {
|
|
251
|
+
var _a;
|
|
252
|
+
const result = await communityQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
|
|
253
|
+
const inviteNode = getBinaryNodeChild(result, 'invite');
|
|
254
|
+
return (_a = inviteNode === null || inviteNode === void 0 ? void 0 : inviteNode.attrs) === null || _a === void 0 ? void 0 : _a.code;
|
|
255
|
+
},
|
|
256
|
+
communityAcceptInvite: async (code) => {
|
|
257
|
+
var _a;
|
|
258
|
+
const results = await communityQuery('@g.us', 'set', [
|
|
259
|
+
{ tag: 'invite', attrs: { code } }
|
|
260
|
+
]);
|
|
261
|
+
const result = getBinaryNodeChild(results, 'community');
|
|
262
|
+
return (_a = result === null || result === void 0 ? void 0 : result.attrs) === null || _a === void 0 ? void 0 : _a.jid;
|
|
263
|
+
},
|
|
264
|
+
communityRevokeInviteV4: async (communityJid, invitedJid) => {
|
|
265
|
+
const result = await communityQuery(communityJid, 'set', [
|
|
266
|
+
{
|
|
267
|
+
tag: 'revoke',
|
|
268
|
+
attrs: {},
|
|
269
|
+
content: [{ tag: 'participant', attrs: { jid: invitedJid } }]
|
|
270
|
+
}
|
|
271
|
+
]);
|
|
272
|
+
return !!result;
|
|
273
|
+
},
|
|
274
|
+
communityAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
|
|
275
|
+
var _a;
|
|
276
|
+
key = typeof key === 'string' ? { remoteJid: key } : key;
|
|
277
|
+
const results = await communityQuery(inviteMessage.groupJid, 'set', [
|
|
278
|
+
{
|
|
279
|
+
tag: 'accept',
|
|
280
|
+
attrs: {
|
|
281
|
+
code: inviteMessage.inviteCode,
|
|
282
|
+
expiration: inviteMessage.inviteExpiration.toString(),
|
|
283
|
+
admin: key.remoteJid
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
]);
|
|
287
|
+
if (key.id) {
|
|
288
|
+
inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage);
|
|
289
|
+
inviteMessage.inviteExpiration = 0;
|
|
290
|
+
inviteMessage.inviteCode = '';
|
|
291
|
+
ev.emit('messages.update', [
|
|
292
|
+
{ key, update: { message: { groupInviteMessage: inviteMessage } } }
|
|
293
|
+
]);
|
|
294
|
+
}
|
|
295
|
+
await upsertMessage({
|
|
296
|
+
key: {
|
|
297
|
+
remoteJid: inviteMessage.groupJid,
|
|
298
|
+
id: generateMessageID((_a = conn.user) === null || _a === void 0 ? void 0 : _a.id),
|
|
299
|
+
fromMe: false,
|
|
300
|
+
participant: key.remoteJid
|
|
301
|
+
},
|
|
302
|
+
messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
|
|
303
|
+
messageStubParameters: [JSON.stringify(authState.creds.me)],
|
|
304
|
+
participant: key.remoteJid,
|
|
305
|
+
messageTimestamp: unixTimestampSeconds()
|
|
306
|
+
}, 'notify');
|
|
307
|
+
return results.attrs.from;
|
|
308
|
+
}),
|
|
309
|
+
communityGetInviteInfo: async (code) => {
|
|
310
|
+
const results = await communityQuery('@g.us', 'get', [
|
|
311
|
+
{ tag: 'invite', attrs: { code } }
|
|
312
|
+
]);
|
|
313
|
+
return extractCommunityMetadata(results);
|
|
314
|
+
},
|
|
315
|
+
communityToggleEphemeral: async (jid, ephemeralExpiration) => {
|
|
316
|
+
const content = ephemeralExpiration
|
|
317
|
+
? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
|
|
318
|
+
: { tag: 'not_ephemeral', attrs: {} };
|
|
319
|
+
await communityQuery(jid, 'set', [content]);
|
|
320
|
+
},
|
|
321
|
+
communitySettingUpdate: async (jid, setting) => {
|
|
322
|
+
await communityQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
|
|
323
|
+
},
|
|
324
|
+
communityMemberAddMode: async (jid, mode) => {
|
|
325
|
+
await communityQuery(jid, 'set', [
|
|
326
|
+
{ tag: 'member_add_mode', attrs: {}, content: mode }
|
|
327
|
+
]);
|
|
328
|
+
},
|
|
329
|
+
communityJoinApprovalMode: async (jid, mode) => {
|
|
330
|
+
await communityQuery(jid, 'set', [
|
|
331
|
+
{
|
|
332
|
+
tag: 'membership_approval_mode',
|
|
333
|
+
attrs: {},
|
|
334
|
+
content: [{ tag: 'community_join', attrs: { state: mode } }]
|
|
335
|
+
}
|
|
336
|
+
]);
|
|
337
|
+
},
|
|
338
|
+
communityFetchAllParticipating
|
|
339
|
+
};
|
|
340
|
+
};
|
|
341
|
+
exports.makeCommunitiesSocket = makeCommunitiesSocket;
|
|
342
|
+
const extractCommunityMetadata = (result) => {
|
|
343
|
+
var _a, _b, _c, _d, _e;
|
|
344
|
+
const community = getBinaryNodeChild(result, 'group');
|
|
345
|
+
const descChild = getBinaryNodeChild(community, 'description');
|
|
346
|
+
let desc;
|
|
347
|
+
let descId;
|
|
348
|
+
if (descChild) {
|
|
349
|
+
desc = getBinaryNodeChildString(descChild, 'body');
|
|
350
|
+
descId = descChild.attrs.id;
|
|
351
|
+
}
|
|
352
|
+
const mode = community.attrs.addressing_mode;
|
|
353
|
+
const communityId = community.attrs.id.includes('@')
|
|
354
|
+
? community.attrs.id
|
|
355
|
+
: jidEncode(community.attrs.id, 'g.us');
|
|
356
|
+
const eph = (_a = getBinaryNodeChild(community, 'ephemeral')) === null || _a === void 0 ? void 0 : _a.attrs.expiration;
|
|
357
|
+
const memberAddMode = getBinaryNodeChildString(community, 'member_add_mode') === 'all_member_add';
|
|
358
|
+
const metadata = {
|
|
359
|
+
id: communityId,
|
|
360
|
+
subject: community.attrs.subject,
|
|
361
|
+
subjectOwner: community.attrs.s_o,
|
|
362
|
+
subjectOwnerAlt: ((_b = community.attrs) === null || _b === void 0 ? void 0 : _b.s_o_pn) ? community.attrs.s_o_pn : community.attrs.s_o,
|
|
363
|
+
subjectTime: Number(community.attrs.s_t || 0),
|
|
364
|
+
size: Number((_c = community.attrs) === null || _c === void 0 ? void 0 : _c.size
|
|
365
|
+
? community.attrs.size
|
|
366
|
+
: getBinaryNodeChildren(community, 'participant').length),
|
|
367
|
+
creation: Number(community.attrs.creation || 0),
|
|
368
|
+
owner: community.attrs.creator ? jidNormalizedUser(community.attrs.creator) : undefined,
|
|
369
|
+
ownerAlt: community.attrs.creator
|
|
370
|
+
? jidNormalizedUser(((_d = community.attrs) === null || _d === void 0 ? void 0 : _d.creator_pn) ? community.attrs.creator_pn : community.attrs.creator)
|
|
371
|
+
: undefined,
|
|
372
|
+
ownerCountry: community.attrs.creator_country_code,
|
|
373
|
+
desc,
|
|
374
|
+
descId,
|
|
375
|
+
linkedParent: ((_e = getBinaryNodeChild(community, 'linked_parent')) === null || _e === void 0 ? void 0 : _e.attrs.jid) || undefined,
|
|
376
|
+
restrict: !!getBinaryNodeChild(community, 'locked'),
|
|
377
|
+
announce: !!getBinaryNodeChild(community, 'announcement'),
|
|
378
|
+
isCommunity: !!getBinaryNodeChild(community, 'parent'),
|
|
379
|
+
isCommunityAnnounce: !!getBinaryNodeChild(community, 'default_sub_group'),
|
|
380
|
+
joinApprovalMode: !!getBinaryNodeChild(community, 'membership_approval_mode'),
|
|
381
|
+
memberAddMode,
|
|
382
|
+
participants: getBinaryNodeChildren(community, 'participant').map(({ attrs }) => ({
|
|
383
|
+
id: mode === WAMessageAddressingMode.LID ? community.attrs.phone_number : attrs.jid,
|
|
384
|
+
lid: mode === WAMessageAddressingMode.LID ? community.attrs.jid : attrs.lid,
|
|
385
|
+
admin: attrs.type || null
|
|
386
|
+
})),
|
|
387
|
+
ephemeralDuration: eph ? Number(eph) : undefined,
|
|
388
|
+
addressingMode: mode
|
|
389
|
+
};
|
|
390
|
+
return metadata;
|
|
391
|
+
};
|
|
392
|
+
exports.extractCommunityMetadata = extractCommunityMetadata;
|