@badzz88/baileys 8.5.4 → 8.5.5

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.
Files changed (107) hide show
  1. package/README.md +1 -1
  2. package/WAProto/WAProto.proto +75 -1256
  3. package/WAProto/index.d.ts +19729 -36122
  4. package/WAProto/index.js +132193 -178538
  5. package/engine-requirements.js +15 -7
  6. package/lib/Defaults/index.js +14 -22
  7. package/lib/Signal/Group/group_cipher.js +5 -5
  8. package/lib/Signal/Group/keyhelper.js +4 -4
  9. package/lib/Signal/Group/sender-chain-key.js +2 -2
  10. package/lib/Signal/Group/sender-key-distribution-message.js +1 -1
  11. package/lib/Signal/Group/sender-key-message.js +3 -3
  12. package/lib/Signal/Group/sender-key-record.js +1 -1
  13. package/lib/Signal/Group/sender-message-key.js +5 -5
  14. package/lib/Signal/libsignal.js +28 -39
  15. package/lib/Signal/lid-mapping.js +8 -28
  16. package/lib/Socket/aigroups.js +5 -5
  17. package/lib/Socket/business.js +11 -3
  18. package/lib/Socket/chats.js +319 -668
  19. package/lib/Socket/communities.js +89 -85
  20. package/lib/Socket/graphql.js +228 -435
  21. package/lib/Socket/groups.js +211 -132
  22. package/lib/Socket/index.js +7 -9
  23. package/lib/Socket/interactive-handler.js +60 -117
  24. package/lib/Socket/interop.js +175 -56
  25. package/lib/Socket/luxu.js +387 -0
  26. package/lib/Socket/managed-account.js +48 -79
  27. package/lib/Socket/messages-recv.js +340 -898
  28. package/lib/Socket/messages-send.js +160 -462
  29. package/lib/Socket/mex.js +53 -40
  30. package/lib/Socket/newsletter.js +295 -291
  31. package/lib/Socket/privacy.js +265 -77
  32. package/lib/Socket/registration.js +157 -164
  33. package/lib/Socket/socket.js +199 -181
  34. package/lib/Socket/text-router.js +83 -0
  35. package/lib/Socket/username.js +227 -144
  36. package/lib/Store/keyed-db.js +108 -0
  37. package/lib/Store/make-cache-manager-store.js +2 -2
  38. package/lib/Store/make-in-memory-store.js +141 -25
  39. package/lib/Types/Auth.js +3 -3
  40. package/lib/Types/Label.js +1 -1
  41. package/lib/Types/LabelAssociation.js +1 -1
  42. package/lib/Types/Mex.js +112 -0
  43. package/lib/Types/Newsletter.js +65 -96
  44. package/lib/Types/State.js +4 -4
  45. package/lib/Types/index.js +1 -1
  46. package/lib/Utils/auth-utils.js +57 -52
  47. package/lib/Utils/browser-utils.js +1 -1
  48. package/lib/Utils/business.js +6 -2
  49. package/lib/Utils/chat-utils.js +38 -102
  50. package/lib/Utils/command-loader.d.ts +31 -0
  51. package/lib/Utils/command-loader.js +100 -0
  52. package/lib/Utils/companion-reg-client-utils.js +42 -0
  53. package/lib/Utils/crypto.js +84 -54
  54. package/lib/Utils/curve25519-js.js +275 -0
  55. package/lib/Utils/decode-wa-message.js +83 -316
  56. package/lib/Utils/event-buffer.js +61 -37
  57. package/lib/Utils/generics.js +103 -157
  58. package/lib/Utils/group-history.js +12 -3
  59. package/lib/Utils/history.js +15 -15
  60. package/lib/Utils/index.js +5 -1
  61. package/lib/Utils/link-preview.js +8 -3
  62. package/lib/Utils/lt-hash.js +35 -2
  63. package/lib/Utils/make-mutex.js +1 -1
  64. package/lib/Utils/message-retry-manager.js +92 -27
  65. package/lib/Utils/messages-media.js +130 -159
  66. package/lib/Utils/messages.js +566 -144
  67. package/lib/Utils/meta-ai-msmsg.js +202 -62
  68. package/lib/Utils/native-bridge.js +82 -0
  69. package/lib/Utils/noise-handler.js +21 -19
  70. package/lib/Utils/offline-node-processor.js +8 -3
  71. package/lib/Utils/pre-key-manager.js +23 -13
  72. package/lib/Utils/process-message.js +106 -197
  73. package/lib/Utils/reporting-utils.js +2 -2
  74. package/lib/Utils/session-pool.d.ts +16 -0
  75. package/lib/Utils/session-pool.js +94 -0
  76. package/lib/Utils/signal.js +63 -28
  77. package/lib/Utils/stanza-ack.js +12 -39
  78. package/lib/Utils/sticker.d.ts +17 -0
  79. package/lib/Utils/sticker.js +145 -0
  80. package/lib/Utils/sync-action-utils.js +7 -4
  81. package/lib/Utils/tc-token-utils.js +25 -20
  82. package/lib/Utils/use-multi-file-auth-state.js +14 -30
  83. package/lib/Utils/validate-connection.js +19 -59
  84. package/lib/Utils/view-once-cache.d.ts +9 -0
  85. package/lib/Utils/view-once-cache.js +79 -0
  86. package/lib/WABinary/decode.js +16 -50
  87. package/lib/WABinary/encode.js +224 -54
  88. package/lib/WABinary/generic-utils.js +97 -7
  89. package/lib/WABinary/jid-utils.js +14 -27
  90. package/lib/WAM/encode.js +7 -7
  91. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +1 -58
  92. package/lib/WAUSync/Protocols/USyncContactProtocol.js +1 -7
  93. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +5 -13
  94. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +4 -1
  95. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +7 -20
  96. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +1 -1
  97. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +2 -2
  98. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -7
  99. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +1 -1
  100. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +1 -2
  101. package/lib/WAUSync/Protocols/index.js +0 -1
  102. package/lib/WAUSync/USyncQuery.js +6 -77
  103. package/lib/WAUSync/USyncUser.js +8 -16
  104. package/lib/WAUSync/index.js +0 -1
  105. package/lib/antiban.js +854 -608
  106. package/lib/index.js +1 -1
  107. package/package.json +20 -16
