@hbmodsofc/baileys 1.7.8 → 2.2.0

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 (155) hide show
  1. package/LICENSE +1 -1
  2. package/lib/Defaults/baileys-version.json +3 -0
  3. package/lib/Defaults/index.d.ts +8 -12
  4. package/lib/Defaults/index.js +124 -90
  5. package/lib/Defaults/phonenumber-mcc.json +223 -0
  6. package/lib/Signal/Group/group_cipher.d.ts +1 -0
  7. package/lib/Signal/Group/group_cipher.js +39 -28
  8. package/lib/Signal/Group/queue-job.d.ts +1 -0
  9. package/lib/Signal/Group/queue-job.js +57 -0
  10. package/lib/Signal/Group/sender-chain-key.d.ts +1 -1
  11. package/lib/Signal/Group/sender-chain-key.js +2 -9
  12. package/lib/Signal/Group/sender-key-distribution-message.js +3 -3
  13. package/lib/Signal/Group/sender-key-message.js +3 -3
  14. package/lib/Signal/Group/sender-key-state.d.ts +4 -4
  15. package/lib/Signal/Group/sender-key-state.js +16 -47
  16. package/lib/Signal/libsignal.d.ts +3 -7
  17. package/lib/Signal/libsignal.js +39 -224
  18. package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +3 -1
  19. package/lib/Socket/Client/index.d.ts +3 -2
  20. package/lib/Socket/Client/index.js +3 -2
  21. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  22. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  23. package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -1
  24. package/lib/Socket/Client/{websocket.js → web-socket-client.js} +16 -10
  25. package/lib/Socket/business.d.ts +78 -94
  26. package/lib/Socket/business.js +11 -130
  27. package/lib/Socket/chats.d.ts +233 -63
  28. package/lib/Socket/chats.js +184 -234
  29. package/lib/Socket/groups.d.ts +41 -62
  30. package/lib/Socket/groups.js +64 -76
  31. package/lib/Socket/hbmods.d.ts +253 -0
  32. package/lib/Socket/hbmods.js +1 -0
  33. package/lib/Socket/index.d.ts +83 -129
  34. package/lib/Socket/index.js +6 -13
  35. package/lib/Socket/messages-recv.d.ts +48 -59
  36. package/lib/Socket/messages-recv.js +371 -516
  37. package/lib/Socket/messages-send.d.ts +67 -86
  38. package/lib/Socket/messages-send.js +1 -1091
  39. package/lib/Socket/newsletter.d.ts +64 -76
  40. package/lib/Socket/newsletter.js +1 -184
  41. package/lib/Socket/registration.d.ts +267 -0
  42. package/lib/Socket/registration.js +166 -0
  43. package/lib/Socket/socket.d.ts +13 -19
  44. package/lib/Socket/socket.js +1 -805
  45. package/lib/Socket/usync.d.ts +36 -0
  46. package/lib/Socket/usync.js +70 -0
  47. package/lib/Types/Auth.d.ts +10 -4
  48. package/lib/Types/Call.d.ts +1 -1
  49. package/lib/Types/Chat.d.ts +9 -29
  50. package/lib/Types/Chat.js +1 -7
  51. package/lib/Types/Contact.d.ts +1 -5
  52. package/lib/Types/Events.d.ts +14 -55
  53. package/lib/Types/GroupMetadata.d.ts +5 -15
  54. package/lib/Types/Label.d.ts +0 -11
  55. package/lib/Types/Label.js +1 -1
  56. package/lib/Types/LabelAssociation.js +1 -1
  57. package/lib/Types/Message.d.ts +49 -75
  58. package/lib/Types/Message.js +7 -10
  59. package/lib/Types/Newsletter.d.ts +98 -129
  60. package/lib/Types/Newsletter.js +38 -33
  61. package/lib/Types/Product.d.ts +1 -1
  62. package/lib/Types/Signal.d.ts +1 -29
  63. package/lib/Types/Socket.d.ts +22 -48
  64. package/lib/Types/State.d.ts +2 -13
  65. package/lib/Types/State.js +0 -12
  66. package/lib/Types/USync.d.ts +1 -1
  67. package/lib/Types/index.d.ts +3 -10
  68. package/lib/Types/index.js +2 -2
  69. package/lib/Utils/auth-utils.d.ts +3 -3
  70. package/lib/Utils/auth-utils.js +102 -378
  71. package/lib/Utils/baileys-event-stream.js +1 -1
  72. package/lib/Utils/business.d.ts +2 -2
  73. package/lib/Utils/business.js +13 -19
  74. package/lib/Utils/chat-utils.d.ts +22 -21
  75. package/lib/Utils/chat-utils.js +154 -201
  76. package/lib/Utils/crypto.d.ts +19 -18
  77. package/lib/Utils/crypto.js +37 -78
  78. package/lib/Utils/decode-wa-message.d.ts +7 -34
  79. package/lib/Utils/decode-wa-message.js +66 -138
  80. package/lib/Utils/event-buffer.d.ts +8 -6
  81. package/lib/Utils/event-buffer.js +43 -81
  82. package/lib/Utils/generics.d.ts +27 -27
  83. package/lib/Utils/generics.js +133 -128
  84. package/lib/Utils/history.d.ts +5 -9
  85. package/lib/Utils/history.js +23 -17
  86. package/lib/Utils/index.d.ts +0 -2
  87. package/lib/Utils/index.js +0 -2
  88. package/lib/Utils/link-preview.d.ts +4 -4
  89. package/lib/Utils/link-preview.js +12 -40
  90. package/lib/Utils/logger.d.ts +3 -11
  91. package/lib/Utils/lt-hash.d.ts +8 -8
  92. package/lib/Utils/lt-hash.js +24 -23
  93. package/lib/Utils/make-mutex.d.ts +2 -2
  94. package/lib/Utils/make-mutex.js +2 -3
  95. package/lib/Utils/messages-media.d.ts +41 -37
  96. package/lib/Utils/messages-media.js +368 -252
  97. package/lib/Utils/messages.d.ts +15 -13
  98. package/lib/Utils/messages.js +261 -274
  99. package/lib/Utils/noise-handler.d.ts +15 -13
  100. package/lib/Utils/noise-handler.js +26 -20
  101. package/lib/Utils/process-message.d.ts +8 -9
  102. package/lib/Utils/process-message.js +93 -157
  103. package/lib/Utils/signal.d.ts +5 -6
  104. package/lib/Utils/signal.js +29 -37
  105. package/lib/Utils/use-multi-file-auth-state.d.ts +2 -1
  106. package/lib/Utils/use-multi-file-auth-state.js +7 -12
  107. package/lib/Utils/validate-connection.d.ts +6 -5
  108. package/lib/Utils/validate-connection.js +97 -39
  109. package/lib/WABinary/constants.d.ts +27 -24
  110. package/lib/WABinary/constants.js +13 -1276
  111. package/lib/WABinary/decode.d.ts +4 -3
  112. package/lib/WABinary/decode.js +14 -28
  113. package/lib/WABinary/encode.d.ts +2 -1
  114. package/lib/WABinary/encode.js +147 -134
  115. package/lib/WABinary/generic-utils.d.ts +7 -4
  116. package/lib/WABinary/generic-utils.js +125 -40
  117. package/lib/WABinary/jid-utils.d.ts +8 -13
  118. package/lib/WABinary/jid-utils.js +16 -27
  119. package/lib/WAM/BinaryInfo.d.ts +11 -2
  120. package/lib/WAM/constants.d.ts +2 -3
  121. package/lib/WAM/constants.js +2359 -2252
  122. package/lib/WAM/encode.d.ts +2 -1
  123. package/lib/WAM/encode.js +11 -8
  124. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +2 -2
  125. package/lib/WAUSync/Protocols/USyncContactProtocol.js +4 -3
  126. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -2
  127. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +5 -5
  128. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -2
  129. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +5 -5
  130. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -2
  131. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +6 -5
  132. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +2 -2
  133. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -1
  134. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -4
  135. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +3 -11
  136. package/lib/WAUSync/USyncQuery.d.ts +2 -2
  137. package/lib/WAUSync/USyncQuery.js +15 -19
  138. package/lib/WAUSync/USyncUser.d.ts +5 -5
  139. package/lib/WAUSync/index.d.ts +1 -1
  140. package/lib/WAUSync/index.js +1 -1
  141. package/package.json +102 -104
  142. package/WAProto/index.js +0 -37306
  143. package/lib/Signal/lid-mapping.d.ts +0 -26
  144. package/lib/Signal/lid-mapping.js +0 -146
  145. package/lib/Socket/communities.d.ts +0 -232
  146. package/lib/Socket/communities.js +0 -402
  147. package/lib/Socket/mex.d.ts +0 -2
  148. package/lib/Socket/mex.js +0 -45
  149. package/lib/Types/Bussines.d.ts +0 -24
  150. package/lib/Types/Bussines.js +0 -2
  151. package/lib/Utils/lidToJid-test.d.ts +0 -11
  152. package/lib/Utils/lidToJid-test.js +0 -27
  153. package/lib/Utils/message-retry-manager.d.ts +0 -81
  154. package/lib/Utils/message-retry-manager.js +0 -152
  155. /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
