@kevin-b2t/baileys 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/README.md +393 -0
  2. package/WAProto/index.js +169661 -0
  3. package/engine-requirements.js +10 -0
  4. package/lib/Defaults/baileys-version.json +3 -0
  5. package/lib/Defaults/index.d.ts +53 -0
  6. package/lib/Defaults/index.js +147 -0
  7. package/lib/Defaults/phonenumber-mcc.json +223 -0
  8. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  9. package/lib/Signal/Group/ciphertext-message.js +15 -0
  10. package/lib/Signal/Group/group-session-builder.d.ts +14 -0
  11. package/lib/Signal/Group/group-session-builder.js +64 -0
  12. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  13. package/lib/Signal/Group/group_cipher.js +96 -0
  14. package/lib/Signal/Group/index.d.ts +11 -0
  15. package/lib/Signal/Group/index.js +57 -0
  16. package/lib/Signal/Group/keyhelper.d.ts +10 -0
  17. package/lib/Signal/Group/keyhelper.js +55 -0
  18. package/lib/Signal/Group/queue-job.d.ts +1 -0
  19. package/lib/Signal/Group/queue-job.js +57 -0
  20. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  21. package/lib/Signal/Group/sender-chain-key.js +34 -0
  22. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  23. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  24. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  25. package/lib/Signal/Group/sender-key-message.js +69 -0
  26. package/lib/Signal/Group/sender-key-name.d.ts +17 -0
  27. package/lib/Signal/Group/sender-key-name.js +51 -0
  28. package/lib/Signal/Group/sender-key-record.d.ts +30 -0
  29. package/lib/Signal/Group/sender-key-record.js +53 -0
  30. package/lib/Signal/Group/sender-key-state.d.ts +38 -0
  31. package/lib/Signal/Group/sender-key-state.js +99 -0
  32. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  33. package/lib/Signal/Group/sender-message-key.js +29 -0
  34. package/lib/Signal/libsignal.d.ts +3 -0
  35. package/lib/Signal/libsignal.js +174 -0
  36. package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
  37. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  38. package/lib/Socket/Client/index.d.ts +3 -0
  39. package/lib/Socket/Client/index.js +19 -0
  40. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  41. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  42. package/lib/Socket/Client/web-socket-client.d.ts +12 -0
  43. package/lib/Socket/Client/web-socket-client.js +62 -0
  44. package/lib/Socket/business.d.ts +171 -0
  45. package/lib/Socket/business.js +260 -0
  46. package/lib/Socket/chats.d.ts +267 -0
  47. package/lib/Socket/chats.js +983 -0
  48. package/lib/Socket/communities.js +421 -0
  49. package/lib/Socket/dugong.d.ts +258 -0
  50. package/lib/Socket/dugong.js +424 -0
  51. package/lib/Socket/groups.d.ts +115 -0
  52. package/lib/Socket/groups.js +324 -0
  53. package/lib/Socket/index.d.ts +173 -0
  54. package/lib/Socket/index.js +11 -0
  55. package/lib/Socket/messages-recv.d.ts +161 -0
  56. package/lib/Socket/messages-recv.js +1138 -0
  57. package/lib/Socket/messages-send.d.ts +149 -0
  58. package/lib/Socket/messages-send.js +909 -0
  59. package/lib/Socket/newsletter.d.ts +134 -0
  60. package/lib/Socket/newsletter.js +334 -0
  61. package/lib/Socket/registration.d.ts +267 -0
  62. package/lib/Socket/registration.js +166 -0
  63. package/lib/Socket/socket.d.ts +43 -0
  64. package/lib/Socket/socket.js +665 -0
  65. package/lib/Socket/usync.d.ts +36 -0
  66. package/lib/Socket/usync.js +70 -0
  67. package/lib/Store/index.d.ts +3 -0
  68. package/lib/Store/index.js +10 -0
  69. package/lib/Store/make-cache-manager-store.d.ts +13 -0
  70. package/lib/Store/make-cache-manager-store.js +83 -0
  71. package/lib/Store/make-in-memory-store.d.ts +118 -0
  72. package/lib/Store/make-in-memory-store.js +427 -0
  73. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  74. package/lib/Store/make-ordered-dictionary.js +81 -0
  75. package/lib/Store/object-repository.d.ts +10 -0
  76. package/lib/Store/object-repository.js +27 -0
  77. package/lib/Types/Auth.d.ts +110 -0
  78. package/lib/Types/Auth.js +2 -0
  79. package/lib/Types/Call.d.ts +13 -0
  80. package/lib/Types/Call.js +2 -0
  81. package/lib/Types/Chat.d.ts +102 -0
  82. package/lib/Types/Chat.js +4 -0
  83. package/lib/Types/Contact.d.ts +19 -0
  84. package/lib/Types/Contact.js +2 -0
  85. package/lib/Types/Events.d.ts +157 -0
  86. package/lib/Types/Events.js +2 -0
  87. package/lib/Types/GroupMetadata.d.ts +55 -0
  88. package/lib/Types/GroupMetadata.js +2 -0
  89. package/lib/Types/Label.d.ts +35 -0
  90. package/lib/Types/Label.js +27 -0
  91. package/lib/Types/LabelAssociation.d.ts +29 -0
  92. package/lib/Types/LabelAssociation.js +9 -0
  93. package/lib/Types/Message.d.ts +273 -0
  94. package/lib/Types/Message.js +9 -0
  95. package/lib/Types/Newsletter.d.ts +103 -0
  96. package/lib/Types/Newsletter.js +38 -0
  97. package/lib/Types/Product.d.ts +78 -0
  98. package/lib/Types/Product.js +2 -0
  99. package/lib/Types/Signal.d.ts +57 -0
  100. package/lib/Types/Signal.js +2 -0
  101. package/lib/Types/Socket.d.ts +111 -0
  102. package/lib/Types/Socket.js +2 -0
  103. package/lib/Types/State.d.ts +27 -0
  104. package/lib/Types/State.js +2 -0
  105. package/lib/Types/USync.d.ts +25 -0
  106. package/lib/Types/USync.js +2 -0
  107. package/lib/Types/index.d.ts +57 -0
  108. package/lib/Types/index.js +42 -0
  109. package/lib/Utils/auth-utils.d.ts +18 -0
  110. package/lib/Utils/auth-utils.js +206 -0
  111. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  112. package/lib/Utils/baileys-event-stream.js +63 -0
  113. package/lib/Utils/business.d.ts +22 -0
  114. package/lib/Utils/business.js +234 -0
  115. package/lib/Utils/chat-utils.d.ts +71 -0
  116. package/lib/Utils/chat-utils.js +729 -0
  117. package/lib/Utils/crypto.d.ts +41 -0
  118. package/lib/Utils/crypto.js +151 -0
  119. package/lib/Utils/decode-wa-message.d.ts +19 -0
  120. package/lib/Utils/decode-wa-message.js +198 -0
  121. package/lib/Utils/event-buffer.d.ts +35 -0
  122. package/lib/Utils/event-buffer.js +514 -0
  123. package/lib/Utils/generics.d.ts +92 -0
  124. package/lib/Utils/generics.js +457 -0
  125. package/lib/Utils/history.d.ts +15 -0
  126. package/lib/Utils/history.js +96 -0
  127. package/lib/Utils/index.d.ts +17 -0
  128. package/lib/Utils/index.js +35 -0
  129. package/lib/Utils/lid-resolver.js +73 -0
  130. package/lib/Utils/link-preview.d.ts +21 -0
  131. package/lib/Utils/link-preview.js +93 -0
  132. package/lib/Utils/logger.d.ts +4 -0
  133. package/lib/Utils/logger.js +7 -0
  134. package/lib/Utils/lt-hash.d.ts +12 -0
  135. package/lib/Utils/lt-hash.js +51 -0
  136. package/lib/Utils/make-mutex.d.ts +7 -0
  137. package/lib/Utils/make-mutex.js +43 -0
  138. package/lib/Utils/mention.d.ts +7 -0
  139. package/lib/Utils/mention.js +147 -0
  140. package/lib/Utils/messages-media.d.ts +116 -0
  141. package/lib/Utils/messages-media.js +819 -0
  142. package/lib/Utils/messages.d.ts +77 -0
  143. package/lib/Utils/messages.js +784 -0
  144. package/lib/Utils/noise-handler.d.ts +21 -0
  145. package/lib/Utils/noise-handler.js +155 -0
  146. package/lib/Utils/process-message.d.ts +41 -0
  147. package/lib/Utils/process-message.js +321 -0
  148. package/lib/Utils/signal.d.ts +32 -0
  149. package/lib/Utils/signal.js +153 -0
  150. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  151. package/lib/Utils/use-multi-file-auth-state.js +119 -0
  152. package/lib/Utils/validate-connection.d.ts +11 -0
  153. package/lib/Utils/validate-connection.js +229 -0
  154. package/lib/WABinary/constants.d.ts +30 -0
  155. package/lib/WABinary/constants.js +40 -0
  156. package/lib/WABinary/decode.d.ts +7 -0
  157. package/lib/WABinary/decode.js +252 -0
  158. package/lib/WABinary/encode.d.ts +3 -0
  159. package/lib/WABinary/encode.js +265 -0
  160. package/lib/WABinary/generic-utils.d.ts +17 -0
  161. package/lib/WABinary/generic-utils.js +198 -0
  162. package/lib/WABinary/index.d.ts +5 -0
  163. package/lib/WABinary/index.js +21 -0
  164. package/lib/WABinary/jid-utils.d.ts +31 -0
  165. package/lib/WABinary/jid-utils.js +62 -0
  166. package/lib/WABinary/types.d.ts +18 -0
  167. package/lib/WABinary/types.js +2 -0
  168. package/lib/WAM/BinaryInfo.d.ts +17 -0
  169. package/lib/WAM/BinaryInfo.js +13 -0
  170. package/lib/WAM/constants.d.ts +38 -0
  171. package/lib/WAM/constants.js +15350 -0
  172. package/lib/WAM/encode.d.ts +3 -0
  173. package/lib/WAM/encode.js +155 -0
  174. package/lib/WAM/index.d.ts +3 -0
  175. package/lib/WAM/index.js +19 -0
  176. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  177. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  178. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  179. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  180. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  181. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  182. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  183. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  184. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +29 -0
  185. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
  186. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
  187. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
  188. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
  189. package/lib/WAUSync/Protocols/index.d.ts +4 -0
  190. package/lib/WAUSync/Protocols/index.js +21 -0
  191. package/lib/WAUSync/USyncQuery.d.ts +28 -0
  192. package/lib/WAUSync/USyncQuery.js +93 -0
  193. package/lib/WAUSync/USyncUser.d.ts +12 -0
  194. package/lib/WAUSync/USyncUser.js +26 -0
  195. package/lib/WAUSync/index.d.ts +3 -0
  196. package/lib/WAUSync/index.js +19 -0
  197. package/lib/index.d.ts +12 -0
  198. package/lib/index.js +43 -0
  199. package/package.json +111 -0
