kage-baileys 3.0.6 → 3.2.3

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 (216) hide show
  1. package/Example/connection.cjs +4 -0
  2. package/README.MD +4726 -48
  3. package/WAProto/WAProto.proto +3395 -415
  4. package/WAProto/compat.cjs +12 -0
  5. package/WAProto/index.d.ts +47104 -19888
  6. package/WAProto/index.js +131979 -57361
  7. package/lib/Addon/http-error.js +43 -0
  8. package/lib/Addon/index.js +32 -0
  9. package/lib/Addon/keyed-db.js +250 -0
  10. package/lib/Addon/link-preview.js +82 -0
  11. package/lib/Defaults/baileys-version.json +3 -0
  12. package/lib/Defaults/connection.js +110 -0
  13. package/lib/Defaults/constants.js +156 -0
  14. package/lib/Defaults/history.js +46 -0
  15. package/lib/Defaults/index.js +230 -0
  16. package/lib/Defaults/media.js +104 -0
  17. package/lib/Defaults/phonenumber-mcc.json +223 -0
  18. package/lib/Defaults/prefix.js +44 -0
  19. package/lib/Extensions/business-advanced.js +382 -0
  20. package/lib/Extensions/business.js +159 -0
  21. package/lib/Extensions/chats-advanced.js +1106 -0
  22. package/lib/Extensions/chats.js +349 -0
  23. package/lib/Extensions/communities-advanced.js +430 -0
  24. package/lib/Extensions/community.js +94 -0
  25. package/lib/Extensions/groups-advanced.js +343 -0
  26. package/lib/Extensions/index.js +30 -0
  27. package/lib/Extensions/messages-recv-advanced.js +1690 -0
  28. package/lib/Extensions/messages-send-advanced.js +622 -0
  29. package/lib/Extensions/messages-send.js +1380 -0
  30. package/lib/Extensions/newsletter-advanced.js +228 -0
  31. package/lib/Extensions/newsletter.js +72 -0
  32. package/lib/Extensions/socket.js +389 -0
  33. package/lib/Modded/message_builder.js +2084 -4
  34. package/lib/Signal/Group/ciphertext-message.js +54 -0
  35. package/lib/Signal/Group/group-session-builder.js +124 -0
  36. package/lib/Signal/Group/group_cipher.js +216 -0
  37. package/lib/Signal/Group/index.js +124 -0
  38. package/lib/Signal/Group/keyhelper.js +108 -0
  39. package/lib/Signal/Group/sender-chain-key.js +83 -0
  40. package/lib/Signal/Group/sender-key-distribution-message.js +157 -0
  41. package/lib/Signal/Group/sender-key-message.js +166 -0
  42. package/lib/Signal/Group/sender-key-name.js +130 -0
  43. package/lib/Signal/Group/sender-key-record.js +113 -0
  44. package/lib/Signal/Group/sender-key-state.js +208 -0
  45. package/lib/Signal/Group/sender-message-key.js +82 -0
  46. package/lib/Signal/libsignal.js +935 -0
  47. package/lib/Signal/lid-mapping.js +545 -1
  48. package/lib/Socket/Client/index.js +60 -0
  49. package/lib/Socket/Client/types.js +51 -0
  50. package/lib/Socket/Client/websocket.js +152 -0
  51. package/lib/Socket/business.js +831 -0
  52. package/lib/Socket/chats.js +2535 -49
  53. package/lib/Socket/communities.js +450 -1
  54. package/lib/Socket/community.js +1022 -0
  55. package/lib/Socket/dugong.js +1 -1
  56. package/lib/Socket/groups.js +747 -0
  57. package/lib/Socket/index.js +60 -2
  58. package/lib/Socket/messages-recv.js +3450 -5
  59. package/lib/Socket/messages-send.js +3123 -0
  60. package/lib/Socket/mex.js +126 -1
  61. package/lib/Socket/newsletter.js +465 -0
  62. package/lib/Socket/socket.js +2217 -1
  63. package/lib/Store/index.js +79 -0
  64. package/lib/Store/make-cache-manager-store.js +186 -0
  65. package/lib/Store/make-in-memory-store.js +878 -0
  66. package/lib/Store/make-ordered-dictionary.js +187 -0
  67. package/lib/Store/object-repository.js +78 -0
  68. package/lib/Types/Auth.js +25 -0
  69. package/lib/Types/Bussines.js +25 -1
  70. package/lib/Types/Call.js +25 -0
  71. package/lib/Types/Chat.js +39 -0
  72. package/lib/Types/Contact.js +25 -0
  73. package/lib/Types/Events.js +25 -0
  74. package/lib/Types/GroupMetadata.js +25 -0
  75. package/lib/Types/Label.js +76 -0
  76. package/lib/Types/LabelAssociation.js +40 -0
  77. package/lib/Types/Message.js +57 -0
  78. package/lib/Types/Mex.js +56 -1
  79. package/lib/Types/MexUpdates.js +46 -0
  80. package/lib/Types/Newsletter.js +56 -0
  81. package/lib/Types/Product.js +25 -0
  82. package/lib/Types/RichType.js +23 -0
  83. package/lib/Types/Signal.js +25 -0
  84. package/lib/Types/Socket.js +25 -0
  85. package/lib/Types/State.js +92 -0
  86. package/lib/Types/USync.js +25 -0
  87. package/lib/Types/index.js +133 -0
  88. package/lib/Utils/auth-utils.js +703 -0
  89. package/lib/Utils/automation-tools.js +51 -16
  90. package/lib/Utils/baileys-event-stream.js +146 -0
  91. package/lib/Utils/browser-utils.js +95 -0
  92. package/lib/Utils/business.js +525 -0
  93. package/lib/Utils/chat-utils.js +1861 -0
  94. package/lib/Utils/companion-reg-client-utils.js +55 -1
  95. package/lib/Utils/crypto.js +355 -0
  96. package/lib/Utils/decode-wa-message.js +709 -0
  97. package/lib/Utils/event-buffer.js +1323 -8
  98. package/lib/Utils/generics.js +945 -1
  99. package/lib/Utils/history.js +266 -0
  100. package/lib/Utils/identity-change-handler.js +62 -1
  101. package/lib/Utils/index.js +114 -0
  102. package/lib/Utils/link-preview.js +179 -0
  103. package/lib/Utils/logger.js +42 -0
  104. package/lib/Utils/lt-hash.js +73 -0
  105. package/lib/Utils/make-mutex.js +104 -0
  106. package/lib/Utils/message-inspector.js +110 -0
  107. package/lib/Utils/message-retry-manager.js +507 -2
  108. package/lib/Utils/messages-media.js +1931 -1
  109. package/lib/Utils/messages.js +3748 -0
  110. package/lib/Utils/noise-handler.js +423 -0
  111. package/lib/Utils/offline-node-processor.js +53 -1
  112. package/lib/Utils/pre-key-manager.js +255 -1
  113. package/lib/Utils/process-message.js +1592 -0
  114. package/lib/Utils/reporting-utils.js +272 -1
  115. package/lib/Utils/rich-message-utils.js +377 -0
  116. package/lib/Utils/rich-messages.js +1 -1
  117. package/lib/Utils/signal.js +437 -0
  118. package/lib/Utils/stanza-ack.js +51 -1
  119. package/lib/Utils/status-refresh.js +37 -0
  120. package/lib/Utils/status-tools.js +4 -2
  121. package/lib/Utils/sync-action-utils.js +63 -1
  122. package/lib/Utils/tc-token-utils.js +185 -1
  123. package/lib/Utils/terminal-banner.js +31 -0
  124. package/lib/Utils/use-multi-file-auth-state.js +271 -0
  125. package/lib/Utils/use-single-file-auth-state.js +108 -0
  126. package/lib/Utils/use-sqlite-auth-state.js +142 -0
  127. package/lib/Utils/validate-connection.js +497 -1
  128. package/lib/Utils/view-once-compat.js +13 -5
  129. package/lib/VoIP/audio-feeder.js +150 -0
  130. package/lib/VoIP/index.js +289 -0
  131. package/lib/VoIP/relay-transport.js +608 -0
  132. package/lib/VoIP/signaling.js +583 -0
  133. package/lib/VoIP/types.js +30 -0
  134. package/lib/VoIP/wasm-engine.js +1261 -2
  135. package/lib/VoIP/worker-bootstrap.js +1090 -2
  136. package/lib/WABinary/constants.js +2805 -0
  137. package/lib/WABinary/decode.js +649 -2
  138. package/lib/WABinary/encode.js +564 -2
  139. package/lib/WABinary/generic-utils.js +401 -0
  140. package/lib/WABinary/index.js +82 -0
  141. package/lib/WABinary/jid-utils.js +290 -0
  142. package/lib/WABinary/types.js +25 -0
  143. package/lib/WAM/BinaryInfo.js +50 -0
  144. package/lib/WAM/constants.js +45747 -0
  145. package/lib/WAM/encode.js +393 -0
  146. package/lib/WAM/index.js +78 -0
  147. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +135 -0
  148. package/lib/WAUSync/Protocols/USyncContactProtocol.js +110 -0
  149. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +142 -0
  150. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +85 -0
  151. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +69 -0
  152. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +107 -0
  153. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +38 -1
  154. package/lib/WAUSync/Protocols/index.js +83 -0
  155. package/lib/WAUSync/USyncQuery.js +241 -2
  156. package/lib/WAUSync/USyncUser.js +86 -0
  157. package/lib/WAUSync/index.js +78 -0
  158. package/lib/assets/wasm/loader.js +1875 -1
  159. package/lib/assets/wasm/worker-modules.js +11047 -1
  160. package/lib/index.d.ts +126 -0
  161. package/lib/index.js +53 -21
  162. package/lib/index.mjs +437 -0
  163. package/licenses/upstream-MIT.txt +22 -0
  164. package/maintenance/api-coverage.json +1642 -0
  165. package/maintenance/archivos-sha256.json +207 -0
  166. package/maintenance/consumer-validation.log +3 -0
  167. package/maintenance/dependency-audit.json +4 -4
  168. package/maintenance/extension-inventory.json +57 -0
  169. package/maintenance/protocol-update.json +1101 -0
  170. package/maintenance/protocol-wire-audit.json +4 -0
  171. package/maintenance/reference-socket-surface.json +209 -0
  172. package/maintenance/resumen-validacion.json +50 -0
  173. package/maintenance/validation.log +2725 -0
  174. package/maintenance/verification.json +566 -0
  175. package/package.json +107 -9
  176. package/scripts/check-imports.cjs +10 -0
  177. package/scripts/check-package.cjs +40 -0
  178. package/scripts/check-syntax.cjs +1 -1
  179. package/scripts/generate-protobuf.cjs +6 -1
  180. package/scripts/generate-public-types.cjs +9 -0
  181. package/scripts/kage-base64-fix.cjs +45 -0
  182. package/scripts/maintenance.cjs +10 -0
  183. package/test/advanced.test.cjs +24 -0
  184. package/test/base64-fix.test.cjs +49 -0
  185. package/test/maintenance.test.cjs +1 -1
  186. package/test/npm-publication.test.cjs +141 -0
  187. package/test/recepcion-reparada.test.cjs +98 -0
  188. package/test/resilience-binary.test.cjs +69 -0
  189. package/test/resilience-transport.test.cjs +34 -0
  190. package/test/types.test.ts +5 -0
  191. package/test/upgrade.test.cjs +104 -0
  192. package/tsconfig.json +20 -0
  193. package/WAProto/p.html +0 -1
  194. package/lib/KageExtra/Modded/message_builder.js +0 -2330
  195. package/lib/KageExtra/VoIP/audio-feeder.js +0 -136
  196. package/lib/KageExtra/VoIP/index.js +0 -282
  197. package/lib/KageExtra/VoIP/relay-transport.js +0 -559
  198. package/lib/KageExtra/VoIP/signaling.js +0 -603
  199. package/lib/KageExtra/VoIP/types.js +0 -17
  200. package/lib/KageExtra/VoIP/wasm-engine.js +0 -1214
  201. package/lib/KageExtra/VoIP/worker-bootstrap.js +0 -1042
  202. package/lib/KageExtra/assets/wasm/loader.js +0 -5
  203. package/lib/KageExtra/assets/wasm/whatsapp.wasm +0 -0
  204. package/lib/KageExtra/assets/wasm/worker-modules.js +0 -273
  205. package/lib/KageExtra/index.js +0 -3
  206. package/lib/KageExtra/package.json +0 -1
  207. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -53
  208. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -24
  209. package/maintenance/revision-full-check.txt +0 -1097
  210. package/maintenance/revision-library-tests.tap +0 -1088
  211. package/maintenance/revision-protobuf.txt +0 -5
  212. package/maintenance/revision-syntax.txt +0 -5
  213. package/maintenance/schema-coverage.json +0 -23
  214. package/maintenance/schema-merge.json +0 -30
  215. package/maintenance/validation-node20.txt +0 -191
  216. package/maintenance/validation-node22.txt +0 -237
