libzapitu 1.0.0-alpha.3

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 (183) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1294 -0
  3. package/WAProto/GenerateStatics.sh +2 -0
  4. package/WAProto/WAProto.proto +4633 -0
  5. package/WAProto/index.d.ts +53473 -0
  6. package/WAProto/index.js +165029 -0
  7. package/engine-requirements.js +10 -0
  8. package/lib/Defaults/baileys-version.json +3 -0
  9. package/lib/Defaults/index.d.ts +51 -0
  10. package/lib/Defaults/index.js +105 -0
  11. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  12. package/lib/Signal/Group/ciphertext-message.js +15 -0
  13. package/lib/Signal/Group/group-session-builder.d.ts +14 -0
  14. package/lib/Signal/Group/group-session-builder.js +64 -0
  15. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  16. package/lib/Signal/Group/group_cipher.js +96 -0
  17. package/lib/Signal/Group/index.d.ts +11 -0
  18. package/lib/Signal/Group/index.js +57 -0
  19. package/lib/Signal/Group/keyhelper.d.ts +10 -0
  20. package/lib/Signal/Group/keyhelper.js +55 -0
  21. package/lib/Signal/Group/queue-job.d.ts +1 -0
  22. package/lib/Signal/Group/queue-job.js +57 -0
  23. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  24. package/lib/Signal/Group/sender-chain-key.js +34 -0
  25. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  26. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  27. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  28. package/lib/Signal/Group/sender-key-message.js +69 -0
  29. package/lib/Signal/Group/sender-key-name.d.ts +17 -0
  30. package/lib/Signal/Group/sender-key-name.js +51 -0
  31. package/lib/Signal/Group/sender-key-record.d.ts +30 -0
  32. package/lib/Signal/Group/sender-key-record.js +53 -0
  33. package/lib/Signal/Group/sender-key-state.d.ts +38 -0
  34. package/lib/Signal/Group/sender-key-state.js +99 -0
  35. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  36. package/lib/Signal/Group/sender-message-key.js +29 -0
  37. package/lib/Signal/libsignal.d.ts +3 -0
  38. package/lib/Signal/libsignal.js +174 -0
  39. package/lib/Socket/Client/index.d.ts +2 -0
  40. package/lib/Socket/Client/index.js +18 -0
  41. package/lib/Socket/Client/types.d.ts +15 -0
  42. package/lib/Socket/Client/types.js +13 -0
  43. package/lib/Socket/Client/websocket.d.ts +12 -0
  44. package/lib/Socket/Client/websocket.js +62 -0
  45. package/lib/Socket/business.d.ts +153 -0
  46. package/lib/Socket/business.js +260 -0
  47. package/lib/Socket/chats.d.ts +90 -0
  48. package/lib/Socket/chats.js +898 -0
  49. package/lib/Socket/groups.d.ts +132 -0
  50. package/lib/Socket/groups.js +331 -0
  51. package/lib/Socket/index.d.ts +153 -0
  52. package/lib/Socket/index.js +10 -0
  53. package/lib/Socket/messages-recv.d.ts +142 -0
  54. package/lib/Socket/messages-recv.js +1089 -0
  55. package/lib/Socket/messages-send.d.ts +137 -0
  56. package/lib/Socket/messages-send.js +818 -0
  57. package/lib/Socket/mex.d.ts +2 -0
  58. package/lib/Socket/mex.js +46 -0
  59. package/lib/Socket/newsletter.d.ts +143 -0
  60. package/lib/Socket/newsletter.js +183 -0
  61. package/lib/Socket/socket.d.ts +42 -0
  62. package/lib/Socket/socket.js +616 -0
  63. package/lib/Socket/usync.d.ts +36 -0
  64. package/lib/Socket/usync.js +65 -0
  65. package/lib/Types/Auth.d.ts +103 -0
  66. package/lib/Types/Auth.js +2 -0
  67. package/lib/Types/Call.d.ts +13 -0
  68. package/lib/Types/Call.js +2 -0
  69. package/lib/Types/Chat.d.ts +115 -0
  70. package/lib/Types/Chat.js +10 -0
  71. package/lib/Types/Contact.d.ts +23 -0
  72. package/lib/Types/Contact.js +2 -0
  73. package/lib/Types/Events.d.ts +198 -0
  74. package/lib/Types/Events.js +2 -0
  75. package/lib/Types/GroupMetadata.d.ts +63 -0
  76. package/lib/Types/GroupMetadata.js +2 -0
  77. package/lib/Types/Label.d.ts +46 -0
  78. package/lib/Types/Label.js +27 -0
  79. package/lib/Types/LabelAssociation.d.ts +29 -0
  80. package/lib/Types/LabelAssociation.js +9 -0
  81. package/lib/Types/Message.d.ts +279 -0
  82. package/lib/Types/Message.js +7 -0
  83. package/lib/Types/Newsletter.d.ts +134 -0
  84. package/lib/Types/Newsletter.js +33 -0
  85. package/lib/Types/Product.d.ts +78 -0
  86. package/lib/Types/Product.js +2 -0
  87. package/lib/Types/Signal.d.ts +57 -0
  88. package/lib/Types/Signal.js +2 -0
  89. package/lib/Types/Socket.d.ts +121 -0
  90. package/lib/Types/Socket.js +2 -0
  91. package/lib/Types/State.d.ts +27 -0
  92. package/lib/Types/State.js +2 -0
  93. package/lib/Types/USync.d.ts +25 -0
  94. package/lib/Types/USync.js +2 -0
  95. package/lib/Types/index.d.ts +64 -0
  96. package/lib/Types/index.js +42 -0
  97. package/lib/Utils/auth-utils.d.ts +18 -0
  98. package/lib/Utils/auth-utils.js +199 -0
  99. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  100. package/lib/Utils/baileys-event-stream.js +63 -0
  101. package/lib/Utils/business.d.ts +22 -0
  102. package/lib/Utils/business.js +240 -0
  103. package/lib/Utils/chat-utils.d.ts +70 -0
  104. package/lib/Utils/chat-utils.js +753 -0
  105. package/lib/Utils/crypto.d.ts +40 -0
  106. package/lib/Utils/crypto.js +187 -0
  107. package/lib/Utils/decode-wa-message.d.ts +36 -0
  108. package/lib/Utils/decode-wa-message.js +236 -0
  109. package/lib/Utils/event-buffer.d.ts +35 -0
  110. package/lib/Utils/event-buffer.js +516 -0
  111. package/lib/Utils/generics.d.ts +91 -0
  112. package/lib/Utils/generics.js +397 -0
  113. package/lib/Utils/history.d.ts +19 -0
  114. package/lib/Utils/history.js +93 -0
  115. package/lib/Utils/index.d.ts +17 -0
  116. package/lib/Utils/index.js +33 -0
  117. package/lib/Utils/link-preview.d.ts +21 -0
  118. package/lib/Utils/link-preview.js +122 -0
  119. package/lib/Utils/logger.d.ts +11 -0
  120. package/lib/Utils/logger.js +7 -0
  121. package/lib/Utils/lt-hash.d.ts +12 -0
  122. package/lib/Utils/lt-hash.js +51 -0
  123. package/lib/Utils/make-mutex.d.ts +7 -0
  124. package/lib/Utils/make-mutex.js +44 -0
  125. package/lib/Utils/messages-media.d.ts +111 -0
  126. package/lib/Utils/messages-media.js +701 -0
  127. package/lib/Utils/messages.d.ts +76 -0
  128. package/lib/Utils/messages.js +816 -0
  129. package/lib/Utils/noise-handler.d.ts +19 -0
  130. package/lib/Utils/noise-handler.js +150 -0
  131. package/lib/Utils/process-message.d.ts +41 -0
  132. package/lib/Utils/process-message.js +377 -0
  133. package/lib/Utils/signal.d.ts +33 -0
  134. package/lib/Utils/signal.js +159 -0
  135. package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
  136. package/lib/Utils/use-multi-file-auth-state.js +124 -0
  137. package/lib/Utils/validate-connection.d.ts +10 -0
  138. package/lib/Utils/validate-connection.js +170 -0
  139. package/lib/WABinary/constants.d.ts +27 -0
  140. package/lib/WABinary/constants.js +1303 -0
  141. package/lib/WABinary/decode.d.ts +6 -0
  142. package/lib/WABinary/decode.js +266 -0
  143. package/lib/WABinary/encode.d.ts +2 -0
  144. package/lib/WABinary/encode.js +252 -0
  145. package/lib/WABinary/generic-utils.d.ts +14 -0
  146. package/lib/WABinary/generic-utils.js +110 -0
  147. package/lib/WABinary/index.d.ts +5 -0
  148. package/lib/WABinary/index.js +21 -0
  149. package/lib/WABinary/jid-utils.d.ts +36 -0
  150. package/lib/WABinary/jid-utils.js +66 -0
  151. package/lib/WABinary/types.d.ts +18 -0
  152. package/lib/WABinary/types.js +2 -0
  153. package/lib/WAM/BinaryInfo.d.ts +8 -0
  154. package/lib/WAM/BinaryInfo.js +13 -0
  155. package/lib/WAM/constants.d.ts +39 -0
  156. package/lib/WAM/constants.js +15243 -0
  157. package/lib/WAM/encode.d.ts +2 -0
  158. package/lib/WAM/encode.js +153 -0
  159. package/lib/WAM/index.d.ts +3 -0
  160. package/lib/WAM/index.js +19 -0
  161. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  162. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  163. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  164. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  165. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  166. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  167. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  168. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  169. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
  170. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
  171. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
  172. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
  173. package/lib/WAUSync/Protocols/index.d.ts +4 -0
  174. package/lib/WAUSync/Protocols/index.js +20 -0
  175. package/lib/WAUSync/USyncQuery.d.ts +28 -0
  176. package/lib/WAUSync/USyncQuery.js +93 -0
  177. package/lib/WAUSync/USyncUser.d.ts +12 -0
  178. package/lib/WAUSync/USyncUser.js +26 -0
  179. package/lib/WAUSync/index.d.ts +3 -0
  180. package/lib/WAUSync/index.js +19 -0
  181. package/lib/index.d.ts +11 -0
  182. package/lib/index.js +30 -0
  183. package/package.json +102 -0
