supunmd-bail 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/LICENSE +21 -0
  2. package/WAProto/GenerateStatics.sh +3 -0
  3. package/WAProto/WAProto.proto +5519 -0
  4. package/WAProto/fix-imports.js +29 -0
  5. package/WAProto/index.d.ts +11969 -0
  6. package/WAProto/index.js +84368 -0
  7. package/engine-requirements.js +10 -0
  8. package/lib/Defaults/baileys-version.json +3 -0
  9. package/lib/Defaults/index.d.ts +62 -0
  10. package/lib/Defaults/index.js +115 -0
  11. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  12. package/lib/Signal/Group/ciphertext-message.js +12 -0
  13. package/lib/Signal/Group/group-session-builder.d.ts +15 -0
  14. package/lib/Signal/Group/group-session-builder.js +30 -0
  15. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  16. package/lib/Signal/Group/group_cipher.js +82 -0
  17. package/lib/Signal/Group/index.d.ts +12 -0
  18. package/lib/Signal/Group/index.js +12 -0
  19. package/lib/Signal/Group/keyhelper.d.ts +11 -0
  20. package/lib/Signal/Group/keyhelper.js +18 -0
  21. package/lib/Signal/Group/queue-job.d.ts +2 -0
  22. package/lib/Signal/Group/queue-job.js +54 -0
  23. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  24. package/lib/Signal/Group/sender-chain-key.js +26 -0
  25. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  26. package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
  27. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  28. package/lib/Signal/Group/sender-key-message.js +66 -0
  29. package/lib/Signal/Group/sender-key-name.d.ts +18 -0
  30. package/lib/Signal/Group/sender-key-name.js +48 -0
  31. package/lib/Signal/Group/sender-key-record.d.ts +31 -0
  32. package/lib/Signal/Group/sender-key-record.js +41 -0
  33. package/lib/Signal/Group/sender-key-state.d.ts +39 -0
  34. package/lib/Signal/Group/sender-key-state.js +84 -0
  35. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  36. package/lib/Signal/Group/sender-message-key.js +26 -0
  37. package/lib/Signal/libsignal.d.ts +5 -0
  38. package/lib/Signal/libsignal.js +342 -0
  39. package/lib/Signal/lid-mapping.d.ts +23 -0
  40. package/lib/Signal/lid-mapping.js +171 -0
  41. package/lib/Socket/Client/index.d.ts +3 -0
  42. package/lib/Socket/Client/index.js +3 -0
  43. package/lib/Socket/Client/types.d.ts +16 -0
  44. package/lib/Socket/Client/types.js +11 -0
  45. package/lib/Socket/Client/websocket.d.ts +13 -0
  46. package/lib/Socket/Client/websocket.js +50 -0
  47. package/lib/Socket/business.d.ts +188 -0
  48. package/lib/Socket/business.js +376 -0
  49. package/lib/Socket/chats.d.ts +98 -0
  50. package/lib/Socket/chats.js +962 -0
  51. package/lib/Socket/communities.d.ts +244 -0
  52. package/lib/Socket/communities.js +431 -0
  53. package/lib/Socket/groups.d.ts +137 -0
  54. package/lib/Socket/groups.js +327 -0
  55. package/lib/Socket/index.d.ts +231 -0
  56. package/lib/Socket/index.js +18 -0
  57. package/lib/Socket/messages-recv.d.ts +173 -0
  58. package/lib/Socket/messages-recv.js +1228 -0
  59. package/lib/Socket/messages-send.d.ts +169 -0
  60. package/lib/Socket/messages-send.js +1070 -0
  61. package/lib/Socket/mex.d.ts +3 -0
  62. package/lib/Socket/mex.js +42 -0
  63. package/lib/Socket/newsletter.d.ts +147 -0
  64. package/lib/Socket/newsletter.js +181 -0
  65. package/lib/Socket/socket.d.ts +51 -0
  66. package/lib/Socket/socket.js +883 -0
  67. package/lib/Socket/usync.d.ts +37 -0
  68. package/lib/Socket/usync.js +63 -0
  69. package/lib/Types/Auth.d.ts +111 -0
  70. package/lib/Types/Auth.js +2 -0
  71. package/lib/Types/Bussines.d.ts +25 -0
  72. package/lib/Types/Bussines.js +2 -0
  73. package/lib/Types/Call.d.ts +14 -0
  74. package/lib/Types/Call.js +2 -0
  75. package/lib/Types/Chat.d.ts +123 -0
  76. package/lib/Types/Chat.js +8 -0
  77. package/lib/Types/Contact.d.ts +24 -0
  78. package/lib/Types/Contact.js +2 -0
  79. package/lib/Types/Events.d.ts +202 -0
  80. package/lib/Types/Events.js +2 -0
  81. package/lib/Types/GroupMetadata.d.ts +67 -0
  82. package/lib/Types/GroupMetadata.js +2 -0
  83. package/lib/Types/Label.d.ts +47 -0
  84. package/lib/Types/Label.js +25 -0
  85. package/lib/Types/LabelAssociation.d.ts +30 -0
  86. package/lib/Types/LabelAssociation.js +7 -0
  87. package/lib/Types/Message.d.ts +303 -0
  88. package/lib/Types/Message.js +11 -0
  89. package/lib/Types/Newsletter.d.ts +135 -0
  90. package/lib/Types/Newsletter.js +31 -0
  91. package/lib/Types/Product.d.ts +79 -0
  92. package/lib/Types/Product.js +2 -0
  93. package/lib/Types/Signal.d.ts +76 -0
  94. package/lib/Types/Signal.js +2 -0
  95. package/lib/Types/Socket.d.ts +133 -0
  96. package/lib/Types/Socket.js +3 -0
  97. package/lib/Types/State.d.ts +39 -0
  98. package/lib/Types/State.js +13 -0
  99. package/lib/Types/USync.d.ts +26 -0
  100. package/lib/Types/USync.js +2 -0
  101. package/lib/Types/index.d.ts +65 -0
  102. package/lib/Types/index.js +26 -0
  103. package/lib/Utils/auth-utils.d.ts +19 -0
  104. package/lib/Utils/auth-utils.js +257 -0
  105. package/lib/Utils/baileys-event-stream.d.ts +17 -0
  106. package/lib/Utils/baileys-event-stream.js +56 -0
  107. package/lib/Utils/browser-utils.d.ts +4 -0
  108. package/lib/Utils/browser-utils.js +28 -0
  109. package/lib/Utils/business.d.ts +23 -0
  110. package/lib/Utils/business.js +231 -0
  111. package/lib/Utils/chat-utils.d.ts +70 -0
  112. package/lib/Utils/chat-utils.js +763 -0
  113. package/lib/Utils/crypto.d.ts +41 -0
  114. package/lib/Utils/crypto.js +142 -0
  115. package/lib/Utils/decode-wa-message.d.ts +48 -0
  116. package/lib/Utils/decode-wa-message.js +279 -0
  117. package/lib/Utils/event-buffer.d.ts +34 -0
  118. package/lib/Utils/event-buffer.js +548 -0
  119. package/lib/Utils/generics.d.ts +90 -0
  120. package/lib/Utils/generics.js +381 -0
  121. package/lib/Utils/history.d.ts +19 -0
  122. package/lib/Utils/history.js +84 -0
  123. package/lib/Utils/index.d.ts +20 -0
  124. package/lib/Utils/index.js +20 -0
  125. package/lib/Utils/link-preview.d.ts +21 -0
  126. package/lib/Utils/link-preview.js +85 -0
  127. package/lib/Utils/logger.d.ts +12 -0
  128. package/lib/Utils/logger.js +3 -0
  129. package/lib/Utils/lt-hash.d.ts +13 -0
  130. package/lib/Utils/lt-hash.js +48 -0
  131. package/lib/Utils/make-mutex.d.ts +8 -0
  132. package/lib/Utils/make-mutex.js +40 -0
  133. package/lib/Utils/message-retry-manager.d.ts +82 -0
  134. package/lib/Utils/message-retry-manager.js +149 -0
  135. package/lib/Utils/messages-media.d.ts +114 -0
  136. package/lib/Utils/messages-media.js +663 -0
  137. package/lib/Utils/messages.d.ts +76 -0
  138. package/lib/Utils/messages.js +908 -0
  139. package/lib/Utils/noise-handler.d.ts +20 -0
  140. package/lib/Utils/noise-handler.js +147 -0
  141. package/lib/Utils/pre-key-manager.d.ts +28 -0
  142. package/lib/Utils/pre-key-manager.js +106 -0
  143. package/lib/Utils/process-message.d.ts +42 -0
  144. package/lib/Utils/process-message.js +413 -0
  145. package/lib/Utils/signal.d.ts +34 -0
  146. package/lib/Utils/signal.js +159 -0
  147. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  148. package/lib/Utils/use-multi-file-auth-state.js +121 -0
  149. package/lib/Utils/validate-connection.d.ts +11 -0
  150. package/lib/Utils/validate-connection.js +195 -0
  151. package/lib/WABinary/constants.d.ts +28 -0
  152. package/lib/WABinary/constants.js +1301 -0
  153. package/lib/WABinary/decode.d.ts +7 -0
  154. package/lib/WABinary/decode.js +238 -0
  155. package/lib/WABinary/encode.d.ts +3 -0
  156. package/lib/WABinary/encode.js +216 -0
  157. package/lib/WABinary/generic-utils.d.ts +15 -0
  158. package/lib/WABinary/generic-utils.js +191 -0
  159. package/lib/WABinary/index.d.ts +6 -0
  160. package/lib/WABinary/index.js +6 -0
  161. package/lib/WABinary/jid-utils.d.ts +48 -0
  162. package/lib/WABinary/jid-utils.js +96 -0
  163. package/lib/WABinary/types.d.ts +19 -0
  164. package/lib/WABinary/types.js +2 -0
  165. package/lib/WAM/BinaryInfo.d.ts +9 -0
  166. package/lib/WAM/BinaryInfo.js +10 -0
  167. package/lib/WAM/constants.d.ts +40 -0
  168. package/lib/WAM/constants.js +22853 -0
  169. package/lib/WAM/encode.d.ts +3 -0
  170. package/lib/WAM/encode.js +150 -0
  171. package/lib/WAM/index.d.ts +4 -0
  172. package/lib/WAM/index.js +4 -0
  173. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  174. package/lib/WAUSync/Protocols/USyncContactProtocol.js +29 -0
  175. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  176. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +54 -0
  177. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  178. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
  179. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  180. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
  181. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  182. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
  183. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
  184. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
  185. package/lib/WAUSync/Protocols/index.d.ts +5 -0
  186. package/lib/WAUSync/Protocols/index.js +5 -0
  187. package/lib/WAUSync/USyncQuery.d.ts +29 -0
  188. package/lib/WAUSync/USyncQuery.js +94 -0
  189. package/lib/WAUSync/USyncUser.d.ts +13 -0
  190. package/lib/WAUSync/USyncUser.js +23 -0
  191. package/lib/WAUSync/index.d.ts +4 -0
  192. package/lib/WAUSync/index.js +4 -0
  193. package/lib/index.d.ts +22 -0
  194. package/lib/index.js +36 -0
  195. package/lib/supun +1 -0
  196. package/package.json +104 -0
