@hbmodsofc/baileys 1.5.0 → 1.7.6

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 (156) hide show
  1. package/LICENSE +1 -1
  2. package/WAProto/index.js +19671 -152026
  3. package/engine-requirements.js +4 -4
  4. package/lib/Defaults/index.d.ts +12 -8
  5. package/lib/Defaults/index.js +90 -124
  6. package/lib/Signal/Group/group_cipher.d.ts +0 -1
  7. package/lib/Signal/Group/group_cipher.js +28 -39
  8. package/lib/Signal/Group/sender-chain-key.d.ts +1 -1
  9. package/lib/Signal/Group/sender-chain-key.js +9 -2
  10. package/lib/Signal/Group/sender-key-distribution-message.js +3 -3
  11. package/lib/Signal/Group/sender-key-message.js +3 -3
  12. package/lib/Signal/Group/sender-key-state.d.ts +4 -4
  13. package/lib/Signal/Group/sender-key-state.js +47 -16
  14. package/lib/Signal/libsignal.d.ts +7 -3
  15. package/lib/Signal/libsignal.js +224 -39
  16. package/lib/Signal/lid-mapping.d.ts +26 -0
  17. package/lib/Signal/lid-mapping.js +146 -0
  18. package/lib/Socket/Client/index.d.ts +2 -3
  19. package/lib/Socket/Client/index.js +2 -3
  20. package/lib/Socket/Client/{abstract-socket-client.d.ts → types.d.ts} +1 -3
  21. package/lib/Socket/Client/{web-socket-client.d.ts → websocket.d.ts} +1 -1
  22. package/lib/Socket/Client/{web-socket-client.js → websocket.js} +10 -16
  23. package/lib/Socket/business.d.ts +94 -78
  24. package/lib/Socket/business.js +130 -11
  25. package/lib/Socket/chats.d.ts +63 -233
  26. package/lib/Socket/chats.js +234 -184
  27. package/lib/Socket/communities.d.ts +232 -0
  28. package/lib/Socket/communities.js +402 -0
  29. package/lib/Socket/groups.d.ts +62 -41
  30. package/lib/Socket/groups.js +76 -64
  31. package/lib/Socket/index.d.ts +129 -83
  32. package/lib/Socket/index.js +13 -6
  33. package/lib/Socket/messages-recv.d.ts +59 -48
  34. package/lib/Socket/messages-recv.js +516 -371
  35. package/lib/Socket/messages-send.d.ts +86 -67
  36. package/lib/Socket/messages-send.js +1091 -1
  37. package/lib/Socket/mex.d.ts +2 -0
  38. package/lib/Socket/mex.js +45 -0
  39. package/lib/Socket/newsletter.d.ts +76 -64
  40. package/lib/Socket/newsletter.js +184 -1
  41. package/lib/Socket/socket.d.ts +19 -13
  42. package/lib/Socket/socket.js +805 -1
  43. package/lib/Types/Auth.d.ts +4 -10
  44. package/lib/Types/Bussines.d.ts +24 -0
  45. package/lib/Types/Bussines.js +2 -0
  46. package/lib/Types/Call.d.ts +1 -1
  47. package/lib/Types/Chat.d.ts +29 -9
  48. package/lib/Types/Chat.js +7 -1
  49. package/lib/Types/Contact.d.ts +5 -1
  50. package/lib/Types/Events.d.ts +55 -14
  51. package/lib/Types/GroupMetadata.d.ts +15 -5
  52. package/lib/Types/Label.d.ts +11 -0
  53. package/lib/Types/Label.js +1 -1
  54. package/lib/Types/LabelAssociation.js +1 -1
  55. package/lib/Types/Message.d.ts +75 -49
  56. package/lib/Types/Message.js +10 -7
  57. package/lib/Types/Newsletter.d.ts +129 -98
  58. package/lib/Types/Newsletter.js +33 -38
  59. package/lib/Types/Product.d.ts +1 -1
  60. package/lib/Types/Signal.d.ts +29 -1
  61. package/lib/Types/Socket.d.ts +48 -22
  62. package/lib/Types/State.d.ts +13 -2
  63. package/lib/Types/State.js +12 -0
  64. package/lib/Types/USync.d.ts +1 -1
  65. package/lib/Types/index.d.ts +10 -3
  66. package/lib/Types/index.js +2 -2
  67. package/lib/Utils/auth-utils.d.ts +3 -3
  68. package/lib/Utils/auth-utils.js +378 -102
  69. package/lib/Utils/baileys-event-stream.js +1 -1
  70. package/lib/Utils/business.d.ts +2 -2
  71. package/lib/Utils/business.js +19 -13
  72. package/lib/Utils/chat-utils.d.ts +21 -22
  73. package/lib/Utils/chat-utils.js +201 -154
  74. package/lib/Utils/crypto.d.ts +18 -19
  75. package/lib/Utils/crypto.js +78 -37
  76. package/lib/Utils/decode-wa-message.d.ts +34 -7
  77. package/lib/Utils/decode-wa-message.js +138 -66
  78. package/lib/Utils/event-buffer.d.ts +6 -8
  79. package/lib/Utils/event-buffer.js +81 -43
  80. package/lib/Utils/generics.d.ts +27 -27
  81. package/lib/Utils/generics.js +128 -133
  82. package/lib/Utils/history.d.ts +9 -5
  83. package/lib/Utils/history.js +17 -23
  84. package/lib/Utils/index.d.ts +2 -0
  85. package/lib/Utils/index.js +2 -0
  86. package/lib/Utils/lidToJid-test.d.ts +11 -0
  87. package/lib/Utils/lidToJid-test.js +27 -0
  88. package/lib/Utils/link-preview.d.ts +4 -4
  89. package/lib/Utils/link-preview.js +40 -12
  90. package/lib/Utils/logger.d.ts +11 -3
  91. package/lib/Utils/lt-hash.d.ts +8 -8
  92. package/lib/Utils/lt-hash.js +23 -24
  93. package/lib/Utils/make-mutex.d.ts +2 -2
  94. package/lib/Utils/make-mutex.js +3 -2
  95. package/lib/Utils/message-retry-manager.d.ts +81 -0
  96. package/lib/Utils/message-retry-manager.js +152 -0
  97. package/lib/Utils/messages-media.d.ts +37 -41
  98. package/lib/Utils/messages-media.js +252 -368
  99. package/lib/Utils/messages.d.ts +13 -15
  100. package/lib/Utils/messages.js +274 -261
  101. package/lib/Utils/noise-handler.d.ts +13 -15
  102. package/lib/Utils/noise-handler.js +20 -26
  103. package/lib/Utils/process-message.d.ts +9 -8
  104. package/lib/Utils/process-message.js +157 -93
  105. package/lib/Utils/signal.d.ts +6 -5
  106. package/lib/Utils/signal.js +37 -29
  107. package/lib/Utils/use-multi-file-auth-state.d.ts +1 -2
  108. package/lib/Utils/use-multi-file-auth-state.js +12 -7
  109. package/lib/Utils/validate-connection.d.ts +5 -6
  110. package/lib/Utils/validate-connection.js +39 -97
  111. package/lib/WABinary/constants.d.ts +24 -27
  112. package/lib/WABinary/constants.js +1276 -13
  113. package/lib/WABinary/decode.d.ts +3 -4
  114. package/lib/WABinary/decode.js +28 -14
  115. package/lib/WABinary/encode.d.ts +1 -2
  116. package/lib/WABinary/encode.js +134 -147
  117. package/lib/WABinary/generic-utils.d.ts +4 -7
  118. package/lib/WABinary/generic-utils.js +40 -125
  119. package/lib/WABinary/jid-utils.d.ts +13 -8
  120. package/lib/WABinary/jid-utils.js +27 -16
  121. package/lib/WAM/BinaryInfo.d.ts +2 -11
  122. package/lib/WAM/constants.d.ts +3 -2
  123. package/lib/WAM/constants.js +2252 -2359
  124. package/lib/WAM/encode.d.ts +1 -2
  125. package/lib/WAM/encode.js +8 -11
  126. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +2 -2
  127. package/lib/WAUSync/Protocols/USyncContactProtocol.js +3 -4
  128. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -2
  129. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +5 -5
  130. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -2
  131. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +5 -5
  132. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -2
  133. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +5 -6
  134. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +2 -2
  135. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -1
  136. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +4 -3
  137. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +11 -3
  138. package/lib/WAUSync/USyncQuery.d.ts +2 -2
  139. package/lib/WAUSync/USyncQuery.js +19 -15
  140. package/lib/WAUSync/USyncUser.d.ts +5 -5
  141. package/lib/WAUSync/index.d.ts +1 -1
  142. package/lib/WAUSync/index.js +1 -1
  143. package/package.json +102 -102
  144. package/lib/Defaults/baileys-version.json +0 -3
  145. package/lib/Defaults/phonenumber-mcc.json +0 -223
  146. package/lib/Signal/Group/queue-job.d.ts +0 -1
  147. package/lib/Signal/Group/queue-job.js +0 -57
  148. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
  149. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  150. package/lib/Socket/hbmods.d.ts +0 -253
  151. package/lib/Socket/hbmods.js +0 -1
  152. package/lib/Socket/registration.d.ts +0 -267
  153. package/lib/Socket/registration.js +0 -166
  154. package/lib/Socket/usync.d.ts +0 -36
  155. package/lib/Socket/usync.js +0 -70
  156. /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
