violetics 7.0.7-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 (411) 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 +2670 -9199
  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 +14 -22
  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 +2 -1
  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 +154 -69
  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 +471 -253
  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 +620 -226
  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 +109 -62
  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 +12 -3
  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 +2 -1
  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 -6
  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 +7 -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 +2 -1
  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 +185 -185
  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 +932 -1120
  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 -1
  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 +55 -77
  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 +14 -113
  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 +5 -2
  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 -53
  406. package/.github/workflows/publish.yml +0 -75
  407. package/.pnp.cjs +0 -8572
  408. package/.pnp.loader.mjs +0 -2126
  409. package/.yarn/install-state.gz +0 -0
  410. package/lib/Utils/offline-node-processor.js +0 -39
  411. package/lib/Utils/stanza-ack.js +0 -37
@@ -7,18 +7,16 @@ 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
- const devicesMutex = makeMutex();
22
20
  const msgRetryCache = config.msgRetryCounterCache ||
23
21
  new NodeCache({
24
22
  stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
@@ -34,11 +32,6 @@ export const makeMessagesRecvSocket = (config) => {
34
32
  stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
35
33
  useClones: false
36
34
  });
37
- const userDevicesCache = config.userDevicesCache ??=
38
- new NodeCache({
39
- stdTTL: DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
40
- useClones: false
41
- });
42
35
  // Debounce identity-change session refreshes per JID to avoid bursts
43
36
  const identityAssertDebounce = new NodeCache({ stdTTL: 5, useClones: false });
44
37
  let sendActiveReceipts = false;
@@ -212,7 +205,7 @@ export const makeMessagesRecvSocket = (config) => {
212
205
  message: messageProto,
213
206
  messageTimestamp: +child.attrs.t
214
207
  }).toJSON();
215
- await upsertMessage(fullMessage, 'append');
208
+ await upsertMessage(fullMessage, 'notify');
216
209
  logger.info('Processed plaintext newsletter message');
217
210
  }
218
211
  catch (error) {
@@ -225,9 +218,32 @@ export const makeMessagesRecvSocket = (config) => {
225
218
  break;
226
219
  }
227
220
  };
228
- const sendMessageAck = async (node, errorCode) => {
229
- const stanza = buildAckStanza(node, errorCode, authState.creds.me.id);
230
- 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');
231
247
  await sendNode(stanza);
232
248
  };
233
249
  const rejectCall = async (callId, callFrom) => {
@@ -251,97 +267,6 @@ export const makeMessagesRecvSocket = (config) => {
251
267
  };
252
268
  await query(stanza);
253
269
  };
254
- // Lia@Note 01-03-26 --- Source: https://github.com/koptereli/Baileys/commit/575cd41e6f01a9b3e1d7e2708c2292fa93de91f2
255
- const initiateCall = async (jid, options = {}) => {
256
- const meId = authState.creds.me?.id;
257
- if (!meId) {
258
- throw new Boom('Not authenticated');
259
- }
260
- const callId = randomBytes(8).toString('hex');
261
- const isVideo = !!options.isVideo;
262
- const isGroup = isJidGroup(jid);
263
- const stanza = {
264
- tag: 'call',
265
- attrs: {
266
- id: generateMessageTag(),
267
- from: meId,
268
- to: jid,
269
- t: String(unixTimestampSeconds()),
270
- ...(authState.creds.me?.name ? { notify: authState.creds.me.name } : {})
271
- },
272
- content: [
273
- {
274
- tag: 'offer',
275
- attrs: {
276
- 'call-id': callId,
277
- 'call-creator': meId,
278
- count: '0'
279
- },
280
- content: [
281
- {
282
- tag: isVideo ? 'video' : 'audio',
283
- attrs: {}
284
- },
285
- {
286
- tag: 'net',
287
- attrs: {}
288
- },
289
- {
290
- tag: 'encopt',
291
- attrs: { key: randomBytes(2).toString('hex') }
292
- },
293
- {
294
- tag: 'relaylatency',
295
- attrs: {}
296
- },
297
- {
298
- tag: 'te',
299
- attrs: {}
300
- }
301
- ]
302
- }
303
- ]
304
- };
305
- await query(stanza);
306
- await callOfferCache.set(callId, {
307
- chatId: jid,
308
- from: meId,
309
- id: callId,
310
- date: new Date(),
311
- offline: false,
312
- status: 'offer',
313
- isVideo,
314
- isGroup,
315
- groupJid: isGroup ? jid : undefined
316
- });
317
- // TODO: implement ICE/DTLS-SRTP call media setup once full signaling requirements are mapped.
318
- return { callId, to: jid, isVideo };
319
- };
320
- const cancelCall = async (callId, callTo) => {
321
- const meId = authState.creds.me?.id;
322
- if (!meId) {
323
- throw new Boom('Not authenticated');
324
- }
325
- const stanza = {
326
- tag: 'call',
327
- attrs: {
328
- from: meId,
329
- to: callTo
330
- },
331
- content: [
332
- {
333
- tag: 'terminate',
334
- attrs: {
335
- 'call-id': callId,
336
- 'call-creator': meId,
337
- count: '0'
338
- }
339
- }
340
- ]
341
- };
342
- await query(stanza);
343
- await callOfferCache.del(callId);
344
- };
345
270
  const sendRetryRequest = async (node, forceIncludeKeys = false) => {
346
271
  const { fullMessage } = decodeMessageNode(node, authState.creds.me.id, authState.creds.me.lid || '');
347
272
  const { key: msgKey } = fullMessage;
@@ -621,64 +546,6 @@ export const makeMessagesRecvSocket = (config) => {
621
546
  break;
622
547
  }
623
548
  };
