@badzz88/baileys 8.5.7 → 8.5.9
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 +337 -1055
- package/WAProto/WAProto.proto +284 -264
- package/WAProto/index.js +5 -5
- package/engine-requirements.js +7 -15
- package/lib/Defaults/index.js +130 -187
- package/lib/Signal/Group/ciphertext-message.js +11 -14
- package/lib/Signal/Group/group-session-builder.js +29 -91
- package/lib/Signal/Group/group_cipher.js +81 -88
- package/lib/Signal/Group/index.js +12 -136
- package/lib/Signal/Group/keyhelper.js +15 -70
- package/lib/Signal/Group/sender-chain-key.js +25 -31
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -65
- package/lib/Signal/Group/sender-key-message.js +65 -68
- package/lib/Signal/Group/sender-key-name.js +41 -43
- package/lib/Signal/Group/sender-key-record.js +40 -43
- package/lib/Signal/Group/sender-key-state.js +83 -96
- package/lib/Signal/Group/sender-message-key.js +25 -29
- package/lib/Signal/libsignal.js +425 -453
- package/lib/Signal/lid-mapping.js +276 -259
- package/lib/Socket/Client/index.js +3 -30
- package/lib/Socket/Client/types.js +10 -12
- package/lib/Socket/Client/websocket.js +53 -61
- package/lib/Socket/business.js +379 -422
- package/lib/Socket/chats.js +1193 -1816
- package/lib/Socket/communities.js +431 -549
- package/lib/Socket/graphql.js +672 -612
- package/lib/Socket/groups.js +374 -764
- package/lib/Socket/index.js +17 -38
- package/lib/Socket/interop.js +417 -503
- package/lib/Socket/messages-recv.js +1915 -2441
- package/lib/Socket/messages-send.js +1213 -1630
- package/lib/Socket/mex.js +9 -15
- package/lib/Socket/newsletter.js +746 -808
- package/lib/Socket/privacy.js +310 -441
- package/lib/Socket/socket.js +1025 -1022
- package/lib/Socket/username.js +8 -15
- package/lib/Store/index.js +10 -36
- package/lib/Store/make-cache-manager-store.js +80 -85
- package/lib/Store/make-in-memory-store.js +231 -591
- package/lib/Store/make-ordered-dictionary.js +72 -78
- package/lib/Store/object-repository.js +28 -25
- package/lib/Types/Auth.js +2 -38
- package/lib/Types/Bussines.js +2 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.js +8 -4
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.js +24 -26
- package/lib/Types/LabelAssociation.js +6 -8
- package/lib/Types/Message.js +11 -95
- package/lib/Types/Mex.js +111 -112
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.js +3 -2
- package/lib/Types/State.js +56 -70
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.js +26 -55
- package/lib/Utils/auth-utils.js +288 -292
- package/lib/Utils/browser-utils.js +47 -113
- package/lib/Utils/business.js +224 -240
- package/lib/Utils/chat-utils.js +869 -1205
- package/lib/Utils/companion-reg-client-utils.js +34 -41
- package/lib/Utils/crypto.js +107 -144
- package/lib/Utils/decode-wa-message.js +308 -518
- package/lib/Utils/event-buffer.js +611 -596
- package/lib/Utils/generics.js +355 -515
- package/lib/Utils/history.js +134 -244
- package/lib/Utils/identity-change-handler.js +49 -51
- package/lib/Utils/index.js +23 -57
- package/lib/Utils/link-preview.js +77 -135
- package/lib/Utils/logger.js +3 -9
- package/lib/Utils/lt-hash.js +6 -37
- package/lib/Utils/make-mutex.js +33 -36
- package/lib/Utils/message-composer.js +233 -439
- package/lib/Utils/message-retry-manager.js +260 -265
- package/lib/Utils/messages-media.js +829 -855
- package/lib/Utils/messages.js +961 -2528
- package/lib/Utils/noise-handler.js +200 -195
- package/lib/Utils/offline-node-processor.js +33 -35
- package/lib/Utils/pre-key-manager.js +102 -103
- package/lib/Utils/process-message.js +560 -978
- package/lib/Utils/reporting-utils.js +253 -257
- package/lib/Utils/signal.js +195 -218
- package/lib/Utils/stanza-ack.js +29 -31
- package/lib/Utils/sticker.js +109 -144
- package/lib/Utils/sync-action-utils.js +45 -50
- package/lib/Utils/tc-token-utils.js +139 -137
- package/lib/Utils/use-multi-file-auth-state.js +109 -109
- package/lib/Utils/validate-connection.js +202 -218
- package/lib/WABinary/constants.js +1299 -1302
- package/lib/WABinary/decode.js +262 -343
- package/lib/WABinary/encode.js +4 -12
- package/lib/WABinary/generic-utils.js +187 -223
- package/lib/WABinary/index.js +6 -33
- package/lib/WABinary/jid-utils.js +88 -351
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +9 -12
- package/lib/WAM/constants.js +22853 -39486
- package/lib/WAM/encode.js +140 -132
- package/lib/WAM/index.js +4 -31
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +21 -23
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +9 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +7 -7
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +10 -10
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +7 -7
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +11 -12
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +4 -5
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +7 -7
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +7 -8
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -7
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +8 -8
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +7 -7
- package/lib/WAUSync/Protocols/index.js +12 -39
- package/lib/WAUSync/USyncQuery.js +67 -49
- package/lib/WAUSync/USyncUser.js +11 -5
- package/lib/WAUSync/index.js +3 -31
- package/lib/index.js +15 -48
- package/package.json +129 -99
- package/LICENSE +0 -21
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Socket/aigroups.js +0 -240
- package/lib/Socket/interactive-handler.js +0 -522
- package/lib/Socket/managed-account.js +0 -183
- package/lib/Socket/registration.js +0 -427
- package/lib/Socket/text-router.js +0 -83
- package/lib/Types/Newsletter.js +0 -121
- package/lib/Utils/command-loader.d.ts +0 -31
- package/lib/Utils/command-loader.js +0 -100
- package/lib/Utils/consumer-application.js +0 -107
- package/lib/Utils/curve25519-js.js +0 -275
- package/lib/Utils/group-history.js +0 -60
- package/lib/Utils/jid-display-normalization.js +0 -218
- package/lib/Utils/meta-ai-msmsg.js +0 -262
- 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/view-once-cache.d.ts +0 -9
- package/lib/Utils/view-once-cache.js +0 -79
- package/lib/Utils/voip-rekey.js +0 -22
- package/lib/antiban.js +0 -4637
package/lib/Socket/groups.js
CHANGED
|
@@ -1,764 +1,374 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
const results = await groupQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }])
|
|
376
|
-
return (0, exports.extractGroupMetadata)(results)
|
|
377
|
-
},
|
|
378
|
-
groupToggleEphemeral: async (jid, ephemeralExpiration) => {
|
|
379
|
-
const content = ephemeralExpiration
|
|
380
|
-
? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
|
|
381
|
-
: { tag: 'not_ephemeral', attrs: {} }
|
|
382
|
-
await groupQuery(jid, 'set', [content])
|
|
383
|
-
},
|
|
384
|
-
groupSettingUpdate: async (jid, setting) => {
|
|
385
|
-
await groupQuery(jid, 'set', [{ tag: setting, attrs: {} }])
|
|
386
|
-
},
|
|
387
|
-
groupMemberAddMode: async (jid, mode) => {
|
|
388
|
-
await groupQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }])
|
|
389
|
-
},
|
|
390
|
-
groupJoinApprovalMode: async (jid, mode) => {
|
|
391
|
-
await groupQuery(jid, 'set', [
|
|
392
|
-
{ tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }
|
|
393
|
-
])
|
|
394
|
-
},
|
|
395
|
-
/**
|
|
396
|
-
* Get past participants of a group (left/removed members)
|
|
397
|
-
*/
|
|
398
|
-
groupGetPastParticipants: async jid => {
|
|
399
|
-
const result = await groupQuery(jid, 'get', [{ tag: 'past_participants', attrs: {} }])
|
|
400
|
-
const node = (0, WABinary_1.getBinaryNodeChild)(result, 'past_participants')
|
|
401
|
-
if (!node) return []
|
|
402
|
-
const participants = (0, WABinary_1.getBinaryNodeChildren)(node, 'past_participant')
|
|
403
|
-
return participants.map(p => ({
|
|
404
|
-
jid: p.attrs.jid,
|
|
405
|
-
leaveReason: p.attrs.reason,
|
|
406
|
-
leaveTimestamp: p.attrs.t ? Number(p.attrs.t) : undefined
|
|
407
|
-
}))
|
|
408
|
-
},
|
|
409
|
-
/**
|
|
410
|
-
* Create a subgroup within a community
|
|
411
|
-
*/
|
|
412
|
-
groupCreateSubgroup: async (communityJid, subject, participants = []) => {
|
|
413
|
-
const key = (0, Utils_1.generateMessageIDV2)()
|
|
414
|
-
const result = await groupQuery('@g.us', 'set', [
|
|
415
|
-
{
|
|
416
|
-
tag: 'create',
|
|
417
|
-
attrs: { subject, key, parent_group_id: communityJid },
|
|
418
|
-
content: participants.map(jid => ({ tag: 'participant', attrs: { jid } }))
|
|
419
|
-
}
|
|
420
|
-
])
|
|
421
|
-
return (0, exports.extractGroupMetadata)(result)
|
|
422
|
-
},
|
|
423
|
-
/**
|
|
424
|
-
* Link an existing group to a community
|
|
425
|
-
*/
|
|
426
|
-
groupLinkToCommunity: async (communityJid, groupJid) => {
|
|
427
|
-
await groupQuery(communityJid, 'set', [
|
|
428
|
-
{
|
|
429
|
-
tag: 'links',
|
|
430
|
-
attrs: {},
|
|
431
|
-
content: [
|
|
432
|
-
{ tag: 'link', attrs: { link_type: 'sub_group' }, content: [{ tag: 'group', attrs: { jid: groupJid } }] }
|
|
433
|
-
]
|
|
434
|
-
}
|
|
435
|
-
])
|
|
436
|
-
},
|
|
437
|
-
/**
|
|
438
|
-
* Unlink a group from a community
|
|
439
|
-
*/
|
|
440
|
-
groupUnlinkFromCommunity: async (communityJid, groupJid) => {
|
|
441
|
-
await groupQuery(communityJid, 'set', [
|
|
442
|
-
{
|
|
443
|
-
tag: 'unlinks',
|
|
444
|
-
attrs: {},
|
|
445
|
-
content: [
|
|
446
|
-
{ tag: 'unlink', attrs: { link_type: 'sub_group' }, content: [{ tag: 'group', attrs: { jid: groupJid } }] }
|
|
447
|
-
]
|
|
448
|
-
}
|
|
449
|
-
])
|
|
450
|
-
},
|
|
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
|
-
*/
|
|
457
|
-
groupSetMemberLabel: async (jid, participantJid, label) => {
|
|
458
|
-
await groupQuery(jid, 'set', [
|
|
459
|
-
{
|
|
460
|
-
tag: 'member_add_mode',
|
|
461
|
-
attrs: {},
|
|
462
|
-
content: [
|
|
463
|
-
{
|
|
464
|
-
tag: 'participant',
|
|
465
|
-
attrs: { jid: participantJid, label: label || '' }
|
|
466
|
-
}
|
|
467
|
-
]
|
|
468
|
-
}
|
|
469
|
-
])
|
|
470
|
-
},
|
|
471
|
-
/**
|
|
472
|
-
* Get community-linked subgroups for a community JID
|
|
473
|
-
*/
|
|
474
|
-
groupGetLinkedSubgroups: async communityJid => {
|
|
475
|
-
const result = await groupQuery(communityJid, 'get', [{ tag: 'links', attrs: { link_type: 'sub_group' } }])
|
|
476
|
-
const linksNode = (0, WABinary_1.getBinaryNodeChild)(result, 'links')
|
|
477
|
-
if (!linksNode) return []
|
|
478
|
-
return (0, WABinary_1.getBinaryNodeChildren)(linksNode, 'link')
|
|
479
|
-
.map(link => {
|
|
480
|
-
const group = (0, WABinary_1.getBinaryNodeChild)(link, 'group')
|
|
481
|
-
return { jid: group?.attrs?.jid, linkType: link.attrs?.link_type }
|
|
482
|
-
})
|
|
483
|
-
.filter(l => !!l.jid)
|
|
484
|
-
},
|
|
485
|
-
groupFetchAllParticipating,
|
|
486
|
-
|
|
487
|
-
// ── MEX queries (JSON responses) ──────────────────────────────────────
|
|
488
|
-
|
|
489
|
-
/**
|
|
490
|
-
* Fetch group info via MEX (richer than IQ — includes invite link, LID addressing, etc.)
|
|
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'),
|
|
495
|
-
|
|
496
|
-
/**
|
|
497
|
-
* Fetch group info by invite code via MEX.
|
|
498
|
-
* @param {string} code - Group invite code (without the link prefix)
|
|
499
|
-
*/
|
|
500
|
-
groupQueryInfoByCode: code =>
|
|
501
|
-
mexQuery({ group_input: { invite_code: code } }, GROUP_MEX_QUERY_IDS.QUERY_INFO_BY_CODE, 'xwa2_group_query_by_id'),
|
|
502
|
-
|
|
503
|
-
/**
|
|
504
|
-
* Fetch multiple groups at once via MEX.
|
|
505
|
-
* @param {string[]} jids - Array of group JIDs
|
|
506
|
-
*/
|
|
507
|
-
groupQueryBatch: jids =>
|
|
508
|
-
mexQuery(
|
|
509
|
-
{ groups_input: jids.map(group_id => ({ group_id })) },
|
|
510
|
-
GROUP_MEX_QUERY_IDS.QUERY_BATCH,
|
|
511
|
-
'xwa2_group_query_batch'
|
|
512
|
-
),
|
|
513
|
-
|
|
514
|
-
/**
|
|
515
|
-
* Fetch invite link info via MEX (includes expiration, creator, etc.)
|
|
516
|
-
* @param {string} jid - Group JID
|
|
517
|
-
*/
|
|
518
|
-
groupQueryInviteLink: jid =>
|
|
519
|
-
mexQuery({ group_input: { group_id: jid } }, GROUP_MEX_QUERY_IDS.QUERY_INVITE_LINK, 'xwa2_group_query_by_id'),
|
|
520
|
-
|
|
521
|
-
/**
|
|
522
|
-
* Fetch all groups the current user is participating in via MEX.
|
|
523
|
-
* Returns richer data than the IQ-based groupFetchAllParticipating.
|
|
524
|
-
*/
|
|
525
|
-
groupQueryParticipating: () =>
|
|
526
|
-
mexQuery({}, GROUP_MEX_QUERY_IDS.QUERY_PARTICIPATING, 'xwa2_group_query_participating'),
|
|
527
|
-
|
|
528
|
-
/**
|
|
529
|
-
* Fetch suggested groups (community sub-group suggestions) via MEX.
|
|
530
|
-
* @param {string} communityJid - Community JID to get suggestions for
|
|
531
|
-
*/
|
|
532
|
-
groupQuerySuggested: communityJid =>
|
|
533
|
-
mexQuery(
|
|
534
|
-
{ group_input: { group_id: communityJid } },
|
|
535
|
-
GROUP_MEX_QUERY_IDS.QUERY_SUGGESTED,
|
|
536
|
-
'xwa2_group_query_by_id'
|
|
537
|
-
),
|
|
538
|
-
|
|
539
|
-
/**
|
|
540
|
-
* Fetch linked subgroup info for a community group via MEX.
|
|
541
|
-
* @param {string} jid - Group or community JID
|
|
542
|
-
*/
|
|
543
|
-
groupQueryLinked: jid =>
|
|
544
|
-
mexQuery({ group_input: { group_id: jid } }, GROUP_MEX_QUERY_IDS.QUERY_LINKED, 'xwa2_group_query_by_id'),
|
|
545
|
-
|
|
546
|
-
/**
|
|
547
|
-
* Fetch subgroups of a community via MEX.
|
|
548
|
-
* @param {string} communityJid - Community JID
|
|
549
|
-
*/
|
|
550
|
-
groupQuerySubgroups: communityJid =>
|
|
551
|
-
mexQuery(
|
|
552
|
-
{ group_input: { group_id: communityJid } },
|
|
553
|
-
GROUP_MEX_QUERY_IDS.QUERY_SUBGROUPS,
|
|
554
|
-
'xwa2_group_query_by_id'
|
|
555
|
-
),
|
|
556
|
-
|
|
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
|
-
*/
|
|
563
|
-
groupAddParticipantsMex: (jid, participants) =>
|
|
564
|
-
mexQuery(
|
|
565
|
-
{ group_id: jid, participants: participants.map(p => ({ user_jid: p })) },
|
|
566
|
-
GROUP_MEX_QUERY_IDS.ADD_PARTICIPANTS_V2,
|
|
567
|
-
'xwa2_group_add_participants'
|
|
568
|
-
),
|
|
569
|
-
|
|
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
|
-
*/
|
|
577
|
-
groupSetProperty: (jid, property, value) =>
|
|
578
|
-
mexQuery({ group_id: jid, [property]: value }, GROUP_MEX_QUERY_IDS.SET_PROPERTY, 'xwa2_group_set_property'),
|
|
579
|
-
|
|
580
|
-
/**
|
|
581
|
-
* Reset a group's invite link via MEX (generates new code, invalidates old one).
|
|
582
|
-
* @param {string} jid - Group JID
|
|
583
|
-
*/
|
|
584
|
-
groupResetInviteLinkMex: jid =>
|
|
585
|
-
mexQuery({ group_jid: jid }, GROUP_MEX_QUERY_IDS.RESET_INVITE_LINK, 'xwa2_group_reset_invite_link'),
|
|
586
|
-
|
|
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
|
-
*/
|
|
593
|
-
groupCreateMex: (subject, participantJids) =>
|
|
594
|
-
mexQuery(
|
|
595
|
-
{ input: { subject, participants: participantJids.map(jid => ({ jid })) } },
|
|
596
|
-
GROUP_MEX_QUERY_IDS.CREATE_GROUP,
|
|
597
|
-
'xwa2_group_create'
|
|
598
|
-
),
|
|
599
|
-
|
|
600
|
-
/**
|
|
601
|
-
* Allow non-admin community members to create subgroups.
|
|
602
|
-
* @param {string} communityJid - Community JID
|
|
603
|
-
* @param {boolean} allow
|
|
604
|
-
*/
|
|
605
|
-
groupAllowNonAdminCreation: (communityJid, allow) =>
|
|
606
|
-
mexQuery(
|
|
607
|
-
{ group_jid: communityJid, allow_non_admin_sub_group_creation: allow },
|
|
608
|
-
GROUP_MEX_QUERY_IDS.ALLOW_NON_ADMIN_GROUP_CREATION,
|
|
609
|
-
'xwa2_group_allow_non_admin_creation'
|
|
610
|
-
),
|
|
611
|
-
|
|
612
|
-
/**
|
|
613
|
-
* Get info about a group invite link (before joining).
|
|
614
|
-
* @param {string} inviteCode - The raw invite code (not full URL)
|
|
615
|
-
*/
|
|
616
|
-
groupGetInviteInfo: inviteCode =>
|
|
617
|
-
mexQuery({ invite_code: inviteCode }, GROUP_MEX_QUERY_IDS.GET_INVITE_INFO, 'xwa2_group_get_invite_info'),
|
|
618
|
-
|
|
619
|
-
/**
|
|
620
|
-
* Fetch pending add requests for pre-registration group invites.
|
|
621
|
-
* @param {string} jid - Group JID
|
|
622
|
-
*/
|
|
623
|
-
groupPreRegAddRequests: jid =>
|
|
624
|
-
mexQuery({ group_jid: jid }, GROUP_MEX_QUERY_IDS.GET_PRE_REG_ADD_REQUESTS, 'xwa2_group_pre_reg_add_requests'),
|
|
625
|
-
|
|
626
|
-
/**
|
|
627
|
-
* Get suggested contacts to add to a group.
|
|
628
|
-
* @param {string} jid - Group JID
|
|
629
|
-
*/
|
|
630
|
-
groupSuggestedContacts: jid =>
|
|
631
|
-
mexQuery({ group_jid: jid }, GROUP_MEX_QUERY_IDS.GET_SUGGESTED_CONTACTS, 'xwa2_group_suggested_contacts'),
|
|
632
|
-
|
|
633
|
-
/**
|
|
634
|
-
* Store SMS invite links for a group.
|
|
635
|
-
* @param {string} jid - Group JID
|
|
636
|
-
* @param {{ phone: string, inviteCode: string }[]} invites
|
|
637
|
-
*/
|
|
638
|
-
groupStoreInvitesSms: (jid, invites) =>
|
|
639
|
-
mexQuery(
|
|
640
|
-
{ group_jid: jid, invites: invites.map(({ phone, inviteCode }) => ({ phone, invite_code: inviteCode })) },
|
|
641
|
-
GROUP_MEX_QUERY_IDS.STORE_INVITES_SMS,
|
|
642
|
-
'xwa2_group_store_invites_sms'
|
|
643
|
-
),
|
|
644
|
-
|
|
645
|
-
/**
|
|
646
|
-
* Log a server-sent invite intent (analytics).
|
|
647
|
-
* @param {string} jid - Group JID
|
|
648
|
-
* @param {string} inviteCode
|
|
649
|
-
*/
|
|
650
|
-
groupLogServerSentInvite: (jid, inviteCode) =>
|
|
651
|
-
mexQuery(
|
|
652
|
-
{ group_jid: jid, invite_code: inviteCode },
|
|
653
|
-
GROUP_MEX_QUERY_IDS.LOG_SERVER_SENT_INVITE,
|
|
654
|
-
'xwa2_group_log_server_sent_invite'
|
|
655
|
-
),
|
|
656
|
-
|
|
657
|
-
/**
|
|
658
|
-
* Query online status of users from PDP.
|
|
659
|
-
* @param {string[]} jids - User JIDs
|
|
660
|
-
*/
|
|
661
|
-
queryOnlineStatus: jids =>
|
|
662
|
-
mexQuery({ jids }, GROUP_MEX_QUERY_IDS.QUERY_ONLINE_STATUS, 'xwa2_query_online_status'),
|
|
663
|
-
|
|
664
|
-
/**
|
|
665
|
-
* Query online status and last seen of users from PDP.
|
|
666
|
-
* @param {string[]} jids - User JIDs
|
|
667
|
-
*/
|
|
668
|
-
queryOnlineStatusLastSeen: jids =>
|
|
669
|
-
mexQuery({ jids }, GROUP_MEX_QUERY_IDS.QUERY_ONLINE_STATUS_LAST_SEEN, 'xwa2_query_online_status_last_seen'),
|
|
670
|
-
|
|
671
|
-
GROUP_MEX_QUERY_IDS
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
exports.makeGroupsSocket = makeGroupsSocket
|
|
675
|
-
const extractGroupMetadata = result => {
|
|
676
|
-
const group = (0, WABinary_1.getBinaryNodeChild)(result, 'group')
|
|
677
|
-
const descChild = (0, WABinary_1.getBinaryNodeChild)(group, 'description')
|
|
678
|
-
let desc
|
|
679
|
-
let descId
|
|
680
|
-
let descOwner
|
|
681
|
-
let descOwnerPn
|
|
682
|
-
let descOwnerUsername
|
|
683
|
-
let descTime
|
|
684
|
-
if (descChild) {
|
|
685
|
-
desc = (0, WABinary_1.getBinaryNodeChildString)(descChild, 'body')
|
|
686
|
-
descOwner = descChild.attrs.participant ? (0, WABinary_1.jidNormalizedUser)(descChild.attrs.participant) : undefined
|
|
687
|
-
descOwnerPn = descChild.attrs.participant_pn
|
|
688
|
-
? (0, WABinary_1.jidNormalizedUser)(descChild.attrs.participant_pn)
|
|
689
|
-
: undefined
|
|
690
|
-
descOwnerUsername = descChild.attrs.participant_username || undefined
|
|
691
|
-
descTime = +descChild.attrs.t
|
|
692
|
-
descId = descChild.attrs.id
|
|
693
|
-
}
|
|
694
|
-
const groupId = group.attrs.id.includes('@') ? group.attrs.id : (0, WABinary_1.jidEncode)(group.attrs.id, 'g.us')
|
|
695
|
-
const eph = (0, WABinary_1.getBinaryNodeChild)(group, 'ephemeral')?.attrs.expiration
|
|
696
|
-
const memberAddMode = (0, WABinary_1.getBinaryNodeChildString)(group, 'member_add_mode') === 'all_member_add'
|
|
697
|
-
const linkedParentNode = (0, WABinary_1.getBinaryNodeChild)(group, 'linked_parent')
|
|
698
|
-
const communityMemberAddGroupNode = (0, WABinary_1.getBinaryNodeChild)(group, 'allow_non_admin_sub_group_creation')
|
|
699
|
-
const subGroupVisibilityNode = (0, WABinary_1.getBinaryNodeChild)(group, 'sub_groups_list')
|
|
700
|
-
const membershipApprovalNode = (0, WABinary_1.getBinaryNodeChild)(group, 'membership_approval_mode')
|
|
701
|
-
const metadata = {
|
|
702
|
-
id: groupId,
|
|
703
|
-
notify: group.attrs.notify,
|
|
704
|
-
addressingMode:
|
|
705
|
-
group.attrs.addressing_mode === 'lid' ? Types_1.WAMessageAddressingMode.LID : Types_1.WAMessageAddressingMode.PN,
|
|
706
|
-
subject: group.attrs.subject,
|
|
707
|
-
subjectOwner: group.attrs.s_o,
|
|
708
|
-
subjectOwnerPn: group.attrs.s_o_pn,
|
|
709
|
-
subjectOwnerUsername: group.attrs.s_o_username,
|
|
710
|
-
subjectTime: +group.attrs.s_t,
|
|
711
|
-
size: group.attrs.size ? +group.attrs.size : (0, WABinary_1.getBinaryNodeChildren)(group, 'participant').length,
|
|
712
|
-
creation: +group.attrs.creation,
|
|
713
|
-
owner: group.attrs.creator ? (0, WABinary_1.jidNormalizedUser)(group.attrs.creator) : undefined,
|
|
714
|
-
ownerPn: group.attrs.creator_pn ? (0, WABinary_1.jidNormalizedUser)(group.attrs.creator_pn) : undefined,
|
|
715
|
-
ownerUsername: group.attrs.creator_username || undefined,
|
|
716
|
-
owner_country_code: group.attrs.creator_country_code,
|
|
717
|
-
desc,
|
|
718
|
-
descId,
|
|
719
|
-
descOwner,
|
|
720
|
-
descOwnerPn,
|
|
721
|
-
descOwnerUsername,
|
|
722
|
-
descTime,
|
|
723
|
-
linkedParent: linkedParentNode?.attrs.jid || undefined,
|
|
724
|
-
restrict: !!(0, WABinary_1.getBinaryNodeChild)(group, 'locked'),
|
|
725
|
-
announce: !!(0, WABinary_1.getBinaryNodeChild)(group, 'announcement'),
|
|
726
|
-
isCommunity: !!(0, WABinary_1.getBinaryNodeChild)(group, 'parent'),
|
|
727
|
-
isCommunityAnnounce: !!(0, WABinary_1.getBinaryNodeChild)(group, 'default_sub_group'),
|
|
728
|
-
joinApprovalMode: !!membershipApprovalNode,
|
|
729
|
-
memberAddMode,
|
|
730
|
-
memberShareHistoryMode: (0, WABinary_1.getBinaryNodeChildString)(group, 'member_share_group_history_mode') || undefined,
|
|
731
|
-
memberLinkMode: (0, WABinary_1.getBinaryNodeChildString)(group, 'member_link_mode') || undefined,
|
|
732
|
-
limitSharing: !!(0, WABinary_1.getBinaryNodeChild)(group, 'limit_sharing_enabled'),
|
|
733
|
-
communityMemberAddGroupMode: communityMemberAddGroupNode?.attrs.state || undefined,
|
|
734
|
-
capiCreatedGroup: group.attrs.capi_created === 'true' || undefined,
|
|
735
|
-
appealStatus: group.attrs.appeal_status || undefined,
|
|
736
|
-
isSubGroupHidden: group.attrs.sub_group_visibility === 'hidden' || undefined,
|
|
737
|
-
participants: (0, WABinary_1.getBinaryNodeChildren)(group, 'participant').map(({ attrs }) => {
|
|
738
|
-
// TODO: Store LID MAPPINGS
|
|
739
|
-
return {
|
|
740
|
-
id: attrs.jid,
|
|
741
|
-
phoneNumber:
|
|
742
|
-
(0, WABinary_1.isLidUser)(attrs.jid) && (0, WABinary_1.isPnUser)(attrs.phone_number)
|
|
743
|
-
? attrs.phone_number
|
|
744
|
-
: undefined,
|
|
745
|
-
lid: (0, WABinary_1.isPnUser)(attrs.jid) && (0, WABinary_1.isLidUser)(attrs.lid) ? attrs.lid : undefined,
|
|
746
|
-
username: attrs.participant_username || attrs.username || undefined,
|
|
747
|
-
admin: attrs.type || null,
|
|
748
|
-
memberLabel: attrs.label || undefined,
|
|
749
|
-
memberLabelTimestamp: attrs.label_ts ? +attrs.label_ts : undefined,
|
|
750
|
-
isBanned: attrs.error === '403' || attrs.ban === 'true' || undefined
|
|
751
|
-
}
|
|
752
|
-
}),
|
|
753
|
-
bannedParticipants: (0, WABinary_1.getBinaryNodeChildren)(group, 'participant')
|
|
754
|
-
.filter(({ attrs }) => attrs.error === '403' || attrs.ban === 'true')
|
|
755
|
-
.map(({ attrs }) => ({
|
|
756
|
-
id: attrs.jid,
|
|
757
|
-
phoneNumber: attrs.phone_number || undefined,
|
|
758
|
-
lid: attrs.lid || undefined
|
|
759
|
-
})),
|
|
760
|
-
ephemeralDuration: eph ? +eph : undefined
|
|
761
|
-
}
|
|
762
|
-
return metadata
|
|
763
|
-
}
|
|
764
|
-
exports.extractGroupMetadata = extractGroupMetadata
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { proto } from '../../WAProto/index.js';
|
|
3
|
+
import { WAMessageAddressingMode, WAMessageStubType } from '../Types/index.js';
|
|
4
|
+
import { generateMessageIDV2, 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
|
+
const groupMetadata = async (jid) => {
|
|
20
|
+
const result = await groupQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
|
|
21
|
+
return extractGroupMetadata(result);
|
|
22
|
+
};
|
|
23
|
+
const groupFetchAllParticipating = async () => {
|
|
24
|
+
const result = await query({
|
|
25
|
+
tag: 'iq',
|
|
26
|
+
attrs: {
|
|
27
|
+
to: '@g.us',
|
|
28
|
+
xmlns: 'w:g2',
|
|
29
|
+
type: 'get'
|
|
30
|
+
},
|
|
31
|
+
content: [
|
|
32
|
+
{
|
|
33
|
+
tag: 'participating',
|
|
34
|
+
attrs: {},
|
|
35
|
+
content: [
|
|
36
|
+
{ tag: 'participants', attrs: {} },
|
|
37
|
+
{ tag: 'description', attrs: {} }
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
});
|
|
42
|
+
const data = {};
|
|
43
|
+
const groupsChild = getBinaryNodeChild(result, 'groups');
|
|
44
|
+
if (groupsChild) {
|
|
45
|
+
const groups = getBinaryNodeChildren(groupsChild, 'group');
|
|
46
|
+
for (const groupNode of groups) {
|
|
47
|
+
const meta = extractGroupMetadata({
|
|
48
|
+
tag: 'result',
|
|
49
|
+
attrs: {},
|
|
50
|
+
content: [groupNode]
|
|
51
|
+
});
|
|
52
|
+
data[meta.id] = meta;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// TODO: properly parse LID / PN DATA
|
|
56
|
+
sock.ev.emit('groups.update', Object.values(data));
|
|
57
|
+
return data;
|
|
58
|
+
};
|
|
59
|
+
sock.ws.on('CB:ib,,dirty', async (node) => {
|
|
60
|
+
const { attrs } = getBinaryNodeChild(node, 'dirty');
|
|
61
|
+
if (attrs.type !== 'groups') {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
await groupFetchAllParticipating();
|
|
65
|
+
await sock.cleanDirtyBits('groups');
|
|
66
|
+
});
|
|
67
|
+
return {
|
|
68
|
+
...sock,
|
|
69
|
+
groupMetadata,
|
|
70
|
+
groupCreate: async (subject, participants) => {
|
|
71
|
+
const key = generateMessageIDV2();
|
|
72
|
+
const result = await groupQuery('@g.us', 'set', [
|
|
73
|
+
{
|
|
74
|
+
tag: 'create',
|
|
75
|
+
attrs: {
|
|
76
|
+
subject,
|
|
77
|
+
key
|
|
78
|
+
},
|
|
79
|
+
content: participants.map(jid => ({
|
|
80
|
+
tag: 'participant',
|
|
81
|
+
attrs: { jid }
|
|
82
|
+
}))
|
|
83
|
+
}
|
|
84
|
+
]);
|
|
85
|
+
return extractGroupMetadata(result);
|
|
86
|
+
},
|
|
87
|
+
groupLeave: async (id) => {
|
|
88
|
+
await groupQuery('@g.us', 'set', [
|
|
89
|
+
{
|
|
90
|
+
tag: 'leave',
|
|
91
|
+
attrs: {},
|
|
92
|
+
content: [{ tag: 'group', attrs: { id } }]
|
|
93
|
+
}
|
|
94
|
+
]);
|
|
95
|
+
},
|
|
96
|
+
groupUpdateSubject: async (jid, subject) => {
|
|
97
|
+
await groupQuery(jid, 'set', [
|
|
98
|
+
{
|
|
99
|
+
tag: 'subject',
|
|
100
|
+
attrs: {},
|
|
101
|
+
content: Buffer.from(subject, 'utf-8')
|
|
102
|
+
}
|
|
103
|
+
]);
|
|
104
|
+
},
|
|
105
|
+
groupRequestParticipantsList: async (jid) => {
|
|
106
|
+
const result = await groupQuery(jid, 'get', [
|
|
107
|
+
{
|
|
108
|
+
tag: 'membership_approval_requests',
|
|
109
|
+
attrs: {}
|
|
110
|
+
}
|
|
111
|
+
]);
|
|
112
|
+
const node = getBinaryNodeChild(result, 'membership_approval_requests');
|
|
113
|
+
const participants = getBinaryNodeChildren(node, 'membership_approval_request');
|
|
114
|
+
return participants.map(v => v.attrs);
|
|
115
|
+
},
|
|
116
|
+
groupRequestParticipantsUpdate: async (jid, participants, action) => {
|
|
117
|
+
const result = await groupQuery(jid, 'set', [
|
|
118
|
+
{
|
|
119
|
+
tag: 'membership_requests_action',
|
|
120
|
+
attrs: {},
|
|
121
|
+
content: [
|
|
122
|
+
{
|
|
123
|
+
tag: action,
|
|
124
|
+
attrs: {},
|
|
125
|
+
content: participants.map(jid => ({
|
|
126
|
+
tag: 'participant',
|
|
127
|
+
attrs: { jid }
|
|
128
|
+
}))
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
}
|
|
132
|
+
]);
|
|
133
|
+
const node = getBinaryNodeChild(result, 'membership_requests_action');
|
|
134
|
+
const nodeAction = getBinaryNodeChild(node, action);
|
|
135
|
+
const participantsAffected = getBinaryNodeChildren(nodeAction, 'participant');
|
|
136
|
+
return participantsAffected.map(p => {
|
|
137
|
+
return { status: p.attrs.error || '200', jid: p.attrs.jid };
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
groupParticipantsUpdate: async (jid, participants, action) => {
|
|
141
|
+
const result = await groupQuery(jid, 'set', [
|
|
142
|
+
{
|
|
143
|
+
tag: action,
|
|
144
|
+
attrs: {},
|
|
145
|
+
content: participants.map(jid => ({
|
|
146
|
+
tag: 'participant',
|
|
147
|
+
attrs: { jid }
|
|
148
|
+
}))
|
|
149
|
+
}
|
|
150
|
+
]);
|
|
151
|
+
const node = getBinaryNodeChild(result, action);
|
|
152
|
+
const participantsAffected = getBinaryNodeChildren(node, 'participant');
|
|
153
|
+
return participantsAffected.map(p => {
|
|
154
|
+
return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
|
|
155
|
+
});
|
|
156
|
+
},
|
|
157
|
+
groupUpdateDescription: async (jid, description) => {
|
|
158
|
+
const metadata = await groupMetadata(jid);
|
|
159
|
+
const prev = metadata.descId ?? null;
|
|
160
|
+
await groupQuery(jid, 'set', [
|
|
161
|
+
{
|
|
162
|
+
tag: 'description',
|
|
163
|
+
attrs: {
|
|
164
|
+
...(description ? { id: generateMessageIDV2() } : { delete: 'true' }),
|
|
165
|
+
...(prev ? { prev } : {})
|
|
166
|
+
},
|
|
167
|
+
content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
|
|
168
|
+
}
|
|
169
|
+
]);
|
|
170
|
+
},
|
|
171
|
+
groupInviteCode: async (jid) => {
|
|
172
|
+
const result = await groupQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
|
|
173
|
+
const inviteNode = getBinaryNodeChild(result, 'invite');
|
|
174
|
+
return inviteNode?.attrs.code;
|
|
175
|
+
},
|
|
176
|
+
groupRevokeInvite: async (jid) => {
|
|
177
|
+
const result = await groupQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
|
|
178
|
+
const inviteNode = getBinaryNodeChild(result, 'invite');
|
|
179
|
+
return inviteNode?.attrs.code;
|
|
180
|
+
},
|
|
181
|
+
groupAcceptInvite: async (code) => {
|
|
182
|
+
const results = await groupQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
|
|
183
|
+
const result = getBinaryNodeChild(results, 'group');
|
|
184
|
+
return result?.attrs.jid;
|
|
185
|
+
},
|
|
186
|
+
/**
|
|
187
|
+
* revoke a v4 invite for someone
|
|
188
|
+
* @param groupJid group jid
|
|
189
|
+
* @param invitedJid jid of person you invited
|
|
190
|
+
* @returns true if successful
|
|
191
|
+
*/
|
|
192
|
+
groupRevokeInviteV4: async (groupJid, invitedJid) => {
|
|
193
|
+
const result = await groupQuery(groupJid, 'set', [
|
|
194
|
+
{ tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
|
|
195
|
+
]);
|
|
196
|
+
return !!result;
|
|
197
|
+
},
|
|
198
|
+
/**
|
|
199
|
+
* accept a GroupInviteMessage
|
|
200
|
+
* @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
|
|
201
|
+
* @param inviteMessage the message to accept
|
|
202
|
+
*/
|
|
203
|
+
groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
|
|
204
|
+
key = typeof key === 'string' ? { remoteJid: key } : key;
|
|
205
|
+
const results = await groupQuery(inviteMessage.groupJid, 'set', [
|
|
206
|
+
{
|
|
207
|
+
tag: 'accept',
|
|
208
|
+
attrs: {
|
|
209
|
+
code: inviteMessage.inviteCode,
|
|
210
|
+
expiration: inviteMessage.inviteExpiration.toString(),
|
|
211
|
+
admin: key.remoteJid
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
]);
|
|
215
|
+
// if we have the full message key
|
|
216
|
+
// update the invite message to be expired
|
|
217
|
+
if (key.id) {
|
|
218
|
+
// create new invite message that is expired
|
|
219
|
+
inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage);
|
|
220
|
+
inviteMessage.inviteExpiration = 0;
|
|
221
|
+
inviteMessage.inviteCode = '';
|
|
222
|
+
ev.emit('messages.update', [
|
|
223
|
+
{
|
|
224
|
+
key,
|
|
225
|
+
update: {
|
|
226
|
+
message: {
|
|
227
|
+
groupInviteMessage: inviteMessage
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
]);
|
|
232
|
+
}
|
|
233
|
+
// generate the group add message
|
|
234
|
+
await upsertMessage({
|
|
235
|
+
key: {
|
|
236
|
+
remoteJid: inviteMessage.groupJid,
|
|
237
|
+
id: generateMessageIDV2(sock.user?.id),
|
|
238
|
+
fromMe: false,
|
|
239
|
+
participant: key.remoteJid
|
|
240
|
+
},
|
|
241
|
+
messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
|
|
242
|
+
messageStubParameters: [JSON.stringify(authState.creds.me)],
|
|
243
|
+
participant: key.remoteJid,
|
|
244
|
+
messageTimestamp: unixTimestampSeconds()
|
|
245
|
+
}, 'notify');
|
|
246
|
+
return results.attrs.from;
|
|
247
|
+
}),
|
|
248
|
+
groupGetInviteInfo: async (code) => {
|
|
249
|
+
const results = await groupQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
|
|
250
|
+
return extractGroupMetadata(results);
|
|
251
|
+
},
|
|
252
|
+
groupToggleEphemeral: async (jid, ephemeralExpiration) => {
|
|
253
|
+
const content = ephemeralExpiration
|
|
254
|
+
? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
|
|
255
|
+
: { tag: 'not_ephemeral', attrs: {} };
|
|
256
|
+
await groupQuery(jid, 'set', [content]);
|
|
257
|
+
},
|
|
258
|
+
groupSettingUpdate: async (jid, setting) => {
|
|
259
|
+
await groupQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
|
|
260
|
+
},
|
|
261
|
+
groupMemberAddMode: async (jid, mode) => {
|
|
262
|
+
await groupQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
|
|
263
|
+
},
|
|
264
|
+
groupJoinApprovalMode: async (jid, mode) => {
|
|
265
|
+
await groupQuery(jid, 'set', [
|
|
266
|
+
{ tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }
|
|
267
|
+
]);
|
|
268
|
+
},
|
|
269
|
+
groupToggleHistory: async (jid, enable = true) => {
|
|
270
|
+
const result = await query({
|
|
271
|
+
tag: "iq",
|
|
272
|
+
attrs: {
|
|
273
|
+
type: "get",
|
|
274
|
+
to: "s.whatsapp.net",
|
|
275
|
+
xmlns: "w:mex"
|
|
276
|
+
},
|
|
277
|
+
content: [
|
|
278
|
+
{
|
|
279
|
+
tag: "query",
|
|
280
|
+
attrs: {
|
|
281
|
+
query_id: "24688994337458819"
|
|
282
|
+
},
|
|
283
|
+
content: Buffer.from(JSON.stringify({
|
|
284
|
+
variables: {
|
|
285
|
+
group_id: jid,
|
|
286
|
+
input: {
|
|
287
|
+
member_share_group_history_mode: enable ? "ALL_MEMBER_SHARE" : "ADMIN_SHARE"
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}), "utf-8")
|
|
291
|
+
}
|
|
292
|
+
]
|
|
293
|
+
});
|
|
294
|
+
return result;
|
|
295
|
+
},
|
|
296
|
+
groupFetchAllParticipating
|
|
297
|
+
};
|
|
298
|
+
};
|
|
299
|
+
export const extractGroupMetadata = (result) => {
|
|
300
|
+
const group = getBinaryNodeChild(result, 'group');
|
|
301
|
+
if (!group) {
|
|
302
|
+
// Mirror WAWeb: surface server/client errors with their code+text instead of crashing.
|
|
303
|
+
const errorNode = getBinaryNodeChild(result, 'error');
|
|
304
|
+
if (errorNode) {
|
|
305
|
+
const code = errorNode.attrs.code ? +errorNode.attrs.code : 500;
|
|
306
|
+
const text = errorNode.attrs.text || 'group metadata query failed';
|
|
307
|
+
throw new Boom(text, { statusCode: code, data: errorNode });
|
|
308
|
+
}
|
|
309
|
+
throw new Boom('Invalid group metadata response: missing <group> node', { data: result });
|
|
310
|
+
}
|
|
311
|
+
if (!group.attrs.id) {
|
|
312
|
+
throw new Boom('Invalid group metadata response: missing group id', { data: group });
|
|
313
|
+
}
|
|
314
|
+
const descChild = getBinaryNodeChild(group, 'description');
|
|
315
|
+
let desc;
|
|
316
|
+
let descId;
|
|
317
|
+
let descOwner;
|
|
318
|
+
let descOwnerPn;
|
|
319
|
+
let descOwnerUsername;
|
|
320
|
+
let descTime;
|
|
321
|
+
if (descChild) {
|
|
322
|
+
desc = getBinaryNodeChildString(descChild, 'body');
|
|
323
|
+
descOwner = descChild.attrs.participant ? jidNormalizedUser(descChild.attrs.participant) : undefined;
|
|
324
|
+
descOwnerPn = descChild.attrs.participant_pn ? jidNormalizedUser(descChild.attrs.participant_pn) : undefined;
|
|
325
|
+
descOwnerUsername = descChild.attrs.participant_username || undefined;
|
|
326
|
+
descTime = +descChild.attrs.t;
|
|
327
|
+
descId = descChild.attrs.id;
|
|
328
|
+
}
|
|
329
|
+
const groupId = group.attrs.id.includes('@') ? group.attrs.id : jidEncode(group.attrs.id, 'g.us');
|
|
330
|
+
const eph = getBinaryNodeChild(group, 'ephemeral')?.attrs.expiration;
|
|
331
|
+
const memberAddMode = getBinaryNodeChildString(group, 'member_add_mode') === 'all_member_add';
|
|
332
|
+
const metadata = {
|
|
333
|
+
id: groupId,
|
|
334
|
+
notify: group.attrs.notify,
|
|
335
|
+
addressingMode: group.attrs.addressing_mode === 'lid' ? WAMessageAddressingMode.LID : WAMessageAddressingMode.PN,
|
|
336
|
+
subject: group.attrs.subject,
|
|
337
|
+
subjectOwner: group.attrs.s_o,
|
|
338
|
+
subjectOwnerPn: group.attrs.s_o_pn,
|
|
339
|
+
subjectOwnerUsername: group.attrs.s_o_username,
|
|
340
|
+
subjectTime: +group.attrs.s_t,
|
|
341
|
+
size: group.attrs.size ? +group.attrs.size : getBinaryNodeChildren(group, 'participant').length,
|
|
342
|
+
creation: +group.attrs.creation,
|
|
343
|
+
owner: group.attrs.creator ? jidNormalizedUser(group.attrs.creator) : undefined,
|
|
344
|
+
ownerPn: group.attrs.creator_pn ? jidNormalizedUser(group.attrs.creator_pn) : undefined,
|
|
345
|
+
ownerUsername: group.attrs.creator_username || undefined,
|
|
346
|
+
owner_country_code: group.attrs.creator_country_code,
|
|
347
|
+
desc,
|
|
348
|
+
descId,
|
|
349
|
+
descOwner,
|
|
350
|
+
descOwnerPn,
|
|
351
|
+
descOwnerUsername,
|
|
352
|
+
descTime,
|
|
353
|
+
linkedParent: getBinaryNodeChild(group, 'linked_parent')?.attrs.jid || undefined,
|
|
354
|
+
restrict: !!getBinaryNodeChild(group, 'locked'),
|
|
355
|
+
announce: !!getBinaryNodeChild(group, 'announcement'),
|
|
356
|
+
isCommunity: !!getBinaryNodeChild(group, 'parent'),
|
|
357
|
+
isCommunityAnnounce: !!getBinaryNodeChild(group, 'default_sub_group'),
|
|
358
|
+
joinApprovalMode: !!getBinaryNodeChild(group, 'membership_approval_mode'),
|
|
359
|
+
memberAddMode,
|
|
360
|
+
participants: getBinaryNodeChildren(group, 'participant').map(({ attrs }) => {
|
|
361
|
+
// TODO: Store LID MAPPINGS
|
|
362
|
+
return {
|
|
363
|
+
id: attrs.jid,
|
|
364
|
+
phoneNumber: isLidUser(attrs.jid) && isPnUser(attrs.phone_number) ? attrs.phone_number : undefined,
|
|
365
|
+
lid: isPnUser(attrs.jid) && isLidUser(attrs.lid) ? attrs.lid : undefined,
|
|
366
|
+
username: attrs.participant_username || attrs.username || undefined,
|
|
367
|
+
admin: (attrs.type || null)
|
|
368
|
+
};
|
|
369
|
+
}),
|
|
370
|
+
ephemeralDuration: eph ? +eph : undefined
|
|
371
|
+
};
|
|
372
|
+
return metadata;
|
|
373
|
+
};
|
|
374
|
+
//# sourceMappingURL=groups.js.map
|