@@ -0,0 +1,232 @@
1
+ import { proto } from '../../WAProto/index.js';
2
+ import { type GroupMetadata, type ParticipantAction, type SocketConfig, type WAMessageKey } from '../Types';
3
+ import { type 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
+ communityCreateGroup: (subject: string, participants: string[], parentCommunityJid: string) => Promise<GroupMetadata | null>;
8
+ communityLeave: (id: string) => Promise<void>;
9
+ communityUpdateSubject: (jid: string, subject: string) => Promise<void>;
10
+ communityLinkGroup: (groupJid: string, parentCommunityJid: string) => Promise<void>;
11
+ communityUnlinkGroup: (groupJid: string, parentCommunityJid: string) => Promise<void>;
12
+ communityRequestParticipantsList: (jid: string) => Promise<{
13
+ [key: string]: string;
14
+ }[]>;
15
+ communityRequestParticipantsUpdate: (jid: string, participants: string[], action: "approve" | "reject") => Promise<{
16
+ status: string;
17
+ jid: string;
18
+ }[]>;
19
+ communityParticipantsUpdate: (jid: string, participants: string[], action: ParticipantAction) => Promise<{
20
+ status: string;
21
+ jid: string;
22
+ content: BinaryNode;
23
+ }[]>;
24
+ communityUpdateDescription: (jid: string, description?: string) => Promise<void>;
25
+ communityInviteCode: (jid: string) => Promise<string | undefined>;
26
+ communityRevokeInvite: (jid: string) => Promise<string | undefined>;
27
+ communityAcceptInvite: (code: string) => Promise<string | undefined>;
28
+ /**
29
+ * revoke a v4 invite for someone
30
+ * @param communityJid community jid
31
+ * @param invitedJid jid of person you invited
32
+ * @returns true if successful
33
+ */
34
+ communityRevokeInviteV4: (communityJid: string, invitedJid: string) => Promise<boolean>;
35
+ /**
36
+ * accept a CommunityInviteMessage
37
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
38
+ * @param inviteMessage the message to accept
39
+ */
40
+ communityAcceptInviteV4: (key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<any>;
41
+ communityGetInviteInfo: (code: string) => Promise<GroupMetadata>;
42
+ communityToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
43
+ communitySettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
44
+ communityMemberAddMode: (jid: string, mode: "admin_add" | "all_member_add") => Promise<void>;
45
+ communityJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
46
+ communityFetchAllParticipating: () => Promise<{
47
+ [_: string]: GroupMetadata;
48
+ }>;
49
+ logger: import("../Utils/logger").ILogger;
50
+ getOrderDetails: (orderId: string, tokenBase64: string) => Promise<import("../Types").OrderDetails>;
51
+ getCatalog: ({ jid, limit, cursor }: import("../Types").GetCatalogOptions) => Promise<{
52
+ products: import("../Types").Product[];
53
+ nextPageCursor: string | undefined;
54
+ }>;
55
+ getCollections: (jid?: string, limit?: number) => Promise<{
56
+ collections: import("../Types").CatalogCollection[];
57
+ }>;
58
+ productCreate: (create: import("../Types").ProductCreate) => Promise<import("../Types").Product>;
59
+ productDelete: (productIds: string[]) => Promise<{
60
+ deleted: number;
61
+ }>;
62
+ productUpdate: (productId: string, update: import("../Types").ProductUpdate) => Promise<import("../Types").Product>;
63
+ updateBussinesProfile: (args: import("../Types/Bussines.js").UpdateBussinesProfileProps) => Promise<any>;
64
+ updateCoverPhoto: (photo: import("../Types").WAMediaUpload) => Promise<number>;
65
+ removeCoverPhoto: (id: string) => Promise<any>;
66
+ sendMessageAck: ({ tag, attrs, content }: BinaryNode, errorCode?: number) => Promise<void>;
67
+ sendRetryRequest: (node: BinaryNode, forceIncludeKeys?: boolean) => Promise<void>;
68
+ rejectCall: (callId: string, callFrom: string) => Promise<void>;
69
+ fetchMessageHistory: (count: number, oldestMsgKey: WAMessageKey, oldestMsgTimestamp: number | Long) => Promise<string>;
70
+ requestPlaceholderResend: (messageKey: WAMessageKey) => Promise<string | undefined>;
71
+ messageRetryManager: import("../Utils").MessageRetryManager | null;
72
+ getPrivacyTokens: (jids: string[]) => Promise<any>;
73
+ assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
74
+ relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
75
+ sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
76
+ sendReceipts: (keys: WAMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>;
77
+ readMessages: (keys: WAMessageKey[]) => Promise<void>;
78
+ refreshMediaConn: (forceGet?: boolean) => Promise<import("../Types").MediaConnInfo>;
79
+ waUploadToServer: import("../Types").WAMediaUploadFunction;
80
+ fetchPrivacySettings: (force?: boolean) => Promise<{
81
+ [_: string]: string;
82
+ }>;
83
+ sendPeerDataOperationMessage: (pdoMessage: proto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
84
+ createParticipantNodes: (jids: string[], message: proto.IMessage, extraAttrs?: BinaryNode["attrs"], dsmMessage?: proto.IMessage) => Promise<{
85
+ nodes: BinaryNode[];
86
+ shouldIncludeDeviceIdentity: boolean;
87
+ }>;
88
+ getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<(import("../WABinary").JidWithDevice & {
89
+ wireJid: string;
90
+ })[]>;
91
+ updateMediaMessage: (message: proto.IWebMessageInfo) => Promise<proto.IWebMessageInfo>;
92
+ sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo | undefined>;
93
+ newsletterCreate: (name: string, description?: string) => Promise<import("../Types").NewsletterMetadata>;
94
+ newsletterUpdate: (jid: string, updates: import("../Types").NewsletterUpdate) => Promise<unknown>;
95
+ newsletterSubscribers: (jid: string) => Promise<{
96
+ subscribers: number;
97
+ }>;
98
+ newsletterMetadata: (type: "invite" | "jid", key: string) => Promise<import("../Types").NewsletterMetadata | null>;
99
+ newsletterFollow: (jid: string) => Promise<unknown>;
100
+ newsletterUnfollow: (jid: string) => Promise<unknown>;
101
+ newsletterMute: (jid: string) => Promise<unknown>;
102
+ newsletterUnmute: (jid: string) => Promise<unknown>;
103
+ newsletterUpdateName: (jid: string, name: string) => Promise<unknown>;
104
+ newsletterUpdateDescription: (jid: string, description: string) => Promise<unknown>;
105
+ newsletterUpdatePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<unknown>;
106
+ newsletterRemovePicture: (jid: string) => Promise<unknown>;
107
+ newsletterReactMessage: (jid: string, serverId: string, reaction?: string) => Promise<void>;
108
+ newsletterFetchMessages: (jid: string, count: number, since: number, after: number) => Promise<any>;
109
+ subscribeNewsletterUpdates: (jid: string) => Promise<{
110
+ duration: string;
111
+ } | null>;
112
+ newsletterAdminCount: (jid: string) => Promise<number>;
113
+ newsletterChangeOwner: (jid: string, newOwnerJid: string) => Promise<void>;
114
+ newsletterDemote: (jid: string, userJid: string) => Promise<void>;
115
+ newsletterDelete: (jid: string) => Promise<void>;
116
+ groupMetadata: (jid: string) => Promise<GroupMetadata>;
117
+ groupCreate: (subject: string, participants: string[]) => Promise<GroupMetadata>;
118
+ groupLeave: (id: string) => Promise<void>;
119
+ groupUpdateSubject: (jid: string, subject: string) => Promise<void>;
120
+ groupRequestParticipantsList: (jid: string) => Promise<{
121
+ [key: string]: string;
122
+ }[]>;
123
+ groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "approve" | "reject") => Promise<{
124
+ status: string;
125
+ jid: string;
126
+ }[]>;
127
+ groupParticipantsUpdate: (jid: string, participants: string[], action: ParticipantAction) => Promise<{
128
+ status: string;
129
+ jid: string;
130
+ content: BinaryNode;
131
+ }[]>;
132
+ groupUpdateDescription: (jid: string, description?: string) => Promise<void>;
133
+ groupInviteCode: (jid: string) => Promise<string | undefined>;
134
+ groupRevokeInvite: (jid: string) => Promise<string | undefined>;
135
+ groupAcceptInvite: (code: string) => Promise<string | undefined>;
136
+ groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
137
+ groupAcceptInviteV4: (key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<any>;
138
+ groupGetInviteInfo: (code: string) => Promise<GroupMetadata>;
139
+ groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
140
+ groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
141
+ groupMemberAddMode: (jid: string, mode: "admin_add" | "all_member_add") => Promise<void>;
142
+ groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
143
+ groupFetchAllParticipating: () => Promise<{
144
+ [_: string]: GroupMetadata;
145
+ }>;
146
+ createCallLink: (type: "audio" | "video", event?: {
147
+ startTime: number;
148
+ }, timeoutMs?: number) => Promise<string | undefined>;
149
+ getBotListV2: () => Promise<import("../Types").BotListInfo[]>;
150
+ processingMutex: {
151
+ mutex<T>(code: () => Promise<T> | T): Promise<T>;
152
+ };
153
+ upsertMessage: (msg: import("../Types").WAMessage, type: import("../Types").MessageUpsertType) => Promise<void>;
154
+ appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
155
+ sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string) => Promise<void>;
156
+ presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
157
+ profilePictureUrl: (jid: string, type?: "preview" | "image", timeoutMs?: number) => Promise<string | undefined>;
158
+ fetchBlocklist: () => Promise<string[]>;
159
+ fetchStatus: (...jids: string[]) => Promise<import("../index.js").USyncQueryResultList[] | undefined>;
160
+ fetchDisappearingDuration: (...jids: string[]) => Promise<import("../index.js").USyncQueryResultList[] | undefined>;
161
+ updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload, dimensions?: {
162
+ width: number;
163
+ height: number;
164
+ }) => Promise<void>;
165
+ removeProfilePicture: (jid: string) => Promise<void>;
166
+ updateProfileStatus: (status: string) => Promise<void>;
167
+ updateProfileName: (name: string) => Promise<void>;
168
+ updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
169
+ updateDisableLinkPreviewsPrivacy: (isPreviewsDisabled: boolean) => Promise<void>;
170
+ updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
171
+ updateMessagesPrivacy: (value: import("../Types").WAPrivacyMessagesValue) => Promise<void>;
172
+ updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
173
+ updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
174
+ updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
175
+ updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
176
+ updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
177
+ updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
178
+ updateDefaultDisappearingMode: (duration: number) => Promise<void>;
179
+ getBusinessProfile: (jid: string) => Promise<import("../Types").WABusinessProfile | void>;
180
+ resyncAppState: (collections: readonly ("critical_unblock_low" | "regular_high" | "regular_low" | "critical_block" | "regular")[], isInitialSync: boolean) => Promise<void>;
181
+ chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
182
+ cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
183
+ addOrEditContact: (jid: string, contact: proto.SyncActionValue.IContactAction) => Promise<void>;
184
+ removeContact: (jid: string) => Promise<void>;
185
+ addLabel: (jid: string, labels: import("../Types/Label.js").LabelActionBody) => Promise<void>;
186
+ addChatLabel: (jid: string, labelId: string) => Promise<void>;
187
+ removeChatLabel: (jid: string, labelId: string) => Promise<void>;
188
+ addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
189
+ removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
190
+ star: (jid: string, messages: {
191
+ id: string;
192
+ fromMe?: boolean;
193
+ }[], star: boolean) => Promise<void>;
194
+ addOrEditQuickReply: (quickReply: import("../Types/Bussines.js").QuickReplyAction) => Promise<void>;
195
+ removeQuickReply: (timestamp: string) => Promise<void>;
196
+ type: "md";
197
+ ws: import("./Client/websocket.js").WebSocketClient;
198
+ ev: import("../Types").BaileysEventEmitter & {
199
+ process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
200
+ buffer(): void;
201
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
202
+ flush(): boolean;
203
+ isBuffering(): boolean;
204
+ };
205
+ authState: {
206
+ creds: import("../Types").AuthenticationCreds;
207
+ keys: import("../Types").SignalKeyStoreWithTransaction;
208
+ };
209
+ signalRepository: import("../Types").SignalRepositoryWithLIDStore;
210
+ user: import("../Types").Contact | undefined;
211
+ generateMessageTag: () => string;
212
+ query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
213
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<T | undefined>;
214
+ waitForSocketOpen: () => Promise<void>;
215
+ sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
216
+ sendNode: (frame: BinaryNode) => Promise<void>;
217
+ logout: (msg?: string) => Promise<void>;
218
+ end: (error: Error | undefined) => void;
219
+ onUnexpectedError: (err: Error | import("@hapi/boom").Boom, msg: string) => void;
220
+ uploadPreKeys: (count?: number, retryCount?: number) => Promise<void>;
221
+ uploadPreKeysToServerIfRequired: () => Promise<void>;
222
+ requestPairingCode: (phoneNumber: string, customPairingCode?: string) => Promise<string>;
223
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
224
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
225
+ executeUSyncQuery: (usyncQuery: import("../index.js").USyncQuery) => Promise<import("../index.js").USyncQueryResult | undefined>;
226
+ onWhatsApp: (...jids: string[]) => Promise<{
227
+ jid: string;
228
+ exists: boolean;
229
+ lid: string;
230
+ }[] | undefined>;
231
+ };
232
+ export declare const extractCommunityMetadata: (result: BinaryNode) => GroupMetadata;
@@ -0,0 +1,402 @@
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
+ communityCreateGroup: async (subject, participants, parentCommunityJid) => {
131
+ const key = (0, Utils_1.generateMessageIDV2)();
132
+ const result = await communityQuery('@g.us', 'set', [
133
+ {
134
+ tag: 'create',
135
+ attrs: {
136
+ subject,
137
+ key
138
+ },
139
+ content: [
140
+ ...participants.map(jid => ({
141
+ tag: 'participant',
142
+ attrs: { jid }
143
+ })),
144
+ { tag: 'linked_parent', attrs: { jid: parentCommunityJid } }
145
+ ]
146
+ }
147
+ ]);
148
+ return await parseGroupResult(result);
149
+ },
150
+ communityLeave: async (id) => {
151
+ await communityQuery('@g.us', 'set', [
152
+ {
153
+ tag: 'leave',
154
+ attrs: {},
155
+ content: [{ tag: 'community', attrs: { id } }]
156
+ }
157
+ ]);
158
+ },
159
+ communityUpdateSubject: async (jid, subject) => {
160
+ await communityQuery(jid, 'set', [
161
+ {
162
+ tag: 'subject',
163
+ attrs: {},
164
+ content: Buffer.from(subject, 'utf-8')
165
+ }
166
+ ]);
167
+ },
168
+ communityLinkGroup: async (groupJid, parentCommunityJid) => {
169
+ await communityQuery(parentCommunityJid, 'set', [
170
+ {
171
+ tag: 'links',
172
+ attrs: {},
173
+ content: [
174
+ {
175
+ tag: 'link',
176
+ attrs: { link_type: 'sub_group' },
177
+ content: [{ tag: 'group', attrs: { jid: groupJid } }]
178
+ }
179
+ ]
180
+ }
181
+ ]);
182
+ },
183
+ communityUnlinkGroup: async (groupJid, parentCommunityJid) => {
184
+ await communityQuery(parentCommunityJid, 'set', [
185
+ {
186
+ tag: 'unlink',
187
+ attrs: { unlink_type: 'sub_group' },
188
+ content: [{ tag: 'group', attrs: { jid: groupJid } }]
189
+ }
190
+ ]);
191
+ },
192
+ communityRequestParticipantsList: async (jid) => {
193
+ const result = await communityQuery(jid, 'get', [
194
+ {
195
+ tag: 'membership_approval_requests',
196
+ attrs: {}
197
+ }
198
+ ]);
199
+ const node = (0, WABinary_1.getBinaryNodeChild)(result, 'membership_approval_requests');
200
+ const participants = (0, WABinary_1.getBinaryNodeChildren)(node, 'membership_approval_request');
201
+ return participants.map(v => v.attrs);
202
+ },
203
+ communityRequestParticipantsUpdate: async (jid, participants, action) => {
204
+ const result = await communityQuery(jid, 'set', [
205
+ {
206
+ tag: 'membership_requests_action',
207
+ attrs: {},
208
+ content: [
209
+ {
210
+ tag: action,
211
+ attrs: {},
212
+ content: participants.map(jid => ({
213
+ tag: 'participant',
214
+ attrs: { jid }
215
+ }))
216
+ }
217
+ ]
218
+ }
219
+ ]);
220
+ const node = (0, WABinary_1.getBinaryNodeChild)(result, 'membership_requests_action');
221
+ const nodeAction = (0, WABinary_1.getBinaryNodeChild)(node, action);
222
+ const participantsAffected = (0, WABinary_1.getBinaryNodeChildren)(nodeAction, 'participant');
223
+ return participantsAffected.map(p => {
224
+ return { status: p.attrs.error || '200', jid: p.attrs.jid };
225
+ });
226
+ },
227
+ communityParticipantsUpdate: async (jid, participants, action) => {
228
+ const result = await communityQuery(jid, 'set', [
229
+ {
230
+ tag: action,
231
+ attrs: {},
232
+ content: participants.map(jid => ({
233
+ tag: 'participant',
234
+ attrs: { jid }
235
+ }))
236
+ }
237
+ ]);
238
+ const node = (0, WABinary_1.getBinaryNodeChild)(result, action);
239
+ const participantsAffected = (0, WABinary_1.getBinaryNodeChildren)(node, 'participant');
240
+ return participantsAffected.map(p => {
241
+ return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
242
+ });
243
+ },
244
+ communityUpdateDescription: async (jid, description) => {
245
+ const metadata = await communityMetadata(jid);
246
+ const prev = metadata.descId ?? null;
247
+ await communityQuery(jid, 'set', [
248
+ {
249
+ tag: 'description',
250
+ attrs: {
251
+ ...(description ? { id: (0, Utils_1.generateMessageID)() } : { delete: 'true' }),
252
+ ...(prev ? { prev } : {})
253
+ },
254
+ content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
255
+ }
256
+ ]);
257
+ },
258
+ communityInviteCode: async (jid) => {
259
+ const result = await communityQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
260
+ const inviteNode = (0, WABinary_1.getBinaryNodeChild)(result, 'invite');
261
+ return inviteNode?.attrs.code;
262
+ },
263
+ communityRevokeInvite: async (jid) => {
264
+ const result = await communityQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
265
+ const inviteNode = (0, WABinary_1.getBinaryNodeChild)(result, 'invite');
266
+ return inviteNode?.attrs.code;
267
+ },
268
+ communityAcceptInvite: async (code) => {
269
+ const results = await communityQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
270
+ const result = (0, WABinary_1.getBinaryNodeChild)(results, 'community');
271
+ return result?.attrs.jid;
272
+ },
273
+ /**
274
+ * revoke a v4 invite for someone
275
+ * @param communityJid community jid
276
+ * @param invitedJid jid of person you invited
277
+ * @returns true if successful
278
+ */
279
+ communityRevokeInviteV4: async (communityJid, invitedJid) => {
280
+ const result = await communityQuery(communityJid, 'set', [
281
+ { tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
282
+ ]);
283
+ return !!result;
284
+ },
285
+ /**
286
+ * accept a CommunityInviteMessage
287
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
288
+ * @param inviteMessage the message to accept
289
+ */
290
+ communityAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
291
+ key = typeof key === 'string' ? { remoteJid: key } : key;
292
+ const results = await communityQuery(inviteMessage.groupJid, 'set', [
293
+ {
294
+ tag: 'accept',
295
+ attrs: {
296
+ code: inviteMessage.inviteCode,
297
+ expiration: inviteMessage.inviteExpiration.toString(),
298
+ admin: key.remoteJid
299
+ }
300
+ }
301
+ ]);
302
+ // if we have the full message key
303
+ // update the invite message to be expired
304
+ if (key.id) {
305
+ // create new invite message that is expired
306
+ inviteMessage = index_js_1.proto.Message.GroupInviteMessage.create(inviteMessage);
307
+ inviteMessage.inviteExpiration = 0;
308
+ inviteMessage.inviteCode = '';
309
+ ev.emit('messages.update', [
310
+ {
311
+ key,
312
+ update: {
313
+ message: {
314
+ groupInviteMessage: inviteMessage
315
+ }
316
+ }
317
+ }
318
+ ]);
319
+ }
320
+ // generate the community add message
321
+ await upsertMessage({
322
+ key: {
323
+ remoteJid: inviteMessage.groupJid,
324
+ id: (0, Utils_1.generateMessageIDV2)(sock.user?.id),
325
+ fromMe: false,
326
+ participant: key.remoteJid
327
+ },
328
+ messageStubType: Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD,
329
+ messageStubParameters: [authState.creds.me.id],
330
+ participant: key.remoteJid,
331
+ messageTimestamp: (0, Utils_1.unixTimestampSeconds)()
332
+ }, 'notify');
333
+ return results.attrs.from;
334
+ }),
335
+ communityGetInviteInfo: async (code) => {
336
+ const results = await communityQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
337
+ return (0, exports.extractCommunityMetadata)(results);
338
+ },
339
+ communityToggleEphemeral: async (jid, ephemeralExpiration) => {
340
+ const content = ephemeralExpiration
341
+ ? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
342
+ : { tag: 'not_ephemeral', attrs: {} };
343
+ await communityQuery(jid, 'set', [content]);
344
+ },
345
+ communitySettingUpdate: async (jid, setting) => {
346
+ await communityQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
347
+ },
348
+ communityMemberAddMode: async (jid, mode) => {
349
+ await communityQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
350
+ },
351
+ communityJoinApprovalMode: async (jid, mode) => {
352
+ await communityQuery(jid, 'set', [
353
+ { tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'community_join', attrs: { state: mode } }] }
354
+ ]);
355
+ },
356
+ communityFetchAllParticipating
357
+ };
358
+ };
359
+ exports.makeCommunitiesSocket = makeCommunitiesSocket;
360
+ const extractCommunityMetadata = (result) => {
361
+ const community = (0, WABinary_1.getBinaryNodeChild)(result, 'community');
362
+ const descChild = (0, WABinary_1.getBinaryNodeChild)(community, 'description');
363
+ let desc;
364
+ let descId;
365
+ if (descChild) {
366
+ desc = (0, WABinary_1.getBinaryNodeChildString)(descChild, 'body');
367
+ descId = descChild.attrs.id;
368
+ }
369
+ const communityId = community.attrs.id?.includes('@')
370
+ ? community.attrs.id
371
+ : (0, WABinary_1.jidEncode)(community.attrs.id || '', 'g.us');
372
+ const eph = (0, WABinary_1.getBinaryNodeChild)(community, 'ephemeral')?.attrs.expiration;
373
+ const memberAddMode = (0, WABinary_1.getBinaryNodeChildString)(community, 'member_add_mode') === 'all_member_add';
374
+ const metadata = {
375
+ id: communityId,
376
+ subject: community.attrs.subject || '',
377
+ subjectOwner: community.attrs.s_o,
378
+ subjectTime: Number(community.attrs.s_t || 0),
379
+ size: (0, WABinary_1.getBinaryNodeChildren)(community, 'participant').length,
380
+ creation: Number(community.attrs.creation || 0),
381
+ owner: community.attrs.creator ? (0, WABinary_1.jidNormalizedUser)(community.attrs.creator) : undefined,
382
+ desc,
383
+ descId,
384
+ linkedParent: (0, WABinary_1.getBinaryNodeChild)(community, 'linked_parent')?.attrs.jid || undefined,
385
+ restrict: !!(0, WABinary_1.getBinaryNodeChild)(community, 'locked'),
386
+ announce: !!(0, WABinary_1.getBinaryNodeChild)(community, 'announcement'),
387
+ isCommunity: !!(0, WABinary_1.getBinaryNodeChild)(community, 'parent'),
388
+ isCommunityAnnounce: !!(0, WABinary_1.getBinaryNodeChild)(community, 'default_sub_community'),
389
+ joinApprovalMode: !!(0, WABinary_1.getBinaryNodeChild)(community, 'membership_approval_mode'),
390
+ memberAddMode,
391
+ participants: (0, WABinary_1.getBinaryNodeChildren)(community, 'participant').map(({ attrs }) => {
392
+ return {
393
+ id: attrs.jid,
394
+ admin: (attrs.type || null)
395
+ };
396
+ }),
397
+ ephemeralDuration: eph ? +eph : undefined,
398
+ addressingMode: (0, WABinary_1.getBinaryNodeChildString)(community, 'addressing_mode')
399
+ };
400
+ return metadata;
401
+ };
402
+ exports.extractCommunityMetadata = extractCommunityMetadata;