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