624
- const handleDevicesNotification = async (node) => {
625
- const [child] = getAllBinaryNodeChildren(node);
626
- const from = jidNormalizedUser(node.attrs.from);
627
- const devices = getBinaryNodeChildren(child, 'device');
628
- if (areJidsSameUser(from, authState.creds.me.id) ||
629
- areJidsSameUser(from, authState.creds.me.lid)) {
630
- const deviceJids = devices.map(d => d.attrs.jid);
631
- logger.info({ deviceJids }, 'got my own devices');
632
- }
633
- if (!devices || !devices.length || !devices[0]) {
634
- logger.debug({ from }, 'no devices in notification, skipping');
635
- return;
636
- }
637
- const deviceJid = devices[0].attrs.jid;
638
- const decoded = jidDecode(deviceJid);
639
- if (!decoded) return;
640
- const { user, device } = decoded;
641
- const tag = child.tag;
642
- if (!deviceJid) {
643
- logger.debug({ tag }, 'no device jid in notification, skipping');
644
- return;
645
- }
646
- await devicesMutex.mutex(async () => {
647
- if (tag === 'update') {
648
- logger.debug({ user }, `${user}'s device list updated, dropping cached devices`);
649
- if (userDevicesCache) {
650
- await userDevicesCache.del(user);
651
- }
652
- return;
653
- }
654
- const existingCache = (await (userDevicesCache?.get(user))) || [];
655
- if (!existingCache.length) {
656
- logger.debug({ user, tag }, 'device list not cached, skipping cache update')
657
- return;
658
- }
659
- const deviceHash = child.attrs.device_hash;
660
- let updatedDevices = [];
661
- switch (tag) {
662
- case 'add':
663
- logger.info({ deviceHash }, 'device added');
664
- updatedDevices = [
665
- ...existingCache.filter(d => d.device !== device),
666
- { user, device }
667
- ];
668
- break;
669
- case 'remove':
670
- logger.info({ deviceHash }, 'device removed');
671
- updatedDevices = existingCache.filter(d => d.device !== device);
672
- break;
673
- default:
674
- logger.debug({ tag }, 'Unknown device list change tag');
675
- return;
676
- }
677
- if (updatedDevices.length > 0 && userDevicesCache) {
678
- await userDevicesCache.set(user, updatedDevices);
679
- }
680
- });
681
- };
682
549
  const processNotification = async (node) => {
683
550
  const result = {};
684
551
  const [child] = getAllBinaryNodeChildren(node);
@@ -703,12 +570,13 @@ export const makeMessagesRecvSocket = (config) => {
703
570
  await handleEncryptNotification(node);
704
571
  break;
705
572
  case 'devices':
706
- try {
707
- await handleDevicesNotification(node);
708
- }
709
- catch (error) {
710
- logger.error({ error, node }, 'failed to handle devices notification');
573
+ const devices = getBinaryNodeChildren(child, 'device');
574
+ if (areJidsSameUser(child.attrs.jid, authState.creds.me.id) ||
575
+ areJidsSameUser(child.attrs.lid, authState.creds.me.lid)) {
576
+ const deviceData = devices.map(d => ({ id: d.attrs.jid, lid: d.attrs.lid }));
577
+ logger.info({ deviceData }, 'my own devices changed');
711
578
  }
579
+ //TODO: drop a new event, add hashes
712
580
  break;
713
581
  case 'server_sync':
714
582
  const update = getBinaryNodeChild(node, 'collection');
@@ -1037,7 +905,7 @@ export const makeMessagesRecvSocket = (config) => {
1037
905
  ]);
1038
906
  }
1039
907
  finally {
1040
- await sendMessageAck(node).catch(ackErr => logger.error({ ackErr }, 'failed to ack receipt'));
908
+ await sendMessageAck(node);
1041
909
  }
1042
910
  };
1043
911
  const handleNotification = async (node) => {
@@ -1072,7 +940,245 @@ export const makeMessagesRecvSocket = (config) => {
1072
940
  ]);
