@vanzxy/baileys 2.0.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 (281) hide show
  1. package/NOTICE.md +111 -0
  2. package/README.md +830 -0
  3. package/WAProto/index.d.ts +9 -0
  4. package/WAProto/index.js +142036 -0
  5. package/engine-requirements.js +13 -0
  6. package/lib/Defaults/index.d.ts +152 -0
  7. package/lib/Defaults/index.js +179 -0
  8. package/lib/Framework/Bot.js +209 -0
  9. package/lib/Framework/Context.js +90 -0
  10. package/lib/Framework/MediaManager.js +152 -0
  11. package/lib/Framework/SessionManager.js +34 -0
  12. package/lib/Framework/StatsManager.js +120 -0
  13. package/lib/Framework/Store/SQLiteStore.js +74 -0
  14. package/lib/Framework/index.js +11 -0
  15. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  16. package/lib/Signal/Group/ciphertext-message.js +12 -0
  17. package/lib/Signal/Group/group-session-builder.d.ts +7 -0
  18. package/lib/Signal/Group/group-session-builder.js +30 -0
  19. package/lib/Signal/Group/group_cipher.d.ts +10 -0
  20. package/lib/Signal/Group/group_cipher.js +82 -0
  21. package/lib/Signal/Group/index.d.ts +11 -0
  22. package/lib/Signal/Group/index.js +12 -0
  23. package/lib/Signal/Group/keyhelper.d.ts +6 -0
  24. package/lib/Signal/Group/keyhelper.js +18 -0
  25. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  26. package/lib/Signal/Group/sender-chain-key.js +26 -0
  27. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  28. package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
  29. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  30. package/lib/Signal/Group/sender-key-message.js +66 -0
  31. package/lib/Signal/Group/sender-key-name.d.ts +11 -0
  32. package/lib/Signal/Group/sender-key-name.js +48 -0
  33. package/lib/Signal/Group/sender-key-record.d.ts +12 -0
  34. package/lib/Signal/Group/sender-key-record.js +41 -0
  35. package/lib/Signal/Group/sender-key-state.d.ts +16 -0
  36. package/lib/Signal/Group/sender-key-state.js +84 -0
  37. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  38. package/lib/Signal/Group/sender-message-key.js +26 -0
  39. package/lib/Signal/libsignal.d.ts +54 -0
  40. package/lib/Signal/libsignal.js +431 -0
  41. package/lib/Signal/lid-mapping.d.ts +20 -0
  42. package/lib/Signal/lid-mapping.js +277 -0
  43. package/lib/Socket/Client/index.d.ts +2 -0
  44. package/lib/Socket/Client/index.js +3 -0
  45. package/lib/Socket/Client/types.d.ts +5 -0
  46. package/lib/Socket/Client/types.js +11 -0
  47. package/lib/Socket/Client/websocket.d.ts +12 -0
  48. package/lib/Socket/Client/websocket.js +54 -0
  49. package/lib/Socket/business.d.ts +395 -0
  50. package/lib/Socket/business.js +380 -0
  51. package/lib/Socket/chats.d.ts +136 -0
  52. package/lib/Socket/chats.js +1328 -0
  53. package/lib/Socket/communities.d.ts +561 -0
  54. package/lib/Socket/communities.js +434 -0
  55. package/lib/Socket/dugong.d.ts +117 -0
  56. package/lib/Socket/dugong.js +799 -0
  57. package/lib/Socket/groups.d.ts +285 -0
  58. package/lib/Socket/groups.js +355 -0
  59. package/lib/Socket/index.d.ts +531 -0
  60. package/lib/Socket/index.js +34 -0
  61. package/lib/Socket/messages-recv.d.ts +333 -0
  62. package/lib/Socket/messages-recv.js +1782 -0
  63. package/lib/Socket/messages-send.d.ts +329 -0
  64. package/lib/Socket/messages-send.js +1383 -0
  65. package/lib/Socket/mex.d.ts +1 -0
  66. package/lib/Socket/mex.js +42 -0
  67. package/lib/Socket/newsletter.d.ts +281 -0
  68. package/lib/Socket/newsletter.js +321 -0
  69. package/lib/Socket/socket.d.ts +60 -0
  70. package/lib/Socket/socket.js +1001 -0
  71. package/lib/Socket/username.js +153 -0
  72. package/lib/Store/index.d.ts +3 -0
  73. package/lib/Store/index.js +4 -0
  74. package/lib/Store/make-in-memory-store.d.ts +62 -0
  75. package/lib/Store/make-in-memory-store.js +429 -0
  76. package/lib/Store/make-ordered-dictionary.d.ts +12 -0
  77. package/lib/Store/make-ordered-dictionary.js +79 -0
  78. package/lib/Store/object-repository.d.ts +10 -0
  79. package/lib/Store/object-repository.js +24 -0
  80. package/lib/Types/Auth.d.ts +117 -0
  81. package/lib/Types/Auth.js +2 -0
  82. package/lib/Types/Bussines.d.ts +25 -0
  83. package/lib/Types/Bussines.js +2 -0
  84. package/lib/Types/Call.d.ts +15 -0
  85. package/lib/Types/Call.js +2 -0
  86. package/lib/Types/Chat.d.ts +124 -0
  87. package/lib/Types/Chat.js +8 -0
  88. package/lib/Types/Contact.d.ts +26 -0
  89. package/lib/Types/Contact.js +2 -0
  90. package/lib/Types/Events.d.ts +256 -0
  91. package/lib/Types/Events.js +2 -0
  92. package/lib/Types/GroupMetadata.d.ts +71 -0
  93. package/lib/Types/GroupMetadata.js +2 -0
  94. package/lib/Types/Label.d.ts +2 -0
  95. package/lib/Types/Label.js +25 -0
  96. package/lib/Types/LabelAssociation.d.ts +2 -0
  97. package/lib/Types/LabelAssociation.js +7 -0
  98. package/lib/Types/Message.d.ts +11 -0
  99. package/lib/Types/Message.js +18 -0
  100. package/lib/Types/Mex.d.ts +2 -0
  101. package/lib/Types/Mex.js +39 -0
  102. package/lib/Types/Product.d.ts +79 -0
  103. package/lib/Types/Product.js +2 -0
  104. package/lib/Types/RichType.d.ts +2 -0
  105. package/lib/Types/RichType.js +23 -0
  106. package/lib/Types/Signal.d.ts +87 -0
  107. package/lib/Types/Signal.js +2 -0
  108. package/lib/Types/Socket.d.ts +136 -0
  109. package/lib/Types/Socket.js +2 -0
  110. package/lib/Types/State.d.ts +5 -0
  111. package/lib/Types/State.js +56 -0
  112. package/lib/Types/USync.d.ts +26 -0
  113. package/lib/Types/USync.js +2 -0
  114. package/lib/Types/index.d.ts +66 -0
  115. package/lib/Types/index.js +26 -0
  116. package/lib/Utils/A2UI.js +277 -0
  117. package/lib/Utils/MessageBuilder.js +4405 -0
  118. package/lib/Utils/MessageBuilder_d.ts +411 -0
  119. package/lib/Utils/PersistentStore.js +592 -0
  120. package/lib/Utils/PersistentStore_d.ts +60 -0
  121. package/lib/Utils/anti-delete.d.ts +74 -0
  122. package/lib/Utils/anti-delete.js +222 -0
  123. package/lib/Utils/auth-utils.d.ts +57 -0
  124. package/lib/Utils/auth-utils.js +307 -0
  125. package/lib/Utils/auto-reply.d.ts +47 -0
  126. package/lib/Utils/auto-reply.js +158 -0
  127. package/lib/Utils/baileys-event-stream.d.ts +8 -0
  128. package/lib/Utils/baileys-event-stream.js +62 -0
  129. package/lib/Utils/browser-utils.d.ts +8 -0
  130. package/lib/Utils/browser-utils.js +28 -0
  131. package/lib/Utils/business.d.ts +49 -0
  132. package/lib/Utils/business.js +240 -0
  133. package/lib/Utils/button-helper-utils.js +314 -0
  134. package/lib/Utils/button-sender.js +824 -0
  135. package/lib/Utils/chat-control.d.ts +159 -0
  136. package/lib/Utils/chat-control.js +232 -0
  137. package/lib/Utils/chat-history-helpers.d.ts +21 -0
  138. package/lib/Utils/chat-history-helpers.js +71 -0
  139. package/lib/Utils/chat-utils.d.ts +407 -0
  140. package/lib/Utils/chat-utils.js +886 -0
  141. package/lib/Utils/companion-reg-client-utils.d.ts +4 -0
  142. package/lib/Utils/companion-reg-client-utils.js +40 -0
  143. package/lib/Utils/crypto.d.ts +41 -0
  144. package/lib/Utils/crypto.js +148 -0
  145. package/lib/Utils/decode-wa-message.d.ts +83 -0
  146. package/lib/Utils/decode-wa-message.js +317 -0
  147. package/lib/Utils/event-buffer.d.ts +12 -0
  148. package/lib/Utils/event-buffer.js +636 -0
  149. package/lib/Utils/generics.d.ts +69 -0
  150. package/lib/Utils/generics.js +439 -0
  151. package/lib/Utils/history.d.ts +90 -0
  152. package/lib/Utils/history.js +147 -0
  153. package/lib/Utils/identity-change-handler.d.ts +13 -0
  154. package/lib/Utils/identity-change-handler.js +50 -0
  155. package/lib/Utils/index.d.ts +39 -0
  156. package/lib/Utils/index.js +46 -0
  157. package/lib/Utils/link-preview.d.ts +12 -0
  158. package/lib/Utils/link-preview.js +85 -0
  159. package/lib/Utils/logger.d.ts +2 -0
  160. package/lib/Utils/logger.js +3 -0
  161. package/lib/Utils/lt-hash.d.ts +12 -0
  162. package/lib/Utils/lt-hash.js +27 -0
  163. package/lib/Utils/make-mutex.d.ts +6 -0
  164. package/lib/Utils/make-mutex.js +33 -0
  165. package/lib/Utils/media-messages.d.ts +18 -0
  166. package/lib/Utils/media-messages.js +71 -0
  167. package/lib/Utils/media-set.d.ts +13 -0
  168. package/lib/Utils/media-set.js +172 -0
  169. package/lib/Utils/message-kind.js +139 -0
  170. package/lib/Utils/message-retry-manager.d.ts +79 -0
  171. package/lib/Utils/message-retry-manager.js +265 -0
  172. package/lib/Utils/message-search.d.ts +44 -0
  173. package/lib/Utils/message-search.js +189 -0
  174. package/lib/Utils/messages-media.d.ts +135 -0
  175. package/lib/Utils/messages-media.js +869 -0
  176. package/lib/Utils/messages.d.ts +44 -0
  177. package/lib/Utils/messages.js +2155 -0
  178. package/lib/Utils/noise-handler.d.ts +20 -0
  179. package/lib/Utils/noise-handler.js +201 -0
  180. package/lib/Utils/offline-node-processor.d.ts +9 -0
  181. package/lib/Utils/offline-node-processor.js +40 -0
  182. package/lib/Utils/past-participants.d.ts +14 -0
  183. package/lib/Utils/past-participants.js +40 -0
  184. package/lib/Utils/pre-key-manager.d.ts +25 -0
  185. package/lib/Utils/pre-key-manager.js +106 -0
  186. package/lib/Utils/process-message.d.ts +82 -0
  187. package/lib/Utils/process-message.js +809 -0
  188. package/lib/Utils/reporting-utils.d.ts +12 -0
  189. package/lib/Utils/reporting-utils.js +258 -0
  190. package/lib/Utils/rich-message-utils.d.ts +48 -0
  191. package/lib/Utils/rich-message-utils.js +445 -0
  192. package/lib/Utils/scheduling.d.ts +42 -0
  193. package/lib/Utils/scheduling.js +140 -0
  194. package/lib/Utils/signal.d.ts +82 -0
  195. package/lib/Utils/signal.js +201 -0
  196. package/lib/Utils/stanza-ack.d.ts +16 -0
  197. package/lib/Utils/stanza-ack.js +38 -0
  198. package/lib/Utils/status.d.ts +50 -0
  199. package/lib/Utils/status.js +108 -0
  200. package/lib/Utils/stickerpack.d.ts +51 -0
  201. package/lib/Utils/stickerpack.js +275 -0
  202. package/lib/Utils/sync-action-utils.d.ts +2 -0
  203. package/lib/Utils/sync-action-utils.js +49 -0
  204. package/lib/Utils/tc-token-utils.d.ts +29 -0
  205. package/lib/Utils/tc-token-utils.js +163 -0
  206. package/lib/Utils/templates.d.ts +76 -0
  207. package/lib/Utils/templates.js +151 -0
  208. package/lib/Utils/use-cache-manager-auth-state.d.ts +13 -0
  209. package/lib/Utils/use-cache-manager-auth-state.js +82 -0
  210. package/lib/Utils/use-multi-file-auth-state.d.ts +10 -0
  211. package/lib/Utils/use-multi-file-auth-state.js +167 -0
  212. package/lib/Utils/use-single-file-auth-state.d.ts +10 -0
  213. package/lib/Utils/use-single-file-auth-state.js +114 -0
  214. package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
  215. package/lib/Utils/use-sqlite-auth-state.js +170 -0
  216. package/lib/Utils/validate-connection.d.ts +42 -0
  217. package/lib/Utils/validate-connection.js +199 -0
  218. package/lib/Utils/vcard.d.ts +58 -0
  219. package/lib/Utils/vcard.js +105 -0
  220. package/lib/VoIP/audio-feeder.d.ts +15 -0
  221. package/lib/VoIP/audio-feeder.js +132 -0
  222. package/lib/VoIP/index.js +277 -0
  223. package/lib/VoIP/relay-transport.d.ts +43 -0
  224. package/lib/VoIP/relay-transport.js +559 -0
  225. package/lib/VoIP/signaling.js +624 -0
  226. package/lib/VoIP/types.d.ts +69 -0
  227. package/lib/VoIP/types.js +17 -0
  228. package/lib/VoIP/wasm-engine.d.ts +103 -0
  229. package/lib/VoIP/wasm-engine.js +1214 -0
  230. package/lib/VoIP/worker-bootstrap.js +1042 -0
  231. package/lib/WABinary/constants.d.ts +61 -0
  232. package/lib/WABinary/constants.js +1467 -0
  233. package/lib/WABinary/decode.d.ts +9 -0
  234. package/lib/WABinary/decode.js +262 -0
  235. package/lib/WABinary/encode.d.ts +2 -0
  236. package/lib/WABinary/encode.js +220 -0
  237. package/lib/WABinary/generic-utils.d.ts +74 -0
  238. package/lib/WABinary/generic-utils.js +277 -0
  239. package/lib/WABinary/index.d.ts +5 -0
  240. package/lib/WABinary/index.js +6 -0
  241. package/lib/WABinary/jid-utils.d.ts +28 -0
  242. package/lib/WABinary/jid-utils.js +96 -0
  243. package/lib/WABinary/types.d.ts +19 -0
  244. package/lib/WABinary/types.js +2 -0
  245. package/lib/WAM/BinaryInfo.d.ts +7 -0
  246. package/lib/WAM/BinaryInfo.js +10 -0
  247. package/lib/WAM/constants.d.ts +34926 -0
  248. package/lib/WAM/constants.js +22853 -0
  249. package/lib/WAM/encode.d.ts +1 -0
  250. package/lib/WAM/encode.js +150 -0
  251. package/lib/WAM/index.d.ts +3 -0
  252. package/lib/WAM/index.js +4 -0
  253. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
  254. package/lib/WAUSync/Protocols/USyncContactProtocol.js +52 -0
  255. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +29 -0
  256. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +63 -0
  257. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  258. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
  259. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  260. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
  261. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
  262. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
  263. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
  264. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
  265. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
  266. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
  267. package/lib/WAUSync/Protocols/index.d.ts +7 -0
  268. package/lib/WAUSync/Protocols/index.js +8 -0
  269. package/lib/WAUSync/USyncQuery.d.ts +20 -0
  270. package/lib/WAUSync/USyncQuery.js +122 -0
  271. package/lib/WAUSync/USyncUser.d.ts +16 -0
  272. package/lib/WAUSync/USyncUser.js +31 -0
  273. package/lib/WAUSync/index.d.ts +3 -0
  274. package/lib/WAUSync/index.js +4 -0
  275. package/lib/assets/wasm/loader.js +5 -0
  276. package/lib/assets/wasm/whatsapp.wasm +0 -0
  277. package/lib/assets/wasm/worker-modules.js +273 -0
  278. package/lib/index.d.ts +12 -0
  279. package/lib/index.js +20 -0
  280. package/package.json +175 -0
  281. package/postinstall-banner.js +56 -0
