@queenanya/baileys 8.5.0-beta → 8.5.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/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- # 8.5.0-beta (2025-07-25)
1
+ ## 8.5.1 (2025-08-19)
2
2
 
3
3
 
4
4
 
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": [2, 3000, 1025005758]
2
+ "version": [2, 3000, 1026056356]
3
3
  }
@@ -38,11 +38,13 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
38
38
  }>;
39
39
  getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<import("../WABinary").JidWithDevice[]>;
40
40
  createParticipantNodes: (jids: string[], message: import("../Types").WAProto.IMessage, extraAttrs?: BinaryNode["attrs"]) => Promise<{
41
- nodes: BinaryNode[];
41
+ nodes: any[];
42
42
  shouldIncludeDeviceIdentity: boolean;
43
43
  }>;
44
44
  sendPeerDataOperationMessage: (pdoMessage: import("../Types").WAProto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
45
45
  updateMediaMessage: (message: import("../Types").WAProto.IWebMessageInfo) => Promise<import("../Types").WAProto.IWebMessageInfo>;
46
+ sendStatusMentions: (jid: any, content: any) => Promise<import("../Types").WAProto.WebMessageInfo>;
47
+ sendStatusMentionsV2: (jid: any, content: any) => Promise<import("../Types").WAProto.WebMessageInfo>;
46
48
  sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<import("../Types").WAProto.WebMessageInfo>;
47
49
  subscribeNewsletterUpdates: (jid: string) => Promise<{
48
50
  duration: string;
@@ -118,6 +120,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
118
120
  updateProfileStatus: (status: string) => Promise<void>;
119
121
  updateProfileName: (name: string) => Promise<void>;
120
122
  updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
123
+ updateDisableLinkPreviewsPrivacy: (isPreviewsDisabled: boolean) => Promise<void>;
121
124
  updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
122
125
  updateMessagesPrivacy: (value: import("../Types").WAPrivacyMessagesValue) => Promise<void>;
123
126
  updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
@@ -29,6 +29,7 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
29
29
  updateProfileStatus: (status: string) => Promise<void>;
30
30
  updateProfileName: (name: string) => Promise<void>;
31
31
  updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
32
+ updateDisableLinkPreviewsPrivacy: (isPreviewsDisabled: boolean) => Promise<void>;
32
33
  updateCallPrivacy: (value: WAPrivacyCallValue) => Promise<void>;
33
34
  updateMessagesPrivacy: (value: WAPrivacyMessagesValue) => Promise<void>;
34
35
  updateLastSeenPrivacy: (value: WAPrivacyValue) => Promise<void>;
@@ -26,10 +26,10 @@ const makeChatsSocket = (config) => {
26
26
  let pendingAppStateSync = false;
27
27
  /** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
28
28
  const processingMutex = (0, make_mutex_1.makeMutex)();
29
- const placeholderResendCache = config.placeholderResendCache || new node_cache_1.default({
29
+ const placeholderResendCache = (config.placeholderResendCache || new node_cache_1.default({
30
30
  stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
31
31
  useClones: false
32
- });
32
+ }));
33
33
  if (!config.placeholderResendCache) {
34
34
  config.placeholderResendCache = placeholderResendCache;
35
35
  }
@@ -717,6 +717,14 @@ const makeChatsSocket = (config) => {
717
717
  const patch = (0, Utils_1.chatModificationToAppPatch)(mod, jid);
718
718
  return appPatch(patch);
719
719
  };
720
+ /**
721
+ * Enable/Disable link preview privacy, not related to baileys link preview generation
722
+ */
723
+ const updateDisableLinkPreviewsPrivacy = (isPreviewsDisabled) => {
724
+ return chatModify({
725
+ disableLinkPreviews: { isPreviewsDisabled }
726
+ }, '');
727
+ };
720
728
  /**
721
729
  * Star or Unstar a message
722
730
  */
@@ -918,6 +926,7 @@ const makeChatsSocket = (config) => {
918
926
  updateProfileStatus,
919
927
  updateProfileName,
920
928
  updateBlockStatus,
929
+ updateDisableLinkPreviewsPrivacy,
921
930
  updateCallPrivacy,
922
931
  updateMessagesPrivacy,
923
932
  updateLastSeenPrivacy,
@@ -0,0 +1,220 @@
1
+ import { proto } from '../../WAProto/index.js';
2
+ import { GroupMetadata, ParticipantAction, SocketConfig, WAMessageKey } from '../Types';
3
+ import { BinaryNode } from '../WABinary';
4
+ export declare const makeCommunitiesSocket: (config: SocketConfig) => {
5
+ communityMetadata: (jid: string) => Promise<GroupMetadata>;
6
+ communityCreate: (subject: string, body: string) => Promise<GroupMetadata | null>;
7
+ communityLeave: (id: string) => Promise<void>;
8
+ communityUpdateSubject: (jid: string, subject: string) => Promise<void>;
9
+ communityRequestParticipantsList: (jid: string) => Promise<{
10
+ [key: string]: string;
11
+ }[]>;
12
+ communityRequestParticipantsUpdate: (jid: string, participants: string[], action: "approve" | "reject") => Promise<{
13
+ status: string;
14
+ jid: string;
15
+ }[]>;
16
+ communityParticipantsUpdate: (jid: string, participants: string[], action: ParticipantAction) => Promise<{
17
+ status: string;
18
+ jid: string;
19
+ content: BinaryNode;
20
+ }[]>;
21
+ communityUpdateDescription: (jid: string, description?: string) => Promise<void>;
22
+ communityInviteCode: (jid: string) => Promise<string | undefined>;
23
+ communityRevokeInvite: (jid: string) => Promise<string | undefined>;
24
+ communityAcceptInvite: (code: string) => Promise<string | undefined>;
25
+ /**
26
+ * revoke a v4 invite for someone
27
+ * @param communityJid community jid
28
+ * @param invitedJid jid of person you invited
29
+ * @returns true if successful
30
+ */
31
+ communityRevokeInviteV4: (communityJid: string, invitedJid: string) => Promise<boolean>;
32
+ /**
33
+ * accept a CommunityInviteMessage
34
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
35
+ * @param inviteMessage the message to accept
36
+ */
37
+ communityAcceptInviteV4: (key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<any>;
38
+ communityGetInviteInfo: (code: string) => Promise<GroupMetadata>;
39
+ communityToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
40
+ communitySettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
41
+ communityMemberAddMode: (jid: string, mode: "admin_add" | "all_member_add") => Promise<void>;
42
+ communityJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
43
+ communityFetchAllParticipating: () => Promise<{
44
+ [_: string]: GroupMetadata;
45
+ }>;
46
+ logger: import("../Utils/logger").ILogger;
47
+ getOrderDetails: (orderId: string, tokenBase64: string) => Promise<import("../Types").OrderDetails>;
48
+ getCatalog: ({ jid, limit, cursor }: import("../Types").GetCatalogOptions) => Promise<{
49
+ products: import("../Types").Product[];
50
+ nextPageCursor: string | undefined;
51
+ }>;
52
+ getCollections: (jid?: string, limit?: number) => Promise<{
53
+ collections: import("../Types").CatalogCollection[];
54
+ }>;
55
+ productCreate: (create: import("../Types").ProductCreate) => Promise<import("../Types").Product>;
56
+ productDelete: (productIds: string[]) => Promise<{
57
+ deleted: number;
58
+ }>;
59
+ productUpdate: (productId: string, update: import("../Types").ProductUpdate) => Promise<import("../Types").Product>;
60
+ sendMessageAck: ({ tag, attrs, content }: BinaryNode, errorCode?: number) => Promise<void>;
61
+ sendRetryRequest: (node: BinaryNode, forceIncludeKeys?: boolean) => Promise<void>;
62
+ rejectCall: (callId: string, callFrom: string) => Promise<void>;
63
+ offerCall: (toJid: string, isVideo?: boolean) => Promise<{
64
+ callId: string;
65
+ toJid: string;
66
+ isVideo: boolean;
67
+ }>;
68
+ fetchMessageHistory: (count: number, oldestMsgKey: WAMessageKey, oldestMsgTimestamp: number | import("long")) => Promise<string>;
69
+ requestPlaceholderResend: (messageKey: WAMessageKey) => Promise<string | undefined>;
70
+ getPrivacyTokens: (jids: string[]) => Promise<any>;
71
+ assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
72
+ relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
73
+ sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
74
+ sendReceipts: (keys: WAMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>;
75
+ readMessages: (keys: WAMessageKey[]) => Promise<void>;
76
+ refreshMediaConn: (forceGet?: boolean) => Promise<import("../Types").MediaConnInfo>;
77
+ waUploadToServer: import("../Types").WAMediaUploadFunction;
78
+ fetchPrivacySettings: (force?: boolean) => Promise<{
79
+ [_: string]: string;
80
+ }>;
81
+ getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<import("../WABinary").JidWithDevice[]>;
82
+ createParticipantNodes: (jids: string[], message: proto.IMessage, extraAttrs?: BinaryNode["attrs"]) => Promise<{
83
+ nodes: any[];
84
+ shouldIncludeDeviceIdentity: boolean;
85
+ }>;
86
+ sendPeerDataOperationMessage: (pdoMessage: proto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
87
+ updateMediaMessage: (message: proto.IWebMessageInfo) => Promise<proto.IWebMessageInfo>;
88
+ sendStatusMentions: (jid: any, content: any) => Promise<proto.WebMessageInfo>;
89
+ sendStatusMentionsV2: (jid: any, content: any) => Promise<proto.WebMessageInfo>;
90
+ sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo>;
91
+ subscribeNewsletterUpdates: (jid: string) => Promise<{
92
+ duration: string;
93
+ }>;
94
+ newsletterReactionMode: (jid: string, mode: import("../Types").NewsletterReactionMode) => Promise<void>;
95
+ newsletterUpdateDescription: (jid: string, description?: string) => Promise<void>;
96
+ newsletterUpdateName: (jid: string, name: string) => Promise<void>;
97
+ newsletterUpdatePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
98
+ newsletterRemovePicture: (jid: string) => Promise<void>;
99
+ newsletterUnfollow: (jid: string) => Promise<void>;
100
+ newsletterFollow: (jid: string) => Promise<void>;
101
+ newsletterUnmute: (jid: string) => Promise<void>;
102
+ newsletterMute: (jid: string) => Promise<void>;
103
+ newsletterCreate: (name: string, description?: string, picture?: import("../Types").WAMediaUpload) => Promise<import("../Types").NewsletterMetadata>;
104
+ newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole) => Promise<import("../Types").NewsletterMetadata>;
105
+ newsletterAdminCount: (jid: string) => Promise<number>;
106
+ newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
107
+ newsletterDemote: (jid: string, user: string) => Promise<void>;
108
+ newsletterDelete: (jid: string) => Promise<void>;
109
+ newsletterReactMessage: (jid: string, server_id: string, code?: string) => Promise<void>;
110
+ newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
111
+ newsletterFetchUpdates: (jid: string, count: number, after?: number, since?: number) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
112
+ groupQuery: (jid: string, type: "get" | "set", content: BinaryNode[]) => Promise<any>;
113
+ groupMetadata: (jid: string) => Promise<GroupMetadata>;
114
+ groupCreate: (subject: string, participants: string[]) => Promise<GroupMetadata>;
115
+ groupLeave: (id: string) => Promise<void>;
116
+ groupUpdateSubject: (jid: string, subject: string) => Promise<void>;
117
+ groupRequestParticipantsList: (jid: string) => Promise<{
118
+ [key: string]: string;
119
+ }[]>;
120
+ groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "approve" | "reject") => Promise<{
121
+ status: string;
122
+ jid: string;
123
+ }[]>;
124
+ groupParticipantsUpdate: (jid: string, participants: string[], action: ParticipantAction) => Promise<{
125
+ status: string;
126
+ jid: string;
127
+ content: BinaryNode;
128
+ }[]>;
129
+ groupUpdateDescription: (jid: string, description?: string) => Promise<void>;
130
+ groupInviteCode: (jid: string) => Promise<string | undefined>;
131
+ groupRevokeInvite: (jid: string) => Promise<string | undefined>;
132
+ groupAcceptInvite: (code: string) => Promise<string | undefined>;
133
+ groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
134
+ groupAcceptInviteV4: (key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<any>;
135
+ groupGetInviteInfo: (code: string) => Promise<GroupMetadata>;
136
+ groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
137
+ groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
138
+ groupMemberAddMode: (jid: string, mode: "admin_add" | "all_member_add") => Promise<void>;
139
+ groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
140
+ groupFetchAllParticipating: () => Promise<{
141
+ [_: string]: GroupMetadata;
142
+ }>;
143
+ getBotListV2: () => Promise<import("../Types").BotListInfo[]>;
144
+ processingMutex: {
145
+ mutex<T>(code: () => Promise<T> | T): Promise<T>;
146
+ };
147
+ upsertMessage: (msg: import("../Types").WAMessage, type: import("../Types").MessageUpsertType) => Promise<void>;
148
+ appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
149
+ sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string) => Promise<void>;
150
+ presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
151
+ profilePictureUrl: (jid: string, type?: "preview" | "image", timeoutMs?: number) => Promise<string | undefined>;
152
+ onWhatsApp: (...jids: string[]) => Promise<{
153
+ jid: string;
154
+ exists: unknown;
155
+ lid: unknown;
156
+ }[] | undefined>;
157
+ fetchBlocklist: () => Promise<string[]>;
158
+ fetchDisappearingDuration: (...jids: string[]) => Promise<import("../index.js").USyncQueryResultList[] | undefined>;
159
+ fetchStatus: (...jids: string[]) => Promise<import("../index.js").USyncQueryResultList[] | undefined>;
160
+ updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
161
+ removeProfilePicture: (jid: string) => Promise<void>;
162
+ updateProfileStatus: (status: string) => Promise<void>;
163
+ updateProfileName: (name: string) => Promise<void>;
164
+ updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
165
+ updateDisableLinkPreviewsPrivacy: (isPreviewsDisabled: boolean) => Promise<void>;
166
+ updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
167
+ updateMessagesPrivacy: (value: import("../Types").WAPrivacyMessagesValue) => Promise<void>;
168
+ updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
169
+ updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
170
+ updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
171
+ updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
172
+ updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
173
+ updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
174
+ updateDefaultDisappearingMode: (duration: number) => Promise<void>;
175
+ getBusinessProfile: (jid: string) => Promise<import("../Types").WABusinessProfile | void>;
176
+ resyncAppState: (collections: readonly ("critical_unblock_low" | "regular_high" | "regular_low" | "critical_block" | "regular")[], isInitialSync: boolean) => Promise<void>;
177
+ chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
178
+ cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
179
+ addOrEditContact: (jid: string, contact: proto.SyncActionValue.IContactAction) => Promise<void>;
180
+ removeContact: (jid: string) => Promise<void>;
181
+ addChatLabel: (jid: string, labelId: string) => Promise<void>;
182
+ removeChatLabel: (jid: string, labelId: string) => Promise<void>;
183
+ addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
184
+ removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
185
+ star: (jid: string, messages: {
186
+ id: string;
187
+ fromMe?: boolean;
188
+ }[], star: boolean) => Promise<void>;
189
+ executeUSyncQuery: (usyncQuery: import("../index.js").USyncQuery) => Promise<import("../index.js").USyncQueryResult | undefined>;
190
+ type: "md";
191
+ ws: import("./Client/websocket.js").WebSocketClient;
192
+ ev: import("../Types").BaileysEventEmitter & {
193
+ process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
194
+ buffer(): void;
195
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
196
+ flush(force?: boolean): boolean;
197
+ isBuffering(): boolean;
198
+ };
199
+ authState: {
200
+ creds: import("../Types").AuthenticationCreds;
201
+ keys: import("../Types").SignalKeyStoreWithTransaction;
202
+ };
203
+ signalRepository: import("../Types").SignalRepository;
204
+ user: import("../Types").Contact | undefined;
205
+ generateMessageTag: () => string;
206
+ query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
207
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
208
+ waitForSocketOpen: () => Promise<void>;
209
+ sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
210
+ sendNode: (frame: BinaryNode) => Promise<void>;
211
+ logout: (msg?: string) => Promise<void>;
212
+ end: (error: Error | undefined) => void;
213
+ onUnexpectedError: (err: Error | import("@hapi/boom").Boom, msg: string) => void;
214
+ uploadPreKeys: (count?: number) => Promise<void>;
215
+ uploadPreKeysToServerIfRequired: () => Promise<void>;
216
+ requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
217
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
218
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
219
+ };
220
+ export declare const extractCommunityMetadata: (result: BinaryNode) => GroupMetadata;
@@ -0,0 +1,363 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.extractCommunityMetadata = exports.makeCommunitiesSocket = void 0;
7
+ const index_js_1 = require("../../WAProto/index.js");
8
+ const Types_1 = require("../Types");
9
+ const Utils_1 = require("../Utils");
10
+ const logger_1 = __importDefault(require("../Utils/logger"));
11
+ const WABinary_1 = require("../WABinary");
12
+ const business_1 = require("./business");
13
+ const makeCommunitiesSocket = (config) => {
14
+ const sock = (0, business_1.makeBusinessSocket)(config);
15
+ const { authState, ev, query, upsertMessage } = sock;
16
+ const communityQuery = async (jid, type, content) => query({
17
+ tag: 'iq',
18
+ attrs: {
19
+ type,
20
+ xmlns: 'w:g2',
21
+ to: jid
22
+ },
23
+ content
24
+ });
25
+ const communityMetadata = async (jid) => {
26
+ const result = await communityQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
27
+ return (0, exports.extractCommunityMetadata)(result);
28
+ };
29
+ const communityFetchAllParticipating = async () => {
30
+ const result = await query({
31
+ tag: 'iq',
32
+ attrs: {
33
+ to: '@g.us',
34
+ xmlns: 'w:g2',
35
+ type: 'get'
36
+ },
37
+ content: [
38
+ {
39
+ tag: 'participating',
40
+ attrs: {},
41
+ content: [
42
+ { tag: 'participants', attrs: {} },
43
+ { tag: 'description', attrs: {} }
44
+ ]
45
+ }
46
+ ]
47
+ });
48
+ const data = {};
49
+ const communitiesChild = (0, WABinary_1.getBinaryNodeChild)(result, 'communities');
50
+ if (communitiesChild) {
51
+ const communities = (0, WABinary_1.getBinaryNodeChildren)(communitiesChild, 'community');
52
+ for (const communityNode of communities) {
53
+ const meta = (0, exports.extractCommunityMetadata)({
54
+ tag: 'result',
55
+ attrs: {},
56
+ content: [communityNode]
57
+ });
58
+ data[meta.id] = meta;
59
+ }
60
+ }
61
+ sock.ev.emit('groups.update', Object.values(data));
62
+ return data;
63
+ };
64
+ async function parseGroupResult(node) {
65
+ logger_1.default.info({ node }, 'parseGroupResult');
66
+ const groupNode = (0, WABinary_1.getBinaryNodeChild)(node, 'group');
67
+ if (groupNode) {
68
+ try {
69
+ logger_1.default.info({ groupNode }, 'groupNode');
70
+ const metadata = await sock.groupMetadata(`${groupNode.attrs.id}@g.us`);
71
+ return metadata ? metadata : Optional.empty();
72
+ }
73
+ catch (error) {
74
+ console.error('Error parsing group metadata:', error);
75
+ return Optional.empty();
76
+ }
77
+ }
78
+ return Optional.empty();
79
+ }
80
+ const Optional = {
81
+ empty: () => null,
82
+ of: (value) => (value !== null ? { value } : null)
83
+ };
84
+ sock.ws.on('CB:ib,,dirty', async (node) => {
85
+ const { attrs } = (0, WABinary_1.getBinaryNodeChild)(node, 'dirty');
86
+ if (attrs.type !== 'communities') {
87
+ return;
88
+ }
89
+ await communityFetchAllParticipating();
90
+ await sock.cleanDirtyBits('groups');
91
+ });
92
+ return {
93
+ ...sock,
94
+ communityMetadata,
95
+ communityCreate: async (subject, body) => {
96
+ const descriptionId = (0, Utils_1.generateMessageID)().substring(0, 12);
97
+ const result = await communityQuery('@g.us', 'set', [
98
+ {
99
+ tag: 'create',
100
+ attrs: { subject },
101
+ content: [
102
+ {
103
+ tag: 'description',
104
+ attrs: { id: descriptionId },
105
+ content: [
106
+ {
107
+ tag: 'body',
108
+ attrs: {},
109
+ content: Buffer.from(body || '', 'utf-8')
110
+ }
111
+ ]
112
+ },
113
+ {
114
+ tag: 'parent',
115
+ attrs: { default_membership_approval_mode: 'request_required' }
116
+ },
117
+ {
118
+ tag: 'allow_non_admin_sub_group_creation',
119
+ attrs: {}
120
+ },
121
+ {
122
+ tag: 'create_general_chat',
123
+ attrs: {}
124
+ }
125
+ ]
126
+ }
127
+ ]);
128
+ return await parseGroupResult(result);
129
+ },
130
+ communityLeave: async (id) => {
131
+ await communityQuery('@g.us', 'set', [
132
+ {
133
+ tag: 'leave',
134
+ attrs: {},
135
+ content: [{ tag: 'community', attrs: { id } }]
136
+ }
137
+ ]);
138
+ },
139
+ communityUpdateSubject: async (jid, subject) => {
140
+ await communityQuery(jid, 'set', [
141
+ {
142
+ tag: 'subject',
143
+ attrs: {},
144
+ content: Buffer.from(subject, 'utf-8')
145
+ }
146
+ ]);
147
+ },
148
+ communityRequestParticipantsList: async (jid) => {
149
+ const result = await communityQuery(jid, 'get', [
150
+ {
151
+ tag: 'membership_approval_requests',
152
+ attrs: {}
153
+ }
154
+ ]);
155
+ const node = (0, WABinary_1.getBinaryNodeChild)(result, 'membership_approval_requests');
156
+ const participants = (0, WABinary_1.getBinaryNodeChildren)(node, 'membership_approval_request');
157
+ return participants.map(v => v.attrs);
158
+ },
159
+ communityRequestParticipantsUpdate: async (jid, participants, action) => {
160
+ const result = await communityQuery(jid, 'set', [
161
+ {
162
+ tag: 'membership_requests_action',
163
+ attrs: {},
164
+ content: [
165
+ {
166
+ tag: action,
167
+ attrs: {},
168
+ content: participants.map(jid => ({
169
+ tag: 'participant',
170
+ attrs: { jid }
171
+ }))
172
+ }
173
+ ]
174
+ }
175
+ ]);
176
+ const node = (0, WABinary_1.getBinaryNodeChild)(result, 'membership_requests_action');
177
+ const nodeAction = (0, WABinary_1.getBinaryNodeChild)(node, action);
178
+ const participantsAffected = (0, WABinary_1.getBinaryNodeChildren)(nodeAction, 'participant');
179
+ return participantsAffected.map(p => {
180
+ return { status: p.attrs.error || '200', jid: p.attrs.jid };
181
+ });
182
+ },
183
+ communityParticipantsUpdate: async (jid, participants, action) => {
184
+ const result = await communityQuery(jid, 'set', [
185
+ {
186
+ tag: action,
187
+ attrs: {},
188
+ content: participants.map(jid => ({
189
+ tag: 'participant',
190
+ attrs: { jid }
191
+ }))
192
+ }
193
+ ]);
194
+ const node = (0, WABinary_1.getBinaryNodeChild)(result, action);
195
+ const participantsAffected = (0, WABinary_1.getBinaryNodeChildren)(node, 'participant');
196
+ return participantsAffected.map(p => {
197
+ return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
198
+ });
199
+ },
200
+ communityUpdateDescription: async (jid, description) => {
201
+ var _a;
202
+ const metadata = await communityMetadata(jid);
203
+ const prev = (_a = metadata.descId) !== null && _a !== void 0 ? _a : null;
204
+ await communityQuery(jid, 'set', [
205
+ {
206
+ tag: 'description',
207
+ attrs: {
208
+ ...(description ? { id: (0, Utils_1.generateMessageID)() } : { delete: 'true' }),
209
+ ...(prev ? { prev } : {})
210
+ },
211
+ content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
212
+ }
213
+ ]);
214
+ },
215
+ communityInviteCode: async (jid) => {
216
+ const result = await communityQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
217
+ const inviteNode = (0, WABinary_1.getBinaryNodeChild)(result, 'invite');
218
+ return inviteNode === null || inviteNode === void 0 ? void 0 : inviteNode.attrs.code;
219
+ },
220
+ communityRevokeInvite: async (jid) => {
221
+ const result = await communityQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
222
+ const inviteNode = (0, WABinary_1.getBinaryNodeChild)(result, 'invite');
223
+ return inviteNode === null || inviteNode === void 0 ? void 0 : inviteNode.attrs.code;
224
+ },
225
+ communityAcceptInvite: async (code) => {
226
+ const results = await communityQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
227
+ const result = (0, WABinary_1.getBinaryNodeChild)(results, 'community');
228
+ return result === null || result === void 0 ? void 0 : result.attrs.jid;
229
+ },
230
+ /**
231
+ * revoke a v4 invite for someone
232
+ * @param communityJid community jid
233
+ * @param invitedJid jid of person you invited
234
+ * @returns true if successful
235
+ */
236
+ communityRevokeInviteV4: async (communityJid, invitedJid) => {
237
+ const result = await communityQuery(communityJid, 'set', [
238
+ { tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
239
+ ]);
240
+ return !!result;
241
+ },
242
+ /**
243
+ * accept a CommunityInviteMessage
244
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
245
+ * @param inviteMessage the message to accept
246
+ */
247
+ communityAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
248
+ var _a;
249
+ key = typeof key === 'string' ? { remoteJid: key } : key;
250
+ const results = await communityQuery(inviteMessage.groupJid, 'set', [
251
+ {
252
+ tag: 'accept',
253
+ attrs: {
254
+ code: inviteMessage.inviteCode,
255
+ expiration: inviteMessage.inviteExpiration.toString(),
256
+ admin: key.remoteJid
257
+ }
258
+ }
259
+ ]);
260
+ // if we have the full message key
261
+ // update the invite message to be expired
262
+ if (key.id) {
263
+ // create new invite message that is expired
264
+ inviteMessage = index_js_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage);
265
+ inviteMessage.inviteExpiration = 0;
266
+ inviteMessage.inviteCode = '';
267
+ ev.emit('messages.update', [
268
+ {
269
+ key,
270
+ update: {
271
+ message: {
272
+ groupInviteMessage: inviteMessage
273
+ }
274
+ }
275
+ }
276
+ ]);
277
+ }
278
+ // generate the community add message
279
+ await upsertMessage({
280
+ key: {
281
+ remoteJid: inviteMessage.groupJid,
282
+ id: (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id),
283
+ fromMe: false,
284
+ participant: key.remoteJid
285
+ },
286
+ messageStubType: Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD,
287
+ messageStubParameters: [authState.creds.me.id],
288
+ participant: key.remoteJid,
289
+ messageTimestamp: (0, Utils_1.unixTimestampSeconds)()
290
+ }, 'notify');
291
+ return results.attrs.from;
292
+ }),
293
+ communityGetInviteInfo: async (code) => {
294
+ const results = await communityQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
295
+ return (0, exports.extractCommunityMetadata)(results);
296
+ },
297
+ communityToggleEphemeral: async (jid, ephemeralExpiration) => {
298
+ const content = ephemeralExpiration
299
+ ? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
300
+ : { tag: 'not_ephemeral', attrs: {} };
301
+ await communityQuery(jid, 'set', [content]);
302
+ },
303
+ communitySettingUpdate: async (jid, setting) => {
304
+ await communityQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
305
+ },
306
+ communityMemberAddMode: async (jid, mode) => {
307
+ await communityQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
308
+ },
309
+ communityJoinApprovalMode: async (jid, mode) => {
310
+ await communityQuery(jid, 'set', [
311
+ { tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'community_join', attrs: { state: mode } }] }
312
+ ]);
313
+ },
314
+ communityFetchAllParticipating
315
+ };
316
+ };
317
+ exports.makeCommunitiesSocket = makeCommunitiesSocket;
318
+ const extractCommunityMetadata = (result) => {
319
+ var _a, _b, _c;
320
+ const community = (0, WABinary_1.getBinaryNodeChild)(result, 'community');
321
+ const descChild = (0, WABinary_1.getBinaryNodeChild)(community, 'description');
322
+ let desc;
323
+ let descId;
324
+ if (descChild) {
325
+ desc = (0, WABinary_1.getBinaryNodeChildString)(descChild, 'body');
326
+ descId = descChild.attrs.id;
327
+ }
328
+ const communityId = ((_a = community.attrs.id) === null || _a === void 0 ? void 0 : _a.includes('@'))
329
+ ? community.attrs.id
330
+ : (0, WABinary_1.jidEncode)(community.attrs.id || '', 'g.us');
331
+ const eph = (_b = (0, WABinary_1.getBinaryNodeChild)(community, 'ephemeral')) === null || _b === void 0 ? void 0 : _b.attrs.expiration;
332
+ const memberAddMode = (0, WABinary_1.getBinaryNodeChildString)(community, 'member_add_mode') === 'all_member_add';
333
+ const metadata = {
334
+ id: communityId,
335
+ subject: community.attrs.subject || '',
336
+ subjectOwner: community.attrs.s_o,
337
+ subjectTime: Number(community.attrs.s_t || 0),
338
+ size: (0, WABinary_1.getBinaryNodeChildren)(community, 'participant').length,
339
+ creation: Number(community.attrs.creation || 0),
340
+ owner: community.attrs.creator ? (0, WABinary_1.jidNormalizedUser)(community.attrs.creator) : undefined,
341
+ ownerJid: community.attrs.creator_pn ? (0, WABinary_1.jidNormalizedUser)(community.attrs.creator_pn) : undefined,
342
+ owner_country_code: community.attrs.creator_country_code,
343
+ desc,
344
+ descId,
345
+ linkedParent: ((_c = (0, WABinary_1.getBinaryNodeChild)(community, 'linked_parent')) === null || _c === void 0 ? void 0 : _c.attrs.jid) || undefined,
346
+ restrict: !!(0, WABinary_1.getBinaryNodeChild)(community, 'locked'),
347
+ announce: !!(0, WABinary_1.getBinaryNodeChild)(community, 'announcement'),
348
+ isCommunity: !!(0, WABinary_1.getBinaryNodeChild)(community, 'parent'),
349
+ isCommunityAnnounce: !!(0, WABinary_1.getBinaryNodeChild)(community, 'default_sub_community'),
350
+ joinApprovalMode: !!(0, WABinary_1.getBinaryNodeChild)(community, 'membership_approval_mode'),
351
+ memberAddMode,
352
+ participants: (0, WABinary_1.getBinaryNodeChildren)(community, 'participant').map(({ attrs }) => {
353
+ return {
354
+ id: attrs.jid,
355
+ admin: (attrs.type || null)
356
+ };
357
+ }),
358
+ ephemeralDuration: eph ? +eph : undefined,
359
+ addressingMode: (0, WABinary_1.getBinaryNodeChildString)(community, 'addressing_mode')
360
+ };
361
+ return metadata;
362
+ };
363
+ exports.extractCommunityMetadata = extractCommunityMetadata;