violetics 7.0.6-alpha → 7.0.8-alpha

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 (407) hide show
  1. package/LICENSE +1 -2
  2. package/README.md +456 -978
  3. package/WAProto/GenerateStatics.sh +3 -0
  4. package/WAProto/WAProto.proto +5479 -0
  5. package/WAProto/fix-imports.js +81 -0
  6. package/WAProto/index.d.ts +14017 -0
  7. package/WAProto/index.js +2728 -7894
  8. package/engine-requirements.js +7 -10
  9. package/index.cjs +196 -0
  10. package/index.d.ts +30 -0
  11. package/lib/Defaults/index.d.ts +74 -0
  12. package/lib/Defaults/index.d.ts.map +1 -0
  13. package/lib/Defaults/index.js +16 -25
  14. package/lib/Defaults/index.js.map +1 -0
  15. package/lib/Defaults/phonenumber-mcc.json +223 -0
  16. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  17. package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
  18. package/lib/Signal/Group/ciphertext-message.js +2 -1
  19. package/lib/Signal/Group/ciphertext-message.js.map +1 -0
  20. package/lib/Signal/Group/group-session-builder.d.ts +15 -0
  21. package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
  22. package/lib/Signal/Group/group-session-builder.js +2 -1
  23. package/lib/Signal/Group/group-session-builder.js.map +1 -0
  24. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  25. package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
  26. package/lib/Signal/Group/group_cipher.js +2 -1
  27. package/lib/Signal/Group/group_cipher.js.map +1 -0
  28. package/lib/Signal/Group/index.d.ts +12 -0
  29. package/lib/Signal/Group/index.d.ts.map +1 -0
  30. package/lib/Signal/Group/index.js +2 -1
  31. package/lib/Signal/Group/index.js.map +1 -0
  32. package/lib/Signal/Group/keyhelper.d.ts +11 -0
  33. package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
  34. package/lib/Signal/Group/keyhelper.js +2 -1
  35. package/lib/Signal/Group/keyhelper.js.map +1 -0
  36. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  37. package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
  38. package/lib/Signal/Group/sender-chain-key.js +2 -1
  39. package/lib/Signal/Group/sender-chain-key.js.map +1 -0
  40. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  41. package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
  42. package/lib/Signal/Group/sender-key-distribution-message.js +2 -1
  43. package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
  44. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  45. package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
  46. package/lib/Signal/Group/sender-key-message.js +2 -1
  47. package/lib/Signal/Group/sender-key-message.js.map +1 -0
  48. package/lib/Signal/Group/sender-key-name.d.ts +18 -0
  49. package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
  50. package/lib/Signal/Group/sender-key-name.js +2 -1
  51. package/lib/Signal/Group/sender-key-name.js.map +1 -0
  52. package/lib/Signal/Group/sender-key-record.d.ts +31 -0
  53. package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
  54. package/lib/Signal/Group/sender-key-record.js +2 -1
  55. package/lib/Signal/Group/sender-key-record.js.map +1 -0
  56. package/lib/Signal/Group/sender-key-state.d.ts +39 -0
  57. package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
  58. package/lib/Signal/Group/sender-key-state.js +2 -1
  59. package/lib/Signal/Group/sender-key-state.js.map +1 -0
  60. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  61. package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
  62. package/lib/Signal/Group/sender-message-key.js +2 -1
  63. package/lib/Signal/Group/sender-message-key.js.map +1 -0
  64. package/lib/Signal/libsignal.d.ts +5 -0
  65. package/lib/Signal/libsignal.d.ts.map +1 -0
  66. package/lib/Signal/libsignal.js +44 -8
  67. package/lib/Signal/libsignal.js.map +1 -0
  68. package/lib/Signal/lid-mapping.d.ts +19 -0
  69. package/lib/Signal/lid-mapping.d.ts.map +1 -0
  70. package/lib/Signal/lid-mapping.js +2 -1
  71. package/lib/Signal/lid-mapping.js.map +1 -0
  72. package/lib/Socket/Client/index.d.ts +3 -0
  73. package/lib/Socket/Client/index.d.ts.map +1 -0
  74. package/lib/Socket/Client/index.js +2 -1
  75. package/lib/Socket/Client/index.js.map +1 -0
  76. package/lib/Socket/Client/types.d.ts +16 -0
  77. package/lib/Socket/Client/types.d.ts.map +1 -0
  78. package/lib/Socket/Client/types.js +2 -1
  79. package/lib/Socket/Client/types.js.map +1 -0
  80. package/lib/Socket/Client/websocket.d.ts +13 -0
  81. package/lib/Socket/Client/websocket.d.ts.map +1 -0
  82. package/lib/Socket/Client/websocket.js +3 -11
  83. package/lib/Socket/Client/websocket.js.map +1 -0
  84. package/lib/Socket/business.d.ts +202 -0
  85. package/lib/Socket/business.d.ts.map +1 -0
  86. package/lib/Socket/business.js +2 -1
  87. package/lib/Socket/business.js.map +1 -0
  88. package/lib/Socket/chats.d.ts +111 -0
  89. package/lib/Socket/chats.d.ts.map +1 -0
  90. package/lib/Socket/chats.js +155 -71
  91. package/lib/Socket/chats.js.map +1 -0
  92. package/lib/Socket/communities.d.ts +258 -0
  93. package/lib/Socket/communities.d.ts.map +1 -0
  94. package/lib/Socket/communities.js +2 -1
  95. package/lib/Socket/communities.js.map +1 -0
  96. package/lib/Socket/community.js +361 -0
  97. package/lib/Socket/groups.d.ts +150 -0
  98. package/lib/Socket/groups.d.ts.map +1 -0
  99. package/lib/Socket/groups.js +140 -9
  100. package/lib/Socket/groups.js.map +1 -0
  101. package/lib/Socket/index.d.ts +245 -0
  102. package/lib/Socket/index.d.ts.map +1 -0
  103. package/lib/Socket/index.js +2 -1
  104. package/lib/Socket/index.js.map +1 -0
  105. package/lib/Socket/messages-recv.d.ts +187 -0
  106. package/lib/Socket/messages-recv.d.ts.map +1 -0
  107. package/lib/Socket/messages-recv.js +481 -204
  108. package/lib/Socket/messages-recv.js.map +1 -0
  109. package/lib/Socket/messages-send.d.ts +183 -0
  110. package/lib/Socket/messages-send.d.ts.map +1 -0
  111. package/lib/Socket/messages-send.js +622 -233
  112. package/lib/Socket/messages-send.js.map +1 -0
  113. package/lib/Socket/mex.d.ts +3 -0
  114. package/lib/Socket/mex.d.ts.map +1 -0
  115. package/lib/Socket/mex.js +2 -1
  116. package/lib/Socket/mex.js.map +1 -0
  117. package/lib/Socket/newsletter.d.ts +160 -0
  118. package/lib/Socket/newsletter.d.ts.map +1 -0
  119. package/lib/Socket/newsletter.js +107 -68
  120. package/lib/Socket/newsletter.js.map +1 -0
  121. package/lib/Socket/socket.d.ts +55 -0
  122. package/lib/Socket/socket.d.ts.map +1 -0
  123. package/lib/Socket/socket.js +25 -26
  124. package/lib/Socket/socket.js.map +1 -0
  125. package/lib/Socket/usync.js +76 -0
  126. package/lib/Store/index.js +2 -1
  127. package/lib/Store/make-cache-manager-store.js +77 -0
  128. package/lib/Store/make-in-memory-store.js +44 -65
  129. package/lib/Store/make-ordered-dictionary.js +1 -1
  130. package/lib/Store/object-repository.js +1 -1
  131. package/lib/Types/Auth.d.ts +116 -0
  132. package/lib/Types/Auth.d.ts.map +1 -0
  133. package/lib/Types/Auth.js +2 -1
  134. package/lib/Types/Auth.js.map +1 -0
  135. package/lib/Types/Bussines.d.ts +25 -0
  136. package/lib/Types/Bussines.d.ts.map +1 -0
  137. package/lib/Types/Bussines.js +2 -1
  138. package/lib/Types/Bussines.js.map +1 -0
  139. package/lib/Types/Call.d.ts +15 -0
  140. package/lib/Types/Call.d.ts.map +1 -0
  141. package/lib/Types/Call.js +2 -1
  142. package/lib/Types/Call.js.map +1 -0
  143. package/lib/Types/Chat.d.ts +123 -0
  144. package/lib/Types/Chat.d.ts.map +1 -0
  145. package/lib/Types/Chat.js +2 -1
  146. package/lib/Types/Chat.js.map +1 -0
  147. package/lib/Types/Contact.d.ts +24 -0
  148. package/lib/Types/Contact.d.ts.map +1 -0
  149. package/lib/Types/Contact.js +2 -1
  150. package/lib/Types/Contact.js.map +1 -0
  151. package/lib/Types/Events.d.ts +237 -0
  152. package/lib/Types/Events.d.ts.map +1 -0
  153. package/lib/Types/Events.js +2 -1
  154. package/lib/Types/Events.js.map +1 -0
  155. package/lib/Types/GroupMetadata.d.ts +67 -0
  156. package/lib/Types/GroupMetadata.d.ts.map +1 -0
  157. package/lib/Types/GroupMetadata.js +2 -1
  158. package/lib/Types/GroupMetadata.js.map +1 -0
  159. package/lib/Types/Label.d.ts +47 -0
  160. package/lib/Types/Label.d.ts.map +1 -0
  161. package/lib/Types/Label.js +2 -1
  162. package/lib/Types/Label.js.map +1 -0
  163. package/lib/Types/LabelAssociation.d.ts +30 -0
  164. package/lib/Types/LabelAssociation.d.ts.map +1 -0
  165. package/lib/Types/LabelAssociation.js +2 -1
  166. package/lib/Types/LabelAssociation.js.map +1 -0
  167. package/lib/Types/Message.d.ts +305 -0
  168. package/lib/Types/Message.d.ts.map +1 -0
  169. package/lib/Types/Message.js +2 -8
  170. package/lib/Types/Message.js.map +1 -0
  171. package/lib/Types/MexUpdates.js +9 -0
  172. package/lib/Types/Newsletter.d.ts +135 -0
  173. package/lib/Types/Newsletter.d.ts.map +1 -0
  174. package/lib/Types/Newsletter.js +14 -4
  175. package/lib/Types/Newsletter.js.map +1 -0
  176. package/lib/Types/Product.d.ts +79 -0
  177. package/lib/Types/Product.d.ts.map +1 -0
  178. package/lib/Types/Product.js +2 -1
  179. package/lib/Types/Product.js.map +1 -0
  180. package/lib/Types/Signal.d.ts +76 -0
  181. package/lib/Types/Signal.d.ts.map +1 -0
  182. package/lib/Types/Signal.js +2 -1
  183. package/lib/Types/Signal.js.map +1 -0
  184. package/lib/Types/Socket.d.ts +133 -0
  185. package/lib/Types/Socket.d.ts.map +1 -0
  186. package/lib/Types/Socket.js +2 -1
  187. package/lib/Types/Socket.js.map +1 -0
  188. package/lib/Types/State.d.ts +39 -0
  189. package/lib/Types/State.d.ts.map +1 -0
  190. package/lib/Types/State.js +2 -1
  191. package/lib/Types/State.js.map +1 -0
  192. package/lib/Types/USync.d.ts +26 -0
  193. package/lib/Types/USync.d.ts.map +1 -0
  194. package/lib/Types/USync.js +2 -1
  195. package/lib/Types/USync.js.map +1 -0
  196. package/lib/Types/index.d.ts +65 -0
  197. package/lib/Types/index.d.ts.map +1 -0
  198. package/lib/Types/index.js +3 -1
  199. package/lib/Types/index.js.map +1 -0
  200. package/lib/Utils/audioToBuffer.js +31 -0
  201. package/lib/Utils/auth-utils.d.ts +19 -0
  202. package/lib/Utils/auth-utils.d.ts.map +1 -0
  203. package/lib/Utils/auth-utils.js +2 -1
  204. package/lib/Utils/auth-utils.js.map +1 -0
  205. package/lib/Utils/baileys-event-stream.js +54 -0
  206. package/lib/Utils/browser-utils.d.ts +4 -0
  207. package/lib/Utils/browser-utils.d.ts.map +1 -0
  208. package/lib/Utils/browser-utils.js +35 -22
  209. package/lib/Utils/browser-utils.js.map +1 -0
  210. package/lib/Utils/business.d.ts +23 -0
  211. package/lib/Utils/business.d.ts.map +1 -0
  212. package/lib/Utils/business.js +2 -1
  213. package/lib/Utils/business.js.map +1 -0
  214. package/lib/Utils/chat-utils.d.ts +70 -0
  215. package/lib/Utils/chat-utils.d.ts.map +1 -0
  216. package/lib/Utils/chat-utils.js +2 -1
  217. package/lib/Utils/chat-utils.js.map +1 -0
  218. package/lib/Utils/crypto.d.ts +37 -0
  219. package/lib/Utils/crypto.d.ts.map +1 -0
  220. package/lib/Utils/crypto.js +2 -1
  221. package/lib/Utils/crypto.js.map +1 -0
  222. package/lib/Utils/decode-wa-message.d.ts +48 -0
  223. package/lib/Utils/decode-wa-message.d.ts.map +1 -0
  224. package/lib/Utils/decode-wa-message.js +2 -1
  225. package/lib/Utils/decode-wa-message.js.map +1 -0
  226. package/lib/Utils/event-buffer.d.ts +34 -0
  227. package/lib/Utils/event-buffer.d.ts.map +1 -0
  228. package/lib/Utils/event-buffer.js +4 -3
  229. package/lib/Utils/event-buffer.js.map +1 -0
  230. package/lib/Utils/generics.d.ts +91 -0
  231. package/lib/Utils/generics.d.ts.map +1 -0
  232. package/lib/Utils/generics.js +34 -7
  233. package/lib/Utils/generics.js.map +1 -0
  234. package/lib/Utils/history.d.ts +22 -0
  235. package/lib/Utils/history.d.ts.map +1 -0
  236. package/lib/Utils/history.js +2 -1
  237. package/lib/Utils/history.js.map +1 -0
  238. package/lib/Utils/identity-change-handler.d.ts +37 -0
  239. package/lib/Utils/identity-change-handler.d.ts.map +1 -0
  240. package/lib/Utils/identity-change-handler.js +2 -1
  241. package/lib/Utils/identity-change-handler.js.map +1 -0
  242. package/lib/Utils/index.d.ts +22 -0
  243. package/lib/Utils/index.d.ts.map +1 -0
  244. package/lib/Utils/index.js +8 -1
  245. package/lib/Utils/index.js.map +1 -0
  246. package/lib/Utils/link-preview.d.ts +21 -0
  247. package/lib/Utils/link-preview.d.ts.map +1 -0
  248. package/lib/Utils/link-preview.js +2 -1
  249. package/lib/Utils/link-preview.js.map +1 -0
  250. package/lib/Utils/logger.d.ts +13 -0
  251. package/lib/Utils/logger.d.ts.map +1 -0
  252. package/lib/Utils/logger.js +2 -1
  253. package/lib/Utils/logger.js.map +1 -0
  254. package/lib/Utils/lt-hash.d.ts +8 -0
  255. package/lib/Utils/lt-hash.d.ts.map +1 -0
  256. package/lib/Utils/lt-hash.js +2 -1
  257. package/lib/Utils/lt-hash.js.map +1 -0
  258. package/lib/Utils/make-mutex.d.ts +9 -0
  259. package/lib/Utils/make-mutex.d.ts.map +1 -0
  260. package/lib/Utils/make-mutex.js +2 -1
  261. package/lib/Utils/make-mutex.js.map +1 -0
  262. package/lib/Utils/message-retry-manager.d.ts +110 -0
  263. package/lib/Utils/message-retry-manager.d.ts.map +1 -0
  264. package/lib/Utils/message-retry-manager.js +3 -2
  265. package/lib/Utils/message-retry-manager.js.map +1 -0
  266. package/lib/Utils/messages-media.d.ts +130 -0
  267. package/lib/Utils/messages-media.d.ts.map +1 -0
  268. package/lib/Utils/messages-media.js +186 -180
  269. package/lib/Utils/messages-media.js.map +1 -0
  270. package/lib/Utils/messages-newsletter.d.ts +84 -0
  271. package/lib/Utils/messages-newsletter.js +316 -0
  272. package/lib/Utils/messages.d.ts +92 -0
  273. package/lib/Utils/messages.d.ts.map +1 -0
  274. package/lib/Utils/messages.js +929 -1116
  275. package/lib/Utils/messages.js.map +1 -0
  276. package/lib/Utils/noise-handler.d.ts +20 -0
  277. package/lib/Utils/noise-handler.d.ts.map +1 -0
  278. package/lib/Utils/noise-handler.js +2 -7
  279. package/lib/Utils/noise-handler.js.map +1 -0
  280. package/lib/Utils/pre-key-manager.d.ts +28 -0
  281. package/lib/Utils/pre-key-manager.d.ts.map +1 -0
  282. package/lib/Utils/pre-key-manager.js +2 -1
  283. package/lib/Utils/pre-key-manager.js.map +1 -0
  284. package/lib/Utils/process-message.d.ts +60 -0
  285. package/lib/Utils/process-message.d.ts.map +1 -0
  286. package/lib/Utils/process-message.js +2 -1
  287. package/lib/Utils/process-message.js.map +1 -0
  288. package/lib/Utils/reporting-utils.d.ts +11 -0
  289. package/lib/Utils/reporting-utils.d.ts.map +1 -0
  290. package/lib/Utils/reporting-utils.js +2 -1
  291. package/lib/Utils/reporting-utils.js.map +1 -0
  292. package/lib/Utils/resolve-jid.d.ts +43 -0
  293. package/lib/Utils/resolve-jid.js +101 -0
  294. package/lib/Utils/signal.d.ts +34 -0
  295. package/lib/Utils/signal.d.ts.map +1 -0
  296. package/lib/Utils/signal.js +2 -1
  297. package/lib/Utils/signal.js.map +1 -0
  298. package/lib/Utils/streamToBuffer.js +17 -0
  299. package/lib/Utils/sync-action-utils.d.ts +19 -0
  300. package/lib/Utils/sync-action-utils.d.ts.map +1 -0
  301. package/lib/Utils/sync-action-utils.js +2 -1
  302. package/lib/Utils/sync-action-utils.js.map +1 -0
  303. package/lib/Utils/tc-token-utils.d.ts +12 -0
  304. package/lib/Utils/tc-token-utils.d.ts.map +1 -0
  305. package/lib/Utils/tc-token-utils.js +2 -1
  306. package/lib/Utils/tc-token-utils.js.map +1 -0
  307. package/lib/Utils/use-mongo-file-auth-state.js +77 -0
  308. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  309. package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
  310. package/lib/Utils/use-multi-file-auth-state.js +2 -1
  311. package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
  312. package/lib/Utils/use-single-file-auth-state.js +74 -0
  313. package/lib/Utils/validate-connection.d.ts +11 -0
  314. package/lib/Utils/validate-connection.d.ts.map +1 -0
  315. package/lib/Utils/validate-connection.js +4 -10
  316. package/lib/Utils/validate-connection.js.map +1 -0
  317. package/lib/WABinary/constants.d.ts +28 -0
  318. package/lib/WABinary/constants.d.ts.map +1 -0
  319. package/lib/WABinary/constants.js +2 -1
  320. package/lib/WABinary/constants.js.map +1 -0
  321. package/lib/WABinary/decode.d.ts +7 -0
  322. package/lib/WABinary/decode.d.ts.map +1 -0
  323. package/lib/WABinary/decode.js +2 -1
  324. package/lib/WABinary/decode.js.map +1 -0
  325. package/lib/WABinary/encode.d.ts +3 -0
  326. package/lib/WABinary/encode.d.ts.map +1 -0
  327. package/lib/WABinary/encode.js +2 -1
  328. package/lib/WABinary/encode.js.map +1 -0
  329. package/lib/WABinary/generic-utils.d.ts +15 -0
  330. package/lib/WABinary/generic-utils.d.ts.map +1 -0
  331. package/lib/WABinary/generic-utils.js +15 -97
  332. package/lib/WABinary/generic-utils.js.map +1 -0
  333. package/lib/WABinary/index.d.ts +6 -0
  334. package/lib/WABinary/index.d.ts.map +1 -0
  335. package/lib/WABinary/index.js +3 -1
  336. package/lib/WABinary/index.js.map +1 -0
  337. package/lib/WABinary/jid-utils.d.ts +48 -0
  338. package/lib/WABinary/jid-utils.d.ts.map +1 -0
  339. package/lib/WABinary/jid-utils.js +4 -1
  340. package/lib/WABinary/jid-utils.js.map +1 -0
  341. package/lib/WABinary/types.d.ts +19 -0
  342. package/lib/WABinary/types.d.ts.map +1 -0
  343. package/lib/WABinary/types.js +2 -1
  344. package/lib/WABinary/types.js.map +1 -0
  345. package/lib/WAM/BinaryInfo.d.ts +9 -0
  346. package/lib/WAM/BinaryInfo.d.ts.map +1 -0
  347. package/lib/WAM/BinaryInfo.js +2 -1
  348. package/lib/WAM/BinaryInfo.js.map +1 -0
  349. package/lib/WAM/constants.d.ts +40 -0
  350. package/lib/WAM/constants.d.ts.map +1 -0
  351. package/lib/WAM/constants.js +2 -1
  352. package/lib/WAM/constants.js.map +1 -0
  353. package/lib/WAM/encode.d.ts +3 -0
  354. package/lib/WAM/encode.d.ts.map +1 -0
  355. package/lib/WAM/encode.js +2 -1
  356. package/lib/WAM/encode.js.map +1 -0
  357. package/lib/WAM/index.d.ts +4 -0
  358. package/lib/WAM/index.d.ts.map +1 -0
  359. package/lib/WAM/index.js +2 -1
  360. package/lib/WAM/index.js.map +1 -0
  361. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  362. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
  363. package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -1
  364. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
  365. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  366. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
  367. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +2 -1
  368. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
  369. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  370. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
  371. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -1
  372. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
  373. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  374. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
  375. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -1
  376. package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
  377. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  378. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
  379. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +2 -1
  380. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
  381. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
  382. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
  383. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +2 -1
  384. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
  385. package/lib/WAUSync/Protocols/index.d.ts +5 -0
  386. package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
  387. package/lib/WAUSync/Protocols/index.js +3 -1
  388. package/lib/WAUSync/Protocols/index.js.map +1 -0
  389. package/lib/WAUSync/USyncQuery.d.ts +29 -0
  390. package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
  391. package/lib/WAUSync/USyncQuery.js +2 -1
  392. package/lib/WAUSync/USyncQuery.js.map +1 -0
  393. package/lib/WAUSync/USyncUser.d.ts +13 -0
  394. package/lib/WAUSync/USyncUser.d.ts.map +1 -0
  395. package/lib/WAUSync/USyncUser.js +2 -1
  396. package/lib/WAUSync/USyncUser.js.map +1 -0
  397. package/lib/WAUSync/index.d.ts +4 -0
  398. package/lib/WAUSync/index.d.ts.map +1 -0
  399. package/lib/WAUSync/index.js +2 -1
  400. package/lib/WAUSync/index.js.map +1 -0
  401. package/lib/index.d.ts +12 -0
  402. package/lib/index.d.ts.map +1 -0
  403. package/lib/index.js +22 -2
  404. package/lib/index.js.map +1 -0
  405. package/package.json +75 -72
  406. package/lib/Utils/offline-node-processor.js +0 -39
  407. package/lib/Utils/stanza-ack.js +0 -37
