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
@@ -0,0 +1,430 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.extractCommunityMetadata = exports.attachAdvanced = void 0;
7
+ const index_js_1 = require("../../WAProto/index.js");
8
+ const index_js_2 = require("../Types/index.js");
9
+ const index_js_3 = require("../Utils/index.js");
10
+ const logger_js_1 = __importDefault(require("../Utils/logger.js"));
11
+ const index_js_4 = require("../WABinary/index.js");
12
+ const attachAdvanced = (base, config) => {
13
+ const sock = base;
14
+ const { authState, ev, query, upsertMessage } = sock;
15
+ const communityQuery = async (jid, type, content) => query({
16
+ tag: 'iq',
17
+ attrs: {
18
+ type,
19
+ xmlns: 'w:g2',
20
+ to: jid
21
+ },
22
+ content
23
+ });
24
+ const communityMetadata = async (jid) => {
25
+ const result = await communityQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
26
+ return (0, exports.extractCommunityMetadata)(result);
27
+ };
28
+ const communityFetchAllParticipating = async () => {
29
+ const result = await query({
30
+ tag: 'iq',
31
+ attrs: {
32
+ to: '@g.us',
33
+ xmlns: 'w:g2',
34
+ type: 'get'
35
+ },
36
+ content: [
37
+ {
38
+ tag: 'participating',
39
+ attrs: {},
40
+ content: [
41
+ { tag: 'participants', attrs: {} },
42
+ { tag: 'description', attrs: {} }
43
+ ]
44
+ }
45
+ ]
46
+ });
47
+ const data = {};
48
+ const communitiesChild = (0, index_js_4.getBinaryNodeChild)(result, 'communities');
49
+ if (communitiesChild) {
50
+ const communities = (0, index_js_4.getBinaryNodeChildren)(communitiesChild, 'community');
51
+ for (const communityNode of communities) {
52
+ const meta = (0, exports.extractCommunityMetadata)({
53
+ tag: 'result',
54
+ attrs: {},
55
+ content: [communityNode]
56
+ });
57
+ data[meta.id] = meta;
58
+ }
59
+ }
60
+ sock.ev.emit('groups.update', Object.values(data));
61
+ return data;
62
+ };
63
+ async function parseGroupResult(node) {
64
+ logger_js_1.default.info({ node }, 'parseGroupResult');
65
+ const groupNode = (0, index_js_4.getBinaryNodeChild)(node, 'group');
66
+ if (groupNode) {
67
+ try {
68
+ logger_js_1.default.info({ groupNode }, 'groupNode');
69
+ const metadata = await sock.groupMetadata(`${groupNode.attrs.id}@g.us`);
70
+ return metadata ? metadata : Optional.empty();
71
+ }
72
+ catch (error) {
73
+ console.error('Error parsing group metadata:', error);
74
+ return Optional.empty();
75
+ }
76
+ }
77
+ return Optional.empty();
78
+ }
79
+ const Optional = {
80
+ empty: () => null,
81
+ of: (value) => (value !== null ? { value } : null)
82
+ };
83
+ return {
84
+ ...sock,
85
+ communityQuery,
86
+ communityMetadata,
87
+ communityCreate: async (subject, body) => {
88
+ const descriptionId = (0, index_js_3.generateMessageID)().substring(0, 12);
89
+ const result = await communityQuery('@g.us', 'set', [
90
+ {
91
+ tag: 'create',
92
+ attrs: { subject },
93
+ content: [
94
+ {
95
+ tag: 'description',
96
+ attrs: { id: descriptionId },
97
+ content: [
98
+ {
99
+ tag: 'body',
100
+ attrs: {},
101
+ content: Buffer.from(body || '', 'utf-8')
102
+ }
103
+ ]
104
+ },
105
+ {
106
+ tag: 'parent',
107
+ attrs: { default_membership_approval_mode: 'request_required' }
108
+ },
109
+ {
110
+ tag: 'allow_non_admin_sub_group_creation',
111
+ attrs: {}
112
+ },
113
+ {
114
+ tag: 'create_general_chat',
115
+ attrs: {}
116
+ }
117
+ ]
118
+ }
119
+ ]);
120
+ return await parseGroupResult(result);
121
+ },
122
+ communityCreateGroup: async (subject, participants, parentCommunityJid) => {
123
+ const key = (0, index_js_3.generateMessageIDV2)();
124
+ const result = await communityQuery('@g.us', 'set', [
125
+ {
126
+ tag: 'create',
127
+ attrs: {
128
+ subject,
129
+ key
130
+ },
131
+ content: [
132
+ ...participants.map(jid => ({
133
+ tag: 'participant',
134
+ attrs: { jid }
135
+ })),
136
+ { tag: 'linked_parent', attrs: { jid: parentCommunityJid } }
137
+ ]
138
+ }
139
+ ]);
140
+ return await parseGroupResult(result);
141
+ },
142
+ communityLeave: async (id) => {
143
+ await communityQuery('@g.us', 'set', [
144
+ {
145
+ tag: 'leave',
146
+ attrs: {},
147
+ content: [{ tag: 'community', attrs: { id } }]
148
+ }
149
+ ]);
150
+ },
151
+ communityUpdateSubject: async (jid, subject) => {
152
+ await communityQuery(jid, 'set', [
153
+ {
154
+ tag: 'subject',
155
+ attrs: {},
156
+ content: Buffer.from(subject, 'utf-8')
157
+ }
158
+ ]);
159
+ },
160
+ communityLinkGroup: async (groupJid, parentCommunityJid) => {
161
+ await communityQuery(parentCommunityJid, 'set', [
162
+ {
163
+ tag: 'links',
164
+ attrs: {},
165
+ content: [
166
+ {
167
+ tag: 'link',
168
+ attrs: { link_type: 'sub_group' },
169
+ content: [{ tag: 'group', attrs: { jid: groupJid } }]
170
+ }
171
+ ]
172
+ }
173
+ ]);
174
+ },
175
+ communityUnlinkGroup: async (groupJid, parentCommunityJid) => {
176
+ await communityQuery(parentCommunityJid, 'set', [
177
+ {
178
+ tag: 'unlink',
179
+ attrs: { unlink_type: 'sub_group' },
180
+ content: [{ tag: 'group', attrs: { jid: groupJid } }]
181
+ }
182
+ ]);
183
+ },
184
+ communityFetchLinkedGroups: async (jid) => {
185
+ let communityJid = jid;
186
+ let isCommunity = false;
187
+ // Try to determine if it is a subgroup or a community
188
+ const metadata = await sock.groupMetadata(jid);
189
+ if (metadata.linkedParent) {
190
+ // It is a subgroup, get the community jid
191
+ communityJid = metadata.linkedParent;
192
+ }
193
+ else {
194
+ // It is a community
195
+ isCommunity = true;
196
+ }
197
+ // Fetch all subgroups of the community
198
+ const result = await communityQuery(communityJid, 'get', [{ tag: 'sub_groups', attrs: {} }]);
199
+ const linkedGroupsData = [];
200
+ const subGroupsNode = (0, index_js_4.getBinaryNodeChild)(result, 'sub_groups');
201
+ if (subGroupsNode) {
202
+ const groupNodes = (0, index_js_4.getBinaryNodeChildren)(subGroupsNode, 'group');
203
+ for (const groupNode of groupNodes) {
204
+ linkedGroupsData.push({
205
+ id: groupNode.attrs.id ? (0, index_js_4.jidEncode)(groupNode.attrs.id, 'g.us') : undefined,
206
+ subject: groupNode.attrs.subject || '',
207
+ creation: groupNode.attrs.creation ? Number(groupNode.attrs.creation) : undefined,
208
+ owner: groupNode.attrs.creator ? (0, index_js_4.jidNormalizedUser)(groupNode.attrs.creator) : undefined,
209
+ size: groupNode.attrs.size ? Number(groupNode.attrs.size) : undefined
210
+ });
211
+ }
212
+ }
213
+ return {
214
+ communityJid,
215
+ isCommunity,
216
+ linkedGroups: linkedGroupsData
217
+ };
218
+ },
219
+ communityRequestParticipantsList: async (jid) => {
220
+ const result = await communityQuery(jid, 'get', [
221
+ {
222
+ tag: 'membership_approval_requests',
223
+ attrs: {}
224
+ }
225
+ ]);
226
+ const node = (0, index_js_4.getBinaryNodeChild)(result, 'membership_approval_requests');
227
+ const participants = (0, index_js_4.getBinaryNodeChildren)(node, 'membership_approval_request');
228
+ return participants.map(v => v.attrs);
229
+ },
230
+ communityRequestParticipantsUpdate: async (jid, participants, action) => {
231
+ const result = await communityQuery(jid, 'set', [
232
+ {
233
+ tag: 'membership_requests_action',
234
+ attrs: {},
235
+ content: [
236
+ {
237
+ tag: action,
238
+ attrs: {},
239
+ content: participants.map(jid => ({
240
+ tag: 'participant',
241
+ attrs: { jid }
242
+ }))
243
+ }
244
+ ]
245
+ }
246
+ ]);
247
+ const node = (0, index_js_4.getBinaryNodeChild)(result, 'membership_requests_action');
248
+ const nodeAction = (0, index_js_4.getBinaryNodeChild)(node, action);
249
+ const participantsAffected = (0, index_js_4.getBinaryNodeChildren)(nodeAction, 'participant');
250
+ return participantsAffected.map(p => {
251
+ return { status: p.attrs.error || '200', jid: p.attrs.jid };
252
+ });
253
+ },
254
+ communityParticipantsUpdate: async (jid, participants, action) => {
255
+ const result = await communityQuery(jid, 'set', [
256
+ {
257
+ tag: action,
258
+ attrs: action === 'remove' ? { linked_groups: 'true' } : {},
259
+ content: participants.map(jid => ({
260
+ tag: 'participant',
261
+ attrs: { jid }
262
+ }))
263
+ }
264
+ ]);
265
+ const node = (0, index_js_4.getBinaryNodeChild)(result, action);
266
+ const participantsAffected = (0, index_js_4.getBinaryNodeChildren)(node, 'participant');
267
+ return participantsAffected.map(p => {
268
+ return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
269
+ });
270
+ },
271
+ communityUpdateDescription: async (jid, description) => {
272
+ const metadata = await communityMetadata(jid);
273
+ const prev = metadata.descId ?? null;
274
+ await communityQuery(jid, 'set', [
275
+ {
276
+ tag: 'description',
277
+ attrs: {
278
+ ...(description ? { id: (0, index_js_3.generateMessageID)() } : { delete: 'true' }),
279
+ ...(prev ? { prev } : {})
280
+ },
281
+ content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
282
+ }
283
+ ]);
284
+ },
285
+ communityInviteCode: async (jid) => {
286
+ const result = await communityQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
287
+ const inviteNode = (0, index_js_4.getBinaryNodeChild)(result, 'invite');
288
+ return inviteNode?.attrs.code;
289
+ },
290
+ communityRevokeInvite: async (jid) => {
291
+ const result = await communityQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
292
+ const inviteNode = (0, index_js_4.getBinaryNodeChild)(result, 'invite');
293
+ return inviteNode?.attrs.code;
294
+ },
295
+ communityAcceptInvite: async (code) => {
296
+ const results = await communityQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
297
+ const result = (0, index_js_4.getBinaryNodeChild)(results, 'community');
298
+ return result?.attrs.jid;
299
+ },
300
+ /**
301
+ * revoke a v4 invite for someone
302
+ * @param communityJid community jid
303
+ * @param invitedJid jid of person you invited
304
+ * @returns true if successful
305
+ */
306
+ communityRevokeInviteV4: async (communityJid, invitedJid) => {
307
+ const result = await communityQuery(communityJid, 'set', [
308
+ { tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
309
+ ]);
310
+ return !!result;
311
+ },
312
+ /**
313
+ * accept a CommunityInviteMessage
314
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
315
+ * @param inviteMessage the message to accept
316
+ */
317
+ communityAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
318
+ key = typeof key === 'string' ? { remoteJid: key } : key;
319
+ const results = await communityQuery(inviteMessage.groupJid, 'set', [
320
+ {
321
+ tag: 'accept',
322
+ attrs: {
323
+ code: inviteMessage.inviteCode,
324
+ expiration: inviteMessage.inviteExpiration.toString(),
325
+ admin: key.remoteJid
326
+ }
327
+ }
328
+ ]);
329
+ // if we have the full message key
330
+ // update the invite message to be expired
331
+ if (key.id) {
332
+ // create new invite message that is expired
333
+ inviteMessage = index_js_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage);
334
+ inviteMessage.inviteExpiration = 0;
335
+ inviteMessage.inviteCode = '';
336
+ ev.emit('messages.update', [
337
+ {
338
+ key,
339
+ update: {
340
+ message: {
341
+ groupInviteMessage: inviteMessage
342
+ }
343
+ }
344
+ }
345
+ ]);
346
+ }
347
+ // generate the community add message
348
+ await upsertMessage({
349
+ key: {
350
+ remoteJid: inviteMessage.groupJid,
351
+ id: (0, index_js_3.generateMessageIDV2)(sock.user?.id),
352
+ fromMe: false,
353
+ participant: key.remoteJid // TODO: investigate if this makes any sense at all
354
+ },
355
+ messageStubType: index_js_2.WAMessageStubType.GROUP_PARTICIPANT_ADD,
356
+ messageStubParameters: [JSON.stringify(authState.creds.me)],
357
+ participant: key.remoteJid,
358
+ messageTimestamp: (0, index_js_3.unixTimestampSeconds)()
359
+ }, 'notify');
360
+ return results.attrs.from;
361
+ }),
362
+ communityGetInviteInfo: async (code) => {
363
+ const results = await communityQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
364
+ return (0, exports.extractCommunityMetadata)(results);
365
+ },
366
+ communityToggleEphemeral: async (jid, ephemeralExpiration) => {
367
+ const content = ephemeralExpiration
368
+ ? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
369
+ : { tag: 'not_ephemeral', attrs: {} };
370
+ await communityQuery(jid, 'set', [content]);
371
+ },
372
+ communitySettingUpdate: async (jid, setting) => {
373
+ await communityQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
374
+ },
375
+ communityMemberAddMode: async (jid, mode) => {
376
+ await communityQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
377
+ },
378
+ communityJoinApprovalMode: async (jid, mode) => {
379
+ await communityQuery(jid, 'set', [
380
+ { tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'community_join', attrs: { state: mode } }] }
381
+ ]);
382
+ },
383
+ communityFetchAllParticipating
384
+ };
385
+ };
386
+ exports.attachAdvanced = attachAdvanced;
387
+ const extractCommunityMetadata = (result) => {
388
+ const community = (0, index_js_4.getBinaryNodeChild)(result, 'community');
389
+ const descChild = (0, index_js_4.getBinaryNodeChild)(community, 'description');
390
+ let desc;
391
+ let descId;
392
+ if (descChild) {
393
+ desc = (0, index_js_4.getBinaryNodeChildString)(descChild, 'body');
394
+ descId = descChild.attrs.id;
395
+ }
396
+ const communityId = community.attrs.id?.includes('@')
397
+ ? community.attrs.id
398
+ : (0, index_js_4.jidEncode)(community.attrs.id || '', 'g.us');
399
+ const eph = (0, index_js_4.getBinaryNodeChild)(community, 'ephemeral')?.attrs.expiration;
400
+ const memberAddMode = (0, index_js_4.getBinaryNodeChildString)(community, 'member_add_mode') === 'all_member_add';
401
+ const metadata = {
402
+ id: communityId,
403
+ subject: community.attrs.subject || '',
404
+ subjectOwner: community.attrs.s_o,
405
+ subjectTime: Number(community.attrs.s_t || 0),
406
+ size: (0, index_js_4.getBinaryNodeChildren)(community, 'participant').length,
407
+ creation: Number(community.attrs.creation || 0),
408
+ owner: community.attrs.creator ? (0, index_js_4.jidNormalizedUser)(community.attrs.creator) : undefined,
409
+ desc,
410
+ descId,
411
+ linkedParent: (0, index_js_4.getBinaryNodeChild)(community, 'linked_parent')?.attrs.jid || undefined,
412
+ restrict: !!(0, index_js_4.getBinaryNodeChild)(community, 'locked'),
413
+ announce: !!(0, index_js_4.getBinaryNodeChild)(community, 'announcement'),
414
+ isCommunity: !!(0, index_js_4.getBinaryNodeChild)(community, 'parent'),
415
+ isCommunityAnnounce: !!(0, index_js_4.getBinaryNodeChild)(community, 'default_sub_community'),
416
+ joinApprovalMode: !!(0, index_js_4.getBinaryNodeChild)(community, 'membership_approval_mode'),
417
+ memberAddMode,
418
+ participants: (0, index_js_4.getBinaryNodeChildren)(community, 'participant').map(({ attrs }) => {
419
+ return {
420
+ // TODO: IMPLEMENT THE PN/LID FIELDS HERE!!
421
+ id: attrs.jid,
422
+ admin: (attrs.type || null)
423
+ };
424
+ }),
425
+ ephemeralDuration: eph ? +eph : undefined,
426
+ addressingMode: (0, index_js_4.getBinaryNodeChildString)(community, 'addressing_mode')
427
+ };
428
+ return metadata;
429
+ };
430
+ exports.extractCommunityMetadata = extractCommunityMetadata;
@@ -0,0 +1,94 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", { value: true })
3
+ const { proto } = require("../../WAProto")
4
+ const { default: logger } = require("../Utils/logger")
5
+ const {
6
+ WAMessageStubType,
7
+ WAMessageAddressingMode
8
+ } = require("../Types")
9
+ const {
10
+ generateMessageID,
11
+ unixTimestampSeconds
12
+ } = require("../Utils")
13
+ const {
14
+ getBinaryNodeChild,
15
+ getBinaryNodeChildren,
16
+ getBinaryNodeChildString,
17
+ jidEncode,
18
+ jidNormalizedUser
19
+ } = require("../WABinary")
20
+ const { makeBusinessSocket } = require("../Socket/business")
21
+ const extractCommunityMetadata = (result) => {
22
+ const community = getBinaryNodeChild(result, 'group')
23
+ const descChild = getBinaryNodeChild(community, 'description')
24
+
25
+ let desc
26
+ let descId
27
+
28
+ if (descChild) {
29
+ desc = getBinaryNodeChildString(descChild, 'body')
30
+ descId = descChild.attrs.id
31
+ }
32
+
33
+ const mode = community.attrs.addressing_mode
34
+ const communityId = community.attrs.id.includes('@') ? community.attrs.id : jidEncode(community.attrs.id, 'g.us')
35
+ const eph = getBinaryNodeChild(community, 'ephemeral')?.attrs.expiration
36
+ const memberAddMode = getBinaryNodeChildString(community, 'member_add_mode') === 'all_member_add'
37
+
38
+ const metadata = {
39
+ id: communityId,
40
+ subject: community.attrs.subject,
41
+ subjectOwner: community.attrs.s_o,
42
+ subjectOwnerAlt: community.attrs?.s_o_pn ? community.attrs.s_o_pn : community.attrs.s_o,
43
+ subjectTime: Number(community.attrs.s_t || 0),
44
+ size: Number(community.attrs?.size ? community.attrs.size : getBinaryNodeChildren(community, 'participant').length),
45
+ creation: Number(community.attrs.creation || 0),
46
+ owner: community.attrs.creator ? jidNormalizedUser(community.attrs.creator) : undefined,
47
+ ownerAlt: community.attrs.creator ? jidNormalizedUser(community.attrs?.creator_pn ? community.attrs.creator_pn : community.attrs.creator) : undefined,
48
+ ownerCountry: community.attrs.creator_country_code,
49
+ desc,
50
+ descId,
51
+ linkedParent: getBinaryNodeChild(community, 'linked_parent')?.attrs.jid || undefined,
52
+ restrict: !!getBinaryNodeChild(community, 'locked'),
53
+ announce: !!getBinaryNodeChild(community, 'announcement'),
54
+ isCommunity: !!getBinaryNodeChild(community, 'parent'),
55
+ isCommunityAnnounce: !!getBinaryNodeChild(community, 'default_sub_group'),
56
+ joinApprovalMode: !!getBinaryNodeChild(community, 'membership_approval_mode'),
57
+ memberAddMode,
58
+ participants: getBinaryNodeChildren(community, 'participant').map(({ attrs }) => {
59
+ return {
60
+ id: mode === WAMessageAddressingMode.LID ? community.phone_number : attrs.jid,
61
+ lid: mode === WAMessageAddressingMode.LID ? community.jid : attrs.lid,
62
+ admin: (attrs.type || null),
63
+ }
64
+ }),
65
+ ephemeralDuration: eph ? Number(eph) : undefined,
66
+ addressingMode: mode
67
+ }
68
+
69
+ return metadata
70
+ }
71
+
72
+ exports.attach = function(base, config) {
73
+ const suki = base
74
+ const {
75
+ authState,
76
+ ev,
77
+ query,
78
+ groupMetadata,
79
+ upsertMessage,
80
+ cleanDirtyBits
81
+ } = suki
82
+ const communityQuery = (base["communityQuery"] !== undefined ? base["communityQuery"] : (async (jid, type, content) => (query({
83
+ tag: 'iq',
84
+ attrs: {
85
+ type,
86
+ xmlns: 'w:g2',
87
+ to: jid,
88
+ },
89
+ content
90
+ }))))
91
+ return {
92
+ communityQuery
93
+ };
94
+ };