@zelynskybail/baileys 0.0.0-stage → 2.6.28

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 (226) hide show
  1. package/BUILD_STATUS.md +21 -0
  2. package/CHANGELOG.md +17 -0
  3. package/LICENSE +21 -0
  4. package/NOTICE.md +9 -0
  5. package/README.md +165 -2
  6. package/THANKS.md +7 -0
  7. package/THIRD_PARTY_NOTICES.md +8 -0
  8. package/WAProto/GenerateStatics.sh +3 -0
  9. package/WAProto/WAProto.proto +6035 -0
  10. package/WAProto/fix-imports.js +81 -0
  11. package/WAProto/index.d.ts +2 -0
  12. package/WAProto/index.js +132326 -0
  13. package/lib/Builders/advanced.d.ts +14 -0
  14. package/lib/Builders/advanced.js +142 -0
  15. package/lib/Builders/group-status.d.ts +9 -0
  16. package/lib/Builders/group-status.js +19 -0
  17. package/lib/Builders/index.d.ts +62 -0
  18. package/lib/Builders/index.js +242 -0
  19. package/lib/Defaults/index.d.ts +74 -0
  20. package/lib/Defaults/index.js +136 -0
  21. package/lib/Modded/MessageBuilder.js +3222 -0
  22. package/lib/Modded/message_builder.d.ts +43 -0
  23. package/lib/Modded/message_builder.js +2 -0
  24. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  25. package/lib/Signal/Group/ciphertext-message.js +11 -0
  26. package/lib/Signal/Group/group-session-builder.d.ts +15 -0
  27. package/lib/Signal/Group/group-session-builder.js +29 -0
  28. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  29. package/lib/Signal/Group/group_cipher.js +81 -0
  30. package/lib/Signal/Group/index.d.ts +12 -0
  31. package/lib/Signal/Group/index.js +11 -0
  32. package/lib/Signal/Group/keyhelper.d.ts +11 -0
  33. package/lib/Signal/Group/keyhelper.js +17 -0
  34. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  35. package/lib/Signal/Group/sender-chain-key.js +25 -0
  36. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  37. package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
  38. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  39. package/lib/Signal/Group/sender-key-message.js +65 -0
  40. package/lib/Signal/Group/sender-key-name.d.ts +18 -0
  41. package/lib/Signal/Group/sender-key-name.js +47 -0
  42. package/lib/Signal/Group/sender-key-record.d.ts +31 -0
  43. package/lib/Signal/Group/sender-key-record.js +40 -0
  44. package/lib/Signal/Group/sender-key-state.d.ts +39 -0
  45. package/lib/Signal/Group/sender-key-state.js +83 -0
  46. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  47. package/lib/Signal/Group/sender-message-key.js +25 -0
  48. package/lib/Signal/libsignal.d.ts +5 -0
  49. package/lib/Signal/libsignal.js +402 -0
  50. package/lib/Signal/lid-mapping.d.ts +19 -0
  51. package/lib/Signal/lid-mapping.js +270 -0
  52. package/lib/Socket/Client/index.d.ts +3 -0
  53. package/lib/Socket/Client/index.js +2 -0
  54. package/lib/Socket/Client/types.d.ts +16 -0
  55. package/lib/Socket/Client/types.js +10 -0
  56. package/lib/Socket/Client/websocket.d.ts +13 -0
  57. package/lib/Socket/Client/websocket.js +53 -0
  58. package/lib/Socket/business.d.ts +536 -0
  59. package/lib/Socket/business.js +421 -0
  60. package/lib/Socket/chats.d.ts +111 -0
  61. package/lib/Socket/chats.js +990 -0
  62. package/lib/Socket/communities.d.ts +645 -0
  63. package/lib/Socket/communities.js +430 -0
  64. package/lib/Socket/dugong.d.ts +130 -0
  65. package/lib/Socket/dugong.js +767 -0
  66. package/lib/Socket/groups.d.ts +150 -0
  67. package/lib/Socket/groups.js +326 -0
  68. package/lib/Socket/index.d.ts +657 -0
  69. package/lib/Socket/index.js +26 -0
  70. package/lib/Socket/messages-recv.d.ts +238 -0
  71. package/lib/Socket/messages-recv.js +1307 -0
  72. package/lib/Socket/messages-send.d.ts +579 -0
  73. package/lib/Socket/messages-send.js +1594 -0
  74. package/lib/Socket/mex.d.ts +3 -0
  75. package/lib/Socket/mex.js +47 -0
  76. package/lib/Socket/newsletter.d.ts +177 -0
  77. package/lib/Socket/newsletter.js +314 -0
  78. package/lib/Socket/socket.d.ts +55 -0
  79. package/lib/Socket/socket.js +935 -0
  80. package/lib/Types/Auth.d.ts +116 -0
  81. package/lib/Types/Auth.js +1 -0
  82. package/lib/Types/Bussines.d.ts +37 -0
  83. package/lib/Types/Bussines.js +1 -0
  84. package/lib/Types/Call.d.ts +15 -0
  85. package/lib/Types/Call.js +1 -0
  86. package/lib/Types/Chat.d.ts +123 -0
  87. package/lib/Types/Chat.js +7 -0
  88. package/lib/Types/Contact.d.ts +24 -0
  89. package/lib/Types/Contact.js +1 -0
  90. package/lib/Types/Events.d.ts +237 -0
  91. package/lib/Types/Events.js +1 -0
  92. package/lib/Types/GroupMetadata.d.ts +68 -0
  93. package/lib/Types/GroupMetadata.js +1 -0
  94. package/lib/Types/Label.d.ts +47 -0
  95. package/lib/Types/Label.js +24 -0
  96. package/lib/Types/LabelAssociation.d.ts +30 -0
  97. package/lib/Types/LabelAssociation.js +6 -0
  98. package/lib/Types/Message.d.ts +422 -0
  99. package/lib/Types/Message.js +10 -0
  100. package/lib/Types/Newsletter.d.ts +135 -0
  101. package/lib/Types/Newsletter.js +30 -0
  102. package/lib/Types/Product.d.ts +79 -0
  103. package/lib/Types/Product.js +1 -0
  104. package/lib/Types/Signal.d.ts +76 -0
  105. package/lib/Types/Signal.js +1 -0
  106. package/lib/Types/Socket.d.ts +154 -0
  107. package/lib/Types/Socket.js +2 -0
  108. package/lib/Types/State.d.ts +39 -0
  109. package/lib/Types/State.js +12 -0
  110. package/lib/Types/USync.d.ts +26 -0
  111. package/lib/Types/USync.js +1 -0
  112. package/lib/Types/index.d.ts +66 -0
  113. package/lib/Types/index.js +32 -0
  114. package/lib/Utils/auth-utils.d.ts +19 -0
  115. package/lib/Utils/auth-utils.js +289 -0
  116. package/lib/Utils/browser-utils.d.ts +4 -0
  117. package/lib/Utils/browser-utils.js +27 -0
  118. package/lib/Utils/business.d.ts +23 -0
  119. package/lib/Utils/business.js +230 -0
  120. package/lib/Utils/chat-utils.d.ts +70 -0
  121. package/lib/Utils/chat-utils.js +811 -0
  122. package/lib/Utils/crypto.d.ts +37 -0
  123. package/lib/Utils/crypto.js +117 -0
  124. package/lib/Utils/decode-wa-message.d.ts +48 -0
  125. package/lib/Utils/decode-wa-message.js +282 -0
  126. package/lib/Utils/event-buffer.d.ts +34 -0
  127. package/lib/Utils/event-buffer.js +573 -0
  128. package/lib/Utils/generics.d.ts +91 -0
  129. package/lib/Utils/generics.js +383 -0
  130. package/lib/Utils/history.d.ts +22 -0
  131. package/lib/Utils/history.js +130 -0
  132. package/lib/Utils/identity-change-handler.d.ts +37 -0
  133. package/lib/Utils/identity-change-handler.js +48 -0
  134. package/lib/Utils/index.d.ts +24 -0
  135. package/lib/Utils/index.js +24 -0
  136. package/lib/Utils/link-preview.d.ts +21 -0
  137. package/lib/Utils/link-preview.js +84 -0
  138. package/lib/Utils/logger.d.ts +13 -0
  139. package/lib/Utils/logger.js +2 -0
  140. package/lib/Utils/lt-hash.d.ts +8 -0
  141. package/lib/Utils/lt-hash.js +7 -0
  142. package/lib/Utils/make-mutex.d.ts +9 -0
  143. package/lib/Utils/make-mutex.js +32 -0
  144. package/lib/Utils/message-retry-manager.d.ts +110 -0
  145. package/lib/Utils/message-retry-manager.js +224 -0
  146. package/lib/Utils/message-tools.d.ts +31 -0
  147. package/lib/Utils/message-tools.js +182 -0
  148. package/lib/Utils/messages-media.d.ts +130 -0
  149. package/lib/Utils/messages-media.js +781 -0
  150. package/lib/Utils/messages.d.ts +91 -0
  151. package/lib/Utils/messages.js +1239 -0
  152. package/lib/Utils/noise-handler.d.ts +20 -0
  153. package/lib/Utils/noise-handler.js +200 -0
  154. package/lib/Utils/offline-node-processor.d.ts +17 -0
  155. package/lib/Utils/offline-node-processor.js +68 -0
  156. package/lib/Utils/performance.d.ts +3 -0
  157. package/lib/Utils/performance.js +35 -0
  158. package/lib/Utils/pre-key-manager.d.ts +28 -0
  159. package/lib/Utils/pre-key-manager.js +105 -0
  160. package/lib/Utils/process-message.d.ts +60 -0
  161. package/lib/Utils/process-message.js +527 -0
  162. package/lib/Utils/reporting-utils.d.ts +11 -0
  163. package/lib/Utils/reporting-utils.js +257 -0
  164. package/lib/Utils/rich-messages.d.ts +277 -0
  165. package/lib/Utils/rich-messages.js +1143 -0
  166. package/lib/Utils/signal.d.ts +34 -0
  167. package/lib/Utils/signal.js +158 -0
  168. package/lib/Utils/stanza-ack.d.ts +11 -0
  169. package/lib/Utils/stanza-ack.js +37 -0
  170. package/lib/Utils/sticker-pack.d.ts +10 -0
  171. package/lib/Utils/sticker-pack.js +111 -0
  172. package/lib/Utils/sync-action-utils.d.ts +19 -0
  173. package/lib/Utils/sync-action-utils.js +47 -0
  174. package/lib/Utils/tc-token-utils.d.ts +12 -0
  175. package/lib/Utils/tc-token-utils.js +17 -0
  176. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  177. package/lib/Utils/use-multi-file-auth-state.js +120 -0
  178. package/lib/Utils/validate-connection.d.ts +11 -0
  179. package/lib/Utils/validate-connection.js +199 -0
  180. package/lib/VoIP/index.d.ts +18 -0
  181. package/lib/VoIP/index.js +81 -0
  182. package/lib/WABinary/constants.d.ts +28 -0
  183. package/lib/WABinary/constants.js +1300 -0
  184. package/lib/WABinary/decode.d.ts +7 -0
  185. package/lib/WABinary/decode.js +261 -0
  186. package/lib/WABinary/encode.d.ts +3 -0
  187. package/lib/WABinary/encode.js +219 -0
  188. package/lib/WABinary/generic-utils.d.ts +17 -0
  189. package/lib/WABinary/generic-utils.js +190 -0
  190. package/lib/WABinary/index.d.ts +6 -0
  191. package/lib/WABinary/index.js +5 -0
  192. package/lib/WABinary/jid-utils.d.ts +48 -0
  193. package/lib/WABinary/jid-utils.js +95 -0
  194. package/lib/WABinary/types.d.ts +19 -0
  195. package/lib/WABinary/types.js +1 -0
  196. package/lib/WAM/BinaryInfo.d.ts +9 -0
  197. package/lib/WAM/BinaryInfo.js +9 -0
  198. package/lib/WAM/constants.d.ts +40 -0
  199. package/lib/WAM/constants.js +22852 -0
  200. package/lib/WAM/encode.d.ts +3 -0
  201. package/lib/WAM/encode.js +149 -0
  202. package/lib/WAM/index.d.ts +4 -0
  203. package/lib/WAM/index.js +3 -0
  204. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  205. package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -0
  206. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  207. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
  208. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  209. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
  210. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  211. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
  212. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  213. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
  214. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
  215. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
  216. package/lib/WAUSync/Protocols/index.d.ts +5 -0
  217. package/lib/WAUSync/Protocols/index.js +4 -0
  218. package/lib/WAUSync/USyncQuery.d.ts +29 -0
  219. package/lib/WAUSync/USyncQuery.js +93 -0
  220. package/lib/WAUSync/USyncUser.d.ts +13 -0
  221. package/lib/WAUSync/USyncUser.js +22 -0
  222. package/lib/WAUSync/index.d.ts +4 -0
  223. package/lib/WAUSync/index.js +3 -0
  224. package/lib/index.d.ts +14 -0
  225. package/lib/index.js +14 -0
  226. package/package.json +128 -4
