@xbibzlibrary/whatsbibz 1.3.0

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 (260) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/LICENSE +22 -0
  3. package/LICENSE.upstream +21 -0
  4. package/README.md +280 -0
  5. package/VERIFIKASI-IDENTITAS-2026-09-03.md +138 -0
  6. package/WAProto/GenerateStatics.sh +3 -0
  7. package/WAProto/WAProto.proto +6035 -0
  8. package/WAProto/fix-imports.js +81 -0
  9. package/WAProto/index.d.ts +15314 -0
  10. package/WAProto/index.js +132326 -0
  11. package/assets/logo/README.md +21 -0
  12. package/assets/logo/png/banner-1200x360.png +0 -0
  13. package/assets/logo/png/icon-1024.png +0 -0
  14. package/assets/logo/png/icon-128.png +0 -0
  15. package/assets/logo/png/icon-16.png +0 -0
  16. package/assets/logo/png/icon-24.png +0 -0
  17. package/assets/logo/png/icon-256.png +0 -0
  18. package/assets/logo/png/icon-32.png +0 -0
  19. package/assets/logo/png/icon-48.png +0 -0
  20. package/assets/logo/png/icon-512.png +0 -0
  21. package/assets/logo/png/icon-64.png +0 -0
  22. package/assets/logo/png/mark-512.png +0 -0
  23. package/assets/logo/preview.png +0 -0
  24. package/assets/logo/whatsbibz.ico +0 -0
  25. package/lib/BibzWhats/client.d.ts +95 -0
  26. package/lib/BibzWhats/client.js +501 -0
  27. package/lib/BibzWhats/device-identity.d.ts +60 -0
  28. package/lib/BibzWhats/device-identity.js +234 -0
  29. package/lib/BibzWhats/extract.d.ts +29 -0
  30. package/lib/BibzWhats/extract.js +115 -0
  31. package/lib/BibzWhats/index.d.ts +7 -0
  32. package/lib/BibzWhats/index.js +8 -0
  33. package/lib/BibzWhats/jid.d.ts +22 -0
  34. package/lib/BibzWhats/jid.js +98 -0
  35. package/lib/BibzWhats/pairing.d.ts +35 -0
  36. package/lib/BibzWhats/pairing.js +186 -0
  37. package/lib/BibzWhats/send.d.ts +9 -0
  38. package/lib/BibzWhats/send.js +107 -0
  39. package/lib/BibzWhats/version.d.ts +6 -0
  40. package/lib/BibzWhats/version.js +7 -0
  41. package/lib/Defaults/index.d.ts +73 -0
  42. package/lib/Defaults/index.js +141 -0
  43. package/lib/Modded/message_builder.d.ts +15 -0
  44. package/lib/Modded/message_builder.js +2330 -0
  45. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  46. package/lib/Signal/Group/ciphertext-message.js +11 -0
  47. package/lib/Signal/Group/group-session-builder.d.ts +14 -0
  48. package/lib/Signal/Group/group-session-builder.js +29 -0
  49. package/lib/Signal/Group/group_cipher.d.ts +16 -0
  50. package/lib/Signal/Group/group_cipher.js +81 -0
  51. package/lib/Signal/Group/index.d.ts +11 -0
  52. package/lib/Signal/Group/index.js +11 -0
  53. package/lib/Signal/Group/keyhelper.d.ts +10 -0
  54. package/lib/Signal/Group/keyhelper.js +17 -0
  55. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  56. package/lib/Signal/Group/sender-chain-key.js +25 -0
  57. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  58. package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
  59. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  60. package/lib/Signal/Group/sender-key-message.js +65 -0
  61. package/lib/Signal/Group/sender-key-name.d.ts +17 -0
  62. package/lib/Signal/Group/sender-key-name.js +47 -0
  63. package/lib/Signal/Group/sender-key-record.d.ts +30 -0
  64. package/lib/Signal/Group/sender-key-record.js +40 -0
  65. package/lib/Signal/Group/sender-key-state.d.ts +38 -0
  66. package/lib/Signal/Group/sender-key-state.js +83 -0
  67. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  68. package/lib/Signal/Group/sender-message-key.js +25 -0
  69. package/lib/Signal/libsignal.d.ts +4 -0
  70. package/lib/Signal/libsignal.js +406 -0
  71. package/lib/Signal/lid-mapping.d.ts +18 -0
  72. package/lib/Signal/lid-mapping.js +276 -0
  73. package/lib/Socket/Client/index.d.ts +2 -0
  74. package/lib/Socket/Client/index.js +2 -0
  75. package/lib/Socket/Client/types.d.ts +15 -0
  76. package/lib/Socket/Client/types.js +10 -0
  77. package/lib/Socket/Client/websocket.d.ts +12 -0
  78. package/lib/Socket/Client/websocket.js +53 -0
  79. package/lib/Socket/business.d.ts +537 -0
  80. package/lib/Socket/business.js +421 -0
  81. package/lib/Socket/chats.d.ts +110 -0
  82. package/lib/Socket/chats.js +1006 -0
  83. package/lib/Socket/communities.d.ts +646 -0
  84. package/lib/Socket/communities.js +430 -0
  85. package/lib/Socket/engine.d.ts +129 -0
  86. package/lib/Socket/engine.js +767 -0
  87. package/lib/Socket/groups.d.ts +149 -0
  88. package/lib/Socket/groups.js +326 -0
  89. package/lib/Socket/index.d.ts +637 -0
  90. package/lib/Socket/index.js +14 -0
  91. package/lib/Socket/messages-recv.d.ts +239 -0
  92. package/lib/Socket/messages-recv.js +1307 -0
  93. package/lib/Socket/messages-send.d.ts +580 -0
  94. package/lib/Socket/messages-send.js +1639 -0
  95. package/lib/Socket/mex.d.ts +2 -0
  96. package/lib/Socket/mex.js +47 -0
  97. package/lib/Socket/newsletter.d.ts +176 -0
  98. package/lib/Socket/newsletter.js +456 -0
  99. package/lib/Socket/socket.d.ts +56 -0
  100. package/lib/Socket/socket.js +998 -0
  101. package/lib/Types/Auth.d.ts +115 -0
  102. package/lib/Types/Auth.js +1 -0
  103. package/lib/Types/Bussines.d.ts +36 -0
  104. package/lib/Types/Bussines.js +1 -0
  105. package/lib/Types/Call.d.ts +14 -0
  106. package/lib/Types/Call.js +1 -0
  107. package/lib/Types/Chat.d.ts +124 -0
  108. package/lib/Types/Chat.js +7 -0
  109. package/lib/Types/Contact.d.ts +23 -0
  110. package/lib/Types/Contact.js +1 -0
  111. package/lib/Types/Events.d.ts +241 -0
  112. package/lib/Types/Events.js +1 -0
  113. package/lib/Types/GroupMetadata.d.ts +67 -0
  114. package/lib/Types/GroupMetadata.js +1 -0
  115. package/lib/Types/Label.d.ts +46 -0
  116. package/lib/Types/Label.js +24 -0
  117. package/lib/Types/LabelAssociation.d.ts +29 -0
  118. package/lib/Types/LabelAssociation.js +6 -0
  119. package/lib/Types/Message.d.ts +427 -0
  120. package/lib/Types/Message.js +10 -0
  121. package/lib/Types/Newsletter.d.ts +134 -0
  122. package/lib/Types/Newsletter.js +30 -0
  123. package/lib/Types/Product.d.ts +78 -0
  124. package/lib/Types/Product.js +1 -0
  125. package/lib/Types/Signal.d.ts +77 -0
  126. package/lib/Types/Signal.js +1 -0
  127. package/lib/Types/Socket.d.ts +173 -0
  128. package/lib/Types/Socket.js +2 -0
  129. package/lib/Types/State.d.ts +38 -0
  130. package/lib/Types/State.js +12 -0
  131. package/lib/Types/USync.d.ts +25 -0
  132. package/lib/Types/USync.js +1 -0
  133. package/lib/Types/index.d.ts +75 -0
  134. package/lib/Types/index.js +32 -0
  135. package/lib/Utils/auth-utils.d.ts +18 -0
  136. package/lib/Utils/auth-utils.js +289 -0
  137. package/lib/Utils/browser-utils.d.ts +3 -0
  138. package/lib/Utils/browser-utils.js +47 -0
  139. package/lib/Utils/business.d.ts +22 -0
  140. package/lib/Utils/business.js +230 -0
  141. package/lib/Utils/chat-utils.d.ts +69 -0
  142. package/lib/Utils/chat-utils.js +811 -0
  143. package/lib/Utils/companion-reg-client-utils.d.ts +20 -0
  144. package/lib/Utils/companion-reg-client-utils.js +66 -0
  145. package/lib/Utils/crypto.d.ts +41 -0
  146. package/lib/Utils/crypto.js +117 -0
  147. package/lib/Utils/decode-wa-message.d.ts +47 -0
  148. package/lib/Utils/decode-wa-message.js +282 -0
  149. package/lib/Utils/event-buffer.d.ts +35 -0
  150. package/lib/Utils/event-buffer.js +590 -0
  151. package/lib/Utils/generics.d.ts +90 -0
  152. package/lib/Utils/generics.js +384 -0
  153. package/lib/Utils/history.d.ts +21 -0
  154. package/lib/Utils/history.js +130 -0
  155. package/lib/Utils/identity-change-handler.d.ts +36 -0
  156. package/lib/Utils/identity-change-handler.js +48 -0
  157. package/lib/Utils/index.d.ts +25 -0
  158. package/lib/Utils/index.js +24 -0
  159. package/lib/Utils/link-preview.d.ts +20 -0
  160. package/lib/Utils/link-preview.js +84 -0
  161. package/lib/Utils/logger.d.ts +12 -0
  162. package/lib/Utils/logger.js +2 -0
  163. package/lib/Utils/lt-hash.d.ts +10 -0
  164. package/lib/Utils/lt-hash.js +7 -0
  165. package/lib/Utils/make-mutex.d.ts +8 -0
  166. package/lib/Utils/make-mutex.js +32 -0
  167. package/lib/Utils/message-retry-manager.d.ts +109 -0
  168. package/lib/Utils/message-retry-manager.js +224 -0
  169. package/lib/Utils/messages-media.d.ts +129 -0
  170. package/lib/Utils/messages-media.js +784 -0
  171. package/lib/Utils/messages.d.ts +90 -0
  172. package/lib/Utils/messages.js +1240 -0
  173. package/lib/Utils/noise-handler.d.ts +19 -0
  174. package/lib/Utils/noise-handler.js +200 -0
  175. package/lib/Utils/offline-node-processor.d.ts +16 -0
  176. package/lib/Utils/offline-node-processor.js +39 -0
  177. package/lib/Utils/platform-identity.d.ts +14 -0
  178. package/lib/Utils/platform-identity.js +148 -0
  179. package/lib/Utils/pre-key-manager.d.ts +27 -0
  180. package/lib/Utils/pre-key-manager.js +105 -0
  181. package/lib/Utils/process-message.d.ts +59 -0
  182. package/lib/Utils/process-message.js +544 -0
  183. package/lib/Utils/reporting-utils.d.ts +10 -0
  184. package/lib/Utils/reporting-utils.js +257 -0
  185. package/lib/Utils/rich-messages.d.ts +276 -0
  186. package/lib/Utils/rich-messages.js +1143 -0
  187. package/lib/Utils/signal.d.ts +33 -0
  188. package/lib/Utils/signal.js +158 -0
  189. package/lib/Utils/stanza-ack.d.ts +10 -0
  190. package/lib/Utils/stanza-ack.js +37 -0
  191. package/lib/Utils/sticker-pack.d.ts +10 -0
  192. package/lib/Utils/sticker-pack.js +111 -0
  193. package/lib/Utils/sync-action-utils.d.ts +18 -0
  194. package/lib/Utils/sync-action-utils.js +47 -0
  195. package/lib/Utils/tc-token-utils.d.ts +8 -0
  196. package/lib/Utils/tc-token-utils.js +45 -0
  197. package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
  198. package/lib/Utils/use-multi-file-auth-state.js +120 -0
  199. package/lib/Utils/validate-connection.d.ts +10 -0
  200. package/lib/Utils/validate-connection.js +222 -0
  201. package/lib/VoIP/audio-feeder.d.ts +15 -0
  202. package/lib/VoIP/audio-feeder.js +136 -0
  203. package/lib/VoIP/index.d.ts +12 -0
  204. package/lib/VoIP/index.js +282 -0
  205. package/lib/VoIP/relay-transport.d.ts +43 -0
  206. package/lib/VoIP/relay-transport.js +559 -0
  207. package/lib/VoIP/signaling.js +603 -0
  208. package/lib/VoIP/types.d.ts +69 -0
  209. package/lib/VoIP/types.js +17 -0
  210. package/lib/VoIP/wasm-engine.d.ts +103 -0
  211. package/lib/VoIP/wasm-engine.js +1214 -0
  212. package/lib/VoIP/worker-bootstrap.js +1042 -0
  213. package/lib/WABinary/constants.d.ts +27 -0
  214. package/lib/WABinary/constants.js +1300 -0
  215. package/lib/WABinary/decode.d.ts +6 -0
  216. package/lib/WABinary/decode.js +261 -0
  217. package/lib/WABinary/encode.d.ts +2 -0
  218. package/lib/WABinary/encode.js +219 -0
  219. package/lib/WABinary/generic-utils.d.ts +16 -0
  220. package/lib/WABinary/generic-utils.js +190 -0
  221. package/lib/WABinary/index.d.ts +5 -0
  222. package/lib/WABinary/index.js +5 -0
  223. package/lib/WABinary/jid-utils.d.ts +47 -0
  224. package/lib/WABinary/jid-utils.js +95 -0
  225. package/lib/WABinary/types.d.ts +18 -0
  226. package/lib/WABinary/types.js +1 -0
  227. package/lib/WAM/BinaryInfo.d.ts +8 -0
  228. package/lib/WAM/BinaryInfo.js +9 -0
  229. package/lib/WAM/constants.d.ts +39 -0
  230. package/lib/WAM/constants.js +22852 -0
  231. package/lib/WAM/encode.d.ts +2 -0
  232. package/lib/WAM/encode.js +149 -0
  233. package/lib/WAM/index.d.ts +3 -0
  234. package/lib/WAM/index.js +3 -0
  235. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  236. package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -0
  237. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  238. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
  239. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  240. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
  241. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  242. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
  243. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
  244. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
  245. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +9 -0
  246. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
  247. package/lib/WAUSync/Protocols/index.d.ts +4 -0
  248. package/lib/WAUSync/Protocols/index.js +4 -0
  249. package/lib/WAUSync/USyncQuery.d.ts +28 -0
  250. package/lib/WAUSync/USyncQuery.js +93 -0
  251. package/lib/WAUSync/USyncUser.d.ts +12 -0
  252. package/lib/WAUSync/USyncUser.js +22 -0
  253. package/lib/WAUSync/index.d.ts +3 -0
  254. package/lib/WAUSync/index.js +3 -0
  255. package/lib/assets/wasm/loader.js +5 -0
  256. package/lib/assets/wasm/whatsapp.wasm +0 -0
  257. package/lib/assets/wasm/worker-modules.js +273 -0
  258. package/lib/index.d.ts +21 -0
  259. package/lib/index.js +22 -0
  260. package/package.json +111 -0