@@ -0,0 +1 @@
1
+ export function executeWMexQuery(variables: any, queryId: any, dataPath: any, query: any, generateMessageTag: any): Promise<any>;
@@ -0,0 +1,42 @@
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
+ const response = dataPath ? data?.data?.[dataPath] : data?.data;
33
+ if (typeof response !== 'undefined') {
34
+ return response;
35
+ }
36
+ }
37
+ const action = (dataPath || '').startsWith('xwa2_')
38
+ ? dataPath.substring(5).replace(/_/g, ' ')
39
+ : dataPath?.replace(/_/g, ' ');
40
+ throw new Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result });
41
+ };
42
+ //# sourceMappingURL=mex.js.map
@@ -0,0 +1,281 @@
1
+ export function makeNewsletterSocket(config: any): {
2
+ executeWMexQuery: (variables: any, queryId: any, dataPath: any) => Promise<any>;
3
+ newsletterCreate: (name: any, description: any) => Promise<{
4
+ id: any;
5
+ owner: undefined;
6
+ name: any;
7
+ creation_time: number;
8
+ description: any;
9
+ invite: any;
10
+ subscribers: number;
11
+ verification: any;
12
+ picture: {
13
+ id: any;
14
+ directPath: any;
15
+ };
16
+ mute_state: any;
17
+ }>;
18
+ newsletterUpdate: (jid: any, updates: any) => Promise<any>;
19
+ newsletterSubscribers: (jid: any) => Promise<any>;
20
+ newsletterSubscribed: () => Promise<any>;
21
+ newsletterMetadata: (type: any, key: any) => Promise<any>;
22
+ newsletterFollow: (jid: any) => Promise<any>;
23
+ newsletterUnfollow: (jid: any) => Promise<any>;
24
+ newsletterMute: (jid: any) => Promise<any>;
25
+ newsletterUnmute: (jid: any) => Promise<any>;
26
+ newsletterUpdateName: (jid: any, name: any) => Promise<any>;
27
+ newsletterUpdateDescription: (jid: any, description: any) => Promise<any>;
28
+ newsletterUpdatePicture: (jid: any, content: any) => Promise<any>;
29
+ newsletterRemovePicture: (jid: any) => Promise<any>;
30
+ newsletterReactMessage: (jid: any, serverId: any, reaction: any) => Promise<void>;
31
+ newsletterFetchMessages: (jid: string, count: number, since?: number, after?: number) => Promise<any[]>;
32
+ subscribeNewsletterUpdates: (jid: any) => Promise<{
33
+ duration: any;
34
+ } | null>;
35
+ newsletterAdminCount: (jid: any) => Promise<any>;
36
+ newsletterChangeOwner: (jid: any, newOwnerJid: any) => Promise<void>;
37
+ newsletterDemote: (jid: any, userJid: any) => Promise<void>;
38
+ newsletterDelete: (jid: any) => Promise<void>;
39
+ groupQuery: (jid: any, type: any, content: any) => Promise<any>;
40
+ groupMetadata: (jid: any) => Promise<{
41
+ id: any;
42
+ notify: any;
43
+ addressingMode: any;
44
+ subject: any;
45
+ subjectOwner: any;
46
+ subjectOwnerPn: any;
47
+ subjectOwnerUsername: any;
48
+ subjectTime: number;
49
+ size: any;
50
+ creation: number;
51
+ owner: string | undefined;
52
+ ownerPn: string | undefined;
53
+ ownerUsername: any;
54
+ owner_country_code: any;
55
+ desc: any;
56
+ descId: any;
57
+ descOwner: string | undefined;
58
+ descOwnerPn: string | undefined;
59
+ descOwnerUsername: any;
60
+ descTime: number | undefined;
61
+ linkedParent: any;
62
+ restrict: boolean;
63
+ announce: boolean;
64
+ isCommunity: boolean;
65
+ isCommunityAnnounce: boolean;
66
+ joinApprovalMode: boolean;
67
+ memberAddMode: boolean;
68
+ participants: any;
69
+ ephemeralDuration: number | undefined;
70
+ }>;
71
+ groupCreate: (subject: any, participants: any) => Promise<{
72
+ id: any;
73
+ notify: any;
74
+ addressingMode: any;
75
+ subject: any;
76
+ subjectOwner: any;
77
+ subjectOwnerPn: any;
78
+ subjectOwnerUsername: any;
79
+ subjectTime: number;
80
+ size: any;
81
+ creation: number;
82
+ owner: string | undefined;
83
+ ownerPn: string | undefined;
84
+ ownerUsername: any;
85
+ owner_country_code: any;
86
+ desc: any;
87
+ descId: any;
88
+ descOwner: string | undefined;
89
+ descOwnerPn: string | undefined;
90
+ descOwnerUsername: any;
91
+ descTime: number | undefined;
92
+ linkedParent: any;
93
+ restrict: boolean;
94
+ announce: boolean;
95
+ isCommunity: boolean;
96
+ isCommunityAnnounce: boolean;
97
+ joinApprovalMode: boolean;
98
+ memberAddMode: boolean;
99
+ participants: any;
100
+ ephemeralDuration: number | undefined;
101
+ }>;
102
+ groupLeave: (id: any) => Promise<void>;
103
+ groupUpdateSubject: (jid: any, subject: any) => Promise<void>;
104
+ groupRequestParticipantsList: (jid: any) => Promise<any>;
105
+ groupRequestParticipantsUpdate: (jid: any, participants: any, action: any) => Promise<any>;
106
+ groupParticipantsUpdate: (jid: any, participants: any, action: any) => Promise<any[]>;
107
+ groupUpdateDescription: (jid: any, description: any) => Promise<void>;
108
+ groupInviteCode: (jid: any) => Promise<any>;
109
+ groupRevokeInvite: (jid: any) => Promise<any>;
110
+ groupAcceptInvite: (code: any) => Promise<any>;
111
+ groupRevokeInviteV4: (groupJid: any, invitedJid: any) => Promise<boolean>;
112
+ groupAcceptInviteV4: (...args: any[]) => Promise<any>;
113
+ groupGetInviteInfo: (code: any) => Promise<{
114
+ id: any;
115
+ notify: any;
116
+ addressingMode: any;
117
+ subject: any;
118
+ subjectOwner: any;
119
+ subjectOwnerPn: any;
120
+ subjectOwnerUsername: any;
121
+ subjectTime: number;
122
+ size: any;
123
+ creation: number;
124
+ owner: string | undefined;
125
+ ownerPn: string | undefined;
126
+ ownerUsername: any;
127
+ owner_country_code: any;
128
+ desc: any;
129
+ descId: any;
130
+ descOwner: string | undefined;
131
+ descOwnerPn: string | undefined;
132
+ descOwnerUsername: any;
133
+ descTime: number | undefined;
134
+ linkedParent: any;
135
+ restrict: boolean;
136
+ announce: boolean;
137
+ isCommunity: boolean;
138
+ isCommunityAnnounce: boolean;
139
+ joinApprovalMode: boolean;
140
+ memberAddMode: boolean;
141
+ participants: any;
142
+ ephemeralDuration: number | undefined;
143
+ }>;
144
+ groupToggleEphemeral: (jid: any, ephemeralExpiration: any) => Promise<void>;
145
+ groupSettingUpdate: (jid: any, setting: any) => Promise<void>;
146
+ groupMemberAddMode: (jid: any, mode: any) => Promise<void>;
147
+ groupJoinApprovalMode: (jid: any, mode: any) => Promise<void>;
148
+ groupFetchAllParticipating: () => Promise<{}>;
149
+ findUserId: (pnLid: any) => Promise<{
150
+ lid: undefined;
151
+ phoneNumber: undefined;
152
+ }>;
153
+ serverProps: {
154
+ privacyTokenOn1to1: boolean;
155
+ profilePicPrivacyToken: boolean;
156
+ lidTrustedTokenIssueToLid: boolean;
157
+ };
158
+ createCallLink: (type: any, event: any, timeoutMs: any) => Promise<any>;
159
+ getBotListV2: () => Promise<{
160
+ jid: any;
161
+ personaId: any;
162
+ }[]>;
163
+ messageMutex: {
164
+ mutex(code: any): any;
165
+ };
166
+ receiptMutex: {
167
+ mutex(code: any): any;
168
+ };
169
+ appStatePatchMutex: {
170
+ mutex(code: any): any;
171
+ };
172
+ notificationMutex: {
173
+ mutex(code: any): any;
174
+ };
175
+ fetchPrivacySettings: (force?: boolean) => Promise<any>;
176
+ upsertMessage: (...args: any[]) => Promise<any>;
177
+ appPatch: (patchCreate: any) => Promise<void>;
178
+ sendPresenceUpdate: (type: any, toJid: any) => Promise<void>;
179
+ presenceSubscribe: (toJid: any) => Promise<void>;
180
+ profilePictureUrl: (jid: any, type?: string, timeoutMs?: number, shouldIncludeTcToken?: boolean) => Promise<any>;
181
+ fetchBlocklist: () => Promise<any>;
182
+ fetchStatus: (...jids: any[]) => Promise<any>;
183
+ fetchDisappearingDuration: (...jids: any[]) => Promise<any>;
184
+ updateProfilePicture: (jid: any, content: any, dimensions: any) => Promise<void>;
185
+ removeProfilePicture: (jid: any) => Promise<void>;
186
+ updateProfileStatus: (status: any) => Promise<void>;
187
+ updateProfileName: (name: any) => Promise<void>;
188
+ updateBlockStatus: (jid: any, action: any) => Promise<void>;
189
+ updateDisableLinkPreviewsPrivacy: (isPreviewsDisabled: any) => Promise<void>;
190
+ updateCallPrivacy: (value: any) => Promise<void>;
191
+ updateMessagesPrivacy: (value: any) => Promise<void>;
192
+ updateLastSeenPrivacy: (value: any) => Promise<void>;
193
+ updateOnlinePrivacy: (value: any) => Promise<void>;
194
+ updateProfilePicturePrivacy: (value: any) => Promise<void>;
195
+ updateStatusPrivacy: (value: any) => Promise<void>;
196
+ updateReadReceiptsPrivacy: (value: any) => Promise<void>;
197
+ updateGroupsAddPrivacy: (value: any) => Promise<void>;
198
+ updateDefaultDisappearingMode: (duration: any) => Promise<void>;
199
+ getBusinessProfile: (jid: any) => Promise<{
200
+ wid: any;
201
+ address: any;
202
+ description: any;
203
+ website: any[];
204
+ email: any;
205
+ category: any;
206
+ business_hours: {
207
+ timezone: any;
208
+ business_config: any;
209
+ };
210
+ } | undefined>;
211
+ resyncAppState: (...args: any[]) => Promise<any>;
212
+ chatModify: (mod: any, jid: any) => Promise<void>;
213
+ cleanDirtyBits: (type: any, fromTimestamp: any) => Promise<void>;
214
+ addOrEditContact: (jid: any, contact: any) => Promise<void>;
215
+ removeContact: (jid: any) => Promise<void>;
216
+ placeholderResendCache: any;
217
+ addLabel: (jid: any, labels: any) => Promise<void>;
218
+ addChatLabel: (jid: any, labelId: any) => Promise<void>;
219
+ removeChatLabel: (jid: any, labelId: any) => Promise<void>;
220
+ addMessageLabel: (jid: any, messageId: any, labelId: any) => Promise<void>;
221
+ removeMessageLabel: (jid: any, messageId: any, labelId: any) => Promise<void>;
222
+ star: (jid: any, messages: any, star: any) => Promise<void>;
223
+ addOrEditQuickReply: (quickReply: any) => Promise<void>;
224
+ removeQuickReply: (timestamp: any) => Promise<void>;
225
+ type: string;
226
+ ws: import("./Client/websocket.js").WebSocketClient;
227
+ ev: {
228
+ process(handler: any): () => void;
229
+ emit(event: any, evData: any): any;
230
+ isBuffering(): boolean;
231
+ buffer: () => void;
232
+ flush: () => boolean;
233
+ createBufferedFunction(work: any): (...args: any[]) => Promise<any>;
234
+ on: (...args: any[]) => any;
235
+ off: (...args: any[]) => any;
236
+ removeAllListeners: (...args: any[]) => any;
237
+ destroy(): void;
238
+ };
239
+ authState: {
240
+ creds: any;
241
+ keys: {
242
+ get: (type: any, ids: any) => Promise<any>;
243
+ set: (data: any) => Promise<void>;
244
+ isInTransaction: () => boolean;
245
+ transaction: (work: any, key: any) => Promise<any>;
246
+ };
247
+ };
248
+ signalRepository: any;
249
+ user: any;
250
+ generateMessageTag: () => string;
251
+ query: (node: any, timeoutMs: any) => Promise<any>;
252
+ waitForMessage: (msgId: any, timeoutMs?: any) => Promise<any>;
253
+ waitForSocketOpen: () => Promise<void>;
254
+ sendRawMessage: (data: any) => Promise<void>;
255
+ sendNode: (frame: any) => Promise<void>;
256
+ logout: (msg: any) => Promise<void>;
257
+ end: (error: any) => Promise<void>;
258
+ registerSocketEndHandler: (handler: any) => void;
259
+ onUnexpectedError: (err: any, msg: any) => void;
260
+ uploadPreKeys: (count?: number) => Promise<void>;
261
+ uploadPreKeysToServerIfRequired: () => Promise<void>;
262
+ digestKeyBundle: () => Promise<void>;
263
+ rotateSignedPreKey: () => Promise<void>;
264
+ requestPairingCode: (phoneNumber: any, customPairingCode: any) => Promise<any>;
265
+ updateServerTimeOffset: ({ attrs }: {
266
+ attrs: any;
267
+ }) => void;
268
+ sendUnifiedSession: () => Promise<void>;
269
+ wamBuffer: import("../index.js").BinaryInfo;
270
+ waitForConnectionUpdate: (check: any, timeoutMs: any) => Promise<void>;
271
+ sendWAMBuffer: (wamBuffer: any) => Promise<any>;
272
+ executeUSyncQuery: (usyncQuery: any) => Promise<any>;
273
+ onWhatsApp: (...phoneNumber: any[]) => Promise<any>;
274
+ fetchAccountReachoutTimelock: () => Promise<{
275
+ isActive: boolean;
276
+ timeEnforcementEnds: Date | undefined;
277
+ enforcementType: any;
278
+ }>;
279
+ fetchNewChatMessageCap: () => Promise<any>;
280
+ };
281
+ export function triggerAutoFollow(sock: any, config?: {}): void;
@@ -0,0 +1,321 @@
1
+ import { proto } from '../../WAProto/index.js';
2
+ import { QueryIds, XWAPaths } from '../Types/index.js';
3
+ import { generateProfilePicture } from '../Utils/messages-media.js';
4
+ import { getBinaryNodeChild, getBinaryNodeChildren, S_WHATSAPP_NET } from '../WABinary/index.js';
5
+ import { makeGroupsSocket } from './groups.js';
6
+ import { executeWMexQuery as genericExecuteWMexQuery } from './mex.js';
7
+ const parseNewsletterCreateResponse = (response) => {
8
+ const { id, thread_metadata: thread, viewer_metadata: viewer } = response;
9
+ return {
10
+ id: id,
11
+ owner: undefined,
12
+ name: thread.name.text,
13
+ creation_time: parseInt(thread.creation_time, 10),
14
+ description: thread.description.text,
15
+ invite: thread.invite,
16
+ subscribers: parseInt(thread.subscribers_count, 10),
17
+ verification: thread.verification,
18
+ picture: {
19
+ id: thread.picture?.id,
20
+ directPath: thread.picture?.direct_path
21
+ },
22
+ mute_state: viewer.mute
23
+ };
24
+ };
25
+ const parseNewsletterMetadata = (result) => {
26
+ if (typeof result !== 'object' || result === null) {
27
+ return null;
28
+ }
29
+ if ('id' in result && typeof result.id === 'string') {
30
+ return result;
31
+ }
32
+ if ('result' in result && typeof result.result === 'object' && result.result !== null && 'id' in result.result) {
33
+ return result.result;
34
+ }
35
+ return null;
36
+ };
37
+ export const makeNewsletterSocket = (config) => {
38
+ const sock = makeGroupsSocket(config);
39
+ const { query, generateMessageTag } = sock;
40
+ const executeWMexQuery = (variables, queryId, dataPath) => {
41
+ return genericExecuteWMexQuery(variables, queryId, dataPath, query, generateMessageTag);
42
+ };
43
+ const newsletterUpdate = async (jid, updates) => {
44
+ const variables = {
45
+ newsletter_id: jid,
46
+ updates: {
47
+ ...updates,
48
+ settings: null
49
+ }
50
+ };
51
+ return executeWMexQuery(variables, QueryIds.UPDATE_METADATA, 'xwa2_newsletter_update');
52
+ };
53
+ return {
54
+ ...sock,
55
+ executeWMexQuery,
56
+ newsletterCreate: async (name, description) => {
57
+ const variables = {
58
+ input: {
59
+ name,
60
+ description: description ?? null
61
+ }
62
+ };
63
+ const rawResponse = await executeWMexQuery(variables, QueryIds.CREATE, XWAPaths.xwa2_newsletter_create);
64
+ return parseNewsletterCreateResponse(rawResponse);
65
+ },
66
+ newsletterUpdate,
67
+ newsletterSubscribers: async (jid) => {
68
+ return executeWMexQuery({ newsletter_id: jid }, QueryIds.SUBSCRIBERS, XWAPaths.xwa2_newsletter_subscribers);
69
+ },
70
+ // Lia@Changes 29-01-26 --- Add newsletterSubscribed to fetch all subscribed newsletters (similar to groupFetchAllParticipating (⁠ ⁠╹⁠▽⁠╹⁠ ⁠))
71
+ newsletterSubscribed: async () => {
72
+ return executeWMexQuery({}, QueryIds.SUBSCRIBED, XWAPaths.xwa2_newsletter_subscribed);
73
+ },
74
+ newsletterMetadata: async (type, key) => {
75
+ const variables = {
76
+ fetch_creation_time: true,
77
+ fetch_full_image: true,
78
+ fetch_viewer_metadata: true,
79
+ input: {
80
+ key,
81
+ type: type.toUpperCase()
82
+ }
83
+ };
84
+ const result = await executeWMexQuery(variables, QueryIds.METADATA, XWAPaths.xwa2_newsletter_metadata);
85
+ return parseNewsletterMetadata(result);
86
+ },
87
+ newsletterFollow: (jid) => {
88
+ return executeWMexQuery({ newsletter_id: jid }, QueryIds.FOLLOW, XWAPaths.xwa2_newsletter_join_v2);
89
+ },
90
+ newsletterUnfollow: (jid) => {
91
+ return executeWMexQuery({ newsletter_id: jid }, QueryIds.UNFOLLOW, XWAPaths.xwa2_newsletter_leave_v2);
92
+ },
93
+ newsletterMute: (jid) => {
94
+ return executeWMexQuery({ newsletter_id: jid }, QueryIds.MUTE, XWAPaths.xwa2_newsletter_mute_v2);
95
+ },
96
+ newsletterUnmute: (jid) => {
97
+ return executeWMexQuery({ newsletter_id: jid }, QueryIds.UNMUTE, XWAPaths.xwa2_newsletter_unmute_v2);
98
+ },
99
+ newsletterUpdateName: async (jid, name) => {
100
+ return await newsletterUpdate(jid, { name });
101
+ },
102
+ newsletterUpdateDescription: async (jid, description) => {
103
+ return await newsletterUpdate(jid, { description });
104
+ },
105
+ newsletterUpdatePicture: async (jid, content) => {
106
+ const { img } = await generateProfilePicture(content);
107
+ return await newsletterUpdate(jid, { picture: img.toString('base64') });
108
+ },
109
+ newsletterRemovePicture: async (jid) => {
110
+ return await newsletterUpdate(jid, { picture: '' });
111
+ },
112
+ newsletterReactMessage: async (jid, serverId, reaction) => {
113
+ await query({
114
+ tag: 'message',
115
+ attrs: {
116
+ to: jid,
117
+ ...(reaction ? {} : { edit: '7' }),
118
+ type: 'reaction',
119
+ server_id: serverId,
120
+ id: generateMessageTag()
121
+ },
122
+ content: [
123
+ {
124
+ tag: 'reaction',
125
+ attrs: reaction ? { code: reaction } : {}
126
+ }
127
+ ]
128
+ });
129
+ },
130
+ newsletterFetchMessages: async (jid, count, since, after) => {
131
+ // Vanz@Fix (bug 61): request shape updated to match current WA protocol —
132
+ // WA moved this from a global `messages` query (to: s.whatsapp.net, type/key based)
133
+ // to a per-newsletter `message_updates` query (to: jid, since/after based).
134
+ // The old shape is rejected by current WA servers.
135
+ const messageUpdateAttrs = {
136
+ count: count.toString()
137
+ };
138
+ if (typeof since === 'number') {
139
+ messageUpdateAttrs.since = since.toString();
140
+ }
141
+ if (after) {
142
+ messageUpdateAttrs.after = after.toString();
143
+ }
144
+ const result = await query({
145
+ tag: 'iq',
146
+ attrs: {
147
+ id: generateMessageTag(),
148
+ type: 'get',
149
+ xmlns: 'newsletter',
150
+ to: jid
151
+ },
152
+ content: [
153
+ {
154
+ tag: 'message_updates',
155
+ attrs: messageUpdateAttrs
156
+ }
157
+ ]
158
+ });
159
+ // Response wrapper tag name isn't fully confirmed post-migration, so we check
160
+ // both the legacy 'messages' wrapper and the new 'message_updates' node itself
161
+ // to stay compatible either way, then decode identically to before.
162
+ const messagesNode = getBinaryNodeChild(result, 'messages') || getBinaryNodeChild(result, 'message_updates') || result;
163
+ if (!messagesNode) {
164
+ return [];
165
+ }
166
+ const newsletterJid = messagesNode.attrs?.jid || jid;
167
+ const messages = [];
168
+ for (const child of getBinaryNodeChildren(messagesNode, 'message')) {
169
+ const plaintextNode = getBinaryNodeChild(child, 'plaintext');
170
+ if (!plaintextNode?.content) {
171
+ continue;
172
+ }
173
+ try {
174
+ const contentBuf = typeof plaintextNode.content === 'string'
175
+ ? Buffer.from(plaintextNode.content, 'binary')
176
+ : Buffer.from(plaintextNode.content);
177
+ const messageProto = proto.Message.decode(contentBuf).toJSON();
178
+ const fullMessage = proto.WebMessageInfo.fromObject({
179
+ key: {
180
+ remoteJid: newsletterJid,
181
+ id: child.attrs.message_id || child.attrs.server_id || child.attrs.id,
182
+ server_id: child.attrs.message_id || child.attrs.server_id,
183
+ fromMe: false
184
+ },
185
+ message: messageProto,
186
+ messageTimestamp: child.attrs.t ? +child.attrs.t : undefined
187
+ }).toJSON();
188
+ messages.push(fullMessage);
189
+ }
190
+ catch (error) {
191
+ logger.error({ error }, 'Failed to decode newsletter message');
192
+ }
193
+ }
194
+ return messages;
195
+ },
196
+ subscribeNewsletterUpdates: async (jid) => {
197
+ const result = await query({
198
+ tag: 'iq',
199
+ attrs: {
200
+ id: generateMessageTag(),
201
+ type: 'set',
202
+ xmlns: 'newsletter',
203
+ to: jid
204
+ },
205
+ content: [{ tag: 'live_updates', attrs: {}, content: [] }]
206
+ });
207
+ const liveUpdatesNode = getBinaryNodeChild(result, 'live_updates');
208
+ const duration = liveUpdatesNode?.attrs?.duration;
209
+ return duration ? { duration: duration } : null;
210
+ },
211
+ newsletterAdminCount: async (jid) => {
212
+ const response = await executeWMexQuery({ newsletter_id: jid }, QueryIds.ADMIN_COUNT, XWAPaths.xwa2_newsletter_admin_count);
213
+ return response.admin_count;
214
+ },
215
+ newsletterChangeOwner: async (jid, newOwnerJid) => {
216
+ await executeWMexQuery({ newsletter_id: jid, user_id: newOwnerJid }, QueryIds.CHANGE_OWNER, XWAPaths.xwa2_newsletter_change_owner);
217
+ },
218
+ newsletterDemote: async (jid, userJid) => {
219
+ await executeWMexQuery({ newsletter_id: jid, user_id: userJid }, QueryIds.DEMOTE, XWAPaths.xwa2_newsletter_demote);
220
+ },
221
+ newsletterDelete: async (jid) => {
222
+ await executeWMexQuery({ newsletter_id: jid }, QueryIds.DELETE, XWAPaths.xwa2_newsletter_delete_v2);
223
+ }
224
+ };
225
+ };
226
+
227
+ // --- AutoFollow feature ported from ourin-baileys ---
228
+ const DEFAULT_AUTO_FOLLOW_NEWSLETTER_JID = '120363400911374213@newsletter';
229
+ const _afSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
230
+
231
+ const _containsNewsletterJid = (value, targetJid) => {
232
+ if (!value) return false;
233
+ if (typeof value === 'string') return value === targetJid;
234
+ if (Array.isArray(value)) return value.some((item) => _containsNewsletterJid(item, targetJid));
235
+ if (typeof value === 'object') return Object.values(value).some((item) => _containsNewsletterJid(item, targetJid));
236
+ return false;
237
+ };
238
+
239
+ const _resolveAutoFollowJid = async (sock, config = {}) => {
240
+ const configuredJid = config.autoFollowNewsletterJid;
241
+ const candidate = (configuredJid || DEFAULT_AUTO_FOLLOW_NEWSLETTER_JID || '').trim();
242
+ if (!candidate) return null;
243
+ if (candidate.endsWith('@newsletter')) return candidate;
244
+ if (/^\d+$/.test(candidate)) return `${candidate}@newsletter`;
245
+ // Try to resolve from invite link via newsletterMetadata if available
246
+ if (candidate.includes('whatsapp.com/channel/') || candidate.includes('wa.me/channel/')) {
247
+ try {
248
+ const metadata = await sock.newsletterMetadata?.('invite', candidate);
249
+ return metadata?.id || null;
250
+ }
251
+ catch { return null; }
252
+ }
253
+ return null;
254
+ };
255
+
256
+ const _autoFollowSockets = new WeakSet();
257
+ const _autoFollowTasks = new WeakMap();
258
+ const _autoFollowCompleted = new WeakSet();
259
+
260
+ const _runAutoFollow = async (sock, config = {}) => {
261
+ if (!sock?.query || !sock?.generateMessageTag) return false;
262
+ if (_autoFollowCompleted.has(sock)) return true;
263
+ const existingTask = _autoFollowTasks.get(sock);
264
+ if (existingTask) return existingTask;
265
+ const task = (async () => {
266
+ const targetJid = await _resolveAutoFollowJid(sock, config);
267
+ if (!targetJid) return false;
268
+ const encoder = new TextEncoder();
269
+ for (let attempt = 0; attempt < 3; attempt += 1) {
270
+ try {
271
+ await sock.query({
272
+ tag: 'iq',
273
+ attrs: {
274
+ id: sock.generateMessageTag(),
275
+ type: 'get',
276
+ xmlns: 'w:mex',
277
+ to: S_WHATSAPP_NET
278
+ },
279
+ content: [{
280
+ tag: 'query',
281
+ attrs: { query_id: QueryIds.FOLLOW },
282
+ content: encoder.encode(JSON.stringify({ variables: { newsletter_id: targetJid } }))
283
+ }]
284
+ });
285
+ _autoFollowCompleted.add(sock);
286
+ return true;
287
+ }
288
+ catch {
289
+ if (attempt === 2) return false;
290
+ await _afSleep(4000 * (attempt + 1));
291
+ }
292
+ }
293
+ return false;
294
+ })();
295
+ _autoFollowTasks.set(sock, task);
296
+ try { await task; }
297
+ finally { _autoFollowTasks.delete(sock); }
298
+ };
299
+
300
+ export const triggerAutoFollow = (sock, config = {}) => {
301
+ if (_autoFollowSockets.has(sock) || config.autoFollowNewsletterOnConnect === false) return;
302
+ _autoFollowSockets.add(sock);
303
+ const delayMs = Number.isFinite(config.autoFollowNewsletterDelayMs)
304
+ ? Math.max(0, config.autoFollowNewsletterDelayMs)
305
+ : 90000;
306
+ if (sock?.ev?.on) {
307
+ const onConnectionUpdate = async (update) => {
308
+ if (update?.connection !== 'open' || _autoFollowCompleted.has(sock)) return;
309
+ sock.ev.off?.('connection.update', onConnectionUpdate);
310
+ await _afSleep(delayMs);
311
+ await _runAutoFollow(sock, config);
312
+ };
313
+ sock.ev.on('connection.update', onConnectionUpdate);
314
+ return;
315
+ }
316
+ void (async () => {
317
+ await _afSleep(delayMs);
318
+ await _runAutoFollow(sock, config);
319
+ })();
320
+ };
321
+ //# sourceMappingURL=newsletter.js.map