@@ -7,15 +7,14 @@ import { DEFAULT_CACHE_TTLS, KEY_BUNDLE_TYPE, MIN_PREKEY_COUNT, PLACEHOLDER_MAX_
7
7
  import { WAMessageStatus, WAMessageStubType } from '../Types/index.js';
8
8
  import { aesDecryptCTR, aesEncryptGCM, cleanMessage, Curve, decodeMediaRetryNode, decodeMessageNode, decryptMessageNode, delay, derivePairingCodeKey, encodeBigEndian, encodeSignedDeviceIdentity, extractAddressingContext, getCallStatusFromNode, getHistoryMsg, getNextPreKeys, getStatusFromReceiptType, handleIdentityChange, hkdf, MISSING_KEYS_ERROR_TEXT, NACK_REASONS, NO_MESSAGE_FOUND_ERROR_TEXT, toNumber, unixTimestampSeconds, xmppPreKey, xmppSignedPreKey } from '../Utils/index.js';
9
9
  import { makeMutex } from '../Utils/make-mutex.js';
10
- import { makeOfflineNodeProcessor } from '../Utils/offline-node-processor.js';
11
- import { buildAckStanza } from '../Utils/stanza-ack.js';
12
10
  import { areJidsSameUser, binaryNodeToString, getAllBinaryNodeChildren, getBinaryNodeChild, getBinaryNodeChildBuffer, getBinaryNodeChildren, getBinaryNodeChildString, isJidGroup, isJidNewsletter, isJidStatusBroadcast, isLidUser, isPnUser, jidDecode, jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary/index.js';
13
11
  import { extractGroupMetadata } from './groups.js';
14
12
  import { makeMessagesSocket } from './messages-send.js';
13
+ import { USyncQuery, USyncUser } from '../WAUSync/index.js';
15
14
  export const makeMessagesRecvSocket = (config) => {
16
15
  const { logger, retryRequestDelayMs, maxMsgRetryCount, getMessage, shouldIgnoreJid, enableAutoSessionRecreation } = config;
17
16
  const sock = makeMessagesSocket(config);
18
- const { ev, authState, ws, messageMutex, notificationMutex, receiptMutex, signalRepository, query, upsertMessage, resyncAppState, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, sendPeerDataOperationMessage, generateMessageTag, messageRetryManager } = sock;
17
+ const { ev, authState, ws, messageMutex, notificationMutex, receiptMutex, signalRepository, query, upsertMessage, resyncAppState, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, sendPeerDataOperationMessage, messageRetryManager } = sock;
19
18
  /** this mutex ensures that each retryRequest will wait for the previous one to finish */
20
19
  const retryMutex = makeMutex();
21
20
  const msgRetryCache = config.msgRetryCounterCache ||
@@ -65,7 +64,7 @@ export const makeMessagesRecvSocket = (config) => {
65
64
  // metadata (LID details, timestamps, etc.) that the phone may omit
66
65
  await placeholderResendCache.set(messageKey?.id, msgData || true);
67
66
  }
68
- await delay(500);
67
+ await delay(2000);
69
68
  if (!(await placeholderResendCache.get(messageKey?.id))) {
70
69
  logger.debug({ messageKey }, 'message received while resend requested');
71
70
  return 'RESOLVED';
@@ -206,7 +205,7 @@ export const makeMessagesRecvSocket = (config) => {
206
205
  message: messageProto,
207
206
  messageTimestamp: +child.attrs.t
208
207
  }).toJSON();
209
- await upsertMessage(fullMessage, 'append');
208
+ await upsertMessage(fullMessage, 'notify');
210
209
  logger.info('Processed plaintext newsletter message');
211
210
  }
212
211
  catch (error) {
@@ -219,9 +218,32 @@ export const makeMessagesRecvSocket = (config) => {
219
218
  break;
220
219
  }
221
220
  };
222
- const sendMessageAck = async (node, errorCode) => {
223
- const stanza = buildAckStanza(node, errorCode, authState.creds.me.id);
224
- logger.debug({ recv: { tag: node.tag, attrs: node.attrs }, sent: stanza.attrs }, 'sent ack');
221
+ const sendMessageAck = async ({ tag, attrs, content }, errorCode) => {
222
+ const stanza = {
223
+ tag: 'ack',
224
+ attrs: {
225
+ id: attrs.id,
226
+ to: attrs.from,
227
+ class: tag
228
+ }
229
+ };
230
+ if (!!errorCode) {
231
+ stanza.attrs.error = errorCode.toString();
232
+ }
233
+ if (!!attrs.participant) {
234
+ stanza.attrs.participant = attrs.participant;
235
+ }
236
+ if (!!attrs.recipient) {
237
+ stanza.attrs.recipient = attrs.recipient;
238
+ }
239
+ if (!!attrs.type &&
240
+ (tag !== 'message' || getBinaryNodeChild({ tag, attrs, content }, 'unavailable') || errorCode !== 0)) {
241
+ stanza.attrs.type = attrs.type;
242
+ }
243
+ if (tag === 'message' && getBinaryNodeChild({ tag, attrs, content }, 'unavailable')) {
244
+ stanza.attrs.from = authState.creds.me.id;
245
+ }
246
+ logger.debug({ recv: { tag, attrs }, sent: stanza.attrs }, 'sent ack');
225
247
  await sendNode(stanza);
226
248
  };
227
249
  const rejectCall = async (callId, callFrom) => {
@@ -245,97 +267,6 @@ export const makeMessagesRecvSocket = (config) => {
245
267
  };
246
268
  await query(stanza);
247
269
  };
248
- // Lia@Note 01-03-26 --- Source: https://github.com/koptereli/Baileys/commit/575cd41e6f01a9b3e1d7e2708c2292fa93de91f2
249
- const initiateCall = async (jid, options = {}) => {
250
- const meId = authState.creds.me?.id;
251
- if (!meId) {
252
- throw new Boom('Not authenticated');
253
- }
254
- const callId = randomBytes(8).toString('hex');
255
- const isVideo = !!options.isVideo;
256
- const isGroup = isJidGroup(jid);
257
- const stanza = {
258
- tag: 'call',
259
- attrs: {
260
- id: generateMessageTag(),
261
- from: meId,
262
- to: jid,
263
- t: String(unixTimestampSeconds()),
264
- ...(authState.creds.me?.name ? { notify: authState.creds.me.name } : {})
265
- },
266
- content: [
267
- {
268
- tag: 'offer',
269
- attrs: {
270
- 'call-id': callId,
271
- 'call-creator': meId,
272
- count: '0'
273
- },
274
- content: [
275
- {
276
- tag: isVideo ? 'video' : 'audio',
277
- attrs: {}
278
- },
279
- {
280
- tag: 'net',
281
- attrs: {}
282
- },
283
- {
284
- tag: 'encopt',
285
- attrs: { key: randomBytes(2).toString('hex') }
286
- },
287
- {
288
- tag: 'relaylatency',
289
- attrs: {}
290
- },
291
- {
292
- tag: 'te',
293
- attrs: {}
294
- }
295
- ]
296
- }
297
- ]
298
- };
299
- await query(stanza);
300
- await callOfferCache.set(callId, {
301
- chatId: jid,
302
- from: meId,
303
- id: callId,
304
- date: new Date(),
305
- offline: false,
306
- status: 'offer',
307
- isVideo,
308
- isGroup,
309
- groupJid: isGroup ? jid : undefined
310
- });
311
- // TODO: implement ICE/DTLS-SRTP call media setup once full signaling requirements are mapped.
312
- return { callId, to: jid, isVideo };
313
- };
314
- const cancelCall = async (callId, callTo) => {
315
- const meId = authState.creds.me?.id;
316
- if (!meId) {
317
- throw new Boom('Not authenticated');
318
- }
319
- const stanza = {
320
- tag: 'call',
321
- attrs: {
322
- from: meId,
323
- to: callTo
324
- },
325
- content: [
326
- {
327
- tag: 'terminate',
328
- attrs: {
329
- 'call-id': callId,
330
- 'call-creator': meId,
331
- count: '0'
332
- }
333
- }
334
- ]
335
- };
336
- await query(stanza);
337
- await callOfferCache.del(callId);
338
- };
339
270
  const sendRetryRequest = async (node, forceIncludeKeys = false) => {
340
271
  const { fullMessage } = decodeMessageNode(node, authState.creds.me.id, authState.creds.me.lid || '');
341
272
  const { key: msgKey } = fullMessage;
@@ -974,7 +905,7 @@ export const makeMessagesRecvSocket = (config) => {
974
905
  ]);
975
906
  }
976
907
  finally {
977
- await sendMessageAck(node).catch(ackErr => logger.error({ ackErr }, 'failed to ack receipt'));
908
+ await sendMessageAck(node);
978
909
  }
979
910
  };
980
911
  const handleNotification = async (node) => {
@@ -1009,7 +940,245 @@ export const makeMessagesRecvSocket = (config) => {
1009
940
  ]);
1010
941
  }