@@ -0,0 +1,132 @@
1
+ import { proto } from '../../WAProto';
2
+ import { GroupMetadata, ParticipantAction, SocketConfig, WAMessageKey } from '../Types';
3
+ import { BinaryNode } from '../WABinary';
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;
15
+ lid: string;
16
+ }[]>;
17
+ groupParticipantsUpdate: (jid: string, participants: string[], action: ParticipantAction) => Promise<{
18
+ status: string;
19
+ jid: string;
20
+ lid: string;
21
+ content: BinaryNode;
22
+ }[]>;
23
+ groupUpdateDescription: (jid: string, description?: string) => Promise<void>;
24
+ groupInviteCode: (jid: string) => Promise<string | undefined>;
25
+ groupRevokeInvite: (jid: string) => Promise<string | undefined>;
26
+ groupAcceptInvite: (code: string) => Promise<string | undefined>;
27
+ /**
28
+ * revoke a v4 invite for someone
29
+ * @param groupJid group jid
30
+ * @param invitedJid jid of person you invited
31
+ * @returns true if successful
32
+ */
33
+ groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
34
+ /**
35
+ * accept a GroupInviteMessage
36
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
37
+ * @param inviteMessage the message to accept
38
+ */
39
+ groupAcceptInviteV4: (key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<any>;
40
+ groupGetInviteInfo: (code: string) => Promise<GroupMetadata>;
41
+ groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
42
+ groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
43
+ groupMemberAddMode: (jid: string, mode: "admin_add" | "all_member_add") => Promise<void>;
44
+ groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
45
+ groupFetchAllParticipating: () => Promise<{
46
+ [_: string]: GroupMetadata;
47
+ }>;
48
+ getBotListV2: () => Promise<import("../Types").BotListInfo[]>;
49
+ processingMutex: {
50
+ mutex<T>(code: () => Promise<T> | T): Promise<T>;
51
+ };
52
+ fetchPrivacySettings: (force?: boolean) => Promise<{
53
+ [_: string]: string;
54
+ }>;
55
+ upsertMessage: (msg: import("../Types").WAMessage, type: import("../Types").MessageUpsertType) => Promise<void>;
56
+ appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
57
+ sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string) => Promise<void>;
58
+ presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
59
+ profilePictureUrl: (jid: string, type?: "preview" | "image", timeoutMs?: number) => Promise<string | undefined>;
60
+ onWhatsApp: (...jids: string[]) => Promise<{
61
+ jid: string;
62
+ exists: unknown;
63
+ lid: unknown;
64
+ }[] | undefined>;
65
+ fetchBlocklist: () => Promise<string[]>;
66
+ fetchStatus: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
67
+ fetchDisappearingDuration: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
68
+ updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload, dimensions?: {
69
+ width: number;
70
+ height: number;
71
+ }) => Promise<void>;
72
+ removeProfilePicture: (jid: string) => Promise<void>;
73
+ updateProfileStatus: (status: string) => Promise<void>;
74
+ updateProfileName: (name: string) => Promise<void>;
75
+ updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
76
+ updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
77
+ updateMessagesPrivacy: (value: import("../Types").WAPrivacyMessagesValue) => Promise<void>;
78
+ updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
79
+ updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
80
+ updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
81
+ updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
82
+ updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
83
+ updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
84
+ updateDefaultDisappearingMode: (duration: number) => Promise<void>;
85
+ getBusinessProfile: (jid: string) => Promise<import("../Types").WABusinessProfile | void>;
86
+ resyncAppState: (collections: readonly ("critical_unblock_low" | "regular_high" | "regular_low" | "critical_block" | "regular")[], isInitialSync: boolean) => Promise<void>;
87
+ chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
88
+ cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
89
+ addOrEditContact: (jid: string, contact: proto.SyncActionValue.IContactAction) => Promise<void>;
90
+ removeContact: (jid: string) => Promise<void>;
91
+ addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
92
+ addChatLabel: (jid: string, labelId: string) => Promise<void>;
93
+ removeChatLabel: (jid: string, labelId: string) => Promise<void>;
94
+ addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
95
+ removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
96
+ star: (jid: string, messages: {
97
+ id: string;
98
+ fromMe?: boolean;
99
+ }[], star: boolean) => Promise<void>;
100
+ executeUSyncQuery: (usyncQuery: import("..").USyncQuery) => Promise<import("..").USyncQueryResult | undefined>;
101
+ type: "md";
102
+ ws: import("./Client").WebSocketClient;
103
+ ev: import("../Types").BaileysEventEmitter & {
104
+ process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
105
+ buffer(): void;
106
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
107
+ flush(force?: boolean): boolean;
108
+ isBuffering(): boolean;
109
+ };
110
+ authState: {
111
+ creds: import("../Types").AuthenticationCreds;
112
+ keys: import("../Types").SignalKeyStoreWithTransaction;
113
+ };
114
+ signalRepository: import("../Types").SignalRepository;
115
+ user: import("../Types").Contact | undefined;
116
+ generateMessageTag: () => string;
117
+ query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
118
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
119
+ waitForSocketOpen: () => Promise<void>;
120
+ sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
121
+ sendNode: (frame: BinaryNode) => Promise<void>;
122
+ logout: (msg?: string) => Promise<void>;
123
+ end: (error: Error | undefined) => void;
124
+ onUnexpectedError: (err: Error | import("@hapi/boom").Boom, msg: string) => void;
125
+ uploadPreKeys: (count?: number) => Promise<void>;
126
+ uploadPreKeysToServerIfRequired: () => Promise<void>;
127
+ requestPairingCode: (phoneNumber: string, customPairingCode?: string) => Promise<string>;
128
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
129
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
130
+ };
131
+ export declare const extractGroupMetadata: (result: BinaryNode) => GroupMetadata;
132
+ export type GroupsSocket = ReturnType<typeof makeGroupsSocket>;
@@ -0,0 +1,331 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractGroupMetadata = exports.makeGroupsSocket = void 0;
4
+ const WAProto_1 = require("../../WAProto");
5
+ const Types_1 = require("../Types");
6
+ const Utils_1 = require("../Utils");
7
+ const WABinary_1 = require("../WABinary");
8
+ const chats_1 = require("./chats");
9
+ const makeGroupsSocket = (config) => {
10
+ const sock = (0, chats_1.makeChatsSocket)(config);
11
+ const { authState, ev, query, upsertMessage } = sock;
12
+ const groupQuery = async (jid, type, content) => query({
13
+ tag: 'iq',
14
+ attrs: {
15
+ type,
16
+ xmlns: 'w:g2',
17
+ to: jid
18
+ },
19
+ content
20
+ });
21
+ const groupMetadata = async (jid) => {
22
+ const result = await groupQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
23
+ return (0, exports.extractGroupMetadata)(result);
24
+ };
25
+ const groupFetchAllParticipating = async () => {
26
+ const result = await query({
27
+ tag: 'iq',
28
+ attrs: {
29
+ to: '@g.us',
30
+ xmlns: 'w:g2',
31
+ type: 'get'
32
+ },
33
+ content: [
34
+ {
35
+ tag: 'participating',
36
+ attrs: {},
37
+ content: [
38
+ { tag: 'participants', attrs: {} },
39
+ { tag: 'description', attrs: {} }
40
+ ]
41
+ }
42
+ ]
43
+ });
44
+ const data = {};
45
+ const groupsChild = (0, WABinary_1.getBinaryNodeChild)(result, 'groups');
46
+ if (groupsChild) {
47
+ const groups = (0, WABinary_1.getBinaryNodeChildren)(groupsChild, 'group');
48
+ for (const groupNode of groups) {
49
+ const meta = (0, exports.extractGroupMetadata)({
50
+ tag: 'result',
51
+ attrs: {},
52
+ content: [groupNode]
53
+ });
54
+ data[meta.id] = meta;
55
+ }
56
+ }
57
+ sock.ev.emit('groups.update', Object.values(data));
58
+ return data;
59
+ };
60
+ sock.ws.on('CB:ib,,dirty', async (node) => {
61
+ const { attrs } = (0, WABinary_1.getBinaryNodeChild)(node, 'dirty');
62
+ if (attrs.type !== 'groups') {
63
+ return;
64
+ }
65
+ await groupFetchAllParticipating();
66
+ await sock.cleanDirtyBits('groups');
67
+ });
68
+ return {
69
+ ...sock,
70
+ groupMetadata,
71
+ groupCreate: async (subject, participants) => {
72
+ const key = (0, Utils_1.generateMessageIDV2)();
73
+ const result = await groupQuery('@g.us', 'set', [
74
+ {
75
+ tag: 'create',
76
+ attrs: {
77
+ subject,
78
+ key
79
+ },
80
+ content: participants.map(jid => ({
81
+ tag: 'participant',
82
+ attrs: { jid }
83
+ }))
84
+ }
85
+ ]);
86
+ return (0, exports.extractGroupMetadata)(result);
87
+ },
88
+ groupLeave: async (id) => {
89
+ await groupQuery('@g.us', 'set', [
90
+ {
91
+ tag: 'leave',
92
+ attrs: {},
93
+ content: [{ tag: 'group', attrs: { id } }]
94
+ }
95
+ ]);
96
+ },
97
+ groupUpdateSubject: async (jid, subject) => {
98
+ await groupQuery(jid, 'set', [
99
+ {
100
+ tag: 'subject',
101
+ attrs: {},
102
+ content: Buffer.from(subject, 'utf-8')
103
+ }
104
+ ]);
105
+ },
106
+ groupRequestParticipantsList: async (jid) => {
107
+ const result = await groupQuery(jid, 'get', [
108
+ {
109
+ tag: 'membership_approval_requests',
110
+ attrs: {}
111
+ }
112
+ ]);
113
+ const node = (0, WABinary_1.getBinaryNodeChild)(result, 'membership_approval_requests');
114
+ const participants = (0, WABinary_1.getBinaryNodeChildren)(node, 'membership_approval_request');
115
+ return participants.map(v => v.attrs);
116
+ },
117
+ groupRequestParticipantsUpdate: async (jid, participants, action) => {
118
+ const result = await groupQuery(jid, 'set', [
119
+ {
120
+ tag: 'membership_requests_action',
121
+ attrs: {},
122
+ content: [
123
+ {
124
+ tag: action,
125
+ attrs: {},
126
+ content: participants.map(jid => ({
127
+ tag: 'participant',
128
+ attrs: { jid }
129
+ }))
130
+ }
131
+ ]
132
+ }
133
+ ]);
134
+ const node = (0, WABinary_1.getBinaryNodeChild)(result, 'membership_requests_action');
135
+ const nodeAction = (0, WABinary_1.getBinaryNodeChild)(node, action);
136
+ const participantsAffected = (0, WABinary_1.getBinaryNodeChildren)(nodeAction, 'participant');
137
+ return participantsAffected.map(p => {
138
+ return { status: p.attrs.error || '200', jid: p.attrs.jid, lid: p.attrs.lid };
139
+ });
140
+ },
141
+ groupParticipantsUpdate: async (jid, participants, action) => {
142
+ const result = await groupQuery(jid, 'set', [
143
+ {
144
+ tag: action,
145
+ attrs: {},
146
+ content: participants.map(jid => ({
147
+ tag: 'participant',
148
+ attrs: { jid }
149
+ }))
150
+ }
151
+ ]);
152
+ const node = (0, WABinary_1.getBinaryNodeChild)(result, action);
153
+ const participantsAffected = (0, WABinary_1.getBinaryNodeChildren)(node, 'participant');
154
+ return participantsAffected.map(p => {
155
+ return { status: p.attrs.error || '200', jid: p.attrs.jid, lid: p.attrs.lid, content: p };
156
+ });
157
+ },
158
+ groupUpdateDescription: async (jid, description) => {
159
+ var _a;
160
+ const metadata = await groupMetadata(jid);
161
+ const prev = (_a = metadata.descId) !== null && _a !== void 0 ? _a : null;
162
+ await groupQuery(jid, 'set', [
163
+ {
164
+ tag: 'description',
165
+ attrs: {
166
+ ...(description ? { id: (0, Utils_1.generateMessageIDV2)() } : { delete: 'true' }),
167
+ ...(prev ? { prev } : {})
168
+ },
169
+ content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
170
+ }
171
+ ]);
172
+ },
173
+ groupInviteCode: async (jid) => {
174
+ const result = await groupQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
175
+ const inviteNode = (0, WABinary_1.getBinaryNodeChild)(result, 'invite');
176
+ return inviteNode === null || inviteNode === void 0 ? void 0 : inviteNode.attrs.code;
177
+ },
178
+ groupRevokeInvite: async (jid) => {
179
+ const result = await groupQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
180
+ const inviteNode = (0, WABinary_1.getBinaryNodeChild)(result, 'invite');
181
+ return inviteNode === null || inviteNode === void 0 ? void 0 : inviteNode.attrs.code;
182
+ },
183
+ groupAcceptInvite: async (code) => {
184
+ const results = await groupQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
185
+ const result = (0, WABinary_1.getBinaryNodeChild)(results, 'group');
186
+ return result === null || result === void 0 ? void 0 : result.attrs.jid;
187
+ },
188
+ /**
189
+ * revoke a v4 invite for someone
190
+ * @param groupJid group jid
191
+ * @param invitedJid jid of person you invited
192
+ * @returns true if successful
193
+ */
194
+ groupRevokeInviteV4: async (groupJid, invitedJid) => {
195
+ const result = await groupQuery(groupJid, 'set', [
196
+ { tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
197
+ ]);
198
+ return !!result;
199
+ },
200
+ /**
201
+ * accept a GroupInviteMessage
202
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
203
+ * @param inviteMessage the message to accept
204
+ */
205
+ groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
206
+ var _a;
207
+ key = typeof key === 'string' ? { remoteJid: key } : key;
208
+ const results = await groupQuery(inviteMessage.groupJid, 'set', [
209
+ {
210
+ tag: 'accept',
211
+ attrs: {
212
+ code: inviteMessage.inviteCode,
213
+ expiration: inviteMessage.inviteExpiration.toString(),
214
+ admin: key.remoteJid
215
+ }
216
+ }
217
+ ]);
218
+ // if we have the full message key
219
+ // update the invite message to be expired
220
+ if (key.id) {
221
+ // create new invite message that is expired
222
+ inviteMessage = WAProto_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage);
223
+ inviteMessage.inviteExpiration = 0;
224
+ inviteMessage.inviteCode = '';
225
+ ev.emit('messages.update', [
226
+ {
227
+ key,
228
+ update: {
229
+ message: {
230
+ groupInviteMessage: inviteMessage
231
+ }
232
+ }
233
+ }
234
+ ]);
235
+ }
236
+ // generate the group add message
237
+ await upsertMessage({
238
+ key: {
239
+ remoteJid: inviteMessage.groupJid,
240
+ id: (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id),
241
+ fromMe: false,
242
+ participant: key.remoteJid
243
+ },
244
+ messageStubType: Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD,
245
+ messageStubParameters: [authState.creds.me.id],
246
+ participant: key.remoteJid,
247
+ messageTimestamp: (0, Utils_1.unixTimestampSeconds)()
248
+ }, 'notify');
249
+ return results.attrs.from;
250
+ }),
251
+ groupGetInviteInfo: async (code) => {
252
+ const results = await groupQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
253
+ return (0, exports.extractGroupMetadata)(results);
254
+ },
255
+ groupToggleEphemeral: async (jid, ephemeralExpiration) => {
256
+ const content = ephemeralExpiration
257
+ ? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
258
+ : { tag: 'not_ephemeral', attrs: {} };
259
+ await groupQuery(jid, 'set', [content]);
260
+ },
261
+ groupSettingUpdate: async (jid, setting) => {
262
+ await groupQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
263
+ },
264
+ groupMemberAddMode: async (jid, mode) => {
265
+ await groupQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
266
+ },
267
+ groupJoinApprovalMode: async (jid, mode) => {
268
+ await groupQuery(jid, 'set', [
269
+ { tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }
270
+ ]);
271
+ },
272
+ groupFetchAllParticipating
273
+ };
274
+ };
275
+ exports.makeGroupsSocket = makeGroupsSocket;
276
+ const extractGroupMetadata = (result) => {
277
+ var _a, _b;
278
+ const group = (0, WABinary_1.getBinaryNodeChild)(result, 'group');
279
+ const descChild = (0, WABinary_1.getBinaryNodeChild)(group, 'description');
280
+ let desc;
281
+ let descId;
282
+ let descOwner;
283
+ let descOwnerJid;
284
+ let descTime;
285
+ if (descChild) {
286
+ desc = (0, WABinary_1.getBinaryNodeChildString)(descChild, 'body');
287
+ descOwner = descChild.attrs.participant ? (0, WABinary_1.jidNormalizedUser)(descChild.attrs.participant) : undefined;
288
+ descOwnerJid = descChild.attrs.participant_pn ? (0, WABinary_1.jidNormalizedUser)(descChild.attrs.participant_pn) : undefined;
289
+ descTime = +descChild.attrs.t;
290
+ descId = descChild.attrs.id;
291
+ }
292
+ const groupId = group.attrs.id.includes('@') ? group.attrs.id : (0, WABinary_1.jidEncode)(group.attrs.id, 'g.us');
293
+ const eph = (_a = (0, WABinary_1.getBinaryNodeChild)(group, 'ephemeral')) === null || _a === void 0 ? void 0 : _a.attrs.expiration;
294
+ const memberAddMode = (0, WABinary_1.getBinaryNodeChildString)(group, 'member_add_mode') === 'all_member_add';
295
+ const metadata = {
296
+ id: groupId,
297
+ addressingMode: group.attrs.addressing_mode,
298
+ subject: group.attrs.subject,
299
+ subjectOwner: group.attrs.s_o,
300
+ subjectOwnerJid: group.attrs.s_o_pn,
301
+ subjectTime: +group.attrs.s_t,
302
+ size: (0, WABinary_1.getBinaryNodeChildren)(group, 'participant').length,
303
+ creation: +group.attrs.creation,
304
+ owner: group.attrs.creator ? (0, WABinary_1.jidNormalizedUser)(group.attrs.creator) : undefined,
305
+ ownerJid: group.attrs.creator_pn ? (0, WABinary_1.jidNormalizedUser)(group.attrs.creator_pn) : undefined,
306
+ owner_country_code: group.attrs.creator_country_code,
307
+ desc,
308
+ descId,
309
+ descOwner,
310
+ descOwnerJid,
311
+ descTime,
312
+ linkedParent: ((_b = (0, WABinary_1.getBinaryNodeChild)(group, 'linked_parent')) === null || _b === void 0 ? void 0 : _b.attrs.jid) || undefined,
313
+ restrict: !!(0, WABinary_1.getBinaryNodeChild)(group, 'locked'),
314
+ announce: !!(0, WABinary_1.getBinaryNodeChild)(group, 'announcement'),
315
+ isCommunity: !!(0, WABinary_1.getBinaryNodeChild)(group, 'parent'),
316
+ isCommunityAnnounce: !!(0, WABinary_1.getBinaryNodeChild)(group, 'default_sub_group'),
317
+ joinApprovalMode: !!(0, WABinary_1.getBinaryNodeChild)(group, 'membership_approval_mode'),
318
+ memberAddMode,
319
+ participants: (0, WABinary_1.getBinaryNodeChildren)(group, 'participant').map(({ attrs }) => {
320
+ return {
321
+ id: attrs.jid,
322
+ jid: (0, WABinary_1.isJidUser)(attrs.jid) ? attrs.jid : (0, WABinary_1.jidNormalizedUser)(attrs.phone_number),
323
+ lid: (0, WABinary_1.isLidUser)(attrs.jid) ? attrs.jid : attrs.lid,
324
+ admin: (attrs.type || null)
325
+ };
326
+ }),
327
+ ephemeralDuration: eph ? +eph : undefined
328
+ };
329
+ return metadata;
330
+ };
331
+ exports.extractGroupMetadata = extractGroupMetadata;
@@ -0,0 +1,153 @@
1
+ import { UserFacingSocketConfig } from '../Types';
2
+ declare const makeWASocket: (config: UserFacingSocketConfig) => {
3
+ logger: import("../Utils/logger").ILogger;
4
+ getOrderDetails: (orderId: string, tokenBase64: string) => Promise<import("../Types").OrderDetails>;
5
+ getCatalog: ({ jid, limit, cursor }: import("../Types").GetCatalogOptions) => Promise<{
6
+ products: import("../Types").Product[];
7
+ nextPageCursor: string | undefined;
8
+ }>;
9
+ getCollections: (jid?: string, limit?: number) => Promise<{
10
+ collections: import("../Types").CatalogCollection[];
11
+ }>;
12
+ productCreate: (create: import("../Types").ProductCreate) => Promise<import("../Types").Product>;
13
+ productDelete: (productIds: string[]) => Promise<{
14
+ deleted: number;
15
+ }>;
16
+ productUpdate: (productId: string, update: import("../Types").ProductUpdate) => Promise<import("../Types").Product>;
17
+ sendMessageAck: ({ tag, attrs, content }: import("..").BinaryNode, errorCode?: number) => Promise<void>;
18
+ sendRetryRequest: (node: import("..").BinaryNode, forceIncludeKeys?: boolean) => Promise<void>;
19
+ rejectCall: (callId: string, callFrom: string) => Promise<void>;
20
+ fetchMessageHistory: (count: number, oldestMsgKey: import("../Types").WAMessageKey, oldestMsgTimestamp: number | import("long").default) => Promise<string>;
21
+ requestPlaceholderResend: (messageKey: import("../Types").WAMessageKey) => Promise<string | undefined>;
22
+ getPrivacyTokens: (jids: string[]) => Promise<any>;
23
+ assertSessions: (jids: string[], force: boolean, lids?: string) => Promise<boolean>;
24
+ relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList, isretry }: import("../Types").MessageRelayOptions) => Promise<string>;
25
+ sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
26
+ sendReceipts: (keys: import("../Types").WAMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>;
27
+ readMessages: (keys: import("../Types").WAMessageKey[]) => Promise<void>;
28
+ refreshMediaConn: (forceGet?: boolean) => Promise<import("../Types").MediaConnInfo>;
29
+ waUploadToServer: import("../Types").WAMediaUploadFunction;
30
+ fetchPrivacySettings: (force?: boolean) => Promise<{
31
+ [_: string]: string;
32
+ }>;
33
+ sendPeerDataOperationMessage: (pdoMessage: import("../Types").WAProto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
34
+ createParticipantNodes: (jids: string[], message: import("../Types").WAProto.IMessage, extraAttrs?: import("..").BinaryNode["attrs"], lid?: any, meid?: any, melid?: any) => Promise<{
35
+ nodes: import("..").BinaryNode[];
36
+ shouldIncludeDeviceIdentity: boolean;
37
+ }>;
38
+ getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<import("..").JidWithDevice[]>;
39
+ updateMediaMessage: (message: import("../Types").WAProto.IWebMessageInfo) => Promise<import("../Types").WAProto.IWebMessageInfo>;
40
+ sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<import("../Types").WAProto.WebMessageInfo | undefined>;
41
+ groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
42
+ groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
43
+ groupLeave: (id: string) => Promise<void>;
44
+ groupUpdateSubject: (jid: string, subject: string) => Promise<void>;
45
+ groupRequestParticipantsList: (jid: string) => Promise<{
46
+ [key: string]: string;
47
+ }[]>;
48
+ groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "approve" | "reject") => Promise<{
49
+ status: string;
50
+ jid: string;
51
+ lid: string;
52
+ }[]>;
53
+ groupParticipantsUpdate: (jid: string, participants: string[], action: import("../Types").ParticipantAction) => Promise<{
54
+ status: string;
55
+ jid: string;
56
+ lid: string;
57
+ content: import("..").BinaryNode;
58
+ }[]>;
59
+ groupUpdateDescription: (jid: string, description?: string) => Promise<void>;
60
+ groupInviteCode: (jid: string) => Promise<string | undefined>;
61
+ groupRevokeInvite: (jid: string) => Promise<string | undefined>;
62
+ groupAcceptInvite: (code: string) => Promise<string | undefined>;
63
+ groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
64
+ groupAcceptInviteV4: (key: string | import("../Types").WAMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<any>;
65
+ groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
66
+ groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
67
+ groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
68
+ groupMemberAddMode: (jid: string, mode: "admin_add" | "all_member_add") => Promise<void>;
69
+ groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
70
+ groupFetchAllParticipating: () => Promise<{
71
+ [_: string]: import("../Types").GroupMetadata;
72
+ }>;
73
+ getBotListV2: () => Promise<import("../Types").BotListInfo[]>;
74
+ processingMutex: {
75
+ mutex<T>(code: () => Promise<T> | T): Promise<T>;
76
+ };
77
+ upsertMessage: (msg: import("../Types").WAMessage, type: import("../Types").MessageUpsertType) => Promise<void>;
78
+ appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
79
+ sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string) => Promise<void>;
80
+ presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
81
+ profilePictureUrl: (jid: string, type?: "preview" | "image", timeoutMs?: number) => Promise<string | undefined>;
82
+ onWhatsApp: (...jids: string[]) => Promise<{
83
+ jid: string;
84
+ exists: unknown;
85
+ lid: unknown;
86
+ }[] | undefined>;
87
+ fetchBlocklist: () => Promise<string[]>;
88
+ fetchStatus: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
89
+ fetchDisappearingDuration: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
90
+ updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload, dimensions?: {
91
+ width: number;
92
+ height: number;
93
+ }) => Promise<void>;
94
+ removeProfilePicture: (jid: string) => Promise<void>;
95
+ updateProfileStatus: (status: string) => Promise<void>;
96
+ updateProfileName: (name: string) => Promise<void>;
97
+ updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
98
+ updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
99
+ updateMessagesPrivacy: (value: import("../Types").WAPrivacyMessagesValue) => Promise<void>;
100
+ updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
101
+ updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
102
+ updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
103
+ updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
104
+ updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
105
+ updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
106
+ updateDefaultDisappearingMode: (duration: number) => Promise<void>;
107
+ getBusinessProfile: (jid: string) => Promise<import("../Types").WABusinessProfile | void>;
108
+ resyncAppState: (collections: readonly ("critical_unblock_low" | "regular_high" | "regular_low" | "critical_block" | "regular")[], isInitialSync: boolean) => Promise<void>;
109
+ chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
110
+ cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
111
+ addOrEditContact: (jid: string, contact: import("../Types").WAProto.SyncActionValue.IContactAction) => Promise<void>;
112
+ removeContact: (jid: string) => Promise<void>;
113
+ addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
114
+ addChatLabel: (jid: string, labelId: string) => Promise<void>;
115
+ removeChatLabel: (jid: string, labelId: string) => Promise<void>;
116
+ addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
117
+ removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
118
+ star: (jid: string, messages: {
119
+ id: string;
120
+ fromMe?: boolean;
121
+ }[], star: boolean) => Promise<void>;
122
+ executeUSyncQuery: (usyncQuery: import("..").USyncQuery) => Promise<import("..").USyncQueryResult | undefined>;
123
+ type: "md";
124
+ ws: import("./Client").WebSocketClient;
125
+ ev: import("../Types").BaileysEventEmitter & {
126
+ process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
127
+ buffer(): void;
128
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
129
+ flush(force?: boolean): boolean;
130
+ isBuffering(): boolean;
131
+ };
132
+ authState: {
133
+ creds: import("../Types").AuthenticationCreds;
134
+ keys: import("../Types").SignalKeyStoreWithTransaction;
135
+ };
136
+ signalRepository: import("../Types").SignalRepository;
137
+ user: import("../Types").Contact | undefined;
138
+ generateMessageTag: () => string;
139
+ query: (node: import("..").BinaryNode, timeoutMs?: number) => Promise<any>;
140
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
141
+ waitForSocketOpen: () => Promise<void>;
142
+ sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
143
+ sendNode: (frame: import("..").BinaryNode) => Promise<void>;
144
+ logout: (msg?: string) => Promise<void>;
145
+ end: (error: Error | undefined) => void;
146
+ onUnexpectedError: (err: Error | import("@hapi/boom").Boom, msg: string) => void;
147
+ uploadPreKeys: (count?: number) => Promise<void>;
148
+ uploadPreKeysToServerIfRequired: () => Promise<void>;
149
+ requestPairingCode: (phoneNumber: string, customPairingCode?: string) => Promise<string>;
150
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
151
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
152
+ };
153
+ export default makeWASocket;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const Defaults_1 = require("../Defaults");
4
+ const business_1 = require("./business");
5
+ // export the last socket layer
6
+ const makeWASocket = (config) => (0, business_1.makeBusinessSocket)({
7
+ ...Defaults_1.DEFAULT_CONNECTION_CONFIG,
8
+ ...config
9
+ });
10
+ exports.default = makeWASocket;