@badzz88/baileys 8.5.2 → 8.5.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/README.md +1 -1
- package/WAProto/WAProto.proto +1256 -75
- package/WAProto/index.d.ts +36042 -19649
- package/WAProto/index.js +181990 -135645
- package/engine-requirements.js +7 -15
- package/lib/Defaults/index.js +22 -17
- package/lib/Signal/Group/group_cipher.js +5 -5
- package/lib/Signal/Group/keyhelper.js +4 -4
- package/lib/Signal/Group/sender-chain-key.js +2 -2
- package/lib/Signal/Group/sender-key-distribution-message.js +1 -1
- package/lib/Signal/Group/sender-key-message.js +3 -3
- package/lib/Signal/Group/sender-key-record.js +1 -1
- package/lib/Signal/Group/sender-message-key.js +5 -5
- package/lib/Signal/libsignal.js +39 -59
- package/lib/Signal/lid-mapping.js +28 -10
- package/lib/Socket/aigroups.js +5 -5
- package/lib/Socket/business.js +3 -11
- package/lib/Socket/chats.js +668 -319
- package/lib/Socket/communities.js +85 -89
- package/lib/Socket/graphql.js +435 -228
- package/lib/Socket/groups.js +132 -211
- package/lib/Socket/index.js +9 -7
- package/lib/Socket/interactive-handler.js +117 -60
- package/lib/Socket/interop.js +56 -175
- package/lib/Socket/managed-account.js +79 -48
- package/lib/Socket/messages-recv.js +898 -340
- package/lib/Socket/messages-send.js +462 -160
- package/lib/Socket/mex.js +40 -53
- package/lib/Socket/newsletter.js +291 -291
- package/lib/Socket/privacy.js +77 -265
- package/lib/Socket/registration.js +164 -157
- package/lib/Socket/socket.js +181 -199
- package/lib/Socket/username.js +144 -227
- package/lib/Store/make-cache-manager-store.js +2 -2
- package/lib/Store/make-in-memory-store.js +25 -141
- package/lib/Types/Auth.js +3 -3
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Newsletter.js +96 -65
- package/lib/Types/State.js +4 -4
- package/lib/Types/index.js +1 -1
- package/lib/Utils/auth-utils.js +52 -57
- package/lib/Utils/browser-utils.js +1 -1
- package/lib/Utils/business.js +2 -6
- package/lib/Utils/chat-utils.js +102 -38
- package/lib/Utils/crypto.js +54 -84
- package/lib/Utils/decode-wa-message.js +316 -83
- package/lib/Utils/event-buffer.js +37 -61
- package/lib/Utils/generics.js +157 -103
- package/lib/Utils/group-history.js +3 -12
- package/lib/Utils/history.js +15 -15
- package/lib/Utils/index.js +1 -5
- package/lib/Utils/link-preview.js +3 -8
- package/lib/Utils/lt-hash.js +2 -35
- package/lib/Utils/make-mutex.js +1 -1
- package/lib/Utils/message-inspect.js +393 -0
- package/lib/Utils/message-retry-manager.js +27 -92
- package/lib/Utils/messages-media.js +159 -130
- package/lib/Utils/messages.js +144 -566
- package/lib/Utils/meta-ai-msmsg.js +62 -202
- package/lib/Utils/noise-handler.js +19 -21
- package/lib/Utils/offline-node-processor.js +3 -8
- package/lib/Utils/pre-key-manager.js +13 -23
- package/lib/Utils/process-message.js +197 -106
- package/lib/Utils/reporting-utils.js +2 -2
- package/lib/Utils/signal.js +28 -63
- package/lib/Utils/stanza-ack.js +39 -12
- package/lib/Utils/sync-action-utils.js +4 -7
- package/lib/Utils/tc-token-utils.js +20 -25
- package/lib/Utils/use-multi-file-auth-state.js +30 -14
- package/lib/Utils/validate-connection.js +59 -19
- package/lib/WABinary/decode.js +50 -16
- package/lib/WABinary/encode.js +54 -224
- package/lib/WABinary/generic-utils.js +7 -97
- package/lib/WABinary/jid-utils.js +27 -14
- package/lib/WAM/encode.js +7 -7
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +58 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +7 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +13 -5
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -4
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +20 -7
- package/lib/WAUSync/Protocols/USyncNewsletterProtocol.js +865 -0
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +1 -1
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -2
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +1 -1
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +2 -1
- package/lib/WAUSync/Protocols/index.js +1 -0
- package/lib/WAUSync/USyncBackoff.js +26 -0
- package/lib/WAUSync/USyncQuery.js +77 -6
- package/lib/WAUSync/USyncUser.js +16 -8
- package/lib/WAUSync/index.js +1 -0
- package/lib/antiban.js +608 -854
- package/lib/index.js +3 -3
- package/package.json +16 -19
- package/lib/Socket/luxu.js +0 -387
- package/lib/Socket/text-router.js +0 -83
- package/lib/Store/keyed-db.js +0 -108
- package/lib/Types/Mex.js +0 -112
- package/lib/Utils/command-loader.d.ts +0 -31
- package/lib/Utils/command-loader.js +0 -100
- package/lib/Utils/companion-reg-client-utils.js +0 -42
- package/lib/Utils/curve25519-js.js +0 -275
- package/lib/Utils/native-bridge.js +0 -82
- package/lib/Utils/session-pool.d.ts +0 -16
- package/lib/Utils/session-pool.js +0 -94
- package/lib/Utils/sticker.d.ts +0 -17
- package/lib/Utils/sticker.js +0 -145
- package/lib/Utils/view-once-cache.d.ts +0 -9
- package/lib/Utils/view-once-cache.js +0 -79
package/lib/Socket/groups.js
CHANGED
|
@@ -9,28 +9,28 @@ const chats_1 = require('./chats')
|
|
|
9
9
|
const mex_1 = require('./mex')
|
|
10
10
|
|
|
11
11
|
const GROUP_MEX_QUERY_IDS = {
|
|
12
|
-
QUERY_INFO: '25530136513328492',
|
|
13
|
-
QUERY_INFO_BY_CODE: '24576337542042464',
|
|
14
|
-
QUERY_BATCH: '26440064815661176',
|
|
15
|
-
QUERY_INVITE_LINK: '24558418350455204',
|
|
16
|
-
QUERY_PARTICIPATING: '26664341543184776',
|
|
17
|
-
QUERY_SUGGESTED: '26012055225051916',
|
|
18
|
-
QUERY_LINKED: '25629003043401452',
|
|
19
|
-
QUERY_SUBGROUPS: '25554052094203120',
|
|
20
|
-
ADD_PARTICIPANTS_V2: '32627550323510250',
|
|
21
|
-
ADD_PARTICIPANTS_V3: '26581073158212628',
|
|
22
|
-
SET_PROPERTY: '24688994337458820',
|
|
23
|
-
RESET_INVITE_LINK: '24812851838367452',
|
|
24
|
-
CREATE_INVITE_CODE: '25207706598901440',
|
|
25
|
-
CREATE_GROUP: '32341779532133480',
|
|
26
|
-
ALLOW_NON_ADMIN_GROUP_CREATION: '32024438593867696',
|
|
27
|
-
GET_INVITE_INFO: '24745668928467084',
|
|
28
|
-
GET_PRE_REG_ADD_REQUESTS: '25018599251091280',
|
|
29
|
-
GET_SUGGESTED_CONTACTS: '27208468032086900',
|
|
30
|
-
STORE_INVITES_SMS: '25508574885415376',
|
|
31
|
-
LOG_SERVER_SENT_INVITE: '26580640204871220',
|
|
32
|
-
QUERY_ONLINE_STATUS: '24599444653063564',
|
|
33
|
-
QUERY_ONLINE_STATUS_LAST_SEEN: '24653084284365540'
|
|
12
|
+
QUERY_INFO: '25530136513328492',
|
|
13
|
+
QUERY_INFO_BY_CODE: '24576337542042464',
|
|
14
|
+
QUERY_BATCH: '26440064815661176',
|
|
15
|
+
QUERY_INVITE_LINK: '24558418350455204',
|
|
16
|
+
QUERY_PARTICIPATING: '26664341543184776',
|
|
17
|
+
QUERY_SUGGESTED: '26012055225051916',
|
|
18
|
+
QUERY_LINKED: '25629003043401452',
|
|
19
|
+
QUERY_SUBGROUPS: '25554052094203120',
|
|
20
|
+
ADD_PARTICIPANTS_V2: '32627550323510250',
|
|
21
|
+
ADD_PARTICIPANTS_V3: '26581073158212628',
|
|
22
|
+
SET_PROPERTY: '24688994337458820',
|
|
23
|
+
RESET_INVITE_LINK: '24812851838367452',
|
|
24
|
+
CREATE_INVITE_CODE: '25207706598901440',
|
|
25
|
+
CREATE_GROUP: '32341779532133480',
|
|
26
|
+
ALLOW_NON_ADMIN_GROUP_CREATION: '32024438593867696',
|
|
27
|
+
GET_INVITE_INFO: '24745668928467084',
|
|
28
|
+
GET_PRE_REG_ADD_REQUESTS: '25018599251091280',
|
|
29
|
+
GET_SUGGESTED_CONTACTS: '27208468032086900',
|
|
30
|
+
STORE_INVITES_SMS: '25508574885415376',
|
|
31
|
+
LOG_SERVER_SENT_INVITE: '26580640204871220',
|
|
32
|
+
QUERY_ONLINE_STATUS: '24599444653063564',
|
|
33
|
+
QUERY_ONLINE_STATUS_LAST_SEEN: '24653084284365540'
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
const makeGroupsSocket = config => {
|
|
@@ -46,25 +46,38 @@ const makeGroupsSocket = config => {
|
|
|
46
46
|
},
|
|
47
47
|
content
|
|
48
48
|
})
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
const persistParticipantLidMappings = async participantLists => {
|
|
53
|
+
const pairs = []
|
|
54
|
+
for (const participants of participantLists) {
|
|
55
|
+
for (const p of participants || []) {
|
|
56
|
+
if (p.phoneNumber) pairs.push({ lid: p.id, pn: p.phoneNumber })
|
|
57
|
+
else if (p.lid) pairs.push({ lid: p.lid, pn: p.id })
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (!pairs.length) return
|
|
61
|
+
try {
|
|
62
|
+
await sock.signalRepository.lidMapping.storeLIDPNMappings(pairs)
|
|
63
|
+
} catch (error) {
|
|
64
|
+
sock.logger?.warn?.({ error }, 'failed to store LID/PN mappings from group metadata')
|
|
65
|
+
}
|
|
66
|
+
}
|
|
49
67
|
|
|
50
68
|
const mexQuery = (variables, queryId, dataPath) =>
|
|
51
69
|
(0, mex_1.executeWMexQuery)(variables, queryId, dataPath, query, generateMessageTag)
|
|
52
70
|
const groupMetadata = async jid => {
|
|
53
71
|
const result = await groupQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }])
|
|
54
|
-
|
|
72
|
+
const metadata = (0, exports.extractGroupMetadata)(result)
|
|
73
|
+
persistParticipantLidMappings([metadata.participants]).catch(() => {})
|
|
74
|
+
return metadata
|
|
55
75
|
}
|
|
56
|
-
|
|
57
|
-
* Acknowledge a group. Ported from WhatsApp Web's WASmaxGroupsAcknowledgeGroupRPC
|
|
58
|
-
* (`<iq to=jid xmlns=w:g2 type=set><ack/></iq>`).
|
|
59
|
-
*/
|
|
76
|
+
|
|
60
77
|
const groupAcknowledge = async jid => {
|
|
61
78
|
await groupQuery(jid, 'set', [{ tag: 'ack', attrs: {} }])
|
|
62
79
|
}
|
|
63
|
-
|
|
64
|
-
* Get the participants of a community's linked/sub groups. Ported from
|
|
65
|
-
* WhatsApp Web's WASmaxGroupsGetLinkedGroupsParticipantsRPC.
|
|
66
|
-
* @returns {Promise<Array<{ jid: string, phoneNumber?: string }>>}
|
|
67
|
-
*/
|
|
80
|
+
|
|
68
81
|
const groupGetLinkedParticipants = async jid => {
|
|
69
82
|
const result = await groupQuery(jid, 'get', [{ tag: 'linked_groups_participants', attrs: {} }])
|
|
70
83
|
const node = (0, WABinary_1.getBinaryNodeChild)(result, 'linked_groups_participants')
|
|
@@ -73,26 +86,14 @@ const makeGroupsSocket = config => {
|
|
|
73
86
|
phoneNumber: p.attrs.phone_number || p.attrs.pn || undefined
|
|
74
87
|
}))
|
|
75
88
|
}
|
|
76
|
-
|
|
77
|
-
* Join a community's linked/sub group (may raise a membership approval request).
|
|
78
|
-
* Ported from WhatsApp Web's WASmaxGroupsJoinLinkedGroupRPC.
|
|
79
|
-
* @param {string} parentJid community/parent group to address
|
|
80
|
-
* @param {string} linkedGroupJid linked/sub group to join
|
|
81
|
-
* @param {string} [type]
|
|
82
|
-
*/
|
|
89
|
+
|
|
83
90
|
const groupJoinLinked = async (parentJid, linkedGroupJid, type) => {
|
|
84
91
|
const result = await groupQuery(parentJid, 'set', [
|
|
85
92
|
{ tag: 'join_linked_group', attrs: { jid: linkedGroupJid, ...(type ? { type } : {}) } }
|
|
86
93
|
])
|
|
87
94
|
return { approvalRequested: !!(0, WABinary_1.getBinaryNodeChild)(result, 'membership_approval_request') }
|
|
88
95
|
}
|
|
89
|
-
|
|
90
|
-
* Batch-fetch group profile pictures via w:g2. Ported from WhatsApp Web's
|
|
91
|
-
* WASmaxGroupsGetGroupProfilePicturesRPC. NOTE: untested against live WhatsApp —
|
|
92
|
-
* for a single group prefer profilePictureUrl().
|
|
93
|
-
* @param {string[]} jids group jids
|
|
94
|
-
* @param {'preview' | 'image'} [type]
|
|
95
|
-
*/
|
|
96
|
+
|
|
96
97
|
const getGroupProfilePictures = async (jids, type = 'preview') => {
|
|
97
98
|
const result = await groupQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
|
|
98
99
|
{
|
|
@@ -108,32 +109,26 @@ const makeGroupsSocket = config => {
|
|
|
108
109
|
url: pic.attrs.url
|
|
109
110
|
}))
|
|
110
111
|
}
|
|
111
|
-
|
|
112
|
-
* Create a sub-group suggestion for a community. Ported from WhatsApp Web's
|
|
113
|
-
* WASmaxGroupsCreateSubGroupSuggestionRPC. The suggestion body (new vs existing
|
|
114
|
-
* groups) is caller-provided. NOTE: untested against live WhatsApp.
|
|
115
|
-
* @param {string} parentJid community/parent group to address
|
|
116
|
-
* @param {Array<{ tag: string, attrs?: object, content?: any }>} suggestion child node(s)
|
|
117
|
-
*/
|
|
112
|
+
|
|
118
113
|
const groupCreateSubGroupSuggestion = async (parentJid, suggestion) => {
|
|
119
114
|
await groupQuery(parentJid, 'set', [{ tag: 'sub_group_suggestion', attrs: {}, content: suggestion }])
|
|
120
115
|
}
|
|
121
|
-
|
|
122
|
-
* Approve or reject sub-group suggestions for a community. Ported from WhatsApp
|
|
123
|
-
* Web's WASmaxGroupsSubGroupSuggestionsActionRPC. NOTE: untested against live WhatsApp.
|
|
124
|
-
* @param {string} parentJid community/parent group to address
|
|
125
|
-
* @param {'approve' | 'reject'} action
|
|
126
|
-
* @param {Array<{ creator: string, jid?: string }>} suggestions
|
|
127
|
-
*/
|
|
116
|
+
|
|
128
117
|
const groupSubGroupSuggestionsAction = async (parentJid, action, suggestions) => {
|
|
129
118
|
await groupQuery(parentJid, 'set', [
|
|
130
119
|
{
|
|
131
|
-
tag:
|
|
120
|
+
tag: 'sub_group_suggestions_action',
|
|
132
121
|
attrs: {},
|
|
133
|
-
content:
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
122
|
+
content: [
|
|
123
|
+
{
|
|
124
|
+
tag: action,
|
|
125
|
+
attrs: {},
|
|
126
|
+
content: suggestions.map(s => ({
|
|
127
|
+
tag: 'sub_group_suggestion',
|
|
128
|
+
attrs: action === 'cancel' ? { jid: s.jid } : { creator: s.creator }
|
|
129
|
+
}))
|
|
130
|
+
}
|
|
131
|
+
]
|
|
137
132
|
}
|
|
138
133
|
])
|
|
139
134
|
}
|
|
@@ -169,8 +164,9 @@ const makeGroupsSocket = config => {
|
|
|
169
164
|
data[meta.id] = meta
|
|
170
165
|
}
|
|
171
166
|
}
|
|
172
|
-
|
|
173
|
-
|
|
167
|
+
const allGroups = Object.values(data)
|
|
168
|
+
persistParticipantLidMappings(allGroups.map(g => g.participants)).catch(() => {})
|
|
169
|
+
sock.ev.emit('groups.update', allGroups)
|
|
174
170
|
return data
|
|
175
171
|
}
|
|
176
172
|
sock.ws.on('CB:ib,,dirty', async node => {
|
|
@@ -306,23 +302,14 @@ const makeGroupsSocket = config => {
|
|
|
306
302
|
const result = (0, WABinary_1.getBinaryNodeChild)(results, 'group')
|
|
307
303
|
return result?.attrs.jid
|
|
308
304
|
},
|
|
309
|
-
|
|
310
|
-
* revoke a v4 invite for someone
|
|
311
|
-
* @param groupJid group jid
|
|
312
|
-
* @param invitedJid jid of person you invited
|
|
313
|
-
* @returns true if successful
|
|
314
|
-
*/
|
|
305
|
+
|
|
315
306
|
groupRevokeInviteV4: async (groupJid, invitedJid) => {
|
|
316
307
|
const result = await groupQuery(groupJid, 'set', [
|
|
317
308
|
{ tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
|
|
318
309
|
])
|
|
319
310
|
return !!result
|
|
320
311
|
},
|
|
321
|
-
|
|
322
|
-
* accept a GroupInviteMessage
|
|
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
|
-
*/
|
|
312
|
+
|
|
326
313
|
groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
|
|
327
314
|
key = typeof key === 'string' ? { remoteJid: key } : key
|
|
328
315
|
const results = await groupQuery(inviteMessage.groupJid, 'set', [
|
|
@@ -335,10 +322,10 @@ const makeGroupsSocket = config => {
|
|
|
335
322
|
}
|
|
336
323
|
}
|
|
337
324
|
])
|
|
338
|
-
|
|
339
|
-
|
|
325
|
+
|
|
326
|
+
|
|
340
327
|
if (key.id) {
|
|
341
|
-
|
|
328
|
+
|
|
342
329
|
inviteMessage = index_js_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage)
|
|
343
330
|
inviteMessage.inviteExpiration = 0
|
|
344
331
|
inviteMessage.inviteCode = ''
|
|
@@ -353,7 +340,7 @@ const makeGroupsSocket = config => {
|
|
|
353
340
|
}
|
|
354
341
|
])
|
|
355
342
|
}
|
|
356
|
-
|
|
343
|
+
|
|
357
344
|
await upsertMessage(
|
|
358
345
|
{
|
|
359
346
|
key: {
|
|
@@ -392,9 +379,7 @@ const makeGroupsSocket = config => {
|
|
|
392
379
|
{ tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }
|
|
393
380
|
])
|
|
394
381
|
},
|
|
395
|
-
|
|
396
|
-
* Get past participants of a group (left/removed members)
|
|
397
|
-
*/
|
|
382
|
+
|
|
398
383
|
groupGetPastParticipants: async jid => {
|
|
399
384
|
const result = await groupQuery(jid, 'get', [{ tag: 'past_participants', attrs: {} }])
|
|
400
385
|
const node = (0, WABinary_1.getBinaryNodeChild)(result, 'past_participants')
|
|
@@ -406,23 +391,22 @@ const makeGroupsSocket = config => {
|
|
|
406
391
|
leaveTimestamp: p.attrs.t ? Number(p.attrs.t) : undefined
|
|
407
392
|
}))
|
|
408
393
|
},
|
|
409
|
-
|
|
410
|
-
* Create a subgroup within a community
|
|
411
|
-
*/
|
|
394
|
+
|
|
412
395
|
groupCreateSubgroup: async (communityJid, subject, participants = []) => {
|
|
413
396
|
const key = (0, Utils_1.generateMessageIDV2)()
|
|
414
397
|
const result = await groupQuery('@g.us', 'set', [
|
|
415
398
|
{
|
|
416
399
|
tag: 'create',
|
|
417
|
-
attrs: { subject, key
|
|
418
|
-
content:
|
|
400
|
+
attrs: { subject, key },
|
|
401
|
+
content: [
|
|
402
|
+
...participants.map(jid => ({ tag: 'participant', attrs: { jid } })),
|
|
403
|
+
{ tag: 'linked_parent', attrs: { jid: communityJid } }
|
|
404
|
+
]
|
|
419
405
|
}
|
|
420
406
|
])
|
|
421
407
|
return (0, exports.extractGroupMetadata)(result)
|
|
422
408
|
},
|
|
423
|
-
|
|
424
|
-
* Link an existing group to a community
|
|
425
|
-
*/
|
|
409
|
+
|
|
426
410
|
groupLinkToCommunity: async (communityJid, groupJid) => {
|
|
427
411
|
await groupQuery(communityJid, 'set', [
|
|
428
412
|
{
|
|
@@ -434,9 +418,7 @@ const makeGroupsSocket = config => {
|
|
|
434
418
|
}
|
|
435
419
|
])
|
|
436
420
|
},
|
|
437
|
-
|
|
438
|
-
* Unlink a group from a community
|
|
439
|
-
*/
|
|
421
|
+
|
|
440
422
|
groupUnlinkFromCommunity: async (communityJid, groupJid) => {
|
|
441
423
|
await groupQuery(communityJid, 'set', [
|
|
442
424
|
{
|
|
@@ -448,12 +430,7 @@ const makeGroupsSocket = config => {
|
|
|
448
430
|
}
|
|
449
431
|
])
|
|
450
432
|
},
|
|
451
|
-
|
|
452
|
-
* Set a member label/tag in a group
|
|
453
|
-
* @param jid group JID
|
|
454
|
-
* @param participantJid participant JID to label
|
|
455
|
-
* @param label the label string ('' to remove)
|
|
456
|
-
*/
|
|
433
|
+
|
|
457
434
|
groupSetMemberLabel: async (jid, participantJid, label) => {
|
|
458
435
|
await groupQuery(jid, 'set', [
|
|
459
436
|
{
|
|
@@ -468,9 +445,7 @@ const makeGroupsSocket = config => {
|
|
|
468
445
|
}
|
|
469
446
|
])
|
|
470
447
|
},
|
|
471
|
-
|
|
472
|
-
* Get community-linked subgroups for a community JID
|
|
473
|
-
*/
|
|
448
|
+
|
|
474
449
|
groupGetLinkedSubgroups: async communityJid => {
|
|
475
450
|
const result = await groupQuery(communityJid, 'get', [{ tag: 'links', attrs: { link_type: 'sub_group' } }])
|
|
476
451
|
const linksNode = (0, WABinary_1.getBinaryNodeChild)(result, 'links')
|
|
@@ -484,26 +459,20 @@ const makeGroupsSocket = config => {
|
|
|
484
459
|
},
|
|
485
460
|
groupFetchAllParticipating,
|
|
486
461
|
|
|
487
|
-
|
|
462
|
+
|
|
488
463
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
* @param {string} jid - Group JID
|
|
492
|
-
*/
|
|
493
|
-
groupQueryInfo: jid =>
|
|
494
|
-
mexQuery({ group_id: jid }, GROUP_MEX_QUERY_IDS.QUERY_INFO, 'xwa2_group_query_by_id'),
|
|
464
|
+
|
|
465
|
+
groupQueryInfo: jid => mexQuery({ group_id: jid }, GROUP_MEX_QUERY_IDS.QUERY_INFO, 'xwa2_group_query_by_id'),
|
|
495
466
|
|
|
496
|
-
|
|
497
|
-
* Fetch group info by invite code via MEX.
|
|
498
|
-
* @param {string} code - Group invite code (without the link prefix)
|
|
499
|
-
*/
|
|
467
|
+
|
|
500
468
|
groupQueryInfoByCode: code =>
|
|
501
|
-
mexQuery(
|
|
469
|
+
mexQuery(
|
|
470
|
+
{ group_input: { invite_code: code } },
|
|
471
|
+
GROUP_MEX_QUERY_IDS.QUERY_INFO_BY_CODE,
|
|
472
|
+
'xwa2_group_query_by_id'
|
|
473
|
+
),
|
|
502
474
|
|
|
503
|
-
|
|
504
|
-
* Fetch multiple groups at once via MEX.
|
|
505
|
-
* @param {string[]} jids - Array of group JIDs
|
|
506
|
-
*/
|
|
475
|
+
|
|
507
476
|
groupQueryBatch: jids =>
|
|
508
477
|
mexQuery(
|
|
509
478
|
{ groups_input: jids.map(group_id => ({ group_id })) },
|
|
@@ -511,24 +480,15 @@ const makeGroupsSocket = config => {
|
|
|
511
480
|
'xwa2_group_query_batch'
|
|
512
481
|
),
|
|
513
482
|
|
|
514
|
-
|
|
515
|
-
* Fetch invite link info via MEX (includes expiration, creator, etc.)
|
|
516
|
-
* @param {string} jid - Group JID
|
|
517
|
-
*/
|
|
483
|
+
|
|
518
484
|
groupQueryInviteLink: jid =>
|
|
519
485
|
mexQuery({ group_input: { group_id: jid } }, GROUP_MEX_QUERY_IDS.QUERY_INVITE_LINK, 'xwa2_group_query_by_id'),
|
|
520
486
|
|
|
521
|
-
|
|
522
|
-
* Fetch all groups the current user is participating in via MEX.
|
|
523
|
-
* Returns richer data than the IQ-based groupFetchAllParticipating.
|
|
524
|
-
*/
|
|
487
|
+
|
|
525
488
|
groupQueryParticipating: () =>
|
|
526
489
|
mexQuery({}, GROUP_MEX_QUERY_IDS.QUERY_PARTICIPATING, 'xwa2_group_query_participating'),
|
|
527
490
|
|
|
528
|
-
|
|
529
|
-
* Fetch suggested groups (community sub-group suggestions) via MEX.
|
|
530
|
-
* @param {string} communityJid - Community JID to get suggestions for
|
|
531
|
-
*/
|
|
491
|
+
|
|
532
492
|
groupQuerySuggested: communityJid =>
|
|
533
493
|
mexQuery(
|
|
534
494
|
{ group_input: { group_id: communityJid } },
|
|
@@ -536,17 +496,11 @@ const makeGroupsSocket = config => {
|
|
|
536
496
|
'xwa2_group_query_by_id'
|
|
537
497
|
),
|
|
538
498
|
|
|
539
|
-
|
|
540
|
-
* Fetch linked subgroup info for a community group via MEX.
|
|
541
|
-
* @param {string} jid - Group or community JID
|
|
542
|
-
*/
|
|
499
|
+
|
|
543
500
|
groupQueryLinked: jid =>
|
|
544
501
|
mexQuery({ group_input: { group_id: jid } }, GROUP_MEX_QUERY_IDS.QUERY_LINKED, 'xwa2_group_query_by_id'),
|
|
545
502
|
|
|
546
|
-
|
|
547
|
-
* Fetch subgroups of a community via MEX.
|
|
548
|
-
* @param {string} communityJid - Community JID
|
|
549
|
-
*/
|
|
503
|
+
|
|
550
504
|
groupQuerySubgroups: communityJid =>
|
|
551
505
|
mexQuery(
|
|
552
506
|
{ group_input: { group_id: communityJid } },
|
|
@@ -554,12 +508,7 @@ const makeGroupsSocket = config => {
|
|
|
554
508
|
'xwa2_group_query_by_id'
|
|
555
509
|
),
|
|
556
510
|
|
|
557
|
-
|
|
558
|
-
* Add participants to a group via MEX (V2 — supports LID, privacy metadata).
|
|
559
|
-
* Falls back to the IQ-based groupParticipantsUpdate for older servers.
|
|
560
|
-
* @param {string} jid - Group JID
|
|
561
|
-
* @param {string[]} participants - Array of JIDs to add
|
|
562
|
-
*/
|
|
511
|
+
|
|
563
512
|
groupAddParticipantsMex: (jid, participants) =>
|
|
564
513
|
mexQuery(
|
|
565
514
|
{ group_id: jid, participants: participants.map(p => ({ user_jid: p })) },
|
|
@@ -567,29 +516,15 @@ const makeGroupsSocket = config => {
|
|
|
567
516
|
'xwa2_group_add_participants'
|
|
568
517
|
),
|
|
569
518
|
|
|
570
|
-
|
|
571
|
-
* Set a group property via MEX.
|
|
572
|
-
* Known properties: member_add_mode, membership_approval_mode_enabled, member_share_group_history_mode
|
|
573
|
-
* @param {string} jid - Group JID
|
|
574
|
-
* @param {string} property - Property name
|
|
575
|
-
* @param {*} value - Property value
|
|
576
|
-
*/
|
|
519
|
+
|
|
577
520
|
groupSetProperty: (jid, property, value) =>
|
|
578
|
-
mexQuery({ group_id: jid, [property]: value }, GROUP_MEX_QUERY_IDS.SET_PROPERTY, '
|
|
521
|
+
mexQuery({ group_id: jid, [property]: value }, GROUP_MEX_QUERY_IDS.SET_PROPERTY, 'xwa2_group_update_property'),
|
|
579
522
|
|
|
580
|
-
|
|
581
|
-
* Reset a group's invite link via MEX (generates new code, invalidates old one).
|
|
582
|
-
* @param {string} jid - Group JID
|
|
583
|
-
*/
|
|
523
|
+
|
|
584
524
|
groupResetInviteLinkMex: jid =>
|
|
585
525
|
mexQuery({ group_jid: jid }, GROUP_MEX_QUERY_IDS.RESET_INVITE_LINK, 'xwa2_group_reset_invite_link'),
|
|
586
526
|
|
|
587
|
-
|
|
588
|
-
* Create a group via MEX.
|
|
589
|
-
* Confirmed from CreateGroup mutation — input: { subject, participants: [{jid}] }
|
|
590
|
-
* @param {string} subject - Group name
|
|
591
|
-
* @param {string[]} participantJids
|
|
592
|
-
*/
|
|
527
|
+
|
|
593
528
|
groupCreateMex: (subject, participantJids) =>
|
|
594
529
|
mexQuery(
|
|
595
530
|
{ input: { subject, participants: participantJids.map(jid => ({ jid })) } },
|
|
@@ -597,11 +532,7 @@ const makeGroupsSocket = config => {
|
|
|
597
532
|
'xwa2_group_create'
|
|
598
533
|
),
|
|
599
534
|
|
|
600
|
-
|
|
601
|
-
* Allow non-admin community members to create subgroups.
|
|
602
|
-
* @param {string} communityJid - Community JID
|
|
603
|
-
* @param {boolean} allow
|
|
604
|
-
*/
|
|
535
|
+
|
|
605
536
|
groupAllowNonAdminCreation: (communityJid, allow) =>
|
|
606
537
|
mexQuery(
|
|
607
538
|
{ group_jid: communityJid, allow_non_admin_sub_group_creation: allow },
|
|
@@ -609,32 +540,19 @@ const makeGroupsSocket = config => {
|
|
|
609
540
|
'xwa2_group_allow_non_admin_creation'
|
|
610
541
|
),
|
|
611
542
|
|
|
612
|
-
|
|
613
|
-
* Get info about a group invite link (before joining).
|
|
614
|
-
* @param {string} inviteCode - The raw invite code (not full URL)
|
|
615
|
-
*/
|
|
543
|
+
|
|
616
544
|
groupGetInviteInfo: inviteCode =>
|
|
617
545
|
mexQuery({ invite_code: inviteCode }, GROUP_MEX_QUERY_IDS.GET_INVITE_INFO, 'xwa2_group_get_invite_info'),
|
|
618
546
|
|
|
619
|
-
|
|
620
|
-
* Fetch pending add requests for pre-registration group invites.
|
|
621
|
-
* @param {string} jid - Group JID
|
|
622
|
-
*/
|
|
547
|
+
|
|
623
548
|
groupPreRegAddRequests: jid =>
|
|
624
549
|
mexQuery({ group_jid: jid }, GROUP_MEX_QUERY_IDS.GET_PRE_REG_ADD_REQUESTS, 'xwa2_group_pre_reg_add_requests'),
|
|
625
550
|
|
|
626
|
-
|
|
627
|
-
* Get suggested contacts to add to a group.
|
|
628
|
-
* @param {string} jid - Group JID
|
|
629
|
-
*/
|
|
551
|
+
|
|
630
552
|
groupSuggestedContacts: jid =>
|
|
631
553
|
mexQuery({ group_jid: jid }, GROUP_MEX_QUERY_IDS.GET_SUGGESTED_CONTACTS, 'xwa2_group_suggested_contacts'),
|
|
632
554
|
|
|
633
|
-
|
|
634
|
-
* Store SMS invite links for a group.
|
|
635
|
-
* @param {string} jid - Group JID
|
|
636
|
-
* @param {{ phone: string, inviteCode: string }[]} invites
|
|
637
|
-
*/
|
|
555
|
+
|
|
638
556
|
groupStoreInvitesSms: (jid, invites) =>
|
|
639
557
|
mexQuery(
|
|
640
558
|
{ group_jid: jid, invites: invites.map(({ phone, inviteCode }) => ({ phone, invite_code: inviteCode })) },
|
|
@@ -642,11 +560,7 @@ const makeGroupsSocket = config => {
|
|
|
642
560
|
'xwa2_group_store_invites_sms'
|
|
643
561
|
),
|
|
644
562
|
|
|
645
|
-
|
|
646
|
-
* Log a server-sent invite intent (analytics).
|
|
647
|
-
* @param {string} jid - Group JID
|
|
648
|
-
* @param {string} inviteCode
|
|
649
|
-
*/
|
|
563
|
+
|
|
650
564
|
groupLogServerSentInvite: (jid, inviteCode) =>
|
|
651
565
|
mexQuery(
|
|
652
566
|
{ group_jid: jid, invite_code: inviteCode },
|
|
@@ -654,17 +568,10 @@ const makeGroupsSocket = config => {
|
|
|
654
568
|
'xwa2_group_log_server_sent_invite'
|
|
655
569
|
),
|
|
656
570
|
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
* @param {string[]} jids - User JIDs
|
|
660
|
-
*/
|
|
661
|
-
queryOnlineStatus: jids =>
|
|
662
|
-
mexQuery({ jids }, GROUP_MEX_QUERY_IDS.QUERY_ONLINE_STATUS, 'xwa2_query_online_status'),
|
|
571
|
+
|
|
572
|
+
queryOnlineStatus: jids => mexQuery({ jids }, GROUP_MEX_QUERY_IDS.QUERY_ONLINE_STATUS, 'xwa2_query_online_status'),
|
|
663
573
|
|
|
664
|
-
|
|
665
|
-
* Query online status and last seen of users from PDP.
|
|
666
|
-
* @param {string[]} jids - User JIDs
|
|
667
|
-
*/
|
|
574
|
+
|
|
668
575
|
queryOnlineStatusLastSeen: jids =>
|
|
669
576
|
mexQuery({ jids }, GROUP_MEX_QUERY_IDS.QUERY_ONLINE_STATUS_LAST_SEEN, 'xwa2_query_online_status_last_seen'),
|
|
670
577
|
|
|
@@ -698,6 +605,11 @@ const extractGroupMetadata = result => {
|
|
|
698
605
|
const communityMemberAddGroupNode = (0, WABinary_1.getBinaryNodeChild)(group, 'allow_non_admin_sub_group_creation')
|
|
699
606
|
const subGroupVisibilityNode = (0, WABinary_1.getBinaryNodeChild)(group, 'sub_groups_list')
|
|
700
607
|
const membershipApprovalNode = (0, WABinary_1.getBinaryNodeChild)(group, 'membership_approval_mode')
|
|
608
|
+
const capiNode = (0, WABinary_1.getBinaryNodeChild)(group, 'capi')
|
|
609
|
+
const appealStatusNode = (0, WABinary_1.getBinaryNodeChild)(group, 'appeal_status')
|
|
610
|
+
const defaultSubGroupNode = (0, WABinary_1.getBinaryNodeChild)(group, 'default_sub_group')
|
|
611
|
+
const generalChatNode = (0, WABinary_1.getBinaryNodeChild)(group, 'general_chat')
|
|
612
|
+
const hiddenGroupNode = (0, WABinary_1.getBinaryNodeChild)(group, 'hidden_group')
|
|
701
613
|
const metadata = {
|
|
702
614
|
id: groupId,
|
|
703
615
|
notify: group.attrs.notify,
|
|
@@ -727,15 +639,23 @@ const extractGroupMetadata = result => {
|
|
|
727
639
|
isCommunityAnnounce: !!(0, WABinary_1.getBinaryNodeChild)(group, 'default_sub_group'),
|
|
728
640
|
joinApprovalMode: !!membershipApprovalNode,
|
|
729
641
|
memberAddMode,
|
|
730
|
-
memberShareHistoryMode:
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
642
|
+
memberShareHistoryMode:
|
|
643
|
+
(0, WABinary_1.getBinaryNodeChildString)(group, 'member_share_group_history_mode') || undefined,
|
|
644
|
+
memberLinkMode: (0, WABinary_1.getBinaryNodeChildString)(group, 'member_link_mode') || undefined,
|
|
645
|
+
limitSharing: !!(0, WABinary_1.getBinaryNodeChild)(group, 'limit_sharing_enabled'),
|
|
646
|
+
communityMemberAddGroupMode: communityMemberAddGroupNode?.attrs.state || undefined,
|
|
647
|
+
capiCreatedGroup: !!capiNode || undefined,
|
|
648
|
+
appealStatus: appealStatusNode?.attrs.type || undefined,
|
|
736
649
|
isSubGroupHidden: group.attrs.sub_group_visibility === 'hidden' || undefined,
|
|
650
|
+
membershipApprovalMode: group.attrs.membership_approval_mode || undefined,
|
|
651
|
+
joinPermissions: group.attrs.join_permissions || undefined,
|
|
652
|
+
isDefaultSubgroup: !!defaultSubGroupNode || undefined,
|
|
653
|
+
isGeneralSubgroup: !!generalChatNode || undefined,
|
|
654
|
+
isHiddenSubgroup: !!hiddenGroupNode || undefined,
|
|
737
655
|
participants: (0, WABinary_1.getBinaryNodeChildren)(group, 'participant').map(({ attrs }) => {
|
|
738
|
-
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
|
|
739
659
|
return {
|
|
740
660
|
id: attrs.jid,
|
|
741
661
|
phoneNumber:
|
|
@@ -747,11 +667,12 @@ const extractGroupMetadata = result => {
|
|
|
747
667
|
admin: attrs.type || null,
|
|
748
668
|
memberLabel: attrs.label || undefined,
|
|
749
669
|
memberLabelTimestamp: attrs.label_ts ? +attrs.label_ts : undefined,
|
|
750
|
-
isBanned: attrs.error === '
|
|
670
|
+
isBanned: attrs.error === '402' || attrs.ban === 'true' || undefined,
|
|
671
|
+
uuid: attrs.uuid || attrs.participant_uuid || undefined
|
|
751
672
|
}
|
|
752
673
|
}),
|
|
753
674
|
bannedParticipants: (0, WABinary_1.getBinaryNodeChildren)(group, 'participant')
|
|
754
|
-
.filter(({ attrs }) => attrs.error === '
|
|
675
|
+
.filter(({ attrs }) => attrs.error === '402' || attrs.ban === 'true')
|
|
755
676
|
.map(({ attrs }) => ({
|
|
756
677
|
id: attrs.jid,
|
|
757
678
|
phoneNumber: attrs.phone_number || undefined,
|
package/lib/Socket/index.js
CHANGED
|
@@ -7,11 +7,10 @@ const { makePrivacySocket } = require('./privacy')
|
|
|
7
7
|
const { makeRegistrationSocket } = require('./registration')
|
|
8
8
|
const { makeManagedAccountSocket } = require('./managed-account')
|
|
9
9
|
const { makeGraphQLSocket } = require('./graphql')
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
const { wrapSocket: _wrapSocket } = require('../antiban')
|
|
12
|
-
const { attachTextRouter } = require('./text-router')
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
|
|
15
14
|
const makeWASocket = config => {
|
|
16
15
|
const userExplicitSyncFlag = typeof config?.syncFullHistory === 'boolean'
|
|
17
16
|
const initialFullSyncDone = !!config?.auth?.creds?.initialFullSyncDone
|
|
@@ -31,9 +30,12 @@ const makeWASocket = config => {
|
|
|
31
30
|
const registrationSock = makeRegistrationSocket(privacySock)
|
|
32
31
|
const managedSock = makeManagedAccountSocket(registrationSock)
|
|
33
32
|
const sock = makeGraphQLSocket(managedSock)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
if (_wrapSocket && config?.antiban !== false) {
|
|
36
|
+
const antibanConfig = config?.antiban || 'aggressive'
|
|
37
|
+
return _wrapSocket(sock, antibanConfig)
|
|
38
|
+
}
|
|
39
|
+
return sock
|
|
38
40
|
}
|
|
39
41
|
exports.default = makeWASocket
|