@lynovratech/baileys 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (787) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1312 -0
  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 +97687 -0
  8. package/engine-requirements.js +10 -0
  9. package/lib/cjs/Defaults/index.d.ts +74 -0
  10. package/lib/cjs/Defaults/index.d.ts.map +1 -0
  11. package/lib/cjs/Defaults/index.js +134 -0
  12. package/lib/cjs/Defaults/index.js.map +1 -0
  13. package/lib/cjs/Signal/Group/ciphertext-message.d.ts +10 -0
  14. package/lib/cjs/Signal/Group/ciphertext-message.d.ts.map +1 -0
  15. package/lib/cjs/Signal/Group/ciphertext-message.js +16 -0
  16. package/lib/cjs/Signal/Group/ciphertext-message.js.map +1 -0
  17. package/lib/cjs/Signal/Group/group-session-builder.d.ts +15 -0
  18. package/lib/cjs/Signal/Group/group-session-builder.d.ts.map +1 -0
  19. package/lib/cjs/Signal/Group/group-session-builder.js +65 -0
  20. package/lib/cjs/Signal/Group/group-session-builder.js.map +1 -0
  21. package/lib/cjs/Signal/Group/group_cipher.d.ts +17 -0
  22. package/lib/cjs/Signal/Group/group_cipher.d.ts.map +1 -0
  23. package/lib/cjs/Signal/Group/group_cipher.js +83 -0
  24. package/lib/cjs/Signal/Group/group_cipher.js.map +1 -0
  25. package/lib/cjs/Signal/Group/index.d.ts +12 -0
  26. package/lib/cjs/Signal/Group/index.d.ts.map +1 -0
  27. package/lib/cjs/Signal/Group/index.js +58 -0
  28. package/lib/cjs/Signal/Group/index.js.map +1 -0
  29. package/lib/cjs/Signal/Group/keyhelper.d.ts +11 -0
  30. package/lib/cjs/Signal/Group/keyhelper.d.ts.map +1 -0
  31. package/lib/cjs/Signal/Group/keyhelper.js +56 -0
  32. package/lib/cjs/Signal/Group/keyhelper.js.map +1 -0
  33. package/lib/cjs/Signal/Group/sender-chain-key.d.ts +14 -0
  34. package/lib/cjs/Signal/Group/sender-chain-key.d.ts.map +1 -0
  35. package/lib/cjs/Signal/Group/sender-chain-key.js +30 -0
  36. package/lib/cjs/Signal/Group/sender-chain-key.js.map +1 -0
  37. package/lib/cjs/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  38. package/lib/cjs/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
  39. package/lib/cjs/Signal/Group/sender-key-distribution-message.js +67 -0
  40. package/lib/cjs/Signal/Group/sender-key-distribution-message.js.map +1 -0
  41. package/lib/cjs/Signal/Group/sender-key-message.d.ts +19 -0
  42. package/lib/cjs/Signal/Group/sender-key-message.d.ts.map +1 -0
  43. package/lib/cjs/Signal/Group/sender-key-message.js +70 -0
  44. package/lib/cjs/Signal/Group/sender-key-message.js.map +1 -0
  45. package/lib/cjs/Signal/Group/sender-key-name.d.ts +18 -0
  46. package/lib/cjs/Signal/Group/sender-key-name.d.ts.map +1 -0
  47. package/lib/cjs/Signal/Group/sender-key-name.js +52 -0
  48. package/lib/cjs/Signal/Group/sender-key-name.js.map +1 -0
  49. package/lib/cjs/Signal/Group/sender-key-record.d.ts +31 -0
  50. package/lib/cjs/Signal/Group/sender-key-record.d.ts.map +1 -0
  51. package/lib/cjs/Signal/Group/sender-key-record.js +45 -0
  52. package/lib/cjs/Signal/Group/sender-key-record.js.map +1 -0
  53. package/lib/cjs/Signal/Group/sender-key-state.d.ts +39 -0
  54. package/lib/cjs/Signal/Group/sender-key-state.d.ts.map +1 -0
  55. package/lib/cjs/Signal/Group/sender-key-state.js +88 -0
  56. package/lib/cjs/Signal/Group/sender-key-state.js.map +1 -0
  57. package/lib/cjs/Signal/Group/sender-message-key.d.ts +12 -0
  58. package/lib/cjs/Signal/Group/sender-message-key.d.ts.map +1 -0
  59. package/lib/cjs/Signal/Group/sender-message-key.js +30 -0
  60. package/lib/cjs/Signal/Group/sender-message-key.js.map +1 -0
  61. package/lib/cjs/Signal/jid-mapping.d.ts +50 -0
  62. package/lib/cjs/Signal/jid-mapping.d.ts.map +1 -0
  63. package/lib/cjs/Signal/jid-mapping.js +218 -0
  64. package/lib/cjs/Signal/jid-mapping.js.map +1 -0
  65. package/lib/cjs/Signal/libsignal.d.ts +7 -0
  66. package/lib/cjs/Signal/libsignal.d.ts.map +1 -0
  67. package/lib/cjs/Signal/libsignal.js +447 -0
  68. package/lib/cjs/Signal/libsignal.js.map +1 -0
  69. package/lib/cjs/Signal/lid-mapping.d.ts +6 -0
  70. package/lib/cjs/Signal/lid-mapping.d.ts.map +1 -0
  71. package/lib/cjs/Signal/lid-mapping.js +10 -0
  72. package/lib/cjs/Signal/lid-mapping.js.map +1 -0
  73. package/lib/cjs/Socket/Client/index.d.ts +3 -0
  74. package/lib/cjs/Socket/Client/index.d.ts.map +1 -0
  75. package/lib/cjs/Socket/Client/index.js +19 -0
  76. package/lib/cjs/Socket/Client/index.js.map +1 -0
  77. package/lib/cjs/Socket/Client/types.d.ts +16 -0
  78. package/lib/cjs/Socket/Client/types.d.ts.map +1 -0
  79. package/lib/cjs/Socket/Client/types.js +14 -0
  80. package/lib/cjs/Socket/Client/types.js.map +1 -0
  81. package/lib/cjs/Socket/Client/websocket.d.ts +13 -0
  82. package/lib/cjs/Socket/Client/websocket.d.ts.map +1 -0
  83. package/lib/cjs/Socket/Client/websocket.js +61 -0
  84. package/lib/cjs/Socket/Client/websocket.js.map +1 -0
  85. package/lib/cjs/Socket/business.d.ts +202 -0
  86. package/lib/cjs/Socket/business.d.ts.map +1 -0
  87. package/lib/cjs/Socket/business.js +383 -0
  88. package/lib/cjs/Socket/business.js.map +1 -0
  89. package/lib/cjs/Socket/chats.d.ts +111 -0
  90. package/lib/cjs/Socket/chats.d.ts.map +1 -0
  91. package/lib/cjs/Socket/chats.js +1006 -0
  92. package/lib/cjs/Socket/chats.js.map +1 -0
  93. package/lib/cjs/Socket/communities.d.ts +258 -0
  94. package/lib/cjs/Socket/communities.d.ts.map +1 -0
  95. package/lib/cjs/Socket/communities.js +439 -0
  96. package/lib/cjs/Socket/communities.js.map +1 -0
  97. package/lib/cjs/Socket/groups.d.ts +150 -0
  98. package/lib/cjs/Socket/groups.d.ts.map +1 -0
  99. package/lib/cjs/Socket/groups.js +335 -0
  100. package/lib/cjs/Socket/groups.js.map +1 -0
  101. package/lib/cjs/Socket/index.d.ts +245 -0
  102. package/lib/cjs/Socket/index.d.ts.map +1 -0
  103. package/lib/cjs/Socket/index.js +14 -0
  104. package/lib/cjs/Socket/index.js.map +1 -0
  105. package/lib/cjs/Socket/messages-recv.d.ts +187 -0
  106. package/lib/cjs/Socket/messages-recv.d.ts.map +1 -0
  107. package/lib/cjs/Socket/messages-recv.js +1325 -0
  108. package/lib/cjs/Socket/messages-recv.js.map +1 -0
  109. package/lib/cjs/Socket/messages-send.d.ts +183 -0
  110. package/lib/cjs/Socket/messages-send.d.ts.map +1 -0
  111. package/lib/cjs/Socket/messages-send.js +1046 -0
  112. package/lib/cjs/Socket/messages-send.js.map +1 -0
  113. package/lib/cjs/Socket/mex.d.ts +3 -0
  114. package/lib/cjs/Socket/mex.d.ts.map +1 -0
  115. package/lib/cjs/Socket/mex.js +46 -0
  116. package/lib/cjs/Socket/mex.js.map +1 -0
  117. package/lib/cjs/Socket/newsletter.d.ts +160 -0
  118. package/lib/cjs/Socket/newsletter.d.ts.map +1 -0
  119. package/lib/cjs/Socket/newsletter.js +185 -0
  120. package/lib/cjs/Socket/newsletter.js.map +1 -0
  121. package/lib/cjs/Socket/socket.d.ts +55 -0
  122. package/lib/cjs/Socket/socket.d.ts.map +1 -0
  123. package/lib/cjs/Socket/socket.js +940 -0
  124. package/lib/cjs/Socket/socket.js.map +1 -0
  125. package/lib/cjs/Types/Auth.d.ts +126 -0
  126. package/lib/cjs/Types/Auth.d.ts.map +1 -0
  127. package/lib/cjs/Types/Auth.js +3 -0
  128. package/lib/cjs/Types/Auth.js.map +1 -0
  129. package/lib/cjs/Types/Bussines.d.ts +25 -0
  130. package/lib/cjs/Types/Bussines.d.ts.map +1 -0
  131. package/lib/cjs/Types/Bussines.js +3 -0
  132. package/lib/cjs/Types/Bussines.js.map +1 -0
  133. package/lib/cjs/Types/Call.d.ts +15 -0
  134. package/lib/cjs/Types/Call.d.ts.map +1 -0
  135. package/lib/cjs/Types/Call.js +3 -0
  136. package/lib/cjs/Types/Call.js.map +1 -0
  137. package/lib/cjs/Types/Chat.d.ts +123 -0
  138. package/lib/cjs/Types/Chat.d.ts.map +1 -0
  139. package/lib/cjs/Types/Chat.js +11 -0
  140. package/lib/cjs/Types/Chat.js.map +1 -0
  141. package/lib/cjs/Types/Contact.d.ts +24 -0
  142. package/lib/cjs/Types/Contact.d.ts.map +1 -0
  143. package/lib/cjs/Types/Contact.js +3 -0
  144. package/lib/cjs/Types/Contact.js.map +1 -0
  145. package/lib/cjs/Types/Events.d.ts +241 -0
  146. package/lib/cjs/Types/Events.d.ts.map +1 -0
  147. package/lib/cjs/Types/Events.js +3 -0
  148. package/lib/cjs/Types/Events.js.map +1 -0
  149. package/lib/cjs/Types/GroupMetadata.d.ts +67 -0
  150. package/lib/cjs/Types/GroupMetadata.d.ts.map +1 -0
  151. package/lib/cjs/Types/GroupMetadata.js +3 -0
  152. package/lib/cjs/Types/GroupMetadata.js.map +1 -0
  153. package/lib/cjs/Types/Label.d.ts +47 -0
  154. package/lib/cjs/Types/Label.d.ts.map +1 -0
  155. package/lib/cjs/Types/Label.js +28 -0
  156. package/lib/cjs/Types/Label.js.map +1 -0
  157. package/lib/cjs/Types/LabelAssociation.d.ts +30 -0
  158. package/lib/cjs/Types/LabelAssociation.d.ts.map +1 -0
  159. package/lib/cjs/Types/LabelAssociation.js +10 -0
  160. package/lib/cjs/Types/LabelAssociation.js.map +1 -0
  161. package/lib/cjs/Types/Message.d.ts +310 -0
  162. package/lib/cjs/Types/Message.d.ts.map +1 -0
  163. package/lib/cjs/Types/Message.js +16 -0
  164. package/lib/cjs/Types/Message.js.map +1 -0
  165. package/lib/cjs/Types/Newsletter.d.ts +135 -0
  166. package/lib/cjs/Types/Newsletter.d.ts.map +1 -0
  167. package/lib/cjs/Types/Newsletter.js +34 -0
  168. package/lib/cjs/Types/Newsletter.js.map +1 -0
  169. package/lib/cjs/Types/Product.d.ts +79 -0
  170. package/lib/cjs/Types/Product.d.ts.map +1 -0
  171. package/lib/cjs/Types/Product.js +3 -0
  172. package/lib/cjs/Types/Product.js.map +1 -0
  173. package/lib/cjs/Types/Signal.d.ts +76 -0
  174. package/lib/cjs/Types/Signal.d.ts.map +1 -0
  175. package/lib/cjs/Types/Signal.js +3 -0
  176. package/lib/cjs/Types/Signal.js.map +1 -0
  177. package/lib/cjs/Types/Socket.d.ts +135 -0
  178. package/lib/cjs/Types/Socket.d.ts.map +1 -0
  179. package/lib/cjs/Types/Socket.js +3 -0
  180. package/lib/cjs/Types/Socket.js.map +1 -0
  181. package/lib/cjs/Types/State.d.ts +39 -0
  182. package/lib/cjs/Types/State.d.ts.map +1 -0
  183. package/lib/cjs/Types/State.js +15 -0
  184. package/lib/cjs/Types/State.js.map +1 -0
  185. package/lib/cjs/Types/USync.d.ts +26 -0
  186. package/lib/cjs/Types/USync.d.ts.map +1 -0
  187. package/lib/cjs/Types/USync.js +3 -0
  188. package/lib/cjs/Types/USync.js.map +1 -0
  189. package/lib/cjs/Types/index.d.ts +65 -0
  190. package/lib/cjs/Types/index.d.ts.map +1 -0
  191. package/lib/cjs/Types/index.js +43 -0
  192. package/lib/cjs/Types/index.js.map +1 -0
  193. package/lib/cjs/Utils/auth-utils.d.ts +19 -0
  194. package/lib/cjs/Utils/auth-utils.d.ts.map +1 -0
  195. package/lib/cjs/Utils/auth-utils.js +299 -0
  196. package/lib/cjs/Utils/auth-utils.js.map +1 -0
  197. package/lib/cjs/Utils/browser-utils.d.ts +4 -0
  198. package/lib/cjs/Utils/browser-utils.d.ts.map +1 -0
  199. package/lib/cjs/Utils/browser-utils.js +32 -0
  200. package/lib/cjs/Utils/browser-utils.js.map +1 -0
  201. package/lib/cjs/Utils/business.d.ts +23 -0
  202. package/lib/cjs/Utils/business.d.ts.map +1 -0
  203. package/lib/cjs/Utils/business.js +241 -0
  204. package/lib/cjs/Utils/business.js.map +1 -0
  205. package/lib/cjs/Utils/chat-utils.d.ts +70 -0
  206. package/lib/cjs/Utils/chat-utils.d.ts.map +1 -0
  207. package/lib/cjs/Utils/chat-utils.js +826 -0
  208. package/lib/cjs/Utils/chat-utils.js.map +1 -0
  209. package/lib/cjs/Utils/crypto.d.ts +37 -0
  210. package/lib/cjs/Utils/crypto.d.ts.map +1 -0
  211. package/lib/cjs/Utils/crypto.js +169 -0
  212. package/lib/cjs/Utils/crypto.js.map +1 -0
  213. package/lib/cjs/Utils/decode-wa-message.d.ts +48 -0
  214. package/lib/cjs/Utils/decode-wa-message.d.ts.map +1 -0
  215. package/lib/cjs/Utils/decode-wa-message.js +291 -0
  216. package/lib/cjs/Utils/decode-wa-message.js.map +1 -0
  217. package/lib/cjs/Utils/event-buffer.d.ts +34 -0
  218. package/lib/cjs/Utils/event-buffer.d.ts.map +1 -0
  219. package/lib/cjs/Utils/event-buffer.js +581 -0
  220. package/lib/cjs/Utils/event-buffer.js.map +1 -0
  221. package/lib/cjs/Utils/generics.d.ts +91 -0
  222. package/lib/cjs/Utils/generics.d.ts.map +1 -0
  223. package/lib/cjs/Utils/generics.js +416 -0
  224. package/lib/cjs/Utils/generics.js.map +1 -0
  225. package/lib/cjs/Utils/history.d.ts +22 -0
  226. package/lib/cjs/Utils/history.d.ts.map +1 -0
  227. package/lib/cjs/Utils/history.js +138 -0
  228. package/lib/cjs/Utils/history.js.map +1 -0
  229. package/lib/cjs/Utils/identity-change-handler.d.ts +38 -0
  230. package/lib/cjs/Utils/identity-change-handler.d.ts.map +1 -0
  231. package/lib/cjs/Utils/identity-change-handler.js +52 -0
  232. package/lib/cjs/Utils/identity-change-handler.js.map +1 -0
  233. package/lib/cjs/Utils/index.d.ts +21 -0
  234. package/lib/cjs/Utils/index.d.ts.map +1 -0
  235. package/lib/cjs/Utils/index.js +37 -0
  236. package/lib/cjs/Utils/index.js.map +1 -0
  237. package/lib/cjs/Utils/link-preview.d.ts +21 -0
  238. package/lib/cjs/Utils/link-preview.d.ts.map +1 -0
  239. package/lib/cjs/Utils/link-preview.js +122 -0
  240. package/lib/cjs/Utils/link-preview.js.map +1 -0
  241. package/lib/cjs/Utils/logger.d.ts +13 -0
  242. package/lib/cjs/Utils/logger.d.ts.map +1 -0
  243. package/lib/cjs/Utils/logger.js +8 -0
  244. package/lib/cjs/Utils/logger.js.map +1 -0
  245. package/lib/cjs/Utils/lt-hash.d.ts +8 -0
  246. package/lib/cjs/Utils/lt-hash.d.ts.map +1 -0
  247. package/lib/cjs/Utils/lt-hash.js +11 -0
  248. package/lib/cjs/Utils/lt-hash.js.map +1 -0
  249. package/lib/cjs/Utils/make-mutex.d.ts +9 -0
  250. package/lib/cjs/Utils/make-mutex.d.ts.map +1 -0
  251. package/lib/cjs/Utils/make-mutex.js +38 -0
  252. package/lib/cjs/Utils/make-mutex.js.map +1 -0
  253. package/lib/cjs/Utils/message-retry-manager.d.ts +110 -0
  254. package/lib/cjs/Utils/message-retry-manager.d.ts.map +1 -0
  255. package/lib/cjs/Utils/message-retry-manager.js +229 -0
  256. package/lib/cjs/Utils/message-retry-manager.js.map +1 -0
  257. package/lib/cjs/Utils/messages-media.d.ts +130 -0
  258. package/lib/cjs/Utils/messages-media.d.ts.map +1 -0
  259. package/lib/cjs/Utils/messages-media.js +835 -0
  260. package/lib/cjs/Utils/messages-media.js.map +1 -0
  261. package/lib/cjs/Utils/messages.d.ts +91 -0
  262. package/lib/cjs/Utils/messages.d.ts.map +1 -0
  263. package/lib/cjs/Utils/messages.js +902 -0
  264. package/lib/cjs/Utils/messages.js.map +1 -0
  265. package/lib/cjs/Utils/noise-handler.d.ts +20 -0
  266. package/lib/cjs/Utils/noise-handler.d.ts.map +1 -0
  267. package/lib/cjs/Utils/noise-handler.js +205 -0
  268. package/lib/cjs/Utils/noise-handler.js.map +1 -0
  269. package/lib/cjs/Utils/offline-node-processor.d.ts +17 -0
  270. package/lib/cjs/Utils/offline-node-processor.d.ts.map +1 -0
  271. package/lib/cjs/Utils/offline-node-processor.js +43 -0
  272. package/lib/cjs/Utils/offline-node-processor.js.map +1 -0
  273. package/lib/cjs/Utils/pre-key-manager.d.ts +28 -0
  274. package/lib/cjs/Utils/pre-key-manager.d.ts.map +1 -0
  275. package/lib/cjs/Utils/pre-key-manager.js +113 -0
  276. package/lib/cjs/Utils/pre-key-manager.js.map +1 -0
  277. package/lib/cjs/Utils/process-message.d.ts +60 -0
  278. package/lib/cjs/Utils/process-message.d.ts.map +1 -0
  279. package/lib/cjs/Utils/process-message.js +539 -0
  280. package/lib/cjs/Utils/process-message.js.map +1 -0
  281. package/lib/cjs/Utils/reporting-utils.d.ts +11 -0
  282. package/lib/cjs/Utils/reporting-utils.d.ts.map +1 -0
  283. package/lib/cjs/Utils/reporting-utils.js +262 -0
  284. package/lib/cjs/Utils/reporting-utils.js.map +1 -0
  285. package/lib/cjs/Utils/signal.d.ts +34 -0
  286. package/lib/cjs/Utils/signal.d.ts.map +1 -0
  287. package/lib/cjs/Utils/signal.js +171 -0
  288. package/lib/cjs/Utils/signal.js.map +1 -0
  289. package/lib/cjs/Utils/stanza-ack.d.ts +11 -0
  290. package/lib/cjs/Utils/stanza-ack.d.ts.map +1 -0
  291. package/lib/cjs/Utils/stanza-ack.js +41 -0
  292. package/lib/cjs/Utils/stanza-ack.js.map +1 -0
  293. package/lib/cjs/Utils/sync-action-utils.d.ts +19 -0
  294. package/lib/cjs/Utils/sync-action-utils.d.ts.map +1 -0
  295. package/lib/cjs/Utils/sync-action-utils.js +52 -0
  296. package/lib/cjs/Utils/sync-action-utils.js.map +1 -0
  297. package/lib/cjs/Utils/tc-token-utils.d.ts +12 -0
  298. package/lib/cjs/Utils/tc-token-utils.d.ts.map +1 -0
  299. package/lib/cjs/Utils/tc-token-utils.js +21 -0
  300. package/lib/cjs/Utils/tc-token-utils.js.map +1 -0
  301. package/lib/cjs/Utils/use-multi-file-auth-state.d.ts +13 -0
  302. package/lib/cjs/Utils/use-multi-file-auth-state.d.ts.map +1 -0
  303. package/lib/cjs/Utils/use-multi-file-auth-state.js +125 -0
  304. package/lib/cjs/Utils/use-multi-file-auth-state.js.map +1 -0
  305. package/lib/cjs/Utils/validate-connection.d.ts +11 -0
  306. package/lib/cjs/Utils/validate-connection.d.ts.map +1 -0
  307. package/lib/cjs/Utils/validate-connection.js +209 -0
  308. package/lib/cjs/Utils/validate-connection.js.map +1 -0
  309. package/lib/cjs/WABinary/constants.d.ts +28 -0
  310. package/lib/cjs/WABinary/constants.d.ts.map +1 -0
  311. package/lib/cjs/WABinary/constants.js +1304 -0
  312. package/lib/cjs/WABinary/constants.js.map +1 -0
  313. package/lib/cjs/WABinary/decode.d.ts +7 -0
  314. package/lib/cjs/WABinary/decode.d.ts.map +1 -0
  315. package/lib/cjs/WABinary/decode.js +301 -0
  316. package/lib/cjs/WABinary/decode.js.map +1 -0
  317. package/lib/cjs/WABinary/encode.d.ts +3 -0
  318. package/lib/cjs/WABinary/encode.d.ts.map +1 -0
  319. package/lib/cjs/WABinary/encode.js +257 -0
  320. package/lib/cjs/WABinary/encode.js.map +1 -0
  321. package/lib/cjs/WABinary/generic-utils.d.ts +15 -0
  322. package/lib/cjs/WABinary/generic-utils.d.ts.map +1 -0
  323. package/lib/cjs/WABinary/generic-utils.js +125 -0
  324. package/lib/cjs/WABinary/generic-utils.js.map +1 -0
  325. package/lib/cjs/WABinary/index.d.ts +6 -0
  326. package/lib/cjs/WABinary/index.d.ts.map +1 -0
  327. package/lib/cjs/WABinary/index.js +22 -0
  328. package/lib/cjs/WABinary/index.js.map +1 -0
  329. package/lib/cjs/WABinary/jid-utils.d.ts +48 -0
  330. package/lib/cjs/WABinary/jid-utils.d.ts.map +1 -0
  331. package/lib/cjs/WABinary/jid-utils.js +115 -0
  332. package/lib/cjs/WABinary/jid-utils.js.map +1 -0
  333. package/lib/cjs/WABinary/types.d.ts +19 -0
  334. package/lib/cjs/WABinary/types.d.ts.map +1 -0
  335. package/lib/cjs/WABinary/types.js +3 -0
  336. package/lib/cjs/WABinary/types.js.map +1 -0
  337. package/lib/cjs/WAM/BinaryInfo.d.ts +9 -0
  338. package/lib/cjs/WAM/BinaryInfo.d.ts.map +1 -0
  339. package/lib/cjs/WAM/BinaryInfo.js +14 -0
  340. package/lib/cjs/WAM/BinaryInfo.js.map +1 -0
  341. package/lib/cjs/WAM/constants.d.ts +40 -0
  342. package/lib/cjs/WAM/constants.d.ts.map +1 -0
  343. package/lib/cjs/WAM/constants.js +22856 -0
  344. package/lib/cjs/WAM/constants.js.map +1 -0
  345. package/lib/cjs/WAM/encode.d.ts +3 -0
  346. package/lib/cjs/WAM/encode.d.ts.map +1 -0
  347. package/lib/cjs/WAM/encode.js +153 -0
  348. package/lib/cjs/WAM/encode.js.map +1 -0
  349. package/lib/cjs/WAM/index.d.ts +4 -0
  350. package/lib/cjs/WAM/index.d.ts.map +1 -0
  351. package/lib/cjs/WAM/index.js +20 -0
  352. package/lib/cjs/WAM/index.js.map +1 -0
  353. package/lib/cjs/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  354. package/lib/cjs/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
  355. package/lib/cjs/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  356. package/lib/cjs/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
  357. package/lib/cjs/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  358. package/lib/cjs/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
  359. package/lib/cjs/WAUSync/Protocols/USyncDeviceProtocol.js +58 -0
  360. package/lib/cjs/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
  361. package/lib/cjs/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  362. package/lib/cjs/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
  363. package/lib/cjs/WAUSync/Protocols/USyncDisappearingModeProtocol.js +31 -0
  364. package/lib/cjs/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
  365. package/lib/cjs/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  366. package/lib/cjs/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
  367. package/lib/cjs/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  368. package/lib/cjs/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
  369. package/lib/cjs/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  370. package/lib/cjs/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
  371. package/lib/cjs/WAUSync/Protocols/UsyncBotProfileProtocol.js +54 -0
  372. package/lib/cjs/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
  373. package/lib/cjs/WAUSync/Protocols/UsyncLIDProtocol.d.ts +17 -0
  374. package/lib/cjs/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
  375. package/lib/cjs/WAUSync/Protocols/UsyncLIDProtocol.js +33 -0
  376. package/lib/cjs/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
  377. package/lib/cjs/WAUSync/Protocols/index.d.ts +5 -0
  378. package/lib/cjs/WAUSync/Protocols/index.d.ts.map +1 -0
  379. package/lib/cjs/WAUSync/Protocols/index.js +21 -0
  380. package/lib/cjs/WAUSync/Protocols/index.js.map +1 -0
  381. package/lib/cjs/WAUSync/USyncQuery.d.ts +29 -0
  382. package/lib/cjs/WAUSync/USyncQuery.d.ts.map +1 -0
  383. package/lib/cjs/WAUSync/USyncQuery.js +97 -0
  384. package/lib/cjs/WAUSync/USyncQuery.js.map +1 -0
  385. package/lib/cjs/WAUSync/USyncUser.d.ts +13 -0
  386. package/lib/cjs/WAUSync/USyncUser.d.ts.map +1 -0
  387. package/lib/cjs/WAUSync/USyncUser.js +27 -0
  388. package/lib/cjs/WAUSync/USyncUser.js.map +1 -0
  389. package/lib/cjs/WAUSync/index.d.ts +4 -0
  390. package/lib/cjs/WAUSync/index.d.ts.map +1 -0
  391. package/lib/cjs/WAUSync/index.js +20 -0
  392. package/lib/cjs/WAUSync/index.js.map +1 -0
  393. package/lib/cjs/index.d.ts +12 -0
  394. package/lib/cjs/index.d.ts.map +1 -0
  395. package/lib/cjs/index.js +31 -0
  396. package/lib/cjs/index.js.map +1 -0
  397. package/lib/cjs/package.json +3 -0
  398. package/lib/esm/Defaults/index.d.ts +74 -0
  399. package/lib/esm/Defaults/index.d.ts.map +1 -0
  400. package/lib/esm/Defaults/index.js +128 -0
  401. package/lib/esm/Defaults/index.js.map +1 -0
  402. package/lib/esm/Signal/Group/ciphertext-message.d.ts +10 -0
  403. package/lib/esm/Signal/Group/ciphertext-message.d.ts.map +1 -0
  404. package/lib/esm/Signal/Group/ciphertext-message.js +12 -0
  405. package/lib/esm/Signal/Group/ciphertext-message.js.map +1 -0
  406. package/lib/esm/Signal/Group/group-session-builder.d.ts +15 -0
  407. package/lib/esm/Signal/Group/group-session-builder.d.ts.map +1 -0
  408. package/lib/esm/Signal/Group/group-session-builder.js +30 -0
  409. package/lib/esm/Signal/Group/group-session-builder.js.map +1 -0
  410. package/lib/esm/Signal/Group/group_cipher.d.ts +17 -0
  411. package/lib/esm/Signal/Group/group_cipher.d.ts.map +1 -0
  412. package/lib/esm/Signal/Group/group_cipher.js +82 -0
  413. package/lib/esm/Signal/Group/group_cipher.js.map +1 -0
  414. package/lib/esm/Signal/Group/index.d.ts +12 -0
  415. package/lib/esm/Signal/Group/index.d.ts.map +1 -0
  416. package/lib/esm/Signal/Group/index.js +12 -0
  417. package/lib/esm/Signal/Group/index.js.map +1 -0
  418. package/lib/esm/Signal/Group/keyhelper.d.ts +11 -0
  419. package/lib/esm/Signal/Group/keyhelper.d.ts.map +1 -0
  420. package/lib/esm/Signal/Group/keyhelper.js +18 -0
  421. package/lib/esm/Signal/Group/keyhelper.js.map +1 -0
  422. package/lib/esm/Signal/Group/sender-chain-key.d.ts +14 -0
  423. package/lib/esm/Signal/Group/sender-chain-key.d.ts.map +1 -0
  424. package/lib/esm/Signal/Group/sender-chain-key.js +26 -0
  425. package/lib/esm/Signal/Group/sender-chain-key.js.map +1 -0
  426. package/lib/esm/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  427. package/lib/esm/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
  428. package/lib/esm/Signal/Group/sender-key-distribution-message.js +63 -0
  429. package/lib/esm/Signal/Group/sender-key-distribution-message.js.map +1 -0
  430. package/lib/esm/Signal/Group/sender-key-message.d.ts +19 -0
  431. package/lib/esm/Signal/Group/sender-key-message.d.ts.map +1 -0
  432. package/lib/esm/Signal/Group/sender-key-message.js +66 -0
  433. package/lib/esm/Signal/Group/sender-key-message.js.map +1 -0
  434. package/lib/esm/Signal/Group/sender-key-name.d.ts +18 -0
  435. package/lib/esm/Signal/Group/sender-key-name.d.ts.map +1 -0
  436. package/lib/esm/Signal/Group/sender-key-name.js +48 -0
  437. package/lib/esm/Signal/Group/sender-key-name.js.map +1 -0
  438. package/lib/esm/Signal/Group/sender-key-record.d.ts +31 -0
  439. package/lib/esm/Signal/Group/sender-key-record.d.ts.map +1 -0
  440. package/lib/esm/Signal/Group/sender-key-record.js +41 -0
  441. package/lib/esm/Signal/Group/sender-key-record.js.map +1 -0
  442. package/lib/esm/Signal/Group/sender-key-state.d.ts +39 -0
  443. package/lib/esm/Signal/Group/sender-key-state.d.ts.map +1 -0
  444. package/lib/esm/Signal/Group/sender-key-state.js +84 -0
  445. package/lib/esm/Signal/Group/sender-key-state.js.map +1 -0
  446. package/lib/esm/Signal/Group/sender-message-key.d.ts +12 -0
  447. package/lib/esm/Signal/Group/sender-message-key.d.ts.map +1 -0
  448. package/lib/esm/Signal/Group/sender-message-key.js +26 -0
  449. package/lib/esm/Signal/Group/sender-message-key.js.map +1 -0
  450. package/lib/esm/Signal/jid-mapping.d.ts +50 -0
  451. package/lib/esm/Signal/jid-mapping.d.ts.map +1 -0
  452. package/lib/esm/Signal/jid-mapping.js +214 -0
  453. package/lib/esm/Signal/jid-mapping.js.map +1 -0
  454. package/lib/esm/Signal/libsignal.d.ts +7 -0
  455. package/lib/esm/Signal/libsignal.d.ts.map +1 -0
  456. package/lib/esm/Signal/libsignal.js +413 -0
  457. package/lib/esm/Signal/libsignal.js.map +1 -0
  458. package/lib/esm/Signal/lid-mapping.d.ts +6 -0
  459. package/lib/esm/Signal/lid-mapping.d.ts.map +1 -0
  460. package/lib/esm/Signal/lid-mapping.js +6 -0
  461. package/lib/esm/Signal/lid-mapping.js.map +1 -0
  462. package/lib/esm/Socket/Client/index.d.ts +3 -0
  463. package/lib/esm/Socket/Client/index.d.ts.map +1 -0
  464. package/lib/esm/Socket/Client/index.js +3 -0
  465. package/lib/esm/Socket/Client/index.js.map +1 -0
  466. package/lib/esm/Socket/Client/types.d.ts +16 -0
  467. package/lib/esm/Socket/Client/types.d.ts.map +1 -0
  468. package/lib/esm/Socket/Client/types.js +11 -0
  469. package/lib/esm/Socket/Client/types.js.map +1 -0
  470. package/lib/esm/Socket/Client/websocket.d.ts +13 -0
  471. package/lib/esm/Socket/Client/websocket.d.ts.map +1 -0
  472. package/lib/esm/Socket/Client/websocket.js +54 -0
  473. package/lib/esm/Socket/Client/websocket.js.map +1 -0
  474. package/lib/esm/Socket/business.d.ts +202 -0
  475. package/lib/esm/Socket/business.d.ts.map +1 -0
  476. package/lib/esm/Socket/business.js +379 -0
  477. package/lib/esm/Socket/business.js.map +1 -0
  478. package/lib/esm/Socket/chats.d.ts +111 -0
  479. package/lib/esm/Socket/chats.d.ts.map +1 -0
  480. package/lib/esm/Socket/chats.js +999 -0
  481. package/lib/esm/Socket/chats.js.map +1 -0
  482. package/lib/esm/Socket/communities.d.ts +258 -0
  483. package/lib/esm/Socket/communities.d.ts.map +1 -0
  484. package/lib/esm/Socket/communities.js +431 -0
  485. package/lib/esm/Socket/communities.js.map +1 -0
  486. package/lib/esm/Socket/groups.d.ts +150 -0
  487. package/lib/esm/Socket/groups.d.ts.map +1 -0
  488. package/lib/esm/Socket/groups.js +330 -0
  489. package/lib/esm/Socket/groups.js.map +1 -0
  490. package/lib/esm/Socket/index.d.ts +245 -0
  491. package/lib/esm/Socket/index.d.ts.map +1 -0
  492. package/lib/esm/Socket/index.js +12 -0
  493. package/lib/esm/Socket/index.js.map +1 -0
  494. package/lib/esm/Socket/messages-recv.d.ts +187 -0
  495. package/lib/esm/Socket/messages-recv.d.ts.map +1 -0
  496. package/lib/esm/Socket/messages-recv.js +1319 -0
  497. package/lib/esm/Socket/messages-recv.js.map +1 -0
  498. package/lib/esm/Socket/messages-send.d.ts +183 -0
  499. package/lib/esm/Socket/messages-send.d.ts.map +1 -0
  500. package/lib/esm/Socket/messages-send.js +1039 -0
  501. package/lib/esm/Socket/messages-send.js.map +1 -0
  502. package/lib/esm/Socket/mex.d.ts +3 -0
  503. package/lib/esm/Socket/mex.d.ts.map +1 -0
  504. package/lib/esm/Socket/mex.js +42 -0
  505. package/lib/esm/Socket/mex.js.map +1 -0
  506. package/lib/esm/Socket/newsletter.d.ts +160 -0
  507. package/lib/esm/Socket/newsletter.d.ts.map +1 -0
  508. package/lib/esm/Socket/newsletter.js +181 -0
  509. package/lib/esm/Socket/newsletter.js.map +1 -0
  510. package/lib/esm/Socket/socket.d.ts +55 -0
  511. package/lib/esm/Socket/socket.d.ts.map +1 -0
  512. package/lib/esm/Socket/socket.js +936 -0
  513. package/lib/esm/Socket/socket.js.map +1 -0
  514. package/lib/esm/Types/Auth.d.ts +126 -0
  515. package/lib/esm/Types/Auth.d.ts.map +1 -0
  516. package/lib/esm/Types/Auth.js +2 -0
  517. package/lib/esm/Types/Auth.js.map +1 -0
  518. package/lib/esm/Types/Bussines.d.ts +25 -0
  519. package/lib/esm/Types/Bussines.d.ts.map +1 -0
  520. package/lib/esm/Types/Bussines.js +2 -0
  521. package/lib/esm/Types/Bussines.js.map +1 -0
  522. package/lib/esm/Types/Call.d.ts +15 -0
  523. package/lib/esm/Types/Call.d.ts.map +1 -0
  524. package/lib/esm/Types/Call.js +2 -0
  525. package/lib/esm/Types/Call.js.map +1 -0
  526. package/lib/esm/Types/Chat.d.ts +123 -0
  527. package/lib/esm/Types/Chat.d.ts.map +1 -0
  528. package/lib/esm/Types/Chat.js +8 -0
  529. package/lib/esm/Types/Chat.js.map +1 -0
  530. package/lib/esm/Types/Contact.d.ts +24 -0
  531. package/lib/esm/Types/Contact.d.ts.map +1 -0
  532. package/lib/esm/Types/Contact.js +2 -0
  533. package/lib/esm/Types/Contact.js.map +1 -0
  534. package/lib/esm/Types/Events.d.ts +241 -0
  535. package/lib/esm/Types/Events.d.ts.map +1 -0
  536. package/lib/esm/Types/Events.js +2 -0
  537. package/lib/esm/Types/Events.js.map +1 -0
  538. package/lib/esm/Types/GroupMetadata.d.ts +67 -0
  539. package/lib/esm/Types/GroupMetadata.d.ts.map +1 -0
  540. package/lib/esm/Types/GroupMetadata.js +2 -0
  541. package/lib/esm/Types/GroupMetadata.js.map +1 -0
  542. package/lib/esm/Types/Label.d.ts +47 -0
  543. package/lib/esm/Types/Label.d.ts.map +1 -0
  544. package/lib/esm/Types/Label.js +25 -0
  545. package/lib/esm/Types/Label.js.map +1 -0
  546. package/lib/esm/Types/LabelAssociation.d.ts +30 -0
  547. package/lib/esm/Types/LabelAssociation.d.ts.map +1 -0
  548. package/lib/esm/Types/LabelAssociation.js +7 -0
  549. package/lib/esm/Types/LabelAssociation.js.map +1 -0
  550. package/lib/esm/Types/Message.d.ts +310 -0
  551. package/lib/esm/Types/Message.d.ts.map +1 -0
  552. package/lib/esm/Types/Message.js +14 -0
  553. package/lib/esm/Types/Message.js.map +1 -0
  554. package/lib/esm/Types/Newsletter.d.ts +135 -0
  555. package/lib/esm/Types/Newsletter.d.ts.map +1 -0
  556. package/lib/esm/Types/Newsletter.js +31 -0
  557. package/lib/esm/Types/Newsletter.js.map +1 -0
  558. package/lib/esm/Types/Product.d.ts +79 -0
  559. package/lib/esm/Types/Product.d.ts.map +1 -0
  560. package/lib/esm/Types/Product.js +2 -0
  561. package/lib/esm/Types/Product.js.map +1 -0
  562. package/lib/esm/Types/Signal.d.ts +76 -0
  563. package/lib/esm/Types/Signal.d.ts.map +1 -0
  564. package/lib/esm/Types/Signal.js +2 -0
  565. package/lib/esm/Types/Signal.js.map +1 -0
  566. package/lib/esm/Types/Socket.d.ts +135 -0
  567. package/lib/esm/Types/Socket.d.ts.map +1 -0
  568. package/lib/esm/Types/Socket.js +3 -0
  569. package/lib/esm/Types/Socket.js.map +1 -0
  570. package/lib/esm/Types/State.d.ts +39 -0
  571. package/lib/esm/Types/State.d.ts.map +1 -0
  572. package/lib/esm/Types/State.js +13 -0
  573. package/lib/esm/Types/State.js.map +1 -0
  574. package/lib/esm/Types/USync.d.ts +26 -0
  575. package/lib/esm/Types/USync.d.ts.map +1 -0
  576. package/lib/esm/Types/USync.js +2 -0
  577. package/lib/esm/Types/USync.js.map +1 -0
  578. package/lib/esm/Types/index.d.ts +65 -0
  579. package/lib/esm/Types/index.d.ts.map +1 -0
  580. package/lib/esm/Types/index.js +26 -0
  581. package/lib/esm/Types/index.js.map +1 -0
  582. package/lib/esm/Utils/auth-utils.d.ts +19 -0
  583. package/lib/esm/Utils/auth-utils.d.ts.map +1 -0
  584. package/lib/esm/Utils/auth-utils.js +290 -0
  585. package/lib/esm/Utils/auth-utils.js.map +1 -0
  586. package/lib/esm/Utils/browser-utils.d.ts +4 -0
  587. package/lib/esm/Utils/browser-utils.d.ts.map +1 -0
  588. package/lib/esm/Utils/browser-utils.js +28 -0
  589. package/lib/esm/Utils/browser-utils.js.map +1 -0
  590. package/lib/esm/Utils/business.d.ts +23 -0
  591. package/lib/esm/Utils/business.d.ts.map +1 -0
  592. package/lib/esm/Utils/business.js +231 -0
  593. package/lib/esm/Utils/business.js.map +1 -0
  594. package/lib/esm/Utils/chat-utils.d.ts +70 -0
  595. package/lib/esm/Utils/chat-utils.d.ts.map +1 -0
  596. package/lib/esm/Utils/chat-utils.js +812 -0
  597. package/lib/esm/Utils/chat-utils.js.map +1 -0
  598. package/lib/esm/Utils/crypto.d.ts +37 -0
  599. package/lib/esm/Utils/crypto.d.ts.map +1 -0
  600. package/lib/esm/Utils/crypto.js +118 -0
  601. package/lib/esm/Utils/crypto.js.map +1 -0
  602. package/lib/esm/Utils/decode-wa-message.d.ts +48 -0
  603. package/lib/esm/Utils/decode-wa-message.d.ts.map +1 -0
  604. package/lib/esm/Utils/decode-wa-message.js +286 -0
  605. package/lib/esm/Utils/decode-wa-message.js.map +1 -0
  606. package/lib/esm/Utils/event-buffer.d.ts +34 -0
  607. package/lib/esm/Utils/event-buffer.d.ts.map +1 -0
  608. package/lib/esm/Utils/event-buffer.js +574 -0
  609. package/lib/esm/Utils/event-buffer.js.map +1 -0
  610. package/lib/esm/Utils/generics.d.ts +91 -0
  611. package/lib/esm/Utils/generics.d.ts.map +1 -0
  612. package/lib/esm/Utils/generics.js +384 -0
  613. package/lib/esm/Utils/generics.js.map +1 -0
  614. package/lib/esm/Utils/history.d.ts +22 -0
  615. package/lib/esm/Utils/history.d.ts.map +1 -0
  616. package/lib/esm/Utils/history.js +131 -0
  617. package/lib/esm/Utils/history.js.map +1 -0
  618. package/lib/esm/Utils/identity-change-handler.d.ts +38 -0
  619. package/lib/esm/Utils/identity-change-handler.d.ts.map +1 -0
  620. package/lib/esm/Utils/identity-change-handler.js +50 -0
  621. package/lib/esm/Utils/identity-change-handler.js.map +1 -0
  622. package/lib/esm/Utils/index.d.ts +21 -0
  623. package/lib/esm/Utils/index.d.ts.map +1 -0
  624. package/lib/esm/Utils/index.js +21 -0
  625. package/lib/esm/Utils/index.js.map +1 -0
  626. package/lib/esm/Utils/link-preview.d.ts +21 -0
  627. package/lib/esm/Utils/link-preview.d.ts.map +1 -0
  628. package/lib/esm/Utils/link-preview.js +85 -0
  629. package/lib/esm/Utils/link-preview.js.map +1 -0
  630. package/lib/esm/Utils/logger.d.ts +13 -0
  631. package/lib/esm/Utils/logger.d.ts.map +1 -0
  632. package/lib/esm/Utils/logger.js +3 -0
  633. package/lib/esm/Utils/logger.js.map +1 -0
  634. package/lib/esm/Utils/lt-hash.d.ts +8 -0
  635. package/lib/esm/Utils/lt-hash.d.ts.map +1 -0
  636. package/lib/esm/Utils/lt-hash.js +8 -0
  637. package/lib/esm/Utils/lt-hash.js.map +1 -0
  638. package/lib/esm/Utils/make-mutex.d.ts +9 -0
  639. package/lib/esm/Utils/make-mutex.d.ts.map +1 -0
  640. package/lib/esm/Utils/make-mutex.js +33 -0
  641. package/lib/esm/Utils/make-mutex.js.map +1 -0
  642. package/lib/esm/Utils/message-retry-manager.d.ts +110 -0
  643. package/lib/esm/Utils/message-retry-manager.d.ts.map +1 -0
  644. package/lib/esm/Utils/message-retry-manager.js +225 -0
  645. package/lib/esm/Utils/message-retry-manager.js.map +1 -0
  646. package/lib/esm/Utils/messages-media.d.ts +130 -0
  647. package/lib/esm/Utils/messages-media.d.ts.map +1 -0
  648. package/lib/esm/Utils/messages-media.js +774 -0
  649. package/lib/esm/Utils/messages-media.js.map +1 -0
  650. package/lib/esm/Utils/messages.d.ts +91 -0
  651. package/lib/esm/Utils/messages.d.ts.map +1 -0
  652. package/lib/esm/Utils/messages.js +878 -0
  653. package/lib/esm/Utils/messages.js.map +1 -0
  654. package/lib/esm/Utils/noise-handler.d.ts +20 -0
  655. package/lib/esm/Utils/noise-handler.d.ts.map +1 -0
  656. package/lib/esm/Utils/noise-handler.js +201 -0
  657. package/lib/esm/Utils/noise-handler.js.map +1 -0
  658. package/lib/esm/Utils/offline-node-processor.d.ts +17 -0
  659. package/lib/esm/Utils/offline-node-processor.d.ts.map +1 -0
  660. package/lib/esm/Utils/offline-node-processor.js +40 -0
  661. package/lib/esm/Utils/offline-node-processor.js.map +1 -0
  662. package/lib/esm/Utils/pre-key-manager.d.ts +28 -0
  663. package/lib/esm/Utils/pre-key-manager.d.ts.map +1 -0
  664. package/lib/esm/Utils/pre-key-manager.js +106 -0
  665. package/lib/esm/Utils/pre-key-manager.js.map +1 -0
  666. package/lib/esm/Utils/process-message.d.ts +60 -0
  667. package/lib/esm/Utils/process-message.d.ts.map +1 -0
  668. package/lib/esm/Utils/process-message.js +530 -0
  669. package/lib/esm/Utils/process-message.js.map +1 -0
  670. package/lib/esm/Utils/reporting-utils.d.ts +11 -0
  671. package/lib/esm/Utils/reporting-utils.d.ts.map +1 -0
  672. package/lib/esm/Utils/reporting-utils.js +258 -0
  673. package/lib/esm/Utils/reporting-utils.js.map +1 -0
  674. package/lib/esm/Utils/signal.d.ts +34 -0
  675. package/lib/esm/Utils/signal.d.ts.map +1 -0
  676. package/lib/esm/Utils/signal.js +159 -0
  677. package/lib/esm/Utils/signal.js.map +1 -0
  678. package/lib/esm/Utils/stanza-ack.d.ts +11 -0
  679. package/lib/esm/Utils/stanza-ack.d.ts.map +1 -0
  680. package/lib/esm/Utils/stanza-ack.js +38 -0
  681. package/lib/esm/Utils/stanza-ack.js.map +1 -0
  682. package/lib/esm/Utils/sync-action-utils.d.ts +19 -0
  683. package/lib/esm/Utils/sync-action-utils.d.ts.map +1 -0
  684. package/lib/esm/Utils/sync-action-utils.js +48 -0
  685. package/lib/esm/Utils/sync-action-utils.js.map +1 -0
  686. package/lib/esm/Utils/tc-token-utils.d.ts +12 -0
  687. package/lib/esm/Utils/tc-token-utils.d.ts.map +1 -0
  688. package/lib/esm/Utils/tc-token-utils.js +18 -0
  689. package/lib/esm/Utils/tc-token-utils.js.map +1 -0
  690. package/lib/esm/Utils/use-multi-file-auth-state.d.ts +13 -0
  691. package/lib/esm/Utils/use-multi-file-auth-state.d.ts.map +1 -0
  692. package/lib/esm/Utils/use-multi-file-auth-state.js +121 -0
  693. package/lib/esm/Utils/use-multi-file-auth-state.js.map +1 -0
  694. package/lib/esm/Utils/validate-connection.d.ts +11 -0
  695. package/lib/esm/Utils/validate-connection.d.ts.map +1 -0
  696. package/lib/esm/Utils/validate-connection.js +202 -0
  697. package/lib/esm/Utils/validate-connection.js.map +1 -0
  698. package/lib/esm/WABinary/constants.d.ts +28 -0
  699. package/lib/esm/WABinary/constants.d.ts.map +1 -0
  700. package/lib/esm/WABinary/constants.js +1301 -0
  701. package/lib/esm/WABinary/constants.js.map +1 -0
  702. package/lib/esm/WABinary/decode.d.ts +7 -0
  703. package/lib/esm/WABinary/decode.d.ts.map +1 -0
  704. package/lib/esm/WABinary/decode.js +262 -0
  705. package/lib/esm/WABinary/decode.js.map +1 -0
  706. package/lib/esm/WABinary/encode.d.ts +3 -0
  707. package/lib/esm/WABinary/encode.d.ts.map +1 -0
  708. package/lib/esm/WABinary/encode.js +220 -0
  709. package/lib/esm/WABinary/encode.js.map +1 -0
  710. package/lib/esm/WABinary/generic-utils.d.ts +15 -0
  711. package/lib/esm/WABinary/generic-utils.d.ts.map +1 -0
  712. package/lib/esm/WABinary/generic-utils.js +113 -0
  713. package/lib/esm/WABinary/generic-utils.js.map +1 -0
  714. package/lib/esm/WABinary/index.d.ts +6 -0
  715. package/lib/esm/WABinary/index.d.ts.map +1 -0
  716. package/lib/esm/WABinary/index.js +6 -0
  717. package/lib/esm/WABinary/index.js.map +1 -0
  718. package/lib/esm/WABinary/jid-utils.d.ts +48 -0
  719. package/lib/esm/WABinary/jid-utils.d.ts.map +1 -0
  720. package/lib/esm/WABinary/jid-utils.js +96 -0
  721. package/lib/esm/WABinary/jid-utils.js.map +1 -0
  722. package/lib/esm/WABinary/types.d.ts +19 -0
  723. package/lib/esm/WABinary/types.d.ts.map +1 -0
  724. package/lib/esm/WABinary/types.js +2 -0
  725. package/lib/esm/WABinary/types.js.map +1 -0
  726. package/lib/esm/WAM/BinaryInfo.d.ts +9 -0
  727. package/lib/esm/WAM/BinaryInfo.d.ts.map +1 -0
  728. package/lib/esm/WAM/BinaryInfo.js +10 -0
  729. package/lib/esm/WAM/BinaryInfo.js.map +1 -0
  730. package/lib/esm/WAM/constants.d.ts +40 -0
  731. package/lib/esm/WAM/constants.d.ts.map +1 -0
  732. package/lib/esm/WAM/constants.js +22853 -0
  733. package/lib/esm/WAM/constants.js.map +1 -0
  734. package/lib/esm/WAM/encode.d.ts +3 -0
  735. package/lib/esm/WAM/encode.d.ts.map +1 -0
  736. package/lib/esm/WAM/encode.js +150 -0
  737. package/lib/esm/WAM/encode.js.map +1 -0
  738. package/lib/esm/WAM/index.d.ts +4 -0
  739. package/lib/esm/WAM/index.d.ts.map +1 -0
  740. package/lib/esm/WAM/index.js +4 -0
  741. package/lib/esm/WAM/index.js.map +1 -0
  742. package/lib/esm/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  743. package/lib/esm/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
  744. package/lib/esm/WAUSync/Protocols/USyncContactProtocol.js +29 -0
  745. package/lib/esm/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
  746. package/lib/esm/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  747. package/lib/esm/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
  748. package/lib/esm/WAUSync/Protocols/USyncDeviceProtocol.js +54 -0
  749. package/lib/esm/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
  750. package/lib/esm/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  751. package/lib/esm/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
  752. package/lib/esm/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
  753. package/lib/esm/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
  754. package/lib/esm/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  755. package/lib/esm/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
  756. package/lib/esm/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
  757. package/lib/esm/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
  758. package/lib/esm/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  759. package/lib/esm/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
  760. package/lib/esm/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
  761. package/lib/esm/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
  762. package/lib/esm/WAUSync/Protocols/UsyncLIDProtocol.d.ts +17 -0
  763. package/lib/esm/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
  764. package/lib/esm/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
  765. package/lib/esm/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
  766. package/lib/esm/WAUSync/Protocols/index.d.ts +5 -0
  767. package/lib/esm/WAUSync/Protocols/index.d.ts.map +1 -0
  768. package/lib/esm/WAUSync/Protocols/index.js +5 -0
  769. package/lib/esm/WAUSync/Protocols/index.js.map +1 -0
  770. package/lib/esm/WAUSync/USyncQuery.d.ts +29 -0
  771. package/lib/esm/WAUSync/USyncQuery.d.ts.map +1 -0
  772. package/lib/esm/WAUSync/USyncQuery.js +94 -0
  773. package/lib/esm/WAUSync/USyncQuery.js.map +1 -0
  774. package/lib/esm/WAUSync/USyncUser.d.ts +13 -0
  775. package/lib/esm/WAUSync/USyncUser.d.ts.map +1 -0
  776. package/lib/esm/WAUSync/USyncUser.js +23 -0
  777. package/lib/esm/WAUSync/USyncUser.js.map +1 -0
  778. package/lib/esm/WAUSync/index.d.ts +4 -0
  779. package/lib/esm/WAUSync/index.d.ts.map +1 -0
  780. package/lib/esm/WAUSync/index.js +4 -0
  781. package/lib/esm/WAUSync/index.js.map +1 -0
  782. package/lib/esm/index.d.ts +12 -0
  783. package/lib/esm/index.d.ts.map +1 -0
  784. package/lib/esm/index.js +11 -0
  785. package/lib/esm/index.js.map +1 -0
  786. package/lib/esm/package.json +3 -0
  787. package/package.json +129 -0