1073
941
  }
1074
942
  finally {
1075
- 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;
1076
1182
  }
1077
1183
  };
1078
1184
  const handleMessage = async (node) => {
@@ -1088,34 +1194,36 @@ export const makeMessagesRecvSocket = (config) => {
1088
1194
  await sendMessageAck(node, NACK_REASONS.MissingMessageSecret);
1089
1195
  return;
1090
1196
  }
1091
- let acked = false;
1092
- try {
1093
- const { fullMessage: msg, category, author, decrypt } = decryptMessageNode(node, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, logger);
1094
- const alt = msg.key.participantAlt || msg.key.remoteJidAlt;
1095
- // store new mappings we didn't have before
1096
- if (!!alt) {
1097
- const altServer = jidDecode(alt)?.server;
1098
- const primaryJid = msg.key.participant || msg.key.remoteJid;
1099
- if (altServer === 'lid') {
1100
- if (!(await signalRepository.lidMapping.getPNForLID(alt))) {
1101
- await signalRepository.lidMapping.storeLIDPNMappings([{ lid: alt, pn: primaryJid }]);
1102
- await signalRepository.migrateSession(primaryJid, alt);
1103
- }
1104
- }
1105
- else {
1106
- await signalRepository.lidMapping.storeLIDPNMappings([{ lid: primaryJid, pn: alt }]);
1107
- 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);
1108
1207
  }
1109
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 {
1110
1222
  await messageMutex.mutex(async () => {
1111
1223
  await decrypt();
1112
- if (msg.key?.remoteJid && msg.key?.id && msg.message && messageRetryManager) {
1113
- messageRetryManager.addRecentMessage(msg.key.remoteJid, msg.key.id, msg.message);
1114
- }
1115
1224
  // message failed to decrypt
1116
1225
  if (msg.messageStubType === proto.WebMessageInfo.StubType.CIPHERTEXT && msg.category !== 'peer') {
1117
1226
  if (msg?.messageStubParameters?.[0] === MISSING_KEYS_ERROR_TEXT) {
1118
- acked = true;
1119
1227
  return sendMessageAck(node, NACK_REASONS.ParsingError);
1120
1228
  }
1121
1229
  if (msg.messageStubParameters?.[0] === NO_MESSAGE_FOUND_ERROR_TEXT) {
@@ -1127,13 +1235,11 @@ export const makeMessagesRecvSocket = (config) => {
1127
1235
  unavailableType === 'hosted_unavailable_fanout' ||
1128
1236
  unavailableType === 'view_once_unavailable_fanout') {
1129
1237
  logger.debug({ msgId: msg.key.id, unavailableType }, 'skipping placeholder resend for excluded unavailable type');
1130
- acked = true;
1131
1238
  return sendMessageAck(node);
1132
1239
  }
1133
1240
  const messageAge = unixTimestampSeconds() - toNumber(msg.messageTimestamp);
1134
1241
  if (messageAge > PLACEHOLDER_MAX_AGE_SECONDS) {
1135
1242
  logger.debug({ msgId: msg.key.id, messageAge }, 'skipping placeholder resend for old message');
1136
- acked = true;
1137
1243
  return sendMessageAck(node);
1138
1244
  }
1139
1245
  // Request the real content from the phone via placeholder resend PDO.
@@ -1170,7 +1276,6 @@ export const makeMessagesRecvSocket = (config) => {
1170
1276
  .catch(err => {
1171
1277
  logger.warn({ err, msgId: msg.key.id }, 'failed to request placeholder resend for unavailable message');
1172
1278
  });
1173
- acked = true;
1174
1279
  await sendMessageAck(node);
1175
1280
  // Don't return — fall through to upsertMessage so the stub is emitted
1176
1281
  }
@@ -1180,7 +1285,6 @@ export const makeMessagesRecvSocket = (config) => {
1180
1285
  const messageAge = unixTimestampSeconds() - toNumber(msg.messageTimestamp);
1181
1286
  if (messageAge > STATUS_EXPIRY_SECONDS) {
1182
1287
  logger.debug({ msgId: msg.key.id, messageAge, remoteJid: msg.key.remoteJid }, 'skipping retry for expired status message');
1183
- acked = true;
1184
1288
  return sendMessageAck(node);
1185
1289
  }
1186
1290
  }
@@ -1224,7 +1328,6 @@ export const makeMessagesRecvSocket = (config) => {
1224
1328
  logger.error({ retryErr }, 'Failed to send retry after error handling');
1225
1329
  }
1226
1330
  }
1227
- acked = true;
1228
1331
  await sendMessageAck(node, NACK_REASONS.UnhandledError);
1229
1332
  });
1230
1333
  }
@@ -1253,7 +1356,6 @@ export const makeMessagesRecvSocket = (config) => {
1253
1356
  else if (!sendActiveReceipts) {
1254
1357
  type = 'inactive';
1255
1358
  }
1256
- acked = true;
1257
1359
  await sendReceipt(msg.key.remoteJid, participant, [msg.key.id], type);
1258
1360
  // send ack for history message
1259
1361
  const isAnyHistoryMsg = getHistoryMsg(msg.message);
@@ -1263,66 +1365,147 @@ export const makeMessagesRecvSocket = (config) => {
1263
1365
  }
1264
1366
  }
1265
1367
  else {
1266
- acked = true;
1267
1368
  await sendMessageAck(node);
1268
1369
  logger.debug({ key: msg.key }, 'processed newsletter message without receipts');
1269
1370
  }
1270
1371
  }
1271
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 ──────────────────────────────────────────────
1272
1465
  await upsertMessage(msg, node.attrs.offline ? 'append' : 'notify');
1273
1466
  });