@@ -1,402 +0,0 @@
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.makeCommunitiesSocket = void 0;
7
- const index_js_1 = require("../../WAProto/index.js");
8
- const Types_1 = require("../Types");
9
- const Utils_1 = require("../Utils");
10
- const logger_1 = __importDefault(require("../Utils/logger"));
11
- const WABinary_1 = require("../WABinary");
12
- const business_1 = require("./business");
13
- const makeCommunitiesSocket = (config) => {
14
- const sock = (0, business_1.makeBusinessSocket)(config);
15
- const { authState, ev, query, upsertMessage } = sock;
16
- const communityQuery = async (jid, type, content) => query({
17
- tag: 'iq',
18
- attrs: {
19
- type,
20
- xmlns: 'w:g2',
21
- to: jid
22
- },
23
- content
24
- });
25
- const communityMetadata = async (jid) => {
26
- const result = await communityQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
27
- return (0, exports.extractCommunityMetadata)(result);
28
- };
29
- const communityFetchAllParticipating = async () => {
30
- const result = await query({
31
- tag: 'iq',
32
- attrs: {
33
- to: '@g.us',
34
- xmlns: 'w:g2',
35
- type: 'get'
36
- },
37
- content: [
38
- {
39
- tag: 'participating',
40
- attrs: {},
41
- content: [
42
- { tag: 'participants', attrs: {} },
43
- { tag: 'description', attrs: {} }
44
- ]
45
- }
46
- ]
47
- });
48
- const data = {};
49
- const communitiesChild = (0, WABinary_1.getBinaryNodeChild)(result, 'communities');
50
- if (communitiesChild) {
51
- const communities = (0, WABinary_1.getBinaryNodeChildren)(communitiesChild, 'community');
52
- for (const communityNode of communities) {
53
- const meta = (0, exports.extractCommunityMetadata)({
54
- tag: 'result',
55
- attrs: {},
56
- content: [communityNode]
57
- });
58
- data[meta.id] = meta;
59
- }
60
- }
61
- sock.ev.emit('groups.update', Object.values(data));
62
- return data;
63
- };
64
- async function parseGroupResult(node) {
65
- logger_1.default.info({ node }, 'parseGroupResult');
66
- const groupNode = (0, WABinary_1.getBinaryNodeChild)(node, 'group');
67
- if (groupNode) {
68
- try {
69
- logger_1.default.info({ groupNode }, 'groupNode');
70
- const metadata = await sock.groupMetadata(`${groupNode.attrs.id}@g.us`);
71
- return metadata ? metadata : Optional.empty();
72
- }
73
- catch (error) {
74
- console.error('Error parsing group metadata:', error);
75
- return Optional.empty();
76
- }
77
- }
78
- return Optional.empty();
79
- }
80
- const Optional = {
81
- empty: () => null,
82
- of: (value) => (value !== null ? { value } : null)
83
- };
84
- sock.ws.on('CB:ib,,dirty', async (node) => {
85
- const { attrs } = (0, WABinary_1.getBinaryNodeChild)(node, 'dirty');
86
- if (attrs.type !== 'communities') {
87
- return;
88
- }
89
- await communityFetchAllParticipating();
90
- await sock.cleanDirtyBits('groups');
91
- });
92
- return {
93
- ...sock,
94
- communityMetadata,
95
- communityCreate: async (subject, body) => {
96
- const descriptionId = (0, Utils_1.generateMessageID)().substring(0, 12);
97
- const result = await communityQuery('@g.us', 'set', [
98
- {
99
- tag: 'create',
100
- attrs: { subject },
101
- content: [
102
- {
103
- tag: 'description',
104
- attrs: { id: descriptionId },
105
- content: [
106
- {
107
- tag: 'body',
108
- attrs: {},
109
- content: Buffer.from(body || '', 'utf-8')
110
- }
111
- ]
112
- },
113
- {
114
- tag: 'parent',
115
- attrs: { default_membership_approval_mode: 'request_required' }
116
- },
117
- {
118
- tag: 'allow_non_admin_sub_group_creation',
119
- attrs: {}
120
- },
121
- {
122
- tag: 'create_general_chat',
123
- attrs: {}
124
- }
125
- ]
126
- }
127
- ]);
128
- return await parseGroupResult(result);
129
- },
130
- communityCreateGroup: async (subject, participants, parentCommunityJid) => {
131
- const key = (0, Utils_1.generateMessageIDV2)();
132
- const result = await communityQuery('@g.us', 'set', [
133
- {
134
- tag: 'create',
135
- attrs: {
136
- subject,
137
- key
138
- },
139
- content: [
140
- ...participants.map(jid => ({
141
- tag: 'participant',
142
- attrs: { jid }
143
- })),
144
- { tag: 'linked_parent', attrs: { jid: parentCommunityJid } }
145
- ]
146
- }
147
- ]);
148
- return await parseGroupResult(result);
149
- },
150
- communityLeave: async (id) => {
151
- await communityQuery('@g.us', 'set', [
152
- {
153
- tag: 'leave',
154
- attrs: {},
155
- content: [{ tag: 'community', attrs: { id } }]
156
- }
157
- ]);
158
- },
159
- communityUpdateSubject: async (jid, subject) => {
160
- await communityQuery(jid, 'set', [
161
- {
162
- tag: 'subject',
163
- attrs: {},
164
- content: Buffer.from(subject, 'utf-8')
165
- }
166
- ]);
167
- },
168
- communityLinkGroup: async (groupJid, parentCommunityJid) => {
169
- await communityQuery(parentCommunityJid, 'set', [
170
- {
171
- tag: 'links',
172
- attrs: {},
173
- content: [
174
- {
175
- tag: 'link',
176
- attrs: { link_type: 'sub_group' },
177
- content: [{ tag: 'group', attrs: { jid: groupJid } }]
178
- }
179
- ]
180
- }
181
- ]);
182
- },
183
- communityUnlinkGroup: async (groupJid, parentCommunityJid) => {
184
- await communityQuery(parentCommunityJid, 'set', [
185
- {
186
- tag: 'unlink',
187
- attrs: { unlink_type: 'sub_group' },
188
- content: [{ tag: 'group', attrs: { jid: groupJid } }]
189
- }
190
- ]);
191
- },
192
- communityRequestParticipantsList: async (jid) => {
193
- const result = await communityQuery(jid, 'get', [
194
- {
195
- tag: 'membership_approval_requests',
196
- attrs: {}
197
- }
198
- ]);
199
- const node = (0, WABinary_1.getBinaryNodeChild)(result, 'membership_approval_requests');
200
- const participants = (0, WABinary_1.getBinaryNodeChildren)(node, 'membership_approval_request');
201
- return participants.map(v => v.attrs);
202
- },
203
- communityRequestParticipantsUpdate: async (jid, participants, action) => {
204
- const result = await communityQuery(jid, 'set', [
205
- {
206
- tag: 'membership_requests_action',
207
- attrs: {},
208
- content: [
209
- {
210
- tag: action,
211
- attrs: {},
212
- content: participants.map(jid => ({
213
- tag: 'participant',
214
- attrs: { jid }
215
- }))
216
- }
217
- ]
218
- }
219
- ]);
220
- const node = (0, WABinary_1.getBinaryNodeChild)(result, 'membership_requests_action');
221
- const nodeAction = (0, WABinary_1.getBinaryNodeChild)(node, action);
222
- const participantsAffected = (0, WABinary_1.getBinaryNodeChildren)(nodeAction, 'participant');
223
- return participantsAffected.map(p => {
224
- return { status: p.attrs.error || '200', jid: p.attrs.jid };
225
- });
226
- },
227
- communityParticipantsUpdate: async (jid, participants, action) => {
228
- const result = await communityQuery(jid, 'set', [
229
- {
230
- tag: action,
231
- attrs: {},
232
- content: participants.map(jid => ({
233
- tag: 'participant',
234
- attrs: { jid }
235
- }))
236
- }
237
- ]);
238
- const node = (0, WABinary_1.getBinaryNodeChild)(result, action);
239
- const participantsAffected = (0, WABinary_1.getBinaryNodeChildren)(node, 'participant');
240
- return participantsAffected.map(p => {
241
- return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
242
- });
243
- },
244
- communityUpdateDescription: async (jid, description) => {
245
- const metadata = await communityMetadata(jid);
246
- const prev = metadata.descId ?? null;
247
- await communityQuery(jid, 'set', [
248
- {
249
- tag: 'description',
250
- attrs: {
251
- ...(description ? { id: (0, Utils_1.generateMessageID)() } : { delete: 'true' }),
252
- ...(prev ? { prev } : {})
253
- },
254
- content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
255
- }
256
- ]);
257
- },
258
- communityInviteCode: async (jid) => {
259
- const result = await communityQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
260
- const inviteNode = (0, WABinary_1.getBinaryNodeChild)(result, 'invite');
261
- return inviteNode?.attrs.code;
262
- },
263
- communityRevokeInvite: async (jid) => {
264
- const result = await communityQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
265
- const inviteNode = (0, WABinary_1.getBinaryNodeChild)(result, 'invite');
266
- return inviteNode?.attrs.code;
267
- },
268
- communityAcceptInvite: async (code) => {
269
- const results = await communityQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
270
- const result = (0, WABinary_1.getBinaryNodeChild)(results, 'community');
271
- return result?.attrs.jid;
272
- },
273
- /**
274
- * revoke a v4 invite for someone
275
- * @param communityJid community jid
276
- * @param invitedJid jid of person you invited
277
- * @returns true if successful
278
- */
279
- communityRevokeInviteV4: async (communityJid, invitedJid) => {
280
- const result = await communityQuery(communityJid, 'set', [
281
- { tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
282
- ]);
283
- return !!result;
284
- },
285
- /**
286
- * accept a CommunityInviteMessage
287
- * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
288
- * @param inviteMessage the message to accept
289
- */
290
- communityAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
291
- key = typeof key === 'string' ? { remoteJid: key } : key;
292
- const results = await communityQuery(inviteMessage.groupJid, 'set', [
293
- {
294
- tag: 'accept',
295
- attrs: {
296
- code: inviteMessage.inviteCode,
297
- expiration: inviteMessage.inviteExpiration.toString(),
298
- admin: key.remoteJid
299
- }
300
- }
301
- ]);
302
- // if we have the full message key
303
- // update the invite message to be expired
304
- if (key.id) {
305
- // create new invite message that is expired
306
- inviteMessage = index_js_1.proto.Message.GroupInviteMessage.create(inviteMessage);
307
- inviteMessage.inviteExpiration = 0;
308
- inviteMessage.inviteCode = '';
309
- ev.emit('messages.update', [
310
- {
311
- key,
312
- update: {
313
- message: {
314
- groupInviteMessage: inviteMessage
315
- }
316
- }
317
- }
318
- ]);
319
- }
320
- // generate the community add message
321
- await upsertMessage({
322
- key: {
323
- remoteJid: inviteMessage.groupJid,
324
- id: (0, Utils_1.generateMessageIDV2)(sock.user?.id),
325
- fromMe: false,
326
- participant: key.remoteJid
327
- },
328
- messageStubType: Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD,
329
- messageStubParameters: [authState.creds.me.id],
330
- participant: key.remoteJid,
331
- messageTimestamp: (0, Utils_1.unixTimestampSeconds)()
332
- }, 'notify');
333
- return results.attrs.from;
334
- }),
335
- communityGetInviteInfo: async (code) => {
336
- const results = await communityQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
337
- return (0, exports.extractCommunityMetadata)(results);
338
- },
339
- communityToggleEphemeral: async (jid, ephemeralExpiration) => {
340
- const content = ephemeralExpiration
341
- ? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
342
- : { tag: 'not_ephemeral', attrs: {} };
343
- await communityQuery(jid, 'set', [content]);
344
- },
345
- communitySettingUpdate: async (jid, setting) => {
346
- await communityQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
347
- },
348
- communityMemberAddMode: async (jid, mode) => {
349
- await communityQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
350
- },
351
- communityJoinApprovalMode: async (jid, mode) => {
352
- await communityQuery(jid, 'set', [
353
- { tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'community_join', attrs: { state: mode } }] }
354
- ]);
355
- },
356
- communityFetchAllParticipating
357
- };
358
- };
359
- exports.makeCommunitiesSocket = makeCommunitiesSocket;
360
- const extractCommunityMetadata = (result) => {
361
- const community = (0, WABinary_1.getBinaryNodeChild)(result, 'community');
362
- const descChild = (0, WABinary_1.getBinaryNodeChild)(community, 'description');
363
- let desc;
364
- let descId;
365
- if (descChild) {
366
- desc = (0, WABinary_1.getBinaryNodeChildString)(descChild, 'body');
367
- descId = descChild.attrs.id;
368
- }
369
- const communityId = community.attrs.id?.includes('@')
370
- ? community.attrs.id
371
- : (0, WABinary_1.jidEncode)(community.attrs.id || '', 'g.us');
372
- const eph = (0, WABinary_1.getBinaryNodeChild)(community, 'ephemeral')?.attrs.expiration;
373
- const memberAddMode = (0, WABinary_1.getBinaryNodeChildString)(community, 'member_add_mode') === 'all_member_add';
374
- const metadata = {
375
- id: communityId,
376
- subject: community.attrs.subject || '',
377
- subjectOwner: community.attrs.s_o,
378
- subjectTime: Number(community.attrs.s_t || 0),
379
- size: (0, WABinary_1.getBinaryNodeChildren)(community, 'participant').length,
380
- creation: Number(community.attrs.creation || 0),
381
- owner: community.attrs.creator ? (0, WABinary_1.jidNormalizedUser)(community.attrs.creator) : undefined,
382
- desc,
383
- descId,
384
- linkedParent: (0, WABinary_1.getBinaryNodeChild)(community, 'linked_parent')?.attrs.jid || undefined,
385
- restrict: !!(0, WABinary_1.getBinaryNodeChild)(community, 'locked'),
386
- announce: !!(0, WABinary_1.getBinaryNodeChild)(community, 'announcement'),
387
- isCommunity: !!(0, WABinary_1.getBinaryNodeChild)(community, 'parent'),
388
- isCommunityAnnounce: !!(0, WABinary_1.getBinaryNodeChild)(community, 'default_sub_community'),
389
- joinApprovalMode: !!(0, WABinary_1.getBinaryNodeChild)(community, 'membership_approval_mode'),
390
- memberAddMode,
391
- participants: (0, WABinary_1.getBinaryNodeChildren)(community, 'participant').map(({ attrs }) => {
392
- return {
393
- id: attrs.jid,
394
- admin: (attrs.type || null)
395
- };
396
- }),
397
- ephemeralDuration: eph ? +eph : undefined,
398
- addressingMode: (0, WABinary_1.getBinaryNodeChildString)(community, 'addressing_mode')
399
- };
400
- return metadata;
401
- };
402
- exports.extractCommunityMetadata = extractCommunityMetadata;
@@ -1,2 +0,0 @@
1
- import type { BinaryNode } from '../WABinary';
2
- export declare const executeWMexQuery: <T>(variables: Record<string, unknown>, queryId: string, dataPath: string, query: (node: BinaryNode) => Promise<BinaryNode>, generateMessageTag: () => string) => Promise<T>;
package/lib/Socket/mex.js DELETED
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.executeWMexQuery = void 0;
4
- const boom_1 = require("@hapi/boom");
5
- const WABinary_1 = require("../WABinary");
6
- const wMexQuery = (variables, queryId, query, generateMessageTag) => {
7
- return query({
8
- tag: 'iq',
9
- attrs: {
10
- id: generateMessageTag(),
11
- type: 'get',
12
- to: WABinary_1.S_WHATSAPP_NET,
13
- xmlns: 'w:mex'
14
- },
15
- content: [
16
- {
17
- tag: 'query',
18
- attrs: { query_id: queryId },
19
- content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
20
- }
21
- ]
22
- });
23
- };
24
- const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
25
- const result = await wMexQuery(variables, queryId, query, generateMessageTag);
26
- const child = (0, WABinary_1.getBinaryNodeChild)(result, 'result');
27
- if (child?.content) {
28
- const data = JSON.parse(child.content.toString());
29
- if (data.errors && data.errors.length > 0) {
30
- const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ');
31
- const firstError = data.errors[0];
32
- const errorCode = firstError.extensions?.error_code || 400;
33
- throw new boom_1.Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError });
34
- }
35
- const response = dataPath ? data?.data?.[dataPath] : data?.data;
36
- if (typeof response !== 'undefined') {
37
- return response;
38
- }
39
- }
40
- const action = (dataPath || '').startsWith('xwa2_')
41
- ? dataPath.substring(5).replace(/_/g, ' ')
42
- : dataPath?.replace(/_/g, ' ');
43
- throw new boom_1.Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result });
44
- };
45
- exports.executeWMexQuery = executeWMexQuery;
@@ -1,24 +0,0 @@
1
- import type { proto } from '../../WAProto';
2
- export type DayOfWeekBussines = 'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat';
3
- export type HoursDay = {
4
- day: DayOfWeekBussines;
5
- mode: 'specific_hours';
6
- openTimeInMinutes: string;
7
- closeTimeInMinutes: string;
8
- } | {
9
- day: DayOfWeekBussines;
10
- mode: 'open_24h' | 'appointment_only';
11
- };
12
- export type UpdateBussinesProfileProps = {
13
- address?: string;
14
- websites?: string[];
15
- email?: string;
16
- description?: string;
17
- hours?: {
18
- timezone: string;
19
- days: HoursDay[];
20
- };
21
- };
22
- export type QuickReplyAction = proto.SyncActionValue.IQuickReplyAction & {
23
- timestamp?: string;
24
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,11 +0,0 @@
1
- /**
2
- * Convert a WhatsApp LID (or raw number) into a full JID string.
3
- *
4
- * @param lid - Bisa berupa:
5
- * • string seperti "6281234567890"
6
- * • number (akan di-cast ke string)
7
- * • sudah berformat JID (mis. "6281234567890@s.whatsapp.net")
8
- *
9
- * @returns string JID yang valid (mis. "6281234567890@s.whatsapp.net")
10
- */
11
- export declare function lidToJid(lid: string | number): string;
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lidToJid = lidToJid;
4
- /**
5
- * Convert a WhatsApp LID (or raw number) into a full JID string.
6
- *
7
- * @param lid - Bisa berupa:
8
- * • string seperti "6281234567890"
9
- * • number (akan di-cast ke string)
10
- * • sudah berformat JID (mis. "6281234567890@s.whatsapp.net")
11
- *
12
- * @returns string JID yang valid (mis. "6281234567890@s.whatsapp.net")
13
- */
14
- function lidToJid(lid) {
15
- if (!lid)
16
- throw new Error("lidToJid: parameter 'lid' wajib diisi");
17
- let id = String(lid).trim();
18
- // Jika sudah berakhiran @s.whatsapp.net atau @g.us, langsung kembalikan
19
- if (/@(s\.whatsapp\.net|g\.us)$/.test(id)) {
20
- return id;
21
- }
22
- // Buang karakter non-digit (jaga-jaga jika ada spasi/tanda plus)
23
- id = id.replace(/[^\d]/g, "");
24
- if (!id.length)
25
- throw new Error("lidToJid: format LID tidak valid");
26
- return `${id}@s.whatsapp.net`;
27
- }
@@ -1,81 +0,0 @@
1
- import type { proto } from '../../WAProto/index.js';
2
- import type { ILogger } from './logger';
3
- export interface RecentMessageKey {
4
- to: string;
5
- id: string;
6
- }
7
- export interface RecentMessage {
8
- message: proto.IMessage;
9
- timestamp: number;
10
- }
11
- export interface SessionRecreateHistory {
12
- [jid: string]: number;
13
- }
14
- export interface RetryCounter {
15
- [messageId: string]: number;
16
- }
17
- export interface PendingPhoneRequest {
18
- [messageId: string]: NodeJS.Timeout;
19
- }
20
- export interface RetryStatistics {
21
- totalRetries: number;
22
- successfulRetries: number;
23
- failedRetries: number;
24
- mediaRetries: number;
25
- sessionRecreations: number;
26
- phoneRequests: number;
27
- }
28
- export declare class MessageRetryManager {
29
- private logger;
30
- private recentMessagesMap;
31
- private sessionRecreateHistory;
32
- private retryCounters;
33
- private pendingPhoneRequests;
34
- private readonly maxMsgRetryCount;
35
- private statistics;
36
- constructor(logger: ILogger, maxMsgRetryCount: number);
37
- /**
38
- * Add a recent message to the cache for retry handling
39
- */
40
- addRecentMessage(to: string, id: string, message: proto.IMessage): void;
41
- /**
42
- * Get a recent message from the cache
43
- */
44
- getRecentMessage(to: string, id: string): RecentMessage | undefined;
45
- /**
46
- * Check if a session should be recreated based on retry count and history
47
- */
48
- shouldRecreateSession(jid: string, retryCount: number, hasSession: boolean): {
49
- reason: string;
50
- recreate: boolean;
51
- };
52
- /**
53
- * Increment retry counter for a message
54
- */
55
- incrementRetryCount(messageId: string): number;
56
- /**
57
- * Get retry count for a message
58
- */
59
- getRetryCount(messageId: string): number;
60
- /**
61
- * Check if message has exceeded maximum retry attempts
62
- */
63
- hasExceededMaxRetries(messageId: string): boolean;
64
- /**
65
- * Mark retry as successful
66
- */
67
- markRetrySuccess(messageId: string): void;
68
- /**
69
- * Mark retry as failed
70
- */
71
- markRetryFailed(messageId: string): void;
72
- /**
73
- * Schedule a phone request with delay
74
- */
75
- schedulePhoneRequest(messageId: string, callback: () => void, delay?: number): void;
76
- /**
77
- * Cancel pending phone request
78
- */
79
- cancelPendingPhoneRequest(messageId: string): void;
80
- private keyToString;
81
- }