@japofc/baileys 2.1.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 (342) hide show
  1. package/NOTICE.md +111 -0
  2. package/README.md +1254 -0
  3. package/WAProto/index.d.ts +9 -0
  4. package/WAProto/index.js +142276 -0
  5. package/engine-requirements.js +13 -0
  6. package/lib/Builders/A2UI.d.ts +242 -0
  7. package/lib/Builders/A2UI.js +308 -0
  8. package/lib/Builders/AIRich.d.ts +105 -0
  9. package/lib/Builders/AIRich.js +2286 -0
  10. package/lib/Builders/Button.d.ts +103 -0
  11. package/lib/Builders/Button.js +883 -0
  12. package/lib/Builders/ButtonV2.d.ts +28 -0
  13. package/lib/Builders/ButtonV2.js +144 -0
  14. package/lib/Builders/ButtonV3.d.ts +25 -0
  15. package/lib/Builders/ButtonV3.js +184 -0
  16. package/lib/Builders/Carousel.d.ts +22 -0
  17. package/lib/Builders/Carousel.js +111 -0
  18. package/lib/Builders/JapBaileys.d.ts +34 -0
  19. package/lib/Builders/JapBaileys.js +108 -0
  20. package/lib/Builders/Poll.d.ts +25 -0
  21. package/lib/Builders/Poll.js +128 -0
  22. package/lib/Builders/index.d.ts +17 -0
  23. package/lib/Builders/index.js +11 -0
  24. package/lib/Builders/shared.d.ts +67 -0
  25. package/lib/Builders/shared.js +652 -0
  26. package/lib/Defaults/index.d.ts +154 -0
  27. package/lib/Defaults/index.js +178 -0
  28. package/lib/Framework/Bot.d.ts +61 -0
  29. package/lib/Framework/Bot.js +248 -0
  30. package/lib/Framework/Context.d.ts +21 -0
  31. package/lib/Framework/Context.js +89 -0
  32. package/lib/Framework/MediaManager.d.ts +17 -0
  33. package/lib/Framework/MediaManager.js +151 -0
  34. package/lib/Framework/SessionManager.d.ts +13 -0
  35. package/lib/Framework/SessionManager.js +33 -0
  36. package/lib/Framework/StatsManager.d.ts +26 -0
  37. package/lib/Framework/StatsManager.js +119 -0
  38. package/lib/Framework/Store/SQLiteStore.d.ts +11 -0
  39. package/lib/Framework/Store/SQLiteStore.js +73 -0
  40. package/lib/Framework/index.d.ts +9 -0
  41. package/lib/Framework/index.js +10 -0
  42. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  43. package/lib/Signal/Group/ciphertext-message.js +11 -0
  44. package/lib/Signal/Group/group-session-builder.d.ts +7 -0
  45. package/lib/Signal/Group/group-session-builder.js +29 -0
  46. package/lib/Signal/Group/group_cipher.d.ts +10 -0
  47. package/lib/Signal/Group/group_cipher.js +81 -0
  48. package/lib/Signal/Group/index.d.ts +11 -0
  49. package/lib/Signal/Group/index.js +11 -0
  50. package/lib/Signal/Group/keyhelper.d.ts +6 -0
  51. package/lib/Signal/Group/keyhelper.js +17 -0
  52. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  53. package/lib/Signal/Group/sender-chain-key.js +25 -0
  54. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  55. package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
  56. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  57. package/lib/Signal/Group/sender-key-message.js +65 -0
  58. package/lib/Signal/Group/sender-key-name.d.ts +11 -0
  59. package/lib/Signal/Group/sender-key-name.js +47 -0
  60. package/lib/Signal/Group/sender-key-record.d.ts +12 -0
  61. package/lib/Signal/Group/sender-key-record.js +40 -0
  62. package/lib/Signal/Group/sender-key-state.d.ts +16 -0
  63. package/lib/Signal/Group/sender-key-state.js +83 -0
  64. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  65. package/lib/Signal/Group/sender-message-key.js +25 -0
  66. package/lib/Signal/libsignal.d.ts +54 -0
  67. package/lib/Signal/libsignal.js +430 -0
  68. package/lib/Signal/lid-mapping.d.ts +20 -0
  69. package/lib/Signal/lid-mapping.js +276 -0
  70. package/lib/Socket/Client/index.d.ts +2 -0
  71. package/lib/Socket/Client/index.js +2 -0
  72. package/lib/Socket/Client/types.d.ts +5 -0
  73. package/lib/Socket/Client/types.js +10 -0
  74. package/lib/Socket/Client/websocket.d.ts +12 -0
  75. package/lib/Socket/Client/websocket.js +53 -0
  76. package/lib/Socket/business.d.ts +395 -0
  77. package/lib/Socket/business.js +379 -0
  78. package/lib/Socket/chats.d.ts +136 -0
  79. package/lib/Socket/chats.js +1327 -0
  80. package/lib/Socket/communities.d.ts +562 -0
  81. package/lib/Socket/communities.js +439 -0
  82. package/lib/Socket/dugong.d.ts +117 -0
  83. package/lib/Socket/dugong.js +798 -0
  84. package/lib/Socket/groups.d.ts +285 -0
  85. package/lib/Socket/groups.js +354 -0
  86. package/lib/Socket/index.d.ts +585 -0
  87. package/lib/Socket/index.js +52 -0
  88. package/lib/Socket/messages-recv.d.ts +333 -0
  89. package/lib/Socket/messages-recv.js +1781 -0
  90. package/lib/Socket/messages-send.d.ts +353 -0
  91. package/lib/Socket/messages-send.js +1524 -0
  92. package/lib/Socket/mex.d.ts +1 -0
  93. package/lib/Socket/mex.js +41 -0
  94. package/lib/Socket/newsletter.d.ts +286 -0
  95. package/lib/Socket/newsletter.js +364 -0
  96. package/lib/Socket/socket.d.ts +60 -0
  97. package/lib/Socket/socket.js +1012 -0
  98. package/lib/Socket/username.d.ts +82 -0
  99. package/lib/Socket/username.js +159 -0
  100. package/lib/Store/index.d.ts +3 -0
  101. package/lib/Store/index.js +3 -0
  102. package/lib/Store/make-in-memory-store.d.ts +62 -0
  103. package/lib/Store/make-in-memory-store.js +428 -0
  104. package/lib/Store/make-ordered-dictionary.d.ts +12 -0
  105. package/lib/Store/make-ordered-dictionary.js +78 -0
  106. package/lib/Store/object-repository.d.ts +10 -0
  107. package/lib/Store/object-repository.js +23 -0
  108. package/lib/Types/Auth.d.ts +117 -0
  109. package/lib/Types/Auth.js +1 -0
  110. package/lib/Types/Bussines.d.ts +25 -0
  111. package/lib/Types/Call.d.ts +15 -0
  112. package/lib/Types/Call.js +1 -0
  113. package/lib/Types/Chat.d.ts +124 -0
  114. package/lib/Types/Chat.js +7 -0
  115. package/lib/Types/Contact.d.ts +26 -0
  116. package/lib/Types/Contact.js +1 -0
  117. package/lib/Types/Events.d.ts +256 -0
  118. package/lib/Types/Events.js +1 -0
  119. package/lib/Types/GroupMetadata.d.ts +71 -0
  120. package/lib/Types/GroupMetadata.js +1 -0
  121. package/lib/Types/Label.d.ts +5 -0
  122. package/lib/Types/Label.js +24 -0
  123. package/lib/Types/LabelAssociation.d.ts +6 -0
  124. package/lib/Types/LabelAssociation.js +6 -0
  125. package/lib/Types/Message.d.ts +62 -0
  126. package/lib/Types/Message.js +17 -0
  127. package/lib/Types/Mex.d.ts +2 -0
  128. package/lib/Types/Mex.js +38 -0
  129. package/lib/Types/Product.d.ts +79 -0
  130. package/lib/Types/Product.js +1 -0
  131. package/lib/Types/RichType.d.ts +2 -0
  132. package/lib/Types/RichType.js +22 -0
  133. package/lib/Types/Signal.d.ts +87 -0
  134. package/lib/Types/Signal.js +1 -0
  135. package/lib/Types/Socket.d.ts +138 -0
  136. package/lib/Types/Socket.js +1 -0
  137. package/lib/Types/State.d.ts +8 -0
  138. package/lib/Types/State.js +55 -0
  139. package/lib/Types/USync.d.ts +26 -0
  140. package/lib/Types/index.d.ts +68 -0
  141. package/lib/Types/index.js +27 -0
  142. package/lib/Utils/MessageBuilder.d.ts +2 -0
  143. package/lib/Utils/MessageBuilder.js +2 -0
  144. package/lib/Utils/PersistentStore.d.ts +60 -0
  145. package/lib/Utils/PersistentStore.js +592 -0
  146. package/lib/Utils/anti-delete.d.ts +74 -0
  147. package/lib/Utils/anti-delete.js +221 -0
  148. package/lib/Utils/auth-secure.d.ts +86 -0
  149. package/lib/Utils/auth-secure.js +764 -0
  150. package/lib/Utils/auth-utils.d.ts +57 -0
  151. package/lib/Utils/auth-utils.js +306 -0
  152. package/lib/Utils/auto-reply.d.ts +47 -0
  153. package/lib/Utils/auto-reply.js +157 -0
  154. package/lib/Utils/baileys-event-stream.d.ts +8 -0
  155. package/lib/Utils/baileys-event-stream.js +62 -0
  156. package/lib/Utils/browser-utils.d.ts +8 -0
  157. package/lib/Utils/browser-utils.js +27 -0
  158. package/lib/Utils/business.d.ts +49 -0
  159. package/lib/Utils/business.js +239 -0
  160. package/lib/Utils/button-helper-utils.d.ts +53 -0
  161. package/lib/Utils/button-helper-utils.js +312 -0
  162. package/lib/Utils/button-sender.d.ts +54 -0
  163. package/lib/Utils/button-sender.js +822 -0
  164. package/lib/Utils/chat-control.d.ts +159 -0
  165. package/lib/Utils/chat-control.js +230 -0
  166. package/lib/Utils/chat-history-helpers.d.ts +21 -0
  167. package/lib/Utils/chat-history-helpers.js +70 -0
  168. package/lib/Utils/chat-utils.d.ts +407 -0
  169. package/lib/Utils/chat-utils.js +885 -0
  170. package/lib/Utils/companion-reg-client-utils.d.ts +4 -0
  171. package/lib/Utils/companion-reg-client-utils.js +39 -0
  172. package/lib/Utils/crypto.d.ts +41 -0
  173. package/lib/Utils/crypto.js +147 -0
  174. package/lib/Utils/decode-wa-message.d.ts +83 -0
  175. package/lib/Utils/decode-wa-message.js +316 -0
  176. package/lib/Utils/event-buffer.d.ts +12 -0
  177. package/lib/Utils/event-buffer.js +635 -0
  178. package/lib/Utils/generics.d.ts +69 -0
  179. package/lib/Utils/generics.js +438 -0
  180. package/lib/Utils/history-share.d.ts +11 -0
  181. package/lib/Utils/history-share.js +70 -0
  182. package/lib/Utils/history.d.ts +90 -0
  183. package/lib/Utils/history.js +146 -0
  184. package/lib/Utils/humanizer.d.ts +12 -0
  185. package/lib/Utils/humanizer.js +73 -0
  186. package/lib/Utils/identity-change-handler.d.ts +13 -0
  187. package/lib/Utils/identity-change-handler.js +49 -0
  188. package/lib/Utils/index.d.ts +57 -0
  189. package/lib/Utils/index.js +56 -0
  190. package/lib/Utils/jid-tools.d.ts +6 -0
  191. package/lib/Utils/jid-tools.js +77 -0
  192. package/lib/Utils/link-preview.d.ts +12 -0
  193. package/lib/Utils/link-preview.js +84 -0
  194. package/lib/Utils/logger.d.ts +4 -0
  195. package/lib/Utils/logger.js +2 -0
  196. package/lib/Utils/lt-hash.d.ts +12 -0
  197. package/lib/Utils/lt-hash.js +26 -0
  198. package/lib/Utils/make-mutex.d.ts +6 -0
  199. package/lib/Utils/make-mutex.js +32 -0
  200. package/lib/Utils/media-messages.d.ts +18 -0
  201. package/lib/Utils/media-messages.js +70 -0
  202. package/lib/Utils/media-set.d.ts +13 -0
  203. package/lib/Utils/media-set.js +171 -0
  204. package/lib/Utils/message-kind.d.ts +32 -0
  205. package/lib/Utils/message-kind.js +136 -0
  206. package/lib/Utils/message-retry-manager.d.ts +79 -0
  207. package/lib/Utils/message-retry-manager.js +264 -0
  208. package/lib/Utils/message-search.d.ts +44 -0
  209. package/lib/Utils/message-search.js +188 -0
  210. package/lib/Utils/messages-media.d.ts +135 -0
  211. package/lib/Utils/messages-media.js +868 -0
  212. package/lib/Utils/messages.d.ts +44 -0
  213. package/lib/Utils/messages.js +2326 -0
  214. package/lib/Utils/meta-ai.d.ts +13 -0
  215. package/lib/Utils/meta-ai.js +74 -0
  216. package/lib/Utils/mini-app.d.ts +35 -0
  217. package/lib/Utils/mini-app.js +213 -0
  218. package/lib/Utils/noise-handler.d.ts +20 -0
  219. package/lib/Utils/noise-handler.js +200 -0
  220. package/lib/Utils/offline-node-processor.d.ts +9 -0
  221. package/lib/Utils/offline-node-processor.js +39 -0
  222. package/lib/Utils/past-participants.d.ts +14 -0
  223. package/lib/Utils/past-participants.js +40 -0
  224. package/lib/Utils/pre-key-manager.d.ts +25 -0
  225. package/lib/Utils/pre-key-manager.js +105 -0
  226. package/lib/Utils/process-message.d.ts +82 -0
  227. package/lib/Utils/process-message.js +808 -0
  228. package/lib/Utils/qr-render.d.ts +59 -0
  229. package/lib/Utils/qr-render.js +179 -0
  230. package/lib/Utils/qrcodegen.d.ts +79 -0
  231. package/lib/Utils/qrcodegen.js +848 -0
  232. package/lib/Utils/reporting-utils.d.ts +12 -0
  233. package/lib/Utils/reporting-utils.js +257 -0
  234. package/lib/Utils/rich-message-utils.d.ts +48 -0
  235. package/lib/Utils/rich-message-utils.js +444 -0
  236. package/lib/Utils/router.d.ts +37 -0
  237. package/lib/Utils/router.js +165 -0
  238. package/lib/Utils/scheduled-posts.d.ts +30 -0
  239. package/lib/Utils/scheduled-posts.js +110 -0
  240. package/lib/Utils/scheduling.d.ts +42 -0
  241. package/lib/Utils/scheduling.js +139 -0
  242. package/lib/Utils/signal.d.ts +82 -0
  243. package/lib/Utils/signal.js +200 -0
  244. package/lib/Utils/stanza-ack.d.ts +16 -0
  245. package/lib/Utils/stanza-ack.js +37 -0
  246. package/lib/Utils/status.d.ts +50 -0
  247. package/lib/Utils/status.js +107 -0
  248. package/lib/Utils/stickerpack.d.ts +51 -0
  249. package/lib/Utils/stickerpack.js +274 -0
  250. package/lib/Utils/sync-action-utils.d.ts +2 -0
  251. package/lib/Utils/sync-action-utils.js +48 -0
  252. package/lib/Utils/tag.d.ts +12 -0
  253. package/lib/Utils/tag.js +44 -0
  254. package/lib/Utils/tc-token-utils.d.ts +29 -0
  255. package/lib/Utils/tc-token-utils.js +162 -0
  256. package/lib/Utils/templates.d.ts +76 -0
  257. package/lib/Utils/templates.js +150 -0
  258. package/lib/Utils/transcribe.d.ts +12 -0
  259. package/lib/Utils/transcribe.js +107 -0
  260. package/lib/Utils/use-cache-manager-auth-state.d.ts +13 -0
  261. package/lib/Utils/use-cache-manager-auth-state.js +81 -0
  262. package/lib/Utils/use-multi-file-auth-state.d.ts +10 -0
  263. package/lib/Utils/use-multi-file-auth-state.js +166 -0
  264. package/lib/Utils/use-single-file-auth-state.d.ts +10 -0
  265. package/lib/Utils/use-single-file-auth-state.js +113 -0
  266. package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
  267. package/lib/Utils/use-sqlite-auth-state.js +169 -0
  268. package/lib/Utils/validate-connection.d.ts +42 -0
  269. package/lib/Utils/validate-connection.js +198 -0
  270. package/lib/Utils/vcard.d.ts +58 -0
  271. package/lib/Utils/vcard.js +104 -0
  272. package/lib/Utils/voice-note.d.ts +15 -0
  273. package/lib/Utils/voice-note.js +63 -0
  274. package/lib/VoIP/audio-feeder.d.ts +18 -0
  275. package/lib/VoIP/audio-feeder.js +160 -0
  276. package/lib/VoIP/call-recorder.d.ts +13 -0
  277. package/lib/VoIP/call-recorder.js +73 -0
  278. package/lib/VoIP/index.d.ts +86 -0
  279. package/lib/VoIP/index.js +611 -0
  280. package/lib/VoIP/relay-transport.d.ts +43 -0
  281. package/lib/VoIP/relay-transport.js +563 -0
  282. package/lib/VoIP/signaling.d.ts +26 -0
  283. package/lib/VoIP/signaling.js +662 -0
  284. package/lib/VoIP/types.d.ts +69 -0
  285. package/lib/VoIP/types.js +17 -0
  286. package/lib/VoIP/wasm-engine.d.ts +120 -0
  287. package/lib/VoIP/wasm-engine.js +1358 -0
  288. package/lib/VoIP/worker-bootstrap.d.ts +4 -0
  289. package/lib/VoIP/worker-bootstrap.js +1046 -0
  290. package/lib/WABinary/constants.d.ts +61 -0
  291. package/lib/WABinary/constants.js +1466 -0
  292. package/lib/WABinary/decode.d.ts +9 -0
  293. package/lib/WABinary/decode.js +261 -0
  294. package/lib/WABinary/encode.d.ts +2 -0
  295. package/lib/WABinary/encode.js +219 -0
  296. package/lib/WABinary/generic-utils.d.ts +74 -0
  297. package/lib/WABinary/generic-utils.js +276 -0
  298. package/lib/WABinary/index.d.ts +5 -0
  299. package/lib/WABinary/index.js +5 -0
  300. package/lib/WABinary/jid-utils.d.ts +28 -0
  301. package/lib/WABinary/jid-utils.js +95 -0
  302. package/lib/WABinary/types.d.ts +19 -0
  303. package/lib/WABinary/types.js +1 -0
  304. package/lib/WAM/BinaryInfo.d.ts +7 -0
  305. package/lib/WAM/BinaryInfo.js +9 -0
  306. package/lib/WAM/constants.d.ts +34926 -0
  307. package/lib/WAM/constants.js +22852 -0
  308. package/lib/WAM/encode.d.ts +1 -0
  309. package/lib/WAM/encode.js +149 -0
  310. package/lib/WAM/index.d.ts +3 -0
  311. package/lib/WAM/index.js +3 -0
  312. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
  313. package/lib/WAUSync/Protocols/USyncContactProtocol.js +51 -0
  314. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +29 -0
  315. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +62 -0
  316. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  317. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
  318. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  319. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
  320. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
  321. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
  322. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
  323. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
  324. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
  325. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
  326. package/lib/WAUSync/Protocols/index.d.ts +7 -0
  327. package/lib/WAUSync/Protocols/index.js +7 -0
  328. package/lib/WAUSync/USyncQuery.d.ts +20 -0
  329. package/lib/WAUSync/USyncQuery.js +121 -0
  330. package/lib/WAUSync/USyncUser.d.ts +16 -0
  331. package/lib/WAUSync/USyncUser.js +30 -0
  332. package/lib/WAUSync/index.d.ts +3 -0
  333. package/lib/WAUSync/index.js +3 -0
  334. package/lib/assets/wasm/loader.d.ts +5 -0
  335. package/lib/assets/wasm/loader.js +5 -0
  336. package/lib/assets/wasm/whatsapp.wasm +0 -0
  337. package/lib/assets/wasm/worker-modules.d.ts +5 -0
  338. package/lib/assets/wasm/worker-modules.js +273 -0
  339. package/lib/index.d.ts +18 -0
  340. package/lib/index.js +23 -0
  341. package/package.json +180 -0
  342. package/postinstall-banner.js +82 -0