@@ -0,0 +1,137 @@
1
+ import { proto } from '../../WAProto/index.js';
2
+ import type { GroupMetadata, ParticipantAction, SocketConfig, WAMessageKey } from '../Types/index.js';
3
+ import { type BinaryNode } from '../WABinary/index.js';
4
+ export declare const makeGroupsSocket: (config: SocketConfig) => {
5
+ groupMetadata: (jid: string) => Promise<GroupMetadata>;
6
+ groupCreate: (subject: string, participants: string[]) => Promise<GroupMetadata>;
7
+ groupLeave: (id: string) => Promise<void>;
8
+ groupUpdateSubject: (jid: string, subject: string) => Promise<void>;
9
+ groupRequestParticipantsList: (jid: string) => Promise<{
10
+ [key: string]: string;
11
+ }[]>;
12
+ groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "approve" | "reject") => Promise<{
13
+ status: string;
14
+ jid: string | undefined;
15
+ }[]>;
16
+ groupParticipantsUpdate: (jid: string, participants: string[], action: ParticipantAction) => Promise<{
17
+ status: string;
18
+ jid: string | undefined;
19
+ content: BinaryNode;
20
+ }[]>;
21
+ groupUpdateDescription: (jid: string, description?: string) => Promise<void>;
22
+ groupInviteCode: (jid: string) => Promise<string | undefined>;
23
+ groupRevokeInvite: (jid: string) => Promise<string | undefined>;
24
+ groupAcceptInvite: (code: string) => Promise<string | undefined>;
25
+ /**
26
+ * revoke a v4 invite for someone
27
+ * @param groupJid group jid
28
+ * @param invitedJid jid of person you invited
29
+ * @returns true if successful
30
+ */
31
+ groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
32
+ /**
33
+ * accept a GroupInviteMessage
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
+ groupAcceptInviteV4: (key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<any>;
38
+ groupGetInviteInfo: (code: string) => Promise<GroupMetadata>;
39
+ groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
40
+ groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
41
+ groupMemberAddMode: (jid: string, mode: "admin_add" | "all_member_add") => Promise<void>;
42
+ groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
43
+ groupFetchAllParticipating: () => Promise<{
44
+ [_: string]: GroupMetadata;
45
+ }>;
46
+ createCallLink: (type: "audio" | "video", event?: {
47
+ startTime: number;
48
+ }, timeoutMs?: number) => Promise<string | undefined>;
49
+ getBotListV2: () => Promise<import("../Types/index.js").BotListInfo[]>;
50
+ processingMutex: {
51
+ mutex<T>(code: () => Promise<T> | T): Promise<T>;
52
+ };
53
+ fetchPrivacySettings: (force?: boolean) => Promise<{
54
+ [_: string]: string;
55
+ }>;
56
+ upsertMessage: (msg: import("../Types/index.js").WAMessage, type: import("../Types/index.js").MessageUpsertType) => Promise<void>;
57
+ appPatch: (patchCreate: import("../Types/index.js").WAPatchCreate) => Promise<void>;
58
+ sendPresenceUpdate: (type: import("../Types/index.js").WAPresence, toJid?: string) => Promise<void>;
59
+ presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
60
+ profilePictureUrl: (jid: string, type?: "preview" | "image", timeoutMs?: number) => Promise<string | undefined>;
61
+ fetchBlocklist: () => Promise<(string | undefined)[]>;
62
+ fetchStatus: (...jids: string[]) => Promise<import("../index.js").USyncQueryResultList[] | undefined>;
63
+ fetchDisappearingDuration: (...jids: string[]) => Promise<import("../index.js").USyncQueryResultList[] | undefined>;
64
+ updateProfilePicture: (jid: string, content: import("../Types/index.js").WAMediaUpload, dimensions?: {
65
+ width: number;
66
+ height: number;
67
+ }) => Promise<void>;
68
+ removeProfilePicture: (jid: string) => Promise<void>;
69
+ updateProfileStatus: (status: string) => Promise<void>;
70
+ updateProfileName: (name: string) => Promise<void>;
71
+ updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
72
+ updateDisableLinkPreviewsPrivacy: (isPreviewsDisabled: boolean) => Promise<void>;
73
+ updateCallPrivacy: (value: import("../Types/index.js").WAPrivacyCallValue) => Promise<void>;
74
+ updateMessagesPrivacy: (value: import("../Types/index.js").WAPrivacyMessagesValue) => Promise<void>;
75
+ updateLastSeenPrivacy: (value: import("../Types/index.js").WAPrivacyValue) => Promise<void>;
76
+ updateOnlinePrivacy: (value: import("../Types/index.js").WAPrivacyOnlineValue) => Promise<void>;
77
+ updateProfilePicturePrivacy: (value: import("../Types/index.js").WAPrivacyValue) => Promise<void>;
78
+ updateStatusPrivacy: (value: import("../Types/index.js").WAPrivacyValue) => Promise<void>;
79
+ updateReadReceiptsPrivacy: (value: import("../Types/index.js").WAReadReceiptsValue) => Promise<void>;
80
+ updateGroupsAddPrivacy: (value: import("../Types/index.js").WAPrivacyGroupAddValue) => Promise<void>;
81
+ updateDefaultDisappearingMode: (duration: number) => Promise<void>;
82
+ getBusinessProfile: (jid: string) => Promise<import("../Types/index.js").WABusinessProfile | void>;
83
+ resyncAppState: (collections: readonly ("critical_unblock_low" | "regular_high" | "regular_low" | "critical_block" | "regular")[], isInitialSync: boolean) => Promise<void>;
84
+ chatModify: (mod: import("../Types/index.js").ChatModification, jid: string) => Promise<void>;
85
+ cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
86
+ addOrEditContact: (jid: string, contact: proto.SyncActionValue.IContactAction) => Promise<void>;
87
+ removeContact: (jid: string) => Promise<void>;
88
+ addLabel: (jid: string, labels: import("../Types/Label.js").LabelActionBody) => Promise<void>;
89
+ addChatLabel: (jid: string, labelId: string) => Promise<void>;
90
+ removeChatLabel: (jid: string, labelId: string) => Promise<void>;
91
+ addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
92
+ removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
93
+ star: (jid: string, messages: {
94
+ id: string;
95
+ fromMe?: boolean;
96
+ }[], star: boolean) => Promise<void>;
97
+ addOrEditQuickReply: (quickReply: import("../Types/Bussines.js").QuickReplyAction) => Promise<void>;
98
+ removeQuickReply: (timestamp: string) => Promise<void>;
99
+ type: "md";
100
+ ws: import("./Client/websocket.js").WebSocketClient;
101
+ ev: import("../Types/index.js").BaileysEventEmitter & {
102
+ process(handler: (events: Partial<import("../Types/index.js").BaileysEventMap>) => void | Promise<void>): () => void;
103
+ buffer(): void;
104
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
105
+ flush(): boolean;
106
+ isBuffering(): boolean;
107
+ };
108
+ authState: {
109
+ creds: import("../Types/index.js").AuthenticationCreds;
110
+ keys: import("../Types/index.js").SignalKeyStoreWithTransaction;
111
+ };
112
+ signalRepository: import("../Types/index.js").SignalRepositoryWithLIDStore;
113
+ user: import("../Types/index.js").Contact | undefined;
114
+ generateMessageTag: () => string;
115
+ query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
116
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<T | undefined>;
117
+ waitForSocketOpen: () => Promise<void>;
118
+ sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
119
+ sendNode: (frame: BinaryNode) => Promise<void>;
120
+ logout: (msg?: string) => Promise<void>;
121
+ end: (error: Error | undefined) => void;
122
+ onUnexpectedError: (err: Error | import("@hapi/boom").Boom, msg: string) => void;
123
+ uploadPreKeys: (count?: number, retryCount?: number) => Promise<void>;
124
+ uploadPreKeysToServerIfRequired: () => Promise<void>;
125
+ requestPairingCode: (phoneNumber: string, customPairingCode?: string) => Promise<string>;
126
+ wamBuffer: import("../index.js").BinaryInfo;
127
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types/index.js").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
128
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
129
+ executeUSyncQuery: (usyncQuery: import("../index.js").USyncQuery) => Promise<import("../index.js").USyncQueryResult | undefined>;
130
+ onWhatsApp: (...phoneNumber: string[]) => Promise<{
131
+ jid: string;
132
+ exists: boolean;
133
+ }[] | undefined>;
134
+ };
135
+ export declare const extractGroupMetadata: (result: BinaryNode) => GroupMetadata;
136
+ export type GroupsSocket = ReturnType<typeof makeGroupsSocket>;
137
+ //# sourceMappingURL=groups.d.ts.map
@@ -0,0 +1,327 @@
1
+ import { proto } from '../../WAProto/index.js';
2
+ import { WAMessageAddressingMode, WAMessageStubType } from '../Types/index.js';
3
+ import { generateMessageIDV2, unixTimestampSeconds } from '../Utils/index.js';
4
+ import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString, isLidUser, isPnUser, jidEncode, jidNormalizedUser } from '../WABinary/index.js';
5
+ import { makeChatsSocket } from './chats.js';
6
+ export const makeGroupsSocket = (config) => {
7
+ const sock = makeChatsSocket(config);
8
+ const { authState, ev, query, upsertMessage } = sock;
9
+ const groupQuery = 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 groupMetadata = async (jid) => {
19
+ const result = await groupQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
20
+ return extractGroupMetadata(result);
21
+ };
22
+ const groupFetchAllParticipating = 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 groupsChild = getBinaryNodeChild(result, 'groups');
43
+ if (groupsChild) {
44
+ const groups = getBinaryNodeChildren(groupsChild, 'group');
45
+ for (const groupNode of groups) {
46
+ const meta = extractGroupMetadata({
47
+ tag: 'result',
48
+ attrs: {},
49
+ content: [groupNode]
50
+ });
51
+ data[meta.id] = meta;
52
+ }
53
+ }
54
+ // TODO: properly parse LID / PN DATA
55
+ sock.ev.emit('groups.update', Object.values(data));
56
+ return data;
57
+ };
58
+ sock.ws.on('CB:ib,,dirty', async (node) => {
59
+ const { attrs } = getBinaryNodeChild(node, 'dirty');
60
+ if (attrs.type !== 'groups') {
61
+ return;
62
+ }
63
+ await groupFetchAllParticipating();
64
+ await sock.cleanDirtyBits('groups');
65
+ });
66
+ return {
67
+ ...sock,
68
+ groupMetadata,
69
+ groupCreate: async (subject, participants) => {
70
+ const key = generateMessageIDV2();
71
+ const result = await groupQuery('@g.us', 'set', [
72
+ {
73
+ tag: 'create',
74
+ attrs: {
75
+ subject,
76
+ key
77
+ },
78
+ content: participants.map(jid => ({
79
+ tag: 'participant',
80
+ attrs: { jid }
81
+ }))
82
+ }
83
+ ]);
84
+ return extractGroupMetadata(result);
85
+ },
86
+ groupLeave: async (id) => {
87
+ await groupQuery('@g.us', 'set', [
88
+ {
89
+ tag: 'leave',
90
+ attrs: {},
91
+ content: [{ tag: 'group', attrs: { id } }]
92
+ }
93
+ ]);
94
+ },
95
+ groupUpdateSubject: async (jid, subject) => {
96
+ await groupQuery(jid, 'set', [
97
+ {
98
+ tag: 'subject',
99
+ attrs: {},
100
+ content: Buffer.from(subject, 'utf-8')
101
+ }
102
+ ]);
103
+ },
104
+ groupRequestParticipantsList: async (jid) => {
105
+ const result = await groupQuery(jid, 'get', [
106
+ {
107
+ tag: 'membership_approval_requests',
108
+ attrs: {}
109
+ }
110
+ ]);
111
+ const node = getBinaryNodeChild(result, 'membership_approval_requests');
112
+ const participants = getBinaryNodeChildren(node, 'membership_approval_request');
113
+ return participants.map(v => v.attrs);
114
+ },
115
+ groupRequestParticipantsUpdate: async (jid, participants, action) => {
116
+ const result = await groupQuery(jid, 'set', [
117
+ {
118
+ tag: 'membership_requests_action',
119
+ attrs: {},
120
+ content: [
121
+ {
122
+ tag: action,
123
+ attrs: {},
124
+ content: participants.map(jid => ({
125
+ tag: 'participant',
126
+ attrs: { jid }
127
+ }))
128
+ }
129
+ ]
130
+ }
131
+ ]);
132
+ const node = getBinaryNodeChild(result, 'membership_requests_action');
133
+ const nodeAction = getBinaryNodeChild(node, action);
134
+ const participantsAffected = getBinaryNodeChildren(nodeAction, 'participant');
135
+ return participantsAffected.map(p => {
136
+ return { status: p.attrs.error || '200', jid: p.attrs.jid };
137
+ });
138
+ },
139
+ groupParticipantsUpdate: async (jid, participants, action) => {
140
+ const result = await groupQuery(jid, 'set', [
141
+ {
142
+ tag: action,
143
+ attrs: {},
144
+ content: participants.map(jid => ({
145
+ tag: 'participant',
146
+ attrs: { jid }
147
+ }))
148
+ }
149
+ ]);
150
+ const node = getBinaryNodeChild(result, action);
151
+ const participantsAffected = getBinaryNodeChildren(node, 'participant');
152
+ return participantsAffected.map(p => {
153
+ return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
154
+ });
155
+ },
156
+ groupUpdateDescription: async (jid, description) => {
157
+ const metadata = await groupMetadata(jid);
158
+ const prev = metadata.descId ?? null;
159
+ await groupQuery(jid, 'set', [
160
+ {
161
+ tag: 'description',
162
+ attrs: {
163
+ ...(description ? { id: generateMessageIDV2() } : { delete: 'true' }),
164
+ ...(prev ? { prev } : {})
165
+ },
166
+ content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
167
+ }
168
+ ]);
169
+ },
170
+ groupInviteCode: async (jid) => {
171
+ const result = await groupQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
172
+ const inviteNode = getBinaryNodeChild(result, 'invite');
173
+ return inviteNode?.attrs.code;
174
+ },
175
+ groupRevokeInvite: async (jid) => {
176
+ const result = await groupQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
177
+ const inviteNode = getBinaryNodeChild(result, 'invite');
178
+ return inviteNode?.attrs.code;
179
+ },
180
+ groupAcceptInvite: async (code) => {
181
+ const results = await groupQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
182
+ const result = getBinaryNodeChild(results, 'group');
183
+ return result?.attrs.jid;
184
+ },
185
+ /**
186
+ * revoke a v4 invite for someone
187
+ * @param groupJid group jid
188
+ * @param invitedJid jid of person you invited
189
+ * @returns true if successful
190
+ */
191
+ groupRevokeInviteV4: async (groupJid, invitedJid) => {
192
+ const result = await groupQuery(groupJid, 'set', [
193
+ { tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
194
+ ]);
195
+ return !!result;
196
+ },
197
+ /**
198
+ * accept a GroupInviteMessage
199
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
200
+ * @param inviteMessage the message to accept
201
+ */
202
+ groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
203
+ key = typeof key === 'string' ? { remoteJid: key } : key;
204
+ const results = await groupQuery(inviteMessage.groupJid, 'set', [
205
+ {
206
+ tag: 'accept',
207
+ attrs: {
208
+ code: inviteMessage.inviteCode,
209
+ expiration: inviteMessage.inviteExpiration.toString(),
210
+ admin: key.remoteJid
211
+ }
212
+ }
213
+ ]);
214
+ // if we have the full message key
215
+ // update the invite message to be expired
216
+ if (key.id) {
217
+ // create new invite message that is expired
218
+ inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage);
219
+ inviteMessage.inviteExpiration = 0;
220
+ inviteMessage.inviteCode = '';
221
+ ev.emit('messages.update', [
222
+ {
223
+ key,
224
+ update: {
225
+ message: {
226
+ groupInviteMessage: inviteMessage
227
+ }
228
+ }
229
+ }
230
+ ]);
231
+ }
232
+ // generate the group add message
233
+ await upsertMessage({
234
+ key: {
235
+ remoteJid: inviteMessage.groupJid,
236
+ id: generateMessageIDV2(sock.user?.id),
237
+ fromMe: false,
238
+ participant: key.remoteJid
239
+ },
240
+ messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
241
+ messageStubParameters: [JSON.stringify(authState.creds.me)],
242
+ participant: key.remoteJid,
243
+ messageTimestamp: unixTimestampSeconds()
244
+ }, 'notify');
245
+ return results.attrs.from;
246
+ }),
247
+ groupGetInviteInfo: async (code) => {
248
+ const results = await groupQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
249
+ return extractGroupMetadata(results);
250
+ },
251
+ groupToggleEphemeral: async (jid, ephemeralExpiration) => {
252
+ const content = ephemeralExpiration
253
+ ? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
254
+ : { tag: 'not_ephemeral', attrs: {} };
255
+ await groupQuery(jid, 'set', [content]);
256
+ },
257
+ groupSettingUpdate: async (jid, setting) => {
258
+ await groupQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
259
+ },
260
+ groupMemberAddMode: async (jid, mode) => {
261
+ await groupQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
262
+ },
263
+ groupJoinApprovalMode: async (jid, mode) => {
264
+ await groupQuery(jid, 'set', [
265
+ { tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }
266
+ ]);
267
+ },
268
+ groupFetchAllParticipating
269
+ };
270
+ };
271
+ export const extractGroupMetadata = (result) => {
272
+ const group = getBinaryNodeChild(result, 'group');
273
+ const descChild = getBinaryNodeChild(group, 'description');
274
+ let desc;
275
+ let descId;
276
+ let descOwner;
277
+ let descOwnerPn;
278
+ let descTime;
279
+ if (descChild) {
280
+ desc = getBinaryNodeChildString(descChild, 'body');
281
+ descOwner = descChild.attrs.participant ? jidNormalizedUser(descChild.attrs.participant) : undefined;
282
+ descOwnerPn = descChild.attrs.participant_pn ? jidNormalizedUser(descChild.attrs.participant_pn) : undefined;
283
+ descTime = +descChild.attrs.t;
284
+ descId = descChild.attrs.id;
285
+ }
286
+ const groupId = group.attrs.id.includes('@') ? group.attrs.id : jidEncode(group.attrs.id, 'g.us');
287
+ const eph = getBinaryNodeChild(group, 'ephemeral')?.attrs.expiration;
288
+ const memberAddMode = getBinaryNodeChildString(group, 'member_add_mode') === 'all_member_add';
289
+ const metadata = {
290
+ id: groupId,
291
+ notify: group.attrs.notify,
292
+ addressingMode: group.attrs.addressing_mode === 'lid' ? WAMessageAddressingMode.LID : WAMessageAddressingMode.PN,
293
+ subject: group.attrs.subject,
294
+ subjectOwner: group.attrs.s_o,
295
+ subjectOwnerPn: group.attrs.s_o_pn,
296
+ subjectTime: +group.attrs.s_t,
297
+ size: group.attrs.size ? +group.attrs.size : getBinaryNodeChildren(group, 'participant').length,
298
+ creation: +group.attrs.creation,
299
+ owner: group.attrs.creator ? jidNormalizedUser(group.attrs.creator) : undefined,
300
+ ownerPn: group.attrs.creator_pn ? jidNormalizedUser(group.attrs.creator_pn) : undefined,
301
+ owner_country_code: group.attrs.creator_country_code,
302
+ desc,
303
+ descId,
304
+ descOwner,
305
+ descOwnerPn,
306
+ descTime,
307
+ linkedParent: getBinaryNodeChild(group, 'linked_parent')?.attrs.jid || undefined,
308
+ restrict: !!getBinaryNodeChild(group, 'locked'),
309
+ announce: !!getBinaryNodeChild(group, 'announcement'),
310
+ isCommunity: !!getBinaryNodeChild(group, 'parent'),
311
+ isCommunityAnnounce: !!getBinaryNodeChild(group, 'default_sub_group'),
312
+ joinApprovalMode: !!getBinaryNodeChild(group, 'membership_approval_mode'),
313
+ memberAddMode,
314
+ participants: getBinaryNodeChildren(group, 'participant').map(({ attrs }) => {
315
+ // TODO: Store LID MAPPINGS
316
+ return {
317
+ id: attrs.jid,
318
+ phoneNumber: isLidUser(attrs.jid) && isPnUser(attrs.phone_number) ? attrs.phone_number : undefined,
319
+ lid: isPnUser(attrs.jid) && isLidUser(attrs.lid) ? attrs.lid : undefined,
320
+ admin: (attrs.type || null)
321
+ };
322
+ }),
323
+ ephemeralDuration: eph ? +eph : undefined
324
+ };
325
+ return metadata;
326
+ };
327
+ //# sourceMappingURL=groups.js.map