kage-baileys 3.0.6 → 3.2.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 (217) hide show
  1. package/Example/connection.cjs +4 -0
  2. package/README.MD +4726 -48
  3. package/README.md +5941 -0
  4. package/WAProto/WAProto.proto +3395 -415
  5. package/WAProto/compat.cjs +12 -0
  6. package/WAProto/index.d.ts +47104 -19888
  7. package/WAProto/index.js +131979 -57361
  8. package/lib/Addon/http-error.js +43 -0
  9. package/lib/Addon/index.js +32 -0
  10. package/lib/Addon/keyed-db.js +250 -0
  11. package/lib/Addon/link-preview.js +82 -0
  12. package/lib/Defaults/baileys-version.json +3 -0
  13. package/lib/Defaults/connection.js +110 -0
  14. package/lib/Defaults/constants.js +156 -0
  15. package/lib/Defaults/history.js +46 -0
  16. package/lib/Defaults/index.js +230 -0
  17. package/lib/Defaults/media.js +104 -0
  18. package/lib/Defaults/phonenumber-mcc.json +223 -0
  19. package/lib/Defaults/prefix.js +44 -0
  20. package/lib/Extensions/business-advanced.js +382 -0
  21. package/lib/Extensions/business.js +159 -0
  22. package/lib/Extensions/chats-advanced.js +1106 -0
  23. package/lib/Extensions/chats.js +349 -0
  24. package/lib/Extensions/communities-advanced.js +430 -0
  25. package/lib/Extensions/community.js +94 -0
  26. package/lib/Extensions/groups-advanced.js +343 -0
  27. package/lib/Extensions/index.js +30 -0
  28. package/lib/Extensions/messages-recv-advanced.js +1690 -0
  29. package/lib/Extensions/messages-send-advanced.js +622 -0
  30. package/lib/Extensions/messages-send.js +1380 -0
  31. package/lib/Extensions/newsletter-advanced.js +228 -0
  32. package/lib/Extensions/newsletter.js +72 -0
  33. package/lib/Extensions/socket.js +389 -0
  34. package/lib/Modded/message_builder.js +2084 -4
  35. package/lib/Signal/Group/ciphertext-message.js +54 -0
  36. package/lib/Signal/Group/group-session-builder.js +124 -0
  37. package/lib/Signal/Group/group_cipher.js +216 -0
  38. package/lib/Signal/Group/index.js +124 -0
  39. package/lib/Signal/Group/keyhelper.js +108 -0
  40. package/lib/Signal/Group/sender-chain-key.js +83 -0
  41. package/lib/Signal/Group/sender-key-distribution-message.js +157 -0
  42. package/lib/Signal/Group/sender-key-message.js +166 -0
  43. package/lib/Signal/Group/sender-key-name.js +130 -0
  44. package/lib/Signal/Group/sender-key-record.js +113 -0
  45. package/lib/Signal/Group/sender-key-state.js +208 -0
  46. package/lib/Signal/Group/sender-message-key.js +82 -0
  47. package/lib/Signal/libsignal.js +935 -0
  48. package/lib/Signal/lid-mapping.js +545 -1
  49. package/lib/Socket/Client/index.js +60 -0
  50. package/lib/Socket/Client/types.js +51 -0
  51. package/lib/Socket/Client/websocket.js +152 -0
  52. package/lib/Socket/business.js +831 -0
  53. package/lib/Socket/chats.js +2535 -49
  54. package/lib/Socket/communities.js +450 -1
  55. package/lib/Socket/community.js +1022 -0
  56. package/lib/Socket/dugong.js +1 -1
  57. package/lib/Socket/groups.js +747 -0
  58. package/lib/Socket/index.js +60 -2
  59. package/lib/Socket/messages-recv.js +3450 -5
  60. package/lib/Socket/messages-send.js +3123 -0
  61. package/lib/Socket/mex.js +126 -1
  62. package/lib/Socket/newsletter.js +465 -0
  63. package/lib/Socket/socket.js +2217 -1
  64. package/lib/Store/index.js +79 -0
  65. package/lib/Store/make-cache-manager-store.js +186 -0
  66. package/lib/Store/make-in-memory-store.js +878 -0
  67. package/lib/Store/make-ordered-dictionary.js +187 -0
  68. package/lib/Store/object-repository.js +78 -0
  69. package/lib/Types/Auth.js +25 -0
  70. package/lib/Types/Bussines.js +25 -1
  71. package/lib/Types/Call.js +25 -0
  72. package/lib/Types/Chat.js +39 -0
  73. package/lib/Types/Contact.js +25 -0
  74. package/lib/Types/Events.js +25 -0
  75. package/lib/Types/GroupMetadata.js +25 -0
  76. package/lib/Types/Label.js +76 -0
  77. package/lib/Types/LabelAssociation.js +40 -0
  78. package/lib/Types/Message.js +57 -0
  79. package/lib/Types/Mex.js +56 -1
  80. package/lib/Types/MexUpdates.js +46 -0
  81. package/lib/Types/Newsletter.js +56 -0
  82. package/lib/Types/Product.js +25 -0
  83. package/lib/Types/RichType.js +23 -0
  84. package/lib/Types/Signal.js +25 -0
  85. package/lib/Types/Socket.js +25 -0
  86. package/lib/Types/State.js +92 -0
  87. package/lib/Types/USync.js +25 -0
  88. package/lib/Types/index.js +133 -0
  89. package/lib/Utils/auth-utils.js +703 -0
  90. package/lib/Utils/automation-tools.js +51 -16
  91. package/lib/Utils/baileys-event-stream.js +146 -0
  92. package/lib/Utils/browser-utils.js +95 -0
  93. package/lib/Utils/business.js +525 -0
  94. package/lib/Utils/chat-utils.js +1861 -0
  95. package/lib/Utils/companion-reg-client-utils.js +55 -1
  96. package/lib/Utils/crypto.js +355 -0
  97. package/lib/Utils/decode-wa-message.js +709 -0
  98. package/lib/Utils/event-buffer.js +1323 -8
  99. package/lib/Utils/generics.js +945 -1
  100. package/lib/Utils/history.js +266 -0
  101. package/lib/Utils/identity-change-handler.js +62 -1
  102. package/lib/Utils/index.js +114 -0
  103. package/lib/Utils/link-preview.js +179 -0
  104. package/lib/Utils/logger.js +42 -0
  105. package/lib/Utils/lt-hash.js +73 -0
  106. package/lib/Utils/make-mutex.js +104 -0
  107. package/lib/Utils/message-inspector.js +110 -0
  108. package/lib/Utils/message-retry-manager.js +507 -2
  109. package/lib/Utils/messages-media.js +1931 -1
  110. package/lib/Utils/messages.js +3748 -0
  111. package/lib/Utils/noise-handler.js +423 -0
  112. package/lib/Utils/offline-node-processor.js +53 -1
  113. package/lib/Utils/pre-key-manager.js +255 -1
  114. package/lib/Utils/process-message.js +1592 -0
  115. package/lib/Utils/reporting-utils.js +272 -1
  116. package/lib/Utils/rich-message-utils.js +377 -0
  117. package/lib/Utils/rich-messages.js +1 -1
  118. package/lib/Utils/signal.js +437 -0
  119. package/lib/Utils/stanza-ack.js +51 -1
  120. package/lib/Utils/status-refresh.js +37 -0
  121. package/lib/Utils/status-tools.js +4 -2
  122. package/lib/Utils/sync-action-utils.js +63 -1
  123. package/lib/Utils/tc-token-utils.js +185 -1
  124. package/lib/Utils/terminal-banner.js +31 -0
  125. package/lib/Utils/use-multi-file-auth-state.js +271 -0
  126. package/lib/Utils/use-single-file-auth-state.js +108 -0
  127. package/lib/Utils/use-sqlite-auth-state.js +142 -0
  128. package/lib/Utils/validate-connection.js +497 -1
  129. package/lib/Utils/view-once-compat.js +13 -5
  130. package/lib/VoIP/audio-feeder.js +150 -0
  131. package/lib/VoIP/index.js +289 -0
  132. package/lib/VoIP/relay-transport.js +608 -0
  133. package/lib/VoIP/signaling.js +583 -0
  134. package/lib/VoIP/types.js +30 -0
  135. package/lib/VoIP/wasm-engine.js +1261 -2
  136. package/lib/VoIP/worker-bootstrap.js +1090 -2
  137. package/lib/WABinary/constants.js +2805 -0
  138. package/lib/WABinary/decode.js +649 -2
  139. package/lib/WABinary/encode.js +564 -2
  140. package/lib/WABinary/generic-utils.js +401 -0
  141. package/lib/WABinary/index.js +82 -0
  142. package/lib/WABinary/jid-utils.js +290 -0
  143. package/lib/WABinary/types.js +25 -0
  144. package/lib/WAM/BinaryInfo.js +50 -0
  145. package/lib/WAM/constants.js +45747 -0
  146. package/lib/WAM/encode.js +393 -0
  147. package/lib/WAM/index.js +78 -0
  148. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +135 -0
  149. package/lib/WAUSync/Protocols/USyncContactProtocol.js +110 -0
  150. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +142 -0
  151. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +85 -0
  152. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +69 -0
  153. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +107 -0
  154. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +38 -1
  155. package/lib/WAUSync/Protocols/index.js +83 -0
  156. package/lib/WAUSync/USyncQuery.js +241 -2
  157. package/lib/WAUSync/USyncUser.js +86 -0
  158. package/lib/WAUSync/index.js +78 -0
  159. package/lib/assets/wasm/loader.js +1875 -1
  160. package/lib/assets/wasm/worker-modules.js +11047 -1
  161. package/lib/index.d.ts +126 -0
  162. package/lib/index.js +53 -21
  163. package/lib/index.mjs +437 -0
  164. package/licenses/upstream-MIT.txt +22 -0
  165. package/maintenance/api-coverage.json +1642 -0
  166. package/maintenance/archivos-sha256.json +207 -0
  167. package/maintenance/consumer-validation.log +3 -0
  168. package/maintenance/dependency-audit.json +4 -4
  169. package/maintenance/extension-inventory.json +57 -0
  170. package/maintenance/protocol-update.json +1101 -0
  171. package/maintenance/protocol-wire-audit.json +4 -0
  172. package/maintenance/reference-socket-surface.json +209 -0
  173. package/maintenance/resumen-validacion.json +50 -0
  174. package/maintenance/validation.log +2725 -0
  175. package/maintenance/verification.json +566 -0
  176. package/package.json +107 -9
  177. package/scripts/check-imports.cjs +10 -0
  178. package/scripts/check-package.cjs +40 -0
  179. package/scripts/check-syntax.cjs +1 -1
  180. package/scripts/generate-protobuf.cjs +6 -1
  181. package/scripts/generate-public-types.cjs +9 -0
  182. package/scripts/kage-base64-fix.cjs +45 -0
  183. package/scripts/maintenance.cjs +10 -0
  184. package/test/advanced.test.cjs +24 -0
  185. package/test/base64-fix.test.cjs +49 -0
  186. package/test/maintenance.test.cjs +1 -1
  187. package/test/npm-publication.test.cjs +141 -0
  188. package/test/recepcion-reparada.test.cjs +98 -0
  189. package/test/resilience-binary.test.cjs +69 -0
  190. package/test/resilience-transport.test.cjs +34 -0
  191. package/test/types.test.ts +5 -0
  192. package/test/upgrade.test.cjs +104 -0
  193. package/tsconfig.json +20 -0
  194. package/WAProto/p.html +0 -1
  195. package/lib/KageExtra/Modded/message_builder.js +0 -2330
  196. package/lib/KageExtra/VoIP/audio-feeder.js +0 -136
  197. package/lib/KageExtra/VoIP/index.js +0 -282
  198. package/lib/KageExtra/VoIP/relay-transport.js +0 -559
  199. package/lib/KageExtra/VoIP/signaling.js +0 -603
  200. package/lib/KageExtra/VoIP/types.js +0 -17
  201. package/lib/KageExtra/VoIP/wasm-engine.js +0 -1214
  202. package/lib/KageExtra/VoIP/worker-bootstrap.js +0 -1042
  203. package/lib/KageExtra/assets/wasm/loader.js +0 -5
  204. package/lib/KageExtra/assets/wasm/whatsapp.wasm +0 -0
  205. package/lib/KageExtra/assets/wasm/worker-modules.js +0 -273
  206. package/lib/KageExtra/index.js +0 -3
  207. package/lib/KageExtra/package.json +0 -1
  208. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -53
  209. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -24
  210. package/maintenance/revision-full-check.txt +0 -1097
  211. package/maintenance/revision-library-tests.tap +0 -1088
  212. package/maintenance/revision-protobuf.txt +0 -5
  213. package/maintenance/revision-syntax.txt +0 -5
  214. package/maintenance/schema-coverage.json +0 -23
  215. package/maintenance/schema-merge.json +0 -30
  216. package/maintenance/validation-node20.txt +0 -191
  217. package/maintenance/validation-node22.txt +0 -237