@@ -15,10 +15,10 @@ const business_1 = require('./business')
15
15
  const mex_1 = require('./mex')
16
16
 
17
17
  const COMMUNITY_MEX_QUERY_IDS = {
18
- QUERY_PARTICIPANT_COUNT: '31981537024824320',
19
- QUERY_SUBGROUPS: '25554052094203120',
20
- QUERY_SUBGROUP_PARTICIPANT_COUNT: '24784259781196780',
21
- UPDATE_OWNER: '24781435194845316'
18
+ QUERY_PARTICIPANT_COUNT: '31981537024824320', // QueryCommunityParticipantCount
19
+ QUERY_SUBGROUPS: '25554052094203120', // QuerySubgroups (shared with groups)
20
+ QUERY_SUBGROUP_PARTICIPANT_COUNT: '24784259781196780', // QuerySubgroupParticipantCount
21
+ UPDATE_OWNER: '24781435194845316' // UpdateCommunityOwner
22
22
  }
23
23
 
24
24
  const makeCommunitiesSocket = config => {
@@ -205,16 +205,16 @@ const makeCommunitiesSocket = config => {
205
205
  communityFetchLinkedGroups: async jid => {
206
206
  let communityJid = jid
207
207
  let isCommunity = false
208
-
208
+ // Try to determine if it is a subgroup or a community
209
209
  const metadata = await sock.groupMetadata(jid)
210
210
  if (metadata.linkedParent) {
211
-
211
+ // It is a subgroup, get the community jid
212
212
  communityJid = metadata.linkedParent
213
213
  } else {
214
-
214
+ // It is a community
215
215
  isCommunity = true
216
216
  }
217
-
217
+ // Fetch all subgroups of the community
218
218
  const result = await communityQuery(communityJid, 'get', [{ tag: 'sub_groups', attrs: {} }])
219
219
  const linkedGroupsData = []
220
220
  const subGroupsNode = (0, WABinary_1.getBinaryNodeChild)(result, 'sub_groups')
@@ -317,14 +317,23 @@ const makeCommunitiesSocket = config => {
317
317
  const result = (0, WABinary_1.getBinaryNodeChild)(results, 'community')
318
318
  return result?.attrs.jid
319
319
  },
320
-
320
+ /**
321
+ * revoke a v4 invite for someone
322
+ * @param communityJid community jid
323
+ * @param invitedJid jid of person you invited
324
+ * @returns true if successful
325
+ */
321
326
  communityRevokeInviteV4: async (communityJid, invitedJid) => {
322
327
  const result = await communityQuery(communityJid, 'set', [
323
328
  { tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
324
329
  ])
325
330
  return !!result
326
331
  },
327
-
332
+ /**
333
+ * accept a CommunityInviteMessage
334
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
335
+ * @param inviteMessage the message to accept
336
+ */
328
337
  communityAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
329
338
  key = typeof key === 'string' ? { remoteJid: key } : key
330
339
  const results = await communityQuery(inviteMessage.groupJid, 'set', [
@@ -337,10 +346,10 @@ const makeCommunitiesSocket = config => {
337
346
  }
338
347
  }
339
348
  ])
340
-
341
-
349
+ // if we have the full message key
350
+ // update the invite message to be expired
342
351
  if (key.id) {
343
-
352
+ // create new invite message that is expired
344
353
  inviteMessage = index_js_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage)
345
354
  inviteMessage.inviteExpiration = 0
346
355
  inviteMessage.inviteCode = ''
@@ -355,14 +364,14 @@ const makeCommunitiesSocket = config => {
355
364
  }
356
365
  ])
357
366
  }