1011
942
  finally {
1012
- await sendMessageAck(node).catch(ackErr => logger.error({ ackErr }, 'failed to ack notification'));
943
+ await sendMessageAck(node);
944
+ }
945
+ };
946
+ const resolveMentionedLIDs = async (msg, lidMapping) => {
947
+ if (msg.key?.participant?.endsWith('@lid')) {
948
+ try {
949
+ const pn = await lidMapping.getPNForLID(msg.key.participant);
950
+ if (pn) {
951
+ logger.debug({ lid: msg.key.participant, pn }, 'resolved key.participant LID → PN');
952
+ msg.key.participant = pn;
953
+ }
954
+ }
955
+ catch { }
956
+ }
957
+ if (msg.key?.remoteJid?.endsWith('@lid')) {
958
+ try {
959
+ const pn = await lidMapping.getPNForLID(msg.key.remoteJid);
960
+ if (pn) {
961
+ logger.debug({ lid: msg.key.remoteJid, pn }, 'resolved key.remoteJid LID → PN');
962
+ msg.key.remoteJid = pn;
963
+ }
964
+ }
965
+ catch { }
966
+ }
967
+ const msgContent = msg.message;
968
+ if (!msgContent)
969
+ return;
970
+ const getContextInfo = (content) => {
971
+ if (!content || typeof content !== 'object')
972
+ return null;
973
+ if (content.contextInfo)
974
+ return content.contextInfo;
975
+ for (const val of Object.values(content)) {
976
+ const found = getContextInfo(val);
977
+ if (found)
978
+ return found;
979
+ }
980
+ return null;
981
+ };
982
+ const getTextField = (content) => {
983
+ if (!content || typeof content !== 'object')
984
+ return null;
985
+ for (const key of ['text', 'caption', 'conversation']) {
986
+ if (typeof content[key] === 'string')
987
+ return { obj: content, key };
988
+ }
989
+ for (const val of Object.values(content)) {
990
+ const found = getTextField(val);
991
+ if (found)
992
+ return found;
993
+ }
994
+ return null;
995
+ };
996
+ // Resolve semua contextInfo termasuk yang ada di dalam quotedMessage
997
+ const getAllContextInfos = (content, results = []) => {
998
+ if (!content || typeof content !== 'object') return results;
999
+ if (content.contextInfo) {
1000
+ results.push(content.contextInfo);
1001
+ // Juga cari di dalam quotedMessage secara rekursif
1002
+ if (content.contextInfo.quotedMessage) {
1003
+ getAllContextInfos(content.contextInfo.quotedMessage, results);
1004
+ }
1005
+ }
1006
+ for (const val of Object.values(content)) {
1007
+ if (val && typeof val === 'object' && !results.includes(val)) {
1008
+ getAllContextInfos(val, results);
1009
+ }
1010
+ }
1011
+ return results;
1012
+ };
1013
+ const contextInfo = getContextInfo(msgContent);
1014
+ // Resolve participant LID di semua contextInfo (termasuk quotedMessage)
1015
+ const allContextInfos = getAllContextInfos(msgContent);
1016
+ for (const ctx of allContextInfos) {
1017
+ if (ctx?.participant?.endsWith('@lid')) {
1018
+ try {
1019
+ const pn = await lidMapping.getPNForLID(ctx.participant);
1020
+ if (pn) {
1021
+ logger.debug({ lid: ctx.participant, pn }, 'resolved nested contextInfo.participant LID → PN');
1022
+ ctx.participant = pn;
1023
+ }
1024
+ } catch { }
1025
+ }
1026
+ // Resolve mentionedJid di quotedMessage contextInfo juga
1027
+ if (ctx !== contextInfo && ctx?.mentionedJid?.length) {
1028
+ const lids = ctx.mentionedJid.filter(j => j?.endsWith('@lid'));
1029
+ for (const lid of lids) {
1030
+ try {
1031
+ const pn = await lidMapping.getPNForLID(lid);
1032
+ if (pn) ctx.mentionedJid = ctx.mentionedJid.map(j => j === lid ? pn : j);
1033
+ } catch { }
1034
+ }
1035
+ }
1036
+ }
1037
+ // resolve contextInfo.participant (sender of quoted message) jika masih LID
1038
+ if (contextInfo?.participant?.endsWith('@lid')) {
1039
+ try {
1040
+ const pn = await lidMapping.getPNForLID(contextInfo.participant);
1041
+ if (pn) {
1042
+ logger.debug({ lid: contextInfo.participant, pn }, 'resolved contextInfo.participant LID → PN');
1043
+ contextInfo.participant = pn;
1044
+ }
1045
+ }
1046
+ catch { }
1047
+ }
1048
+ if (!contextInfo?.mentionedJid?.length)
1049
+ return;
1050
+ // Fix text yang masih mengandung LID number meskipun mentionedJid sudah resolved ke PN
1051
+ // Kasus: mentionedJid sudah jadi @s.whatsapp.net tapi text masih "@165159209271535" (LID num)
1052
+ const textFieldEarly = getTextField(msgContent);
1053
+ if (textFieldEarly) {
1054
+ let earlyText = textFieldEarly.obj[textFieldEarly.key] || '';
1055
+ // Cek apakah text mengandung @angka panjang (>12 digit = kemungkinan LID number bukan nomor HP)
1056
+ const lidNumPattern = /@(\d{13,20})/g;
1057
+ const lidNumMatches = [...earlyText.matchAll(lidNumPattern)];
1058
+ if (lidNumMatches.length > 0) {
1059
+ // Untuk setiap mentionedJid yang sudah resolved, cek apakah ada LID number di text
1060
+ for (const resolvedJid of contextInfo.mentionedJid) {
1061
+ if (resolvedJid?.endsWith('@lid')) continue; // belum resolved, skip dulu
1062
+ const pnNum = resolvedJid.split('@')[0].split(':')[0];
1063
+ if (!pnNum) continue;
1064
+ // Cari LID number di text yang paling mungkin match (berdasarkan urutan)
1065
+ for (const match of lidNumMatches) {
1066
+ const lidNum = match[1];
1067
+ if (earlyText.includes(`@${lidNum}`)) {
1068
+ earlyText = earlyText.split(`@${lidNum}`).join(`@${pnNum}`);
1069
+ logger.debug({ lidNum, pnNum }, 'replaced LID number in text with PN number');
1070
+ break;
1071
+ }
1072
+ }
1073
+ }
1074
+ textFieldEarly.obj[textFieldEarly.key] = earlyText;
1075
+ }
1076
+ }
1077
+ const hasLid = contextInfo.mentionedJid.some((j) => j?.endsWith('@lid'));
1078
+ if (!hasLid)
1079
+ return;
1080
+ const lidJids = contextInfo.mentionedJid.filter((j) => j?.endsWith('@lid'));
1081
+ const resolveMap = new Map();
1082
+ const stillUnresolved = [];
1083
+ for (const lidJid of lidJids) {
1084
+ try {
1085
+ const pn = await lidMapping.getPNForLID(lidJid);
1086
+ if (pn) {
1087
+ resolveMap.set(lidJid, pn);
1088
+ }
1089
+ else {
1090
+ stillUnresolved.push(lidJid);
1091
+ }
1092
+ }
1093
+ catch {
1094
+ stillUnresolved.push(lidJid);
1095
+ }
1096
+ }
1097
+ if (stillUnresolved.length > 0) {
1098
+ try {
1099
+ const usyncQ = new USyncQuery()
1100
+ .withContactProtocol()
1101
+ .withContext('background');
1102
+ for (const lidJid of stillUnresolved) {
1103
+ usyncQ.withUser(new USyncUser().withId(lidJid));
1104
+ }
1105
+ const result = await sock.executeUSyncQuery(usyncQ);
1106
+ if (result?.list) {
1107
+ const mappings = [];
1108
+ for (const item of result.list) {
1109
+ // item.id bisa berupa PN (@s.whatsapp.net) atau LID (@lid)
1110
+ // stillUnresolved berisi LID. Match berdasarkan numeric prefix
1111
+ const itemNum = (item.id ?? '').split('@')[0].split(':')[0];
1112
+ const lidJid = stillUnresolved.find(l => {
1113
+ if (l === item.id) return true;
1114
+ const lNum = l.split('@')[0].split(':')[0];
1115
+ return itemNum && lNum && itemNum === lNum;
1116
+ });
1117
+ if (lidJid && item.id && !item.id.endsWith('@lid')) {
1118
+ resolveMap.set(lidJid, item.id);
1119
+ mappings.push({ lid: lidJid, pn: item.id });
1120
+ logger.debug({ lid: lidJid, pn: item.id }, 'USync resolved LID → PN');
1121
+ }
1122
+ }
1123
+ if (mappings.length > 0) {
1124
+ lidMapping.storeLIDPNMappings(mappings).catch(() => { });
1125
+ }
1126
+ }
1127
+ }
1128
+ catch (e) {
1129
+ logger.debug({ err: e }, 'USync LID resolve failed, using cache only');
1130
+ }
1131
+ }
1132
+ // ── Text-based PN extraction ─────────────────────────────────────────────
1133
+ // WA kadang sudah resolve nomor HP di text (@6285133801810) tapi mentionedJid
1134
+ // masih berisi LID. Kita ekstrak semua @nomor dari text lalu matching ke LID
1135
+ // yang masih unresolved berdasarkan urutan kemunculan di mentionedJid.
1136
+ const textField = getTextField(msgContent);
1137
+ const stillUnresolvedAfterUSync = lidJids.filter(l => !resolveMap.has(l));
1138
+ if (stillUnresolvedAfterUSync.length > 0 && textField) {
1139
+ const rawText = textField.obj[textField.key] || '';
1140
+ // Ekstrak semua mention @nomor dari text (hanya angka, min 7 digit)
1141
+ const mentionMatches = [...rawText.matchAll(/@(\d{7,15})/g)].map(m => m[1]);
1142
+ if (mentionMatches.length > 0) {
1143
+ // Match LID ke nomor berdasarkan urutan index di mentionedJid
1144
+ const lidOrder = contextInfo.mentionedJid
1145
+ .map((jid, idx) => ({ jid, idx }))
1146
+ .filter(({ jid }) => stillUnresolvedAfterUSync.includes(jid));
1147
+ for (let i = 0; i < lidOrder.length && i < mentionMatches.length; i++) {
1148
+ const lidJid = lidOrder[i].jid;
1149
+ const phoneNum = mentionMatches[i];
1150
+ const pnJid = `${phoneNum}@s.whatsapp.net`;
1151
+ resolveMap.set(lidJid, pnJid);
1152
+ // Simpan mapping baru ini ke store untuk request berikutnya
1153
+ lidMapping.storeLIDPNMappings([{ lid: lidJid, pn: pnJid }]).catch(() => {});
1154
+ logger.debug({ lid: lidJid, pn: pnJid }, 'text-extracted PN for LID → PN');
1155
+ }
1156
+ }
1157
+ }
1158
+ // ── End text-based PN extraction ─────────────────────────────────────────
1159
+
1160
+ contextInfo.mentionedJid = contextInfo.mentionedJid.map((jid) => {
1161
+ if (!jid?.endsWith('@lid'))
1162
+ return jid;
1163
+ const resolved = resolveMap.get(jid);
1164
+ if (resolved) {
1165
+ logger.debug({ lid: jid, pn: resolved }, 'resolved mentionedJid LID → PN');
1166
+ return resolved;
1167
+ }
1168
+ // Tetap kembalikan LID jika benar-benar tidak bisa di-resolve
1169
+ return jid;
1170
+ });
1171
+ if (textField) {
1172
+ let text = textField.obj[textField.key];
1173
+ // Replace LID number di text dengan PN number yang sudah di-resolve
1174
+ for (const [lidJid, pnJid] of resolveMap) {
1175
+ const lidNum = lidJid.split('@')[0].split(':')[0] ?? '';
1176
+ const pnNum = pnJid.replace('@s.whatsapp.net', '').split(':')[0] ?? '';
1177
+ if (lidNum && pnNum && text.includes(lidNum)) {
1178
+ text = text.split(lidNum).join(pnNum);
1179
+ }
1180
+ }
1181
+ textField.obj[textField.key] = text;
1013
1182
  }
1014
1183
  };
