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,1022 @@
1
+ "use strict"
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true })
4
+
5
+ const { proto } = require("../../WAProto")
6
+ const { default: logger } = require("../Utils/logger")
7
+ const {
8
+ WAMessageStubType,
9
+ WAMessageAddressingMode
10
+ } = require("../Types")
11
+ const {
12
+ generateMessageID,
13
+ unixTimestampSeconds
14
+ } = require("../Utils")
15
+ const {
16
+ getBinaryNodeChild,
17
+ getBinaryNodeChildren,
18
+ getBinaryNodeChildString,
19
+ jidEncode,
20
+ jidNormalizedUser
21
+ } = require("../WABinary")
22
+ const { makeBusinessSocket } = require("./business")
23
+
24
+ const makeCommunitiesSocket = (config) => {
25
+ const suki = makeBusinessSocket(config)
26
+ const {
27
+ authState,
28
+ ev,
29
+ query,
30
+ groupMetadata,
31
+ upsertMessage,
32
+ cleanDirtyBits
33
+ } = suki
34
+
35
+ const communityQuery = async (jid, type, content) => (query({
36
+ tag: 'iq',
37
+ attrs: {
38
+ type,
39
+ xmlns: 'w:g2',
40
+ to: jid,
41
+ },
42
+ content
43
+ }))
44
+
45
+ const communityMetadata = async (jid) => {
46
+ const result = await communityQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }])
47
+ return extractCommunityMetadata(result)
48
+ }
49
+
50
+ const communityFetchAllParticipating = async () => {
51
+ const result = await query({
52
+ tag: 'iq',
53
+ attrs: {
54
+ to: '@g.us',
55
+ xmlns: 'w:g2',
56
+ type: 'get',
57
+ },
58
+ content: [
59
+ {
60
+ tag: 'participating',
61
+ attrs: {},
62
+ content: [
63
+ { tag: 'participants', attrs: {} },
64
+ { tag: 'description', attrs: {} }
65
+ ]
66
+ }
67
+ ]
68
+ })
69
+
70
+ const data = {}
71
+ const communitiesChild = getBinaryNodeChild(result, 'communities')
72
+
73
+ if (communitiesChild) {
74
+ const communities = getBinaryNodeChildren(communitiesChild, 'community')
75
+ for (const communityNode of communities) {
76
+ const meta = extractCommunityMetadata({
77
+ tag: 'result',
78
+ attrs: {},
79
+ content: [communityNode]
80
+ })
81
+ data[meta.id] = meta
82
+ }
83
+ }
84
+
85
+ suki.ev.emit('groups.update', Object.values(data))
86
+ return data
87
+ }
88
+
89
+ async function parseGroupResult(node) {
90
+ logger.info({ node }, 'parseGroupResult')
91
+
92
+ const groupNode = getBinaryNodeChild(node, 'group')
93
+
94
+ if (groupNode) {
95
+ try {
96
+ logger.info({ groupNode }, 'groupNode')
97
+
98
+ const metadata = await groupMetadata(`${groupNode.attrs.id}@g.us`)
99
+
100
+ return metadata ? metadata : null
101
+ }
102
+ catch (error) {
103
+ logger.warn({ error }, 'Error parsing group metadata')
104
+ return null
105
+ }
106
+ }
107
+
108
+ return null
109
+ }
110
+
111
+ suki.ws.on('CB:ib,,dirty', async (node) => {
112
+ const { attrs } = getBinaryNodeChild(node, 'dirty')
113
+
114
+ if (attrs.type !== 'communities') {
115
+ return
116
+ }
117
+
118
+ await communityFetchAllParticipating()
119
+ await cleanDirtyBits('groups')
120
+ })
121
+
122
+ return {
123
+ ...suki,
124
+ communityQuery,
125
+ communityMetadata,
126
+ communityCreate: async (subject, body) => {
127
+ const descriptionId = generateMessageID().substring(0, 12)
128
+
129
+ const result = await communityQuery('@g.us', 'set', [
130
+ {
131
+ tag: 'create',
132
+ attrs: { subject },
133
+ content: [{
134
+ tag: 'description',
135
+ attrs: {
136
+ id: descriptionId
137
+ },
138
+ content: [{
139
+ tag: 'body',
140
+ attrs: {},
141
+ content: Buffer.from(body || '', 'utf-8')
142
+ }]
143
+ },
144
+ {
145
+ tag: 'parent',
146
+ attrs: {
147
+ default_membership_approval_mode: 'request_required'
148
+ }
149
+ },
150
+ {
151
+ tag: 'allow_non_admin_sub_group_creation',
152
+ attrs: {}
153
+ },
154
+ {
155
+ tag: 'create_general_chat',
156
+ attrs: {}
157
+ }]
158
+ }
159
+ ])
160
+
161
+ return await parseGroupResult(result)
162
+ },
163
+ communityCreateGroup: async (subject, participants, parentCommunityJid) => {
164
+ const key = generateMessageID()
165
+ const result = await communityQuery('@g.us', 'set', [
166
+ {
167
+ tag: 'create',
168
+ attrs: {
169
+ subject,
170
+ key
171
+ },
172
+ content: [
173
+ ...participants.map(jid => ({
174
+ tag: 'participant',
175
+ attrs: { jid }
176
+ })),
177
+ { tag: 'linked_parent', attrs: { jid: parentCommunityJid } }
178
+ ]
179
+ }
180
+ ])
181
+
182
+ return await parseGroupResult(result)
183
+ },
184
+ communityLeave: async (id) => {
185
+ await communityQuery('@g.us', 'set', [
186
+ {
187
+ tag: 'leave',
188
+ attrs: {},
189
+ content: [
190
+ { tag: 'community', attrs: { id } }
191
+ ]
192
+ }
193
+ ])
194
+ },
195
+ communityUpdateSubject: async (jid, subject) => {
196
+ await communityQuery(jid, 'set', [
197
+ {
198
+ tag: 'subject',
199
+ attrs: {},
200
+ content: Buffer.from(subject, 'utf-8')
201
+ }
202
+ ])
203
+ },
204
+ communityLinkGroup: async (groupJid, parentCommunityJid) => {
205
+ await communityQuery(parentCommunityJid, 'set', [
206
+ {
207
+ tag: 'links',
208
+ attrs: {},
209
+ content: [
210
+ {
211
+ tag: 'link',
212
+ attrs: { link_type: 'sub_group' },
213
+ content: [{ tag: 'group', attrs: { jid: groupJid } }]
214
+ }
215
+ ]
216
+ }
217
+ ])
218
+ },
219
+ communityUnlinkGroup: async (groupJid, parentCommunityJid) => {
220
+ await communityQuery(parentCommunityJid, 'set', [
221
+ {
222
+ tag: 'unlink',
223
+ attrs: { unlink_type: 'sub_group' },
224
+ content: [{ tag: 'group', attrs: { jid: groupJid } }]
225
+ }
226
+ ])
227
+ },
228
+ communityFetchLinkedGroups: async (jid) => {
229
+ let communityJid = jid
230
+ let isCommunity = false
231
+
232
+ // Try to determine if it is a subgroup or a community
233
+ const metadata = await groupMetadata(jid)
234
+
235
+ if (metadata.linkedParent) {
236
+ // It is a subgroup, get the community jid
237
+ communityJid = metadata.linkedParent
238
+ }
239
+
240
+ else {
241
+ // It is a community
242
+ isCommunity = true
243
+ }
244
+
245
+ // Fetch all subgroups of the community
246
+ const result = await communityQuery(communityJid, 'get', [{ tag: 'sub_groups', attrs: {} }])
247
+ const linkedGroupsData = []
248
+ const subGroupsNode = getBinaryNodeChild(result, 'sub_groups')
249
+
250
+ if (subGroupsNode) {
251
+ const groupNodes = getBinaryNodeChildren(subGroupsNode, 'group')
252
+
253
+ for (const groupNode of groupNodes) {
254
+ linkedGroupsData.push({
255
+ id: groupNode.attrs.id ? jidEncode(groupNode.attrs.id, 'g.us') : undefined,
256
+ subject: groupNode.attrs.subject || '',
257
+ creation: groupNode.attrs.creation ? Number(groupNode.attrs.creation) : undefined,
258
+ owner: groupNode.attrs.creator ? jidNormalizedUser(groupNode.attrs.creator) : undefined,
259
+ size: groupNode.attrs.size ? Number(groupNode.attrs.size) : undefined
260
+ })
261
+ }
262
+ }
263
+
264
+ return {
265
+ communityJid,
266
+ isCommunity,
267
+ linkedGroups: linkedGroupsData
268
+ }
269
+ },
270
+ communityRequestParticipantsList: async (jid) => {
271
+ const result = await communityQuery(jid, 'get', [
272
+ {
273
+ tag: 'membership_approval_requests',
274
+ attrs: {}
275
+ }
276
+ ])
277
+
278
+ const node = getBinaryNodeChild(result, 'membership_approval_requests')
279
+ const participants = getBinaryNodeChildren(node, 'membership_approval_request')
280
+
281
+ return participants.map(v => v.attrs)
282
+ },
283
+ communityRequestParticipantsUpdate: async (jid, participants, action) => {
284
+ const result = await communityQuery(jid, 'set', [
285
+ {
286
+ tag: 'membership_requests_action',
287
+ attrs: {},
288
+ content: [
289
+ {
290
+ tag: action,
291
+ attrs: {},
292
+ content: participants.map(jid => ({
293
+ tag: 'participant',
294
+ attrs: { jid }
295
+ }))
296
+ }
297
+ ]
298
+ }
299
+ ])
300
+
301
+ const node = getBinaryNodeChild(result, 'membership_requests_action')
302
+ const nodeAction = getBinaryNodeChild(node, action)
303
+ const participantsAffected = getBinaryNodeChildren(nodeAction, 'participant')
304
+
305
+ return participantsAffected.map(p => {
306
+ return { status: p.attrs.error || '200', jid: p.attrs.jid }
307
+ })
308
+ },
309
+ communityParticipantsUpdate: async (jid, participants, action) => {
310
+ const result = await communityQuery(jid, 'set', [
311
+ {
312
+ tag: action,
313
+ attrs: action === 'remove' ? { linked_groups: 'true' } : {},
314
+ content: participants.map(jid => ({
315
+ tag: 'participant',
316
+ attrs: { jid }
317
+ }))
318
+ }
319
+ ])
320
+
321
+ const node = getBinaryNodeChild(result, action)
322
+ const participantsAffected = getBinaryNodeChildren(node, 'participant')
323
+
324
+ return participantsAffected.map(p => {
325
+ return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p }
326
+ })
327
+ },
328
+ communityUpdateDescription: async (jid, description) => {
329
+ const metadata = await communityMetadata(jid)
330
+ const prev = metadata.descId ?? null
331
+ await communityQuery(jid, 'set', [
332
+ {
333
+ tag: 'description',
334
+ attrs: {
335
+ ...(description ? { id: generateMessageID() } : { delete: 'true' }),
336
+ ...(prev ? { prev } : {})
337
+ },
338
+ content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
339
+ }
340
+ ])
341
+ },
342
+ communityInviteCode: async (jid) => {
343
+ const result = await communityQuery(jid, 'get', [{ tag: 'invite', attrs: {} }])
344
+ const inviteNode = getBinaryNodeChild(result, 'invite')
345
+
346
+ return inviteNode?.attrs.code
347
+ },
348
+ communityRevokeInvite: async (jid) => {
349
+ const result = await communityQuery(jid, 'set', [{ tag: 'invite', attrs: {} }])
350
+ const inviteNode = getBinaryNodeChild(result, 'invite')
351
+
352
+ return inviteNode?.attrs.code
353
+ },
354
+ communityAcceptInvite: async (code) => {
355
+ const results = await communityQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }])
356
+ const result = getBinaryNodeChild(results, 'community')
357
+
358
+ return result?.attrs.jid
359
+ },
360
+ /**
361
+ * revoke a v4 invite for someone
362
+ * @param communityJid community jid
363
+ * @param invitedJid jid of person you invited
364
+ * @returns true if successful
365
+ */
366
+ communityRevokeInviteV4: async (communityJid, invitedJid) => {
367
+ const result = await communityQuery(communityJid, 'set', [
368
+ { tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
369
+ ])
370
+
371
+ return !!result
372
+ },
373
+ /**
374
+ * accept a CommunityInviteMessage
375
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
376
+ * @param inviteMessage the message to accept
377
+ */
378
+ communityAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
379
+ key = typeof key === 'string' ? { remoteJid: key } : key
380
+
381
+ const results = await communityQuery(inviteMessage.groupJid, 'set', [
382
+ {
383
+ tag: 'accept',
384
+ attrs: {
385
+ code: inviteMessage.inviteCode,
386
+ expiration: inviteMessage.inviteExpiration.toString(),
387
+ admin: key.remoteJid
388
+ }
389
+ }
390
+ ])
391
+
392
+ // if we have the full message key
393
+ // update the invite message to be expired
394
+ if (key.id) {
395
+ // create new invite message that is expired
396
+ inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage)
397
+ inviteMessage.inviteExpiration = 0
398
+ inviteMessage.inviteCode = ''
399
+ ev.emit('messages.update', [
400
+ {
401
+ key,
402
+ update: {
403
+ message: {
404
+ groupInviteMessage: inviteMessage
405
+ }
406
+ }
407
+ }
408
+ ])
409
+ }
410
+
411
+ // generate the community add message
412
+ await upsertMessage({
413
+ key: {
414
+ remoteJid: inviteMessage.groupJid,
415
+ id: generateMessageID(suki.user?.id),
416
+ fromMe: false,
417
+ participant: key.remoteJid // TODO: investigate if this makes any sense at all
418
+ },
419
+ messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
420
+ messageStubParameters: [JSON.stringify(authState.creds.me)],
421
+ participant: key.remoteJid,
422
+ messageTimestamp: unixTimestampSeconds()
423
+ }, 'notify')
424
+
425
+ return results.attrs.from
426
+ }),
427
+ communityGetInviteInfo: async (code) => {
428
+ const results = await communityQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }])
429
+ return extractCommunityMetadata(results)
430
+ },
431
+ communityToggleEphemeral: async (jid, ephemeralExpiration) => {
432
+ const content = ephemeralExpiration
433
+ ? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
434
+ : { tag: 'not_ephemeral', attrs: {} }
435
+
436
+ await communityQuery(jid, 'set', [content])
437
+ },
438
+ communitySettingUpdate: async (jid, setting) => {
439
+ await communityQuery(jid, 'set', [{ tag: setting, attrs: {} }])
440
+ },
441
+ communityMemberAddMode: async (jid, mode) => {
442
+ await communityQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }])
443
+ },
444
+ communityJoinApprovalMode: async (jid, mode) => {
445
+ await communityQuery(jid, 'set', [
446
+ { tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'community_join', attrs: { state: mode } }] }
447
+ ])
448
+ },
449
+ communityFetchAllParticipating
450
+ }
451
+ }
452
+
453
+ const extractCommunityMetadata = (result) => {
454
+ const community = getBinaryNodeChild(result, 'group')
455
+ const descChild = getBinaryNodeChild(community, 'description')
456
+
457
+ let desc
458
+ let descId
459
+
460
+ if (descChild) {
461
+ desc = getBinaryNodeChildString(descChild, 'body')
462
+ descId = descChild.attrs.id
463
+ }
464
+
465
+ const mode = community.attrs.addressing_mode
466
+ const communityId = community.attrs.id.includes('@') ? community.attrs.id : jidEncode(community.attrs.id, 'g.us')
467
+ const eph = getBinaryNodeChild(community, 'ephemeral')?.attrs.expiration
468
+ const memberAddMode = getBinaryNodeChildString(community, 'member_add_mode') === 'all_member_add'
469
+
470
+ const metadata = {
471
+ id: communityId,
472
+ subject: community.attrs.subject,
473
+ subjectOwner: community.attrs.s_o,
474
+ subjectOwnerAlt: community.attrs?.s_o_pn ? community.attrs.s_o_pn : community.attrs.s_o,
475
+ subjectTime: Number(community.attrs.s_t || 0),
476
+ size: Number(community.attrs?.size ? community.attrs.size : getBinaryNodeChildren(community, 'participant').length),
477
+ creation: Number(community.attrs.creation || 0),
478
+ owner: community.attrs.creator ? jidNormalizedUser(community.attrs.creator) : undefined,
479
+ ownerAlt: community.attrs.creator ? jidNormalizedUser(community.attrs?.creator_pn ? community.attrs.creator_pn : community.attrs.creator) : undefined,
480
+ ownerCountry: community.attrs.creator_country_code,
481
+ desc,
482
+ descId,
483
+ linkedParent: getBinaryNodeChild(community, 'linked_parent')?.attrs.jid || undefined,
484
+ restrict: !!getBinaryNodeChild(community, 'locked'),
485
+ announce: !!getBinaryNodeChild(community, 'announcement'),
486
+ isCommunity: !!getBinaryNodeChild(community, 'parent'),
487
+ isCommunityAnnounce: !!getBinaryNodeChild(community, 'default_sub_group'),
488
+ joinApprovalMode: !!getBinaryNodeChild(community, 'membership_approval_mode'),
489
+ memberAddMode,
490
+ participants: getBinaryNodeChildren(community, 'participant').map(({ attrs }) => {
491
+ return {
492
+ id: mode === WAMessageAddressingMode.LID ? community.phone_number : attrs.jid,
493
+ lid: mode === WAMessageAddressingMode.LID ? community.jid : attrs.lid,
494
+ admin: (attrs.type || null),
495
+ }
496
+ }),
497
+ ephemeralDuration: eph ? Number(ph) : undefined,
498
+ addressingMode: mode
499
+ }
500
+
501
+ return metadata
502
+ }
503
+
504
+ module.exports = {
505
+ makeCommunitiesSocket,
506
+ extractCommunityMetadata
507
+ }
508
+ // Kage: compatibilidad de API.
509
+ const __kageModule26 = (() => {
510
+ const module = { exports: {} }; const exports = module.exports;
511
+ "use strict"
512
+
513
+ Object.defineProperty(exports, "__esModule", { value: true })
514
+
515
+ const { proto } = require("../../WAProto")
516
+ const { default: logger } = require("../Utils/logger")
517
+ const {
518
+ WAMessageStubType,
519
+ WAMessageAddressingMode
520
+ } = require("../Types")
521
+ const {
522
+ generateMessageID,
523
+ unixTimestampSeconds
524
+ } = require("../Utils")
525
+ const {
526
+ getBinaryNodeChild,
527
+ getBinaryNodeChildren,
528
+ getBinaryNodeChildString,
529
+ jidEncode,
530
+ jidNormalizedUser
531
+ } = require("../WABinary")
532
+ const { makeBusinessSocket } = require("./business")
533
+
534
+ const makeCommunitiesSocket = (config) => {
535
+ const suki = makeBusinessSocket(config)
536
+ const {
537
+ authState,
538
+ ev,
539
+ query,
540
+ groupMetadata,
541
+ upsertMessage,
542
+ cleanDirtyBits
543
+ } = suki
544
+
545
+ const communityQuery = async (jid, type, content) => (query({
546
+ tag: 'iq',
547
+ attrs: {
548
+ type,
549
+ xmlns: 'w:g2',
550
+ to: jid,
551
+ },
552
+ content
553
+ }))
554
+
555
+ const communityMetadata = async (jid) => {
556
+ const result = await communityQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }])
557
+ return extractCommunityMetadata(result)
558
+ }
559
+
560
+ const communityFetchAllParticipating = async () => {
561
+ const result = await query({
562
+ tag: 'iq',
563
+ attrs: {
564
+ to: '@g.us',
565
+ xmlns: 'w:g2',
566
+ type: 'get',
567
+ },
568
+ content: [
569
+ {
570
+ tag: 'participating',
571
+ attrs: {},
572
+ content: [
573
+ { tag: 'participants', attrs: {} },
574
+ { tag: 'description', attrs: {} }
575
+ ]
576
+ }
577
+ ]
578
+ })
579
+
580
+ const data = {}
581
+ const communitiesChild = getBinaryNodeChild(result, 'communities')
582
+
583
+ if (communitiesChild) {
584
+ const communities = getBinaryNodeChildren(communitiesChild, 'community')
585
+ for (const communityNode of communities) {
586
+ const meta = extractCommunityMetadata({
587
+ tag: 'result',
588
+ attrs: {},
589
+ content: [communityNode]
590
+ })
591
+ data[meta.id] = meta
592
+ }
593
+ }
594
+
595
+ suki.ev.emit('groups.update', Object.values(data))
596
+ return data
597
+ }
598
+
599
+ async function parseGroupResult(node) {
600
+ logger.info({ node }, 'parseGroupResult')
601
+
602
+ const groupNode = getBinaryNodeChild(node, 'group')
603
+
604
+ if (groupNode) {
605
+ try {
606
+ logger.info({ groupNode }, 'groupNode')
607
+
608
+ const metadata = await groupMetadata(`${groupNode.attrs.id}@g.us`)
609
+
610
+ return metadata ? metadata : null
611
+ }
612
+ catch (error) {
613
+ logger.warn({ error }, 'Error parsing group metadata')
614
+ return null
615
+ }
616
+ }
617
+
618
+ return null
619
+ }
620
+
621
+ suki.ws.on('CB:ib,,dirty', async (node) => {
622
+ const { attrs } = getBinaryNodeChild(node, 'dirty')
623
+
624
+ if (attrs.type !== 'communities') {
625
+ return
626
+ }
627
+
628
+ await communityFetchAllParticipating()
629
+ await cleanDirtyBits('groups')
630
+ })
631
+
632
+ return {
633
+ ...suki,
634
+ communityQuery,
635
+ communityMetadata,
636
+ communityCreate: async (subject, body) => {
637
+ const descriptionId = generateMessageID().substring(0, 12)
638
+
639
+ const result = await communityQuery('@g.us', 'set', [
640
+ {
641
+ tag: 'create',
642
+ attrs: { subject },
643
+ content: [{
644
+ tag: 'description',
645
+ attrs: {
646
+ id: descriptionId
647
+ },
648
+ content: [{
649
+ tag: 'body',
650
+ attrs: {},
651
+ content: Buffer.from(body || '', 'utf-8')
652
+ }]
653
+ },
654
+ {
655
+ tag: 'parent',
656
+ attrs: {
657
+ default_membership_approval_mode: 'request_required'
658
+ }
659
+ },
660
+ {
661
+ tag: 'allow_non_admin_sub_group_creation',
662
+ attrs: {}
663
+ },
664
+ {
665
+ tag: 'create_general_chat',
666
+ attrs: {}
667
+ }]
668
+ }
669
+ ])
670
+
671
+ return await parseGroupResult(result)
672
+ },
673
+ communityCreateGroup: async (subject, participants, parentCommunityJid) => {
674
+ const key = generateMessageID()
675
+ const result = await communityQuery('@g.us', 'set', [
676
+ {
677
+ tag: 'create',
678
+ attrs: {
679
+ subject,
680
+ key
681
+ },
682
+ content: [
683
+ ...participants.map(jid => ({
684
+ tag: 'participant',
685
+ attrs: { jid }
686
+ })),
687
+ { tag: 'linked_parent', attrs: { jid: parentCommunityJid } }
688
+ ]
689
+ }
690
+ ])
691
+
692
+ return await parseGroupResult(result)
693
+ },
694
+ communityLeave: async (id) => {
695
+ await communityQuery('@g.us', 'set', [
696
+ {
697
+ tag: 'leave',
698
+ attrs: {},
699
+ content: [
700
+ { tag: 'community', attrs: { id } }
701
+ ]
702
+ }
703
+ ])
704
+ },
705
+ communityUpdateSubject: async (jid, subject) => {
706
+ await communityQuery(jid, 'set', [
707
+ {
708
+ tag: 'subject',
709
+ attrs: {},
710
+ content: Buffer.from(subject, 'utf-8')
711
+ }
712
+ ])
713
+ },
714
+ communityLinkGroup: async (groupJid, parentCommunityJid) => {
715
+ await communityQuery(parentCommunityJid, 'set', [
716
+ {
717
+ tag: 'links',
718
+ attrs: {},
719
+ content: [
720
+ {
721
+ tag: 'link',
722
+ attrs: { link_type: 'sub_group' },
723
+ content: [{ tag: 'group', attrs: { jid: groupJid } }]
724
+ }
725
+ ]
726
+ }
727
+ ])
728
+ },
729
+ communityUnlinkGroup: async (groupJid, parentCommunityJid) => {
730
+ await communityQuery(parentCommunityJid, 'set', [
731
+ {
732
+ tag: 'unlink',
733
+ attrs: { unlink_type: 'sub_group' },
734
+ content: [{ tag: 'group', attrs: { jid: groupJid } }]
735
+ }
736
+ ])
737
+ },
738
+ communityFetchLinkedGroups: async (jid) => {
739
+ let communityJid = jid
740
+ let isCommunity = false
741
+
742
+ // Try to determine if it is a subgroup or a community
743
+ const metadata = await groupMetadata(jid)
744
+
745
+ if (metadata.linkedParent) {
746
+ // It is a subgroup, get the community jid
747
+ communityJid = metadata.linkedParent
748
+ }
749
+
750
+ else {
751
+ // It is a community
752
+ isCommunity = true
753
+ }
754
+
755
+ // Fetch all subgroups of the community
756
+ const result = await communityQuery(communityJid, 'get', [{ tag: 'sub_groups', attrs: {} }])
757
+ const linkedGroupsData = []
758
+ const subGroupsNode = getBinaryNodeChild(result, 'sub_groups')
759
+
760
+ if (subGroupsNode) {
761
+ const groupNodes = getBinaryNodeChildren(subGroupsNode, 'group')
762
+
763
+ for (const groupNode of groupNodes) {
764
+ linkedGroupsData.push({
765
+ id: groupNode.attrs.id ? jidEncode(groupNode.attrs.id, 'g.us') : undefined,
766
+ subject: groupNode.attrs.subject || '',
767
+ creation: groupNode.attrs.creation ? Number(groupNode.attrs.creation) : undefined,
768
+ owner: groupNode.attrs.creator ? jidNormalizedUser(groupNode.attrs.creator) : undefined,
769
+ size: groupNode.attrs.size ? Number(groupNode.attrs.size) : undefined
770
+ })
771
+ }
772
+ }
773
+
774
+ return {
775
+ communityJid,
776
+ isCommunity,
777
+ linkedGroups: linkedGroupsData
778
+ }
779
+ },
780
+ communityRequestParticipantsList: async (jid) => {
781
+ const result = await communityQuery(jid, 'get', [
782
+ {
783
+ tag: 'membership_approval_requests',
784
+ attrs: {}
785
+ }
786
+ ])
787
+
788
+ const node = getBinaryNodeChild(result, 'membership_approval_requests')
789
+ const participants = getBinaryNodeChildren(node, 'membership_approval_request')
790
+
791
+ return participants.map(v => v.attrs)
792
+ },
793
+ communityRequestParticipantsUpdate: async (jid, participants, action) => {
794
+ const result = await communityQuery(jid, 'set', [
795
+ {
796
+ tag: 'membership_requests_action',
797
+ attrs: {},
798
+ content: [
799
+ {
800
+ tag: action,
801
+ attrs: {},
802
+ content: participants.map(jid => ({
803
+ tag: 'participant',
804
+ attrs: { jid }
805
+ }))
806
+ }
807
+ ]
808
+ }
809
+ ])
810
+
811
+ const node = getBinaryNodeChild(result, 'membership_requests_action')
812
+ const nodeAction = getBinaryNodeChild(node, action)
813
+ const participantsAffected = getBinaryNodeChildren(nodeAction, 'participant')
814
+
815
+ return participantsAffected.map(p => {
816
+ return { status: p.attrs.error || '200', jid: p.attrs.jid }
817
+ })
818
+ },
819
+ communityParticipantsUpdate: async (jid, participants, action) => {
820
+ const result = await communityQuery(jid, 'set', [
821
+ {
822
+ tag: action,
823
+ attrs: action === 'remove' ? { linked_groups: 'true' } : {},
824
+ content: participants.map(jid => ({
825
+ tag: 'participant',
826
+ attrs: { jid }
827
+ }))
828
+ }
829
+ ])
830
+
831
+ const node = getBinaryNodeChild(result, action)
832
+ const participantsAffected = getBinaryNodeChildren(node, 'participant')
833
+
834
+ return participantsAffected.map(p => {
835
+ return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p }
836
+ })
837
+ },
838
+ communityUpdateDescription: async (jid, description) => {
839
+ const metadata = await communityMetadata(jid)
840
+ const prev = metadata.descId ?? null
841
+ await communityQuery(jid, 'set', [
842
+ {
843
+ tag: 'description',
844
+ attrs: {
845
+ ...(description ? { id: generateMessageID() } : { delete: 'true' }),
846
+ ...(prev ? { prev } : {})
847
+ },
848
+ content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
849
+ }
850
+ ])
851
+ },
852
+ communityInviteCode: async (jid) => {
853
+ const result = await communityQuery(jid, 'get', [{ tag: 'invite', attrs: {} }])
854
+ const inviteNode = getBinaryNodeChild(result, 'invite')
855
+
856
+ return inviteNode?.attrs.code
857
+ },
858
+ communityRevokeInvite: async (jid) => {
859
+ const result = await communityQuery(jid, 'set', [{ tag: 'invite', attrs: {} }])
860
+ const inviteNode = getBinaryNodeChild(result, 'invite')
861
+
862
+ return inviteNode?.attrs.code
863
+ },
864
+ communityAcceptInvite: async (code) => {
865
+ const results = await communityQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }])
866
+ const result = getBinaryNodeChild(results, 'community')
867
+
868
+ return result?.attrs.jid
869
+ },
870
+ /**
871
+ * revoke a v4 invite for someone
872
+ * @param communityJid community jid
873
+ * @param invitedJid jid of person you invited
874
+ * @returns true if successful
875
+ */
876
+ communityRevokeInviteV4: async (communityJid, invitedJid) => {
877
+ const result = await communityQuery(communityJid, 'set', [
878
+ { tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
879
+ ])
880
+
881
+ return !!result
882
+ },
883
+ /**
884
+ * accept a CommunityInviteMessage
885
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
886
+ * @param inviteMessage the message to accept
887
+ */
888
+ communityAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
889
+ key = typeof key === 'string' ? { remoteJid: key } : key
890
+
891
+ const results = await communityQuery(inviteMessage.groupJid, 'set', [
892
+ {
893
+ tag: 'accept',
894
+ attrs: {
895
+ code: inviteMessage.inviteCode,
896
+ expiration: inviteMessage.inviteExpiration.toString(),
897
+ admin: key.remoteJid
898
+ }
899
+ }
900
+ ])
901
+
902
+ // if we have the full message key
903
+ // update the invite message to be expired
904
+ if (key.id) {
905
+ // create new invite message that is expired
906
+ inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage)
907
+ inviteMessage.inviteExpiration = 0
908
+ inviteMessage.inviteCode = ''
909
+ ev.emit('messages.update', [
910
+ {
911
+ key,
912
+ update: {
913
+ message: {
914
+ groupInviteMessage: inviteMessage
915
+ }
916
+ }
917
+ }
918
+ ])
919
+ }
920
+
921
+ // generate the community add message
922
+ await upsertMessage({
923
+ key: {
924
+ remoteJid: inviteMessage.groupJid,
925
+ id: generateMessageID(suki.user?.id),
926
+ fromMe: false,
927
+ participant: key.remoteJid // TODO: investigate if this makes any sense at all
928
+ },
929
+ messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
930
+ messageStubParameters: [JSON.stringify(authState.creds.me)],
931
+ participant: key.remoteJid,
932
+ messageTimestamp: unixTimestampSeconds()
933
+ }, 'notify')
934
+
935
+ return results.attrs.from
936
+ }),
937
+ communityGetInviteInfo: async (code) => {
938
+ const results = await communityQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }])
939
+ return extractCommunityMetadata(results)
940
+ },
941
+ communityToggleEphemeral: async (jid, ephemeralExpiration) => {
942
+ const content = ephemeralExpiration
943
+ ? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
944
+ : { tag: 'not_ephemeral', attrs: {} }
945
+
946
+ await communityQuery(jid, 'set', [content])
947
+ },
948
+ communitySettingUpdate: async (jid, setting) => {
949
+ await communityQuery(jid, 'set', [{ tag: setting, attrs: {} }])
950
+ },
951
+ communityMemberAddMode: async (jid, mode) => {
952
+ await communityQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }])
953
+ },
954
+ communityJoinApprovalMode: async (jid, mode) => {
955
+ await communityQuery(jid, 'set', [
956
+ { tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'community_join', attrs: { state: mode } }] }
957
+ ])
958
+ },
959
+ communityFetchAllParticipating
960
+ }
961
+ }
962
+
963
+ const extractCommunityMetadata = (result) => {
964
+ const community = getBinaryNodeChild(result, 'group')
965
+ const descChild = getBinaryNodeChild(community, 'description')
966
+
967
+ let desc
968
+ let descId
969
+
970
+ if (descChild) {
971
+ desc = getBinaryNodeChildString(descChild, 'body')
972
+ descId = descChild.attrs.id
973
+ }
974
+
975
+ const mode = community.attrs.addressing_mode
976
+ const communityId = community.attrs.id.includes('@') ? community.attrs.id : jidEncode(community.attrs.id, 'g.us')
977
+ const eph = getBinaryNodeChild(community, 'ephemeral')?.attrs.expiration
978
+ const memberAddMode = getBinaryNodeChildString(community, 'member_add_mode') === 'all_member_add'
979
+
980
+ const metadata = {
981
+ id: communityId,
982
+ subject: community.attrs.subject,
983
+ subjectOwner: community.attrs.s_o,
984
+ subjectOwnerAlt: community.attrs?.s_o_pn ? community.attrs.s_o_pn : community.attrs.s_o,
985
+ subjectTime: Number(community.attrs.s_t || 0),
986
+ size: Number(community.attrs?.size ? community.attrs.size : getBinaryNodeChildren(community, 'participant').length),
987
+ creation: Number(community.attrs.creation || 0),
988
+ owner: community.attrs.creator ? jidNormalizedUser(community.attrs.creator) : undefined,
989
+ ownerAlt: community.attrs.creator ? jidNormalizedUser(community.attrs?.creator_pn ? community.attrs.creator_pn : community.attrs.creator) : undefined,
990
+ ownerCountry: community.attrs.creator_country_code,
991
+ desc,
992
+ descId,
993
+ linkedParent: getBinaryNodeChild(community, 'linked_parent')?.attrs.jid || undefined,
994
+ restrict: !!getBinaryNodeChild(community, 'locked'),
995
+ announce: !!getBinaryNodeChild(community, 'announcement'),
996
+ isCommunity: !!getBinaryNodeChild(community, 'parent'),
997
+ isCommunityAnnounce: !!getBinaryNodeChild(community, 'default_sub_group'),
998
+ joinApprovalMode: !!getBinaryNodeChild(community, 'membership_approval_mode'),
999
+ memberAddMode,
1000
+ participants: getBinaryNodeChildren(community, 'participant').map(({ attrs }) => {
1001
+ return {
1002
+ id: mode === WAMessageAddressingMode.LID ? community.phone_number : attrs.jid,
1003
+ lid: mode === WAMessageAddressingMode.LID ? community.jid : attrs.lid,
1004
+ admin: (attrs.type || null),
1005
+ }
1006
+ }),
1007
+ ephemeralDuration: eph ? Number(ph) : undefined,
1008
+ addressingMode: mode
1009
+ }
1010
+
1011
+ return metadata
1012
+ }
1013
+
1014
+ module.exports = {
1015
+ makeCommunitiesSocket,
1016
+ extractCommunityMetadata
1017
+ }
1018
+ return module.exports;
1019
+ })();
1020
+ for (const key of Object.keys(__kageModule26)) {
1021
+ if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule26[key]});
1022
+ }