jagproject 26.3.22 → 26.3.25

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 (206) hide show
  1. package/WAProto/GenerateStatics.sh +3 -4
  2. package/WAProto/WAProto.proto +1215 -511
  3. package/WAProto/fix-imports.js +73 -0
  4. package/WAProto/index.d.ts +14017 -0
  5. package/WAProto/index.js +64857 -145167
  6. package/engine-requirements.js +4 -7
  7. package/lib/Defaults/index.d.ts +74 -0
  8. package/lib/Defaults/index.js +51 -33
  9. package/lib/Defaults/phonenumber-mcc.json +223 -0
  10. package/lib/Defaults/wileys-version.json +2 -2
  11. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  12. package/lib/Signal/Group/group-session-builder.d.ts +15 -0
  13. package/lib/Signal/Group/group-session-builder.js +5 -3
  14. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  15. package/lib/Signal/Group/group_cipher.js +35 -46
  16. package/lib/Signal/Group/index.d.ts +12 -0
  17. package/lib/Signal/Group/index.js +21 -21
  18. package/lib/Signal/Group/keyhelper.d.ts +11 -0
  19. package/lib/Signal/Group/keyhelper.js +2 -2
  20. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  21. package/lib/Signal/Group/sender-chain-key.js +5 -10
  22. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  23. package/lib/Signal/Group/sender-key-distribution-message.js +7 -7
  24. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  25. package/lib/Signal/Group/sender-key-message.js +8 -8
  26. package/lib/Signal/Group/sender-key-name.d.ts +18 -0
  27. package/lib/Signal/Group/sender-key-record.d.ts +31 -0
  28. package/lib/Signal/Group/sender-key-record.js +7 -16
  29. package/lib/Signal/Group/sender-key-state.d.ts +39 -0
  30. package/lib/Signal/Group/sender-key-state.js +25 -37
  31. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  32. package/lib/Signal/Group/sender-message-key.js +2 -2
  33. package/lib/Signal/libsignal.d.ts +5 -0
  34. package/lib/Signal/libsignal.js +358 -54
  35. package/lib/Signal/lid-mapping.d.ts +19 -0
  36. package/lib/Signal/lid-mapping.js +274 -0
  37. package/lib/Socket/Client/index.d.ts +3 -0
  38. package/lib/Socket/Client/index.js +2 -2
  39. package/lib/Socket/Client/types.d.ts +16 -0
  40. package/lib/Socket/Client/types.js +1 -0
  41. package/lib/Socket/Client/websocket.d.ts +13 -0
  42. package/lib/Socket/Client/websocket.js +18 -30
  43. package/lib/Socket/business.d.ts +202 -0
  44. package/lib/Socket/business.js +160 -38
  45. package/lib/Socket/chats.d.ts +111 -0
  46. package/lib/Socket/chats.js +497 -314
  47. package/lib/Socket/communities.d.ts +258 -0
  48. package/lib/Socket/communities.js +438 -0
  49. package/lib/Socket/community.js +333 -0
  50. package/lib/Socket/groups.d.ts +150 -0
  51. package/lib/Socket/groups.js +229 -91
  52. package/lib/Socket/index.d.ts +245 -0
  53. package/lib/Socket/index.js +9 -6
  54. package/lib/Socket/messages-recv.d.ts +187 -0
  55. package/lib/Socket/messages-recv.js +1105 -501
  56. package/lib/Socket/messages-send.d.ts +183 -0
  57. package/lib/Socket/messages-send.js +1184 -501
  58. package/lib/Socket/mex.d.ts +3 -0
  59. package/lib/Socket/mex.js +45 -0
  60. package/lib/Socket/newsletter.d.ts +160 -0
  61. package/lib/Socket/newsletter.js +227 -200
  62. package/lib/Socket/socket.d.ts +55 -0
  63. package/lib/Socket/socket.js +507 -206
  64. package/lib/Socket/usync.js +6 -6
  65. package/lib/Store/index.js +17 -5
  66. package/lib/Store/make-cache-manager-store.js +83 -0
  67. package/lib/Store/make-in-memory-store.js +48 -89
  68. package/lib/Store/make-ordered-dictionary.js +1 -1
  69. package/lib/Types/Auth.d.ts +116 -0
  70. package/lib/Types/Bussines.d.ts +25 -0
  71. package/lib/Types/Bussines.js +2 -0
  72. package/lib/Types/Call.d.ts +15 -0
  73. package/lib/Types/Chat.d.ts +123 -0
  74. package/lib/Types/Chat.js +7 -1
  75. package/lib/Types/Contact.d.ts +24 -0
  76. package/lib/Types/Events.d.ts +237 -0
  77. package/lib/Types/Events.js +1 -0
  78. package/lib/Types/GroupMetadata.d.ts +67 -0
  79. package/lib/Types/Label.d.ts +47 -0
  80. package/lib/Types/Label.js +1 -3
  81. package/lib/Types/LabelAssociation.d.ts +30 -0
  82. package/lib/Types/LabelAssociation.js +1 -3
  83. package/lib/Types/Message.d.ts +305 -0
  84. package/lib/Types/Message.js +9 -5
  85. package/lib/Types/MexUpdates.js +11 -0
  86. package/lib/Types/Newsletter.d.ts +135 -0
  87. package/lib/Types/Newsletter.js +36 -11
  88. package/lib/Types/Product.d.ts +79 -0
  89. package/lib/Types/Signal.d.ts +76 -0
  90. package/lib/Types/Signal.js +1 -0
  91. package/lib/Types/Socket.d.ts +133 -0
  92. package/lib/Types/Socket.js +1 -0
  93. package/lib/Types/State.d.ts +39 -0
  94. package/lib/Types/State.js +12 -0
  95. package/lib/Types/USync.d.ts +26 -0
  96. package/lib/Types/USync.js +1 -0
  97. package/lib/Types/index.d.ts +65 -0
  98. package/lib/Types/index.js +14 -14
  99. package/lib/Utils/audioToBuffer.js +31 -0
  100. package/lib/Utils/auth-utils.d.ts +19 -0
  101. package/lib/Utils/auth-utils.js +222 -123
  102. package/lib/Utils/baileys-event-stream.js +60 -0
  103. package/lib/Utils/browser-utils.d.ts +4 -0
  104. package/lib/Utils/browser-utils.js +38 -29
  105. package/lib/Utils/business.d.ts +23 -0
  106. package/lib/Utils/business.js +54 -48
  107. package/lib/Utils/chat-utils.d.ts +70 -0
  108. package/lib/Utils/chat-utils.js +284 -189
  109. package/lib/Utils/crypto.d.ts +37 -0
  110. package/lib/Utils/crypto.js +16 -41
  111. package/lib/Utils/decode-wa-message.d.ts +48 -0
  112. package/lib/Utils/decode-wa-message.js +128 -48
  113. package/lib/Utils/event-buffer.d.ts +34 -0
  114. package/lib/Utils/event-buffer.js +124 -62
  115. package/lib/Utils/generics.d.ts +91 -0
  116. package/lib/Utils/generics.js +154 -138
  117. package/lib/Utils/history.d.ts +22 -0
  118. package/lib/Utils/history.js +77 -34
  119. package/lib/Utils/identity-change-handler.d.ts +37 -0
  120. package/lib/Utils/identity-change-handler.js +54 -0
  121. package/lib/Utils/index.d.ts +22 -0
  122. package/lib/Utils/index.js +32 -19
  123. package/lib/Utils/link-preview.d.ts +21 -0
  124. package/lib/Utils/link-preview.js +12 -17
  125. package/lib/Utils/logger.d.ts +13 -0
  126. package/lib/Utils/lt-hash.d.ts +8 -0
  127. package/lib/Utils/lt-hash.js +2 -43
  128. package/lib/Utils/make-mutex.d.ts +9 -0
  129. package/lib/Utils/make-mutex.js +21 -27
  130. package/lib/Utils/message-retry-manager.d.ts +110 -0
  131. package/lib/Utils/message-retry-manager.js +143 -45
  132. package/lib/Utils/messages-media.d.ts +130 -0
  133. package/lib/Utils/messages-media.js +429 -502
  134. package/lib/Utils/messages-newsletter.d.ts +84 -0
  135. package/lib/Utils/messages-newsletter.js +295 -0
  136. package/lib/Utils/messages.d.ts +92 -0
  137. package/lib/Utils/messages.js +1099 -400
  138. package/lib/Utils/noise-handler.d.ts +20 -0
  139. package/lib/Utils/noise-handler.js +145 -91
  140. package/lib/Utils/pre-key-manager.d.ts +28 -0
  141. package/lib/Utils/pre-key-manager.js +112 -0
  142. package/lib/Utils/process-message.d.ts +60 -0
  143. package/lib/Utils/process-message.js +316 -184
  144. package/lib/Utils/reporting-utils.d.ts +11 -0
  145. package/lib/Utils/reporting-utils.js +262 -0
  146. package/lib/Utils/resolve-jid.d.ts +43 -0
  147. package/lib/Utils/resolve-jid.js +95 -0
  148. package/lib/Utils/serial-task-queue.js +29 -0
  149. package/lib/Utils/signal.d.ts +34 -0
  150. package/lib/Utils/signal.js +56 -39
  151. package/lib/Utils/streamToBuffer.js +17 -0
  152. package/lib/Utils/sync-action-utils.d.ts +19 -0
  153. package/lib/Utils/sync-action-utils.js +52 -0
  154. package/lib/Utils/tc-token-utils.d.ts +12 -0
  155. package/lib/Utils/tc-token-utils.js +20 -0
  156. package/lib/Utils/use-mongo-file-auth-state.js +71 -0
  157. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  158. package/lib/Utils/use-multi-file-auth-state.js +11 -12
  159. package/lib/Utils/use-single-file-auth-state.js +73 -0
  160. package/lib/Utils/validate-connection.d.ts +11 -0
  161. package/lib/Utils/validate-connection.js +59 -82
  162. package/lib/Utils/wileys-event-stream.js +1 -61
  163. package/lib/WABinary/constants.d.ts +28 -0
  164. package/lib/WABinary/decode.d.ts +7 -0
  165. package/lib/WABinary/decode.js +39 -4
  166. package/lib/WABinary/encode.d.ts +3 -0
  167. package/lib/WABinary/encode.js +17 -11
  168. package/lib/WABinary/generic-utils.d.ts +15 -0
  169. package/lib/WABinary/generic-utils.js +46 -18
  170. package/lib/WABinary/index.d.ts +6 -0
  171. package/lib/WABinary/index.js +9 -5
  172. package/lib/WABinary/jid-utils.d.ts +48 -0
  173. package/lib/WABinary/jid-utils.js +67 -37
  174. package/lib/WABinary/types.d.ts +19 -0
  175. package/lib/WABinary/types.js +34 -0
  176. package/lib/WAM/BinaryInfo.d.ts +9 -0
  177. package/lib/WAM/constants.d.ts +40 -0
  178. package/lib/WAM/constants.js +19183 -11678
  179. package/lib/WAM/encode.d.ts +3 -0
  180. package/lib/WAM/encode.js +15 -17
  181. package/lib/WAM/index.d.ts +4 -0
  182. package/lib/WAM/index.js +3 -3
  183. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  184. package/lib/WAUSync/Protocols/USyncContactProtocol.js +6 -6
  185. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  186. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +9 -9
  187. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  188. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +6 -6
  189. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  190. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -8
  191. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  192. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +18 -17
  193. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
  194. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +11 -3
  195. package/lib/WAUSync/Protocols/index.d.ts +5 -0
  196. package/lib/WAUSync/Protocols/index.js +6 -4
  197. package/lib/WAUSync/USyncQuery.d.ts +29 -0
  198. package/lib/WAUSync/USyncQuery.js +38 -30
  199. package/lib/WAUSync/USyncUser.d.ts +13 -0
  200. package/lib/WAUSync/index.d.ts +4 -0
  201. package/lib/WAUSync/index.js +3 -3
  202. package/lib/index.d.ts +12 -0
  203. package/lib/index.js +3 -5
  204. package/package.json +10 -6
  205. package/readme.md +97 -0
  206. package/LICENSE +0 -21