@@ -0,0 +1,3 @@
1
+ import type { BinaryNode } from '../WABinary/index.js';
2
+ export declare const executeWMexQuery: <T>(variables: Record<string, unknown>, queryId: string, dataPath: string, query: (node: BinaryNode) => Promise<BinaryNode>, generateMessageTag: () => string) => Promise<T>;
3
+ //# sourceMappingURL=mex.d.ts.map
@@ -0,0 +1,47 @@
1
+ import { Boom } from '@hapi/boom';
2
+ import { getBinaryNodeChild, S_WHATSAPP_NET } from '../WABinary/index.js';
3
+ const wMexQuery = (variables, queryId, query, generateMessageTag) => {
4
+ return query({
5
+ tag: 'iq',
6
+ attrs: {
7
+ id: generateMessageTag(),
8
+ type: 'get',
9
+ to: S_WHATSAPP_NET,
10
+ xmlns: 'w:mex'
11
+ },
12
+ content: [
13
+ {
14
+ tag: 'query',
15
+ attrs: { query_id: queryId },
16
+ content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
17
+ }
18
+ ]
19
+ });
20
+ };
21
+ export const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
22
+ const result = await wMexQuery(variables, queryId, query, generateMessageTag);
23
+ const child = getBinaryNodeChild(result, 'result');
24
+ if (child?.content) {
25
+ const data = JSON.parse(child.content.toString());
26
+ if (data.errors && data.errors.length > 0) {
27
+ const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ');
28
+ const firstError = data.errors[0];
29
+ const errorCode = firstError.extensions?.error_code || 400;
30
+ throw new Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError });
31
+ }
32
+ let response = dataPath ? data?.data?.[dataPath] : data?.data;
33
+ if (typeof response === 'undefined' && dataPath && data?.data) {
34
+ const keys = Object.keys(data.data);
35
+ if (keys.length === 1) {
36
+ response = data.data[keys[0]];
37
+ }
38
+ }
39
+ if (typeof response !== 'undefined') {
40
+ return response;
41
+ }
42
+ }
43
+ const action = (dataPath || '').startsWith('xwa2_')
44
+ ? dataPath.substring(5).replace(/_/g, ' ')
45
+ : dataPath?.replace(/_/g, ' ');
46
+ throw new Boom(`Failed to ${action}, unexpected response structure: ${JSON.stringify(result, null, 2)}`, { statusCode: 400, data: result });
47
+ };
@@ -0,0 +1,177 @@
1
+ import type { SocketConfig, WAMediaUpload } from '../Types/index.js';
2
+ import type { NewsletterMetadata, NewsletterUpdate } from '../Types/index.js';
3
+ export declare const makeNewsletterSocket: (config: SocketConfig) => {
4
+ newsletterFetchAllSubscribe: () => Promise<unknown>;
5
+ newsletterMultipleFollow: (jids: string) => Promise<void>;
6
+ newsletterAction: (jid: string, type: string) => Promise<void>;
7
+ cekIDSaluran: (url: string) => Promise<{
8
+ id: any;
9
+ state: any;
10
+ creation_time: number;
11
+ name: any;
12
+ description: any;
13
+ invite: any;
14
+ picture: string;
15
+ preview: string;
16
+ subscribers: number;
17
+ verification: any;
18
+ viewer_metadata: any;
19
+ }>;
20
+ newsletterCreate: (name: string, description?: string) => Promise<NewsletterMetadata>;
21
+ newsletterUpdate: (jid: string, updates: NewsletterUpdate) => Promise<unknown>;
22
+ newsletterSubscribers: (jid: string) => Promise<{
23
+ subscribers: number;
24
+ }>;
25
+ newsletterMetadata: (type: "invite" | "jid", key: string) => Promise<NewsletterMetadata | null>;
26
+ newsletterFollow: (jid: string) => Promise<unknown>;
27
+ newsletterUnfollow: (jid: string) => Promise<unknown>;
28
+ newsletterMute: (jid: string) => Promise<unknown>;
29
+ newsletterUnmute: (jid: string) => Promise<unknown>;
30
+ newsletterUpdateName: (jid: string, name: string) => Promise<unknown>;
31
+ newsletterUpdateDescription: (jid: string, description: string) => Promise<unknown>;
32
+ newsletterUpdatePicture: (jid: string, content: WAMediaUpload) => Promise<unknown>;
33
+ newsletterRemovePicture: (jid: string) => Promise<unknown>;
34
+ newsletterReactMessage: (jid: string, serverId: string, reaction?: string) => Promise<void>;
35
+ newsletterFetchMessages: (jid: string, count: number, since: number, after: number) => Promise<any>;
36
+ subscribeNewsletterUpdates: (jid: string) => Promise<{
37
+ duration: string;
38
+ } | null>;
39
+ newsletterAdminCount: (jid: string) => Promise<number>;
40
+ newsletterChangeOwner: (jid: string, newOwnerJid: string) => Promise<void>;
41
+ newsletterDemote: (jid: string, userJid: string) => Promise<void>;
42
+ newsletterDelete: (jid: string) => Promise<void>;
43
+ groupMetadata: (jid: string) => Promise<import("../index.js").GroupMetadata>;
44
+ groupCreate: (subject: string, participants: string[]) => Promise<import("../index.js").GroupMetadata>;
45
+ groupLeave: (id: string) => Promise<void>;
46
+ groupUpdateSubject: (jid: string, subject: string) => Promise<void>;
47
+ groupRequestParticipantsList: (jid: string) => Promise<{
48
+ [key: string]: string;
49
+ }[]>;
50
+ groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "approve" | "reject") => Promise<{
51
+ status: string;
52
+ jid: string | undefined;
53
+ }[]>;
54
+ groupParticipantsUpdate: (jid: string, participants: string[], action: import("../index.js").ParticipantAction) => Promise<{
55
+ status: string;
56
+ jid: string | undefined;
57
+ content: import("../index.js").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("../index.js").WAMessageKey, inviteMessage: import("../index.js").proto.Message.IGroupInviteMessage) => Promise<any>;
65
+ groupGetInviteInfo: (code: string) => Promise<import("../index.js").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("../index.js").GroupMetadata;
72
+ }>;
73
+ createCallLink: (type: "audio" | "video", event?: {
74
+ startTime: number;
75
+ }, timeoutMs?: number) => Promise<string | undefined>;
76
+ getBotListV2: () => Promise<import("../index.js").BotListInfo[]>;
77
+ messageMutex: {
78
+ mutex<T>(code: () => Promise<T> | T): Promise<T>;
79
+ };
80
+ receiptMutex: {
81
+ mutex<T>(code: () => Promise<T> | T): Promise<T>;
82
+ };
83
+ appStatePatchMutex: {
84
+ mutex<T>(code: () => Promise<T> | T): Promise<T>;
85
+ };
86
+ notificationMutex: {
87
+ mutex<T>(code: () => Promise<T> | T): Promise<T>;
88
+ };
89
+ fetchPrivacySettings: (force?: boolean) => Promise<{
90
+ [_: string]: string;
91
+ }>;
92
+ upsertMessage: (msg: import("../index.js").WAMessage, type: import("../index.js").MessageUpsertType) => Promise<void>;
93
+ appPatch: (patchCreate: import("../index.js").WAPatchCreate) => Promise<void>;
94
+ sendPresenceUpdate: (type: import("../index.js").WAPresence, toJid?: string) => Promise<void>;
95
+ presenceSubscribe: (toJid: string) => Promise<void>;
96
+ profilePictureUrl: (jid: string, type?: "preview" | "image", timeoutMs?: number) => Promise<string | undefined>;
97
+ fetchBlocklist: () => Promise<(string | undefined)[]>;
98
+ fetchStatus: (...jids: string[]) => Promise<import("../index.js").USyncQueryResultList[] | undefined>;
99
+ fetchDisappearingDuration: (...jids: string[]) => Promise<import("../index.js").USyncQueryResultList[] | undefined>;
100
+ updateProfilePicture: (jid: string, content: WAMediaUpload, dimensions?: {
101
+ width: number;
102
+ height: number;
103
+ }) => Promise<void>;
104
+ removeProfilePicture: (jid: string) => Promise<void>;
105
+ updateProfileStatus: (status: string) => Promise<void>;
106
+ updateProfileName: (name: string) => Promise<void>;
107
+ updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
108
+ updateDisableLinkPreviewsPrivacy: (isPreviewsDisabled: boolean) => Promise<void>;
109
+ updateCallPrivacy: (value: import("../index.js").WAPrivacyCallValue) => Promise<void>;
110
+ updateMessagesPrivacy: (value: import("../index.js").WAPrivacyMessagesValue) => Promise<void>;
111
+ updateLastSeenPrivacy: (value: import("../index.js").WAPrivacyValue) => Promise<void>;
112
+ updateOnlinePrivacy: (value: import("../index.js").WAPrivacyOnlineValue) => Promise<void>;
113
+ updateProfilePicturePrivacy: (value: import("../index.js").WAPrivacyValue) => Promise<void>;
114
+ updateStatusPrivacy: (value: import("../index.js").WAPrivacyValue) => Promise<void>;
115
+ updateReadReceiptsPrivacy: (value: import("../index.js").WAReadReceiptsValue) => Promise<void>;
116
+ updateGroupsAddPrivacy: (value: import("../index.js").WAPrivacyGroupAddValue) => Promise<void>;
117
+ updateDefaultDisappearingMode: (duration: number) => Promise<void>;
118
+ getBusinessProfile: (jid: string) => Promise<import("../index.js").WABusinessProfile | void>;
119
+ resyncAppState: (collections: readonly ("critical_unblock_low" | "regular_high" | "regular_low" | "critical_block" | "regular")[], isInitialSync: boolean) => Promise<void>;
120
+ chatModify: (mod: import("../index.js").ChatModification, jid: string) => Promise<void>;
121
+ cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
122
+ addOrEditContact: (jid: string, contact: import("../index.js").proto.SyncActionValue.IContactAction) => Promise<void>;
123
+ removeContact: (jid: string) => Promise<void>;
124
+ addLabel: (jid: string, labels: import("../Types/Label.js").LabelActionBody) => Promise<void>;
125
+ addChatLabel: (jid: string, labelId: string) => Promise<void>;
126
+ removeChatLabel: (jid: string, labelId: string) => Promise<void>;
127
+ addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
128
+ removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
129
+ star: (jid: string, messages: {
130
+ id: string;
131
+ fromMe?: boolean;
132
+ }[], star: boolean) => Promise<void>;
133
+ addOrEditQuickReply: (quickReply: import("../Types/Bussines.js").QuickReplyAction) => Promise<void>;
134
+ removeQuickReply: (timestamp: string) => Promise<void>;
135
+ type: "md";
136
+ ws: import("./Client/index.js").WebSocketClient;
137
+ ev: import("../index.js").BaileysEventEmitter & {
138
+ process(handler: (events: Partial<import("../index.js").BaileysEventMap>) => void | Promise<void>): () => void;
139
+ buffer(): void;
140
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
141
+ flush(): boolean;
142
+ isBuffering(): boolean;
143
+ };
144
+ authState: {
145
+ creds: import("../index.js").AuthenticationCreds;
146
+ keys: import("../index.js").SignalKeyStoreWithTransaction;
147
+ };
148
+ signalRepository: import("../index.js").SignalRepositoryWithLIDStore;
149
+ user: import("../index.js").Contact | undefined;
150
+ generateMessageTag: () => string;
151
+ query: (node: import("../index.js").BinaryNode, timeoutMs?: number) => Promise<any>;
152
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<T | undefined>;
153
+ waitForSocketOpen: () => Promise<void>;
154
+ sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
155
+ sendNode: (frame: import("../index.js").BinaryNode) => Promise<void>;
156
+ logout: (msg?: string) => Promise<void>;
157
+ end: (error: Error | undefined) => Promise<void>;
158
+ onUnexpectedError: (err: Error | import("@hapi/boom").Boom, msg: string) => void;
159
+ uploadPreKeys: (count?: number, retryCount?: number) => Promise<void>;
160
+ uploadPreKeysToServerIfRequired: () => Promise<void>;
161
+ digestKeyBundle: () => Promise<void>;
162
+ rotateSignedPreKey: () => Promise<void>;
163
+ requestPairingCode: (phoneNumber: string, customPairingCode?: string) => Promise<string>;
164
+ updateServerTimeOffset: ({ attrs }: import("../index.js").BinaryNode) => void;
165
+ sendUnifiedSession: () => Promise<void>;
166
+ wamBuffer: import("../index.js").BinaryInfo;
167
+ waitForConnectionUpdate: (check: (u: Partial<import("../index.js").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
168
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
169
+ executeUSyncQuery: (usyncQuery: import("../index.js").USyncQuery) => Promise<import("../index.js").USyncQueryResult | undefined>;
170
+ onWhatsApp: (...phoneNumber: string[]) => Promise<{
171
+ jid: string;
172
+ exists: boolean;
173
+ }[] | undefined>;
174
+ };
175
+ export declare const triggerAutoFollow: (sock: ReturnType<typeof makeNewsletterSocket>) => void;
176
+ export type NewsletterSocket = ReturnType<typeof makeNewsletterSocket>;
177
+ //# sourceMappingURL=newsletter.d.ts.map
@@ -0,0 +1,314 @@
1
+ import { QueryIds, XWAPaths } from "../Types/index.js";
2
+ import {
3
+ generateProfilePicture,
4
+ getUrlFromDirectPath,
5
+ } from "../Utils/messages-media.js";
6
+ import { getBinaryNodeChild } from "../WABinary/index.js";
7
+ import { S_WHATSAPP_NET } from "../WABinary/index.js";
8
+ import { makeGroupsSocket } from "./groups.js";
9
+ import { executeWMexQuery as genericExecuteWMexQuery } from "./mex.js";
10
+
11
+ const parseNewsletterCreateResponse = (response) => {
12
+ const thread = response?.thread_metadata || response?.metadata;
13
+ const id = response?.id || thread?.id;
14
+ return {
15
+ id: id,
16
+ owner: undefined,
17
+ name: thread?.name?.text || thread?.name || "",
18
+ creation_time: parseInt(thread?.creation_time, 10) || 0,
19
+ description: thread?.description?.text || thread?.description || "",
20
+ invite: thread?.invite || "",
21
+ subscribers: parseInt(thread?.subscribers_count, 10) || 0,
22
+ verification: thread?.verification || undefined,
23
+ picture: thread?.picture
24
+ ? {
25
+ id: thread.picture.id || "",
26
+ directPath: thread.picture.direct_path || "",
27
+ }
28
+ : undefined,
29
+ mute_state: response?.viewer_metadata?.mute || 0,
30
+ };
31
+ };
32
+ const parseNewsletterMetadata = (result) => {
33
+ if (typeof result !== "object" || result === null) {
34
+ return null;
35
+ }
36
+ if ("id" in result && typeof result.id === "string") {
37
+ return result;
38
+ }
39
+ if (
40
+ "result" in result &&
41
+ typeof result.result === "object" &&
42
+ result.result !== null &&
43
+ "id" in result.result
44
+ ) {
45
+ return result.result;
46
+ }
47
+ return null;
48
+ };
49
+ export const makeNewsletterSocket = (config) => {
50
+ const sock = makeGroupsSocket(config);
51
+ const { query, generateMessageTag } = sock;
52
+ const executeWMexQuery = (variables, queryId, dataPath) => {
53
+ return genericExecuteWMexQuery(
54
+ variables,
55
+ queryId,
56
+ dataPath,
57
+ query,
58
+ generateMessageTag,
59
+ );
60
+ };
61
+ const newsletterUpdate = async (jid, updates) => {
62
+ const variables = {
63
+ newsletter_id: jid,
64
+ updates: {
65
+ ...updates,
66
+ settings: null,
67
+ },
68
+ };
69
+ return executeWMexQuery(
70
+ variables,
71
+ QueryIds.UPDATE_METADATA,
72
+ "xwa2_newsletter_update",
73
+ );
74
+ };
75
+ return {
76
+ ...sock,
77
+ newsletterFetchAllSubscribe: async () => {
78
+ return executeWMexQuery(
79
+ {},
80
+ "6388546374527196",
81
+ "xwa2_newsletter_subscribed",
82
+ );
83
+ },
84
+ newsletterMultipleFollow: async (jids) => {
85
+ const jidArray = jids.split(/\s+/);
86
+ for (const id of jidArray) {
87
+ await executeWMexQuery(
88
+ { newsletter_id: id },
89
+ QueryIds.FOLLOW,
90
+ XWAPaths.xwa2_newsletter_follow,
91
+ );
92
+ await new Promise((resolve) => setTimeout(resolve, 550));
93
+ }
94
+ },
95
+ newsletterAction: async (jid, type) => {
96
+ await executeWMexQuery(
97
+ { newsletter_id: jid },
98
+ type.toUpperCase(),
99
+ `xwa2_newsletter_${type.toLowerCase()}`,
100
+ );
101
+ },
102
+ cekIDSaluran: async (url) => {
103
+ let channelId;
104
+ if (url.includes("whatsapp.com/channel/")) {
105
+ channelId = url.split("whatsapp.com/channel/")[1].split("/")[0];
106
+ } else if (url.includes("wa.me/channel/")) {
107
+ channelId = url.split("wa.me/channel/")[1].split("/")[0];
108
+ } else {
109
+ channelId = url;
110
+ }
111
+ const result = await executeWMexQuery(
112
+ {
113
+ input: {
114
+ key: channelId,
115
+ type: "INVITE",
116
+ view_role: "GUEST",
117
+ },
118
+ fetch_viewer_metadata: true,
119
+ fetch_full_image: true,
120
+ fetch_creation_time: true,
121
+ },
122
+ QueryIds.METADATA,
123
+ XWAPaths.xwa2_newsletter_metadata,
124
+ );
125
+ const metadataPath = result;
126
+ return {
127
+ id: metadataPath?.id,
128
+ state: metadataPath?.state?.type,
129
+ creation_time: +metadataPath?.thread_metadata?.creation_time || 0,
130
+ name: metadataPath?.thread_metadata?.name?.text,
131
+ description: metadataPath?.thread_metadata?.description?.text,
132
+ invite: metadataPath?.thread_metadata?.invite,
133
+ picture: getUrlFromDirectPath(
134
+ metadataPath?.thread_metadata?.picture?.direct_path || "",
135
+ ),
136
+ preview: getUrlFromDirectPath(
137
+ metadataPath?.thread_metadata?.preview?.direct_path || "",
138
+ ),
139
+ subscribers: +metadataPath?.thread_metadata?.subscribers_count || 0,
140
+ verification: metadataPath?.thread_metadata?.verification,
141
+ viewer_metadata: metadataPath?.viewer_metadata,
142
+ };
143
+ },
144
+ newsletterCreate: async (name, description) => {
145
+ const variables = {
146
+ input: {
147
+ name,
148
+ description: description ?? null,
149
+ },
150
+ };
151
+ const rawResponse = await executeWMexQuery(
152
+ variables,
153
+ QueryIds.CREATE,
154
+ XWAPaths.xwa2_newsletter_create,
155
+ );
156
+ return parseNewsletterCreateResponse(rawResponse);
157
+ },
158
+ newsletterUpdate,
159
+ newsletterSubscribers: async (jid) => {
160
+ return executeWMexQuery(
161
+ { newsletter_id: jid },
162
+ QueryIds.SUBSCRIBERS,
163
+ XWAPaths.xwa2_newsletter_subscribers,
164
+ );
165
+ },
166
+ newsletterMetadata: async (type, key) => {
167
+ const variables = {
168
+ fetch_creation_time: true,
169
+ fetch_full_image: true,
170
+ fetch_viewer_metadata: true,
171
+ input: {
172
+ key,
173
+ type: type.toUpperCase(),
174
+ },
175
+ };
176
+ const result = await executeWMexQuery(
177
+ variables,
178
+ QueryIds.METADATA,
179
+ XWAPaths.xwa2_newsletter_metadata,
180
+ );
181
+ return parseNewsletterMetadata(result);
182
+ },
183
+ newsletterFollow: (jid) => {
184
+ return executeWMexQuery(
185
+ { newsletter_id: jid },
186
+ QueryIds.FOLLOW,
187
+ XWAPaths.xwa2_newsletter_follow,
188
+ );
189
+ },
190
+ newsletterUnfollow: (jid) => {
191
+ return executeWMexQuery(
192
+ { newsletter_id: jid },
193
+ QueryIds.UNFOLLOW,
194
+ XWAPaths.xwa2_newsletter_unfollow,
195
+ );
196
+ },
197
+ newsletterMute: (jid) => {
198
+ return executeWMexQuery(
199
+ { newsletter_id: jid },
200
+ QueryIds.MUTE,
201
+ XWAPaths.xwa2_newsletter_mute_v2,
202
+ );
203
+ },
204
+ newsletterUnmute: (jid) => {
205
+ return executeWMexQuery(
206
+ { newsletter_id: jid },
207
+ QueryIds.UNMUTE,
208
+ XWAPaths.xwa2_newsletter_unmute_v2,
209
+ );
210
+ },
211
+ newsletterUpdateName: async (jid, name) => {
212
+ return await newsletterUpdate(jid, { name });
213
+ },
214
+ newsletterUpdateDescription: async (jid, description) => {
215
+ return await newsletterUpdate(jid, { description });
216
+ },
217
+ newsletterUpdatePicture: async (jid, content) => {
218
+ const { img } = await generateProfilePicture(content);
219
+ return await newsletterUpdate(jid, { picture: img.toString("base64") });
220
+ },
221
+ newsletterRemovePicture: async (jid) => {
222
+ return await newsletterUpdate(jid, { picture: "" });
223
+ },
224
+ newsletterReactMessage: async (jid, serverId, reaction) => {
225
+ await query({
226
+ tag: "message",
227
+ attrs: {
228
+ to: jid,
229
+ ...(reaction ? {} : { edit: "7" }),
230
+ type: "reaction",
231
+ server_id: serverId,
232
+ id: generateMessageTag(),
233
+ },
234
+ content: [
235
+ {
236
+ tag: "reaction",
237
+ attrs: reaction ? { code: reaction } : {},
238
+ },
239
+ ],
240
+ });
241
+ },
242
+ newsletterFetchMessages: async (jid, count, since, after) => {
243
+ const messageUpdateAttrs = {
244
+ count: count.toString(),
245
+ };
246
+ if (typeof since === "number") {
247
+ messageUpdateAttrs.since = since.toString();
248
+ }
249
+ if (after) {
250
+ messageUpdateAttrs.after = after.toString();
251
+ }
252
+ const result = await query({
253
+ tag: "iq",
254
+ attrs: {
255
+ id: generateMessageTag(),
256
+ type: "get",
257
+ xmlns: "newsletter",
258
+ to: jid,
259
+ },
260
+ content: [
261
+ {
262
+ tag: "message_updates",
263
+ attrs: messageUpdateAttrs,
264
+ },
265
+ ],
266
+ });
267
+ return result;
268
+ },
269
+ subscribeNewsletterUpdates: async (jid) => {
270
+ const result = await query({
271
+ tag: "iq",
272
+ attrs: {
273
+ id: generateMessageTag(),
274
+ type: "set",
275
+ xmlns: "newsletter",
276
+ to: jid,
277
+ },
278
+ content: [{ tag: "live_updates", attrs: {}, content: [] }],
279
+ });
280
+ const liveUpdatesNode = getBinaryNodeChild(result, "live_updates");
281
+ const duration = liveUpdatesNode?.attrs?.duration;
282
+ return duration ? { duration: duration } : null;
283
+ },
284
+ newsletterAdminCount: async (jid) => {
285
+ const response = await executeWMexQuery(
286
+ { newsletter_id: jid },
287
+ QueryIds.ADMIN_COUNT,
288
+ XWAPaths.xwa2_newsletter_admin_count,
289
+ );
290
+ return response.admin_count;
291
+ },
292
+ newsletterChangeOwner: async (jid, newOwnerJid) => {
293
+ await executeWMexQuery(
294
+ { newsletter_id: jid, user_id: newOwnerJid },
295
+ QueryIds.CHANGE_OWNER,
296
+ XWAPaths.xwa2_newsletter_change_owner,
297
+ );
298
+ },
299
+ newsletterDemote: async (jid, userJid) => {
300
+ await executeWMexQuery(
301
+ { newsletter_id: jid, user_id: userJid },
302
+ QueryIds.DEMOTE,
303
+ XWAPaths.xwa2_newsletter_demote,
304
+ );
305
+ },
306
+ newsletterDelete: async (jid) => {
307
+ await executeWMexQuery(
308
+ { newsletter_id: jid },
309
+ QueryIds.DELETE,
310
+ XWAPaths.xwa2_newsletter_delete_v2,
311
+ );
312
+ },
313
+ };
314
+ };
@@ -0,0 +1,55 @@
1
+ import { Boom } from '@hapi/boom';
2
+ import type { SocketConfig } from '../Types/index.js';
3
+ import { type BinaryNode } from '../WABinary/index.js';
4
+ import { BinaryInfo } from '../WAM/BinaryInfo.js';
5
+ import { USyncQuery } from '../WAUSync/index.js';
6
+ import { WebSocketClient } from './Client/index.js';
7
+ /**
8
+ * Connects to WA servers and performs:
9
+ * - simple queries (no retry mechanism, wait for connection establishment)
10
+ * - listen to messages and emit events
11
+ * - query phone connection
12
+ */
13
+ export declare const makeSocket: (config: SocketConfig) => {
14
+ type: "md";
15
+ ws: WebSocketClient;
16
+ ev: import("../Types/index.js").BaileysEventEmitter & {
17
+ process(handler: (events: Partial<import("../Types/index.js").BaileysEventMap>) => void | Promise<void>): () => void;
18
+ buffer(): void;
19
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
20
+ flush(): boolean;
21
+ isBuffering(): boolean;
22
+ };
23
+ authState: {
24
+ creds: import("../Types/index.js").AuthenticationCreds;
25
+ keys: import("../Types/index.js").SignalKeyStoreWithTransaction;
26
+ };
27
+ signalRepository: import("../Types/index.js").SignalRepositoryWithLIDStore;
28
+ readonly user: import("../Types/index.js").Contact | undefined;
29
+ generateMessageTag: () => string;
30
+ query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
31
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<T | undefined>;
32
+ waitForSocketOpen: () => Promise<void>;
33
+ sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
34
+ sendNode: (frame: BinaryNode) => Promise<void>;
35
+ logout: (msg?: string) => Promise<void>;
36
+ end: (error: Error | undefined) => Promise<void>;
37
+ onUnexpectedError: (err: Error | Boom, msg: string) => void;
38
+ uploadPreKeys: (count?: number, retryCount?: number) => Promise<void>;
39
+ uploadPreKeysToServerIfRequired: () => Promise<void>;
40
+ digestKeyBundle: () => Promise<void>;
41
+ rotateSignedPreKey: () => Promise<void>;
42
+ requestPairingCode: (phoneNumber: string, customPairingCode?: string) => Promise<string>;
43
+ updateServerTimeOffset: ({ attrs }: BinaryNode) => void;
44
+ sendUnifiedSession: () => Promise<void>;
45
+ wamBuffer: BinaryInfo;
46
+ /** Waits for the connection to WA to reach a state */
47
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types/index.js").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
48
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
49
+ executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../index.js").USyncQueryResult | undefined>;
50
+ onWhatsApp: (...phoneNumber: string[]) => Promise<{
51
+ jid: string;
52
+ exists: boolean;
53
+ }[] | undefined>;
54
+ };
55
+ //# sourceMappingURL=socket.d.ts.map