358
-
367
+ // generate the community add message
359
368
  await upsertMessage(
360
369
  {
361
370
  key: {
362
371
  remoteJid: inviteMessage.groupJid,
363
372
  id: (0, Utils_1.generateMessageIDV2)(sock.user?.id),
364
373
  fromMe: false,
365
- participant: key.remoteJid
374
+ participant: key.remoteJid // TODO: investigate if this makes any sense at all
366
375
  },
367
376
  messageStubType: Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD,
368
377
  messageStubParameters: [JSON.stringify(authState.creds.me)],
@@ -373,15 +382,30 @@ const makeCommunitiesSocket = config => {
373
382
  )
374
383
  return results.attrs.from
375
384
  }),
385
+ communityGetInviteInfo: async code => {
386
+ const results = await communityQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }])
387
+ return (0, exports.extractCommunityMetadata)(results)
388
+ },
389
+ communityToggleEphemeral: async (jid, ephemeralExpiration) => {
390
+ const content = ephemeralExpiration
391
+ ? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
392
+ : { tag: 'not_ephemeral', attrs: {} }
393
+ await communityQuery(jid, 'set', [content])
394
+ },
395
+ communitySettingUpdate: async (jid, setting) => {
396
+ await communityQuery(jid, 'set', [{ tag: setting, attrs: {} }])
397
+ },
376
398
  communityMemberAddMode: async (jid, mode) => {
377
399
  await communityQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }])
378
400
  },
379
401
  communityJoinApprovalMode: async (jid, mode) => {
380
402
  await communityQuery(jid, 'set', [
381
- { tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }
403
+ { tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'community_join', attrs: { state: mode } }] }
382
404
  ])
383
405
  },
384
-
406
+ /**
407
+ * Update community profile picture
408
+ */
385
409
  communityUpdatePicture: async (jid, content) => {
386
410
  const { img } = await (0, Utils_1.generateProfilePicture)(content)
387
411
  await communityQuery(jid, 'set', [
@@ -392,24 +416,34 @@ const makeCommunitiesSocket = config => {
392
416
  }
393
417
  ])
394
418
  },
395
-
419
+ /**
420
+ * Remove community profile picture
421
+ */
396
422
  communityRemovePicture: async jid => {
397
423
  await communityQuery(jid, 'set', [{ tag: 'picture', attrs: { type: 'delete' } }])
398
424
  },