1015
1184
  const handleMessage = async (node) => {
@@ -1025,34 +1194,36 @@ export const makeMessagesRecvSocket = (config) => {
1025
1194
  await sendMessageAck(node, NACK_REASONS.MissingMessageSecret);
1026
1195
  return;
1027
1196
  }
1028
- let acked = false;
1029
- try {
1030
- const { fullMessage: msg, category, author, decrypt } = decryptMessageNode(node, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, logger);
1031
- const alt = msg.key.participantAlt || msg.key.remoteJidAlt;
1032
- // store new mappings we didn't have before
1033
- if (!!alt) {
1034
- const altServer = jidDecode(alt)?.server;
1035
- const primaryJid = msg.key.participant || msg.key.remoteJid;
1036
- if (altServer === 'lid') {
1037
- if (!(await signalRepository.lidMapping.getPNForLID(alt))) {
1038
- await signalRepository.lidMapping.storeLIDPNMappings([{ lid: alt, pn: primaryJid }]);
1039
- await signalRepository.migrateSession(primaryJid, alt);
1040
- }
1041
- }
1042
- else {
1043
- await signalRepository.lidMapping.storeLIDPNMappings([{ lid: primaryJid, pn: alt }]);
1044
- await signalRepository.migrateSession(alt, primaryJid);
1197
+ const { fullMessage: msg, category, author, decrypt } = decryptMessageNode(node, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, logger);
1198
+ const alt = msg.key.participantAlt || msg.key.remoteJidAlt;
1199
+ // store new mappings we didn't have before
1200
+ if (!!alt) {
1201
+ const altServer = jidDecode(alt)?.server;
1202
+ const primaryJid = msg.key.participant || msg.key.remoteJid;
1203
+ if (altServer === 'lid') {
1204
+ if (!(await signalRepository.lidMapping.getPNForLID(alt))) {
1205
+ await signalRepository.lidMapping.storeLIDPNMappings([{ lid: alt, pn: primaryJid }]);
1206
+ await signalRepository.migrateSession(primaryJid, alt);
1045
1207
  }
1046
1208
  }
1209
+ else {
1210
+ await signalRepository.lidMapping.storeLIDPNMappings([{ lid: primaryJid, pn: alt }]);
1211
+ await signalRepository.migrateSession(alt, primaryJid);
1212
+ }
1213
+ }
1214
+ if (msg.key?.remoteJid && msg.key?.id && messageRetryManager) {
1215
+ messageRetryManager.addRecentMessage(msg.key.remoteJid, msg.key.id, msg.message);
1216
+ logger.debug({
1217
+ jid: msg.key.remoteJid,
1218
+ id: msg.key.id
1219
+ }, 'Added message to recent cache for retry receipts');
1220
+ }
1221
+ try {
1047
1222
  await messageMutex.mutex(async () => {
1048
1223
  await decrypt();
1049
- if (msg.key?.remoteJid && msg.key?.id && msg.message && messageRetryManager) {
1050
- messageRetryManager.addRecentMessage(msg.key.remoteJid, msg.key.id, msg.message);
1051
- }
1052
1224
  // message failed to decrypt
1053
1225
  if (msg.messageStubType === proto.WebMessageInfo.StubType.CIPHERTEXT && msg.category !== 'peer') {
1054
1226
  if (msg?.messageStubParameters?.[0] === MISSING_KEYS_ERROR_TEXT) {
1055
- acked = true;
1056
1227
  return sendMessageAck(node, NACK_REASONS.ParsingError);
1057
1228
  }
1058
1229
  if (msg.messageStubParameters?.[0] === NO_MESSAGE_FOUND_ERROR_TEXT) {
@@ -1064,13 +1235,11 @@ export const makeMessagesRecvSocket = (config) => {
1064
1235
  unavailableType === 'hosted_unavailable_fanout' ||
1065
1236
  unavailableType === 'view_once_unavailable_fanout') {
1066
1237
  logger.debug({ msgId: msg.key.id, unavailableType }, 'skipping placeholder resend for excluded unavailable type');
1067
- acked = true;
1068
1238
  return sendMessageAck(node);
1069
1239
  }
1070
1240
  const messageAge = unixTimestampSeconds() - toNumber(msg.messageTimestamp);
1071
1241
  if (messageAge > PLACEHOLDER_MAX_AGE_SECONDS) {
1072
1242
  logger.debug({ msgId: msg.key.id, messageAge }, 'skipping placeholder resend for old message');
1073
- acked = true;
1074
1243
  return sendMessageAck(node);
1075
1244
  }
1076
1245
  // Request the real content from the phone via placeholder resend PDO.
@@ -1094,20 +1263,19 @@ export const makeMessagesRecvSocket = (config) => {
1094
1263
  };
1095
1264
  requestPlaceholderResend(cleanKey, msgData)
1096
1265
  .then(requestId => {
1097
- if (requestId && requestId !== 'RESOLVED') {
1098
- logger.debug({ msgId: msg.key.id, requestId }, 'requested placeholder resend for unavailable message');
1099
- ev.emit('messages.update', [
1100
- {
1101
- key: msg.key,
1102
- update: { messageStubParameters: [NO_MESSAGE_FOUND_ERROR_TEXT, requestId] }
1103
- }
1104
- ]);
1105
- }
1106
- })
1266
+ if (requestId && requestId !== 'RESOLVED') {
1267
+ logger.debug({ msgId: msg.key.id, requestId }, 'requested placeholder resend for unavailable message');
1268
+ ev.emit('messages.update', [
1269
+ {
1270
+ key: msg.key,
1271
+ update: { messageStubParameters: [NO_MESSAGE_FOUND_ERROR_TEXT, requestId] }
1272
+ }
1273
+ ]);
1274
+ }
1275
+ })
1107
1276
  .catch(err => {
1108
- logger.warn({ err, msgId: msg.key.id }, 'failed to request placeholder resend for unavailable message');
1109
- });
1110
- acked = true;
1277
+ logger.warn({ err, msgId: msg.key.id }, 'failed to request placeholder resend for unavailable message');
1278
+ });
1111
1279
  await sendMessageAck(node);
1112
1280
  // Don't return — fall through to upsertMessage so the stub is emitted
1113
1281
  }
@@ -1117,7 +1285,6 @@ export const makeMessagesRecvSocket = (config) => {
1117
1285
  const messageAge = unixTimestampSeconds() - toNumber(msg.messageTimestamp);
1118
1286
  if (messageAge > STATUS_EXPIRY_SECONDS) {
1119
1287
  logger.debug({ msgId: msg.key.id, messageAge, remoteJid: msg.key.remoteJid }, 'skipping retry for expired status message');
1120
- acked = true;
1121
1288
  return sendMessageAck(node);
1122
1289
  }
1123
1290
  }
@@ -1138,7 +1305,7 @@ export const makeMessagesRecvSocket = (config) => {
1138
1305
  logger.debug('Uploading pre-keys for error recovery');
1139
1306
  await uploadPreKeys(5);
1140
1307
  logger.debug('Waiting for server to process new pre-keys');
1141
- await delay(200);
1308
+ await delay(1000);
1142
1309
  }
1143
1310
  catch (uploadErr) {
1144
1311
  logger.error({ uploadErr }, 'Pre-key upload failed, proceeding with retry anyway');
@@ -1161,7 +1328,6 @@ export const makeMessagesRecvSocket = (config) => {
1161
1328
  logger.error({ retryErr }, 'Failed to send retry after error handling');
1162
1329
  }
1163
1330
  }
1164
- acked = true;
1165
1331
  await sendMessageAck(node, NACK_REASONS.UnhandledError);
1166
1332
  });
1167
1333
  }
@@ -1190,7 +1356,6 @@ export const makeMessagesRecvSocket = (config) => {
1190
1356
  else if (!sendActiveReceipts) {
1191
1357
  type = 'inactive';
1192
1358
  }
1193
- acked = true;
1194
1359
  await sendReceipt(msg.key.remoteJid, participant, [msg.key.id], type);
1195
1360
  // send ack for history message
1196
1361
  const isAnyHistoryMsg = getHistoryMsg(msg.message);
@@ -1200,66 +1365,147 @@ export const makeMessagesRecvSocket = (config) => {
1200
1365
  }
1201
1366
  }
1202
1367
  else {
1203
- acked = true;
1204
1368
  await sendMessageAck(node);
1205
1369
  logger.debug({ key: msg.key }, 'processed newsletter message without receipts');
1206
1370
  }
1207
1371
  }
