nrx-bails 0.0.1

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 (199) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1541 -0
  3. package/WAProto/GenerateStatics.sh +4 -0
  4. package/WAProto/WAProto.proto +4775 -0
  5. package/WAProto/index.d.ts +2 -0
  6. package/WAProto/index.js +169661 -0
  7. package/lib/Defaults/index.d.ts +113 -0
  8. package/lib/Defaults/index.js +156 -0
  9. package/lib/Defaults/phonenumber-mcc.json +223 -0
  10. package/lib/Defaults/ye-bail-version.json +3 -0
  11. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  12. package/lib/Signal/Group/ciphertext-message.js +41 -0
  13. package/lib/Signal/Group/group-session-builder.d.ts +8 -0
  14. package/lib/Signal/Group/group-session-builder.js +90 -0
  15. package/lib/Signal/Group/group_cipher.d.ts +12 -0
  16. package/lib/Signal/Group/group_cipher.js +122 -0
  17. package/lib/Signal/Group/index.d.ts +22 -0
  18. package/lib/Signal/Group/index.js +83 -0
  19. package/lib/Signal/Group/keyhelper.d.ts +7 -0
  20. package/lib/Signal/Group/keyhelper.js +81 -0
  21. package/lib/Signal/Group/queue-job.d.ts +3 -0
  22. package/lib/Signal/Group/queue-job.js +83 -0
  23. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  24. package/lib/Signal/Group/sender-chain-key.js +60 -0
  25. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  26. package/lib/Signal/Group/sender-key-distribution-message.js +92 -0
  27. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  28. package/lib/Signal/Group/sender-key-message.js +95 -0
  29. package/lib/Signal/Group/sender-key-name.d.ts +12 -0
  30. package/lib/Signal/Group/sender-key-name.js +77 -0
  31. package/lib/Signal/Group/sender-key-record.d.ts +13 -0
  32. package/lib/Signal/Group/sender-key-record.js +79 -0
  33. package/lib/Signal/Group/sender-key-state.d.ts +17 -0
  34. package/lib/Signal/Group/sender-key-state.js +125 -0
  35. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  36. package/lib/Signal/Group/sender-message-key.js +55 -0
  37. package/lib/Signal/libsignal.d.ts +37 -0
  38. package/lib/Signal/libsignal.js +200 -0
  39. package/lib/Socket/Client/index.d.ts +1 -0
  40. package/lib/Socket/Client/index.js +44 -0
  41. package/lib/Socket/Client/types.d.ts +7 -0
  42. package/lib/Socket/Client/types.js +39 -0
  43. package/lib/Socket/Client/websocket.d.ts +19 -0
  44. package/lib/Socket/Client/websocket.js +137 -0
  45. package/lib/Socket/business.d.ts +329 -0
  46. package/lib/Socket/business.js +286 -0
  47. package/lib/Socket/chats.d.ts +84 -0
  48. package/lib/Socket/chats.js +1022 -0
  49. package/lib/Socket/groups.d.ts +216 -0
  50. package/lib/Socket/groups.js +358 -0
  51. package/lib/Socket/index.d.ts +330 -0
  52. package/lib/Socket/index.js +36 -0
  53. package/lib/Socket/messages-recv.d.ts +271 -0
  54. package/lib/Socket/messages-recv.js +1079 -0
  55. package/lib/Socket/messages-send.d.ts +258 -0
  56. package/lib/Socket/messages-send.js +1190 -0
  57. package/lib/Socket/newsletter.d.ts +253 -0
  58. package/lib/Socket/newsletter.js +362 -0
  59. package/lib/Socket/registration.d.ts +361 -0
  60. package/lib/Socket/registration.js +179 -0
  61. package/lib/Socket/socket.d.ts +33 -0
  62. package/lib/Socket/socket.js +699 -0
  63. package/lib/Socket/usync.d.ts +27 -0
  64. package/lib/Socket/usync.js +96 -0
  65. package/lib/Store/index.d.ts +3 -0
  66. package/lib/Store/index.js +36 -0
  67. package/lib/Store/make-cache-manager-auth-state.d.ts +16 -0
  68. package/lib/Store/make-cache-manager-auth-state.js +118 -0
  69. package/lib/Store/make-in-memory-store.d.ts +64 -0
  70. package/lib/Store/make-in-memory-store.js +465 -0
  71. package/lib/Store/make-ordered-dictionary.d.ts +14 -0
  72. package/lib/Store/make-ordered-dictionary.js +107 -0
  73. package/lib/Store/object-repository.d.ts +11 -0
  74. package/lib/Store/object-repository.js +53 -0
  75. package/lib/Types/Auth.d.ts +1 -0
  76. package/lib/Types/Auth.js +28 -0
  77. package/lib/Types/Call.d.ts +1 -0
  78. package/lib/Types/Call.js +28 -0
  79. package/lib/Types/Chat.d.ts +2 -0
  80. package/lib/Types/Chat.js +30 -0
  81. package/lib/Types/Contact.d.ts +1 -0
  82. package/lib/Types/Contact.js +28 -0
  83. package/lib/Types/Events.d.ts +1 -0
  84. package/lib/Types/Events.js +28 -0
  85. package/lib/Types/GroupMetadata.d.ts +1 -0
  86. package/lib/Types/GroupMetadata.js +28 -0
  87. package/lib/Types/Label.d.ts +2 -0
  88. package/lib/Types/Label.js +53 -0
  89. package/lib/Types/LabelAssociation.d.ts +2 -0
  90. package/lib/Types/LabelAssociation.js +35 -0
  91. package/lib/Types/Message.d.ts +2 -0
  92. package/lib/Types/Message.js +33 -0
  93. package/lib/Types/Newsletter.d.ts +4 -0
  94. package/lib/Types/Newsletter.js +62 -0
  95. package/lib/Types/Product.d.ts +1 -0
  96. package/lib/Types/Product.js +28 -0
  97. package/lib/Types/Signal.d.ts +1 -0
  98. package/lib/Types/Signal.js +28 -0
  99. package/lib/Types/Socket.d.ts +1 -0
  100. package/lib/Types/Socket.js +28 -0
  101. package/lib/Types/State.d.ts +1 -0
  102. package/lib/Types/State.js +28 -0
  103. package/lib/Types/USync.d.ts +1 -0
  104. package/lib/Types/USync.js +28 -0
  105. package/lib/Types/index.d.ts +2 -0
  106. package/lib/Types/index.js +68 -0
  107. package/lib/Utils/auth-utils.d.ts +63 -0
  108. package/lib/Utils/auth-utils.js +248 -0
  109. package/lib/Utils/browser-utils.d.ts +3 -0
  110. package/lib/Utils/browser-utils.js +61 -0
  111. package/lib/Utils/business.d.ts +53 -0
  112. package/lib/Utils/business.js +260 -0
  113. package/lib/Utils/chat-utils.d.ts +253 -0
  114. package/lib/Utils/chat-utils.js +756 -0
  115. package/lib/Utils/crypto.d.ts +43 -0
  116. package/lib/Utils/crypto.js +219 -0
  117. package/lib/Utils/decode-wa-message.d.ts +61 -0
  118. package/lib/Utils/decode-wa-message.js +233 -0
  119. package/lib/Utils/event-buffer.d.ts +17 -0
  120. package/lib/Utils/event-buffer.js +544 -0
  121. package/lib/Utils/generics.d.ts +89 -0
  122. package/lib/Utils/generics.js +471 -0
  123. package/lib/Utils/history.d.ts +59 -0
  124. package/lib/Utils/history.js +120 -0
  125. package/lib/Utils/index.d.ts +1 -0
  126. package/lib/Utils/index.js +61 -0
  127. package/lib/Utils/link-preview.d.ts +19 -0
  128. package/lib/Utils/link-preview.js +152 -0
  129. package/lib/Utils/logger.d.ts +3 -0
  130. package/lib/Utils/logger.js +33 -0
  131. package/lib/Utils/lt-hash.d.ts +13 -0
  132. package/lib/Utils/lt-hash.js +77 -0
  133. package/lib/Utils/make-mutex.d.ts +7 -0
  134. package/lib/Utils/make-mutex.js +69 -0
  135. package/lib/Utils/message-retry-manager.d.ts +34 -0
  136. package/lib/Utils/message-retry-manager.js +154 -0
  137. package/lib/Utils/messages-media.d.ts +137 -0
  138. package/lib/Utils/messages-media.js +1024 -0
  139. package/lib/Utils/messages.d.ts +66 -0
  140. package/lib/Utils/messages.js +1407 -0
  141. package/lib/Utils/noise-handler.d.ts +21 -0
  142. package/lib/Utils/noise-handler.js +176 -0
  143. package/lib/Utils/pre-key-manager.d.ts +13 -0
  144. package/lib/Utils/pre-key-manager.js +93 -0
  145. package/lib/Utils/process-message.d.ts +40 -0
  146. package/lib/Utils/process-message.js +430 -0
  147. package/lib/Utils/signal.d.ts +72 -0
  148. package/lib/Utils/signal.js +179 -0
  149. package/lib/Utils/use-multi-file-auth-state.d.ts +18 -0
  150. package/lib/Utils/use-multi-file-auth-state.js +151 -0
  151. package/lib/Utils/validate-connection.d.ts +43 -0
  152. package/lib/Utils/validate-connection.js +255 -0
  153. package/lib/Utils/ye-bail-event-stream.d.ts +16 -0
  154. package/lib/Utils/ye-bail-event-stream.js +89 -0
  155. package/lib/WABinary/constants.d.ts +23 -0
  156. package/lib/WABinary/constants.js +1328 -0
  157. package/lib/WABinary/decode.d.ts +10 -0
  158. package/lib/WABinary/decode.js +291 -0
  159. package/lib/WABinary/encode.d.ts +2 -0
  160. package/lib/WABinary/encode.js +276 -0
  161. package/lib/WABinary/generic-utils.d.ts +16 -0
  162. package/lib/WABinary/generic-utils.js +155 -0
  163. package/lib/WABinary/index.d.ts +1 -0
  164. package/lib/WABinary/index.js +47 -0
  165. package/lib/WABinary/jid-utils.d.ts +34 -0
  166. package/lib/WABinary/jid-utils.js +111 -0
  167. package/lib/WABinary/types.d.ts +1 -0
  168. package/lib/WABinary/types.js +28 -0
  169. package/lib/WAM/BinaryInfo.d.ts +8 -0
  170. package/lib/WAM/BinaryInfo.js +39 -0
  171. package/lib/WAM/constants.d.ts +35374 -0
  172. package/lib/WAM/constants.js +15376 -0
  173. package/lib/WAM/encode.d.ts +2 -0
  174. package/lib/WAM/encode.js +181 -0
  175. package/lib/WAM/index.d.ts +1 -0
  176. package/lib/WAM/index.js +45 -0
  177. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +14 -0
  178. package/lib/WAUSync/Protocols/USyncContactProtocol.js +58 -0
  179. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  180. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +83 -0
  181. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  182. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +56 -0
  183. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  184. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +68 -0
  185. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +39 -0
  186. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +79 -0
  187. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
  188. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +50 -0
  189. package/lib/WAUSync/Protocols/index.d.ts +1 -0
  190. package/lib/WAUSync/Protocols/index.js +46 -0
  191. package/lib/WAUSync/USyncQuery.d.ts +20 -0
  192. package/lib/WAUSync/USyncQuery.js +115 -0
  193. package/lib/WAUSync/USyncUser.d.ts +13 -0
  194. package/lib/WAUSync/USyncUser.js +52 -0
  195. package/lib/WAUSync/index.d.ts +1 -0
  196. package/lib/WAUSync/index.js +45 -0
  197. package/lib/index.js +81 -0
  198. package/package.json +113 -0
  199. package/requirements.js +32 -0