399
-
425
+ /**
426
+ * Update community settings (announce-only, etc.)
427
+ */
400
428
  communitySettingUpdate: async (jid, setting) => {
401
429
  await communityQuery(jid, 'set', [{ tag: setting, attrs: {} }])
402
430
  },
403
-
431
+ /**
432
+ * Deactivate/delete a community
433
+ */
404
434
  communityDeactivate: async jid => {
405
435
  await communityQuery(jid, 'set', [{ tag: 'delete_parent', attrs: {} }])
406
436
  },
407
-
437
+ /**
438
+ * Get info about a community from an invite link code
439
+ */
408
440
  communityGetInviteInfo: async code => {
409
441
  const results = await communityQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }])
410
442
  return (0, exports.extractCommunityMetadata)(results)
411
443
  },
412
-
444
+ /**
445
+ * Toggle ephemeral messages for the whole community
446
+ */
413
447
  communityToggleEphemeral: async (jid, ephemeralExpiration) => {
414
448
  const content = ephemeralExpiration
415
449
  ? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
@@ -418,50 +452,52 @@ const makeCommunitiesSocket = config => {
418
452
  },
419
453
  communityFetchAllParticipating,
420
454
 
421
-
455
+ // ── MEX queries (JSON responses) ──────────────────────────────────────
422
456
 
423
-
424
- communityParticipantCount: async jid => {
425
- const result = await mexQuery(
457
+ /**
458
+ * Fetch total participant count of a community via MEX.
459
+ * @param {string} jid - Community JID
460
+ */
461
+ communityParticipantCount: jid =>
462
+ mexQuery(
426
463
  { group_input: { group_id: jid } },
427
464
  COMMUNITY_MEX_QUERY_IDS.QUERY_PARTICIPANT_COUNT,
428
465
  'xwa2_group_query_by_id'
429
- )
430
- return result?.participant_count ?? result?.participantCount ?? result?.count ?? result
431
- },
466
+ ),
432
467
 
433
-
434
- communitySubgroupsMex: async jid => {
435
- const result = await mexQuery(
436
- { group_input: { group_id: jid } },
437
- COMMUNITY_MEX_QUERY_IDS.QUERY_SUBGROUPS,
438
- 'xwa2_group_query_by_id'
439
- )
440
- return result?.subgroups ?? result?.linked_groups ?? result?.sub_groups ?? result
441
- },
468
+ /**
469
+ * Fetch subgroups of a community via MEX (includes hidden_group, join approval state, etc.)
470
+ * @param {string} jid - Community JID
471
+ */
472
+ communitySubgroupsMex: jid =>
473
+ mexQuery({ group_input: { group_id: jid } }, COMMUNITY_MEX_QUERY_IDS.QUERY_SUBGROUPS, 'xwa2_group_query_by_id'),
442
474
 
443
-
444
- communitySubgroupParticipantCount: async subgroupJid => {
445
- const result = await mexQuery(
475
+ /**
476
+ * Fetch participant count of a specific subgroup within a community.
477
+ * @param {string} subgroupJid - Subgroup JID
478
+ */
479
+ communitySubgroupParticipantCount: subgroupJid =>
480
+ mexQuery(
446
481
  { group_input: { group_id: subgroupJid } },
447
482
  COMMUNITY_MEX_QUERY_IDS.QUERY_SUBGROUP_PARTICIPANT_COUNT,
448
483
  'xwa2_group_query_by_id'
449
- )
450
- return result?.participant_count ?? result?.participantCount ?? result?.count ?? result
451
- },
484
+ ),
452
485
 
453
-
454
- communityTransferOwnershipMex: async (communityJid, newOwnerJid) => {
455
- const result = await mexQuery(
486
+ /**
487
+ * Transfer community ownership to a new owner via MEX.
488
+ * Sends role_updates: [{ user_jid, new_role: "SUPERADMIN_MEMBER" }]
489
+ * @param {string} communityJid - Community JID
490
+ * @param {string} newOwnerJid - JID of the new owner
491
+ */
492
+ communityTransferOwnershipMex: (communityJid, newOwnerJid) =>
493
+ mexQuery(
456
494
  {
457
495
  group_id: communityJid,
458
496
  role_updates: [{ user_jid: newOwnerJid, new_role: 'SUPERADMIN_MEMBER' }]
459
497
  },
460
498
  COMMUNITY_MEX_QUERY_IDS.UPDATE_OWNER,
461
499
  'xwa2_community_update_owner'
462
- )
463
- return result?.status === 'ok' || !!result?.success || !!result
464
- },
500
+ ),
465
501
 
466
502
  COMMUNITY_MEX_QUERY_IDS
467
503
  }