1208
1372
  cleanMessage(msg, authState.creds.me.id, authState.creds.me.lid);
1373
+ await resolveMentionedLIDs(msg, signalRepository.lidMapping);
1374
+ // ── Post-resolve: fix semua LID yang tersisa di message object ────────
1375
+ // Setelah resolveMentionedLIDs:
1376
+ // 1. Fix text yang masih "@LIDnum" → "@PNnum"
1377
+ // 2. Fix contextInfo.participant yang masih @lid (sender quoted)
1378
+ // 3. Fix mentionedJid & text di dalam quotedMessage
1379
+ try {
1380
+ const _safeSet = (obj, key, val) => {
1381
+ try { obj[key] = val; } catch (_) {
1382
+ // proto readonly fallback
1383
+ const proto = Object.getPrototypeOf(obj);
1384
+ const fresh = Object.assign(Object.create(proto), obj, { [key]: val });
1385
+ // replace reference di parent jika bisa — caller handles
1386
+ return fresh;
1387
+ }
1388
+ return obj;
1389
+ };
1390
+ const _fixTextLid = (innerMsg, mentionedJids, msgTypeLabel) => {
1391
+ const pnNumbers = (mentionedJids || [])
1392
+ .filter(j => j && !j.endsWith('@lid'))
1393
+ .map(j => j.split('@')[0].split(':')[0])
1394
+ .filter(Boolean);
1395
+ if (!pnNumbers.length) return;
1396
+ for (const textKey of ['text', 'caption', 'conversation']) {
1397
+ const originalText = innerMsg[textKey];
1398
+ if (typeof originalText !== 'string') continue;
1399
+ const lidPattern = /@(\d{13,20})/g;
1400
+ let newText = originalText;
1401
+ let match;
1402
+ let pnIdx = 0;
1403
+ while ((match = lidPattern.exec(originalText)) !== null) {
1404
+ if (pnIdx >= pnNumbers.length) break;
1405
+ const lidNum = match[1];
1406
+ const pnNum = pnNumbers[pnIdx++];
1407
+ newText = newText.split(`@${lidNum}`).join(`@${pnNum}`);
1408
+ logger.debug({ lidNum, pnNum, type: msgTypeLabel, textKey }, 'post-resolve: replaced LID num in text');
1409
+ }
1410
+ if (newText !== originalText) _safeSet(innerMsg, textKey, newText);
1411
+ }
1412
+ };
1413
+ const msgObj = msg.message;
1414
+ if (msgObj) {
1415
+ for (const msgType of Object.keys(msgObj)) {
1416
+ const innerMsg = msgObj[msgType];
1417
+ if (!innerMsg || typeof innerMsg !== 'object') continue;
1418
+ const ctxInfo = innerMsg.contextInfo;
1419
+ if (!ctxInfo) continue;
1420
+ // 1. Fix text LID → PN (pesan utama)
1421
+ if (ctxInfo.mentionedJid?.length) {
1422
+ _fixTextLid(innerMsg, ctxInfo.mentionedJid, msgType);
1423
+ }
1424
+ // 2. Fix contextInfo.participant (sender quoted) jika masih LID
1425
+ if (ctxInfo.participant?.endsWith('@lid')) {
1426
+ try {
1427
+ const pn = await signalRepository.lidMapping.getPNForLID(ctxInfo.participant);
1428
+ if (pn) {
1429
+ _safeSet(ctxInfo, 'participant', pn);
1430
+ logger.debug({ lid: ctxInfo.participant, pn }, 'post-resolve: fixed contextInfo.participant LID');
1431
+ }
1432
+ } catch (_) {}
1433
+ }
1434
+ // 3. Fix mentionedJid & text di dalam quotedMessage
1435
+ if (ctxInfo.quotedMessage) {
1436
+ for (const qType of Object.keys(ctxInfo.quotedMessage)) {
1437
+ const qInner = ctxInfo.quotedMessage[qType];
1438
+ if (!qInner || typeof qInner !== 'object') continue;
1439
+ const qCtx = qInner.contextInfo;
1440
+ if (!qCtx?.mentionedJid?.length) continue;
1441
+ // Resolve LID di mentionedJid quoted
1442
+ const resolvedQ = await Promise.all(
1443
+ qCtx.mentionedJid.map(async (jid) => {
1444
+ if (!jid?.endsWith('@lid')) return jid;
1445
+ try {
1446
+ const pn = await signalRepository.lidMapping.getPNForLID(jid);
1447
+ return pn || jid;
1448
+ } catch (_) { return jid; }
1449
+ })
1450
+ );
1451
+ if (resolvedQ.some((j, i) => j !== qCtx.mentionedJid[i])) {
1452
+ _safeSet(qCtx, 'mentionedJid', resolvedQ);
1453
+ logger.debug({ resolvedQ }, 'post-resolve: fixed quotedMessage mentionedJid');
1454
+ }
1455
+ // Fix text LID → PN di quoted
1456
+ _fixTextLid(qInner, resolvedQ, `quoted.${qType}`);
1457
+ }
1458
+ }
1459
+ }
1460
+ }
1461
+ } catch (lidFixErr) {
1462
+ logger.debug({ err: lidFixErr }, 'post-resolve LID fix failed (non-critical)');
1463
+ }
1464
+ // ── End post-resolve fix ──────────────────────────────────────────────
1209
1465
  await upsertMessage(msg, node.attrs.offline ? 'append' : 'notify');