@@ -428,4 +428,453 @@ var _businessjs = require('./business.js');
428
428
  };
429
429
  return metadata;
430
430
  }; exports.extractCommunityMetadata = extractCommunityMetadata;
431
- //# sourceMappingURL=communities.js.map
431
+ //#
432
+ // Kage: funciones avanzadas.
433
+ const __kageModule132 = (() => {
434
+ const module = { exports: {} }; const exports = module.exports;
435
+ "use strict";
436
+ var __importDefault = (this && this.__importDefault) || function (mod) {
437
+ return (mod && mod.__esModule) ? mod : { "default": mod };
438
+ };
439
+ Object.defineProperty(exports, "__esModule", { value: true });
440
+ exports.extractCommunityMetadata = exports.makeCommunitiesSocket = void 0;
441
+ const index_js_1 = require("../../WAProto/index.js");
442
+ const index_js_2 = require("../Types/index.js");
443
+ const index_js_3 = require("../Utils/index.js");
444
+ const logger_js_1 = __importDefault(require("../Utils/logger.js"));
445
+ const index_js_4 = require("../WABinary/index.js");
446
+ const business_js_1 = require("./business.js");
447
+ const makeCommunitiesSocket = (config) => {
448
+ const sock = (0, business_js_1.makeBusinessSocket)(config);
449
+ const { authState, ev, query, upsertMessage } = sock;
450
+ const communityQuery = async (jid, type, content) => query({
451
+ tag: 'iq',
452
+ attrs: {
453
+ type,
454
+ xmlns: 'w:g2',
455
+ to: jid
456
+ },
457
+ content
458
+ });
459
+ const communityMetadata = async (jid) => {
460
+ const result = await communityQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
461
+ return (0, exports.extractCommunityMetadata)(result);
462
+ };
463
+ const communityFetchAllParticipating = async () => {
464
+ const result = await query({
465
+ tag: 'iq',
466
+ attrs: {
467
+ to: '@g.us',
468
+ xmlns: 'w:g2',
469
+ type: 'get'
470
+ },
471
+ content: [
472
+ {
473
+ tag: 'participating',
474
+ attrs: {},
475
+ content: [
476
+ { tag: 'participants', attrs: {} },
477
+ { tag: 'description', attrs: {} }
478
+ ]
479
+ }
480
+ ]
481
+ });
482
+ const data = {};
483
+ const communitiesChild = (0, index_js_4.getBinaryNodeChild)(result, 'communities');
484
+ if (communitiesChild) {
485
+ const communities = (0, index_js_4.getBinaryNodeChildren)(communitiesChild, 'community');
486
+ for (const communityNode of communities) {
487
+ const meta = (0, exports.extractCommunityMetadata)({
488
+ tag: 'result',
489
+ attrs: {},
490
+ content: [communityNode]
491
+ });
492
+ data[meta.id] = meta;
493
+ }
494
+ }
495
+ sock.ev.emit('groups.update', Object.values(data));
496
+ return data;
497
+ };
498
+ async function parseGroupResult(node) {
499
+ logger_js_1.default.info({ node }, 'parseGroupResult');
500
+ const groupNode = (0, index_js_4.getBinaryNodeChild)(node, 'group');
501
+ if (groupNode) {
502
+ try {
503
+ logger_js_1.default.info({ groupNode }, 'groupNode');
504
+ const metadata = await sock.groupMetadata(`${groupNode.attrs.id}@g.us`);
505
+ return metadata ? metadata : Optional.empty();
506
+ }
507
+ catch (error) {
508
+ console.error('Error parsing group metadata:', error);
509
+ return Optional.empty();
510
+ }
511
+ }
512
+ return Optional.empty();
513
+ }
514
+ const Optional = {
515
+ empty: () => null,
516
+ of: (value) => (value !== null ? { value } : null)
517
+ };
518
+ sock.ws.on('CB:ib,,dirty', async (node) => {
519
+ const { attrs } = (0, index_js_4.getBinaryNodeChild)(node, 'dirty');
520
+ if (attrs.type !== 'communities') {
521
+ return;
522
+ }
523
+ await communityFetchAllParticipating();
524
+ await sock.cleanDirtyBits('groups');
525
+ });
526
+ return {
527
+ ...sock,
528
+ communityQuery,
529
+ communityMetadata,
530
+ communityCreate: async (subject, body) => {
531
+ const descriptionId = (0, index_js_3.generateMessageID)().substring(0, 12);
532
+ const result = await communityQuery('@g.us', 'set', [
533
+ {
534
+ tag: 'create',
535
+ attrs: { subject },
536
+ content: [
537
+ {
538
+ tag: 'description',
539
+ attrs: { id: descriptionId },
540
+ content: [
541
+ {
542
+ tag: 'body',
543
+ attrs: {},
544
+ content: Buffer.from(body || '', 'utf-8')
545
+ }
546
+ ]
547
+ },
548
+ {
549
+ tag: 'parent',
550
+ attrs: { default_membership_approval_mode: 'request_required' }
551
+ },
552
+ {
553
+ tag: 'allow_non_admin_sub_group_creation',
554
+ attrs: {}
555
+ },
556
+ {
557
+ tag: 'create_general_chat',
558
+ attrs: {}
559
+ }
560
+ ]
561
+ }
562
+ ]);
563
+ return await parseGroupResult(result);
564
+ },
565
+ communityCreateGroup: async (subject, participants, parentCommunityJid) => {
566
+ const key = (0, index_js_3.generateMessageIDV2)();
567
+ const result = await communityQuery('@g.us', 'set', [
568
+ {
569
+ tag: 'create',
570
+ attrs: {
571
+ subject,
572
+ key
573
+ },
574
+ content: [
575
+ ...participants.map(jid => ({
576
+ tag: 'participant',
577
+ attrs: { jid }
578
+ })),
579
+ { tag: 'linked_parent', attrs: { jid: parentCommunityJid } }
580
+ ]
581
+ }
582
+ ]);
583
+ return await parseGroupResult(result);
584
+ },
585
+ communityLeave: async (id) => {
586
+ await communityQuery('@g.us', 'set', [
587
+ {
588
+ tag: 'leave',
589
+ attrs: {},
590
+ content: [{ tag: 'community', attrs: { id } }]
591
+ }
592
+ ]);
593
+ },
594
+ communityUpdateSubject: async (jid, subject) => {
595
+ await communityQuery(jid, 'set', [
596
+ {
597
+ tag: 'subject',
598
+ attrs: {},
599
+ content: Buffer.from(subject, 'utf-8')
600
+ }
601
+ ]);
602
+ },
603
+ communityLinkGroup: async (groupJid, parentCommunityJid) => {
604
+ await communityQuery(parentCommunityJid, 'set', [
605
+ {
606
+ tag: 'links',
607
+ attrs: {},
608
+ content: [
609
+ {
610
+ tag: 'link',
611
+ attrs: { link_type: 'sub_group' },
612
+ content: [{ tag: 'group', attrs: { jid: groupJid } }]
613
+ }
614
+ ]
615
+ }
616
+ ]);
617
+ },
618
+ communityUnlinkGroup: async (groupJid, parentCommunityJid) => {
619
+ await communityQuery(parentCommunityJid, 'set', [
620
+ {
621
+ tag: 'unlink',
622
+ attrs: { unlink_type: 'sub_group' },
623
+ content: [{ tag: 'group', attrs: { jid: groupJid } }]
624
+ }
625
+ ]);
626
+ },
627
+ communityFetchLinkedGroups: async (jid) => {
628
+ let communityJid = jid;
629
+ let isCommunity = false;
630
+ // Try to determine if it is a subgroup or a community
631
+ const metadata = await sock.groupMetadata(jid);
632
+ if (metadata.linkedParent) {
633
+ // It is a subgroup, get the community jid
634
+ communityJid = metadata.linkedParent;
635
+ }
636
+ else {
637
+ // It is a community
638
+ isCommunity = true;
639
+ }
640
+ // Fetch all subgroups of the community
641
+ const result = await communityQuery(communityJid, 'get', [{ tag: 'sub_groups', attrs: {} }]);
642
+ const linkedGroupsData = [];
643
+ const subGroupsNode = (0, index_js_4.getBinaryNodeChild)(result, 'sub_groups');
644
+ if (subGroupsNode) {
645
+ const groupNodes = (0, index_js_4.getBinaryNodeChildren)(subGroupsNode, 'group');
646
+ for (const groupNode of groupNodes) {
647
+ linkedGroupsData.push({
648
+ id: groupNode.attrs.id ? (0, index_js_4.jidEncode)(groupNode.attrs.id, 'g.us') : undefined,
649
+ subject: groupNode.attrs.subject || '',
650
+ creation: groupNode.attrs.creation ? Number(groupNode.attrs.creation) : undefined,
651
+ owner: groupNode.attrs.creator ? (0, index_js_4.jidNormalizedUser)(groupNode.attrs.creator) : undefined,
652
+ size: groupNode.attrs.size ? Number(groupNode.attrs.size) : undefined
653
+ });
654
+ }
655
+ }
656
+ return {
657
+ communityJid,
658
+ isCommunity,
659
+ linkedGroups: linkedGroupsData
660
+ };
661
+ },
662
+ communityRequestParticipantsList: async (jid) => {
663
+ const result = await communityQuery(jid, 'get', [
664
+ {
665
+ tag: 'membership_approval_requests',
666
+ attrs: {}
667
+ }
668
+ ]);
669
+ const node = (0, index_js_4.getBinaryNodeChild)(result, 'membership_approval_requests');
670
+ const participants = (0, index_js_4.getBinaryNodeChildren)(node, 'membership_approval_request');
671
+ return participants.map(v => v.attrs);
672
+ },
673
+ communityRequestParticipantsUpdate: async (jid, participants, action) => {
674
+ const result = await communityQuery(jid, 'set', [
675
+ {
676
+ tag: 'membership_requests_action',
677
+ attrs: {},
678
+ content: [
679
+ {
680
+ tag: action,
681
+ attrs: {},
682
+ content: participants.map(jid => ({
683
+ tag: 'participant',
684
+ attrs: { jid }
685
+ }))
686
+ }
687
+ ]
688
+ }
689
+ ]);
690
+ const node = (0, index_js_4.getBinaryNodeChild)(result, 'membership_requests_action');
691
+ const nodeAction = (0, index_js_4.getBinaryNodeChild)(node, action);
692
+ const participantsAffected = (0, index_js_4.getBinaryNodeChildren)(nodeAction, 'participant');
693
+ return participantsAffected.map(p => {
694
+ return { status: p.attrs.error || '200', jid: p.attrs.jid };
695
+ });
696
+ },
697
+ communityParticipantsUpdate: async (jid, participants, action) => {
698
+ const result = await communityQuery(jid, 'set', [
699
+ {
700
+ tag: action,
701
+ attrs: action === 'remove' ? { linked_groups: 'true' } : {},
702
+ content: participants.map(jid => ({
703
+ tag: 'participant',
704
+ attrs: { jid }
705
+ }))
706
+ }
707
+ ]);
708
+ const node = (0, index_js_4.getBinaryNodeChild)(result, action);
709
+ const participantsAffected = (0, index_js_4.getBinaryNodeChildren)(node, 'participant');
710
+ return participantsAffected.map(p => {
711
+ return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
712
+ });
713
+ },
714
+ communityUpdateDescription: async (jid, description) => {
715
+ const metadata = await communityMetadata(jid);
716
+ const prev = metadata.descId ?? null;
717
+ await communityQuery(jid, 'set', [
718
+ {
719
+ tag: 'description',
720
+ attrs: {
721
+ ...(description ? { id: (0, index_js_3.generateMessageID)() } : { delete: 'true' }),
722
+ ...(prev ? { prev } : {})
723
+ },
724
+ content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
725
+ }
726
+ ]);
727
+ },
728
+ communityInviteCode: async (jid) => {
729
+ const result = await communityQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
730
+ const inviteNode = (0, index_js_4.getBinaryNodeChild)(result, 'invite');
731
+ return inviteNode?.attrs.code;
732
+ },
733
+ communityRevokeInvite: async (jid) => {
734
+ const result = await communityQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
735
+ const inviteNode = (0, index_js_4.getBinaryNodeChild)(result, 'invite');
736
+ return inviteNode?.attrs.code;
737
+ },
738
+ communityAcceptInvite: async (code) => {
739
+ const results = await communityQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
740
+ const result = (0, index_js_4.getBinaryNodeChild)(results, 'community');
741
+ return result?.attrs.jid;
742
+ },
743
+ /**
744
+ * revoke a v4 invite for someone
745
+ * @param communityJid community jid
746
+ * @param invitedJid jid of person you invited
747
+ * @returns true if successful
748
+ */
749
+ communityRevokeInviteV4: async (communityJid, invitedJid) => {
750
+ const result = await communityQuery(communityJid, 'set', [
751
+ { tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
752
+ ]);
753
+ return !!result;
754
+ },
755
+ /**
756
+ * accept a CommunityInviteMessage
757
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
758
+ * @param inviteMessage the message to accept
759
+ */
760
+ communityAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
761
+ key = typeof key === 'string' ? { remoteJid: key } : key;
762
+ const results = await communityQuery(inviteMessage.groupJid, 'set', [
763
+ {
764
+ tag: 'accept',
765
+ attrs: {
766
+ code: inviteMessage.inviteCode,
767
+ expiration: inviteMessage.inviteExpiration.toString(),
768
+ admin: key.remoteJid
769
+ }
770
+ }
771
+ ]);
772
+ // if we have the full message key
773
+ // update the invite message to be expired
774
+ if (key.id) {
775
+ // create new invite message that is expired
776
+ inviteMessage = index_js_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage);
777
+ inviteMessage.inviteExpiration = 0;
778
+ inviteMessage.inviteCode = '';
779
+ ev.emit('messages.update', [
780
+ {
781
+ key,
782
+ update: {
783
+ message: {
784
+ groupInviteMessage: inviteMessage
785
+ }
786
+ }
787
+ }
788
+ ]);
789
+ }
790
+ // generate the community add message
791
+ await upsertMessage({
792
+ key: {
793
+ remoteJid: inviteMessage.groupJid,
794
+ id: (0, index_js_3.generateMessageIDV2)(sock.user?.id),
795
+ fromMe: false,
796
+ participant: key.remoteJid // TODO: investigate if this makes any sense at all
797
+ },
798
+ messageStubType: index_js_2.WAMessageStubType.GROUP_PARTICIPANT_ADD,
799
+ messageStubParameters: [JSON.stringify(authState.creds.me)],
800
+ participant: key.remoteJid,
801
+ messageTimestamp: (0, index_js_3.unixTimestampSeconds)()
802
+ }, 'notify');
803
+ return results.attrs.from;
804
+ }),
805
+ communityGetInviteInfo: async (code) => {
806
+ const results = await communityQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
807
+ return (0, exports.extractCommunityMetadata)(results);
808
+ },
809
+ communityToggleEphemeral: async (jid, ephemeralExpiration) => {
810
+ const content = ephemeralExpiration
811
+ ? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
812
+ : { tag: 'not_ephemeral', attrs: {} };
813
+ await communityQuery(jid, 'set', [content]);
814
+ },
815
+ communitySettingUpdate: async (jid, setting) => {
816
+ await communityQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
817
+ },
818
+ communityMemberAddMode: async (jid, mode) => {
819
+ await communityQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
820
+ },
821
+ communityJoinApprovalMode: async (jid, mode) => {
822
+ await communityQuery(jid, 'set', [
823
+ { tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'community_join', attrs: { state: mode } }] }
824
+ ]);
825
+ },
826
+ communityFetchAllParticipating
827
+ };
828
+ };
829
+ exports.makeCommunitiesSocket = makeCommunitiesSocket;
830
+ const extractCommunityMetadata = (result) => {
831
+ const community = (0, index_js_4.getBinaryNodeChild)(result, 'community');
832
+ const descChild = (0, index_js_4.getBinaryNodeChild)(community, 'description');
833
+ let desc;
834
+ let descId;
835
+ if (descChild) {
836
+ desc = (0, index_js_4.getBinaryNodeChildString)(descChild, 'body');
837
+ descId = descChild.attrs.id;
838
+ }
839
+ const communityId = community.attrs.id?.includes('@')
840
+ ? community.attrs.id
841
+ : (0, index_js_4.jidEncode)(community.attrs.id || '', 'g.us');
842
+ const eph = (0, index_js_4.getBinaryNodeChild)(community, 'ephemeral')?.attrs.expiration;
843
+ const memberAddMode = (0, index_js_4.getBinaryNodeChildString)(community, 'member_add_mode') === 'all_member_add';
844
+ const metadata = {
845
+ id: communityId,
846
+ subject: community.attrs.subject || '',
847
+ subjectOwner: community.attrs.s_o,
848
+ subjectTime: Number(community.attrs.s_t || 0),
849
+ size: (0, index_js_4.getBinaryNodeChildren)(community, 'participant').length,
850
+ creation: Number(community.attrs.creation || 0),
851
+ owner: community.attrs.creator ? (0, index_js_4.jidNormalizedUser)(community.attrs.creator) : undefined,
852
+ desc,
853
+ descId,
854
+ linkedParent: (0, index_js_4.getBinaryNodeChild)(community, 'linked_parent')?.attrs.jid || undefined,
855
+ restrict: !!(0, index_js_4.getBinaryNodeChild)(community, 'locked'),
856
+ announce: !!(0, index_js_4.getBinaryNodeChild)(community, 'announcement'),
857
+ isCommunity: !!(0, index_js_4.getBinaryNodeChild)(community, 'parent'),
858
+ isCommunityAnnounce: !!(0, index_js_4.getBinaryNodeChild)(community, 'default_sub_community'),
859
+ joinApprovalMode: !!(0, index_js_4.getBinaryNodeChild)(community, 'membership_approval_mode'),
860
+ memberAddMode,
861
+ participants: (0, index_js_4.getBinaryNodeChildren)(community, 'participant').map(({ attrs }) => {
862
+ return {
863
+ // TODO: IMPLEMENT THE PN/LID FIELDS HERE!!
864
+ id: attrs.jid,
865
+ admin: (attrs.type || null)
866
+ };
867
+ }),
868
+ ephemeralDuration: eph ? +eph : undefined,
869
+ addressingMode: (0, index_js_4.getBinaryNodeChildString)(community, 'addressing_mode')
870
+ };
871
+ return metadata;
872
+ };
873
+ exports.extractCommunityMetadata = extractCommunityMetadata;
874
+
875
+ return module.exports;
876
+ })();
877
+ for (const key of Object.keys(__kageModule132)) {
878
+ if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule132[key]});
879
+ }
880
+ Object.defineProperty(exports, Symbol.for('kage.advanced'), {value:__kageModule132, configurable:true});