@@ -0,0 +1,216 @@
1
+ export const __esModule: boolean;
2
+ export function makeGroupsSocket(config: any): {
3
+ groupQuery: (jid: any, type: any, content: any) => Promise<any>;
4
+ groupMetadata: (jid: any) => Promise<{
5
+ desc: any;
6
+ descId: any;
7
+ descOwner: any;
8
+ descOwnerLid: any;
9
+ descTime: number;
10
+ linkedParent: any;
11
+ restrict: boolean;
12
+ announce: boolean;
13
+ isCommunity: boolean;
14
+ isCommunityAnnounce: boolean;
15
+ joinApprovalMode: boolean;
16
+ memberAddMode: boolean;
17
+ participants: any;
18
+ ephemeralDuration: number;
19
+ ownerLid?: any;
20
+ subjectTime: number;
21
+ size: any;
22
+ creation: number;
23
+ owner: any;
24
+ subjectOwnerLid?: any;
25
+ id: any;
26
+ addressingMode: any;
27
+ subject: any;
28
+ subjectOwner: any;
29
+ }>;
30
+ groupCreate: (subject: any, participants: any) => Promise<{
31
+ desc: any;
32
+ descId: any;
33
+ descOwner: any;
34
+ descOwnerLid: any;
35
+ descTime: number;
36
+ linkedParent: any;
37
+ restrict: boolean;
38
+ announce: boolean;
39
+ isCommunity: boolean;
40
+ isCommunityAnnounce: boolean;
41
+ joinApprovalMode: boolean;
42
+ memberAddMode: boolean;
43
+ participants: any;
44
+ ephemeralDuration: number;
45
+ ownerLid?: any;
46
+ subjectTime: number;
47
+ size: any;
48
+ creation: number;
49
+ owner: any;
50
+ subjectOwnerLid?: any;
51
+ id: any;
52
+ addressingMode: any;
53
+ subject: any;
54
+ subjectOwner: any;
55
+ }>;
56
+ groupLeave: (id: any) => Promise<void>;
57
+ groupUpdateSubject: (jid: any, subject: any) => Promise<void>;
58
+ groupRequestParticipantsList: (jid: any) => Promise<any>;
59
+ groupRequestParticipantsUpdate: (jid: any, participants: any, action: any) => Promise<any>;
60
+ groupParticipantsUpdate: (jid: any, participants: any, action: any) => Promise<any>;
61
+ groupUpdateDescription: (jid: any, description: any) => Promise<void>;
62
+ groupInviteCode: (jid: any) => Promise<any>;
63
+ groupRevokeInvite: (jid: any) => Promise<any>;
64
+ groupAcceptInvite: (code: any) => Promise<any>;
65
+ /**
66
+ * revoke a v4 invite for someone
67
+ * @param groupJid group jid
68
+ * @param invitedJid jid of person you invited
69
+ * @returns true if successful
70
+ */
71
+ groupRevokeInviteV4: (groupJid: any, invitedJid: any) => Promise<boolean>;
72
+ /**
73
+ * accept a GroupInviteMessage
74
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
75
+ * @param inviteMessage the message to accept
76
+ */
77
+ groupAcceptInviteV4: any;
78
+ groupGetInviteInfo: (code: any) => Promise<{
79
+ desc: any;
80
+ descId: any;
81
+ descOwner: any;
82
+ descOwnerLid: any;
83
+ descTime: number;
84
+ linkedParent: any;
85
+ restrict: boolean;
86
+ announce: boolean;
87
+ isCommunity: boolean;
88
+ isCommunityAnnounce: boolean;
89
+ joinApprovalMode: boolean;
90
+ memberAddMode: boolean;
91
+ participants: any;
92
+ ephemeralDuration: number;
93
+ ownerLid?: any;
94
+ subjectTime: number;
95
+ size: any;
96
+ creation: number;
97
+ owner: any;
98
+ subjectOwnerLid?: any;
99
+ id: any;
100
+ addressingMode: any;
101
+ subject: any;
102
+ subjectOwner: any;
103
+ }>;
104
+ groupToggleEphemeral: (jid: any, ephemeralExpiration: any) => Promise<void>;
105
+ groupSettingUpdate: (jid: any, setting: any) => Promise<void>;
106
+ groupMemberAddMode: (jid: any, mode: any) => Promise<void>;
107
+ groupJoinApprovalMode: (jid: any, mode: any) => Promise<void>;
108
+ groupFetchAllParticipating: () => Promise<{}>;
109
+ createCallLink: (type: any, event: any, timeoutMs: any) => Promise<any>;
110
+ getBotListV2: () => Promise<{
111
+ jid: any;
112
+ personaId: any;
113
+ }[]>;
114
+ processingMutex: {
115
+ mutex(code: any): Promise<void>;
116
+ };
117
+ fetchPrivacySettings: (force?: boolean) => Promise<any>;
118
+ upsertMessage: any;
119
+ appPatch: (patchCreate: any) => Promise<void>;
120
+ sendPresenceUpdate: (type: any, toJid: any) => Promise<void>;
121
+ presenceSubscribe: (toJid: any, tcToken: any) => Promise<void>;
122
+ profilePictureUrl: (jid: any, type: string, timeoutMs: any) => Promise<any>;
123
+ onWhatsApp: (...jids: any[]) => Promise<any>;
124
+ fetchBlocklist: () => Promise<any>;
125
+ fetchDisappearingDuration: (...jids: any[]) => Promise<any>;
126
+ fetchStatus: (...jids: any[]) => Promise<any>;
127
+ updateProfilePicture: (jid: any, content: any, dimensions: any) => Promise<void>;
128
+ removeProfilePicture: (jid: any) => Promise<void>;
129
+ updateProfileStatus: (status: any) => Promise<void>;
130
+ updateProfileName: (name: any) => Promise<void>;
131
+ updateBlockStatus: (jid: any, action: any) => Promise<void>;
132
+ updateDisableLinkPreviewsPrivacy: (isPreviewsDisabled: any) => Promise<void>;
133
+ updateCallPrivacy: (value: any) => Promise<void>;
134
+ updateMessagesPrivacy: (value: any) => Promise<void>;
135
+ updateLastSeenPrivacy: (value: any) => Promise<void>;
136
+ updateOnlinePrivacy: (value: any) => Promise<void>;
137
+ updateProfilePicturePrivacy: (value: any) => Promise<void>;
138
+ updateStatusPrivacy: (value: any) => Promise<void>;
139
+ updateReadReceiptsPrivacy: (value: any) => Promise<void>;
140
+ updateGroupsAddPrivacy: (value: any) => Promise<void>;
141
+ updateDefaultDisappearingMode: (duration: any) => Promise<void>;
142
+ getBusinessProfile: (jid: any) => Promise<{
143
+ wid: any;
144
+ address: any;
145
+ description: any;
146
+ website: any[];
147
+ email: any;
148
+ category: any;
149
+ business_hours: {
150
+ timezone: any;
151
+ business_config: any;
152
+ };
153
+ }>;
154
+ resyncAppState: any;
155
+ chatModify: (mod: any, jid: any) => Promise<void>;
156
+ cleanDirtyBits: (type: any, fromTimestamp: any) => Promise<void>;
157
+ addOrEditContact: (jid: any, contact: any) => Promise<void>;
158
+ removeContact: (jid: any) => Promise<void>;
159
+ addLabel: (jid: any, labels: any) => Promise<void>;
160
+ addChatLabel: (jid: any, labelId: any) => Promise<void>;
161
+ removeChatLabel: (jid: any, labelId: any) => Promise<void>;
162
+ addMessageLabel: (jid: any, messageId: any, labelId: any) => Promise<void>;
163
+ removeMessageLabel: (jid: any, messageId: any, labelId: any) => Promise<void>;
164
+ star: (jid: any, messages: any, star: any) => Promise<void>;
165
+ checkWhatsApp: (jid: any) => Promise<string>;
166
+ executeUSyncQuery: (usyncQuery: any) => Promise<any>;
167
+ type: string;
168
+ ws: any;
169
+ ev: any;
170
+ authState: {
171
+ creds: any;
172
+ keys: any;
173
+ };
174
+ signalRepository: any;
175
+ user: any;
176
+ generateMessageTag: () => string;
177
+ query: (node: any, timeoutMs: any) => Promise<any>;
178
+ waitForMessage: (msgId: any, timeoutMs?: any) => Promise<any>;
179
+ waitForSocketOpen: () => Promise<void>;
180
+ sendRawMessage: (data: any) => Promise<void>;
181
+ sendNode: (frame: any) => Promise<void>;
182
+ logout: (msg: any) => Promise<void>;
183
+ end: (error: any) => void;
184
+ onUnexpectedError: (err: any, msg: any) => void;
185
+ uploadPreKeys: (count?: 812) => Promise<void>;
186
+ uploadPreKeysToServerIfRequired: () => Promise<void>;
187
+ requestPairingCode: (phoneNumber: any, pairCode?: string) => Promise<any>;
188
+ waitForConnectionUpdate: any;
189
+ sendWAMBuffer: (wamBuffer: any) => Promise<any>;
190
+ };
191
+ export function extractGroupMetadata(result: any): {
192
+ desc: any;
193
+ descId: any;
194
+ descOwner: any;
195
+ descOwnerLid: any;
196
+ descTime: number;
197
+ linkedParent: any;
198
+ restrict: boolean;
199
+ announce: boolean;
200
+ isCommunity: boolean;
201
+ isCommunityAnnounce: boolean;
202
+ joinApprovalMode: boolean;
203
+ memberAddMode: boolean;
204
+ participants: any;
205
+ ephemeralDuration: number;
206
+ ownerLid?: any;
207
+ subjectTime: number;
208
+ size: any;
209
+ creation: number;
210
+ owner: any;
211
+ subjectOwnerLid?: any;
212
+ id: any;
213
+ addressingMode: any;
214
+ subject: any;
215
+ subjectOwner: any;
216
+ };
@@ -0,0 +1,358 @@
1
+ /**
2
+ * ╔═══════════════════════════════════════════════════════════╗
3
+ * ║ NEROX - WhatsApp API Library ║
4
+ * ║ Premium Edition ║
5
+ * ╚═══════════════════════════════════════════════════════════╝
6
+ *
7
+ * @package nerox-bails
8
+ * @version 0.1.0
9
+ * @author NEROX Development Team
10
+ * @copyright Copyright (c) 2025 NEROX. All rights reserved.
11
+ * @license MIT License
12
+ *
13
+ * Permission is hereby granted, free of charge, to any person obtaining
14
+ * a copy of this software and associated documentation files (the "Software"),
15
+ * to deal in the Software without restriction, including without limitation
16
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17
+ * and/or sell copies of the Software, and to permit persons to whom the
18
+ * Software is furnished to do so, subject to the following conditions:
19
+ *
20
+ * The above copyright notice and this permission notice shall be included
21
+ * in all copies or substantial portions of the Software.
22
+ *
23
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26
+ */
27
+ "use strict";
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.extractGroupMetadata = exports.makeGroupsSocket = void 0;
30
+ const WAProto_1 = require("../../WAProto");
31
+ const Types_1 = require("../Types");
32
+ const Utils_1 = require("../Utils");
33
+ const WABinary_1 = require("../WABinary");
34
+ const chats_1 = require("./chats");
35
+ const makeGroupsSocket = (config) => {
36
+ const sock = (0, chats_1.makeChatsSocket)(config);
37
+ const { authState, ev, query, upsertMessage } = sock;
38
+ const groupQuery = async (jid, type, content) => (query({
39
+ tag: 'iq',
40
+ attrs: {
41
+ type,
42
+ xmlns: 'w:g2',
43
+ to: jid,
44
+ },
45
+ content
46
+ }));
47
+ const groupMetadata = async (jid) => {
48
+ const result = await groupQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
49
+ return (0, exports.extractGroupMetadata)(result);
50
+ };
51
+ const groupFetchAllParticipating = async () => {
52
+ const result = await query({
53
+ tag: 'iq',
54
+ attrs: {
55
+ to: '@g.us',
56
+ xmlns: 'w:g2',
57
+ type: 'get',
58
+ },
59
+ content: [
60
+ {
61
+ tag: 'participating',
62
+ attrs: {},
63
+ content: [
64
+ { tag: 'participants', attrs: {} },
65
+ { tag: 'description', attrs: {} }
66
+ ]
67
+ }
68
+ ]
69
+ });
70
+ const data = {};
71
+ const groupsChild = (0, WABinary_1.getBinaryNodeChild)(result, 'groups');
72
+ if (groupsChild) {
73
+ const groups = (0, WABinary_1.getBinaryNodeChildren)(groupsChild, 'group');
74
+ for (const groupNode of groups) {
75
+ const meta = (0, exports.extractGroupMetadata)({
76
+ tag: 'result',
77
+ attrs: {},
78
+ content: [groupNode]
79
+ });
80
+ data[meta.id] = meta;
81
+ }
82
+ }
83
+ sock.ev.emit('groups.update', Object.values(data));
84
+ return data;
85
+ };
86
+ sock.ws.on('CB:ib,,dirty', async (node) => {
87
+ const { attrs } = (0, WABinary_1.getBinaryNodeChild)(node, 'dirty');
88
+ if (attrs.type !== 'groups') {
89
+ return;
90
+ }
91
+ await groupFetchAllParticipating();
92
+ await sock.cleanDirtyBits('groups');
93
+ });
94
+ return {
95
+ ...sock,
96
+ groupQuery,
97
+ groupMetadata,
98
+ groupCreate: async (subject, participants) => {
99
+ const key = (0, Utils_1.generateMessageIDV2)();
100
+ const result = await groupQuery('@g.us', 'set', [
101
+ {
102
+ tag: 'create',
103
+ attrs: {
104
+ subject,
105
+ key
106
+ },
107
+ content: participants.map(jid => ({
108
+ tag: 'participant',
109
+ attrs: { jid }
110
+ }))
111
+ }
112
+ ]);
113
+ return (0, exports.extractGroupMetadata)(result);
114
+ },
115
+ groupLeave: async (id) => {
116
+ await groupQuery('@g.us', 'set', [
117
+ {
118
+ tag: 'leave',
119
+ attrs: {},
120
+ content: [
121
+ { tag: 'group', attrs: { id } }
122
+ ]
123
+ }
124
+ ]);
125
+ },
126
+ groupUpdateSubject: async (jid, subject) => {
127
+ await groupQuery(jid, 'set', [
128
+ {
129
+ tag: 'subject',
130
+ attrs: {},
131
+ content: Buffer.from(subject, 'utf-8')
132
+ }
133
+ ]);
134
+ },
135
+ groupRequestParticipantsList: async (jid) => {
136
+ const result = await groupQuery(jid, 'get', [
137
+ {
138
+ tag: 'membership_approval_requests',
139
+ attrs: {}
140
+ }
141
+ ]);
142
+ const node = (0, WABinary_1.getBinaryNodeChild)(result, 'membership_approval_requests');
143
+ const participants = (0, WABinary_1.getBinaryNodeChildren)(node, 'membership_approval_request');
144
+ return participants.map(v => v.attrs);
145
+ },
146
+ groupRequestParticipantsUpdate: async (jid, participants, action) => {
147
+ const result = await groupQuery(jid, 'set', [{
148
+ tag: 'membership_requests_action',
149
+ attrs: {},
150
+ content: [
151
+ {
152
+ tag: action,
153
+ attrs: {},
154
+ content: participants.map(jid => ({
155
+ tag: 'participant',
156
+ attrs: { jid }
157
+ }))
158
+ }
159
+ ]
160
+ }]);
161
+ const node = (0, WABinary_1.getBinaryNodeChild)(result, 'membership_requests_action');
162
+ const nodeAction = (0, WABinary_1.getBinaryNodeChild)(node, action);
163
+ const participantsAffected = (0, WABinary_1.getBinaryNodeChildren)(nodeAction, 'participant');
164
+ return participantsAffected.map(p => {
165
+ return { status: p.attrs.error || '200', jid: p.attrs.jid };
166
+ });
167
+ },
168
+ groupParticipantsUpdate: async (jid, participants, action) => {
169
+ const result = await groupQuery(jid, 'set', [
170
+ {
171
+ tag: action,
172
+ attrs: {},
173
+ content: participants.map(jid => ({
174
+ tag: 'participant',
175
+ attrs: { jid }
176
+ }))
177
+ }
178
+ ]);
179
+ const node = (0, WABinary_1.getBinaryNodeChild)(result, action);
180
+ const participantsAffected = (0, WABinary_1.getBinaryNodeChildren)(node, 'participant');
181
+ return participantsAffected.map(p => {
182
+ return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
183
+ });
184
+ },
185
+ groupUpdateDescription: async (jid, description) => {
186
+ var _a;
187
+ const metadata = await groupMetadata(jid);
188
+ const prev = (_a = metadata.descId) !== null && _a !== void 0 ? _a : null;
189
+ await groupQuery(jid, 'set', [
190
+ {
191
+ tag: 'description',
192
+ attrs: {
193
+ ...(description ? { id: (0, Utils_1.generateMessageIDV2)() } : { delete: 'true' }),
194
+ ...(prev ? { prev } : {})
195
+ },
196
+ content: description ? [
197
+ { tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }
198
+ ] : undefined
199
+ }
200
+ ]);
201
+ },
202
+ groupInviteCode: async (jid) => {
203
+ const result = await groupQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
204
+ const inviteNode = (0, WABinary_1.getBinaryNodeChild)(result, 'invite');
205
+ return inviteNode === null || inviteNode === void 0 ? void 0 : inviteNode.attrs.code;
206
+ },
207
+ groupRevokeInvite: async (jid) => {
208
+ const result = await groupQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
209
+ const inviteNode = (0, WABinary_1.getBinaryNodeChild)(result, 'invite');
210
+ return inviteNode === null || inviteNode === void 0 ? void 0 : inviteNode.attrs.code;
211
+ },
212
+ groupAcceptInvite: async (code) => {
213
+ const results = await groupQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
214
+ const result = (0, WABinary_1.getBinaryNodeChild)(results, 'group');
215
+ return result === null || result === void 0 ? void 0 : result.attrs.jid;
216
+ },
217
+ /**
218
+ * revoke a v4 invite for someone
219
+ * @param groupJid group jid
220
+ * @param invitedJid jid of person you invited
221
+ * @returns true if successful
222
+ */
223
+ groupRevokeInviteV4: async (groupJid, invitedJid) => {
224
+ const result = await groupQuery(groupJid, 'set', [{ tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }]);
225
+ return !!result;
226
+ },
227
+ /**
228
+ * accept a GroupInviteMessage
229
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
230
+ * @param inviteMessage the message to accept
231
+ */
232
+ groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
233
+ var _a;
234
+ key = typeof key === 'string' ? { remoteJid: key } : key;
235
+ const results = await groupQuery(inviteMessage.groupJid, 'set', [{
236
+ tag: 'accept',
237
+ attrs: {
238
+ code: inviteMessage.inviteCode,
239
+ expiration: inviteMessage.inviteExpiration.toString(),
240
+ admin: key.remoteJid
241
+ }
242
+ }]);
243
+
244
+
245
+ if (key.id) {
246
+
247
+ inviteMessage = WAProto_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage);
248
+ inviteMessage.inviteExpiration = 0;
249
+ inviteMessage.inviteCode = '';
250
+ ev.emit('messages.update', [
251
+ {
252
+ key,
253
+ update: {
254
+ message: {
255
+ groupInviteMessage: inviteMessage
256
+ }
257
+ }
258
+ }
259
+ ]);
260
+ }
261
+
262
+ await upsertMessage({
263
+ key: {
264
+ remoteJid: inviteMessage.groupJid,
265
+ id: (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id),
266
+ fromMe: false,
267
+ participant: key.remoteJid,
268
+ },
269
+ messageStubType: Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD,
270
+ messageStubParameters: [
271
+ authState.creds.me.id
272
+ ],
273
+ participant: key.remoteJid,
274
+ messageTimestamp: (0, Utils_1.unixTimestampSeconds)()
275
+ }, 'notify');
276
+ return results.attrs.from;
277
+ }),
278
+ groupGetInviteInfo: async (code) => {
279
+ const results = await groupQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
280
+ return (0, exports.extractGroupMetadata)(results);
281
+ },
282
+ groupToggleEphemeral: async (jid, ephemeralExpiration) => {
283
+ const content = ephemeralExpiration ?
284
+ { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } } :
285
+ { tag: 'not_ephemeral', attrs: {} };
286
+ await groupQuery(jid, 'set', [content]);
287
+ },
288
+ groupSettingUpdate: async (jid, setting) => {
289
+ await groupQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
290
+ },
291
+ groupMemberAddMode: async (jid, mode) => {
292
+ await groupQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
293
+ },
294
+ groupJoinApprovalMode: async (jid, mode) => {
295
+ await groupQuery(jid, 'set', [{ tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }]);
296
+ },
297
+ groupFetchAllParticipating
298
+ };
299
+ };
300
+ exports.makeGroupsSocket = makeGroupsSocket;
301
+ const extractGroupMetadata = (result) => {
302
+ var _a, _b;
303
+ const group = (0, WABinary_1.getBinaryNodeChild)(result, 'group');
304
+ const descChild = (0, WABinary_1.getBinaryNodeChild)(group, 'description');
305
+ let desc;
306
+ let descId;
307
+ let descOwner;
308
+ let descOwnerLid;
309
+ let descTime;
310
+ if (descChild) {
311
+ desc = (0, WABinary_1.getBinaryNodeChildString)(descChild, 'body');
312
+ descOwner = (0, WABinary_1.jidNormalizedUser)(descChild.attrs.participant_pn || descChild.attrs.participant);
313
+ if (group.attrs.addressing_mode === 'lid') {
314
+ descOwnerLid = (0, WABinary_1.jidNormalizedUser)(descChild.attrs.participant);
315
+ }
316
+ descId = descChild.attrs.id;
317
+ descTime = descChild.attrs.t ? +descChild.attrs.t : undefined;
318
+ }
319
+ const groupSize = group.attrs.size ? Number(group.attrs.size) : undefined;
320
+ const groupId = group.attrs.id.includes('@') ? group.attrs.id : (0, WABinary_1.jidEncode)(group.attrs.id, 'g.us');
321
+ const eph = (_a = (0, WABinary_1.getBinaryNodeChild)(group, 'ephemeral')) === null || _a === void 0 ? void 0 : _a.attrs.expiration;
322
+ const memberAddMode = (0, WABinary_1.getBinaryNodeChildString)(group, 'member_add_mode') === 'all_member_add';
323
+ const metadata = {
324
+ id: groupId,
325
+ addressingMode: group.attrs.addressing_mode,
326
+ subject: group.attrs.subject,
327
+ subjectOwner: (0, WABinary_1.jidNormalizedUser)(group.attrs.s_o_pn || group.attrs.s_o),
328
+ ...(group.attrs.addressing_mode === 'lid' ? { subjectOwnerLid: (0, WABinary_1.jidNormalizedUser)(group.attrs.s_o) } : {}),
329
+ subjectTime: group.attrs.s_t ? +group.attrs.s_t : undefined,
330
+ size: groupSize || (0, WABinary_1.getBinaryNodeChildren)(group, 'participant').length,
331
+ creation: group.attrs.creation ? +group.attrs.creation : undefined,
332
+ owner: (0, WABinary_1.jidNormalizedUser)(group.attrs.creator_pn || group.attrs.creator),
333
+ ...(group.attrs.addressing_mode === 'lid' ? { ownerLid: (0, WABinary_1.jidNormalizedUser)(group.attrs.creator) } : {}),
334
+ desc,
335
+ descId,
336
+ descOwner,
337
+ descOwnerLid,
338
+ descTime,
339
+ linkedParent: ((_b = (0, WABinary_1.getBinaryNodeChild)(group, 'linked_parent')) === null || _b === void 0 ? void 0 : _b.attrs.jid) || undefined,
340
+ restrict: !!(0, WABinary_1.getBinaryNodeChild)(group, 'locked'),
341
+ announce: !!(0, WABinary_1.getBinaryNodeChild)(group, 'announcement'),
342
+ isCommunity: !!(0, WABinary_1.getBinaryNodeChild)(group, 'parent'),
343
+ isCommunityAnnounce: !!(0, WABinary_1.getBinaryNodeChild)(group, 'default_sub_group'),
344
+ joinApprovalMode: !!(0, WABinary_1.getBinaryNodeChild)(group, 'membership_approval_mode'),
345
+ memberAddMode,
346
+ participants: (0, WABinary_1.getBinaryNodeChildren)(group, 'participant').map(({ attrs }) => {
347
+ return {
348
+ id: attrs.jid,
349
+ jid: attrs.phone_number || attrs.jid,
350
+ lid: attrs.lid || attrs.jid,
351
+ admin: (attrs.type || null),
352
+ };
353
+ }),
354
+ ephemeralDuration: eph ? +eph : undefined
355
+ };
356
+ return metadata;
357
+ };
358
+ exports.extractGroupMetadata = extractGroupMetadata;