kage-baileys 3.0.6 → 3.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. package/Example/connection.cjs +4 -0
  2. package/README.MD +4726 -48
  3. package/WAProto/WAProto.proto +3395 -415
  4. package/WAProto/compat.cjs +12 -0
  5. package/WAProto/index.d.ts +47104 -19888
  6. package/WAProto/index.js +131979 -57361
  7. package/lib/Addon/http-error.js +43 -0
  8. package/lib/Addon/index.js +32 -0
  9. package/lib/Addon/keyed-db.js +250 -0
  10. package/lib/Addon/link-preview.js +82 -0
  11. package/lib/Defaults/baileys-version.json +3 -0
  12. package/lib/Defaults/connection.js +110 -0
  13. package/lib/Defaults/constants.js +156 -0
  14. package/lib/Defaults/history.js +46 -0
  15. package/lib/Defaults/index.js +230 -0
  16. package/lib/Defaults/media.js +104 -0
  17. package/lib/Defaults/phonenumber-mcc.json +223 -0
  18. package/lib/Defaults/prefix.js +44 -0
  19. package/lib/Extensions/business-advanced.js +382 -0
  20. package/lib/Extensions/business.js +159 -0
  21. package/lib/Extensions/chats-advanced.js +1106 -0
  22. package/lib/Extensions/chats.js +349 -0
  23. package/lib/Extensions/communities-advanced.js +430 -0
  24. package/lib/Extensions/community.js +94 -0
  25. package/lib/Extensions/groups-advanced.js +343 -0
  26. package/lib/Extensions/index.js +30 -0
  27. package/lib/Extensions/messages-recv-advanced.js +1690 -0
  28. package/lib/Extensions/messages-send-advanced.js +622 -0
  29. package/lib/Extensions/messages-send.js +1380 -0
  30. package/lib/Extensions/newsletter-advanced.js +228 -0
  31. package/lib/Extensions/newsletter.js +72 -0
  32. package/lib/Extensions/socket.js +389 -0
  33. package/lib/Modded/message_builder.js +2084 -4
  34. package/lib/Signal/Group/ciphertext-message.js +54 -0
  35. package/lib/Signal/Group/group-session-builder.js +124 -0
  36. package/lib/Signal/Group/group_cipher.js +216 -0
  37. package/lib/Signal/Group/index.js +124 -0
  38. package/lib/Signal/Group/keyhelper.js +108 -0
  39. package/lib/Signal/Group/sender-chain-key.js +83 -0
  40. package/lib/Signal/Group/sender-key-distribution-message.js +157 -0
  41. package/lib/Signal/Group/sender-key-message.js +166 -0
  42. package/lib/Signal/Group/sender-key-name.js +130 -0
  43. package/lib/Signal/Group/sender-key-record.js +113 -0
  44. package/lib/Signal/Group/sender-key-state.js +208 -0
  45. package/lib/Signal/Group/sender-message-key.js +82 -0
  46. package/lib/Signal/libsignal.js +935 -0
  47. package/lib/Signal/lid-mapping.js +545 -1
  48. package/lib/Socket/Client/index.js +60 -0
  49. package/lib/Socket/Client/types.js +51 -0
  50. package/lib/Socket/Client/websocket.js +152 -0
  51. package/lib/Socket/business.js +831 -0
  52. package/lib/Socket/chats.js +2535 -49
  53. package/lib/Socket/communities.js +450 -1
  54. package/lib/Socket/community.js +1022 -0
  55. package/lib/Socket/dugong.js +1 -1
  56. package/lib/Socket/groups.js +747 -0
  57. package/lib/Socket/index.js +60 -2
  58. package/lib/Socket/messages-recv.js +3450 -5
  59. package/lib/Socket/messages-send.js +3123 -0
  60. package/lib/Socket/mex.js +126 -1
  61. package/lib/Socket/newsletter.js +465 -0
  62. package/lib/Socket/socket.js +2217 -1
  63. package/lib/Store/index.js +79 -0
  64. package/lib/Store/make-cache-manager-store.js +186 -0
  65. package/lib/Store/make-in-memory-store.js +878 -0
  66. package/lib/Store/make-ordered-dictionary.js +187 -0
  67. package/lib/Store/object-repository.js +78 -0
  68. package/lib/Types/Auth.js +25 -0
  69. package/lib/Types/Bussines.js +25 -1
  70. package/lib/Types/Call.js +25 -0
  71. package/lib/Types/Chat.js +39 -0
  72. package/lib/Types/Contact.js +25 -0
  73. package/lib/Types/Events.js +25 -0
  74. package/lib/Types/GroupMetadata.js +25 -0
  75. package/lib/Types/Label.js +76 -0
  76. package/lib/Types/LabelAssociation.js +40 -0
  77. package/lib/Types/Message.js +57 -0
  78. package/lib/Types/Mex.js +56 -1
  79. package/lib/Types/MexUpdates.js +46 -0
  80. package/lib/Types/Newsletter.js +56 -0
  81. package/lib/Types/Product.js +25 -0
  82. package/lib/Types/RichType.js +23 -0
  83. package/lib/Types/Signal.js +25 -0
  84. package/lib/Types/Socket.js +25 -0
  85. package/lib/Types/State.js +92 -0
  86. package/lib/Types/USync.js +25 -0
  87. package/lib/Types/index.js +133 -0
  88. package/lib/Utils/auth-utils.js +703 -0
  89. package/lib/Utils/automation-tools.js +51 -16
  90. package/lib/Utils/baileys-event-stream.js +146 -0
  91. package/lib/Utils/browser-utils.js +95 -0
  92. package/lib/Utils/business.js +525 -0
  93. package/lib/Utils/chat-utils.js +1861 -0
  94. package/lib/Utils/companion-reg-client-utils.js +55 -1
  95. package/lib/Utils/crypto.js +355 -0
  96. package/lib/Utils/decode-wa-message.js +709 -0
  97. package/lib/Utils/event-buffer.js +1323 -8
  98. package/lib/Utils/generics.js +945 -1
  99. package/lib/Utils/history.js +266 -0
  100. package/lib/Utils/identity-change-handler.js +62 -1
  101. package/lib/Utils/index.js +114 -0
  102. package/lib/Utils/link-preview.js +179 -0
  103. package/lib/Utils/logger.js +42 -0
  104. package/lib/Utils/lt-hash.js +73 -0
  105. package/lib/Utils/make-mutex.js +104 -0
  106. package/lib/Utils/message-inspector.js +110 -0
  107. package/lib/Utils/message-retry-manager.js +507 -2
  108. package/lib/Utils/messages-media.js +1931 -1
  109. package/lib/Utils/messages.js +3748 -0
  110. package/lib/Utils/noise-handler.js +423 -0
  111. package/lib/Utils/offline-node-processor.js +53 -1
  112. package/lib/Utils/pre-key-manager.js +255 -1
  113. package/lib/Utils/process-message.js +1592 -0
  114. package/lib/Utils/reporting-utils.js +272 -1
  115. package/lib/Utils/rich-message-utils.js +377 -0
  116. package/lib/Utils/rich-messages.js +1 -1
  117. package/lib/Utils/signal.js +437 -0
  118. package/lib/Utils/stanza-ack.js +51 -1
  119. package/lib/Utils/status-refresh.js +37 -0
  120. package/lib/Utils/status-tools.js +4 -2
  121. package/lib/Utils/sync-action-utils.js +63 -1
  122. package/lib/Utils/tc-token-utils.js +185 -1
  123. package/lib/Utils/terminal-banner.js +31 -0
  124. package/lib/Utils/use-multi-file-auth-state.js +271 -0
  125. package/lib/Utils/use-single-file-auth-state.js +108 -0
  126. package/lib/Utils/use-sqlite-auth-state.js +142 -0
  127. package/lib/Utils/validate-connection.js +497 -1
  128. package/lib/Utils/view-once-compat.js +13 -5
  129. package/lib/VoIP/audio-feeder.js +150 -0
  130. package/lib/VoIP/index.js +289 -0
  131. package/lib/VoIP/relay-transport.js +608 -0
  132. package/lib/VoIP/signaling.js +583 -0
  133. package/lib/VoIP/types.js +30 -0
  134. package/lib/VoIP/wasm-engine.js +1261 -2
  135. package/lib/VoIP/worker-bootstrap.js +1090 -2
  136. package/lib/WABinary/constants.js +2805 -0
  137. package/lib/WABinary/decode.js +649 -2
  138. package/lib/WABinary/encode.js +564 -2
  139. package/lib/WABinary/generic-utils.js +401 -0
  140. package/lib/WABinary/index.js +82 -0
  141. package/lib/WABinary/jid-utils.js +290 -0
  142. package/lib/WABinary/types.js +25 -0
  143. package/lib/WAM/BinaryInfo.js +50 -0
  144. package/lib/WAM/constants.js +45747 -0
  145. package/lib/WAM/encode.js +393 -0
  146. package/lib/WAM/index.js +78 -0
  147. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +135 -0
  148. package/lib/WAUSync/Protocols/USyncContactProtocol.js +110 -0
  149. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +142 -0
  150. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +85 -0
  151. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +69 -0
  152. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +107 -0
  153. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +38 -1
  154. package/lib/WAUSync/Protocols/index.js +83 -0
  155. package/lib/WAUSync/USyncQuery.js +241 -2
  156. package/lib/WAUSync/USyncUser.js +86 -0
  157. package/lib/WAUSync/index.js +78 -0
  158. package/lib/assets/wasm/loader.js +1875 -1
  159. package/lib/assets/wasm/worker-modules.js +11047 -1
  160. package/lib/index.d.ts +126 -0
  161. package/lib/index.js +53 -21
  162. package/lib/index.mjs +437 -0
  163. package/licenses/upstream-MIT.txt +22 -0
  164. package/maintenance/api-coverage.json +1642 -0
  165. package/maintenance/archivos-sha256.json +207 -0
  166. package/maintenance/consumer-validation.log +3 -0
  167. package/maintenance/dependency-audit.json +4 -4
  168. package/maintenance/extension-inventory.json +57 -0
  169. package/maintenance/protocol-update.json +1101 -0
  170. package/maintenance/protocol-wire-audit.json +4 -0
  171. package/maintenance/reference-socket-surface.json +209 -0
  172. package/maintenance/resumen-validacion.json +50 -0
  173. package/maintenance/validation.log +2725 -0
  174. package/maintenance/verification.json +566 -0
  175. package/package.json +107 -9
  176. package/scripts/check-imports.cjs +10 -0
  177. package/scripts/check-package.cjs +40 -0
  178. package/scripts/check-syntax.cjs +1 -1
  179. package/scripts/generate-protobuf.cjs +6 -1
  180. package/scripts/generate-public-types.cjs +9 -0
  181. package/scripts/kage-base64-fix.cjs +45 -0
  182. package/scripts/maintenance.cjs +10 -0
  183. package/test/advanced.test.cjs +24 -0
  184. package/test/base64-fix.test.cjs +49 -0
  185. package/test/maintenance.test.cjs +1 -1
  186. package/test/npm-publication.test.cjs +141 -0
  187. package/test/recepcion-reparada.test.cjs +98 -0
  188. package/test/resilience-binary.test.cjs +69 -0
  189. package/test/resilience-transport.test.cjs +34 -0
  190. package/test/types.test.ts +5 -0
  191. package/test/upgrade.test.cjs +104 -0
  192. package/tsconfig.json +20 -0
  193. package/WAProto/p.html +0 -1
  194. package/lib/KageExtra/Modded/message_builder.js +0 -2330
  195. package/lib/KageExtra/VoIP/audio-feeder.js +0 -136
  196. package/lib/KageExtra/VoIP/index.js +0 -282
  197. package/lib/KageExtra/VoIP/relay-transport.js +0 -559
  198. package/lib/KageExtra/VoIP/signaling.js +0 -603
  199. package/lib/KageExtra/VoIP/types.js +0 -17
  200. package/lib/KageExtra/VoIP/wasm-engine.js +0 -1214
  201. package/lib/KageExtra/VoIP/worker-bootstrap.js +0 -1042
  202. package/lib/KageExtra/assets/wasm/loader.js +0 -5
  203. package/lib/KageExtra/assets/wasm/whatsapp.wasm +0 -0
  204. package/lib/KageExtra/assets/wasm/worker-modules.js +0 -273
  205. package/lib/KageExtra/index.js +0 -3
  206. package/lib/KageExtra/package.json +0 -1
  207. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -53
  208. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -24
  209. package/maintenance/revision-full-check.txt +0 -1097
  210. package/maintenance/revision-library-tests.tap +0 -1088
  211. package/maintenance/revision-protobuf.txt +0 -5
  212. package/maintenance/revision-syntax.txt +0 -5
  213. package/maintenance/schema-coverage.json +0 -23
  214. package/maintenance/schema-merge.json +0 -30
  215. package/maintenance/validation-node20.txt +0 -191
  216. package/maintenance/validation-node22.txt +0 -237