@@ -330,3 +330,750 @@ const extractGroupMetadata = (result) => {
330
330
  return metadata;
331
331
  };
332
332
  exports.extractGroupMetadata = extractGroupMetadata;
333
+
334
+ // Kage: compatibilidad de API.
335
+ const __kageModule27 = (() => {
336
+ const module = { exports: {} }; const exports = module.exports;
337
+ "use strict"
338
+ Object.defineProperty(exports, "__esModule", { value: true })
339
+
340
+ const { proto } = require("../../WAProto")
341
+ const {
342
+ WAMessageStubType,
343
+ WAMessageAddressingMode
344
+ } = require("../Types")
345
+ const {
346
+ generateMessageID,
347
+ unixTimestampSeconds
348
+ } = require("../Utils")
349
+ const {
350
+ getBinaryNodeChild,
351
+ getBinaryNodeChildren,
352
+ getBinaryNodeChildString,
353
+ jidEncode,
354
+ jidNormalizedUser
355
+ } = require("../WABinary")
356
+ const { makeChatsSocket } = require("./chats")
357
+
358
+ const makeGroupsSocket = (config) => {
359
+ const suki = makeChatsSocket(config)
360
+ const {
361
+ authState,
362
+ ev,
363
+ query,
364
+ cleanDirtyBits,
365
+ upsertMessage
366
+ } = suki
367
+
368
+ const groupQuery = async (jid, type, content) => (query({
369
+ tag: 'iq',
370
+ attrs: {
371
+ type,
372
+ xmlns: 'w:g2',
373
+ to: jid,
374
+ },
375
+ content
376
+ }))
377
+
378
+ const groupMetadata = async (jid) => {
379
+ const result = await groupQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }])
380
+ return extractGroupMetadata(result)
381
+ }
382
+
383
+ const groupFetchAllParticipating = async () => {
384
+ const result = await query({
385
+ tag: 'iq',
386
+ attrs: {
387
+ to: '@g.us',
388
+ xmlns: 'w:g2',
389
+ type: 'get',
390
+ },
391
+ content: [
392
+ {
393
+ tag: 'participating',
394
+ attrs: {},
395
+ content: [
396
+ { tag: 'participants', attrs: {} },
397
+ { tag: 'description', attrs: {} }
398
+ ]
399
+ }
400
+ ]
401
+ })
402
+
403
+ const data = {}
404
+ const groupsChild = getBinaryNodeChild(result, 'groups')
405
+
406
+ if (groupsChild) {
407
+ const groups = getBinaryNodeChildren(groupsChild, 'group')
408
+ for (const groupNode of groups) {
409
+ const meta = extractGroupMetadata({
410
+ tag: 'result',
411
+ attrs: {},
412
+ content: [groupNode]
413
+ })
414
+ data[meta.id] = meta
415
+ }
416
+ }
417
+
418
+ suki.ev.emit('groups.update', Object.values(data))
419
+ return data
420
+ }
421
+
422
+ suki.ws.on('CB:ib,,dirty', async (node) => {
423
+ const { attrs } = getBinaryNodeChild(node, 'dirty')
424
+ if (attrs.type !== 'groups') {
425
+ return
426
+ }
427
+
428
+ await groupFetchAllParticipating()
429
+ await cleanDirtyBits('groups')
430
+ })
431
+
432
+ return {
433
+ ...suki,
434
+ groupQuery,
435
+ groupMetadata,
436
+ groupCreate: async (subject, participants) => {
437
+ const key = generateMessageID()
438
+
439
+ const result = await groupQuery('@g.us', 'set', [
440
+ {
441
+ tag: 'create',
442
+ attrs: {
443
+ subject,
444
+ key
445
+ },
446
+ content: participants.map(jid => ({
447
+ tag: 'participant',
448
+ attrs: { jid }
449
+ }))
450
+ }
451
+ ])
452
+
453
+ return extractGroupMetadata(result)
454
+ },
455
+ groupLeave: async (id) => {
456
+ await groupQuery('@g.us', 'set', [
457
+ {
458
+ tag: 'leave',
459
+ attrs: {},
460
+ content: [
461
+ { tag: 'group', attrs: { id } }
462
+ ]
463
+ }
464
+ ])
465
+ },
466
+ groupUpdateSubject: async (jid, subject) => {
467
+ await groupQuery(jid, 'set', [
468
+ {
469
+ tag: 'subject',
470
+ attrs: {},
471
+ content: Buffer.from(subject, 'utf-8')
472
+ }
473
+ ])
474
+ },
475
+ groupRequestParticipantsList: async (jid) => {
476
+ const result = await groupQuery(jid, 'get', [
477
+ {
478
+ tag: 'membership_approval_requests',
479
+ attrs: {}
480
+ }
481
+ ])
482
+
483
+ const node = getBinaryNodeChild(result, 'membership_approval_requests')
484
+ const participants = getBinaryNodeChildren(node, 'membership_approval_request')
485
+
486
+ return participants.map(v => v.attrs)
487
+ },
488
+ groupRequestParticipantsUpdate: async (jid, participants, action) => {
489
+ const result = await groupQuery(jid, 'set', [{
490
+ tag: 'membership_requests_action',
491
+ attrs: {},
492
+ content: [
493
+ {
494
+ tag: action,
495
+ attrs: {},
496
+ content: participants.map(jid => ({
497
+ tag: 'participant',
498
+ attrs: { jid }
499
+ }))
500
+ }
501
+ ]
502
+ }])
503
+
504
+ const node = getBinaryNodeChild(result, 'membership_requests_action')
505
+ const nodeAction = getBinaryNodeChild(node, action)
506
+ const participantsAffected = getBinaryNodeChildren(nodeAction, 'participant')
507
+
508
+ return participantsAffected.map(p => {
509
+ return { status: p.attrs.error || '200', jid: p.attrs.jid }
510
+ })
511
+ },
512
+ groupParticipantsUpdate: async (jid, participants, action) => {
513
+ const result = await groupQuery(jid, 'set', [
514
+ {
515
+ tag: action,
516
+ attrs: {},
517
+ content: participants.map(jid => ({
518
+ tag: 'participant',
519
+ attrs: { jid }
520
+ }))
521
+ }
522
+ ])
523
+ const node = getBinaryNodeChild(result, action)
524
+ const participantsAffected = getBinaryNodeChildren(node, 'participant')
525
+
526
+ return participantsAffected.map(p => {
527
+ return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p }
528
+ })
529
+ },
530
+ groupUpdateDescription: async (jid, description) => {
531
+ const metadata = await groupMetadata(jid)
532
+ const prev = metadata.descId ? metadata.descId : null
533
+
534
+ await groupQuery(jid, 'set', [
535
+ {
536
+ tag: 'description',
537
+ attrs: {
538
+ ...(description ? { id: generateMessageID() } : { delete: 'true' }),
539
+ ...(prev ? { prev } : {})
540
+ },
541
+ content: description ? [
542
+ { tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }
543
+ ] : undefined
544
+ }
545
+ ])
546
+ },
547
+ groupInviteCode: async (jid) => {
548
+ const result = await groupQuery(jid, 'get', [{ tag: 'invite', attrs: {} }])
549
+ const inviteNode = getBinaryNodeChild(result, 'invite')
550
+
551
+ return inviteNode?.attrs?.code
552
+ },
553
+ groupRevokeInvite: async (jid) => {
554
+ const result = await groupQuery(jid, 'set', [{ tag: 'invite', attrs: {} }])
555
+ const inviteNode = getBinaryNodeChild(result, 'invite')
556
+
557
+ return inviteNode?.attrs?.code
558
+ },
559
+ groupAcceptInvite: async (code) => {
560
+ const results = await groupQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }])
561
+ const result = getBinaryNodeChild(results, 'group')
562
+
563
+ return result?.attrs?.jid
564
+ },
565
+ /**
566
+ * revoke a v4 invite for someone
567
+ * @param groupJid group jid
568
+ * @param invitedJid jid of person you invited
569
+ * @returns true if successful
570
+ */
571
+ groupRevokeInviteV4: async (groupJid, invitedJid) => {
572
+ const result = await groupQuery(groupJid, 'set', [{ tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }])
573
+
574
+ return !!result
575
+ },
576
+ /**
577
+ * accept a GroupInviteMessage
578
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
579
+ * @param inviteMessage the message to accept
580
+ */
581
+ groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
582
+ key = typeof key === 'string' ? { remoteJid: key } : key
583
+ const results = await groupQuery(inviteMessage.groupJid, 'set', [{
584
+ tag: 'accept',
585
+ attrs: {
586
+ code: inviteMessage.inviteCode,
587
+ expiration: inviteMessage.inviteExpiration.toString(),
588
+ admin: key.remoteJid
589
+ }
590
+ }])
591
+
592
+ // if we have the full message key
593
+ // update the invite message to be expired
594
+ if (key.id) {
595
+ // create new invite message that is expired
596
+ inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage)
597
+ inviteMessage.inviteExpiration = 0
598
+ inviteMessage.inviteCode = ''
599
+ ev.emit('messages.update', [
600
+ {
601
+ key,
602
+ update: {
603
+ message: {
604
+ groupInviteMessage: inviteMessage
605
+ }
606
+ }
607
+ }
608
+ ])
609
+ }
610
+
611
+ // generate the group add message
612
+ await upsertMessage({
613
+ key: {
614
+ remoteJid: inviteMessage.groupJid,
615
+ id: generateMessageID(suki.user?.id),
616
+ fromMe: false,
617
+ participant: key.remoteJid
618
+ },
619
+ messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
620
+ messageStubParameters: [JSON.stringify(authState.creds.me)],
621
+ participant: key.remoteJid,
622
+ messageTimestamp: unixTimestampSeconds()
623
+ }, 'notify')
624
+
625
+ return results.attrs.from
626
+ }),
627
+ groupGetInviteInfo: async (code) => {
628
+ const results = await groupQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }])
629
+
630
+ return extractGroupMetadata(results)
631
+ },
632
+ groupToggleEphemeral: async (jid, ephemeralExpiration) => {
633
+ const content = ephemeralExpiration ?
634
+ { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } } :
635
+ { tag: 'not_ephemeral', attrs: {} }
636
+ await groupQuery(jid, 'set', [content])
637
+ },
638
+ groupSettingUpdate: async (jid, setting) => {
639
+ await groupQuery(jid, 'set', [{ tag: setting, attrs: {} }])
640
+ },
641
+ groupMemberAddMode: async (jid, mode) => {
642
+ await groupQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }])
643
+ },
644
+ groupJoinApprovalMode: async (jid, mode) => {
645
+ await groupQuery(jid, 'set', [{ tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }])
646
+ },
647
+ groupFetchAllParticipating
648
+ }
649
+ }
650
+
651
+ const extractGroupMetadata = (result) => {
652
+ const group = getBinaryNodeChild(result, 'group')
653
+ const descChild = getBinaryNodeChild(group, 'description')
654
+ const mode = group.attrs.addressing_mode === WAMessageAddressingMode.LID ? WAMessageAddressingMode.LID : WAMessageAddressingMode.PN
655
+
656
+ let desc
657
+ let descId
658
+ let descOwner
659
+ let descOwnerAlt
660
+
661
+ if (descChild) {
662
+ desc = getBinaryNodeChildString(descChild, 'body')
663
+ descId = descChild.attrs.id
664
+ descOwner = mode === WAMessageAddressingMode.LID ? jidNormalizedUser(descChild.attrs.participant_pn) : jidNormalizedUser(descChild.attrs.participant)
665
+ descOwnerAlt = mode === WAMessageAddressingMode.LID ? jidNormalizedUser(descChild.attrs.participant) : undefined
666
+ }
667
+
668
+ const groupId = group.attrs.id.includes('@') ? group.attrs.id : jidEncode(group.attrs.id, 'g.us')
669
+ const eph = getBinaryNodeChild(group, 'ephemeral')?.attrs.expiration
670
+ const memberAddMode = getBinaryNodeChildString(group, 'member_add_mode') === 'all_member_add'
671
+
672
+ const metadata = {
673
+ id: groupId,
674
+ subject: group.attrs.subject,
675
+ subjectOwner: group.attrs.s_o,
676
+ subjectOwnerAlt: group.attrs?.s_o_pn ? group.attrs.s_o_pn : group.attrs.s_o,
677
+ subjectTime: Number(group.attrs.s_t),
678
+ size: Number(group.attrs?.size ? group.attrs.size : getBinaryNodeChildren(group, 'participant').length),
679
+ creation: Number(group.attrs.creation),
680
+ owner: group.attrs.creator ? jidNormalizedUser(group.attrs.creator) : undefined,
681
+ ownerAlt: group.attrs.creator ? jidNormalizedUser(group.attrs?.creator_pn ? group.attrs.creator_pn : group.attrs.creator_pn) : undefined,
682
+ ownerCountry: group.attrs.creator_country_code,
683
+ desc,
684
+ descId,
685
+ descOwner,
686
+ descOwnerAlt,
687
+ linkedParent: getBinaryNodeChild(group, 'linked_parent')?.attrs.jid || undefined,
688
+ restrict: !!getBinaryNodeChild(group, 'locked'),
689
+ announce: !!getBinaryNodeChild(group, 'announcement'),
690
+ isCommunity: !!getBinaryNodeChild(group, 'parent'),
691
+ isCommunityAnnounce: !!getBinaryNodeChild(group, 'default_sub_group'),
692
+ joinApprovalMode: !!getBinaryNodeChild(group, 'membership_approval_mode'),
693
+ memberAddMode,
694
+ participants: getBinaryNodeChildren(group, 'participant').map(({ attrs }) => {
695
+ return {
696
+ id: mode === WAMessageAddressingMode.LID ? attrs.phone_number : attrs.jid,
697
+ lid: mode === WAMessageAddressingMode.LID ? attrs.jid : attrs.lid,
698
+ admin: (attrs.type || null)
699
+ }
700
+ }),
701
+ ephemeralDuration: eph ? Number(eph) : undefined,
702
+ addressingMode: mode
703
+ }
704
+
705
+ return metadata
706
+ }
707
+
708
+ module.exports = {
709
+ makeGroupsSocket,
710
+ extractGroupMetadata
711
+ }
712
+ return module.exports;
713
+ })();
714
+ for (const key of Object.keys(__kageModule27)) {
715
+ if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule27[key]});
716
+ }
717
+
718
+ // Kage: funciones avanzadas.
719
+ const __kageModule133 = (() => {
720
+ const module = { exports: {} }; const exports = module.exports;
721
+ "use strict";
722
+ Object.defineProperty(exports, "__esModule", { value: true });
723
+ exports.extractGroupMetadata = exports.makeGroupsSocket = void 0;
724
+ const index_js_1 = require("../../WAProto/index.js");
725
+ const index_js_2 = require("../Addon/index.js");
726
+ const index_js_3 = require("../Types/index.js");
727
+ const index_js_4 = require("../Utils/index.js");
728
+ const index_js_5 = require("../WABinary/index.js");
729
+ const chats_js_1 = require("./chats.js");
730
+ const makeGroupsSocket = (config) => {
731
+ const sock = (0, chats_js_1.makeChatsSocket)(config);
732
+ const { authState, ev, query, upsertMessage } = sock;
733
+ const groupQuery = async (jid, type, content) => query({
734
+ tag: 'iq',
735
+ attrs: {
736
+ type,
737
+ xmlns: 'w:g2',
738
+ to: jid
739
+ },
740
+ content
741
+ });
742
+ const groupMetadata = async (jid) => {
743
+ const result = await groupQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
744
+ return (0, exports.extractGroupMetadata)(result);
745
+ };
746
+ const groupFetchAllParticipating = async () => {
747
+ const result = await query({
748
+ tag: 'iq',
749
+ attrs: {
750
+ to: '@g.us',
751
+ xmlns: 'w:g2',
752
+ type: 'get'
753
+ },
754
+ content: [
755
+ {
756
+ tag: 'participating',
757
+ attrs: {},
758
+ content: [
759
+ { tag: 'participants', attrs: {} },
760
+ { tag: 'description', attrs: {} }
761
+ ]
762
+ }
763
+ ]
764
+ });
765
+ const data = {};
766
+ const groupsChild = (0, index_js_5.getBinaryNodeChild)(result, 'groups');
767
+ if (groupsChild) {
768
+ const groups = (0, index_js_5.getBinaryNodeChildren)(groupsChild, 'group');
769
+ for (const groupNode of groups) {
770
+ const meta = (0, exports.extractGroupMetadata)({
771
+ tag: 'result',
772
+ attrs: {},
773
+ content: [groupNode]
774
+ });
775
+ data[meta.id] = meta;
776
+ }
777
+ }
778
+ // TODO: properly parse LID / PN DATA
779
+ sock.ev.emit('groups.update', Object.values(data));
780
+ return data;
781
+ };
782
+ sock.ws.on('CB:ib,,dirty', async (node) => {
783
+ const { attrs } = (0, index_js_5.getBinaryNodeChild)(node, 'dirty');
784
+ if (attrs.type !== 'groups') {
785
+ return;
786
+ }
787
+ await groupFetchAllParticipating();
788
+ await sock.cleanDirtyBits('groups');
789
+ });
790
+ return {
791
+ ...sock,
792
+ groupQuery,
793
+ groupMetadata,
794
+ groupCreate: async (subject, participants) => {
795
+ const key = (0, index_js_4.generateMessageIDV2)();
796
+ const result = await groupQuery('@g.us', 'set', [
797
+ {
798
+ tag: 'create',
799
+ attrs: {
800
+ subject,
801
+ key
802
+ },
803
+ content: participants.map(jid => ({
804
+ tag: 'participant',
805
+ attrs: { jid }
806
+ }))
807
+ }
808
+ ]);
809
+ return (0, exports.extractGroupMetadata)(result);
810
+ },
811
+ groupLeave: async (id) => {
812
+ await groupQuery('@g.us', 'set', [
813
+ {
814
+ tag: 'leave',
815
+ attrs: {},
816
+ content: [{ tag: 'group', attrs: { id } }]
817
+ }
818
+ ]);
819
+ },
820
+ groupUpdateSubject: async (jid, subject) => {
821
+ await groupQuery(jid, 'set', [
822
+ {
823
+ tag: 'subject',
824
+ attrs: {},
825
+ content: Buffer.from(subject, 'utf-8')
826
+ }
827
+ ]);
828
+ },
829
+ groupRequestParticipantsList: async (jid) => {
830
+ const result = await groupQuery(jid, 'get', [
831
+ {
832
+ tag: 'membership_approval_requests',
833
+ attrs: {}
834
+ }
835
+ ]);
836
+ const node = (0, index_js_5.getBinaryNodeChild)(result, 'membership_approval_requests');
837
+ const participants = (0, index_js_5.getBinaryNodeChildren)(node, 'membership_approval_request');
838
+ return participants.map(v => v.attrs);
839
+ },
840
+ groupRequestParticipantsUpdate: async (jid, participants, action) => {
841
+ const result = await groupQuery(jid, 'set', [
842
+ {
843
+ tag: 'membership_requests_action',
844
+ attrs: {},
845
+ content: [
846
+ {
847
+ tag: action,
848
+ attrs: {},
849
+ content: participants.map(jid => ({
850
+ tag: 'participant',
851
+ attrs: { jid }
852
+ }))
853
+ }
854
+ ]
855
+ }
856
+ ]);
857
+ const node = (0, index_js_5.getBinaryNodeChild)(result, 'membership_requests_action');
858
+ const nodeAction = (0, index_js_5.getBinaryNodeChild)(node, action);
859
+ const participantsAffected = (0, index_js_5.getBinaryNodeChildren)(nodeAction, 'participant');
860
+ return participantsAffected.map(p => {
861
+ return { status: p.attrs.error || '200', jid: p.attrs.jid };
862
+ });
863
+ },
864
+ groupParticipantsUpdate: async (jid, participants, action) => {
865
+ const result = await groupQuery(jid, 'set', [
866
+ {
867
+ tag: action,
868
+ attrs: {},
869
+ content: participants.map(jid => ({
870
+ tag: 'participant',
871
+ attrs: { jid }
872
+ }))
873
+ }
874
+ ]);
875
+ const node = (0, index_js_5.getBinaryNodeChild)(result, action);
876
+ const participantsAffected = (0, index_js_5.getBinaryNodeChildren)(node, 'participant');
877
+ return participantsAffected.map(p => {
878
+ return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
879
+ });
880
+ },
881
+ groupUpdateDescription: async (jid, description) => {
882
+ const metadata = await groupMetadata(jid);
883
+ const prev = metadata.descId ?? null;
884
+ await groupQuery(jid, 'set', [
885
+ {
886
+ tag: 'description',
887
+ attrs: {
888
+ ...(description ? { id: (0, index_js_4.generateMessageIDV2)() } : { delete: 'true' }),
889
+ ...(prev ? { prev } : {})
890
+ },
891
+ content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
892
+ }
893
+ ]);
894
+ },
895
+ groupInviteCode: async (jid) => {
896
+ const result = await groupQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
897
+ const inviteNode = (0, index_js_5.getBinaryNodeChild)(result, 'invite');
898
+ return inviteNode?.attrs.code;
899
+ },
900
+ groupRevokeInvite: async (jid) => {
901
+ const result = await groupQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
902
+ const inviteNode = (0, index_js_5.getBinaryNodeChild)(result, 'invite');
903
+ return inviteNode?.attrs.code;
904
+ },
905
+ groupAcceptInvite: async (code) => {
906
+ const results = await groupQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
907
+ const result = (0, index_js_5.getBinaryNodeChild)(results, 'group');
908
+ return result?.attrs.jid;
909
+ },
910
+ /**
911
+ * revoke a v4 invite for someone
912
+ * @param groupJid group jid
913
+ * @param invitedJid jid of person you invited
914
+ * @returns true if successful
915
+ */
916
+ groupRevokeInviteV4: async (groupJid, invitedJid) => {
917
+ const result = await groupQuery(groupJid, 'set', [
918
+ { tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
919
+ ]);
920
+ return !!result;
921
+ },
922
+ /**
923
+ * accept a GroupInviteMessage
924
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
925
+ * @param inviteMessage the message to accept
926
+ */
927
+ groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
928
+ key = typeof key === 'string' ? { remoteJid: key } : key;
929
+ const results = await groupQuery(inviteMessage.groupJid, 'set', [
930
+ {
931
+ tag: 'accept',
932
+ attrs: {
933
+ code: inviteMessage.inviteCode,
934
+ expiration: inviteMessage.inviteExpiration.toString(),
935
+ admin: key.remoteJid
936
+ }
937
+ }
938
+ ]);
939
+ // if we have the full message key
940
+ // update the invite message to be expired
941
+ if (key.id) {
942
+ // create new invite message that is expired
943
+ inviteMessage = index_js_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage);
944
+ inviteMessage.inviteExpiration = 0;
945
+ inviteMessage.inviteCode = '';
946
+ ev.emit('messages.update', [
947
+ {
948
+ key,
949
+ update: {
950
+ message: {
951
+ groupInviteMessage: inviteMessage
952
+ }
953
+ }
954
+ }
955
+ ]);
956
+ }
957
+ // generate the group add message
958
+ await upsertMessage({
959
+ key: {
960
+ remoteJid: inviteMessage.groupJid,
961
+ id: (0, index_js_4.generateMessageIDV2)(sock.user?.id),
962
+ fromMe: false,
963
+ participant: key.remoteJid
964
+ },
965
+ messageStubType: index_js_3.WAMessageStubType.GROUP_PARTICIPANT_ADD,
966
+ messageStubParameters: [JSON.stringify(authState.creds.me)],
967
+ participant: key.remoteJid,
968
+ messageTimestamp: (0, index_js_4.unixTimestampSeconds)()
969
+ }, 'notify');
970
+ return results.attrs.from;
971
+ }),
972
+ groupGetInviteInfo: async (code) => {
973
+ const results = await groupQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
974
+ return (0, exports.extractGroupMetadata)(results);
975
+ },
976
+ groupToggleEphemeral: async (jid, ephemeralExpiration) => {
977
+ const content = ephemeralExpiration
978
+ ? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
979
+ : { tag: 'not_ephemeral', attrs: {} };
980
+ await groupQuery(jid, 'set', [content]);
981
+ },
982
+ groupSettingUpdate: async (jid, setting) => {
983
+ await groupQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
984
+ },
985
+ groupMemberAddMode: async (jid, mode) => {
986
+ await groupQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
987
+ },
988
+ groupJoinApprovalMode: async (jid, mode) => {
989
+ await groupQuery(jid, 'set', [
990
+ { tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }
991
+ ]);
992
+ },
993
+ groupFetchAllParticipating
994
+ };
995
+ };
996
+ exports.makeGroupsSocket = makeGroupsSocket;
997
+ const extractGroupMetadata = (result) => {
998
+ const group = (0, index_js_5.getBinaryNodeChild)(result, 'group');
999
+ if (!group) {
1000
+ // Mirror WAWeb: surface server/client errors with their code+text instead of crashing.
1001
+ const errorNode = (0, index_js_5.getBinaryNodeChild)(result, 'error');
1002
+ if (errorNode) {
1003
+ const code = errorNode.attrs.code ? +errorNode.attrs.code : 500;
1004
+ const text = errorNode.attrs.text || 'group metadata query failed';
1005
+ throw new index_js_2.HttpError(text, { statusCode: code, data: errorNode });
1006
+ }
1007
+ throw new index_js_2.HttpError('Invalid group metadata response: missing <group> node', { data: result });
1008
+ }
1009
+ if (!group.attrs.id) {
1010
+ throw new index_js_2.HttpError('Invalid group metadata response: missing group id', { data: group });
1011
+ }
1012
+ const descChild = (0, index_js_5.getBinaryNodeChild)(group, 'description');
1013
+ let desc;
1014
+ let descId;
1015
+ let descOwner;
1016
+ let descOwnerPn;
1017
+ let descOwnerUsername;
1018
+ let descTime;
1019
+ if (descChild) {
1020
+ desc = (0, index_js_5.getBinaryNodeChildString)(descChild, 'body');
1021
+ descOwner = descChild.attrs.participant ? (0, index_js_5.jidNormalizedUser)(descChild.attrs.participant) : undefined;
1022
+ descOwnerPn = descChild.attrs.participant_pn ? (0, index_js_5.jidNormalizedUser)(descChild.attrs.participant_pn) : undefined;
1023
+ descOwnerUsername = descChild.attrs.participant_username || undefined;
1024
+ descTime = +descChild.attrs.t;
1025
+ descId = descChild.attrs.id;
1026
+ }
1027
+ const groupId = group.attrs.id.includes('@') ? group.attrs.id : (0, index_js_5.jidEncode)(group.attrs.id, 'g.us');
1028
+ const eph = (0, index_js_5.getBinaryNodeChild)(group, 'ephemeral')?.attrs.expiration;
1029
+ const memberAddMode = (0, index_js_5.getBinaryNodeChildString)(group, 'member_add_mode') === 'all_member_add';
1030
+ const metadata = {
1031
+ id: groupId,
1032
+ notify: group.attrs.notify,
1033
+ addressingMode: group.attrs.addressing_mode === 'lid' ? index_js_3.WAMessageAddressingMode.LID : index_js_3.WAMessageAddressingMode.PN,
1034
+ subject: group.attrs.subject,
1035
+ subjectOwner: group.attrs.s_o,
1036
+ subjectOwnerPn: group.attrs.s_o_pn,
1037
+ subjectOwnerUsername: group.attrs.s_o_username,
1038
+ subjectTime: +group.attrs.s_t,
1039
+ size: group.attrs.size ? +group.attrs.size : (0, index_js_5.getBinaryNodeChildren)(group, 'participant').length,
1040
+ creation: +group.attrs.creation,
1041
+ owner: group.attrs.creator ? (0, index_js_5.jidNormalizedUser)(group.attrs.creator) : undefined,
1042
+ ownerPn: group.attrs.creator_pn ? (0, index_js_5.jidNormalizedUser)(group.attrs.creator_pn) : undefined,
1043
+ ownerUsername: group.attrs.creator_username || undefined,
1044
+ owner_country_code: group.attrs.creator_country_code,
1045
+ desc,
1046
+ descId,
1047
+ descOwner,
1048
+ descOwnerPn,
1049
+ descOwnerUsername,
1050
+ descTime,
1051
+ linkedParent: (0, index_js_5.getBinaryNodeChild)(group, 'linked_parent')?.attrs.jid || undefined,
1052
+ restrict: !!(0, index_js_5.getBinaryNodeChild)(group, 'locked'),
1053
+ announce: !!(0, index_js_5.getBinaryNodeChild)(group, 'announcement'),
1054
+ isCommunity: !!(0, index_js_5.getBinaryNodeChild)(group, 'parent'),
1055
+ isCommunityAnnounce: !!(0, index_js_5.getBinaryNodeChild)(group, 'default_sub_group'),
1056
+ joinApprovalMode: !!(0, index_js_5.getBinaryNodeChild)(group, 'membership_approval_mode'),
1057
+ memberAddMode,
1058
+ participants: (0, index_js_5.getBinaryNodeChildren)(group, 'participant').map(({ attrs }) => {
1059
+ // TODO: Store LID MAPPINGS
1060
+ return {
1061
+ id: attrs.jid,
1062
+ phoneNumber: (0, index_js_5.isLidUser)(attrs.jid) && (0, index_js_5.isPnUser)(attrs.phone_number) ? attrs.phone_number : undefined,
1063
+ lid: (0, index_js_5.isPnUser)(attrs.jid) && (0, index_js_5.isLidUser)(attrs.lid) ? attrs.lid : undefined,
1064
+ username: attrs.participant_username || attrs.username || undefined,
1065
+ admin: (attrs.type || null)
1066
+ };
1067
+ }),
1068
+ ephemeralDuration: eph ? +eph : undefined
1069
+ };
1070
+ return metadata;
1071
+ };
1072
+ exports.extractGroupMetadata = extractGroupMetadata;
1073
+
1074
+ return module.exports;
1075
+ })();
1076
+ for (const key of Object.keys(__kageModule133)) {
1077
+ if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule133[key]});
1078
+ }
1079
+ Object.defineProperty(exports, Symbol.for('kage.advanced'), {value:__kageModule133, configurable:true});