@vanzxysenpai/baileys 0.0.0-stage → 0.0.2

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 (431) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/LICENSE +25 -0
  3. package/NOTICE.md +158 -0
  4. package/README.md +5294 -2
  5. package/VanzxyBanner.js +134 -0
  6. package/WAProto/index.d.ts +13317 -0
  7. package/WAProto/index.js +147553 -0
  8. package/lib/Builders/A2UI.d.ts +131 -0
  9. package/lib/Builders/A2UI.js +343 -0
  10. package/lib/Builders/AIRich.d.ts +1021 -0
  11. package/lib/Builders/AIRich.js +2889 -0
  12. package/lib/Builders/Album.d.ts +51 -0
  13. package/lib/Builders/Album.js +99 -0
  14. package/lib/Builders/Button.d.ts +137449 -0
  15. package/lib/Builders/Button.js +1054 -0
  16. package/lib/Builders/ButtonV2.d.ts +43 -0
  17. package/lib/Builders/ButtonV2.js +175 -0
  18. package/lib/Builders/ButtonV3.d.ts +35 -0
  19. package/lib/Builders/ButtonV3.js +189 -0
  20. package/lib/Builders/Carousel.d.ts +68 -0
  21. package/lib/Builders/Carousel.js +161 -0
  22. package/lib/Builders/Event.d.ts +61 -0
  23. package/lib/Builders/Event.js +118 -0
  24. package/lib/Builders/Expiring.d.ts +17 -0
  25. package/lib/Builders/Expiring.js +27 -0
  26. package/lib/Builders/Poll.d.ts +63 -0
  27. package/lib/Builders/Poll.js +139 -0
  28. package/lib/Builders/VanzxyBaileys.d.ts +42 -0
  29. package/lib/Builders/VanzxyBaileys.js +110 -0
  30. package/lib/Builders/errors.d.ts +25 -0
  31. package/lib/Builders/errors.js +29 -0
  32. package/lib/Builders/index.d.ts +14 -0
  33. package/lib/Builders/index.js +23 -0
  34. package/lib/Builders/shared.d.ts +395 -0
  35. package/lib/Builders/shared.js +738 -0
  36. package/lib/Defaults/bot-jid.d.ts +1 -0
  37. package/lib/Defaults/bot-jid.js +1 -0
  38. package/lib/Defaults/index.d.ts +161 -0
  39. package/lib/Defaults/index.js +165 -0
  40. package/lib/Defaults/version.d.ts +1 -0
  41. package/lib/Defaults/version.js +1 -0
  42. package/lib/Framework/Bot.d.ts +865 -0
  43. package/lib/Framework/Bot.js +230 -0
  44. package/lib/Framework/Context.d.ts +17 -0
  45. package/lib/Framework/Context.js +90 -0
  46. package/lib/Framework/MediaManager.d.ts +15 -0
  47. package/lib/Framework/MediaManager.js +154 -0
  48. package/lib/Framework/SessionManager.d.ts +10 -0
  49. package/lib/Framework/SessionManager.js +34 -0
  50. package/lib/Framework/StatsManager.d.ts +20 -0
  51. package/lib/Framework/StatsManager.js +117 -0
  52. package/lib/Framework/Store/SQLiteStore.d.ts +13 -0
  53. package/lib/Framework/Store/SQLiteStore.js +68 -0
  54. package/lib/Framework/index.d.ts +6 -0
  55. package/lib/Framework/index.js +11 -0
  56. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  57. package/lib/Signal/Group/ciphertext-message.js +11 -0
  58. package/lib/Signal/Group/group-session-builder.d.ts +7 -0
  59. package/lib/Signal/Group/group-session-builder.js +29 -0
  60. package/lib/Signal/Group/group_cipher.d.ts +10 -0
  61. package/lib/Signal/Group/group_cipher.js +81 -0
  62. package/lib/Signal/Group/index.d.ts +11 -0
  63. package/lib/Signal/Group/index.js +11 -0
  64. package/lib/Signal/Group/keyhelper.d.ts +6 -0
  65. package/lib/Signal/Group/keyhelper.js +17 -0
  66. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  67. package/lib/Signal/Group/sender-chain-key.js +25 -0
  68. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  69. package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
  70. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  71. package/lib/Signal/Group/sender-key-message.js +65 -0
  72. package/lib/Signal/Group/sender-key-name.d.ts +11 -0
  73. package/lib/Signal/Group/sender-key-name.js +47 -0
  74. package/lib/Signal/Group/sender-key-record.d.ts +12 -0
  75. package/lib/Signal/Group/sender-key-record.js +40 -0
  76. package/lib/Signal/Group/sender-key-state.d.ts +16 -0
  77. package/lib/Signal/Group/sender-key-state.js +83 -0
  78. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  79. package/lib/Signal/Group/sender-message-key.js +25 -0
  80. package/lib/Signal/libsignal.d.ts +58 -0
  81. package/lib/Signal/libsignal.js +436 -0
  82. package/lib/Signal/lid-mapping.d.ts +20 -0
  83. package/lib/Signal/lid-mapping.js +276 -0
  84. package/lib/Socket/Client/index.d.ts +2 -0
  85. package/lib/Socket/Client/index.js +2 -0
  86. package/lib/Socket/Client/types.d.ts +5 -0
  87. package/lib/Socket/Client/types.js +10 -0
  88. package/lib/Socket/Client/websocket.d.ts +12 -0
  89. package/lib/Socket/Client/websocket.js +53 -0
  90. package/lib/Socket/business.d.ts +674 -0
  91. package/lib/Socket/business.js +379 -0
  92. package/lib/Socket/chats.d.ts +137 -0
  93. package/lib/Socket/chats.js +1299 -0
  94. package/lib/Socket/communities.d.ts +805 -0
  95. package/lib/Socket/communities.js +454 -0
  96. package/lib/Socket/dugong.d.ts +118 -0
  97. package/lib/Socket/dugong.js +810 -0
  98. package/lib/Socket/groups.d.ts +287 -0
  99. package/lib/Socket/groups.js +386 -0
  100. package/lib/Socket/index.d.ts +826 -0
  101. package/lib/Socket/index.js +35 -0
  102. package/lib/Socket/messages-recv.d.ts +613 -0
  103. package/lib/Socket/messages-recv.js +1851 -0
  104. package/lib/Socket/messages-send.d.ts +608 -0
  105. package/lib/Socket/messages-send.js +1574 -0
  106. package/lib/Socket/mex-fallback.d.ts +51 -0
  107. package/lib/Socket/mex-fallback.js +97 -0
  108. package/lib/Socket/mex.d.ts +1 -0
  109. package/lib/Socket/mex.js +41 -0
  110. package/lib/Socket/newsletter-ext.d.ts +47 -0
  111. package/lib/Socket/newsletter-ext.js +262 -0
  112. package/lib/Socket/newsletter.d.ts +285 -0
  113. package/lib/Socket/newsletter.js +223 -0
  114. package/lib/Socket/socket.d.ts +60 -0
  115. package/lib/Socket/socket.js +1001 -0
  116. package/lib/Socket/username.d.ts +842 -0
  117. package/lib/Socket/username.js +156 -0
  118. package/lib/Store/index.d.ts +3 -0
  119. package/lib/Store/index.js +3 -0
  120. package/lib/Store/make-in-memory-store.d.ts +62 -0
  121. package/lib/Store/make-in-memory-store.js +425 -0
  122. package/lib/Store/make-ordered-dictionary.d.ts +12 -0
  123. package/lib/Store/make-ordered-dictionary.js +78 -0
  124. package/lib/Store/object-repository.d.ts +10 -0
  125. package/lib/Store/object-repository.js +23 -0
  126. package/lib/Types/Auth.d.ts +1 -0
  127. package/lib/Types/Auth.js +1 -0
  128. package/lib/Types/Bussines.d.ts +1 -0
  129. package/lib/Types/Bussines.js +1 -0
  130. package/lib/Types/Call.d.ts +1 -0
  131. package/lib/Types/Call.js +1 -0
  132. package/lib/Types/Chat.d.ts +1 -0
  133. package/lib/Types/Chat.js +7 -0
  134. package/lib/Types/Contact.d.ts +1 -0
  135. package/lib/Types/Contact.js +1 -0
  136. package/lib/Types/Events.d.ts +1 -0
  137. package/lib/Types/Events.js +1 -0
  138. package/lib/Types/GroupMetadata.d.ts +1 -0
  139. package/lib/Types/GroupMetadata.js +1 -0
  140. package/lib/Types/Label.d.ts +2 -0
  141. package/lib/Types/Label.js +24 -0
  142. package/lib/Types/LabelAssociation.d.ts +2 -0
  143. package/lib/Types/LabelAssociation.js +6 -0
  144. package/lib/Types/Message.d.ts +11 -0
  145. package/lib/Types/Message.js +17 -0
  146. package/lib/Types/Mex.d.ts +2 -0
  147. package/lib/Types/Mex.js +38 -0
  148. package/lib/Types/Product.d.ts +1 -0
  149. package/lib/Types/Product.js +1 -0
  150. package/lib/Types/RichType.d.ts +2 -0
  151. package/lib/Types/RichType.js +22 -0
  152. package/lib/Types/Signal.d.ts +1 -0
  153. package/lib/Types/Signal.js +1 -0
  154. package/lib/Types/Socket.d.ts +1 -0
  155. package/lib/Types/Socket.js +1 -0
  156. package/lib/Types/State.d.ts +5 -0
  157. package/lib/Types/State.js +55 -0
  158. package/lib/Types/USync.d.ts +1 -0
  159. package/lib/Types/USync.js +1 -0
  160. package/lib/Types/index.d.ts +15 -0
  161. package/lib/Types/index.js +27 -0
  162. package/lib/Utils/PersistentStore.d.ts +83 -0
  163. package/lib/Utils/PersistentStore.js +592 -0
  164. package/lib/Utils/anchor-guard.d.ts +31 -0
  165. package/lib/Utils/anchor-guard.js +329 -0
  166. package/lib/Utils/android-stanza-id.d.ts +4 -0
  167. package/lib/Utils/android-stanza-id.js +21 -0
  168. package/lib/Utils/anti-delete.d.ts +62 -0
  169. package/lib/Utils/anti-delete.js +212 -0
  170. package/lib/Utils/auth-secure.d.ts +180 -0
  171. package/lib/Utils/auth-secure.js +791 -0
  172. package/lib/Utils/auth-utils.d.ts +59 -0
  173. package/lib/Utils/auth-utils.js +326 -0
  174. package/lib/Utils/auto-reconnect.d.ts +8 -0
  175. package/lib/Utils/auto-reconnect.js +204 -0
  176. package/lib/Utils/auto-reply.d.ts +35 -0
  177. package/lib/Utils/auto-reply.js +152 -0
  178. package/lib/Utils/bad-mac-handler.d.ts +59 -0
  179. package/lib/Utils/bad-mac-handler.js +119 -0
  180. package/lib/Utils/baileys-event-stream.d.ts +5 -0
  181. package/lib/Utils/baileys-event-stream.js +62 -0
  182. package/lib/Utils/browser-utils.d.ts +9 -0
  183. package/lib/Utils/browser-utils.js +29 -0
  184. package/lib/Utils/business.d.ts +49 -0
  185. package/lib/Utils/business.js +236 -0
  186. package/lib/Utils/button-helper-utils.d.ts +59 -0
  187. package/lib/Utils/button-helper-utils.js +266 -0
  188. package/lib/Utils/button-sender.d.ts +164 -0
  189. package/lib/Utils/button-sender.js +845 -0
  190. package/lib/Utils/chat-control.d.ts +98 -0
  191. package/lib/Utils/chat-control.js +231 -0
  192. package/lib/Utils/chat-history-helpers.d.ts +4 -0
  193. package/lib/Utils/chat-history-helpers.js +70 -0
  194. package/lib/Utils/chat-utils.d.ts +408 -0
  195. package/lib/Utils/chat-utils.js +879 -0
  196. package/lib/Utils/companion-reg-client-utils.d.ts +4 -0
  197. package/lib/Utils/companion-reg-client-utils.js +39 -0
  198. package/lib/Utils/connection-watchdog.d.ts +10 -0
  199. package/lib/Utils/connection-watchdog.js +74 -0
  200. package/lib/Utils/crypto.d.ts +41 -0
  201. package/lib/Utils/crypto.js +145 -0
  202. package/lib/Utils/decode-wa-message.d.ts +83 -0
  203. package/lib/Utils/decode-wa-message.js +315 -0
  204. package/lib/Utils/disconnect-reason.d.ts +13 -0
  205. package/lib/Utils/disconnect-reason.js +36 -0
  206. package/lib/Utils/event-buffer.d.ts +12 -0
  207. package/lib/Utils/event-buffer.js +640 -0
  208. package/lib/Utils/fetch-timeout.d.ts +4 -0
  209. package/lib/Utils/fetch-timeout.js +14 -0
  210. package/lib/Utils/ffmpeg-path.d.ts +5 -0
  211. package/lib/Utils/ffmpeg-path.js +130 -0
  212. package/lib/Utils/generics.d.ts +79 -0
  213. package/lib/Utils/generics.js +426 -0
  214. package/lib/Utils/group-metadata-cache.d.ts +3 -0
  215. package/lib/Utils/group-metadata-cache.js +25 -0
  216. package/lib/Utils/group-status-detection.d.ts +5 -0
  217. package/lib/Utils/group-status-detection.js +114 -0
  218. package/lib/Utils/history.d.ts +91 -0
  219. package/lib/Utils/history.js +144 -0
  220. package/lib/Utils/html-app.d.ts +14 -0
  221. package/lib/Utils/html-app.js +97 -0
  222. package/lib/Utils/html-multiplayer.d.ts +8 -0
  223. package/lib/Utils/html-multiplayer.js +90 -0
  224. package/lib/Utils/humanizer.d.ts +8 -0
  225. package/lib/Utils/humanizer.js +74 -0
  226. package/lib/Utils/identity-change-handler.d.ts +13 -0
  227. package/lib/Utils/identity-change-handler.js +49 -0
  228. package/lib/Utils/index.d.ts +88 -0
  229. package/lib/Utils/index.js +93 -0
  230. package/lib/Utils/jid-tools.d.ts +3 -0
  231. package/lib/Utils/jid-tools.js +78 -0
  232. package/lib/Utils/link-preview-metadata.d.ts +47 -0
  233. package/lib/Utils/link-preview-metadata.js +90 -0
  234. package/lib/Utils/link-preview.d.ts +12 -0
  235. package/lib/Utils/link-preview.js +84 -0
  236. package/lib/Utils/lock-manager.d.ts +5 -0
  237. package/lib/Utils/lock-manager.js +50 -0
  238. package/lib/Utils/logger.d.ts +2 -0
  239. package/lib/Utils/logger.js +2 -0
  240. package/lib/Utils/lt-hash.d.ts +12 -0
  241. package/lib/Utils/lt-hash.js +26 -0
  242. package/lib/Utils/make-mutex.d.ts +6 -0
  243. package/lib/Utils/make-mutex.js +32 -0
  244. package/lib/Utils/media-messages.d.ts +35 -0
  245. package/lib/Utils/media-messages.js +70 -0
  246. package/lib/Utils/media-processor.d.ts +6 -0
  247. package/lib/Utils/media-processor.js +174 -0
  248. package/lib/Utils/media-set.d.ts +6 -0
  249. package/lib/Utils/media-set.js +169 -0
  250. package/lib/Utils/message-kind.d.ts +26 -0
  251. package/lib/Utils/message-kind.js +138 -0
  252. package/lib/Utils/message-retry-manager.d.ts +79 -0
  253. package/lib/Utils/message-retry-manager.js +264 -0
  254. package/lib/Utils/message-search.d.ts +40 -0
  255. package/lib/Utils/message-search.js +181 -0
  256. package/lib/Utils/messages-media.d.ts +136 -0
  257. package/lib/Utils/messages-media.js +867 -0
  258. package/lib/Utils/messages.d.ts +66 -0
  259. package/lib/Utils/messages.js +2271 -0
  260. package/lib/Utils/meta-ai-msmsg.d.ts +3 -0
  261. package/lib/Utils/meta-ai-msmsg.js +132 -0
  262. package/lib/Utils/meta-ai.d.ts +4 -0
  263. package/lib/Utils/meta-ai.js +75 -0
  264. package/lib/Utils/migrate-auth-state.d.ts +23 -0
  265. package/lib/Utils/migrate-auth-state.js +126 -0
  266. package/lib/Utils/mini-app.d.ts +20 -0
  267. package/lib/Utils/mini-app.js +215 -0
  268. package/lib/Utils/mock-socket.d.ts +67 -0
  269. package/lib/Utils/mock-socket.js +254 -0
  270. package/lib/Utils/modern-messages.d.ts +64 -0
  271. package/lib/Utils/modern-messages.js +497 -0
  272. package/lib/Utils/native-flow.d.ts +19 -0
  273. package/lib/Utils/native-flow.js +112 -0
  274. package/lib/Utils/newsletter-status.d.ts +157 -0
  275. package/lib/Utils/newsletter-status.js +652 -0
  276. package/lib/Utils/noise-handler.d.ts +20 -0
  277. package/lib/Utils/noise-handler.js +200 -0
  278. package/lib/Utils/offline-node-processor.d.ts +9 -0
  279. package/lib/Utils/offline-node-processor.js +39 -0
  280. package/lib/Utils/pairing-utils.d.ts +5 -0
  281. package/lib/Utils/pairing-utils.js +29 -0
  282. package/lib/Utils/passkey.d.ts +4 -0
  283. package/lib/Utils/passkey.js +11 -0
  284. package/lib/Utils/past-participants.d.ts +2 -0
  285. package/lib/Utils/past-participants.js +40 -0
  286. package/lib/Utils/payment-detection.d.ts +40 -0
  287. package/lib/Utils/payment-detection.js +213 -0
  288. package/lib/Utils/payment-guard.d.ts +28 -0
  289. package/lib/Utils/payment-guard.js +143 -0
  290. package/lib/Utils/payment-messages.d.ts +42 -0
  291. package/lib/Utils/payment-messages.js +161 -0
  292. package/lib/Utils/payment-utils.d.ts +75 -0
  293. package/lib/Utils/payment-utils.js +145 -0
  294. package/lib/Utils/phone-utils.d.ts +3 -0
  295. package/lib/Utils/phone-utils.js +29 -0
  296. package/lib/Utils/pre-key-manager.d.ts +25 -0
  297. package/lib/Utils/pre-key-manager.js +105 -0
  298. package/lib/Utils/process-message.d.ts +103 -0
  299. package/lib/Utils/process-message.js +868 -0
  300. package/lib/Utils/qr-terminal.d.ts +1 -0
  301. package/lib/Utils/qr-terminal.js +16 -0
  302. package/lib/Utils/reconnect-backoff.d.ts +25 -0
  303. package/lib/Utils/reconnect-backoff.js +47 -0
  304. package/lib/Utils/reporting-utils.d.ts +12 -0
  305. package/lib/Utils/reporting-utils.js +257 -0
  306. package/lib/Utils/rich-message-utils.d.ts +54 -0
  307. package/lib/Utils/rich-message-utils.js +435 -0
  308. package/lib/Utils/rich-messages.d.ts +298 -0
  309. package/lib/Utils/rich-messages.js +1145 -0
  310. package/lib/Utils/scheduled-message.d.ts +81 -0
  311. package/lib/Utils/scheduled-message.js +101 -0
  312. package/lib/Utils/scheduling.d.ts +59 -0
  313. package/lib/Utils/scheduling.js +139 -0
  314. package/lib/Utils/signal.d.ts +82 -0
  315. package/lib/Utils/signal.js +200 -0
  316. package/lib/Utils/stanza-ack.d.ts +16 -0
  317. package/lib/Utils/stanza-ack.js +37 -0
  318. package/lib/Utils/status-stickers.d.ts +79 -0
  319. package/lib/Utils/status-stickers.js +261 -0
  320. package/lib/Utils/status.d.ts +107 -0
  321. package/lib/Utils/status.js +131 -0
  322. package/lib/Utils/sticker-pack-maker.d.ts +20 -0
  323. package/lib/Utils/sticker-pack-maker.js +112 -0
  324. package/lib/Utils/stickerpack.d.ts +18 -0
  325. package/lib/Utils/stickerpack.js +316 -0
  326. package/lib/Utils/sync-action-utils.d.ts +2 -0
  327. package/lib/Utils/sync-action-utils.js +48 -0
  328. package/lib/Utils/tag.d.ts +8 -0
  329. package/lib/Utils/tag.js +45 -0
  330. package/lib/Utils/tc-token-utils.d.ts +29 -0
  331. package/lib/Utils/tc-token-utils.js +162 -0
  332. package/lib/Utils/templates.d.ts +86 -0
  333. package/lib/Utils/templates.js +148 -0
  334. package/lib/Utils/text-format.d.ts +13 -0
  335. package/lib/Utils/text-format.js +81 -0
  336. package/lib/Utils/text-tools.d.ts +3 -0
  337. package/lib/Utils/text-tools.js +38 -0
  338. package/lib/Utils/ttl-cache.d.ts +29 -0
  339. package/lib/Utils/ttl-cache.js +123 -0
  340. package/lib/Utils/use-cache-manager-auth-state.d.ts +22 -0
  341. package/lib/Utils/use-cache-manager-auth-state.js +86 -0
  342. package/lib/Utils/use-multi-file-auth-state.d.ts +20 -0
  343. package/lib/Utils/use-multi-file-auth-state.js +201 -0
  344. package/lib/Utils/use-single-file-auth-state.d.ts +10 -0
  345. package/lib/Utils/use-single-file-auth-state.js +111 -0
  346. package/lib/Utils/use-sqlite-auth-state.d.ts +13 -0
  347. package/lib/Utils/use-sqlite-auth-state.js +171 -0
  348. package/lib/Utils/username.d.ts +22 -0
  349. package/lib/Utils/username.js +59 -0
  350. package/lib/Utils/validate-connection.d.ts +43 -0
  351. package/lib/Utils/validate-connection.js +197 -0
  352. package/lib/Utils/vcard.d.ts +40 -0
  353. package/lib/Utils/vcard.js +92 -0
  354. package/lib/Utils/voice-note.d.ts +13 -0
  355. package/lib/Utils/voice-note.js +47 -0
  356. package/lib/VoIP/audio-feeder.d.ts +15 -0
  357. package/lib/VoIP/audio-feeder.js +132 -0
  358. package/lib/VoIP/index.d.ts +22 -0
  359. package/lib/VoIP/index.js +277 -0
  360. package/lib/VoIP/relay-transport.d.ts +16 -0
  361. package/lib/VoIP/relay-transport.js +559 -0
  362. package/lib/VoIP/signaling.d.ts +16 -0
  363. package/lib/VoIP/signaling.js +624 -0
  364. package/lib/VoIP/types.d.ts +11 -0
  365. package/lib/VoIP/types.js +17 -0
  366. package/lib/VoIP/wasm-engine.d.ts +28 -0
  367. package/lib/VoIP/wasm-engine.js +1214 -0
  368. package/lib/VoIP/worker-bootstrap.d.ts +1 -0
  369. package/lib/VoIP/worker-bootstrap.js +1042 -0
  370. package/lib/WABinary/constants.d.ts +61 -0
  371. package/lib/WABinary/constants.js +1466 -0
  372. package/lib/WABinary/decode.d.ts +9 -0
  373. package/lib/WABinary/decode.js +261 -0
  374. package/lib/WABinary/encode.d.ts +2 -0
  375. package/lib/WABinary/encode.js +219 -0
  376. package/lib/WABinary/generic-utils.d.ts +45 -0
  377. package/lib/WABinary/generic-utils.js +285 -0
  378. package/lib/WABinary/index.d.ts +5 -0
  379. package/lib/WABinary/index.js +5 -0
  380. package/lib/WABinary/jid-utils.d.ts +32 -0
  381. package/lib/WABinary/jid-utils.js +102 -0
  382. package/lib/WABinary/types.d.ts +1 -0
  383. package/lib/WABinary/types.js +1 -0
  384. package/lib/WAM/BinaryInfo.d.ts +7 -0
  385. package/lib/WAM/BinaryInfo.js +9 -0
  386. package/lib/WAM/constants.d.ts +34926 -0
  387. package/lib/WAM/constants.js +22852 -0
  388. package/lib/WAM/encode.d.ts +1 -0
  389. package/lib/WAM/encode.js +149 -0
  390. package/lib/WAM/index.d.ts +3 -0
  391. package/lib/WAM/index.js +3 -0
  392. package/lib/WAUSync/Protocols/USyncBusinessProtocol.d.ts +43 -0
  393. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +32 -0
  394. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
  395. package/lib/WAUSync/Protocols/USyncContactProtocol.js +51 -0
  396. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +29 -0
  397. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +60 -0
  398. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  399. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
  400. package/lib/WAUSync/Protocols/USyncFeatureProtocol.d.ts +13 -0
  401. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +28 -0
  402. package/lib/WAUSync/Protocols/USyncPictureProtocol.d.ts +22 -0
  403. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +28 -0
  404. package/lib/WAUSync/Protocols/USyncSidelistProtocol.d.ts +20 -0
  405. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +23 -0
  406. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  407. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
  408. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.d.ts +14 -0
  409. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +24 -0
  410. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
  411. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
  412. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
  413. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +49 -0
  414. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
  415. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
  416. package/lib/WAUSync/Protocols/index.d.ts +12 -0
  417. package/lib/WAUSync/Protocols/index.js +12 -0
  418. package/lib/WAUSync/USyncQuery.d.ts +25 -0
  419. package/lib/WAUSync/USyncQuery.js +140 -0
  420. package/lib/WAUSync/USyncUser.d.ts +24 -0
  421. package/lib/WAUSync/USyncUser.js +47 -0
  422. package/lib/WAUSync/index.d.ts +3 -0
  423. package/lib/WAUSync/index.js +3 -0
  424. package/lib/assets/wasm/loader.js +5 -0
  425. package/lib/assets/wasm/whatsapp.wasm +0 -0
  426. package/lib/assets/wasm/worker-modules.js +273 -0
  427. package/lib/exports-extra.d.ts +45 -0
  428. package/lib/exports-extra.js +47 -0
  429. package/lib/index.d.ts +16 -0
  430. package/lib/index.js +24 -0
  431. package/package.json +161 -4