@@ -0,0 +1,276 @@
1
+ import { Boom } from '@hapi/boom';
2
+ import { randomBytes } from 'crypto';
3
+ import { proto } from '../../WAProto/index.js';
4
+ // some extra useful utilities
5
+ const indexCache = new WeakMap();
6
+ export const getBinaryNodeChildren = (node, childTag) => {
7
+ if (!node || !Array.isArray(node.content))
8
+ return [];
9
+ let index = indexCache.get(node);
10
+ // Build the index once per node
11
+ if (!index) {
12
+ index = new Map();
13
+ for (const child of node.content) {
14
+ let arr = index.get(child.tag);
15
+ if (!arr)
16
+ index.set(child.tag, (arr = []));
17
+ arr.push(child);
18
+ }
19
+ indexCache.set(node, index);
20
+ }
21
+ // Return first matching child
22
+ return index.get(childTag) || [];
23
+ };
24
+ export const getBinaryNodeChild = (node, childTag) => {
25
+ return getBinaryNodeChildren(node, childTag)[0];
26
+ };
27
+ export const getAllBinaryNodeChildren = ({ content }) => {
28
+ if (Array.isArray(content)) {
29
+ return content;
30
+ }
31
+ return [];
32
+ };
33
+ export const getBinaryNodeChildBuffer = (node, childTag) => {
34
+ const child = getBinaryNodeChild(node, childTag)?.content;
35
+ if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
36
+ return child;
37
+ }
38
+ };
39
+ export const getBinaryNodeChildString = (node, childTag) => {
40
+ const child = getBinaryNodeChild(node, childTag)?.content;
41
+ if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
42
+ return Buffer.from(child).toString('utf-8');
43
+ }
44
+ else if (typeof child === 'string') {
45
+ return child;
46
+ }
47
+ };
48
+ export const getBinaryNodeChildUInt = (node, childTag, length) => {
49
+ const buff = getBinaryNodeChildBuffer(node, childTag);
50
+ if (buff) {
51
+ return bufferToUInt(buff, length);
52
+ }
53
+ };
54
+ export const assertNodeErrorFree = (node) => {
55
+ const errNode = getBinaryNodeChild(node, 'error');
56
+ if (errNode) {
57
+ throw new Boom(errNode.attrs.text || 'Unknown error', { data: +errNode.attrs.code });
58
+ }
59
+ };
60
+ export const reduceBinaryNodeToDictionary = (node, tag) => {
61
+ const nodes = getBinaryNodeChildren(node, tag);
62
+ const dict = nodes.reduce((dict, { attrs }) => {
63
+ if (typeof attrs.name === 'string') {
64
+ dict[attrs.name] = attrs.value || attrs.config_value;
65
+ }
66
+ else {
67
+ dict[attrs.config_code] = attrs.value || attrs.config_value;
68
+ }
69
+ return dict;
70
+ }, {});
71
+ return dict;
72
+ };
73
+ export const getBinaryNodeMessages = ({ content }) => {
74
+ const msgs = [];
75
+ if (Array.isArray(content)) {
76
+ for (const item of content) {
77
+ if (item.tag === 'message') {
78
+ msgs.push(proto.WebMessageInfo.decode(item.content).toJSON());
79
+ }
80
+ }
81
+ }
82
+ return msgs;
83
+ };
84
+ function bufferToUInt(e, t) {
85
+ let a = 0;
86
+ for (let i = 0; i < t; i++) {
87
+ a = 256 * a + e[i];
88
+ }
89
+ return a;
90
+ }
91
+ const tabs = (n) => '\t'.repeat(n);
92
+ export function binaryNodeToString(node, i = 0) {
93
+ if (!node) {
94
+ return node;
95
+ }
96
+ if (typeof node === 'string') {
97
+ return tabs(i) + node;
98
+ }
99
+ if (node instanceof Uint8Array) {
100
+ return tabs(i) + Buffer.from(node).toString('hex');
101
+ }
102
+ if (Array.isArray(node)) {
103
+ return node.map(x => tabs(i + 1) + binaryNodeToString(x, i + 1)).join('\n');
104
+ }
105
+ const children = binaryNodeToString(node.content, i + 1);
106
+ const tag = `<${node.tag} ${Object.entries(node.attrs || {})
107
+ .filter(([, v]) => v !== undefined)
108
+ .map(([k, v]) => `${k}='${v}'`)
109
+ .join(' ')}`;
110
+ const content = children ? `>\n${children}\n${tabs(i)}</${node.tag}>` : '/>';
111
+ return tag + content;
112
+ }
113
+ /**
114
+ * JAP@Changes 30-01-26
115
+ * ---
116
+ * Produce the binary node (WABinary-like JSON shape) required for the specific
117
+ * interactive button / list type.
118
+ * compatible with observed official client traffic.
119
+ *
120
+ * NOTE: Returning different "v" (version) and "name" values influences how
121
+ * WhatsApp renders & validates flows. The constants here are empirically derived.
122
+ *
123
+ * @param {object} message Normalized message content (after Baileys normalization).
124
+ * @returns {object} A node with shape { tag, attrs, [content] } to inject into additionalNodes.
125
+ */
126
+ const FLOWS_MAP = {
127
+ // Original flow types
128
+ mpm: true,
129
+ // JAP@Fix (bug 44): the "catalog" nativeFlow shortcut generates a button
130
+ // named 'catalog_message' (see prepareNativeFlowButtons in messages.js),
131
+ // never 'cta_catalog' — the old key here never matched anything, so
132
+ // catalog_message always fell through to the generic mixed-flow node
133
+ // instead of getting its dedicated native_flow node.
134
+ catalog_message: true,
135
+ send_location: true,
136
+ call_permission_request: true,
137
+ wa_payment_transaction_details: true,
138
+ automated_greeting_message_view_catalog: true,
139
+ // Jap extended button types
140
+ card_message: true,
141
+ order_status: true,
142
+ track_order: true,
143
+ reorder: true,
144
+ cancel_order: true,
145
+ clear_chat: true,
146
+ navigateToScreen: true,
147
+ payment_status: true,
148
+ payment_method: true,
149
+ flow_action: true,
150
+ voice_call: true,
151
+ video_call_button: true,
152
+ otp_button: true,
153
+ authentication_button: true,
154
+ cta_reminder: true,
155
+ cta_cancel_reminder: true,
156
+ // JAP@Fix 27-08-26: the real native_flow name for a WhatsApp Flows launch
157
+ // button is 'flow' (matches Button.addFlow()'s button.name after the fix
158
+ // in MessageBuilder.js). 'flow_action' was never a valid native_flow name --
159
+ // it's the name of a *field inside* buttonParamsJson -- so it never actually
160
+ // routed anything real; kept as a harmless alias in case any external caller
161
+ // is still constructing a raw button object with the old (wrong) name.
162
+ flow: true,
163
+ // JAP@Fix (bug 68): removed duplicate `flow_action: true` key — already declared
164
+ // above (Jap extended button types block); this was a leftover copy-paste dupe,
165
+ // harmless (same value) but confusing on re-read.
166
+ // JAP@Fix (single_select never renders alone) --- single_select must NEVER get
167
+ // its own dedicated native_flow node here. WhatsApp only renders a single_select
168
+ // button through the generic <native_flow v='9' name='mixed'> node — the same one
169
+ // used when it's combined with other buttons. Giving it a dedicated
170
+ // <native_flow v='2' name='single_select'> node (like the other FLOWS_MAP entries)
171
+ // silently fails to render client-side, whether single_select is alone or is simply
172
+ // the first button in the array. Removed from this map on purpose so it always
173
+ // falls through to the `flowMsg` mixed-flow branch below.
174
+ };
175
+ const DECISION_SOURCE_CONTENT = [
176
+ {
177
+ tag: 'decision_source',
178
+ attrs: { value: 'df' }
179
+ }
180
+ ];
181
+ const LIST_TYPE_CONTENT = {
182
+ tag: 'list',
183
+ attrs: { v: '2', type: 'product_list' }
184
+ };
185
+ const NATIVE_FLOW_ATTRIBUTE = { type: 'native_flow', v: '1' };
186
+ const MIXED_NATIVE_FLOW = {
187
+ tag: 'interactive',
188
+ attrs: NATIVE_FLOW_ATTRIBUTE,
189
+ content: [
190
+ {
191
+ tag: 'native_flow',
192
+ attrs: { v: '9', name: 'mixed' }
193
+ }
194
+ ]
195
+ };
196
+ export const getBizBinaryNode = (message) => {
197
+ const flowMsg = message.interactiveMessage?.nativeFlowMessage;
198
+ const firstButtonName = flowMsg?.buttons?.[0]?.name;
199
+ const qualityContent = {
200
+ tag: 'quality_control',
201
+ attrs: {
202
+ decision_id: randomBytes(20).toString('hex'),
203
+ source_type: 'third_party'
204
+ },
205
+ content: DECISION_SOURCE_CONTENT
206
+ };
207
+ const bizAttributes = {
208
+ actual_actors: '2',
209
+ host_storage: '2',
210
+ privacy_mode_ts: `${Date.now() / 1_000 | 0}`
211
+ };
212
+ const ORDER_RESPONSE_ALIAS = {
213
+ review_and_pay: 'order_details',
214
+ review_order: 'order_status',
215
+ payment_info: 'payment_info',
216
+ payment_status: 'payment_status',
217
+ payment_method: 'payment_method',
218
+ order_details: 'order_details',
219
+ order_status: 'order_status',
220
+ track_order: 'track_order',
221
+ reorder: 'reorder',
222
+ cancel_order: 'cancel_order',
223
+ };
224
+ if (firstButtonName && ORDER_RESPONSE_ALIAS[firstButtonName]) {
225
+ bizAttributes.native_flow_name = ORDER_RESPONSE_ALIAS[firstButtonName];
226
+ return {
227
+ tag: 'biz',
228
+ attrs: bizAttributes,
229
+ content: [qualityContent]
230
+ };
231
+ }
232
+ if (firstButtonName && FLOWS_MAP[firstButtonName]) {
233
+ return {
234
+ tag: 'biz',
235
+ attrs: bizAttributes,
236
+ content: [
237
+ {
238
+ tag: 'interactive',
239
+ attrs: NATIVE_FLOW_ATTRIBUTE,
240
+ content: [
241
+ {
242
+ tag: 'native_flow',
243
+ attrs: { v: '2', name: firstButtonName }
244
+ }
245
+ ]
246
+ },
247
+ qualityContent
248
+ ]
249
+ };
250
+ }
251
+ if (flowMsg || message.buttonsMessage || message.templateMessage) {
252
+ return {
253
+ tag: 'biz',
254
+ attrs: bizAttributes,
255
+ content: [
256
+ MIXED_NATIVE_FLOW,
257
+ qualityContent
258
+ ]
259
+ };
260
+ }
261
+ if (message.listMessage) {
262
+ return {
263
+ tag: 'biz',
264
+ attrs: bizAttributes,
265
+ content: [
266
+ LIST_TYPE_CONTENT,
267
+ qualityContent
268
+ ]
269
+ };
270
+ }
271
+ return {
272
+ tag: 'biz',
273
+ attrs: bizAttributes,
274
+ content: [qualityContent]
275
+ };
276
+ };
@@ -0,0 +1,5 @@
1
+ export * from "./encode.js";
2
+ export * from "./decode.js";
3
+ export * from "./generic-utils.js";
4
+ export * from "./jid-utils.js";
5
+ export * from "./types.js";
@@ -0,0 +1,5 @@
1
+ export * from './encode.js';
2
+ export * from './decode.js';
3
+ export * from './generic-utils.js';
4
+ export * from './jid-utils.js';
5
+ export * from './types.js';
@@ -0,0 +1,28 @@
1
+ export const S_WHATSAPP_NET: "@s.whatsapp.net";
2
+ export const OFFICIAL_BIZ_JID: "16505361212@c.us";
3
+ export const SERVER_JID: "server@c.us";
4
+ export const PSA_WID: "0@c.us";
5
+ export const STORIES_JID: "status@broadcast";
6
+ export const META_AI_JID: "13135550002@c.us";
7
+ export const WAJIDDomains: any;
8
+ export function getServerFromDomainType(initialServer: any, domainType: any): any;
9
+ export function jidEncode(user: any, server: any, device: any, agent: any): string;
10
+ export function jidDecode(jid: any): {
11
+ server: any;
12
+ user: any;
13
+ domainType: any;
14
+ device: number | undefined;
15
+ } | undefined;
16
+ export function areJidsSameUser(jid1: any, jid2: any): boolean;
17
+ export function isJidMetaAI(jid: any): any;
18
+ export function isPnUser(jid: any): any;
19
+ export function isLidUser(jid: any): any;
20
+ export function isJidBroadcast(jid: any): any;
21
+ export function isJidGroup(jid: any): any;
22
+ export function isJidStatusBroadcast(jid: any): boolean;
23
+ export function isJidNewsletter(jid: any): any;
24
+ export function isHostedPnUser(jid: any): any;
25
+ export function isHostedLidUser(jid: any): any;
26
+ export function isJidBot(jid: any): any;
27
+ export function jidNormalizedUser(jid: any): string;
28
+ export function transferDevice(fromJid: any, toJid: any): string;
@@ -0,0 +1,95 @@
1
+ export const S_WHATSAPP_NET = '@s.whatsapp.net';
2
+ export const OFFICIAL_BIZ_JID = '16505361212@c.us';
3
+ export const SERVER_JID = 'server@c.us';
4
+ export const PSA_WID = '0@c.us';
5
+ export const STORIES_JID = 'status@broadcast';
6
+ export const META_AI_JID = '13135550002@c.us';
7
+ export var WAJIDDomains;
8
+ (function (WAJIDDomains) {
9
+ WAJIDDomains[WAJIDDomains["WHATSAPP"] = 0] = "WHATSAPP";
10
+ WAJIDDomains[WAJIDDomains["LID"] = 1] = "LID";
11
+ WAJIDDomains[WAJIDDomains["HOSTED"] = 128] = "HOSTED";
12
+ WAJIDDomains[WAJIDDomains["HOSTED_LID"] = 129] = "HOSTED_LID";
13
+ })(WAJIDDomains || (WAJIDDomains = {}));
14
+ export const getServerFromDomainType = (initialServer, domainType) => {
15
+ switch (domainType) {
16
+ case WAJIDDomains.LID:
17
+ return 'lid';
18
+ case WAJIDDomains.HOSTED:
19
+ return 'hosted';
20
+ case WAJIDDomains.HOSTED_LID:
21
+ return 'hosted.lid';
22
+ case WAJIDDomains.WHATSAPP:
23
+ default:
24
+ return initialServer;
25
+ }
26
+ };
27
+ export const jidEncode = (user, server, device, agent) => {
28
+ return `${user || ''}${!!agent ? `_${agent}` : ''}${!!device ? `:${device}` : ''}@${server || 'lid'}`;
29
+ };
30
+ export const jidDecode = (jid) => {
31
+ // todo: investigate how to implement hosted ids in this case
32
+ const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1;
33
+ if (sepIdx < 0) {
34
+ return undefined;
35
+ }
36
+ const server = jid.slice(sepIdx + 1);
37
+ const userCombined = jid.slice(0, sepIdx);
38
+ const [userAgent, device] = userCombined.split(':');
39
+ const [user, agent] = userAgent.split('_');
40
+ let domainType = WAJIDDomains.WHATSAPP;
41
+ if (server === 'lid') {
42
+ domainType = WAJIDDomains.LID;
43
+ }
44
+ else if (server === 'hosted') {
45
+ domainType = WAJIDDomains.HOSTED;
46
+ }
47
+ else if (server === 'hosted.lid') {
48
+ domainType = WAJIDDomains.HOSTED_LID;
49
+ }
50
+ else if (agent) {
51
+ domainType = parseInt(agent);
52
+ }
53
+ return {
54
+ server: server,
55
+ user: user,
56
+ domainType,
57
+ device: device ? +device : undefined
58
+ };
59
+ };
60
+ /** is the jid a user */
61
+ export const areJidsSameUser = (jid1, jid2) => jidDecode(jid1)?.user === jidDecode(jid2)?.user;
62
+ /** is the jid Meta AI */
63
+ export const isJidMetaAI = (jid) => jid?.endsWith('@bot');
64
+ /** is the jid a PN user */
65
+ export const isPnUser = (jid) => jid?.endsWith('@s.whatsapp.net');
66
+ /** is the jid a LID */
67
+ export const isLidUser = (jid) => jid?.endsWith('@lid');
68
+ /** is the jid a broadcast */
69
+ export const isJidBroadcast = (jid) => jid?.endsWith('@broadcast');
70
+ /** is the jid a group */
71
+ export const isJidGroup = (jid) => jid?.endsWith('@g.us');
72
+ /** is the jid the status broadcast */
73
+ export const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';
74
+ /** is the jid a newsletter */
75
+ export const isJidNewsletter = (jid) => jid?.endsWith('@newsletter');
76
+ /** is the jid a hosted PN */
77
+ export const isHostedPnUser = (jid) => jid?.endsWith('@hosted');
78
+ /** is the jid a hosted LID */
79
+ export const isHostedLidUser = (jid) => jid?.endsWith('@hosted.lid');
80
+ const botRegexp = /^1313555\d{4}$|^131655500\d{2}$/;
81
+ export const isJidBot = (jid) => jid && botRegexp.test(jid.split('@')[0]) && jid.endsWith('@c.us');
82
+ export const jidNormalizedUser = (jid) => {
83
+ const result = jidDecode(jid);
84
+ if (!result) {
85
+ return '';
86
+ }
87
+ const { user, server } = result;
88
+ return jidEncode(user, server === 'c.us' ? 's.whatsapp.net' : server);
89
+ };
90
+ export const transferDevice = (fromJid, toJid) => {
91
+ const fromDecoded = jidDecode(fromJid);
92
+ const deviceId = fromDecoded?.device || 0;
93
+ const { server, user } = jidDecode(toJid);
94
+ return jidEncode(user, server, deviceId);
95
+ };
@@ -0,0 +1,19 @@
1
+ import * as constants from './constants.js';
2
+ /**
3
+ * the binary node WA uses internally for communication
4
+ *
5
+ * this is manipulated soley as an object and it does not have any functions.
6
+ * This is done for easy serialization, to prevent running into issues with prototypes &
7
+ * to maintain functional code structure
8
+ * */
9
+ export type BinaryNode = {
10
+ tag: string;
11
+ attrs: {
12
+ [key: string]: string;
13
+ };
14
+ content?: BinaryNode[] | string | Uint8Array;
15
+ };
16
+ export type BinaryNodeAttributes = BinaryNode['attrs'];
17
+ export type BinaryNodeData = BinaryNode['content'];
18
+ export type BinaryNodeCodingOptions = typeof constants;
19
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ import * as constants from './constants.js';
@@ -0,0 +1,7 @@
1
+ export class BinaryInfo {
2
+ constructor(options?: {});
3
+ protocolVersion: number;
4
+ sequence: number;
5
+ events: any[];
6
+ buffer: any[];
7
+ }
@@ -0,0 +1,9 @@
1
+ export class BinaryInfo {
2
+ constructor(options = {}) {
3
+ this.protocolVersion = 5;
4
+ this.sequence = 0;
5
+ this.events = [];
6
+ this.buffer = [];
7
+ Object.assign(this, options);
8
+ }
9
+ }