@@ -0,0 +1,1046 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.makeMessagesSocket = void 0;
7
+ const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
8
+ const boom_1 = require("@hapi/boom");
9
+ const index_js_1 = require("../../WAProto/index.js");
10
+ const Defaults_1 = require("../Defaults");
11
+ const Utils_1 = require("../Utils");
12
+ const link_preview_1 = require("../Utils/link-preview");
13
+ const make_mutex_1 = require("../Utils/make-mutex");
14
+ const reporting_utils_1 = require("../Utils/reporting-utils");
15
+ const WABinary_1 = require("../WABinary");
16
+ const WAUSync_1 = require("../WAUSync");
17
+ const newsletter_1 = require("./newsletter");
18
+ const makeMessagesSocket = (config) => {
19
+ const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: httpRequestOptions, patchMessageBeforeSending, cachedGroupMetadata, enableRecentMessageCache, maxMsgRetryCount } = config;
20
+ const sock = (0, newsletter_1.makeNewsletterSocket)(config);
21
+ const { ev, authState, messageMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, sendNode, groupMetadata, groupToggleEphemeral } = sock;
22
+ const userDevicesCache = config.userDevicesCache ||
23
+ new node_cache_1.default({
24
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
25
+ useClones: false
26
+ });
27
+ const peerSessionsCache = new node_cache_1.default({
28
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
29
+ useClones: false
30
+ });
31
+ // Initialize message retry manager if enabled
32
+ const messageRetryManager = enableRecentMessageCache ? new Utils_1.MessageRetryManager(logger, maxMsgRetryCount) : null;
33
+ // Prevent race conditions in Signal session encryption by user
34
+ const encryptionMutex = (0, make_mutex_1.makeKeyedMutex)();
35
+ let mediaConn;
36
+ const refreshMediaConn = async (forceGet = false) => {
37
+ const media = await mediaConn;
38
+ if (!media || forceGet || new Date().getTime() - media.fetchDate.getTime() > media.ttl * 1000) {
39
+ mediaConn = (async () => {
40
+ const result = await query({
41
+ tag: 'iq',
42
+ attrs: {
43
+ type: 'set',
44
+ xmlns: 'w:m',
45
+ to: WABinary_1.S_WHATSAPP_NET
46
+ },
47
+ content: [{ tag: 'media_conn', attrs: {} }]
48
+ });
49
+ const mediaConnNode = (0, WABinary_1.getBinaryNodeChild)(result, 'media_conn');
50
+ // TODO: explore full length of data that whatsapp provides
51
+ const node = {
52
+ hosts: (0, WABinary_1.getBinaryNodeChildren)(mediaConnNode, 'host').map(({ attrs }) => ({
53
+ hostname: attrs.hostname,
54
+ maxContentLengthBytes: +attrs.maxContentLengthBytes
55
+ })),
56
+ auth: mediaConnNode.attrs.auth,
57
+ ttl: +mediaConnNode.attrs.ttl,
58
+ fetchDate: new Date()
59
+ };
60
+ logger.debug('fetched media conn');
61
+ return node;
62
+ })();
63
+ }
64
+ return mediaConn;
65
+ };
66
+ /**
67
+ * generic send receipt function
68
+ * used for receipts of phone call, read, delivery etc.
69
+ * */
70
+ const sendReceipt = async (jid, participant, messageIds, type) => {
71
+ if (!messageIds || messageIds.length === 0) {
72
+ throw new boom_1.Boom('missing ids in receipt');
73
+ }
74
+ const node = {
75
+ tag: 'receipt',
76
+ attrs: {
77
+ id: messageIds[0]
78
+ }
79
+ };
80
+ const isReadReceipt = type === 'read' || type === 'read-self';
81
+ if (isReadReceipt) {
82
+ node.attrs.t = (0, Utils_1.unixTimestampSeconds)().toString();
83
+ }
84
+ if (type === 'sender' && ((0, WABinary_1.isPnUser)(jid) || (0, WABinary_1.isLidUser)(jid))) {
85
+ node.attrs.recipient = jid;
86
+ node.attrs.to = participant;
87
+ }
88
+ else {
89
+ node.attrs.to = jid;
90
+ if (participant) {
91
+ node.attrs.participant = participant;
92
+ }
93
+ }
94
+ if (type) {
95
+ node.attrs.type = type;
96
+ }
97
+ const remainingMessageIds = messageIds.slice(1);
98
+ if (remainingMessageIds.length) {
99
+ node.content = [
100
+ {
101
+ tag: 'list',
102
+ attrs: {},
103
+ content: remainingMessageIds.map(id => ({
104
+ tag: 'item',
105
+ attrs: { id }
106
+ }))
107
+ }
108
+ ];
109
+ }
110
+ logger.debug({ attrs: node.attrs, messageIds }, 'sending receipt for messages');
111
+ await sendNode(node);
112
+ };
113
+ /** Correctly bulk send receipts to multiple chats, participants */
114
+ const sendReceipts = async (keys, type) => {
115
+ const recps = (0, Utils_1.aggregateMessageKeysNotFromMe)(keys);
116
+ for (const { jid, participant, messageIds } of recps) {
117
+ await sendReceipt(jid, participant, messageIds, type);
118
+ }
119
+ };
120
+ /** Bulk read messages. Keys can be from different chats & participants */
121
+ const readMessages = async (keys) => {
122
+ const privacySettings = await fetchPrivacySettings();
123
+ // based on privacy settings, we have to change the read type
124
+ const readType = privacySettings.readreceipts === 'all' ? 'read' : 'read-self';
125
+ await sendReceipts(keys, readType);
126
+ };
127
+ /** Fetch all the devices we've to send a message to */
128
+ const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
129
+ const deviceResults = [];
130
+ if (!useCache) {
131
+ logger.debug('not using cache for devices');
132
+ }
133
+ const toFetch = [];
134
+ const jidsWithUser = jids
135
+ .map(jid => {
136
+ const decoded = (0, WABinary_1.jidDecode)(jid);
137
+ const user = decoded?.user;
138
+ const device = decoded?.device;
139
+ const isExplicitDevice = typeof device === 'number' && device >= 0;
140
+ if (isExplicitDevice && user) {
141
+ deviceResults.push({
142
+ user,
143
+ device,
144
+ jid
145
+ });
146
+ return null;
147
+ }
148
+ jid = (0, WABinary_1.jidNormalizedUser)(jid);
149
+ return { jid, user };
150
+ })
151
+ .filter(jid => jid !== null);
152
+ let mgetDevices;
153
+ if (useCache && userDevicesCache.mget) {
154
+ const usersToFetch = jidsWithUser.map(j => j?.user).filter(Boolean);
155
+ mgetDevices = await userDevicesCache.mget(usersToFetch);
156
+ }
157
+ for (const { jid, user } of jidsWithUser) {
158
+ if (useCache) {
159
+ const devices = mgetDevices?.[user] ||
160
+ (userDevicesCache.mget ? undefined : (await userDevicesCache.get(user)));
161
+ if (devices) {
162
+ const devicesWithJid = devices.map(d => ({
163
+ ...d,
164
+ jid: (0, WABinary_1.jidEncode)(d.user, d.server, d.device)
165
+ }));
166
+ deviceResults.push(...devicesWithJid);
167
+ logger.trace({ user }, 'using cache for devices');
168
+ }
169
+ else {
170
+ toFetch.push(jid);
171
+ }
172
+ }
173
+ else {
174
+ toFetch.push(jid);
175
+ }
176
+ }
177
+ if (!toFetch.length) {
178
+ return deviceResults;
179
+ }
180
+ const requestedLidUsers = new Set();
181
+ for (const jid of toFetch) {
182
+ if ((0, WABinary_1.isLidUser)(jid) || (0, WABinary_1.isHostedLidUser)(jid)) {
183
+ const user = (0, WABinary_1.jidDecode)(jid)?.user;
184
+ if (user)
185
+ requestedLidUsers.add(user);
186
+ }
187
+ }
188
+ const query = new WAUSync_1.USyncQuery().withContext('message').withDeviceProtocol().withLIDProtocol();
189
+ for (const jid of toFetch) {
190
+ query.withUser(new WAUSync_1.USyncUser().withId(jid)); // todo: investigate - the idea here is that <user> should have an inline lid field with the lid being the pn equivalent
191
+ }
192
+ const result = await sock.executeUSyncQuery(query);
193
+ if (result) {
194
+ // TODO: LID MAP this stuff (lid protocol will now return lid with devices)
195
+ const lidResults = result.list.filter(a => !!a.lid);
196
+ if (lidResults.length > 0) {
197
+ logger.trace('Storing LID→JID maps from device call');
198
+ await signalRepository.jidMapping.storeLIDPNMappings(lidResults.map(a => ({ lid: a.lid, pn: a.id })));
199
+ // JID-first: LID→JID mappings stored; sessions addressed by JID, no LID session setup needed
200
+ }
201
+ const extracted = (0, Utils_1.extractDeviceJids)(result?.list, authState.creds.me.id, '' /* JID-first: no lid */, ignoreZeroDevices);
202
+ const deviceMap = {};
203
+ for (const item of extracted) {
204
+ deviceMap[item.user] = deviceMap[item.user] || [];
205
+ deviceMap[item.user]?.push(item);
206
+ }
207
+ // Process each user's devices as a group for bulk LID migration
208
+ for (const [user, userDevices] of Object.entries(deviceMap)) {
209
+ const isLidUser = requestedLidUsers.has(user);
210
+ // Process all devices for this user
211
+ for (const item of userDevices) {
212
+ const finalJid = isLidUser
213
+ ? (0, WABinary_1.jidEncode)(user, item.server, item.device)
214
+ : (0, WABinary_1.jidEncode)(item.user, item.server, item.device);
215
+ deviceResults.push({
216
+ ...item,
217
+ jid: finalJid
218
+ });
219
+ logger.debug({
220
+ user: item.user,
221
+ device: item.device,
222
+ finalJid,
223
+ usedLid: isLidUser
224
+ }, 'Processed device with LID priority');
225
+ }
226
+ }
227
+ if (userDevicesCache.mset) {
228
+ // if the cache supports mset, we can set all devices in one go
229
+ await userDevicesCache.mset(Object.entries(deviceMap).map(([key, value]) => ({ key, value })));
230
+ }
231
+ else {
232
+ for (const key in deviceMap) {
233
+ if (deviceMap[key])
234
+ await userDevicesCache.set(key, deviceMap[key]);
235
+ }
236
+ }
237
+ const userDeviceUpdates = {};
238
+ for (const [userId, devices] of Object.entries(deviceMap)) {
239
+ if (devices && devices.length > 0) {
240
+ userDeviceUpdates[userId] = devices.map(d => d.device?.toString() || '0');
241
+ }
242
+ }
243
+ if (Object.keys(userDeviceUpdates).length > 0) {
244
+ try {
245
+ await authState.keys.set({ 'device-list': userDeviceUpdates });
246
+ logger.debug({ userCount: Object.keys(userDeviceUpdates).length }, 'stored user device lists for bulk migration');
247
+ }
248
+ catch (error) {
249
+ logger.warn({ error }, 'failed to store user device lists');
250
+ }
251
+ }
252
+ }
253
+ return deviceResults;
254
+ };
255
+ /**
256
+ * Update Member Label
257
+ */
258
+ const updateMemberLabel = (jid, memberLabel) => {
259
+ return relayMessage(jid, {
260
+ protocolMessage: {
261
+ type: index_js_1.proto.Message.ProtocolMessage.Type.GROUP_MEMBER_LABEL_CHANGE,
262
+ memberLabel: {
263
+ label: memberLabel?.slice(0, 30),
264
+ labelTimestamp: (0, Utils_1.unixTimestampSeconds)()
265
+ }
266
+ }
267
+ }, {
268
+ additionalNodes: [
269
+ {
270
+ tag: 'meta',
271
+ attrs: {
272
+ tag_reason: 'user_update',
273
+ appdata: 'member_tag'
274
+ },
275
+ content: undefined
276
+ }
277
+ ]
278
+ });
279
+ };
280
+ const assertSessions = async (jids, force) => {
281
+ let didFetchNewSession = false;
282
+ const uniqueJids = [...new Set(jids)]; // Deduplicate JIDs
283
+ const jidsRequiringFetch = [];
284
+ logger.debug({ jids }, 'assertSessions call with jids');
285
+ // Check peerSessionsCache and validate sessions using libsignal loadSession
286
+ for (const jid of uniqueJids) {
287
+ const signalId = signalRepository.jidToSignalProtocolAddress(jid);
288
+ const cachedSession = peerSessionsCache.get(signalId);
289
+ if (cachedSession !== undefined) {
290
+ if (cachedSession && !force) {
291
+ continue; // Session exists in cache
292
+ }
293
+ }
294
+ else {
295
+ const sessionValidation = await signalRepository.validateSession(jid);
296
+ const hasSession = sessionValidation.exists;
297
+ peerSessionsCache.set(signalId, hasSession);
298
+ if (hasSession && !force) {
299
+ continue;
300
+ }
301
+ }
302
+ jidsRequiringFetch.push(jid);
303
+ }
304
+ if (jidsRequiringFetch.length) {
305
+ // LID if mapped, otherwise original
306
+ // JID-first: use JIDs directly; resolve any incoming LID addresses via jidMapping
307
+ const resolvedLidJids = await Promise.all(jidsRequiringFetch
308
+ .filter(jid => !!(0, WABinary_1.isLidUser)(jid) || !!(0, WABinary_1.isHostedLidUser)(jid))
309
+ .map(jid => signalRepository.jidMapping.resolveToJID(jid)));
310
+ const wireJids = [
311
+ ...resolvedLidJids,
312
+ ...jidsRequiringFetch.filter(jid => !!(0, WABinary_1.isPnUser)(jid) || !!(0, WABinary_1.isHostedPnUser)(jid))
313
+ ];
314
+ logger.debug({ jidsRequiringFetch, wireJids }, 'fetching sessions');
315
+ const result = await query({
316
+ tag: 'iq',
317
+ attrs: {
318
+ xmlns: 'encrypt',
319
+ type: 'get',
320
+ to: WABinary_1.S_WHATSAPP_NET
321
+ },
322
+ content: [
323
+ {
324
+ tag: 'key',
325
+ attrs: {},
326
+ content: wireJids.map(jid => {
327
+ const attrs = { jid };
328
+ if (force)
329
+ attrs.reason = 'identity';
330
+ return { tag: 'user', attrs };
331
+ })
332
+ }
333
+ ]
334
+ });
335
+ await (0, Utils_1.parseAndInjectE2ESessions)(result, signalRepository);
336
+ didFetchNewSession = true;
337
+ // Cache fetched sessions using wire JIDs
338
+ for (const wireJid of wireJids) {
339
+ const signalId = signalRepository.jidToSignalProtocolAddress(wireJid);
340
+ peerSessionsCache.set(signalId, true);
341
+ }
342
+ }
343
+ return didFetchNewSession;
344
+ };
345
+ const sendPeerDataOperationMessage = async (pdoMessage) => {
346
+ //TODO: for later, abstract the logic to send a Peer Message instead of just PDO - useful for App State Key Resync with phone
347
+ if (!authState.creds.me?.id) {
348
+ throw new boom_1.Boom('Not authenticated');
349
+ }
350
+ const protocolMessage = {
351
+ protocolMessage: {
352
+ peerDataOperationRequestMessage: pdoMessage,
353
+ type: index_js_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
354
+ }
355
+ };
356
+ const meJid = (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id);
357
+ const msgId = await relayMessage(meJid, protocolMessage, {
358
+ additionalAttributes: {
359
+ category: 'peer',
360
+ push_priority: 'high_force'
361
+ },
362
+ additionalNodes: [
363
+ {
364
+ tag: 'meta',
365
+ attrs: { appdata: 'default' }
366
+ }
367
+ ]
368
+ });
369
+ return msgId;
370
+ };
371
+ const createParticipantNodes = async (recipientJids, message, extraAttrs, dsmMessage) => {
372
+ if (!recipientJids.length) {
373
+ return { nodes: [], shouldIncludeDeviceIdentity: false };
374
+ }
375
+ const patched = await patchMessageBeforeSending(message, recipientJids);
376
+ const patchedMessages = Array.isArray(patched)
377
+ ? patched
378
+ : recipientJids.map(jid => ({ recipientJid: jid, message: patched }));
379
+ let shouldIncludeDeviceIdentity = false;
380
+ const meId = authState.creds.me.id;
381
+ // JID-first: meLid not used for addressing
382
+ const encryptionPromises = patchedMessages.map(async ({ recipientJid: jid, message: patchedMessage }) => {
383
+ try {
384
+ if (!jid)
385
+ return null;
386
+ let msgToEncrypt = patchedMessage;
387
+ if (dsmMessage) {
388
+ const { user: targetUser } = (0, WABinary_1.jidDecode)(jid);
389
+ const { user: ownPnUser } = (0, WABinary_1.jidDecode)(meId);
390
+ const isOwnUser = targetUser === ownPnUser; // JID-first: only PN user match
391
+ const isExactSenderDevice = jid === meId;
392
+ if (isOwnUser && !isExactSenderDevice) {
393
+ msgToEncrypt = dsmMessage;
394
+ logger.debug({ jid, targetUser }, 'Using DSM for own device');
395
+ }
396
+ }
397
+ const bytes = (0, Utils_1.encodeWAMessage)(msgToEncrypt);
398
+ const mutexKey = jid;
399
+ const node = await encryptionMutex.mutex(mutexKey, async () => {
400
+ const { type, ciphertext } = await signalRepository.encryptMessage({ jid, data: bytes });
401
+ if (type === 'pkmsg') {
402
+ shouldIncludeDeviceIdentity = true;
403
+ }
404
+ return {
405
+ tag: 'to',
406
+ attrs: { jid },
407
+ content: [
408
+ {
409
+ tag: 'enc',
410
+ attrs: { v: '2', type, ...(extraAttrs || {}) },
411
+ content: ciphertext
412
+ }
413
+ ]
414
+ };
415
+ });
416
+ return node;
417
+ }
418
+ catch (err) {
419
+ logger.error({ jid, err }, 'Failed to encrypt for recipient');
420
+ return null;
421
+ }
422
+ });
423
+ const nodes = (await Promise.all(encryptionPromises)).filter(node => node !== null);
424
+ if (recipientJids.length > 0 && nodes.length === 0) {
425
+ throw new boom_1.Boom('All encryptions failed', { statusCode: 500 });
426
+ }
427
+ return { nodes, shouldIncludeDeviceIdentity };
428
+ };
429
+ const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }) => {
430
+ const meId = authState.creds.me.id;
431
+ // meLid read for server compat only — addressing always uses meId
432
+ const _meLid = authState.creds.me?.lid;
433
+ const isRetryResend = Boolean(participant?.jid);
434
+ let shouldIncludeDeviceIdentity = isRetryResend;
435
+ const statusJid = 'status@broadcast';
436
+ const { user, server } = (0, WABinary_1.jidDecode)(jid);
437
+ const isGroup = server === 'g.us';
438
+ const isStatus = jid === statusJid;
439
+ const isLid = server === 'lid';
440
+ const isNewsletter = server === 'newsletter';
441
+ const isGroupOrStatus = isGroup || isStatus;
442
+ const finalJid = jid;
443
+ msgId = msgId || (0, Utils_1.generateMessageIDV2)(meId);
444
+ useUserDevicesCache = useUserDevicesCache !== false;
445
+ useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus;
446
+ const participants = [];
447
+ const destinationJid = !isStatus ? finalJid : statusJid;
448
+ const binaryNodeContent = [];
449
+ const devices = [];
450
+ let reportingMessage;
451
+ const meMsg = {
452
+ deviceSentMessage: {
453
+ destinationJid,
454
+ message
455
+ },
456
+ messageContextInfo: message.messageContextInfo
457
+ };
458
+ const extraAttrs = {};
459
+ if (participant) {
460
+ if (!isGroup && !isStatus) {
461
+ additionalAttributes = { ...additionalAttributes, device_fanout: 'false' };
462
+ }
463
+ const { user, device } = (0, WABinary_1.jidDecode)(participant.jid);
464
+ devices.push({
465
+ user,
466
+ device,
467
+ jid: participant.jid
468
+ });
469
+ }
470
+ await authState.keys.transaction(async () => {
471
+ const mediaType = getMediaType(message);
472
+ if (mediaType) {
473
+ extraAttrs['mediatype'] = mediaType;
474
+ }
475
+ if (isNewsletter) {
476
+ const patched = patchMessageBeforeSending ? await patchMessageBeforeSending(message, []) : message;
477
+ const bytes = (0, Utils_1.encodeNewsletterMessage)(patched);
478
+ binaryNodeContent.push({
479
+ tag: 'plaintext',
480
+ attrs: {},
481
+ content: bytes
482
+ });
483
+ const stanza = {
484
+ tag: 'message',
485
+ attrs: {
486
+ to: jid,
487
+ id: msgId,
488
+ type: getMessageType(message),
489
+ ...(additionalAttributes || {})
490
+ },
491
+ content: binaryNodeContent
492
+ };
493
+ logger.debug({ msgId }, `sending newsletter message to ${jid}`);
494
+ await sendNode(stanza);
495
+ return;
496
+ }
497
+ if ((0, Utils_1.normalizeMessageContent)(message)?.pinInChatMessage || (0, Utils_1.normalizeMessageContent)(message)?.reactionMessage) {
498
+ extraAttrs['decrypt-fail'] = 'hide'; // todo: expand for reactions and other types
499
+ }
500
+ if (isGroupOrStatus && !isRetryResend) {
501
+ const [groupData, senderKeyMap] = await Promise.all([
502
+ (async () => {
503
+ let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined; // todo: should we rely on the cache specially if the cache is outdated and the metadata has new fields?
504
+ if (groupData && Array.isArray(groupData?.participants)) {
505
+ logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
506
+ }
507
+ else if (!isStatus) {
508
+ groupData = await groupMetadata(jid); // TODO: start storing group participant list + addr mode in Signal & stop relying on this
509
+ }
510
+ return groupData;
511
+ })(),
512
+ (async () => {
513
+ if (!participant && !isStatus) {
514
+ // what if sender memory is less accurate than the cached metadata
515
+ // on participant change in group, we should do sender memory manipulation
516
+ const result = await authState.keys.get('sender-key-memory', [jid]); // TODO: check out what if the sender key memory doesn't include the LID stuff now?
517
+ return result[jid] || {};
518
+ }
519
+ return {};
520
+ })()
521
+ ]);
522
+ const participantsList = groupData ? groupData.participants.map(p => p.id) : [];
523
+ if (groupData?.ephemeralDuration && groupData.ephemeralDuration > 0) {
524
+ additionalAttributes = {
525
+ ...additionalAttributes,
526
+ expiration: groupData.ephemeralDuration.toString()
527
+ };
528
+ }
529
+ if (isStatus && statusJidList) {
530
+ participantsList.push(...statusJidList);
531
+ }
532
+ const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false);
533
+ devices.push(...additionalDevices);
534
+ if (isGroup) {
535
+ additionalAttributes = {
536
+ ...additionalAttributes,
537
+ addressing_mode: groupData?.addressingMode || 'pn'
538
+ };
539
+ }
540
+ const patched = await patchMessageBeforeSending(message);
541
+ if (Array.isArray(patched)) {
542
+ throw new boom_1.Boom('Per-jid patching is not supported in groups');
543
+ }
544
+ const bytes = (0, Utils_1.encodeWAMessage)(patched);
545
+ reportingMessage = patched;
546
+ const groupAddressingMode = additionalAttributes?.['addressing_mode'] || groupData?.addressingMode || 'pn';
547
+ // JID-first: always use meId (phone number JID), LID is resolved transparently
548
+ const groupSenderIdentity = meId;
549
+ const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
550
+ group: destinationJid,
551
+ data: bytes,
552
+ meId: groupSenderIdentity
553
+ });
554
+ const senderKeyRecipients = [];
555
+ for (const device of devices) {
556
+ const deviceJid = device.jid;
557
+ const hasKey = !!senderKeyMap[deviceJid];
558
+ if ((!hasKey || !!participant) &&
559
+ !(0, WABinary_1.isHostedLidUser)(deviceJid) &&
560
+ !(0, WABinary_1.isHostedPnUser)(deviceJid) &&
561
+ device.device !== 99) {
562
+ //todo: revamp all this logic
563
+ // the goal is to follow with what I said above for each group, and instead of a true false map of ids, we can set an array full of those the app has already sent pkmsgs
564
+ senderKeyRecipients.push(deviceJid);
565
+ senderKeyMap[deviceJid] = true;
566
+ }
567
+ }
568
+ if (senderKeyRecipients.length) {
569
+ logger.debug({ senderKeyJids: senderKeyRecipients }, 'sending new sender key');
570
+ const senderKeyMsg = {
571
+ senderKeyDistributionMessage: {
572
+ axolotlSenderKeyDistributionMessage: senderKeyDistributionMessage,
573
+ groupId: destinationJid
574
+ }
575
+ };
576
+ const senderKeySessionTargets = senderKeyRecipients;
577
+ await assertSessions(senderKeySessionTargets);
578
+ const result = await createParticipantNodes(senderKeyRecipients, senderKeyMsg, extraAttrs);
579
+ shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity;
580
+ participants.push(...result.nodes);
581
+ }
582
+ binaryNodeContent.push({
583
+ tag: 'enc',
584
+ attrs: { v: '2', type: 'skmsg', ...extraAttrs },
585
+ content: ciphertext
586
+ });
587
+ await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
588
+ }
589
+ else {
590
+ // ADDRESSING CONSISTENCY: Match own identity to conversation context
591
+ // TODO: investigate if this is true
592
+ // JID-first: always use phone number JID as own identity
593
+ let ownId = meId;
594
+ if (isLid) {
595
+ // LID conversation — resolve to JID
596
+ logger.debug({ to: jid, ownId }, 'Resolving @lid conversation to JID identity');
597
+ }
598
+ else {
599
+ logger.debug({ to: jid, ownId }, 'Using JID identity for conversation');
600
+ }
601
+ const { user: ownUser } = (0, WABinary_1.jidDecode)(ownId);
602
+ if (!participant) {
603
+ const patchedForReporting = await patchMessageBeforeSending(message, [jid]);
604
+ reportingMessage = Array.isArray(patchedForReporting)
605
+ ? patchedForReporting.find(item => item.recipientJid === jid) || patchedForReporting[0]
606
+ : patchedForReporting;
607
+ }
608
+ if (!isRetryResend) {
609
+ const targetUserServer = 's.whatsapp.net'; // JID-first: always use phone number server
610
+ devices.push({
611
+ user,
612
+ device: 0,
613
+ jid: (0, WABinary_1.jidEncode)(user, targetUserServer, 0) // rajeh, todo: this entire logic is convoluted and weird.
614
+ });
615
+ if (user !== ownUser) {
616
+ const ownUserServer = 's.whatsapp.net'; // JID-first
617
+ const ownUserForAddressing = (0, WABinary_1.jidDecode)(meId).user; // JID-first: always PN user
618
+ devices.push({
619
+ user: ownUserForAddressing,
620
+ device: 0,
621
+ jid: (0, WABinary_1.jidEncode)(ownUserForAddressing, ownUserServer, 0)
622
+ });
623
+ }
624
+ if (additionalAttributes?.['category'] !== 'peer') {
625
+ // Clear placeholders and enumerate actual devices
626
+ devices.length = 0;
627
+ // Use conversation-appropriate sender identity
628
+ // JID-first: always address as phone number JID
629
+ const senderIdentity = (0, WABinary_1.jidEncode)((0, WABinary_1.jidDecode)(meId)?.user, 's.whatsapp.net', undefined);
630
+ // Enumerate devices for sender and target with consistent addressing
631
+ const sessionDevices = await getUSyncDevices([senderIdentity, jid], true, false);
632
+ devices.push(...sessionDevices);
633
+ logger.debug({
634
+ deviceCount: devices.length,
635
+ devices: devices.map(d => `${d.user}:${d.device}@${(0, WABinary_1.jidDecode)(d.jid)?.server}`)
636
+ }, 'Device enumeration complete with unified addressing');
637
+ }
638
+ }
639
+ const allRecipients = [];
640
+ const meRecipients = [];
641
+ const otherRecipients = [];
642
+ const { user: mePnUser } = (0, WABinary_1.jidDecode)(meId);
643
+ // meLidUser removed — JID-first
644
+ for (const { user, jid } of devices) {
645
+ const isExactSenderDevice = jid === meId;
646
+ if (isExactSenderDevice) {
647
+ logger.debug({ jid, meId }, 'Skipping exact sender device (whatsmeow pattern)');
648
+ continue;
649
+ }
650
+ // Check if this is our device (could match either PN or LID user)
651
+ const isMe = user === mePnUser; // JID-first: only match phone number user
652
+ if (isMe) {
653
+ meRecipients.push(jid);
654
+ }
655
+ else {
656
+ otherRecipients.push(jid);
657
+ }
658
+ allRecipients.push(jid);
659
+ }
660
+ await assertSessions(allRecipients);
661
+ const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
662
+ // For own devices: use DSM if available (1:1 chats only)
663
+ createParticipantNodes(meRecipients, meMsg || message, extraAttrs),
664
+ createParticipantNodes(otherRecipients, message, extraAttrs, meMsg)
665
+ ]);
666
+ participants.push(...meNodes);
667
+ participants.push(...otherNodes);
668
+ if (meRecipients.length > 0 || otherRecipients.length > 0) {
669
+ extraAttrs['phash'] = (0, Utils_1.generateParticipantHashV2)([...meRecipients, ...otherRecipients]);
670
+ }
671
+ shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
672
+ }
673
+ if (isRetryResend) {
674
+ // JID-first: isLidUser check kept for server compat, but always compare with meId
675
+ const _isParticipantLid = (0, WABinary_1.isLidUser)(participant.jid);
676
+ const isMe = (0, WABinary_1.areJidsSameUser)(participant.jid, meId);
677
+ const encodedMessageToSend = isMe
678
+ ? (0, Utils_1.encodeWAMessage)({
679
+ deviceSentMessage: {
680
+ destinationJid,
681
+ message
682
+ }
683
+ })
684
+ : (0, Utils_1.encodeWAMessage)(message);
685
+ const { type, ciphertext: encryptedContent } = await signalRepository.encryptMessage({
686
+ data: encodedMessageToSend,
687
+ jid: participant.jid
688
+ });
689
+ binaryNodeContent.push({
690
+ tag: 'enc',
691
+ attrs: {
692
+ v: '2',
693
+ type,
694
+ count: participant.count.toString()
695
+ },
696
+ content: encryptedContent
697
+ });
698
+ }
699
+ if (participants.length) {
700
+ if (additionalAttributes?.['category'] === 'peer') {
701
+ const peerNode = participants[0]?.content?.[0];
702
+ if (peerNode) {
703
+ binaryNodeContent.push(peerNode); // push only enc
704
+ }
705
+ }
706
+ else {
707
+ binaryNodeContent.push({
708
+ tag: 'participants',
709
+ attrs: {},
710
+ content: participants
711
+ });
712
+ }
713
+ }
714
+ const stanza = {
715
+ tag: 'message',
716
+ attrs: {
717
+ id: msgId,
718
+ to: destinationJid,
719
+ type: getMessageType(message),
720
+ ...(additionalAttributes || {})
721
+ },
722
+ content: binaryNodeContent
723
+ };
724
+ // if the participant to send to is explicitly specified (generally retry recp)
725
+ // ensure the message is only sent to that person
726
+ // if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
727
+ if (participant) {
728
+ if ((0, WABinary_1.isJidGroup)(destinationJid)) {
729
+ stanza.attrs.to = destinationJid;
730
+ stanza.attrs.participant = participant.jid;
731
+ }
732
+ else if ((0, WABinary_1.areJidsSameUser)(participant.jid, meId)) {
733
+ stanza.attrs.to = participant.jid;
734
+ stanza.attrs.recipient = destinationJid;
735
+ }
736
+ else {
737
+ stanza.attrs.to = participant.jid;
738
+ }
739
+ }
740
+ else {
741
+ stanza.attrs.to = destinationJid;
742
+ }
743
+ if (shouldIncludeDeviceIdentity) {
744
+ ;
745
+ stanza.content.push({
746
+ tag: 'device-identity',
747
+ attrs: {},
748
+ content: (0, Utils_1.encodeSignedDeviceIdentity)(authState.creds.account, true)
749
+ });
750
+ logger.debug({ jid }, 'adding device identity');
751
+ }
752
+ if (!isNewsletter &&
753
+ !isRetryResend &&
754
+ reportingMessage?.messageContextInfo?.messageSecret &&
755
+ (0, reporting_utils_1.shouldIncludeReportingToken)(reportingMessage)) {
756
+ try {
757
+ const encoded = (0, Utils_1.encodeWAMessage)(reportingMessage);
758
+ const reportingKey = {
759
+ id: msgId,
760
+ fromMe: true,
761
+ remoteJid: destinationJid,
762
+ participant: participant?.jid
763
+ };
764
+ const reportingNode = await (0, reporting_utils_1.getMessageReportingToken)(encoded, reportingMessage, reportingKey);
765
+ if (reportingNode) {
766
+ ;
767
+ stanza.content.push(reportingNode);
768
+ logger.trace({ jid }, 'added reporting token to message');
769
+ }
770
+ }
771
+ catch (error) {
772
+ logger.warn({ jid, trace: error?.stack }, 'failed to attach reporting token');
773
+ }
774
+ }
775
+ const contactTcTokenData = !isGroup && !isRetryResend && !isStatus ? await authState.keys.get('tctoken', [destinationJid]) : {};
776
+ const tcTokenBuffer = contactTcTokenData[destinationJid]?.token;
777
+ if (tcTokenBuffer) {
778
+ ;
779
+ stanza.content.push({
780
+ tag: 'tctoken',
781
+ attrs: {},
782
+ content: tcTokenBuffer
783
+ });
784
+ }
785
+ if (additionalNodes && additionalNodes.length > 0) {
786
+ ;
787
+ stanza.content.push(...additionalNodes);
788
+ }
789
+ logger.debug({ msgId }, `sending message to ${participants.length} devices`);
790
+ await sendNode(stanza);
791
+ // Add message to retry cache if enabled
792
+ if (messageRetryManager && !participant) {
793
+ messageRetryManager.addRecentMessage(destinationJid, msgId, message);
794
+ }
795
+ }, meId);
796
+ return msgId;
797
+ };
798
+ const getMessageType = (message) => {
799
+ const normalizedMessage = (0, Utils_1.normalizeMessageContent)(message);
800
+ if (!normalizedMessage)
801
+ return 'text';
802
+ if (normalizedMessage.reactionMessage || normalizedMessage.encReactionMessage) {
803
+ return 'reaction';
804
+ }
805
+ if (normalizedMessage.pollCreationMessage ||
806
+ normalizedMessage.pollCreationMessageV2 ||
807
+ normalizedMessage.pollCreationMessageV3 ||
808
+ normalizedMessage.pollUpdateMessage) {
809
+ return 'poll';
810
+ }
811
+ if (normalizedMessage.eventMessage) {
812
+ return 'event';
813
+ }
814
+ if (getMediaType(normalizedMessage) !== '') {
815
+ return 'media';
816
+ }
817
+ return 'text';
818
+ };
819
+ const getMediaType = (message) => {
820
+ if (message.imageMessage) {
821
+ return 'image';
822
+ }
823
+ else if (message.videoMessage) {
824
+ return message.videoMessage.gifPlayback ? 'gif' : 'video';
825
+ }
826
+ else if (message.audioMessage) {
827
+ return message.audioMessage.ptt ? 'ptt' : 'audio';
828
+ }
829
+ else if (message.contactMessage) {
830
+ return 'vcard';
831
+ }
832
+ else if (message.documentMessage) {
833
+ return 'document';
834
+ }
835
+ else if (message.contactsArrayMessage) {
836
+ return 'contact_array';
837
+ }
838
+ else if (message.liveLocationMessage) {
839
+ return 'livelocation';
840
+ }
841
+ else if (message.stickerMessage) {
842
+ return 'sticker';
843
+ }
844
+ else if (message.listMessage) {
845
+ return 'list';
846
+ }
847
+ else if (message.listResponseMessage) {
848
+ return 'list_response';
849
+ }
850
+ else if (message.buttonsResponseMessage) {
851
+ return 'buttons_response';
852
+ }
853
+ else if (message.orderMessage) {
854
+ return 'order';
855
+ }
856
+ else if (message.productMessage) {
857
+ return 'product';
858
+ }
859
+ else if (message.interactiveResponseMessage) {
860
+ return 'native_flow_response';
861
+ }
862
+ else if (message.groupInviteMessage) {
863
+ return 'url';
864
+ }
865
+ return '';
866
+ };
867
+ const getPrivacyTokens = async (jids) => {
868
+ const t = (0, Utils_1.unixTimestampSeconds)().toString();
869
+ const result = await query({
870
+ tag: 'iq',
871
+ attrs: {
872
+ to: WABinary_1.S_WHATSAPP_NET,
873
+ type: 'set',
874
+ xmlns: 'privacy'
875
+ },
876
+ content: [
877
+ {
878
+ tag: 'tokens',
879
+ attrs: {},
880
+ content: jids.map(jid => ({
881
+ tag: 'token',
882
+ attrs: {
883
+ jid: (0, WABinary_1.jidNormalizedUser)(jid),
884
+ t,
885
+ type: 'trusted_contact'
886
+ }
887
+ }))
888
+ }
889
+ ]
890
+ });
891
+ return result;
892
+ };
893
+ const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
894
+ const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
895
+ return {
896
+ ...sock,
897
+ getPrivacyTokens,
898
+ assertSessions,
899
+ relayMessage,
900
+ sendReceipt,
901
+ sendReceipts,
902
+ readMessages,
903
+ refreshMediaConn,
904
+ waUploadToServer,
905
+ fetchPrivacySettings,
906
+ sendPeerDataOperationMessage,
907
+ createParticipantNodes,
908
+ getUSyncDevices,
909
+ messageRetryManager,
910
+ updateMemberLabel,
911
+ updateMediaMessage: async (message) => {
912
+ const content = (0, Utils_1.assertMediaContent)(message.message);
913
+ const mediaKey = content.mediaKey;
914
+ const meId = authState.creds.me.id;
915
+ const node = (0, Utils_1.encryptMediaRetryRequest)(message.key, mediaKey, meId);
916
+ let error = undefined;
917
+ await Promise.all([
918
+ sendNode(node),
919
+ waitForMsgMediaUpdate(async (update) => {
920
+ const result = update.find(c => c.key.id === message.key.id);
921
+ if (result) {
922
+ if (result.error) {
923
+ error = result.error;
924
+ }
925
+ else {
926
+ try {
927
+ const media = (0, Utils_1.decryptMediaRetryData)(result.media, mediaKey, result.key.id);
928
+ if (media.result !== index_js_1.proto.MediaRetryNotification.ResultType.SUCCESS) {
929
+ const resultStr = index_js_1.proto.MediaRetryNotification.ResultType[media.result];
930
+ throw new boom_1.Boom(`Media re-upload failed by device (${resultStr})`, {
931
+ data: media,
932
+ statusCode: (0, Utils_1.getStatusCodeForMediaRetry)(media.result) || 404
933
+ });
934
+ }
935
+ content.directPath = media.directPath;
936
+ content.url = (0, Utils_1.getUrlFromDirectPath)(content.directPath);
937
+ logger.debug({ directPath: media.directPath, key: result.key }, 'media update successful');
938
+ }
939
+ catch (err) {
940
+ error = err;
941
+ }
942
+ }
943
+ return true;
944
+ }
945
+ })
946
+ ]);
947
+ if (error) {
948
+ throw error;
949
+ }
950
+ ev.emit('messages.update', [{ key: message.key, update: { message: message.message } }]);
951
+ return message;
952
+ },
953
+ sendMessage: async (jid, content, options = {}) => {
954
+ const userJid = authState.creds.me.id;
955
+ if (typeof content === 'object' &&
956
+ 'disappearingMessagesInChat' in content &&
957
+ typeof content['disappearingMessagesInChat'] !== 'undefined' &&
958
+ (0, WABinary_1.isJidGroup)(jid)) {
959
+ const { disappearingMessagesInChat } = content;
960
+ const value = typeof disappearingMessagesInChat === 'boolean'
961
+ ? disappearingMessagesInChat
962
+ ? Defaults_1.WA_DEFAULT_EPHEMERAL
963
+ : 0
964
+ : disappearingMessagesInChat;
965
+ await groupToggleEphemeral(jid, value);
966
+ }
967
+ else {
968
+ const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
969
+ logger,
970
+ userJid,
971
+ getUrlInfo: text => (0, link_preview_1.getUrlInfo)(text, {
972
+ thumbnailWidth: linkPreviewImageThumbnailWidth,
973
+ fetchOpts: {
974
+ timeout: 3000,
975
+ ...(httpRequestOptions || {})
976
+ },
977
+ logger,
978
+ uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
979
+ }),
980
+ //TODO: CACHE
981
+ getProfilePicUrl: sock.profilePictureUrl,
982
+ getCallLink: sock.createCallLink,
983
+ upload: waUploadToServer,
984
+ mediaCache: config.mediaCache,
985
+ options: config.options,
986
+ messageId: (0, Utils_1.generateMessageIDV2)(sock.user?.id),
987
+ ...options
988
+ });
989
+ const isEventMsg = 'event' in content && !!content.event;
990
+ const isDeleteMsg = 'delete' in content && !!content.delete;
991
+ const isEditMsg = 'edit' in content && !!content.edit;
992
+ const isPinMsg = 'pin' in content && !!content.pin;
993
+ const isPollMessage = 'poll' in content && !!content.poll;
994
+ const additionalAttributes = {};
995
+ const additionalNodes = [];
996
+ // required for delete
997
+ if (isDeleteMsg) {
998
+ // if the chat is a group, and I am not the author, then delete the message as an admin
999
+ if ((0, WABinary_1.isJidGroup)(content.delete?.remoteJid) && !content.delete?.fromMe) {
1000
+ additionalAttributes.edit = '8';
1001
+ }
1002
+ else {
1003
+ additionalAttributes.edit = '7';
1004
+ }
1005
+ }
1006
+ else if (isEditMsg) {
1007
+ additionalAttributes.edit = '1';
1008
+ }
1009
+ else if (isPinMsg) {
1010
+ additionalAttributes.edit = '2';
1011
+ }
1012
+ else if (isPollMessage) {
1013
+ additionalNodes.push({
1014
+ tag: 'meta',
1015
+ attrs: {
1016
+ polltype: 'creation'
1017
+ }
1018
+ });
1019
+ }
1020
+ else if (isEventMsg) {
1021
+ additionalNodes.push({
1022
+ tag: 'meta',
1023
+ attrs: {
1024
+ event_type: 'creation'
1025
+ }
1026
+ });
1027
+ }
1028
+ await relayMessage(jid, fullMsg.message, {
1029
+ messageId: fullMsg.key.id,
1030
+ useCachedGroupMetadata: options.useCachedGroupMetadata,
1031
+ additionalAttributes,
1032
+ statusJidList: options.statusJidList,
1033
+ additionalNodes
1034
+ });
1035
+ if (config.emitOwnEvents) {
1036
+ process.nextTick(async () => {
1037
+ await messageMutex.mutex(() => upsertMessage(fullMsg, 'append'));
1038
+ });
1039
+ }
1040
+ return fullMsg;
1041
+ }
1042
+ }
1043
+ };
1044
+ };
1045
+ exports.makeMessagesSocket = makeMessagesSocket;
1046
+ //# sourceMappingURL=messages-send.js.map