@@ -0,0 +1,652 @@
1
+ // Vanz@Port --- ported from @rexxhayanasi/elaina-baileys 1.3.10 (newsletter-status.js). Creator credits untouched. See NOTICE.md.
2
+ import { proto } from '../../WAProto/index.js'
3
+ import { encodeNewsletterMessage, generateMessageIDV2 } from './generics.js'
4
+ import { generateWAMessage, normalizeMessageContent } from './messages.js'
5
+ import { prepareModernMessageContent } from './modern-messages.js'
6
+ import { WAMessageStatus } from '../Types/Message.js'
7
+ import { getBinaryNodeChild, getBinaryNodeChildren, S_WHATSAPP_NET } from '../WABinary/index.js'
8
+ import { isJidNewsletter } from '../WABinary/jid-utils.js'
9
+
10
+ const NEWSLETTER_STATUS_MEDIA_TYPES = new Set(['audio', 'gif', 'image', 'video'])
11
+ const NEWSLETTER_STATUS_WEB_MEDIA_TYPES = new Set(['image', 'video'])
12
+ const NEWSLETTER_STATUS_INTERACTIONS = new Set(['question', 'question_response', 'question_reshare'])
13
+ const NEWSLETTER_STATUS_CONTENT_TYPES = new Set(['text', 'media', 'reaction'])
14
+ const NEWSLETTER_STATUS_CALLBACK_EVENTS = ['CB:ack', 'CB:status', 'CB:iq', 'CB:notification', 'CB:message']
15
+ const NEWSLETTER_STATUS_EDIT_REACTION_REVOKE = '7'
16
+ const NEWSLETTER_STATUS_EDIT_ADMIN_REVOKE = '8'
17
+ const NEWSLETTER_STATUS_ACK_CLASS = 'status'
18
+ const NEWSLETTER_STATUS_ACK_TIMEOUT_MS = 20000
19
+ const NEWSLETTER_STATUS_SERVER_ID_TIMEOUT_MS = 8000
20
+
21
+ export const getNewsletterStatusMediaType = message => {
22
+ const content = normalizeMessageContent(message)
23
+ if (content?.imageMessage) return 'image'
24
+ if (content?.videoMessage) return content.videoMessage.gifPlayback ? 'gif' : 'video'
25
+ if (content?.audioMessage) return 'audio'
26
+ return undefined
27
+ }
28
+
29
+ const assertNewsletterJid = jid => {
30
+ if (!isJidNewsletter(jid)) throw new TypeError('Newsletter status target must be a @newsletter JID')
31
+ }
32
+
33
+ const assertInteraction = interactionType => {
34
+ if (interactionType !== undefined && !NEWSLETTER_STATUS_INTERACTIONS.has(interactionType)) {
35
+ throw new TypeError(`Unsupported newsletter status interaction: ${interactionType}`)
36
+ }
37
+ }
38
+
39
+ const assertMediaType = mediaType => {
40
+ if (mediaType !== undefined && !NEWSLETTER_STATUS_MEDIA_TYPES.has(mediaType)) {
41
+ throw new TypeError(`Unsupported newsletter status media type: ${mediaType}`)
42
+ }
43
+ }
44
+
45
+ const isPresent = value => value !== undefined && value !== null && value !== ''
46
+
47
+ const NEWSLETTER_SERVER_ID_MIN = 99
48
+ const NEWSLETTER_SERVER_ID_MAX = 2147476647
49
+
50
+ const toNewsletterServerId = (value, label) => {
51
+ const parsed = typeof value === 'number' ? value : Number(String(value).trim())
52
+ if (!Number.isInteger(parsed) || parsed < NEWSLETTER_SERVER_ID_MIN || parsed > NEWSLETTER_SERVER_ID_MAX) {
53
+ throw new TypeError(`${JSON.stringify(value)} is not a newsletter server id${label ? ` for ${label}` : ''}; the server accepts ${NEWSLETTER_SERVER_ID_MIN}..${NEWSLETTER_SERVER_ID_MAX}, and you get one from newsletterFetchMessages or a sent status`)
54
+ }
55
+ return String(parsed)
56
+ }
57
+
58
+ const toServerId = (value, label) => toNewsletterServerId(value, label)
59
+
60
+ const buildMetaNode = ({ interactionType, parentServerId, responseServerId, aiContent }) => {
61
+ assertInteraction(interactionType)
62
+
63
+ const attrs = {}
64
+ if (interactionType) {
65
+ attrs.interaction_type = interactionType
66
+ if (interactionType === 'question_reshare') {
67
+ if (!isPresent(parentServerId)) throw new TypeError('question_reshare requires parentServerId')
68
+ if (!isPresent(responseServerId)) throw new TypeError('question_reshare requires responseServerId')
69
+ attrs.parent_server_id = toServerId(parentServerId, 'parentServerId')
70
+ attrs.response_server_id = String(responseServerId)
71
+ }
72
+ else if (interactionType === 'question_response' && isPresent(responseServerId)) {
73
+ attrs.response_server_id = String(responseServerId)
74
+ }
75
+ }
76
+
77
+ if (!interactionType && !aiContent) return undefined
78
+
79
+ return {
80
+ tag: 'meta',
81
+ attrs,
82
+ content: aiContent ? [{ tag: 'ai_content', attrs: {}, content: undefined }] : undefined
83
+ }
84
+ }
85
+
86
+ export const withNewsletterStatusAttribution = content => ({
87
+ ...content,
88
+ contextInfo: {
89
+ statusAttributions: [{ type: proto.StatusAttribution.Type.NEWSLETTER_STATUS }],
90
+ featureEligibilities: { canBeReshared: true },
91
+ ...(content?.contextInfo || {})
92
+ }
93
+ })
94
+
95
+ const snapshotCallbackNode = (event, node) => ({
96
+ event,
97
+ tag: node?.tag,
98
+ attrs: node?.attrs || {},
99
+ children: Array.isArray(node?.content)
100
+ ? node.content.map(child => ({ tag: child?.tag, attrs: child?.attrs || {} }))
101
+ : []
102
+ })
103
+
104
+ const collectStatusCallbacks = sock => {
105
+ const frames = []
106
+ const listeners = []
107
+
108
+ for (const event of NEWSLETTER_STATUS_CALLBACK_EVENTS) {
109
+ const listener = node => {
110
+ if (frames.length >= 40) return
111
+ frames.push(snapshotCallbackNode(event, node))
112
+ }
113
+ sock.ws.on(event, listener)
114
+ listeners.push([event, listener])
115
+ }
116
+
117
+ return {
118
+ frames,
119
+ stop: () => {
120
+ for (const [event, listener] of listeners) {
121
+ sock.ws.off(event, listener)
122
+ }
123
+ }
124
+ }
125
+ }
126
+
127
+ const readIntAttr = (attrs, key) => {
128
+ if (!isPresent(attrs?.[key])) return undefined
129
+ const parsed = Number.parseInt(String(attrs[key]), 10)
130
+ return Number.isFinite(parsed) ? parsed : undefined
131
+ }
132
+
133
+ export const parseNewsletterStatusAck = (node, { jid, messageId } = {}) => {
134
+ if (!node || typeof node !== 'object') throw new TypeError('Newsletter status ack node is required')
135
+ if (node.tag !== 'ack') {
136
+ const error = new Error(`Newsletter status expected <ack>, got <${node.tag}>`)
137
+ error.data = node
138
+ throw error
139
+ }
140
+
141
+ const attrs = node.attrs || {}
142
+ if (attrs.class !== undefined && attrs.class !== NEWSLETTER_STATUS_ACK_CLASS) {
143
+ const error = new Error(`Newsletter status ack has class "${attrs.class}", expected "${NEWSLETTER_STATUS_ACK_CLASS}"`)
144
+ error.data = node
145
+ throw error
146
+ }
147
+ if (isPresent(messageId) && isPresent(attrs.id) && attrs.id !== messageId) {
148
+ const error = new Error(`Newsletter status ack id mismatch: ${attrs.id} != ${messageId}`)
149
+ error.data = node
150
+ throw error
151
+ }
152
+ if (isPresent(jid) && isPresent(attrs.from) && attrs.from !== jid) {
153
+ const error = new Error(`Newsletter status ack from mismatch: ${attrs.from} != ${jid}`)
154
+ error.data = node
155
+ throw error
156
+ }
157
+
158
+ return {
159
+ class: attrs.class,
160
+ from: attrs.from,
161
+ id: attrs.id,
162
+ t: readIntAttr(attrs, 't'),
163
+ serverId: readIntAttr(attrs, 'server_id'),
164
+ edit: attrs.edit,
165
+ error: isPresent(attrs.error) ? String(attrs.error) : undefined,
166
+ applicationError: readIntAttr(attrs, 'application_error'),
167
+ backoff: readIntAttr(attrs, 'backoff'),
168
+ node
169
+ }
170
+ }
171
+
172
+ /**
173
+ * The ack carries from, class, id and t, and nothing else. The server id lands
174
+ * separately, in the <status> stanza the server sends back to the publisher --
175
+ * WASmaxInStatusDeliverFromNewsletterMixin reads from, server_id, t and
176
+ * is_sender off exactly that tag. Reacting to or revoking your own status needs
177
+ * that id, so wait a moment for the echo rather than returning undefined.
178
+ */
179
+ export const waitForNewsletterStatusServerId = (sock, { jid, messageId, timeoutMs = 8000 }) => {
180
+ let settle
181
+ const promise = new Promise(resolve => {
182
+ let done = false
183
+ const finish = value => {
184
+ if (done) return
185
+ done = true
186
+ clearTimeout(timer)
187
+ sock.ws.off('CB:status', onStatus)
188
+ resolve(value)
189
+ }
190
+ const onStatus = node => {
191
+ if (node?.tag !== 'status') return
192
+ const attrs = node.attrs || {}
193
+ if (isPresent(jid) && isPresent(attrs.from) && attrs.from !== jid) return
194
+ if (isPresent(messageId) && isPresent(attrs.id) && attrs.id !== messageId) return
195
+ const serverId = readIntAttr(attrs, 'server_id')
196
+ if (serverId !== undefined) finish({ serverId, node })
197
+ }
198
+ const timer = setTimeout(() => finish(undefined), timeoutMs)
199
+ sock.ws.on('CB:status', onStatus)
200
+ settle = finish
201
+ })
202
+ promise.cancel = () => settle(undefined)
203
+ return promise
204
+ }
205
+
206
+ const assertStatusServerResponse = (response, { jid, messageId, callbacks = [] }) => {
207
+ if (!response) {
208
+ const suffix = callbacks.length
209
+ ? `; callbacks=${JSON.stringify(callbacks)}`
210
+ : '; no ack/status/iq/notification/message callback observed'
211
+ const error = new Error(`Newsletter status server ACK timed out for ${messageId}${suffix}`)
212
+ error.data = { messageId, callbacks }
213
+ throw error
214
+ }
215
+
216
+ const ack = parseNewsletterStatusAck(response, { jid, messageId })
217
+ if (ack.error) {
218
+ const details = [
219
+ ack.applicationError !== undefined ? `application_error=${ack.applicationError}` : undefined,
220
+ ack.backoff !== undefined ? `backoff=${ack.backoff}` : undefined
221
+ ].filter(Boolean).join(', ')
222
+ const hint = ack.error === '403' || ack.error === '401' || ack.error === 'not-authorized' || ack.error === 'forbidden'
223
+ ? '; the channel may be missing the CHANNEL_STATUS_PRODUCER capability, check newsletterCanPostStatus(jid)'
224
+ : ''
225
+ const error = new Error(`Newsletter status rejected by server (${ack.error})${details ? `: ${details}` : ''}${hint}`)
226
+ error.data = ack
227
+ throw error
228
+ }
229
+
230
+ return ack
231
+ }
232
+
233
+ export const buildNewsletterAdminProfileStatusMessage = message => {
234
+ if (!message || typeof message !== 'object') throw new TypeError('Newsletter status message is required')
235
+ return proto.Message.create({
236
+ newsletterAdminProfileStatusMessage: proto.Message.FutureProofMessage.create({
237
+ message
238
+ })
239
+ })
240
+ }
241
+
242
+ const resolveStatusPayload = ({ message, payload }) => {
243
+ if (payload !== undefined) {
244
+ if (!(payload instanceof Uint8Array)) throw new TypeError('Newsletter status payload must be a Uint8Array')
245
+ return payload
246
+ }
247
+ if (!message || typeof message !== 'object') throw new TypeError('Newsletter status message is required')
248
+ return encodeNewsletterMessage(message)
249
+ }
250
+
251
+ export const buildNewsletterStatusNode = ({
252
+ jid,
253
+ message,
254
+ payload,
255
+ messageId,
256
+ mediaType,
257
+ mediaId,
258
+ mediaHandle,
259
+ parentServerId,
260
+ responseServerId,
261
+ interactionType,
262
+ aiContent
263
+ }) => {
264
+ assertNewsletterJid(jid)
265
+ if (!messageId) throw new TypeError('Newsletter status messageId is required')
266
+ assertMediaType(mediaType)
267
+ assertInteraction(interactionType)
268
+
269
+ const handle = isPresent(mediaHandle) ? mediaHandle : mediaId
270
+ if (isPresent(handle) && !mediaType) {
271
+ throw new TypeError('mediaId requires a media newsletter status')
272
+ }
273
+ if (mediaType && !isPresent(handle)) {
274
+ throw new TypeError('Native newsletter status media requires the media handle returned by the newsletter upload')
275
+ }
276
+ if (interactionType === 'question_reshare' && !mediaType) {
277
+ throw new TypeError('question_reshare requires media')
278
+ }
279
+ if (interactionType === 'question_response') {
280
+ if (mediaType) throw new TypeError('question_response is published as a text status')
281
+ if (!isPresent(parentServerId)) throw new TypeError('question_response requires parentServerId')
282
+ }
283
+
284
+ const attrs = {
285
+ to: jid,
286
+ id: messageId,
287
+ type: mediaType ? 'media' : 'text'
288
+ }
289
+ if (mediaType) attrs.media_id = String(handle)
290
+ if (interactionType === 'question_response') {
291
+ attrs.server_id = toServerId(parentServerId, 'parentServerId')
292
+ }
293
+
294
+ const content = [{
295
+ tag: 'plaintext',
296
+ attrs: mediaType ? { mediatype: mediaType } : {},
297
+ content: resolveStatusPayload({ message, payload })
298
+ }]
299
+
300
+ const metaNode = buildMetaNode({ interactionType, parentServerId, responseServerId, aiContent })
301
+ if (metaNode) content.push(metaNode)
302
+
303
+ return { tag: 'status', attrs, content }
304
+ }
305
+
306
+ export const buildNewsletterStatusReactionNode = ({ jid, messageId, parentServerId, reaction }) => {
307
+ assertNewsletterJid(jid)
308
+ if (!messageId) throw new TypeError('Newsletter status reaction messageId is required')
309
+ if (!isPresent(parentServerId)) {
310
+ throw new TypeError('Newsletter status reaction requires parentServerId')
311
+ }
312
+
313
+ const isRevoke = !isPresent(reaction)
314
+ const attrs = {
315
+ to: jid,
316
+ id: messageId,
317
+ server_id: toServerId(parentServerId, 'parentServerId'),
318
+ type: 'reaction'
319
+ }
320
+ if (isRevoke) attrs.edit = NEWSLETTER_STATUS_EDIT_REACTION_REVOKE
321
+
322
+ return {
323
+ tag: 'status',
324
+ attrs,
325
+ content: [{
326
+ tag: 'reaction',
327
+ attrs: isRevoke ? {} : { code: reaction },
328
+ content: undefined
329
+ }]
330
+ }
331
+ }
332
+
333
+ export const buildNewsletterStatusRevokeNode = ({ jid, statusId }) => {
334
+ assertNewsletterJid(jid)
335
+ if (!statusId) throw new TypeError('Newsletter status revoke requires the status id')
336
+
337
+ return {
338
+ tag: 'status',
339
+ attrs: {
340
+ to: jid,
341
+ id: statusId,
342
+ type: 'text',
343
+ edit: NEWSLETTER_STATUS_EDIT_ADMIN_REVOKE
344
+ },
345
+ content: [{ tag: 'plaintext', attrs: {}, content: undefined }]
346
+ }
347
+ }
348
+
349
+ const sendStatusNode = async (sock, node, { jid, messageId, timeoutMs }) => {
350
+ const diagnostics = collectStatusCallbacks(sock)
351
+ const responsePromise = sock.waitForMessage(messageId, timeoutMs)
352
+
353
+ try {
354
+ await sock.sendNode(node)
355
+ const response = await responsePromise
356
+ return assertStatusServerResponse(response, { jid, messageId, callbacks: diagnostics.frames })
357
+ }
358
+ finally {
359
+ diagnostics.stop()
360
+ }
361
+ }
362
+
363
+ export const makeNewsletterStatusSender = (sock, config) => async (jid, content, options = {}) => {
364
+ assertNewsletterJid(jid)
365
+ if (!content || typeof content !== 'object' || Array.isArray(content)) {
366
+ throw new TypeError('Newsletter status content must be an object')
367
+ }
368
+
369
+ const userJid = sock.authState?.creds?.me?.id
370
+ if (!userJid) throw new TypeError('Not authenticated')
371
+
372
+ const {
373
+ mediaId,
374
+ mediaHandle: requestedMediaHandle,
375
+ parentServerId,
376
+ responseServerId,
377
+ interactionType: requestedInteractionType,
378
+ aiContent,
379
+ statusAttribution = true,
380
+ messageId: requestedMessageId,
381
+ ackTimeoutMs,
382
+ resolveServerId,
383
+ serverIdTimeoutMs,
384
+ transport,
385
+ ...messageOptions
386
+ } = options
387
+
388
+ if (transport !== undefined) {
389
+ config.logger?.warn?.({ transport }, 'newsletter status "transport" option is obsolete, the verified status-publish transport is always used')
390
+ }
391
+
392
+ let uploadedMediaHandle
393
+ const upload = async (...args) => {
394
+ const result = await sock.waUploadToServer(...args)
395
+ if (args[1]?.newsletter) {
396
+ uploadedMediaHandle = result?.handle ?? result?.media_id ?? result?.mediaId ?? result?.fbid ?? uploadedMediaHandle
397
+ }
398
+ return result
399
+ }
400
+
401
+ const preparedContent = prepareModernMessageContent(content)
402
+ const fullMsg = await generateWAMessage(jid, statusAttribution ? withNewsletterStatusAttribution(preparedContent) : preparedContent, {
403
+ logger: config.logger,
404
+ userJid,
405
+ upload,
406
+ mediaCache: config.mediaCache,
407
+ options: config.options,
408
+ ...messageOptions,
409
+ messageId: requestedMessageId || generateMessageIDV2(userJid)
410
+ })
411
+
412
+ const normalized = normalizeMessageContent(fullMsg.message)
413
+ const mediaType = getNewsletterStatusMediaType(fullMsg.message)
414
+ if (!mediaType && (normalized?.documentMessage || normalized?.stickerMessage)) {
415
+ throw new TypeError('Native newsletter status supports text, image, video, gif, and audio')
416
+ }
417
+ if (mediaType && !NEWSLETTER_STATUS_WEB_MEDIA_TYPES.has(mediaType)) {
418
+ config.logger?.warn?.({ mediaType }, 'newsletter status media type is not published by WhatsApp Web itself, the server may reject it')
419
+ }
420
+
421
+ const interactionType = requestedInteractionType || (content.question ? 'question' : undefined)
422
+ if (interactionType === 'question' && !mediaType) {
423
+ config.logger?.warn?.('WhatsApp Web only publishes question newsletter statuses on top of media, a text question status may be rejected')
424
+ }
425
+
426
+ const node = buildNewsletterStatusNode({
427
+ jid,
428
+ message: fullMsg.message,
429
+ messageId: fullMsg.key.id,
430
+ mediaType,
431
+ mediaHandle: requestedMediaHandle ?? mediaId ?? uploadedMediaHandle,
432
+ parentServerId,
433
+ responseServerId,
434
+ interactionType,
435
+ aiContent
436
+ })
437
+
438
+ const echo = resolveServerId === false
439
+ ? null
440
+ : waitForNewsletterStatusServerId(sock, {
441
+ jid,
442
+ messageId: fullMsg.key.id,
443
+ timeoutMs: serverIdTimeoutMs ?? NEWSLETTER_STATUS_SERVER_ID_TIMEOUT_MS
444
+ })
445
+
446
+ let ack
447
+ try {
448
+ ack = await sendStatusNode(sock, node, {
449
+ jid,
450
+ messageId: fullMsg.key.id,
451
+ timeoutMs: ackTimeoutMs ?? NEWSLETTER_STATUS_ACK_TIMEOUT_MS
452
+ })
453
+ }
454
+ catch (error) {
455
+ echo?.cancel()
456
+ throw error
457
+ }
458
+
459
+ const delivered = echo ? await echo : undefined
460
+
461
+ fullMsg.status = WAMessageStatus.SERVER_ACK
462
+ fullMsg.newsletterStatusServerId = ack.serverId ?? delivered?.serverId
463
+ fullMsg.newsletterStatusAck = ack
464
+ fullMsg.newsletterStatusResponse = ack.node
465
+ if (delivered) fullMsg.newsletterStatusDelivered = delivered.node
466
+ return fullMsg
467
+ }
468
+
469
+ export const makeNewsletterStatusReactionSender = sock => async (jid, parentServerId, reaction, options = {}) => {
470
+ assertNewsletterJid(jid)
471
+ const userJid = sock.authState?.creds?.me?.id
472
+ if (!userJid) throw new TypeError('Not authenticated')
473
+
474
+ const messageId = options.messageId || generateMessageIDV2(userJid)
475
+ const node = buildNewsletterStatusReactionNode({ jid, messageId, parentServerId, reaction })
476
+ const ack = await sendStatusNode(sock, node, {
477
+ jid,
478
+ messageId,
479
+ timeoutMs: options.ackTimeoutMs ?? NEWSLETTER_STATUS_ACK_TIMEOUT_MS
480
+ })
481
+
482
+ return {
483
+ key: {
484
+ remoteJid: jid,
485
+ fromMe: true,
486
+ id: messageId
487
+ },
488
+ status: WAMessageStatus.SERVER_ACK,
489
+ newsletterStatusServerId: ack.serverId,
490
+ newsletterStatusAck: ack,
491
+ newsletterStatusResponse: ack.node
492
+ }
493
+ }
494
+
495
+ export const makeNewsletterStatusRevokeSender = sock => async (jid, statusId, options = {}) => {
496
+ assertNewsletterJid(jid)
497
+ const userJid = sock.authState?.creds?.me?.id
498
+ if (!userJid) throw new TypeError('Not authenticated')
499
+
500
+ const node = buildNewsletterStatusRevokeNode({ jid, statusId })
501
+ const ack = await sendStatusNode(sock, node, {
502
+ jid,
503
+ messageId: statusId,
504
+ timeoutMs: options.ackTimeoutMs ?? NEWSLETTER_STATUS_ACK_TIMEOUT_MS
505
+ })
506
+
507
+ return {
508
+ key: {
509
+ remoteJid: jid,
510
+ fromMe: true,
511
+ id: statusId
512
+ },
513
+ status: WAMessageStatus.SERVER_ACK,
514
+ newsletterStatusAck: ack,
515
+ newsletterStatusResponse: ack.node
516
+ }
517
+ }
518
+
519
+ const decodeStatusPayload = plaintext => {
520
+ const bytes = plaintext?.content
521
+ if (!bytes || Array.isArray(bytes)) return undefined
522
+ return proto.Message.decode(bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes))
523
+ }
524
+
525
+ const parseStatusAdminProfile = meta => {
526
+ const adminProfile = meta && getBinaryNodeChild(meta, 'admin_profile')
527
+ if (!adminProfile) return undefined
528
+
529
+ const name = getBinaryNodeChild(adminProfile, 'name')
530
+ const picture = getBinaryNodeChild(adminProfile, 'picture')
531
+ const content = name?.content
532
+ return {
533
+ id: adminProfile.attrs?.id,
534
+ name: typeof content === 'string'
535
+ ? content
536
+ : content instanceof Uint8Array
537
+ ? Buffer.from(content).toString('utf-8')
538
+ : undefined,
539
+ pictureId: picture?.attrs?.id,
540
+ pictureDirectPath: picture?.attrs?.direct_path
541
+ }
542
+ }
543
+
544
+ const parseStatusNode = status => {
545
+ const plaintext = getBinaryNodeChild(status, 'plaintext')
546
+ const reaction = getBinaryNodeChild(status, 'reaction')
547
+ const meta = getBinaryNodeChild(status, 'meta')
548
+ const reactions = getBinaryNodeChild(status, 'reactions')
549
+ const viewsCount = getBinaryNodeChild(status, 'views_count')
550
+ const responsesCount = getBinaryNodeChild(status, 'responses_count')
551
+ return {
552
+ id: status.attrs?.id,
553
+ serverId: readIntAttr(status.attrs, 'server_id'),
554
+ t: readIntAttr(status.attrs, 't'),
555
+ isSender: status.attrs?.is_sender === 'true',
556
+ type: status.attrs?.type,
557
+ edit: status.attrs?.edit,
558
+ mediaType: plaintext?.attrs?.mediatype,
559
+ interactionType: meta?.attrs?.interaction_type,
560
+ reaction: reaction ? reaction.attrs?.code ?? '' : undefined,
561
+ adminProfile: parseStatusAdminProfile(meta),
562
+ paidPartnership: meta ? !!getBinaryNodeChild(meta, 'paid_partnership') : false,
563
+ aiContent: meta ? !!getBinaryNodeChild(meta, 'ai_content') : false,
564
+ editTimestamp: readIntAttr(meta?.attrs, 'msg_edit_t'),
565
+ originalTimestamp: readIntAttr(meta?.attrs, 'original_msg_t'),
566
+ reactionCounts: reactions
567
+ ? getBinaryNodeChildren(reactions, 'reaction').map(entry => ({
568
+ code: entry.attrs?.code,
569
+ count: readIntAttr(entry.attrs, 'count')
570
+ }))
571
+ : undefined,
572
+ viewsCount: readIntAttr(viewsCount?.attrs, 'count'),
573
+ responsesCount: readIntAttr(responsesCount?.attrs, 'count'),
574
+ message: decodeStatusPayload(plaintext),
575
+ node: status
576
+ }
577
+ }
578
+
579
+ export const parseNewsletterStatusUpdatesResponse = node => {
580
+ const updates = getBinaryNodeChild(node, 'status_updates')
581
+ if (!updates) {
582
+ const children = Array.isArray(node?.content) ? node.content.map(child => child?.tag) : []
583
+ const error = new Error(`Newsletter status updates response has no <status_updates> child, got [${children.join(', ')}]`)
584
+ error.data = node
585
+ throw error
586
+ }
587
+
588
+ return parseNewsletterStatusesResponse(updates)
589
+ }
590
+
591
+ export const makeNewsletterStatusUpdatesFetcher = sock => async (jid, options = {}) => {
592
+ assertNewsletterJid(jid)
593
+
594
+ const { count = 20, since, before, after } = options
595
+ const attrs = { count: String(count) }
596
+ if (isPresent(since)) attrs.since = String(since)
597
+ if (isPresent(before)) attrs.before = toServerId(before, 'before')
598
+ else if (isPresent(after)) attrs.after = toServerId(after, 'after')
599
+
600
+ const result = await sock.query({
601
+ tag: 'iq',
602
+ attrs: {
603
+ to: jid,
604
+ xmlns: 'newsletter',
605
+ type: 'get'
606
+ },
607
+ content: [{ tag: 'status_updates', attrs, content: undefined }]
608
+ })
609
+
610
+ return parseNewsletterStatusUpdatesResponse(result)
611
+ }
612
+
613
+ export const parseNewsletterStatusesResponse = node => {
614
+ const statuses = getBinaryNodeChild(node, 'statuses')
615
+ if (!statuses) {
616
+ const children = Array.isArray(node?.content) ? node.content.map(child => child?.tag) : []
617
+ const error = new Error(`Newsletter statuses response has no <statuses> child, got [${children.join(', ')}]`)
618
+ error.data = node
619
+ throw error
620
+ }
621
+
622
+ return {
623
+ jid: statuses.attrs?.jid,
624
+ t: readIntAttr(statuses.attrs, 't'),
625
+ statuses: getBinaryNodeChildren(statuses, 'status').map(parseStatusNode)
626
+ }
627
+ }
628
+
629
+ export const makeNewsletterStatusFetcher = sock => async (jid, options = {}) => {
630
+ assertNewsletterJid(jid)
631
+
632
+ const { count = 20, before, after, viewRole } = options
633
+ const attrs = { type: 'jid', jid }
634
+ if (isPresent(viewRole)) attrs.view_role = String(viewRole).toLowerCase()
635
+ attrs.count = String(count)
636
+ if (isPresent(before)) attrs.before = toServerId(before, 'before')
637
+ else if (isPresent(after)) attrs.after = toServerId(after, 'after')
638
+
639
+ const result = await sock.query({
640
+ tag: 'iq',
641
+ attrs: {
642
+ to: S_WHATSAPP_NET,
643
+ xmlns: 'newsletter',
644
+ type: 'get'
645
+ },
646
+ content: [{ tag: 'statuses', attrs, content: undefined }]
647
+ })
648
+
649
+ return parseNewsletterStatusesResponse(result)
650
+ }
651
+
652
+ export { NEWSLETTER_STATUS_CONTENT_TYPES, NEWSLETTER_STATUS_MEDIA_TYPES, NEWSLETTER_STATUS_WEB_MEDIA_TYPES }
@@ -0,0 +1,20 @@
1
+ export function makeNoiseHandler({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, logger, routingInfo }: {
2
+ keyPair: {
3
+ private: any;
4
+ public: any;
5
+ };
6
+ NOISE_HEADER: any;
7
+ logger: any;
8
+ routingInfo: any;
9
+ }): {
10
+ encrypt: (plaintext: any) => any;
11
+ decrypt: (ciphertext: any) => any;
12
+ authenticate: (data: any) => void;
13
+ mixIntoKey: (data: any) => void;
14
+ finishInit: () => Promise<void>;
15
+ processHandshake: (opts1: { [key: string]: any;
16
+ serverHello: any;
17
+ }, noiseKey: any) => any;
18
+ encodeFrame: (data: any) => any;
19
+ decodeFrame: (newData: any, onFrame: any) => Promise<void>;
20
+ };