1274
1467
  }
1275
1468
  catch (error) {
1276
1469
  logger.error({ error, node: binaryNodeToString(node) }, 'error in handling message');
1277
- if (!acked) {
1278
- await sendMessageAck(node, NACK_REASONS.UnhandledError).catch(ackErr => logger.error({ ackErr }, 'failed to ack message after error'));
1279
- }
1280
1470
  }
1281
1471
  };
1282
1472
  const handleCall = async (node) => {
1283
- try {
1284
- const { attrs } = node;
1285
- const [infoChild] = getAllBinaryNodeChildren(node);
1286
- if (!infoChild) {
1287
- throw new Boom('Missing call info in call node');
1288
- }
1289
- const status = getCallStatusFromNode(infoChild);
1290
- const callId = infoChild.attrs['call-id'];
1291
- const from = infoChild.attrs.from || infoChild.attrs['call-creator'];
1292
- const call = {
1293
- chatId: attrs.from,
1294
- from,
1295
- callerPn: infoChild.attrs['caller_pn'],
1296
- id: callId,
1297
- date: new Date(+attrs.t * 1000),
1298
- offline: !!attrs.offline,
1299
- status
1300
- };
1301
- if (status === 'offer') {
1302
- call.isVideo = !!getBinaryNodeChild(infoChild, 'video');
1303
- call.isGroup = infoChild.attrs.type === 'group' || !!infoChild.attrs['group-jid'];
1304
- call.groupJid = infoChild.attrs['group-jid'];
1305
- await callOfferCache.set(call.id, call);
1306
- }
1307
- const existingCall = await callOfferCache.get(call.id);
1308
- // use existing call info to populate this event
1309
- if (existingCall) {
1310
- call.isVideo = existingCall.isVideo;
1311
- call.isGroup = existingCall.isGroup;
1312
- call.callerPn = call.callerPn || existingCall.callerPn;
1313
- }
1314
- // delete data once call has ended
1315
- if (status === 'reject' || status === 'accept' || status === 'timeout' || status === 'terminate') {
1316
- await callOfferCache.del(call.id);
1317
- }
1318
- 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');
1319
1478
  }
1320
- catch (error) {
1321
- 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);
1322
1495
  }
1323
- finally {
1324
- 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;
1325
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);
1326
1509
  };
1327
1510
  const handleBadAck = async ({ attrs }) => {
1328
1511
  const key = { remoteJid: attrs.from, fromMe: true, id: attrs.id };
@@ -1377,16 +1560,52 @@ export const makeMessagesRecvSocket = (config) => {
1377
1560
  return exec(node, false).catch(err => onUnexpectedError(err, identifier));
1378
1561
  }
1379
1562
  };
1380
- const offlineNodeProcessor = makeOfflineNodeProcessor(new Map([
1381
- ['message', handleMessage],
1382
- ['call', handleCall],
1383
- ['receipt', handleReceipt],
1384
- ['notification', handleNotification]
1385
- ]), {
1386
- isWsOpen: () => ws.isOpen,
1387
- onUnexpectedError,
1388
- yieldToEventLoop: () => new Promise(resolve => setImmediate(resolve))
1389
- });
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();
1390
1609
  const processNode = async (type, node, identifier, exec) => {
1391
1610
  const isOffline = !!node.attrs.offline;
1392
1611
  if (isOffline) {
@@ -1454,10 +1673,9 @@ export const makeMessagesRecvSocket = (config) => {
1454
1673
  sendMessageAck,
1455
1674
  sendRetryRequest,
1456
1675
  rejectCall,
1457
- initiateCall,
1458
- cancelCall,
1459
1676
  fetchMessageHistory,
1460
1677
  requestPlaceholderResend,
1461
1678
  messageRetryManager
1462
1679
  };
1463
- };
1680
+ };
1681
+ //# sourceMappingURL=messages-recv.js.map