@@ -0,0 +1,333 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractCommunityMetadata = exports.makeCommunitiesSocket = void 0;
4
+ const index_js_1 = require("../../WAProto/index.js");
5
+ const index_js_2 = require("../Types/index.js");
6
+ const index_js_3 = require("../Utils/index.js");
7
+ const index_js_4 = require("../WABinary/index.js");
8
+ const business_js_1 = require("./business.js");
9
+ const makeCommunitiesSocket = (config) => {
10
+ const sock = (0, business_js_1.makeBusinessSocket)(config);
11
+ const { authState, ev, query, groupMetadata, upsertMessage } = sock;
12
+ const communityQuery = 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 communityMetadata = async (jid) => {
22
+ const result = await communityQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
23
+ return (0, exports.extractCommunityMetadata)(result);
24
+ };
25
+ const communityFetchAllParticipating = 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 communitiesChild = (0, index_js_4.getBinaryNodeChild)(result, 'communities');
46
+ if (communitiesChild) {
47
+ const communities = (0, index_js_4.getBinaryNodeChildren)(communitiesChild, 'community');
48
+ for (const communityNode of communities) {
49
+ const meta = (0, exports.extractCommunityMetadata)({
50
+ tag: 'result',
51
+ attrs: {},
52
+ content: [communityNode]
53
+ });
54
+ data[meta.id] = meta;
55
+ }
56
+ }
57
+ sock.ev.emit('groups.update', Object.values(data));
58
+ return data;
59
+ };
60
+ sock.ws.on('CB:ib,,dirty', async (node) => {
61
+ const { attrs } = (0, index_js_4.getBinaryNodeChild)(node, 'dirty');
62
+ if (attrs.type !== 'communities') {
63
+ return;
64
+ }
65
+ await communityFetchAllParticipating();
66
+ await sock.cleanDirtyBits('groups');
67
+ });
68
+ return {
69
+ ...sock,
70
+ communityQuery,
71
+ communityMetadata,
72
+ communityCreate: async (subject, body) => {
73
+ const descriptionId = (0, index_js_3.generateMessageID)().substring(0, 12);
74
+ const result = await communityQuery('@g.us', 'set', [
75
+ {
76
+ tag: 'create',
77
+ attrs: { subject },
78
+ content: [{
79
+ tag: 'description',
80
+ attrs: {
81
+ id: descriptionId
82
+ },
83
+ content: [{
84
+ tag: 'body',
85
+ attrs: {},
86
+ content: Buffer.from(body || '', 'utf-8')
87
+ }]
88
+ },
89
+ {
90
+ tag: 'parent',
91
+ attrs: {
92
+ default_membership_approval_mode: 'request_required'
93
+ }
94
+ },
95
+ {
96
+ tag: 'allow_non_admin_sub_group_creation',
97
+ attrs: {}
98
+ },
99
+ {
100
+ tag: 'create_general_chat',
101
+ attrs: {}
102
+ }]
103
+ }
104
+ ]);
105
+ return (0, exports.extractCommunityMetadata)(result);
106
+ },
107
+ communityLeave: async (id) => {
108
+ await communityQuery('@g.us', 'set', [
109
+ {
110
+ tag: 'leave',
111
+ attrs: {},
112
+ content: [
113
+ { tag: 'community', attrs: { id } }
114
+ ]
115
+ }
116
+ ]);
117
+ },
118
+ communityUpdateSubject: async (jid, subject) => {
119
+ await communityQuery(jid, 'set', [
120
+ {
121
+ tag: 'subject',
122
+ attrs: {},
123
+ content: Buffer.from(subject, 'utf-8')
124
+ }
125
+ ]);
126
+ },
127
+ communityRequestParticipantsList: async (jid) => {
128
+ const result = await communityQuery(jid, 'get', [
129
+ {
130
+ tag: 'membership_approval_requests',
131
+ attrs: {}
132
+ }
133
+ ]);
134
+ const node = (0, index_js_4.getBinaryNodeChild)(result, 'membership_approval_requests');
135
+ const participants = (0, index_js_4.getBinaryNodeChildren)(node, 'membership_approval_request');
136
+ return participants.map(v => v.attrs);
137
+ },
138
+ communityRequestParticipantsUpdate: async (jid, participants, action) => {
139
+ const result = await communityQuery(jid, 'set', [{
140
+ tag: 'membership_requests_action',
141
+ attrs: {},
142
+ content: [
143
+ {
144
+ tag: action,
145
+ attrs: {},
146
+ content: participants.map(jid => ({
147
+ tag: 'participant',
148
+ attrs: { jid }
149
+ }))
150
+ }
151
+ ]
152
+ }]);
153
+ const node = (0, index_js_4.getBinaryNodeChild)(result, 'membership_requests_action');
154
+ const nodeAction = (0, index_js_4.getBinaryNodeChild)(node, action);
155
+ const participantsAffected = (0, index_js_4.getBinaryNodeChildren)(nodeAction, 'participant');
156
+ return participantsAffected.map(p => {
157
+ return { status: p.attrs.error || '200', jid: p.attrs.jid };
158
+ });
159
+ },
160
+ communityParticipantsUpdate: async (jid, participants, action) => {
161
+ const result = await communityQuery(jid, 'set', [
162
+ {
163
+ tag: action,
164
+ attrs: {},
165
+ content: participants.map(jid => ({
166
+ tag: 'participant',
167
+ attrs: { jid }
168
+ }))
169
+ }
170
+ ]);
171
+ const node = (0, index_js_4.getBinaryNodeChild)(result, action);
172
+ const participantsAffected = (0, index_js_4.getBinaryNodeChildren)(node, 'participant');
173
+ return participantsAffected.map(p => {
174
+ return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
175
+ });
176
+ },
177
+ communityUpdateDescription: async (jid, description) => {
178
+ const metadata = await communityMetadata(jid);
179
+ const prev = metadata.descId ? metadata.descId : null;
180
+ await communityQuery(jid, 'set', [
181
+ {
182
+ tag: 'description',
183
+ attrs: {
184
+ ...(description ? { id: (0, index_js_3.generateMessageID)() } : { delete: 'true' }),
185
+ ...(prev ? { prev } : {})
186
+ },
187
+ content: description ? [
188
+ { tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }
189
+ ] : undefined
190
+ }
191
+ ]);
192
+ },
193
+ communityInviteCode: async (jid) => {
194
+ const result = await communityQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
195
+ const inviteNode = (0, index_js_4.getBinaryNodeChild)(result, 'invite');
196
+ return inviteNode?.attrs?.code;
197
+ },
198
+ communityRevokeInvite: async (jid) => {
199
+ const result = await communityQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
200
+ const inviteNode = (0, index_js_4.getBinaryNodeChild)(result, 'invite');
201
+ return inviteNode?.attrs?.code;
202
+ },
203
+ communityAcceptInvite: async (code) => {
204
+ const results = await communityQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
205
+ const result = (0, index_js_4.getBinaryNodeChild)(results, 'community');
206
+ return result?.attrs?.jid;
207
+ },
208
+ /**
209
+ * revoke a v4 invite for someone
210
+ * @param communityJid community jid
211
+ * @param invitedJid jid of person you invited
212
+ * @returns true if successful
213
+ */
214
+ communityRevokeInviteV4: async (communityJid, invitedJid) => {
215
+ const result = await communityQuery(communityJid, 'set', [{ tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }]);
216
+ return !!result;
217
+ },
218
+ /**
219
+ * accept a GroupInviteMessage
220
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
221
+ * @param inviteMessage the message to accept
222
+ */
223
+ communityAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
224
+ key = typeof key === 'string' ? { remoteJid: key } : key;
225
+ const results = await communityQuery(inviteMessage.groupJid, 'set', [{
226
+ tag: 'accept',
227
+ attrs: {
228
+ code: inviteMessage.inviteCode,
229
+ expiration: inviteMessage.inviteExpiration.toString(),
230
+ admin: key.remoteJid
231
+ }
232
+ }]);
233
+ // if we have the full message key
234
+ // update the invite message to be expired
235
+ if (key.id) {
236
+ // create new invite message that is expired
237
+ inviteMessage = index_js_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage);
238
+ inviteMessage.inviteExpiration = 0;
239
+ inviteMessage.inviteCode = '';
240
+ ev.emit('messages.update', [
241
+ {
242
+ key,
243
+ update: {
244
+ message: {
245
+ groupInviteMessage: inviteMessage
246
+ }
247
+ }
248
+ }
249
+ ]);
250
+ }
251
+ // generate the group add message
252
+ await upsertMessage({
253
+ key: {
254
+ remoteJid: inviteMessage.groupJid,
255
+ id: (0, index_js_3.generateMessageID)(authState.creds.me?.id),
256
+ fromMe: false,
257
+ participant: key.remoteJid,
258
+ },
259
+ messageStubType: index_js_2.WAMessageStubType.GROUP_PARTICIPANT_ADD,
260
+ messageStubParameters: [
261
+ authState.creds.me.id
262
+ ],
263
+ participant: key.remoteJid,
264
+ messageTimestamp: (0, index_js_3.unixTimestampSeconds)()
265
+ }, 'notify');
266
+ return results.attrs.from;
267
+ }),
268
+ communityGetInviteInfo: async (code) => {
269
+ const results = await communityQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
270
+ return (0, exports.extractCommunityMetadata)(results);
271
+ },
272
+ communityToggleEphemeral: async (jid, ephemeralExpiration) => {
273
+ const content = ephemeralExpiration ?
274
+ { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } } :
275
+ { tag: 'not_ephemeral', attrs: {} };
276
+ await communityQuery(jid, 'set', [content]);
277
+ },
278
+ communitySettingUpdate: async (jid, setting) => {
279
+ await communityQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
280
+ },
281
+ communityMemberAddMode: async (jid, mode) => {
282
+ await communityQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
283
+ },
284
+ communityJoinApprovalMode: async (jid, mode) => {
285
+ await communityQuery(jid, 'set', [{ tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'community_join', attrs: { state: mode } }] }]);
286
+ },
287
+ communityFetchAllParticipating
288
+ };
289
+ };
290
+ exports.makeCommunitiesSocket = makeCommunitiesSocket;
291
+ const extractCommunityMetadata = (result) => {
292
+ const community = (0, index_js_4.getBinaryNodeChild)(result, 'group');
293
+ const descChild = (0, index_js_4.getBinaryNodeChild)(community, 'description');
294
+ let desc;
295
+ let descId;
296
+ if (descChild) {
297
+ desc = (0, index_js_4.getBinaryNodeChildString)(descChild, 'body');
298
+ descId = descChild.attrs.id;
299
+ }
300
+ const mode = community.attrs.addressing_mode;
301
+ const communityId = community.attrs.id.includes('@') ? community.attrs.id : (0, index_js_4.jidEncode)(community.attrs.id, 'g.us');
302
+ const eph = (0, index_js_4.getBinaryNodeChild)(community, 'ephemeral')?.attrs.expiration;
303
+ const memberAddMode = (0, index_js_4.getBinaryNodeChildString)(community, 'member_add_mode') === 'all_member_add';
304
+ const metadata = {
305
+ id: communityId,
306
+ addressingMode: mode,
307
+ subject: community.attrs.subject,
308
+ subjectOwner: mode === 'lid' ? community.attrs.s_o_pn : community.attrs.s_o,
309
+ subjectTime: +community.attrs.s_t,
310
+ size: community.attrs?.size ? +community.attrs.size : (0, index_js_4.getBinaryNodeChildren)(community, 'participant').length,
311
+ creation: +community.attrs.creation,
312
+ owner: community.attrs.creator ? (0, index_js_4.jidNormalizedUser)(mode === 'lid' ? community.attrs.creator_pn : community.attrs.creator) : undefined,
313
+ desc,
314
+ descId,
315
+ linkedParent: (0, index_js_4.getBinaryNodeChild)(community, 'linked_parent')?.attrs.jid || undefined,
316
+ restrict: !!(0, index_js_4.getBinaryNodeChild)(community, 'locked'),
317
+ announce: !!(0, index_js_4.getBinaryNodeChild)(community, 'announcement'),
318
+ isCommunity: !!(0, index_js_4.getBinaryNodeChild)(community, 'parent'),
319
+ isCommunityAnnounce: !!(0, index_js_4.getBinaryNodeChild)(community, 'default_sub_group'),
320
+ joinApprovalMode: !!(0, index_js_4.getBinaryNodeChild)(community, 'membership_approval_mode'),
321
+ memberAddMode,
322
+ participants: (0, index_js_4.getBinaryNodeChildren)(community, 'participant').map(({ attrs }) => {
323
+ return {
324
+ id: mode === 'lid' ? community.phone_number : attrs.jid,
325
+ lid: mode === 'lid' ? community.jid : attrs.lid,
326
+ admin: (attrs.type || null),
327
+ };
328
+ }),
329
+ ephemeralDuration: eph ? +eph : undefined,
330
+ };
331
+ return metadata;
332
+ };
333
+ exports.extractCommunityMetadata = extractCommunityMetadata;
@@ -0,0 +1,150 @@
1
+ import { proto } from '../../WAProto/index.js';
2
+ import type { GroupMetadata, ParticipantAction, SocketConfig, WAMessageKey } from '../Types/index.js';
3
+ import { type BinaryNode } from '../WABinary/index.js';
4
+ export declare const makeGroupsSocket: (config: SocketConfig) => {
5
+ groupMetadata: (jid: string) => Promise<GroupMetadata>;
6
+ groupCreate: (subject: string, participants: string[]) => Promise<GroupMetadata>;
7
+ groupLeave: (id: string) => Promise<void>;
8
+ groupUpdateSubject: (jid: string, subject: string) => Promise<void>;
9
+ groupRequestParticipantsList: (jid: string) => Promise<{
10
+ [key: string]: string;
11
+ }[]>;
12
+ groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "approve" | "reject") => Promise<{
13
+ status: string;
14
+ jid: string | undefined;
15
+ }[]>;
16
+ groupParticipantsUpdate: (jid: string, participants: string[], action: ParticipantAction) => Promise<{
17
+ status: string;
18
+ jid: string | undefined;
19
+ content: BinaryNode;
20
+ }[]>;
21
+ groupUpdateDescription: (jid: string, description?: string) => Promise<void>;
22
+ groupInviteCode: (jid: string) => Promise<string | undefined>;
23
+ groupRevokeInvite: (jid: string) => Promise<string | undefined>;
24
+ groupAcceptInvite: (code: string) => Promise<string | undefined>;
25
+ /**
26
+ * revoke a v4 invite for someone
27
+ * @param groupJid group jid
28
+ * @param invitedJid jid of person you invited
29
+ * @returns true if successful
30
+ */
31
+ groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
32
+ /**
33
+ * accept a GroupInviteMessage
34
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
35
+ * @param inviteMessage the message to accept
36
+ */
37
+ groupAcceptInviteV4: (key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<any>;
38
+ groupGetInviteInfo: (code: string) => Promise<GroupMetadata>;
39
+ groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
40
+ groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
41
+ groupMemberAddMode: (jid: string, mode: "admin_add" | "all_member_add") => Promise<void>;
42
+ groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
43
+ groupFetchAllParticipating: () => Promise<{
44
+ [_: string]: GroupMetadata;
45
+ }>;
46
+ createCallLink: (type: "audio" | "video", event?: {
47
+ startTime: number;
48
+ }, timeoutMs?: number) => Promise<string | undefined>;
49
+ getBotListV2: () => Promise<import("../Types/index.js").BotListInfo[]>;
50
+ messageMutex: {
51
+ mutex<T>(code: () => Promise<T> | T): Promise<T>;
52
+ };
53
+ receiptMutex: {
54
+ mutex<T>(code: () => Promise<T> | T): Promise<T>;
55
+ };
56
+ appStatePatchMutex: {
57
+ mutex<T>(code: () => Promise<T> | T): Promise<T>;
58
+ };
59
+ notificationMutex: {
60
+ mutex<T>(code: () => Promise<T> | T): Promise<T>;
61
+ };
62
+ fetchPrivacySettings: (force?: boolean) => Promise<{
63
+ [_: string]: string;
64
+ }>;
65
+ upsertMessage: (msg: import("../Types/index.js").WAMessage, type: import("../Types/index.js").MessageUpsertType) => Promise<void>;
66
+ appPatch: (patchCreate: import("../Types/index.js").WAPatchCreate) => Promise<void>;
67
+ sendPresenceUpdate: (type: import("../Types/index.js").WAPresence, toJid?: string) => Promise<void>;
68
+ presenceSubscribe: (toJid: string) => Promise<void>;
69
+ profilePictureUrl: (jid: string, type?: "preview" | "image", timeoutMs?: number) => Promise<string | undefined>;
70
+ fetchBlocklist: () => Promise<(string | undefined)[]>;
71
+ fetchStatus: (...jids: string[]) => Promise<import("../index.js").USyncQueryResultList[] | undefined>;
72
+ fetchDisappearingDuration: (...jids: string[]) => Promise<import("../index.js").USyncQueryResultList[] | undefined>;
73
+ updateProfilePicture: (jid: string, content: import("../Types/index.js").WAMediaUpload, dimensions?: {
74
+ width: number;
75
+ height: number;
76
+ }) => Promise<void>;
77
+ removeProfilePicture: (jid: string) => Promise<void>;
78
+ updateProfileStatus: (status: string) => Promise<void>;
79
+ updateProfileName: (name: string) => Promise<void>;
80
+ updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
81
+ updateDisableLinkPreviewsPrivacy: (isPreviewsDisabled: boolean) => Promise<void>;
82
+ updateCallPrivacy: (value: import("../Types/index.js").WAPrivacyCallValue) => Promise<void>;
83
+ updateMessagesPrivacy: (value: import("../Types/index.js").WAPrivacyMessagesValue) => Promise<void>;
84
+ updateLastSeenPrivacy: (value: import("../Types/index.js").WAPrivacyValue) => Promise<void>;
85
+ updateOnlinePrivacy: (value: import("../Types/index.js").WAPrivacyOnlineValue) => Promise<void>;
86
+ updateProfilePicturePrivacy: (value: import("../Types/index.js").WAPrivacyValue) => Promise<void>;
87
+ updateStatusPrivacy: (value: import("../Types/index.js").WAPrivacyValue) => Promise<void>;
88
+ updateReadReceiptsPrivacy: (value: import("../Types/index.js").WAReadReceiptsValue) => Promise<void>;
89
+ updateGroupsAddPrivacy: (value: import("../Types/index.js").WAPrivacyGroupAddValue) => Promise<void>;
90
+ updateDefaultDisappearingMode: (duration: number) => Promise<void>;
91
+ getBusinessProfile: (jid: string) => Promise<import("../Types/index.js").WABusinessProfile | void>;
92
+ resyncAppState: (collections: readonly ("critical_unblock_low" | "regular_high" | "regular_low" | "critical_block" | "regular")[], isInitialSync: boolean) => Promise<void>;
93
+ chatModify: (mod: import("../Types/index.js").ChatModification, jid: string) => Promise<void>;
94
+ cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
95
+ addOrEditContact: (jid: string, contact: proto.SyncActionValue.IContactAction) => Promise<void>;
96
+ removeContact: (jid: string) => Promise<void>;
97
+ addLabel: (jid: string, labels: import("../Types/Label.js").LabelActionBody) => Promise<void>;
98
+ addChatLabel: (jid: string, labelId: string) => Promise<void>;
99
+ removeChatLabel: (jid: string, labelId: string) => Promise<void>;
100
+ addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
101
+ removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
102
+ star: (jid: string, messages: {
103
+ id: string;
104
+ fromMe?: boolean;
105
+ }[], star: boolean) => Promise<void>;
106
+ addOrEditQuickReply: (quickReply: import("../Types/Bussines.js").QuickReplyAction) => Promise<void>;
107
+ removeQuickReply: (timestamp: string) => Promise<void>;
108
+ type: "md";
109
+ ws: import("./Client/websocket.js").WebSocketClient;
110
+ ev: import("../Types/index.js").BaileysEventEmitter & {
111
+ process(handler: (events: Partial<import("../Types/index.js").BaileysEventMap>) => void | Promise<void>): () => void;
112
+ buffer(): void;
113
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
114
+ flush(): boolean;
115
+ isBuffering(): boolean;
116
+ };
117
+ authState: {
118
+ creds: import("../Types/index.js").AuthenticationCreds;
119
+ keys: import("../Types/index.js").SignalKeyStoreWithTransaction;
120
+ };
121
+ signalRepository: import("../Types/index.js").SignalRepositoryWithLIDStore;
122
+ user: import("../Types/index.js").Contact | undefined;
123
+ generateMessageTag: () => string;
124
+ query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
125
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<T | undefined>;
126
+ waitForSocketOpen: () => Promise<void>;
127
+ sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
128
+ sendNode: (frame: BinaryNode) => Promise<void>;
129
+ logout: (msg?: string) => Promise<void>;
130
+ end: (error: Error | undefined) => Promise<void>;
131
+ onUnexpectedError: (err: Error | import("@hapi/boom").Boom, msg: string) => void;
132
+ uploadPreKeys: (count?: number, retryCount?: number) => Promise<void>;
133
+ uploadPreKeysToServerIfRequired: () => Promise<void>;
134
+ digestKeyBundle: () => Promise<void>;
135
+ rotateSignedPreKey: () => Promise<void>;
136
+ requestPairingCode: (phoneNumber: string, customPairingCode?: string) => Promise<string>;
137
+ updateServerTimeOffset: ({ attrs }: BinaryNode) => void;
138
+ sendUnifiedSession: () => Promise<void>;
139
+ wamBuffer: import("../index.js").BinaryInfo;
140
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types/index.js").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
141
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
142
+ executeUSyncQuery: (usyncQuery: import("../index.js").USyncQuery) => Promise<import("../index.js").USyncQueryResult | undefined>;
143
+ onWhatsApp: (...phoneNumber: string[]) => Promise<{
144
+ jid: string;
145
+ exists: boolean;
146
+ }[] | undefined>;
147
+ };
148
+ export declare const extractGroupMetadata: (result: BinaryNode) => GroupMetadata;
149
+ export type GroupsSocket = ReturnType<typeof makeGroupsSocket>;
150
+ //# sourceMappingURL=groups.d.ts.map