@@ -481,12 +517,6 @@ const extractCommunityMetadata = result => {
481
517
  : (0, WABinary_1.jidEncode)(community.attrs.id || '', 'g.us')
482
518
  const eph = (0, WABinary_1.getBinaryNodeChild)(community, 'ephemeral')?.attrs.expiration
483
519
  const memberAddMode = (0, WABinary_1.getBinaryNodeChildString)(community, 'member_add_mode') === 'all_member_add'
484
- const linkedGroupsNode = (0, WABinary_1.getBinaryNodeChild)(community, 'linked_groups')
485
- const linkLimit = community.attrs.parent_group_link_limit
486
- ? +community.attrs.parent_group_link_limit
487
- : linkedGroupsNode?.attrs?.parent_group_link_limit
488
- ? +linkedGroupsNode.attrs.parent_group_link_limit
489
- : undefined
490
520
  const metadata = {
491
521
  id: communityId,
492
522
  subject: community.attrs.subject || '',
@@ -506,39 +536,13 @@ const extractCommunityMetadata = result => {
506
536
  memberAddMode,
507
537
  participants: (0, WABinary_1.getBinaryNodeChildren)(community, 'participant').map(({ attrs }) => {
508
538
  return {
539
+ // TODO: IMPLEMENT THE PN/LID FIELDS HERE!!
509
540
  id: attrs.jid,
510
- admin: attrs.type || null,
511
- ...(attrs.lid ? { lid: attrs.lid } : {}),
512
- ...(attrs.pn ? { pn: attrs.pn } : {})
541
+ admin: attrs.type || null
513
542
  }
514
543
  }),
515
544
  ephemeralDuration: eph ? +eph : undefined,
516
- addressingMode: (0, WABinary_1.getBinaryNodeChildString)(community, 'addressing_mode'),
517
- linkLimit,
518
- suspendAppealStatus: community.attrs.suspend_appeal_status || community.attrs.appeal_status || undefined,
519
- allowMemberSuggestM3:
520
- community.attrs.parent_group_allow_member_suggest_existing_m3 === 'true'
521
- ? true
522
- : community.attrs.parent_group_allow_member_suggest_existing_m3 === 'false'
523
- ? false
524
- : undefined,
525
- allowMemberSuggestM3ForAdmin:
526
- community.attrs.parent_group_allow_member_suggest_existing_m3_for_admin === 'true'
527
- ? true
528
- : community.attrs.parent_group_allow_member_suggest_existing_m3_for_admin === 'false'
529
- ? false
530
- : undefined,
531
- subgroupPollInterval: community.attrs.improve_subgroup_activation_subgroup_poll_interval
532
- ? Number(community.attrs.improve_subgroup_activation_subgroup_poll_interval)
533
- : undefined,
534
- isGeneralSubgroup:
535
- community.attrs.general_subgroup != null
536
- ? community.attrs.general_subgroup === 'true' || community.attrs.general_subgroup === true
537
- : undefined,
538
- isHiddenSubgroup:
539
- community.attrs.hidden_subgroup != null
540
- ? community.attrs.hidden_subgroup === 'true' || community.attrs.hidden_subgroup === true
541
- : undefined
545
+ addressingMode: (0, WABinary_1.getBinaryNodeChildString)(community, 'addressing_mode')
542
546
  }
543
547
  return metadata
544
548
  }