@@ -0,0 +1,343 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractGroupMetadata = exports.attachAdvanced = void 0;
4
+ const index_js_1 = require("../../WAProto/index.js");
5
+ const index_js_2 = require("../Addon/index.js");
6
+ const index_js_3 = require("../Types/index.js");
7
+ const index_js_4 = require("../Utils/index.js");
8
+ const index_js_5 = require("../WABinary/index.js");
9
+ const attachAdvanced = (base, config) => {
10
+ const sock = base;
11
+ const { authState, ev, query, upsertMessage } = sock;
12
+ const groupQuery = async (jid, type, content) => query({
13
+ tag: 'iq',
14
+ attrs: {
15
+ type,
16
+ xmlns: 'w:g2',
17
+ to: jid
18
+ },
19
+ content
20
+ });
21
+ const groupMetadata = async (jid) => {
22
+ const result = await groupQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
23
+ return (0, exports.extractGroupMetadata)(result);
24
+ };
25
+ const groupFetchAllParticipating = async () => {
26
+ const result = await query({
27
+ tag: 'iq',
28
+ attrs: {
29
+ to: '@g.us',
30
+ xmlns: 'w:g2',
31
+ type: 'get'
32
+ },
33
+ content: [
34
+ {
35
+ tag: 'participating',
36
+ attrs: {},
37
+ content: [
38
+ { tag: 'participants', attrs: {} },
39
+ { tag: 'description', attrs: {} }
40
+ ]
41
+ }
42
+ ]
43
+ });
44
+ const data = {};
45
+ const groupsChild = (0, index_js_5.getBinaryNodeChild)(result, 'groups');
46
+ if (groupsChild) {
47
+ const groups = (0, index_js_5.getBinaryNodeChildren)(groupsChild, 'group');
48
+ for (const groupNode of groups) {
49
+ const meta = (0, exports.extractGroupMetadata)({
50
+ tag: 'result',
51
+ attrs: {},
52
+ content: [groupNode]
53
+ });
54
+ data[meta.id] = meta;
55
+ }
56
+ }
57
+ // TODO: properly parse LID / PN DATA
58
+ sock.ev.emit('groups.update', Object.values(data));
59
+ return data;
60
+ };
61
+ return {
62
+ ...sock,
63
+ groupQuery,
64
+ groupMetadata,
65
+ groupCreate: async (subject, participants) => {
66
+ const key = (0, index_js_4.generateMessageIDV2)();
67
+ const result = await groupQuery('@g.us', 'set', [
68
+ {
69
+ tag: 'create',
70
+ attrs: {
71
+ subject,
72
+ key
73
+ },
74
+ content: participants.map(jid => ({
75
+ tag: 'participant',
76
+ attrs: { jid }
77
+ }))
78
+ }
79
+ ]);
80
+ return (0, exports.extractGroupMetadata)(result);
81
+ },
82
+ groupLeave: async (id) => {
83
+ await groupQuery('@g.us', 'set', [
84
+ {
85
+ tag: 'leave',
86
+ attrs: {},
87
+ content: [{ tag: 'group', attrs: { id } }]
88
+ }
89
+ ]);
90
+ },
91
+ groupUpdateSubject: async (jid, subject) => {
92
+ await groupQuery(jid, 'set', [
93
+ {
94
+ tag: 'subject',
95
+ attrs: {},
96
+ content: Buffer.from(subject, 'utf-8')
97
+ }
98
+ ]);
99
+ },
100
+ groupRequestParticipantsList: async (jid) => {
101
+ const result = await groupQuery(jid, 'get', [
102
+ {
103
+ tag: 'membership_approval_requests',
104
+ attrs: {}
105
+ }
106
+ ]);
107
+ const node = (0, index_js_5.getBinaryNodeChild)(result, 'membership_approval_requests');
108
+ const participants = (0, index_js_5.getBinaryNodeChildren)(node, 'membership_approval_request');
109
+ return participants.map(v => v.attrs);
110
+ },
111
+ groupRequestParticipantsUpdate: async (jid, participants, action) => {
112
+ const result = await groupQuery(jid, 'set', [
113
+ {
114
+ tag: 'membership_requests_action',
115
+ attrs: {},
116
+ content: [
117
+ {
118
+ tag: action,
119
+ attrs: {},
120
+ content: participants.map(jid => ({
121
+ tag: 'participant',
122
+ attrs: { jid }
123
+ }))
124
+ }
125
+ ]
126
+ }
127
+ ]);
128
+ const node = (0, index_js_5.getBinaryNodeChild)(result, 'membership_requests_action');
129
+ const nodeAction = (0, index_js_5.getBinaryNodeChild)(node, action);
130
+ const participantsAffected = (0, index_js_5.getBinaryNodeChildren)(nodeAction, 'participant');
131
+ return participantsAffected.map(p => {
132
+ return { status: p.attrs.error || '200', jid: p.attrs.jid };
133
+ });
134
+ },
135
+ groupParticipantsUpdate: async (jid, participants, action) => {
136
+ const result = await groupQuery(jid, 'set', [
137
+ {
138
+ tag: action,
139
+ attrs: {},
140
+ content: participants.map(jid => ({
141
+ tag: 'participant',
142
+ attrs: { jid }
143
+ }))
144
+ }
145
+ ]);
146
+ const node = (0, index_js_5.getBinaryNodeChild)(result, action);
147
+ const participantsAffected = (0, index_js_5.getBinaryNodeChildren)(node, 'participant');
148
+ return participantsAffected.map(p => {
149
+ return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
150
+ });
151
+ },
152
+ groupUpdateDescription: async (jid, description) => {
153
+ const metadata = await groupMetadata(jid);
154
+ const prev = metadata.descId ?? null;
155
+ await groupQuery(jid, 'set', [
156
+ {
157
+ tag: 'description',
158
+ attrs: {
159
+ ...(description ? { id: (0, index_js_4.generateMessageIDV2)() } : { delete: 'true' }),
160
+ ...(prev ? { prev } : {})
161
+ },
162
+ content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
163
+ }
164
+ ]);
165
+ },
166
+ groupInviteCode: async (jid) => {
167
+ const result = await groupQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
168
+ const inviteNode = (0, index_js_5.getBinaryNodeChild)(result, 'invite');
169
+ return inviteNode?.attrs.code;
170
+ },
171
+ groupRevokeInvite: async (jid) => {
172
+ const result = await groupQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
173
+ const inviteNode = (0, index_js_5.getBinaryNodeChild)(result, 'invite');
174
+ return inviteNode?.attrs.code;
175
+ },
176
+ groupAcceptInvite: async (code) => {
177
+ const results = await groupQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
178
+ const result = (0, index_js_5.getBinaryNodeChild)(results, 'group');
179
+ return result?.attrs.jid;
180
+ },
181
+ /**
182
+ * revoke a v4 invite for someone
183
+ * @param groupJid group jid
184
+ * @param invitedJid jid of person you invited
185
+ * @returns true if successful
186
+ */
187
+ groupRevokeInviteV4: async (groupJid, invitedJid) => {
188
+ const result = await groupQuery(groupJid, 'set', [
189
+ { tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
190
+ ]);
191
+ return !!result;
192
+ },
193
+ /**
194
+ * accept a GroupInviteMessage
195
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
196
+ * @param inviteMessage the message to accept
197
+ */
198
+ groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
199
+ key = typeof key === 'string' ? { remoteJid: key } : key;
200
+ const results = await groupQuery(inviteMessage.groupJid, 'set', [
201
+ {
202
+ tag: 'accept',
203
+ attrs: {
204
+ code: inviteMessage.inviteCode,
205
+ expiration: inviteMessage.inviteExpiration.toString(),
206
+ admin: key.remoteJid
207
+ }
208
+ }
209
+ ]);
210
+ // if we have the full message key
211
+ // update the invite message to be expired
212
+ if (key.id) {
213
+ // create new invite message that is expired
214
+ inviteMessage = index_js_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage);
215
+ inviteMessage.inviteExpiration = 0;
216
+ inviteMessage.inviteCode = '';
217
+ ev.emit('messages.update', [
218
+ {
219
+ key,
220
+ update: {
221
+ message: {
222
+ groupInviteMessage: inviteMessage
223
+ }
224
+ }
225
+ }
226
+ ]);
227
+ }
228
+ // generate the group add message
229
+ await upsertMessage({
230
+ key: {
231
+ remoteJid: inviteMessage.groupJid,
232
+ id: (0, index_js_4.generateMessageIDV2)(sock.user?.id),
233
+ fromMe: false,
234
+ participant: key.remoteJid
235
+ },
236
+ messageStubType: index_js_3.WAMessageStubType.GROUP_PARTICIPANT_ADD,
237
+ messageStubParameters: [JSON.stringify(authState.creds.me)],
238
+ participant: key.remoteJid,
239
+ messageTimestamp: (0, index_js_4.unixTimestampSeconds)()
240
+ }, 'notify');
241
+ return results.attrs.from;
242
+ }),
243
+ groupGetInviteInfo: async (code) => {
244
+ const results = await groupQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
245
+ return (0, exports.extractGroupMetadata)(results);
246
+ },
247
+ groupToggleEphemeral: async (jid, ephemeralExpiration) => {
248
+ const content = ephemeralExpiration
249
+ ? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
250
+ : { tag: 'not_ephemeral', attrs: {} };
251
+ await groupQuery(jid, 'set', [content]);
252
+ },
253
+ groupSettingUpdate: async (jid, setting) => {
254
+ await groupQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
255
+ },
256
+ groupMemberAddMode: async (jid, mode) => {
257
+ await groupQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
258
+ },
259
+ groupJoinApprovalMode: async (jid, mode) => {
260
+ await groupQuery(jid, 'set', [
261
+ { tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }
262
+ ]);
263
+ },
264
+ groupFetchAllParticipating
265
+ };
266
+ };
267
+ exports.attachAdvanced = attachAdvanced;
268
+ const extractGroupMetadata = (result) => {
269
+ const group = (0, index_js_5.getBinaryNodeChild)(result, 'group');
270
+ if (!group) {
271
+ // Mirror WAWeb: surface server/client errors with their code+text instead of crashing.
272
+ const errorNode = (0, index_js_5.getBinaryNodeChild)(result, 'error');
273
+ if (errorNode) {
274
+ const code = errorNode.attrs.code ? +errorNode.attrs.code : 500;
275
+ const text = errorNode.attrs.text || 'group metadata query failed';
276
+ throw new index_js_2.HttpError(text, { statusCode: code, data: errorNode });
277
+ }
278
+ throw new index_js_2.HttpError('Invalid group metadata response: missing <group> node', { data: result });
279
+ }
280
+ if (!group.attrs.id) {
281
+ throw new index_js_2.HttpError('Invalid group metadata response: missing group id', { data: group });
282
+ }
283
+ const descChild = (0, index_js_5.getBinaryNodeChild)(group, 'description');
284
+ let desc;
285
+ let descId;
286
+ let descOwner;
287
+ let descOwnerPn;
288
+ let descOwnerUsername;
289
+ let descTime;
290
+ if (descChild) {
291
+ desc = (0, index_js_5.getBinaryNodeChildString)(descChild, 'body');
292
+ descOwner = descChild.attrs.participant ? (0, index_js_5.jidNormalizedUser)(descChild.attrs.participant) : undefined;
293
+ descOwnerPn = descChild.attrs.participant_pn ? (0, index_js_5.jidNormalizedUser)(descChild.attrs.participant_pn) : undefined;
294
+ descOwnerUsername = descChild.attrs.participant_username || undefined;
295
+ descTime = +descChild.attrs.t;
296
+ descId = descChild.attrs.id;
297
+ }
298
+ const groupId = group.attrs.id.includes('@') ? group.attrs.id : (0, index_js_5.jidEncode)(group.attrs.id, 'g.us');
299
+ const eph = (0, index_js_5.getBinaryNodeChild)(group, 'ephemeral')?.attrs.expiration;
300
+ const memberAddMode = (0, index_js_5.getBinaryNodeChildString)(group, 'member_add_mode') === 'all_member_add';
301
+ const metadata = {
302
+ id: groupId,
303
+ notify: group.attrs.notify,
304
+ addressingMode: group.attrs.addressing_mode === 'lid' ? index_js_3.WAMessageAddressingMode.LID : index_js_3.WAMessageAddressingMode.PN,
305
+ subject: group.attrs.subject,
306
+ subjectOwner: group.attrs.s_o,
307
+ subjectOwnerPn: group.attrs.s_o_pn,
308
+ subjectOwnerUsername: group.attrs.s_o_username,
309
+ subjectTime: +group.attrs.s_t,
310
+ size: group.attrs.size ? +group.attrs.size : (0, index_js_5.getBinaryNodeChildren)(group, 'participant').length,
311
+ creation: +group.attrs.creation,
312
+ owner: group.attrs.creator ? (0, index_js_5.jidNormalizedUser)(group.attrs.creator) : undefined,
313
+ ownerPn: group.attrs.creator_pn ? (0, index_js_5.jidNormalizedUser)(group.attrs.creator_pn) : undefined,
314
+ ownerUsername: group.attrs.creator_username || undefined,
315
+ owner_country_code: group.attrs.creator_country_code,
316
+ desc,
317
+ descId,
318
+ descOwner,
319
+ descOwnerPn,
320
+ descOwnerUsername,
321
+ descTime,
322
+ linkedParent: (0, index_js_5.getBinaryNodeChild)(group, 'linked_parent')?.attrs.jid || undefined,
323
+ restrict: !!(0, index_js_5.getBinaryNodeChild)(group, 'locked'),
324
+ announce: !!(0, index_js_5.getBinaryNodeChild)(group, 'announcement'),
325
+ isCommunity: !!(0, index_js_5.getBinaryNodeChild)(group, 'parent'),
326
+ isCommunityAnnounce: !!(0, index_js_5.getBinaryNodeChild)(group, 'default_sub_group'),
327
+ joinApprovalMode: !!(0, index_js_5.getBinaryNodeChild)(group, 'membership_approval_mode'),
328
+ memberAddMode,
329
+ participants: (0, index_js_5.getBinaryNodeChildren)(group, 'participant').map(({ attrs }) => {
330
+ // TODO: Store LID MAPPINGS
331
+ return {
332
+ id: attrs.jid,
333
+ phoneNumber: (0, index_js_5.isLidUser)(attrs.jid) && (0, index_js_5.isPnUser)(attrs.phone_number) ? attrs.phone_number : undefined,
334
+ lid: (0, index_js_5.isPnUser)(attrs.jid) && (0, index_js_5.isLidUser)(attrs.lid) ? attrs.lid : undefined,
335
+ username: attrs.participant_username || attrs.username || undefined,
336
+ admin: (attrs.type || null)
337
+ };
338
+ }),
339
+ ephemeralDuration: eph ? +eph : undefined
340
+ };
341
+ return metadata;
342
+ };
343
+ exports.extractGroupMetadata = extractGroupMetadata;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ const layers = ['chats', 'newsletter', 'messages-send', 'business', 'community', 'socket'];
3
+ exports.installExtensions = (socket, config) => {
4
+ for (const layer of layers) {
5
+ const additions = require('./' + layer).attach(socket, config);
6
+ for (const key of Object.keys(additions)) {
7
+ if (!(key in socket)) socket[key] = additions[key];
8
+ }
9
+ }
10
+ if(socket.signalRepository && !socket.signalRepository.lidMapping) socket.signalRepository.lidMapping=new (require('../Signal/lid-mapping').LIDMappingStore)(socket.authState.keys,config.logger);
11
+ const advancedLayers=['chats','groups','newsletter','messages-send','business','communities'];
12
+ for(const layer of advancedLayers){
13
+ const file=require('node:path').join(__dirname,layer+'-advanced.js');
14
+ if(!require('node:fs').existsSync(file))continue;
15
+ const additions=require(file).attachAdvanced(socket,config);
16
+ for(const [key,value]of Object.entries(additions))if(!(key in socket))socket[key]=value;
17
+ if(layer==='messages-send'){
18
+ const originalSend=socket.sendMessage.bind(socket);
19
+ socket.sendMessage=(jid,content,options={})=>{
20
+ const useAdvanced=require('../Utils/messages').hasAdvancedMessageOptions(content)||require('../WABinary').isJidNewsletter(jid)||Array.isArray(content?.album);
21
+ return useAdvanced?additions.sendMessage(jid,content,options):originalSend(jid,content,options);
22
+ };
23
+ }
24
+ }
25
+ socket.registerSocketEndHandler?.(() => {
26
+ socket.messageRetryManager?.clear?.();
27
+ socket.signalRepository?.lidMapping?.close?.();
28
+ });
29
+ return socket;
30
+ };