@ikyyjee/ikyysinggle 1.7.7
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/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +8083 -0
- package/WAProto/fix-imports.js +85 -0
- package/WAProto/index.d.ts +29095 -0
- package/WAProto/index.js +172336 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/index.js +194 -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/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/index.js +3 -0
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/websocket.js +102 -0
- package/lib/Socket/aigroups.js +221 -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/graphql.js +524 -0
- package/lib/Socket/groups.js +408 -0
- package/lib/Socket/index.js +49 -0
- package/lib/Socket/interop.js +341 -0
- package/lib/Socket/luxu.js +510 -0
- package/lib/Socket/managed-account.js +99 -0
- package/lib/Socket/messages-recv.js +2009 -0
- package/lib/Socket/messages-send.js +1608 -0
- package/lib/Socket/mex.js +41 -0
- package/lib/Socket/newsletter.js +399 -0
- package/lib/Socket/privacy.js +128 -0
- package/lib/Socket/registration.js +238 -0
- package/lib/Socket/socket.js +1000 -0
- package/lib/Socket/text-router.js +67 -0
- package/lib/Socket/username.js +234 -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 +114 -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/adaptive-healing.js +53 -0
- package/lib/Utils/auth-utils.js +302 -0
- package/lib/Utils/browser-utils.js +50 -0
- package/lib/Utils/business.js +231 -0
- package/lib/Utils/chat-utils.js +872 -0
- package/lib/Utils/command-loader.js +108 -0
- package/lib/Utils/companion-reg-client-utils.js +35 -0
- package/lib/Utils/consumer-application.js +106 -0
- package/lib/Utils/crypto.js +137 -0
- package/lib/Utils/curve25519-js.js +262 -0
- package/lib/Utils/decode-wa-message.js +498 -0
- package/lib/Utils/event-buffer.js +622 -0
- package/lib/Utils/generics.js +403 -0
- package/lib/Utils/group-history.js +47 -0
- package/lib/Utils/history.js +134 -0
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/index.js +38 -0
- package/lib/Utils/jid-display-normalization.js +198 -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 +267 -0
- package/lib/Utils/messages-media.js +791 -0
- package/lib/Utils/messages.js +1260 -0
- package/lib/Utils/meta-ai-msmsg.js +271 -0
- package/lib/Utils/native-bridge.js +77 -0
- package/lib/Utils/noise-handler.js +201 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/optimizer.js +90 -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/session-pool.js +73 -0
- package/lib/Utils/signal.js +207 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/sticker.js +139 -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/use-sqlite-auth-state.js +168 -0
- package/lib/Utils/validate-connection.js +203 -0
- package/lib/Utils/view-once-cache.js +79 -0
- package/lib/Utils/voip-rekey.js +25 -0
- package/lib/Utils/warmup.js +117 -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/USyncBusinessProtocol.js +41 -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/USyncFeatureProtocol.js +52 -0
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +31 -0
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +26 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +35 -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 +13 -0
- package/lib/WAUSync/USyncQuery.js +127 -0
- package/lib/WAUSync/USyncUser.js +31 -0
- package/lib/WAUSync/index.js +4 -0
- package/lib/antiban.js +4083 -0
- package/lib/index.js +24 -0
- package/package.json +147 -0
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { proto } from '../../WAProto/index.js';
|
|
3
|
+
import { WAMessageAddressingMode, WAMessageStubType } from '../Types/index.js';
|
|
4
|
+
import { generateMessageIDV2, resolveOptimizerConfig, unixTimestampSeconds } from '../Utils/index.js';
|
|
5
|
+
import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString, isLidUser, isPnUser, jidEncode, jidNormalizedUser } from '../WABinary/index.js';
|
|
6
|
+
import { makeChatsSocket } from './chats.js';
|
|
7
|
+
export const makeGroupsSocket = (config) => {
|
|
8
|
+
const sock = makeChatsSocket(config);
|
|
9
|
+
const { authState, ev, query, upsertMessage } = sock;
|
|
10
|
+
const groupQuery = async (jid, type, content, xlmns) => query({
|
|
11
|
+
tag: 'iq',
|
|
12
|
+
attrs: {
|
|
13
|
+
type,
|
|
14
|
+
xmlns: xlmns ? xlmns : 'w:g2',
|
|
15
|
+
to: jid
|
|
16
|
+
},
|
|
17
|
+
content
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* Auto-group-join guard — same deny-by-default idea as the channel-follow
|
|
21
|
+
* guard in newsletter.js, applied to `groupAcceptInvite`/`groupAcceptInviteV4`.
|
|
22
|
+
* ON by default. Blocks joining a group via invite code/link unless the
|
|
23
|
+
* code (for `groupAcceptInvite`) or the group's JID (for
|
|
24
|
+
* `groupAcceptInviteV4`, where the JID is known up-front) is allowlisted.
|
|
25
|
+
* Disable entirely with `blockAutoJoinGroups: false`, or allowlist specific
|
|
26
|
+
* codes/JIDs with `allowedAutoJoinGroups: [...]`. See README.md.
|
|
27
|
+
*/
|
|
28
|
+
const groupJoinGuardEnabled = config.blockAutoJoinGroups !== false;
|
|
29
|
+
const groupJoinAllowlist = new Set(Array.isArray(config.allowedAutoJoinGroups) ? config.allowedAutoJoinGroups : []);
|
|
30
|
+
const blockedGroupJoins = [];
|
|
31
|
+
const optimizerLimits = resolveOptimizerConfig(config.optiMazer);
|
|
32
|
+
const guardLogMax = config.guardLogMax ?? optimizerLimits?.guardLogMax ?? 200;
|
|
33
|
+
const recordBlockedGroupJoin = (value) => {
|
|
34
|
+
blockedGroupJoins.push({ value, at: new Date().toISOString() });
|
|
35
|
+
if (blockedGroupJoins.length > guardLogMax) {
|
|
36
|
+
blockedGroupJoins.shift();
|
|
37
|
+
}
|
|
38
|
+
config.logger?.warn?.({ value }, 'blocked auto-group-join attempt (not in allowlist)');
|
|
39
|
+
console.warn(`\x1b[33m[xayz-baileys] \u{1F6E1} Blocked group-join attempt: ${value}\x1b[0m`);
|
|
40
|
+
console.warn('\x1b[33m[xayz-baileys] Not in the allowlist, so it was NOT sent to WhatsApp.\x1b[0m');
|
|
41
|
+
console.warn('\x1b[33m[xayz-baileys] Set { blockAutoJoinGroups: false } in your config to allow it.\x1b[0m');
|
|
42
|
+
};
|
|
43
|
+
const groupMetadata = async (jid) => {
|
|
44
|
+
const result = await groupQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
|
|
45
|
+
return extractGroupMetadata(result);
|
|
46
|
+
};
|
|
47
|
+
const groupFetchAllParticipating = async () => {
|
|
48
|
+
const result = await query({
|
|
49
|
+
tag: 'iq',
|
|
50
|
+
attrs: {
|
|
51
|
+
to: '@g.us',
|
|
52
|
+
xmlns: 'w:g2',
|
|
53
|
+
type: 'get'
|
|
54
|
+
},
|
|
55
|
+
content: [
|
|
56
|
+
{
|
|
57
|
+
tag: 'participating',
|
|
58
|
+
attrs: {},
|
|
59
|
+
content: [
|
|
60
|
+
{ tag: 'participants', attrs: {} },
|
|
61
|
+
{ tag: 'description', attrs: {} }
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
});
|
|
66
|
+
const data = {};
|
|
67
|
+
const groupsChild = getBinaryNodeChild(result, 'groups');
|
|
68
|
+
if (groupsChild) {
|
|
69
|
+
const groups = getBinaryNodeChildren(groupsChild, 'group');
|
|
70
|
+
for (const groupNode of groups) {
|
|
71
|
+
const meta = extractGroupMetadata({
|
|
72
|
+
tag: 'result',
|
|
73
|
+
attrs: {},
|
|
74
|
+
content: [groupNode]
|
|
75
|
+
});
|
|
76
|
+
data[meta.id] = meta;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// TODO: properly parse LID / PN DATA
|
|
80
|
+
sock.ev.emit('groups.update', Object.values(data));
|
|
81
|
+
return data;
|
|
82
|
+
};
|
|
83
|
+
sock.ws.on('CB:ib,,dirty', async (node) => {
|
|
84
|
+
const { attrs } = getBinaryNodeChild(node, 'dirty');
|
|
85
|
+
if (attrs.type !== 'groups') {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
await groupFetchAllParticipating();
|
|
89
|
+
await sock.cleanDirtyBits('groups');
|
|
90
|
+
});
|
|
91
|
+
return {
|
|
92
|
+
...sock,
|
|
93
|
+
groupMetadata,
|
|
94
|
+
/** Every group-join attempt the guard has blocked so far. */
|
|
95
|
+
getBlockedGroupJoins: () => [...blockedGroupJoins],
|
|
96
|
+
groupCreate: async (subject, participants) => {
|
|
97
|
+
const key = generateMessageIDV2();
|
|
98
|
+
const result = await groupQuery('@g.us', 'set', [
|
|
99
|
+
{
|
|
100
|
+
tag: 'create',
|
|
101
|
+
attrs: {
|
|
102
|
+
subject,
|
|
103
|
+
key
|
|
104
|
+
},
|
|
105
|
+
content: participants.map(jid => ({
|
|
106
|
+
tag: 'participant',
|
|
107
|
+
attrs: { jid }
|
|
108
|
+
}))
|
|
109
|
+
}
|
|
110
|
+
]);
|
|
111
|
+
return extractGroupMetadata(result);
|
|
112
|
+
},
|
|
113
|
+
groupLeave: async (id) => {
|
|
114
|
+
await groupQuery('@g.us', 'set', [
|
|
115
|
+
{
|
|
116
|
+
tag: 'leave',
|
|
117
|
+
attrs: {},
|
|
118
|
+
content: [{ tag: 'group', attrs: { id } }]
|
|
119
|
+
}
|
|
120
|
+
]);
|
|
121
|
+
},
|
|
122
|
+
groupUpdateSubject: async (jid, subject) => {
|
|
123
|
+
await groupQuery(jid, 'set', [
|
|
124
|
+
{
|
|
125
|
+
tag: 'subject',
|
|
126
|
+
attrs: {},
|
|
127
|
+
content: Buffer.from(subject, 'utf-8')
|
|
128
|
+
}
|
|
129
|
+
]);
|
|
130
|
+
},
|
|
131
|
+
groupRequestParticipantsList: async (jid) => {
|
|
132
|
+
const result = await groupQuery(jid, 'get', [
|
|
133
|
+
{
|
|
134
|
+
tag: 'membership_approval_requests',
|
|
135
|
+
attrs: {}
|
|
136
|
+
}
|
|
137
|
+
]);
|
|
138
|
+
const node = getBinaryNodeChild(result, 'membership_approval_requests');
|
|
139
|
+
const participants = getBinaryNodeChildren(node, 'membership_approval_request');
|
|
140
|
+
return participants.map(v => v.attrs);
|
|
141
|
+
},
|
|
142
|
+
groupRequestParticipantsUpdate: async (jid, participants, action) => {
|
|
143
|
+
const result = await groupQuery(jid, 'set', [
|
|
144
|
+
{
|
|
145
|
+
tag: 'membership_requests_action',
|
|
146
|
+
attrs: {},
|
|
147
|
+
content: [
|
|
148
|
+
{
|
|
149
|
+
tag: action,
|
|
150
|
+
attrs: {},
|
|
151
|
+
content: participants.map(jid => ({
|
|
152
|
+
tag: 'participant',
|
|
153
|
+
attrs: { jid }
|
|
154
|
+
}))
|
|
155
|
+
}
|
|
156
|
+
]
|
|
157
|
+
}
|
|
158
|
+
]);
|
|
159
|
+
const node = getBinaryNodeChild(result, 'membership_requests_action');
|
|
160
|
+
const nodeAction = getBinaryNodeChild(node, action);
|
|
161
|
+
const participantsAffected = getBinaryNodeChildren(nodeAction, 'participant');
|
|
162
|
+
return participantsAffected.map(p => {
|
|
163
|
+
return { status: p.attrs.error || '200', jid: p.attrs.jid };
|
|
164
|
+
});
|
|
165
|
+
},
|
|
166
|
+
groupParticipantsUpdate: async (jid, participants, action) => {
|
|
167
|
+
const result = await groupQuery(jid, 'set', [
|
|
168
|
+
{
|
|
169
|
+
tag: action,
|
|
170
|
+
attrs: {},
|
|
171
|
+
content: participants.map(jid => ({
|
|
172
|
+
tag: 'participant',
|
|
173
|
+
attrs: { jid }
|
|
174
|
+
}))
|
|
175
|
+
}
|
|
176
|
+
]);
|
|
177
|
+
const node = getBinaryNodeChild(result, action);
|
|
178
|
+
const participantsAffected = getBinaryNodeChildren(node, 'participant');
|
|
179
|
+
return participantsAffected.map(p => {
|
|
180
|
+
return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
|
|
181
|
+
});
|
|
182
|
+
},
|
|
183
|
+
groupUpdateDescription: async (jid, description) => {
|
|
184
|
+
const metadata = await groupMetadata(jid);
|
|
185
|
+
const prev = metadata.descId ?? null;
|
|
186
|
+
await groupQuery(jid, 'set', [
|
|
187
|
+
{
|
|
188
|
+
tag: 'description',
|
|
189
|
+
attrs: {
|
|
190
|
+
...(description ? { id: generateMessageIDV2() } : { delete: 'true' }),
|
|
191
|
+
...(prev ? { prev } : {})
|
|
192
|
+
},
|
|
193
|
+
content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
|
|
194
|
+
}
|
|
195
|
+
]);
|
|
196
|
+
},
|
|
197
|
+
groupInviteCode: async (jid) => {
|
|
198
|
+
const result = await groupQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
|
|
199
|
+
const inviteNode = getBinaryNodeChild(result, 'invite');
|
|
200
|
+
return inviteNode?.attrs.code;
|
|
201
|
+
},
|
|
202
|
+
groupRevokeInvite: async (jid) => {
|
|
203
|
+
const result = await groupQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
|
|
204
|
+
const inviteNode = getBinaryNodeChild(result, 'invite');
|
|
205
|
+
return inviteNode?.attrs.code;
|
|
206
|
+
},
|
|
207
|
+
groupAcceptInvite: async (code) => {
|
|
208
|
+
if (groupJoinGuardEnabled && !groupJoinAllowlist.has(code)) {
|
|
209
|
+
recordBlockedGroupJoin(code);
|
|
210
|
+
return { blocked: true, code };
|
|
211
|
+
}
|
|
212
|
+
const results = await groupQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
|
|
213
|
+
const result = getBinaryNodeChild(results, 'group');
|
|
214
|
+
return result?.attrs.jid;
|
|
215
|
+
},
|
|
216
|
+
/**
|
|
217
|
+
* revoke a v4 invite for someone
|
|
218
|
+
* @param groupJid group jid
|
|
219
|
+
* @param invitedJid jid of person you invited
|
|
220
|
+
* @returns true if successful
|
|
221
|
+
*/
|
|
222
|
+
groupRevokeInviteV4: async (groupJid, invitedJid) => {
|
|
223
|
+
const result = await groupQuery(groupJid, 'set', [
|
|
224
|
+
{ tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
|
|
225
|
+
]);
|
|
226
|
+
return !!result;
|
|
227
|
+
},
|
|
228
|
+
/**
|
|
229
|
+
* accept a GroupInviteMessage
|
|
230
|
+
* @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
|
|
231
|
+
* @param inviteMessage the message to accept
|
|
232
|
+
*/
|
|
233
|
+
groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
|
|
234
|
+
key = typeof key === 'string' ? { remoteJid: key } : key;
|
|
235
|
+
if (groupJoinGuardEnabled && !groupJoinAllowlist.has(inviteMessage.groupJid)) {
|
|
236
|
+
recordBlockedGroupJoin(inviteMessage.groupJid);
|
|
237
|
+
return { blocked: true, groupJid: inviteMessage.groupJid };
|
|
238
|
+
}
|
|
239
|
+
const results = await groupQuery(inviteMessage.groupJid, 'set', [
|
|
240
|
+
{
|
|
241
|
+
tag: 'accept',
|
|
242
|
+
attrs: {
|
|
243
|
+
code: inviteMessage.inviteCode,
|
|
244
|
+
expiration: inviteMessage.inviteExpiration.toString(),
|
|
245
|
+
admin: key.remoteJid
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
]);
|
|
249
|
+
// if we have the full message key
|
|
250
|
+
// update the invite message to be expired
|
|
251
|
+
if (key.id) {
|
|
252
|
+
// create new invite message that is expired
|
|
253
|
+
inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage);
|
|
254
|
+
inviteMessage.inviteExpiration = 0;
|
|
255
|
+
inviteMessage.inviteCode = '';
|
|
256
|
+
ev.emit('messages.update', [
|
|
257
|
+
{
|
|
258
|
+
key,
|
|
259
|
+
update: {
|
|
260
|
+
message: {
|
|
261
|
+
groupInviteMessage: inviteMessage
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
]);
|
|
266
|
+
}
|
|
267
|
+
// generate the group add message
|
|
268
|
+
await upsertMessage({
|
|
269
|
+
key: {
|
|
270
|
+
remoteJid: inviteMessage.groupJid,
|
|
271
|
+
id: generateMessageIDV2(sock.user?.id),
|
|
272
|
+
fromMe: false,
|
|
273
|
+
participant: key.remoteJid
|
|
274
|
+
},
|
|
275
|
+
messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
|
|
276
|
+
messageStubParameters: [JSON.stringify(authState.creds.me)],
|
|
277
|
+
participant: key.remoteJid,
|
|
278
|
+
messageTimestamp: unixTimestampSeconds()
|
|
279
|
+
}, 'notify');
|
|
280
|
+
return results.attrs.from;
|
|
281
|
+
}),
|
|
282
|
+
groupGetInviteInfo: async (code) => {
|
|
283
|
+
const results = await groupQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
|
|
284
|
+
return extractGroupMetadata(results);
|
|
285
|
+
},
|
|
286
|
+
groupToggleEphemeral: async (jid, ephemeralExpiration) => {
|
|
287
|
+
const content = ephemeralExpiration
|
|
288
|
+
? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
|
|
289
|
+
: { tag: 'not_ephemeral', attrs: {} };
|
|
290
|
+
await groupQuery(jid, 'set', [content]);
|
|
291
|
+
},
|
|
292
|
+
groupSettingUpdate: async (jid, setting) => {
|
|
293
|
+
await groupQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
|
|
294
|
+
},
|
|
295
|
+
groupMemberAddMode: async (jid, mode) => {
|
|
296
|
+
await groupQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
|
|
297
|
+
},
|
|
298
|
+
groupJoinApprovalMode: async (jid, mode) => {
|
|
299
|
+
await groupQuery(jid, 'set', [
|
|
300
|
+
{ tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }
|
|
301
|
+
]);
|
|
302
|
+
},
|
|
303
|
+
groupToggleHistory: async (jid, enable = true) => {
|
|
304
|
+
const result = await query({
|
|
305
|
+
tag: "iq",
|
|
306
|
+
attrs: {
|
|
307
|
+
type: "get",
|
|
308
|
+
to: "s.whatsapp.net",
|
|
309
|
+
xmlns: "w:mex"
|
|
310
|
+
},
|
|
311
|
+
content: [
|
|
312
|
+
{
|
|
313
|
+
tag: "query",
|
|
314
|
+
attrs: {
|
|
315
|
+
query_id: "24688994337458819"
|
|
316
|
+
},
|
|
317
|
+
content: Buffer.from(JSON.stringify({
|
|
318
|
+
variables: {
|
|
319
|
+
group_id: jid,
|
|
320
|
+
input: {
|
|
321
|
+
member_share_group_history_mode: enable ? "ALL_MEMBER_SHARE" : "ADMIN_SHARE"
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}), "utf-8")
|
|
325
|
+
}
|
|
326
|
+
]
|
|
327
|
+
});
|
|
328
|
+
return result;
|
|
329
|
+
},
|
|
330
|
+
groupFetchAllParticipating
|
|
331
|
+
};
|
|
332
|
+
};
|
|
333
|
+
export const extractGroupMetadata = (result) => {
|
|
334
|
+
const group = getBinaryNodeChild(result, 'group');
|
|
335
|
+
if (!group) {
|
|
336
|
+
// Mirror WAWeb: surface server/client errors with their code+text instead of crashing.
|
|
337
|
+
const errorNode = getBinaryNodeChild(result, 'error');
|
|
338
|
+
if (errorNode) {
|
|
339
|
+
const code = errorNode.attrs.code ? +errorNode.attrs.code : 500;
|
|
340
|
+
const text = errorNode.attrs.text || 'group metadata query failed';
|
|
341
|
+
throw new Boom(text, { statusCode: code, data: errorNode });
|
|
342
|
+
}
|
|
343
|
+
throw new Boom('Invalid group metadata response: missing <group> node', { data: result });
|
|
344
|
+
}
|
|
345
|
+
if (!group.attrs.id) {
|
|
346
|
+
throw new Boom('Invalid group metadata response: missing group id', { data: group });
|
|
347
|
+
}
|
|
348
|
+
const descChild = getBinaryNodeChild(group, 'description');
|
|
349
|
+
let desc;
|
|
350
|
+
let descId;
|
|
351
|
+
let descOwner;
|
|
352
|
+
let descOwnerPn;
|
|
353
|
+
let descOwnerUsername;
|
|
354
|
+
let descTime;
|
|
355
|
+
if (descChild) {
|
|
356
|
+
desc = getBinaryNodeChildString(descChild, 'body');
|
|
357
|
+
descOwner = descChild.attrs.participant ? jidNormalizedUser(descChild.attrs.participant) : undefined;
|
|
358
|
+
descOwnerPn = descChild.attrs.participant_pn ? jidNormalizedUser(descChild.attrs.participant_pn) : undefined;
|
|
359
|
+
descOwnerUsername = descChild.attrs.participant_username || undefined;
|
|
360
|
+
descTime = +descChild.attrs.t;
|
|
361
|
+
descId = descChild.attrs.id;
|
|
362
|
+
}
|
|
363
|
+
const groupId = group.attrs.id.includes('@') ? group.attrs.id : jidEncode(group.attrs.id, 'g.us');
|
|
364
|
+
const eph = getBinaryNodeChild(group, 'ephemeral')?.attrs.expiration;
|
|
365
|
+
const memberAddMode = getBinaryNodeChildString(group, 'member_add_mode') === 'all_member_add';
|
|
366
|
+
const metadata = {
|
|
367
|
+
id: groupId,
|
|
368
|
+
notify: group.attrs.notify,
|
|
369
|
+
addressingMode: group.attrs.addressing_mode === 'lid' ? WAMessageAddressingMode.LID : WAMessageAddressingMode.PN,
|
|
370
|
+
subject: group.attrs.subject,
|
|
371
|
+
subjectOwner: group.attrs.s_o,
|
|
372
|
+
subjectOwnerPn: group.attrs.s_o_pn,
|
|
373
|
+
subjectOwnerUsername: group.attrs.s_o_username,
|
|
374
|
+
subjectTime: +group.attrs.s_t,
|
|
375
|
+
size: group.attrs.size ? +group.attrs.size : getBinaryNodeChildren(group, 'participant').length,
|
|
376
|
+
creation: +group.attrs.creation,
|
|
377
|
+
owner: group.attrs.creator ? jidNormalizedUser(group.attrs.creator) : undefined,
|
|
378
|
+
ownerPn: group.attrs.creator_pn ? jidNormalizedUser(group.attrs.creator_pn) : undefined,
|
|
379
|
+
ownerUsername: group.attrs.creator_username || undefined,
|
|
380
|
+
owner_country_code: group.attrs.creator_country_code,
|
|
381
|
+
desc,
|
|
382
|
+
descId,
|
|
383
|
+
descOwner,
|
|
384
|
+
descOwnerPn,
|
|
385
|
+
descOwnerUsername,
|
|
386
|
+
descTime,
|
|
387
|
+
linkedParent: getBinaryNodeChild(group, 'linked_parent')?.attrs.jid || undefined,
|
|
388
|
+
restrict: !!getBinaryNodeChild(group, 'locked'),
|
|
389
|
+
announce: !!getBinaryNodeChild(group, 'announcement'),
|
|
390
|
+
isCommunity: !!getBinaryNodeChild(group, 'parent'),
|
|
391
|
+
isCommunityAnnounce: !!getBinaryNodeChild(group, 'default_sub_group'),
|
|
392
|
+
joinApprovalMode: !!getBinaryNodeChild(group, 'membership_approval_mode'),
|
|
393
|
+
memberAddMode,
|
|
394
|
+
participants: getBinaryNodeChildren(group, 'participant').map(({ attrs }) => {
|
|
395
|
+
// TODO: Store LID MAPPINGS
|
|
396
|
+
return {
|
|
397
|
+
id: attrs.jid,
|
|
398
|
+
phoneNumber: isLidUser(attrs.jid) && isPnUser(attrs.phone_number) ? attrs.phone_number : undefined,
|
|
399
|
+
lid: isPnUser(attrs.jid) && isLidUser(attrs.lid) ? attrs.lid : undefined,
|
|
400
|
+
username: attrs.participant_username || attrs.username || undefined,
|
|
401
|
+
admin: (attrs.type || null)
|
|
402
|
+
};
|
|
403
|
+
}),
|
|
404
|
+
ephemeralDuration: eph ? +eph : undefined
|
|
405
|
+
};
|
|
406
|
+
return metadata;
|
|
407
|
+
};
|
|
408
|
+
//# sourceMappingURL=groups.js.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { DEFAULT_CONNECTION_CONFIG } from '../Defaults/index.js';
|
|
2
|
+
import { OptiMazer } from '../Utils/optimizer.js';
|
|
3
|
+
import { makeCommunitiesSocket } from './communities.js';
|
|
4
|
+
import { makeAIGroupsSocket } from './aigroups.js';
|
|
5
|
+
import { makeGraphQLSocket } from './graphql.js';
|
|
6
|
+
import { makeInteropSocket } from './interop.js';
|
|
7
|
+
import { makeManagedAccountSocket } from './managed-account.js';
|
|
8
|
+
import { makePrivacySocket } from './privacy.js';
|
|
9
|
+
import { makeRegistrationSocket } from './registration.js';
|
|
10
|
+
import { attachTextRouter } from './text-router.js';
|
|
11
|
+
import { wrapSocket } from '../antiban.js';
|
|
12
|
+
// export the last socket layer
|
|
13
|
+
const makeWASocket = (config) => {
|
|
14
|
+
const newConfig = {
|
|
15
|
+
...DEFAULT_CONNECTION_CONFIG,
|
|
16
|
+
...config
|
|
17
|
+
};
|
|
18
|
+
let sock = makeCommunitiesSocket(newConfig);
|
|
19
|
+
// Extra first-party feature layers (account privacy/registration, Meta AI
|
|
20
|
+
// groups, cross-app interop, GraphQL-based account/payments surface),
|
|
21
|
+
// each a `sock => sock` wrapper adding methods on top of what's already
|
|
22
|
+
// there — see LITERACY.md for what each one covers.
|
|
23
|
+
sock = makeAIGroupsSocket(sock);
|
|
24
|
+
sock = makePrivacySocket(sock);
|
|
25
|
+
sock = makeRegistrationSocket(sock);
|
|
26
|
+
sock = makeManagedAccountSocket(sock);
|
|
27
|
+
sock = makeInteropSocket(sock);
|
|
28
|
+
sock = makeGraphQLSocket(sock);
|
|
29
|
+
// AntiBan — ON by default (preset 'aggressive'), disable with `antiban: false`.
|
|
30
|
+
// Wraps sendMessage with rate-limiting/warm-up/health checks and hooks
|
|
31
|
+
// connection/message events for disconnect & retry tracking.
|
|
32
|
+
// See lib/antiban.js. Access at runtime via sock.antiban (stats, destroy, etc).
|
|
33
|
+
if (newConfig.antiban !== false) {
|
|
34
|
+
sock = wrapSocket(sock, newConfig.antiban || 'aggressive');
|
|
35
|
+
}
|
|
36
|
+
// Optional convenience router: sock.onText/hears/command. Doesn't touch
|
|
37
|
+
// anything unless you actually register a route.
|
|
38
|
+
sock = attachTextRouter(sock);
|
|
39
|
+
// optiMazer — opt-in resource-usage tuning, OFF unless `optiMazer` is set
|
|
40
|
+
// (true or a config object). See lib/Utils/optimizer.js and README.md.
|
|
41
|
+
if (newConfig.optiMazer) {
|
|
42
|
+
const optimizerConfig = typeof newConfig.optiMazer === 'object' ? newConfig.optiMazer : {};
|
|
43
|
+
const optimizer = new OptiMazer(optimizerConfig).attach(sock);
|
|
44
|
+
sock = { ...sock, optiMazer: optimizer, getOptimizerStats: () => optimizer.getStats() };
|
|
45
|
+
}
|
|
46
|
+
return sock;
|
|
47
|
+
};
|
|
48
|
+
export default makeWASocket;
|
|
49
|
+
//# sourceMappingURL=index.js.map
|