@@ -0,0 +1,421 @@
1
+ "use strict";
2
+ // Ported from WhiskeySockets/Baileys (communities.js) to lily's CommonJS style.
3
+ // New, self-contained capability: create/manage WhatsApp Communities (parent
4
+ // groups that link sub-groups together). Doesn't touch signal/protocol
5
+ // internals, only adds new high-level methods on top of the existing socket.
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.extractCommunityMetadata = exports.makeCommunitiesSocket = void 0;
8
+ const WAProto_1 = require("../../WAProto");
9
+ const Types_1 = require("../Types");
10
+ const Utils_1 = require("../Utils");
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
+ const Optional = {
65
+ empty: () => null,
66
+ of: (value) => (value !== null ? { value } : null)
67
+ };
68
+ async function parseGroupResult(node) {
69
+ const groupNode = (0, WABinary_1.getBinaryNodeChild)(node, 'group');
70
+ if (groupNode) {
71
+ try {
72
+ const metadata = await sock.groupMetadata(`${groupNode.attrs.id}@g.us`);
73
+ return metadata ? metadata : Optional.empty();
74
+ }
75
+ catch (error) {
76
+ console.error('Error parsing group metadata:', error);
77
+ return Optional.empty();
78
+ }
79
+ }
80
+ return Optional.empty();
81
+ }
82
+ sock.ws.on('CB:ib,,dirty', async (node) => {
83
+ const { attrs } = (0, WABinary_1.getBinaryNodeChild)(node, 'dirty');
84
+ if (attrs.type !== 'communities') {
85
+ return;
86
+ }
87
+ await communityFetchAllParticipating();
88
+ await sock.cleanDirtyBits('groups');
89
+ });
90
+ return {
91
+ ...sock,
92
+ communityMetadata,
93
+ communityCreate: async (subject, body) => {
94
+ const descriptionId = (0, Utils_1.generateMessageID)().substring(0, 12);
95
+ const result = await communityQuery('@g.us', 'set', [
96
+ {
97
+ tag: 'create',
98
+ attrs: { subject },
99
+ content: [
100
+ {
101
+ tag: 'description',
102
+ attrs: { id: descriptionId },
103
+ content: [
104
+ {
105
+ tag: 'body',
106
+ attrs: {},
107
+ content: Buffer.from(body || '', 'utf-8')
108
+ }
109
+ ]
110
+ },
111
+ {
112
+ tag: 'parent',
113
+ attrs: { default_membership_approval_mode: 'request_required' }
114
+ },
115
+ {
116
+ tag: 'allow_non_admin_sub_group_creation',
117
+ attrs: {}
118
+ },
119
+ {
120
+ tag: 'create_general_chat',
121
+ attrs: {}
122
+ }
123
+ ]
124
+ }
125
+ ]);
126
+ return await parseGroupResult(result);
127
+ },
128
+ communityCreateGroup: async (subject, participants, parentCommunityJid) => {
129
+ const key = (0, Utils_1.generateMessageIDV2)();
130
+ const result = await communityQuery('@g.us', 'set', [
131
+ {
132
+ tag: 'create',
133
+ attrs: {
134
+ subject,
135
+ key
136
+ },
137
+ content: [
138
+ ...participants.map(jid => ({
139
+ tag: 'participant',
140
+ attrs: { jid }
141
+ })),
142
+ { tag: 'linked_parent', attrs: { jid: parentCommunityJid } }
143
+ ]
144
+ }
145
+ ]);
146
+ return await parseGroupResult(result);
147
+ },
148
+ communityLeave: async (id) => {
149
+ await communityQuery('@g.us', 'set', [
150
+ {
151
+ tag: 'leave',
152
+ attrs: {},
153
+ content: [{ tag: 'community', attrs: { id } }]
154
+ }
155
+ ]);
156
+ },
157
+ communityUpdateSubject: async (jid, subject) => {
158
+ await communityQuery(jid, 'set', [
159
+ {
160
+ tag: 'subject',
161
+ attrs: {},
162
+ content: Buffer.from(subject, 'utf-8')
163
+ }
164
+ ]);
165
+ },
166
+ communityLinkGroup: async (groupJid, parentCommunityJid) => {
167
+ await communityQuery(parentCommunityJid, 'set', [
168
+ {
169
+ tag: 'links',
170
+ attrs: {},
171
+ content: [
172
+ {
173
+ tag: 'link',
174
+ attrs: { link_type: 'sub_group' },
175
+ content: [{ tag: 'group', attrs: { jid: groupJid } }]
176
+ }
177
+ ]
178
+ }
179
+ ]);
180
+ },
181
+ communityUnlinkGroup: async (groupJid, parentCommunityJid) => {
182
+ await communityQuery(parentCommunityJid, 'set', [
183
+ {
184
+ tag: 'unlink',
185
+ attrs: { unlink_type: 'sub_group' },
186
+ content: [{ tag: 'group', attrs: { jid: groupJid } }]
187
+ }
188
+ ]);
189
+ },
190
+ communityFetchLinkedGroups: async (jid) => {
191
+ let communityJid = jid;
192
+ let isCommunity = false;
193
+ const metadata = await sock.groupMetadata(jid);
194
+ if (metadata.linkedParent) {
195
+ communityJid = metadata.linkedParent;
196
+ }
197
+ else {
198
+ isCommunity = true;
199
+ }
200
+ const result = await communityQuery(communityJid, 'get', [{ tag: 'sub_groups', attrs: {} }]);
201
+ const linkedGroupsData = [];
202
+ const subGroupsNode = (0, WABinary_1.getBinaryNodeChild)(result, 'sub_groups');
203
+ if (subGroupsNode) {
204
+ const groupNodes = (0, WABinary_1.getBinaryNodeChildren)(subGroupsNode, 'group');
205
+ for (const groupNode of groupNodes) {
206
+ linkedGroupsData.push({
207
+ id: groupNode.attrs.id ? (0, WABinary_1.jidEncode)(groupNode.attrs.id, 'g.us') : undefined,
208
+ subject: groupNode.attrs.subject || '',
209
+ creation: groupNode.attrs.creation ? Number(groupNode.attrs.creation) : undefined,
210
+ owner: groupNode.attrs.creator ? (0, WABinary_1.jidNormalizedUser)(groupNode.attrs.creator) : undefined,
211
+ size: groupNode.attrs.size ? Number(groupNode.attrs.size) : undefined
212
+ });
213
+ }
214
+ }
215
+ return {
216
+ communityJid,
217
+ isCommunity,
218
+ linkedGroups: linkedGroupsData
219
+ };
220
+ },
221
+ communityRequestParticipantsList: async (jid) => {
222
+ const result = await communityQuery(jid, 'get', [
223
+ {
224
+ tag: 'membership_approval_requests',
225
+ attrs: {}
226
+ }
227
+ ]);
228
+ const node = (0, WABinary_1.getBinaryNodeChild)(result, 'membership_approval_requests');
229
+ const participants = (0, WABinary_1.getBinaryNodeChildren)(node, 'membership_approval_request');
230
+ return participants.map(v => v.attrs);
231
+ },
232
+ communityRequestParticipantsUpdate: async (jid, participants, action) => {
233
+ const result = await communityQuery(jid, 'set', [{
234
+ tag: 'membership_requests_action',
235
+ attrs: {},
236
+ content: [
237
+ {
238
+ tag: action,
239
+ attrs: {},
240
+ content: participants.map(jid => ({
241
+ tag: 'participant',
242
+ attrs: { jid }
243
+ }))
244
+ }
245
+ ]
246
+ }]);
247
+ const node = (0, WABinary_1.getBinaryNodeChild)(result, 'membership_requests_action');
248
+ const nodeAction = (0, WABinary_1.getBinaryNodeChild)(node, action);
249
+ const participantsAffected = (0, WABinary_1.getBinaryNodeChildren)(nodeAction, 'participant');
250
+ return participantsAffected.map(p => {
251
+ return { status: p.attrs.error || '200', jid: p.attrs.jid };
252
+ });
253
+ },
254
+ communityParticipantsUpdate: async (jid, participants, action) => {
255
+ const result = await communityQuery(jid, 'set', [
256
+ {
257
+ tag: action,
258
+ attrs: action === 'remove' ? { linked_groups: 'true' } : {},
259
+ content: participants.map(jid => ({
260
+ tag: 'participant',
261
+ attrs: { jid }
262
+ }))
263
+ }
264
+ ]);
265
+ const node = (0, WABinary_1.getBinaryNodeChild)(result, action);
266
+ const participantsAffected = (0, WABinary_1.getBinaryNodeChildren)(node, 'participant');
267
+ return participantsAffected.map(p => {
268
+ return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
269
+ });
270
+ },
271
+ communityUpdateDescription: async (jid, description) => {
272
+ var _a;
273
+ const metadata = await communityMetadata(jid);
274
+ const prev = (_a = metadata.descId) !== null && _a !== void 0 ? _a : null;
275
+ await communityQuery(jid, 'set', [
276
+ {
277
+ tag: 'description',
278
+ attrs: {
279
+ ...(description ? { id: (0, Utils_1.generateMessageID)() } : { delete: 'true' }),
280
+ ...(prev ? { prev } : {})
281
+ },
282
+ content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
283
+ }
284
+ ]);
285
+ },
286
+ communityInviteCode: async (jid) => {
287
+ const result = await communityQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
288
+ const inviteNode = (0, WABinary_1.getBinaryNodeChild)(result, 'invite');
289
+ return inviteNode === null || inviteNode === void 0 ? void 0 : inviteNode.attrs.code;
290
+ },
291
+ communityRevokeInvite: async (jid) => {
292
+ const result = await communityQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
293
+ const inviteNode = (0, WABinary_1.getBinaryNodeChild)(result, 'invite');
294
+ return inviteNode === null || inviteNode === void 0 ? void 0 : inviteNode.attrs.code;
295
+ },
296
+ communityAcceptInvite: async (code) => {
297
+ const results = await communityQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
298
+ const result = (0, WABinary_1.getBinaryNodeChild)(results, 'community');
299
+ return result === null || result === void 0 ? void 0 : result.attrs.jid;
300
+ },
301
+ communityRevokeInviteV4: async (communityJid, invitedJid) => {
302
+ const result = await communityQuery(communityJid, 'set', [
303
+ { tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
304
+ ]);
305
+ return !!result;
306
+ },
307
+ communityAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
308
+ var _a;
309
+ key = typeof key === 'string' ? { remoteJid: key } : key;
310
+ const results = await communityQuery(inviteMessage.groupJid, 'set', [
311
+ {
312
+ tag: 'accept',
313
+ attrs: {
314
+ code: inviteMessage.inviteCode,
315
+ expiration: inviteMessage.inviteExpiration.toString(),
316
+ admin: key.remoteJid
317
+ }
318
+ }
319
+ ]);
320
+ if (key.id) {
321
+ inviteMessage = WAProto_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage);
322
+ inviteMessage.inviteExpiration = 0;
323
+ inviteMessage.inviteCode = '';
324
+ ev.emit('messages.update', [
325
+ {
326
+ key,
327
+ update: {
328
+ message: {
329
+ groupInviteMessage: inviteMessage
330
+ }
331
+ }
332
+ }
333
+ ]);
334
+ }
335
+ await upsertMessage({
336
+ key: {
337
+ remoteJid: inviteMessage.groupJid,
338
+ id: (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id),
339
+ fromMe: false,
340
+ participant: key.remoteJid
341
+ },
342
+ messageStubType: Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD,
343
+ messageStubParameters: [authState.creds.me.id],
344
+ participant: key.remoteJid,
345
+ messageTimestamp: (0, Utils_1.unixTimestampSeconds)()
346
+ }, 'notify');
347
+ return results.attrs.from;
348
+ }),
349
+ communityGetInviteInfo: async (code) => {
350
+ const results = await communityQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
351
+ return (0, exports.extractCommunityMetadata)(results);
352
+ },
353
+ communityToggleEphemeral: async (jid, ephemeralExpiration) => {
354
+ const content = ephemeralExpiration
355
+ ? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
356
+ : { tag: 'not_ephemeral', attrs: {} };
357
+ await communityQuery(jid, 'set', [content]);
358
+ },
359
+ communitySettingUpdate: async (jid, setting) => {
360
+ await communityQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
361
+ },
362
+ communityMemberAddMode: async (jid, mode) => {
363
+ await communityQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
364
+ },
365
+ communityJoinApprovalMode: async (jid, mode) => {
366
+ await communityQuery(jid, 'set', [
367
+ { tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'community_join', attrs: { state: mode } }] }
368
+ ]);
369
+ },
370
+ communityFetchAllParticipating
371
+ };
372
+ };
373
+ exports.makeCommunitiesSocket = makeCommunitiesSocket;
374
+ const extractCommunityMetadata = (result) => {
375
+ var _a;
376
+ const community = (0, WABinary_1.getBinaryNodeChild)(result, 'community');
377
+ const descChild = (0, WABinary_1.getBinaryNodeChild)(community, 'description');
378
+ let desc;
379
+ let descId;
380
+ if (descChild) {
381
+ desc = (0, WABinary_1.getBinaryNodeChildString)(descChild, 'body');
382
+ descId = descChild.attrs.id;
383
+ }
384
+ const communityId = ((_a = community.attrs.id) === null || _a === void 0 ? void 0 : _a.includes('@'))
385
+ ? community.attrs.id
386
+ : (0, WABinary_1.jidEncode)(community.attrs.id || '', 'g.us');
387
+ const eph = (0, WABinary_1.getBinaryNodeChild)(community, 'ephemeral');
388
+ const memberAddMode = (0, WABinary_1.getBinaryNodeChildString)(community, 'member_add_mode') === 'all_member_add';
389
+ const metadata = {
390
+ id: communityId,
391
+ subject: community.attrs.subject || '',
392
+ subjectOwner: community.attrs.s_o,
393
+ subjectTime: Number(community.attrs.s_t || 0),
394
+ size: (0, WABinary_1.getBinaryNodeChildren)(community, 'participant').length,
395
+ creation: Number(community.attrs.creation || 0),
396
+ owner: community.attrs.creator ? (0, WABinary_1.jidNormalizedUser)(community.attrs.creator) : undefined,
397
+ desc,
398
+ descId,
399
+ linkedParent: (() => { const lp = (0, WABinary_1.getBinaryNodeChild)(community, 'linked_parent'); return lp ? lp.attrs.jid : undefined; })(),
400
+ restrict: !!(0, WABinary_1.getBinaryNodeChild)(community, 'locked'),
401
+ announce: !!(0, WABinary_1.getBinaryNodeChild)(community, 'announcement'),
402
+ isCommunity: !!(0, WABinary_1.getBinaryNodeChild)(community, 'parent'),
403
+ isCommunityAnnounce: !!(0, WABinary_1.getBinaryNodeChild)(community, 'default_sub_community'),
404
+ joinApprovalMode: !!(0, WABinary_1.getBinaryNodeChild)(community, 'membership_approval_mode'),
405
+ memberAddMode,
406
+ participants: (0, WABinary_1.getBinaryNodeChildren)(community, 'participant').map(({ attrs }) => {
407
+ const isLid = (0, WABinary_1.isLidUser)(attrs.jid);
408
+ return {
409
+ id: attrs.jid,
410
+ jid: attrs.phone_number || attrs.jid,
411
+ phoneNumber: attrs.phone_number || (!isLid ? attrs.jid : undefined),
412
+ lid: isLid ? attrs.jid : (attrs.lid || undefined),
413
+ admin: (attrs.type || null)
414
+ };
415
+ }),
416
+ ephemeralDuration: eph && eph.attrs.expiration ? +eph.attrs.expiration : undefined,
417
+ addressingMode: (0, WABinary_1.getBinaryNodeChildString)(community, 'addressing_mode')
418
+ };
419
+ return metadata;
420
+ };
421
+ exports.extractCommunityMetadata = extractCommunityMetadata;
@@ -0,0 +1,258 @@
1
+ // dugong.d.ts
2
+ import { proto
3
+ normalizeMentions(mentions: string | string[] | null | undefined): string[];
4
+ applyMentions(msg: any, mentions: string | string[] | null | undefined, contextInfo?: any): any;
5
+
6
+ } from '../../WAProto';
7
+
8
+ declare namespace kikyy {
9
+ interface MediaUploadOptions {
10
+ fileEncSha256?: Buffer;
11
+ mediaType?: string;
12
+ newsletter?: boolean;
13
+ }
14
+
15
+ type WAMediaUploadFunction = (
16
+ stream: Buffer | NodeJS.ReadableStream,
17
+ options?: MediaUploadOptions
18
+ ) => Promise<{ url: string; directPath: string }>;
19
+
20
+ interface WAMessageContentGenerationOptions {
21
+ upload?: WAMediaUploadFunction;
22
+ mediaCache?: any;
23
+ options?: any;
24
+ logger?: any;
25
+ }
26
+
27
+ interface StickerMessage {
28
+ url: string;
29
+ fileSha256: Buffer | string;
30
+ fileEncSha256: Buffer | string;
31
+ mediaKey: Buffer | string;
32
+ mimetype: string;
33
+ directPath: string;
34
+ fileLength: number | string;
35
+ mediaKeyTimestamp: number | string;
36
+ isAnimated?: boolean;
37
+ stickerSentTs?: number | string;
38
+ isAvatar?: boolean;
39
+ isAiSticker?: boolean;
40
+ isLottie?: boolean;
41
+ }
42
+
43
+ interface PaymentMessage {
44
+ amount: number;
45
+ currency?: string;
46
+ from?: string;
47
+ expiry?: number;
48
+ sticker?: { stickerMessage: StickerMessage };
49
+ note?: string;
50
+ background?: {
51
+ id?: string;
52
+ fileLength?: string;
53
+ width?: number;
54
+ height?: number;
55
+ mimetype?: string;
56
+ placeholderArgb?: number;
57
+ textArgb?: number;
58
+ subtextArgb?: number;
59
+ };
60
+ }
61
+
62
+ interface ProductMessage {
63
+ title: string;
64
+ description: string;
65
+ thumbnail: Buffer | { url: string };
66
+ productId: string;
67
+ retailerId: string;
68
+ url: string;
69
+ body?: string;
70
+ footer?: string;
71
+ buttons?: proto.Message.InteractiveMessage.INativeFlowButton[];
72
+ priceAmount1000?: number | null;
73
+ currencyCode?: string;
74
+ }
75
+
76
+ interface InteractiveMessage {
77
+ header?: string;
78
+ title: string;
79
+ footer?: string;
80
+ thumbnail?: string;
81
+ image?: string | Buffer | { url: string };
82
+ video?: string | Buffer | { url: string };
83
+ document?: string | Buffer | { url: string };
84
+ mimetype?: string;
85
+ fileName?: string;
86
+ jpegThumbnail?: string | Buffer | { url: string };
87
+ contextInfo?: {
88
+ mentionedJid?: string[];
89
+ forwardingScore?: number;
90
+ isForwarded?: boolean;
91
+ externalAdReply?: {
92
+ title?: string;
93
+ body?: string;
94
+ mediaType?: number;
95
+ thumbnailUrl?: string;
96
+ mediaUrl?: string;
97
+ sourceUrl?: string;
98
+ showAdAttribution?: boolean;
99
+ renderLargerThumbnail?: boolean;
100
+ [key: string]: any;
101
+ };
102
+ [key: string]: any;
103
+ };
104
+ externalAdReply?: {
105
+ title?: string;
106
+ body?: string;
107
+ mediaType?: number;
108
+ thumbnailUrl?: string;
109
+ mediaUrl?: string;
110
+ sourceUrl?: string;
111
+ showAdAttribution?: boolean;
112
+ renderLargerThumbnail?: boolean;
113
+ [key: string]: any;
114
+ };
115
+ buttons?: proto.Message.InteractiveMessage.INativeFlowButton[];
116
+ nativeFlowMessage?: {
117
+ messageParamsJson?: string;
118
+ buttons?: proto.Message.InteractiveMessage.INativeFlowButton[];
119
+ [key: string]: any;
120
+ };
121
+ }
122
+
123
+ interface AlbumItem {
124
+ image?: string | Buffer | { url: string; caption?: string };
125
+ video?: string | Buffer | { url: string; caption?: string };
126
+ }
127
+
128
+ interface EventMessageLocation {
129
+ degreesLatitude: number;
130
+ degreesLongitude: number;
131
+ name: string;
132
+ }
133
+
134
+ interface EventMessage {
135
+ isCanceled?: boolean;
136
+ name: string;
137
+ description: string;
138
+ location?: EventMessageLocation;
139
+ joinLink?: string;
140
+ startTime?: string | number;
141
+ endTime?: string | number;
142
+ extraGuestsAllowed?: boolean;
143
+ }
144
+
145
+ interface PollVote {
146
+ optionName: string;
147
+ optionVoteCount: string | number;
148
+ }
149
+
150
+ interface PollResultMessage {
151
+ name: string;
152
+ pollVotes: PollVote[];
153
+ }
154
+
155
+ interface GroupStatusMessage {
156
+ message?: any;
157
+ image?: string | Buffer | { url: string };
158
+ video?: string | Buffer | { url: string };
159
+ text?: string;
160
+ caption?: string;
161
+ document?: string | Buffer | { url: string };
162
+ [key: string]: any;
163
+ }
164
+
165
+ interface MessageContent {
166
+ requestPaymentMessage?: PaymentMessage;
167
+ productMessage?: ProductMessage;
168
+ interactiveMessage?: InteractiveMessage;
169
+ albumMessage?: AlbumItem[];
170
+ eventMessage?: EventMessage;
171
+ pollResultMessage?: PollResultMessage;
172
+ groupStatusMessage?: GroupStatusMessage;
173
+ sender?: string;
174
+ }
175
+
176
+ interface MessageOptions {
177
+ quoted?: proto.IWebMessageInfo;
178
+ filter?: boolean;
179
+ }
180
+
181
+ interface Utils {
182
+ prepareWAMessageMedia: (media: any, options: WAMessageContentGenerationOptions) => Promise<any>;
183
+ generateWAMessageContent: (content: any, options: WAMessageContentGenerationOptions) => Promise<any>;
184
+ generateWAMessageFromContent: (jid: string, content: any, options?: any) => Promise<any>;
185
+ generateWAMessage: (jid: string, content: any, options?: any) => Promise<any>;
186
+ generateMessageID: () => string;
187
+ prepareMessageContent?: (content: any, options?: any) => Promise<any>;
188
+ }
189
+
190
+ interface BailUtils {
191
+ generateWAMessageContent?: (content: any, options: WAMessageContentGenerationOptions) => Promise<any>;
192
+ generateMessageID: () => string;
193
+ getContentType: (msg: any) => string;
194
+ }
195
+ }
196
+
197
+ declare class kikyy {
198
+ constructor(
199
+ utils: kikyy.Utils,
200
+ waUploadToServer: kikyy.WAMediaUploadFunction,
201
+ relayMessageFn?: (jid: string, content: any, options?: any) => Promise<any>
202
+ );
203
+
204
+ detectType(content: kikyy.MessageContent): 'PAYMENT' | 'PRODUCT' | 'INTERACTIVE' | 'ALBUM' | 'EVENT' | 'POLL_RESULT' | 'GROUP_STORY' | null;
205
+
206
+ handlePayment(
207
+ content: { requestPaymentMessage: kikyy.PaymentMessage },
208
+ quoted?: proto.IWebMessageInfo
209
+ ): Promise<{ requestPaymentMessage: proto.Message.RequestPaymentMessage }>;
210
+
211
+ handleProduct(
212
+ content: { productMessage: kikyy.ProductMessage },
213
+ jid: string,
214
+ quoted?: proto.IWebMessageInfo
215
+ ): Promise<{ viewOnceMessage: proto.Message.ViewOnceMessage }>;
216
+
217
+ handleInteractive(
218
+ content: { interactiveMessage: kikyy.InteractiveMessage },
219
+ jid: string,
220
+ quoted?: proto.IWebMessageInfo
221
+ ): Promise<{ interactiveMessage: proto.Message.InteractiveMessage }>;
222
+
223
+ handleAlbum(
224
+ content: { albumMessage: kikyy.AlbumItem[] },
225
+ jid: string,
226
+ quoted?: proto.IWebMessageInfo
227
+ ): Promise<any>;
228
+
229
+ handleEvent(
230
+ content: { eventMessage: kikyy.EventMessage },
231
+ jid: string,
232
+ quoted?: proto.IWebMessageInfo
233
+ ): Promise<any>;
234
+
235
+ handlePollResult(
236
+ content: { pollResultMessage: kikyy.PollResultMessage },
237
+ jid: string,
238
+ quoted?: proto.IWebMessageInfo
239
+ ): Promise<any>;
240
+
241
+ handleGroupStory(
242
+ content: { groupStatusMessage: kikyy.GroupStatusMessage },
243
+ jid: string,
244
+ quoted?: proto.IWebMessageInfo
245
+ ): Promise<any>;
246
+
247
+ buildMessageContent(
248
+ content: any,
249
+ opts?: kikyy.WAMessageContentGenerationOptions
250
+ ): Promise<any>;
251
+
252
+ utils: kikyy.Utils;
253
+ relayMessage: (jid: string, content: any, options?: any) => Promise<any>;
254
+ waUploadToServer: kikyy.WAMediaUploadFunction;
255
+ bail: kikyy.BailUtils;
256
+ }
257
+
258
+ export = kikyy;