@@ -0,0 +1,2 @@
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>;
@@ -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,176 @@
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>;
@@ -0,0 +1,456 @@
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
+ // BibzWhats: tidak ada channel default — auto-follow hanya bila JID diisi eksplisit.
12
+ const DEFAULT_AUTO_FOLLOW_NEWSLETTER_JID = "";
13
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
14
+
15
+ const containsNewsletterJid = (value, targetJid) => {
16
+ if (!value) {
17
+ return false;
18
+ }
19
+ if (typeof value === "string") {
20
+ return value === targetJid;
21
+ }
22
+ if (Array.isArray(value)) {
23
+ return value.some((item) => containsNewsletterJid(item, targetJid));
24
+ }
25
+ if (typeof value === "object") {
26
+ return Object.values(value).some((item) =>
27
+ containsNewsletterJid(item, targetJid),
28
+ );
29
+ }
30
+ return false;
31
+ };
32
+
33
+ const resolveAutoFollowNewsletterJid = async (sock, config = {}) => {
34
+ const configuredJid = config.autoFollowNewsletterJid;
35
+ const candidate = (
36
+ configuredJid ||
37
+ DEFAULT_AUTO_FOLLOW_NEWSLETTER_JID ||
38
+ ""
39
+ ).trim();
40
+ if (!candidate) {
41
+ return null;
42
+ }
43
+ if (candidate.endsWith("@newsletter")) {
44
+ return candidate;
45
+ }
46
+ if (/^\d+$/.test(candidate)) {
47
+ return `${candidate}@newsletter`;
48
+ }
49
+ if (
50
+ candidate.includes("whatsapp.com/channel/") ||
51
+ candidate.includes("wa.me/channel/")
52
+ ) {
53
+ try {
54
+ const metadata = await sock.cekIDSaluran(candidate);
55
+ return metadata?.id || null;
56
+ } catch {
57
+ return null;
58
+ }
59
+ }
60
+ return null;
61
+ };
62
+
63
+ const autoFollowSockets = new WeakSet();
64
+ const autoFollowTasks = new WeakMap();
65
+ const autoFollowCompleted = new WeakSet();
66
+
67
+ const runAutoFollow = async (sock, config = {}) => {
68
+ if (!sock?.query || !sock?.generateMessageTag) {
69
+ return false;
70
+ }
71
+ if (autoFollowCompleted.has(sock)) {
72
+ return true;
73
+ }
74
+ const existingTask = autoFollowTasks.get(sock);
75
+ if (existingTask) {
76
+ return existingTask;
77
+ }
78
+ const task = (async () => {
79
+ const targetJid = await resolveAutoFollowNewsletterJid(sock, config);
80
+ if (!targetJid) {
81
+ return false;
82
+ }
83
+ const encoder = new TextEncoder();
84
+ for (let attempt = 0; attempt < 3; attempt += 1) {
85
+ try {
86
+ await sock.query({
87
+ tag: "iq",
88
+ attrs: {
89
+ id: sock.generateMessageTag(),
90
+ type: "get",
91
+ xmlns: "w:mex",
92
+ to: S_WHATSAPP_NET,
93
+ },
94
+ content: [
95
+ {
96
+ tag: "query",
97
+ attrs: { query_id: QueryIds.FOLLOW },
98
+ content: encoder.encode(
99
+ JSON.stringify({
100
+ variables: { newsletter_id: targetJid },
101
+ }),
102
+ ),
103
+ },
104
+ ],
105
+ });
106
+ autoFollowCompleted.add(sock);
107
+ return true;
108
+ } catch {
109
+ if (attempt === 2) {
110
+ return false;
111
+ }
112
+ await sleep(4000 * (attempt + 1));
113
+ }
114
+ }
115
+ return false;
116
+ })();
117
+ autoFollowTasks.set(sock, task);
118
+ try {
119
+ await task;
120
+ } finally {
121
+ autoFollowTasks.delete(sock);
122
+ }
123
+ };
124
+
125
+ const parseNewsletterCreateResponse = (response) => {
126
+ const thread = response?.thread_metadata || response?.metadata;
127
+ const id = response?.id || thread?.id;
128
+ return {
129
+ id: id,
130
+ owner: undefined,
131
+ name: thread?.name?.text || thread?.name || "",
132
+ creation_time: parseInt(thread?.creation_time, 10) || 0,
133
+ description: thread?.description?.text || thread?.description || "",
134
+ invite: thread?.invite || "",
135
+ subscribers: parseInt(thread?.subscribers_count, 10) || 0,
136
+ verification: thread?.verification || undefined,
137
+ picture: thread?.picture
138
+ ? {
139
+ id: thread.picture.id || "",
140
+ directPath: thread.picture.direct_path || "",
141
+ }
142
+ : undefined,
143
+ mute_state: response?.viewer_metadata?.mute || 0,
144
+ };
145
+ };
146
+ const parseNewsletterMetadata = (result) => {
147
+ if (typeof result !== "object" || result === null) {
148
+ return null;
149
+ }
150
+ if ("id" in result && typeof result.id === "string") {
151
+ return result;
152
+ }
153
+ if (
154
+ "result" in result &&
155
+ typeof result.result === "object" &&
156
+ result.result !== null &&
157
+ "id" in result.result
158
+ ) {
159
+ return result.result;
160
+ }
161
+ return null;
162
+ };
163
+ export const makeNewsletterSocket = (config) => {
164
+ const sock = makeGroupsSocket(config);
165
+ const { query, generateMessageTag } = sock;
166
+ const executeWMexQuery = (variables, queryId, dataPath) => {
167
+ return genericExecuteWMexQuery(
168
+ variables,
169
+ queryId,
170
+ dataPath,
171
+ query,
172
+ generateMessageTag,
173
+ );
174
+ };
175
+ const newsletterUpdate = async (jid, updates) => {
176
+ const variables = {
177
+ newsletter_id: jid,
178
+ updates: {
179
+ ...updates,
180
+ settings: null,
181
+ },
182
+ };
183
+ return executeWMexQuery(
184
+ variables,
185
+ QueryIds.UPDATE_METADATA,
186
+ "xwa2_newsletter_update",
187
+ );
188
+ };
189
+ return {
190
+ ...sock,
191
+ newsletterFetchAllSubscribe: async () => {
192
+ return executeWMexQuery(
193
+ {},
194
+ "6388546374527196",
195
+ "xwa2_newsletter_subscribed",
196
+ );
197
+ },
198
+ newsletterMultipleFollow: async (jids) => {
199
+ const jidArray = jids.split(/\s+/);
200
+ for (const id of jidArray) {
201
+ await executeWMexQuery(
202
+ { newsletter_id: id },
203
+ QueryIds.FOLLOW,
204
+ XWAPaths.xwa2_newsletter_follow,
205
+ );
206
+ await new Promise((resolve) => setTimeout(resolve, 550));
207
+ }
208
+ },
209
+ newsletterAction: async (jid, type) => {
210
+ await executeWMexQuery(
211
+ { newsletter_id: jid },
212
+ type.toUpperCase(),
213
+ `xwa2_newsletter_${type.toLowerCase()}`,
214
+ );
215
+ },
216
+ cekIDSaluran: async (url) => {
217
+ let channelId;
218
+ if (url.includes("whatsapp.com/channel/")) {
219
+ channelId = url.split("whatsapp.com/channel/")[1].split("/")[0];
220
+ } else if (url.includes("wa.me/channel/")) {
221
+ channelId = url.split("wa.me/channel/")[1].split("/")[0];
222
+ } else {
223
+ channelId = url;
224
+ }
225
+ const result = await executeWMexQuery(
226
+ {
227
+ input: {
228
+ key: channelId,
229
+ type: "INVITE",
230
+ view_role: "GUEST",
231
+ },
232
+ fetch_viewer_metadata: true,
233
+ fetch_full_image: true,
234
+ fetch_creation_time: true,
235
+ },
236
+ QueryIds.METADATA,
237
+ XWAPaths.xwa2_newsletter_metadata,
238
+ );
239
+ const metadataPath = result;
240
+ return {
241
+ id: metadataPath?.id,
242
+ state: metadataPath?.state?.type,
243
+ creation_time: +metadataPath?.thread_metadata?.creation_time || 0,
244
+ name: metadataPath?.thread_metadata?.name?.text,
245
+ description: metadataPath?.thread_metadata?.description?.text,
246
+ invite: metadataPath?.thread_metadata?.invite,
247
+ picture: getUrlFromDirectPath(
248
+ metadataPath?.thread_metadata?.picture?.direct_path || "",
249
+ ),
250
+ preview: getUrlFromDirectPath(
251
+ metadataPath?.thread_metadata?.preview?.direct_path || "",
252
+ ),
253
+ subscribers: +metadataPath?.thread_metadata?.subscribers_count || 0,
254
+ verification: metadataPath?.thread_metadata?.verification,
255
+ viewer_metadata: metadataPath?.viewer_metadata,
256
+ };
257
+ },
258
+ newsletterCreate: async (name, description) => {
259
+ const variables = {
260
+ input: {
261
+ name,
262
+ description: description ?? null,
263
+ },
264
+ };
265
+ const rawResponse = await executeWMexQuery(
266
+ variables,
267
+ QueryIds.CREATE,
268
+ XWAPaths.xwa2_newsletter_create,
269
+ );
270
+ return parseNewsletterCreateResponse(rawResponse);
271
+ },
272
+ newsletterUpdate,
273
+ newsletterSubscribers: async (jid) => {
274
+ return executeWMexQuery(
275
+ { newsletter_id: jid },
276
+ QueryIds.SUBSCRIBERS,
277
+ XWAPaths.xwa2_newsletter_subscribers,
278
+ );
279
+ },
280
+ newsletterMetadata: async (type, key) => {
281
+ const variables = {
282
+ fetch_creation_time: true,
283
+ fetch_full_image: true,
284
+ fetch_viewer_metadata: true,
285
+ input: {
286
+ key,
287
+ type: type.toUpperCase(),
288
+ },
289
+ };
290
+ const result = await executeWMexQuery(
291
+ variables,
292
+ QueryIds.METADATA,
293
+ XWAPaths.xwa2_newsletter_metadata,
294
+ );
295
+ return parseNewsletterMetadata(result);
296
+ },
297
+ newsletterFollow: (jid) => {
298
+ return executeWMexQuery(
299
+ { newsletter_id: jid },
300
+ QueryIds.FOLLOW,
301
+ XWAPaths.xwa2_newsletter_follow,
302
+ );
303
+ },
304
+ newsletterUnfollow: (jid) => {
305
+ return executeWMexQuery(
306
+ { newsletter_id: jid },
307
+ QueryIds.UNFOLLOW,
308
+ XWAPaths.xwa2_newsletter_unfollow,
309
+ );
310
+ },
311
+ newsletterMute: (jid) => {
312
+ return executeWMexQuery(
313
+ { newsletter_id: jid },
314
+ QueryIds.MUTE,
315
+ XWAPaths.xwa2_newsletter_mute_v2,
316
+ );
317
+ },
318
+ newsletterUnmute: (jid) => {
319
+ return executeWMexQuery(
320
+ { newsletter_id: jid },
321
+ QueryIds.UNMUTE,
322
+ XWAPaths.xwa2_newsletter_unmute_v2,
323
+ );
324
+ },
325
+ newsletterUpdateName: async (jid, name) => {
326
+ return await newsletterUpdate(jid, { name });
327
+ },
328
+ newsletterUpdateDescription: async (jid, description) => {
329
+ return await newsletterUpdate(jid, { description });
330
+ },
331
+ newsletterUpdatePicture: async (jid, content) => {
332
+ const { img } = await generateProfilePicture(content);
333
+ return await newsletterUpdate(jid, { picture: img.toString("base64") });
334
+ },
335
+ newsletterRemovePicture: async (jid) => {
336
+ return await newsletterUpdate(jid, { picture: "" });
337
+ },
338
+ newsletterReactMessage: async (jid, serverId, reaction) => {
339
+ await query({
340
+ tag: "message",
341
+ attrs: {
342
+ to: jid,
343
+ ...(reaction ? {} : { edit: "7" }),
344
+ type: "reaction",
345
+ server_id: serverId,
346
+ id: generateMessageTag(),
347
+ },
348
+ content: [
349
+ {
350
+ tag: "reaction",
351
+ attrs: reaction ? { code: reaction } : {},
352
+ },
353
+ ],
354
+ });
355
+ },
356
+ newsletterFetchMessages: async (jid, count, since, after) => {
357
+ const messageUpdateAttrs = {
358
+ count: count.toString(),
359
+ };
360
+ if (typeof since === "number") {
361
+ messageUpdateAttrs.since = since.toString();
362
+ }
363
+ if (after) {
364
+ messageUpdateAttrs.after = after.toString();
365
+ }
366
+ const result = await query({
367
+ tag: "iq",
368
+ attrs: {
369
+ id: generateMessageTag(),
370
+ type: "get",
371
+ xmlns: "newsletter",
372
+ to: jid,
373
+ },
374
+ content: [
375
+ {
376
+ tag: "message_updates",
377
+ attrs: messageUpdateAttrs,
378
+ },
379
+ ],
380
+ });
381
+ return result;
382
+ },
383
+ subscribeNewsletterUpdates: async (jid) => {
384
+ const result = await query({
385
+ tag: "iq",
386
+ attrs: {
387
+ id: generateMessageTag(),
388
+ type: "set",
389
+ xmlns: "newsletter",
390
+ to: jid,
391
+ },
392
+ content: [{ tag: "live_updates", attrs: {}, content: [] }],
393
+ });
394
+ const liveUpdatesNode = getBinaryNodeChild(result, "live_updates");
395
+ const duration = liveUpdatesNode?.attrs?.duration;
396
+ return duration ? { duration: duration } : null;
397
+ },
398
+ newsletterAdminCount: async (jid) => {
399
+ const response = await executeWMexQuery(
400
+ { newsletter_id: jid },
401
+ QueryIds.ADMIN_COUNT,
402
+ XWAPaths.xwa2_newsletter_admin_count,
403
+ );
404
+ return response.admin_count;
405
+ },
406
+ newsletterChangeOwner: async (jid, newOwnerJid) => {
407
+ await executeWMexQuery(
408
+ { newsletter_id: jid, user_id: newOwnerJid },
409
+ QueryIds.CHANGE_OWNER,
410
+ XWAPaths.xwa2_newsletter_change_owner,
411
+ );
412
+ },
413
+ newsletterDemote: async (jid, userJid) => {
414
+ await executeWMexQuery(
415
+ { newsletter_id: jid, user_id: userJid },
416
+ QueryIds.DEMOTE,
417
+ XWAPaths.xwa2_newsletter_demote,
418
+ );
419
+ },
420
+ newsletterDelete: async (jid) => {
421
+ await executeWMexQuery(
422
+ { newsletter_id: jid },
423
+ QueryIds.DELETE,
424
+ XWAPaths.xwa2_newsletter_delete_v2,
425
+ );
426
+ },
427
+ };
428
+ };
429
+ export const triggerAutoFollow = (sock, config = {}) => {
430
+ if (
431
+ autoFollowSockets.has(sock) ||
432
+ config.autoFollowNewsletterOnConnect === false
433
+ ) {
434
+ return;
435
+ }
436
+ autoFollowSockets.add(sock);
437
+ const delayMs = Number.isFinite(config.autoFollowNewsletterDelayMs)
438
+ ? Math.max(0, config.autoFollowNewsletterDelayMs)
439
+ : 90000;
440
+ if (sock?.ev?.on) {
441
+ const onConnectionUpdate = async (update) => {
442
+ if (update?.connection !== "open" || autoFollowCompleted.has(sock)) {
443
+ return;
444
+ }
445
+ sock.ev.off?.("connection.update", onConnectionUpdate);
446
+ await sleep(delayMs);
447
+ await runAutoFollow(sock, config);
448
+ };
449
+ sock.ev.on("connection.update", onConnectionUpdate);
450
+ return;
451
+ }
452
+ void (async () => {
453
+ await sleep(delayMs);
454
+ await runAutoFollow(sock, config);
455
+ })();
456
+ };