1210
1466
  });
1211
1467
  }
1212
1468
  catch (error) {
1213
1469
  logger.error({ error, node: binaryNodeToString(node) }, 'error in handling message');
1214
- if (!acked) {
1215
- await sendMessageAck(node, NACK_REASONS.UnhandledError).catch(ackErr => logger.error({ ackErr }, 'failed to ack message after error'));
1216
- }
1217
1470
  }
1218
1471
  };
1219
1472
  const handleCall = async (node) => {
1220
- try {
1221
- const { attrs } = node;
1222
- const [infoChild] = getAllBinaryNodeChildren(node);
1223
- if (!infoChild) {
1224
- throw new Boom('Missing call info in call node');
1225
- }
1226
- const status = getCallStatusFromNode(infoChild);
1227
- const callId = infoChild.attrs['call-id'];
1228
- const from = infoChild.attrs.from || infoChild.attrs['call-creator'];
1229
- const call = {
1230
- chatId: attrs.from,
1231
- from,
1232
- callerPn: infoChild.attrs['caller_pn'],
1233
- id: callId,
1234
- date: new Date(+attrs.t * 1000),
1235
- offline: !!attrs.offline,
1236
- status
1237
- };
1238
- if (status === 'offer') {
1239
- call.isVideo = !!getBinaryNodeChild(infoChild, 'video');
1240
- call.isGroup = infoChild.attrs.type === 'group' || !!infoChild.attrs['group-jid'];
1241
- call.groupJid = infoChild.attrs['group-jid'];
1242
- await callOfferCache.set(call.id, call);
1243
- }
1244
- const existingCall = await callOfferCache.get(call.id);
1245
- // use existing call info to populate this event
1246
- if (existingCall) {
1247
- call.isVideo = existingCall.isVideo;
1248
- call.isGroup = existingCall.isGroup;
1249
- call.callerPn = call.callerPn || existingCall.callerPn;
1250
- }
1251
- // delete data once call has ended
1252
- if (status === 'reject' || status === 'accept' || status === 'timeout' || status === 'terminate') {
1253
- await callOfferCache.del(call.id);
1254
- }
1255
- ev.emit('call', [call]);
1473
+ const { attrs } = node;
1474
+ const [infoChild] = getAllBinaryNodeChildren(node);
1475
+ const status = getCallStatusFromNode(infoChild);
1476
+ if (!infoChild) {
1477
+ throw new Boom('Missing call info in call node');
1256
1478
  }
1257
- catch (error) {
1258
- logger.error({ error, node: binaryNodeToString(node) }, 'error in handling call');
1479
+ const callId = infoChild.attrs['call-id'];
1480
+ const from = infoChild.attrs.from || infoChild.attrs['call-creator'];
1481
+ const call = {
1482
+ chatId: attrs.from,
1483
+ from,
1484
+ callerPn: infoChild.attrs['caller_pn'],
1485
+ id: callId,
1486
+ date: new Date(+attrs.t * 1000),
1487
+ offline: !!attrs.offline,
1488
+ status
1489
+ };
1490
+ if (status === 'offer') {
1491
+ call.isVideo = !!getBinaryNodeChild(infoChild, 'video');
1492
+ call.isGroup = infoChild.attrs.type === 'group' || !!infoChild.attrs['group-jid'];
1493
+ call.groupJid = infoChild.attrs['group-jid'];
1494
+ await callOfferCache.set(call.id, call);
1259
1495
  }
1260
- finally {
1261
- await sendMessageAck(node).catch(ackErr => logger.error({ ackErr }, 'failed to ack call'));
1496
+ const existingCall = await callOfferCache.get(call.id);
1497
+ // use existing call info to populate this event
1498
+ if (existingCall) {
1499
+ call.isVideo = existingCall.isVideo;
1500
+ call.isGroup = existingCall.isGroup;
1501
+ call.callerPn = call.callerPn || existingCall.callerPn;
1262
1502
  }
1503
+ // delete data once call has ended
1504
+ if (status === 'reject' || status === 'accept' || status === 'timeout' || status === 'terminate') {
1505
+ await callOfferCache.del(call.id);
1506
+ }
1507
+ ev.emit('call', [call]);
1508
+ await sendMessageAck(node);
1263
1509
  };
1264
1510
  const handleBadAck = async ({ attrs }) => {
1265
1511
  const key = { remoteJid: attrs.from, fromMe: true, id: attrs.id };
@@ -1308,26 +1554,58 @@ export const makeMessagesRecvSocket = (config) => {
1308
1554
  /// and adds the task to the existing buffer if we're buffering events
1309
1555
  const processNodeWithBuffer = async (node, identifier, exec) => {
1310
1556
  ev.buffer();
1311
- try {
1312
- await execTask();
1313
- }
1314
- finally {
1315
- ev.flush();
1316
- }
1557
+ await execTask();
1558
+ ev.flush();
1317
1559
  function execTask() {
1318
1560
  return exec(node, false).catch(err => onUnexpectedError(err, identifier));
1319
1561
  }
1320
1562
  };
1321
- const offlineNodeProcessor = makeOfflineNodeProcessor(new Map([
1322
- ['message', handleMessage],
1323
- ['call', handleCall],
1324
- ['receipt', handleReceipt],
1325
- ['notification', handleNotification]
1326
- ]), {
1327
- isWsOpen: () => ws.isOpen,
1328
- onUnexpectedError,
1329
- yieldToEventLoop: () => new Promise(resolve => setImmediate(resolve))
1330
- });
1563
+ /** Yields control to the event loop to prevent blocking */
1564
+ const yieldToEventLoop = () => {
1565
+ return new Promise(resolve => setImmediate(resolve));
1566
+ };
1567
+ const makeOfflineNodeProcessor = () => {
1568
+ const nodeProcessorMap = new Map([
1569
+ ['message', handleMessage],
1570
+ ['call', handleCall],
1571
+ ['receipt', handleReceipt],
1572
+ ['notification', handleNotification]
1573
+ ]);
1574
+ const nodes = [];
1575
+ let isProcessing = false;
1576
+ // Number of nodes to process before yielding to event loop
1577
+ const BATCH_SIZE = 10;
1578
+ const enqueue = (type, node) => {
1579
+ nodes.push({ type, node });
1580
+ if (isProcessing) {
1581
+ return;
1582
+ }
1583
+ isProcessing = true;
1584
+ const promise = async () => {
1585
+ let processedInBatch = 0;
1586
+ while (nodes.length && ws.isOpen) {
1587
+ const { type, node } = nodes.shift();
1588
+ const nodeProcessor = nodeProcessorMap.get(type);
1589
+ if (!nodeProcessor) {
1590
+ onUnexpectedError(new Error(`unknown offline node type: ${type}`), 'processing offline node');
1591
+ continue;
1592
+ }
1593
+ await nodeProcessor(node);
1594
+ processedInBatch++;
1595
+ // Yield to event loop after processing a batch
1596
+ // This prevents blocking the event loop for too long when there are many offline nodes
1597
+ if (processedInBatch >= BATCH_SIZE) {
1598
+ processedInBatch = 0;
1599
+ await yieldToEventLoop();
1600
+ }
1601
+ }
1602
+ isProcessing = false;
1603
+ };
1604
+ promise().catch(error => onUnexpectedError(error, 'processing offline nodes'));
1605
+ };
1606
+ return { enqueue };
1607
+ };
1608
+ const offlineNodeProcessor = makeOfflineNodeProcessor();
1331
1609
  const processNode = async (type, node, identifier, exec) => {
1332
1610
  const isOffline = !!node.attrs.offline;
1333
1611
  if (isOffline) {
@@ -1395,10 +1673,9 @@ export const makeMessagesRecvSocket = (config) => {
1395
1673
  sendMessageAck,
1396
1674
  sendRetryRequest,
1397
1675
  rejectCall,
1398
- initiateCall,
1399
- cancelCall,
1400
1676
  fetchMessageHistory,
1401
1677
  requestPlaceholderResend,
1402
1678
  messageRetryManager
1403
1679
  };
1404
- };
1680
+ };
1681
+ //# sourceMappingURL=messages-recv.js.map