@d0v3riz/baileys 6.7.21 → 6.7.22

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 (356) hide show
  1. package/WAProto/GenerateStatics.sh +2 -3
  2. package/WAProto/index.js +4138 -4136
  3. package/lib/Defaults/index.d.ts +2 -3
  4. package/lib/Defaults/index.js +40 -36
  5. package/lib/Signal/Group/ciphertext-message.d.ts +0 -1
  6. package/lib/Signal/Group/ciphertext-message.js +5 -2
  7. package/lib/Signal/Group/group-session-builder.d.ts +3 -4
  8. package/lib/Signal/Group/group-session-builder.js +41 -7
  9. package/lib/Signal/Group/group_cipher.d.ts +2 -3
  10. package/lib/Signal/Group/group_cipher.js +16 -14
  11. package/lib/Signal/Group/index.d.ts +11 -12
  12. package/lib/Signal/Group/index.js +57 -12
  13. package/lib/Signal/Group/keyhelper.d.ts +1 -2
  14. package/lib/Signal/Group/keyhelper.js +44 -8
  15. package/lib/Signal/Group/queue-job.d.ts +0 -2
  16. package/lib/Signal/Group/queue-job.js +5 -5
  17. package/lib/Signal/Group/sender-chain-key.d.ts +1 -2
  18. package/lib/Signal/Group/sender-chain-key.js +9 -7
  19. package/lib/Signal/Group/sender-key-distribution-message.d.ts +1 -2
  20. package/lib/Signal/Group/sender-key-distribution-message.js +9 -6
  21. package/lib/Signal/Group/sender-key-message.d.ts +1 -2
  22. package/lib/Signal/Group/sender-key-message.js +12 -10
  23. package/lib/Signal/Group/sender-key-name.d.ts +0 -1
  24. package/lib/Signal/Group/sender-key-name.js +5 -2
  25. package/lib/Signal/Group/sender-key-record.d.ts +1 -2
  26. package/lib/Signal/Group/sender-key-record.js +12 -9
  27. package/lib/Signal/Group/sender-key-state.d.ts +2 -3
  28. package/lib/Signal/Group/sender-key-state.js +9 -6
  29. package/lib/Signal/Group/sender-message-key.d.ts +0 -1
  30. package/lib/Signal/Group/sender-message-key.js +7 -5
  31. package/lib/Signal/libsignal.d.ts +2 -3
  32. package/lib/Signal/libsignal.js +55 -22
  33. package/lib/Socket/Client/index.d.ts +2 -3
  34. package/lib/Socket/Client/index.js +18 -3
  35. package/lib/Socket/Client/types.d.ts +1 -2
  36. package/lib/Socket/Client/types.js +6 -4
  37. package/lib/Socket/Client/websocket.d.ts +1 -2
  38. package/lib/Socket/Client/websocket.js +26 -14
  39. package/lib/Socket/business.d.ts +64 -66
  40. package/lib/Socket/business.js +37 -32
  41. package/lib/Socket/chats.d.ts +19 -21
  42. package/lib/Socket/chats.js +141 -176
  43. package/lib/Socket/groups.d.ts +35 -37
  44. package/lib/Socket/groups.js +63 -56
  45. package/lib/Socket/index.d.ts +70 -102
  46. package/lib/Socket/index.js +9 -16
  47. package/lib/Socket/messages-recv.d.ts +49 -51
  48. package/lib/Socket/messages-recv.js +173 -180
  49. package/lib/Socket/messages-send.d.ts +46 -48
  50. package/lib/Socket/messages-send.js +84 -75
  51. package/lib/Socket/mex.d.ts +1 -2
  52. package/lib/Socket/mex.js +16 -12
  53. package/lib/Socket/newsletter.d.ts +44 -46
  54. package/lib/Socket/newsletter.js +27 -23
  55. package/lib/Socket/socket.d.ts +12 -13
  56. package/lib/Socket/socket.js +115 -135
  57. package/lib/Socket/usync.d.ts +14 -15
  58. package/lib/Socket/usync.js +11 -9
  59. package/lib/Types/Auth.d.ts +3 -4
  60. package/lib/Types/Auth.js +2 -2
  61. package/lib/Types/Call.d.ts +0 -1
  62. package/lib/Types/Call.js +2 -2
  63. package/lib/Types/Chat.d.ts +7 -10
  64. package/lib/Types/Chat.js +4 -2
  65. package/lib/Types/Contact.d.ts +0 -1
  66. package/lib/Types/Contact.js +2 -2
  67. package/lib/Types/Events.d.ts +10 -11
  68. package/lib/Types/Events.js +2 -2
  69. package/lib/Types/GroupMetadata.d.ts +2 -3
  70. package/lib/Types/GroupMetadata.js +2 -2
  71. package/lib/Types/Label.d.ts +0 -1
  72. package/lib/Types/Label.js +5 -3
  73. package/lib/Types/LabelAssociation.d.ts +0 -1
  74. package/lib/Types/LabelAssociation.js +5 -3
  75. package/lib/Types/Message.d.ts +7 -9
  76. package/lib/Types/Message.js +7 -7
  77. package/lib/Types/Newsletter.d.ts +0 -1
  78. package/lib/Types/Newsletter.js +7 -5
  79. package/lib/Types/Product.d.ts +1 -2
  80. package/lib/Types/Product.js +2 -2
  81. package/lib/Types/Signal.d.ts +1 -2
  82. package/lib/Types/Signal.js +2 -2
  83. package/lib/Types/Socket.d.ts +7 -8
  84. package/lib/Types/Socket.js +2 -3
  85. package/lib/Types/State.d.ts +2 -14
  86. package/lib/Types/State.js +2 -13
  87. package/lib/Types/USync.d.ts +2 -3
  88. package/lib/Types/USync.js +2 -2
  89. package/lib/Types/index.d.ts +14 -15
  90. package/lib/Types/index.js +31 -15
  91. package/lib/Utils/auth-utils.d.ts +2 -3
  92. package/lib/Utils/auth-utils.js +34 -25
  93. package/lib/Utils/baileys-event-stream.d.ts +1 -2
  94. package/lib/Utils/baileys-event-stream.js +22 -15
  95. package/lib/Utils/business.d.ts +2 -3
  96. package/lib/Utils/business.js +70 -61
  97. package/lib/Utils/chat-utils.d.ts +7 -8
  98. package/lib/Utils/chat-utils.js +137 -130
  99. package/lib/Utils/crypto.d.ts +1 -2
  100. package/lib/Utils/crypto.js +86 -37
  101. package/lib/Utils/decode-wa-message.d.ts +4 -5
  102. package/lib/Utils/decode-wa-message.js +44 -38
  103. package/lib/Utils/event-buffer.d.ts +4 -4
  104. package/lib/Utils/event-buffer.js +50 -37
  105. package/lib/Utils/generics.d.ts +8 -9
  106. package/lib/Utils/generics.js +114 -87
  107. package/lib/Utils/history.d.ts +3 -4
  108. package/lib/Utils/history.js +40 -32
  109. package/lib/Utils/index.d.ts +17 -18
  110. package/lib/Utils/index.js +33 -18
  111. package/lib/Utils/link-preview.d.ts +3 -4
  112. package/lib/Utils/link-preview.js +47 -10
  113. package/lib/Utils/logger.d.ts +6 -8
  114. package/lib/Utils/logger.js +7 -3
  115. package/lib/Utils/lt-hash.d.ts +8 -9
  116. package/lib/Utils/lt-hash.js +26 -23
  117. package/lib/Utils/make-mutex.d.ts +0 -1
  118. package/lib/Utils/make-mutex.js +9 -5
  119. package/lib/Utils/messages-media.d.ts +10 -11
  120. package/lib/Utils/messages-media.js +203 -141
  121. package/lib/Utils/messages.d.ts +6 -7
  122. package/lib/Utils/messages.js +199 -190
  123. package/lib/Utils/noise-handler.d.ts +4 -5
  124. package/lib/Utils/noise-handler.js +26 -22
  125. package/lib/Utils/process-message.d.ts +4 -5
  126. package/lib/Utils/process-message.js +104 -95
  127. package/lib/Utils/signal.d.ts +4 -5
  128. package/lib/Utils/signal.js +52 -47
  129. package/lib/Utils/use-multi-file-auth-state.d.ts +1 -2
  130. package/lib/Utils/use-multi-file-auth-state.js +26 -23
  131. package/lib/Utils/validate-connection.d.ts +3 -4
  132. package/lib/Utils/validate-connection.js +58 -52
  133. package/lib/WABinary/constants.d.ts +0 -1
  134. package/lib/WABinary/constants.js +11 -9
  135. package/lib/WABinary/decode.d.ts +1 -2
  136. package/lib/WABinary/decode.js +51 -13
  137. package/lib/WABinary/encode.d.ts +1 -2
  138. package/lib/WABinary/encode.js +41 -5
  139. package/lib/WABinary/generic-utils.d.ts +3 -4
  140. package/lib/WABinary/generic-utils.js +38 -30
  141. package/lib/WABinary/index.d.ts +5 -6
  142. package/lib/WABinary/index.js +21 -6
  143. package/lib/WABinary/jid-utils.d.ts +0 -1
  144. package/lib/WABinary/jid-utils.js +35 -21
  145. package/lib/WABinary/types.d.ts +1 -2
  146. package/lib/WABinary/types.js +2 -2
  147. package/lib/WAM/BinaryInfo.d.ts +1 -2
  148. package/lib/WAM/BinaryInfo.js +5 -2
  149. package/lib/WAM/constants.d.ts +0 -1
  150. package/lib/WAM/constants.js +6 -4
  151. package/lib/WAM/encode.d.ts +1 -2
  152. package/lib/WAM/encode.js +14 -12
  153. package/lib/WAM/index.d.ts +3 -4
  154. package/lib/WAM/index.js +19 -4
  155. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +3 -4
  156. package/lib/WAUSync/Protocols/USyncContactProtocol.js +9 -6
  157. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -3
  158. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +12 -9
  159. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -3
  160. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -6
  161. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -3
  162. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +11 -7
  163. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +3 -4
  164. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +21 -19
  165. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +2 -3
  166. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +5 -2
  167. package/lib/WAUSync/Protocols/index.d.ts +4 -5
  168. package/lib/WAUSync/Protocols/index.js +20 -5
  169. package/lib/WAUSync/USyncQuery.d.ts +3 -4
  170. package/lib/WAUSync/USyncQuery.js +20 -18
  171. package/lib/WAUSync/USyncUser.d.ts +5 -6
  172. package/lib/WAUSync/USyncUser.js +5 -2
  173. package/lib/WAUSync/index.d.ts +3 -4
  174. package/lib/WAUSync/index.js +19 -4
  175. package/lib/index.d.ts +8 -9
  176. package/lib/index.js +30 -11
  177. package/package.json +26 -26
  178. package/WAProto/fix-imports.js +0 -29
  179. package/lib/Defaults/index.d.ts.map +0 -1
  180. package/lib/Defaults/index.js.map +0 -1
  181. package/lib/Signal/Group/ciphertext-message.d.ts.map +0 -1
  182. package/lib/Signal/Group/ciphertext-message.js.map +0 -1
  183. package/lib/Signal/Group/group-session-builder.d.ts.map +0 -1
  184. package/lib/Signal/Group/group-session-builder.js.map +0 -1
  185. package/lib/Signal/Group/group_cipher.d.ts.map +0 -1
  186. package/lib/Signal/Group/group_cipher.js.map +0 -1
  187. package/lib/Signal/Group/index.d.ts.map +0 -1
  188. package/lib/Signal/Group/index.js.map +0 -1
  189. package/lib/Signal/Group/keyhelper.d.ts.map +0 -1
  190. package/lib/Signal/Group/keyhelper.js.map +0 -1
  191. package/lib/Signal/Group/queue-job.d.ts.map +0 -1
  192. package/lib/Signal/Group/queue-job.js.map +0 -1
  193. package/lib/Signal/Group/sender-chain-key.d.ts.map +0 -1
  194. package/lib/Signal/Group/sender-chain-key.js.map +0 -1
  195. package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +0 -1
  196. package/lib/Signal/Group/sender-key-distribution-message.js.map +0 -1
  197. package/lib/Signal/Group/sender-key-message.d.ts.map +0 -1
  198. package/lib/Signal/Group/sender-key-message.js.map +0 -1
  199. package/lib/Signal/Group/sender-key-name.d.ts.map +0 -1
  200. package/lib/Signal/Group/sender-key-name.js.map +0 -1
  201. package/lib/Signal/Group/sender-key-record.d.ts.map +0 -1
  202. package/lib/Signal/Group/sender-key-record.js.map +0 -1
  203. package/lib/Signal/Group/sender-key-state.d.ts.map +0 -1
  204. package/lib/Signal/Group/sender-key-state.js.map +0 -1
  205. package/lib/Signal/Group/sender-message-key.d.ts.map +0 -1
  206. package/lib/Signal/Group/sender-message-key.js.map +0 -1
  207. package/lib/Signal/libsignal.d.ts.map +0 -1
  208. package/lib/Signal/libsignal.js.map +0 -1
  209. package/lib/Socket/Client/index.d.ts.map +0 -1
  210. package/lib/Socket/Client/index.js.map +0 -1
  211. package/lib/Socket/Client/types.d.ts.map +0 -1
  212. package/lib/Socket/Client/types.js.map +0 -1
  213. package/lib/Socket/Client/websocket.d.ts.map +0 -1
  214. package/lib/Socket/Client/websocket.js.map +0 -1
  215. package/lib/Socket/business.d.ts.map +0 -1
  216. package/lib/Socket/business.js.map +0 -1
  217. package/lib/Socket/chats.d.ts.map +0 -1
  218. package/lib/Socket/chats.js.map +0 -1
  219. package/lib/Socket/communities.d.ts +0 -219
  220. package/lib/Socket/communities.d.ts.map +0 -1
  221. package/lib/Socket/communities.js +0 -351
  222. package/lib/Socket/communities.js.map +0 -1
  223. package/lib/Socket/groups.d.ts.map +0 -1
  224. package/lib/Socket/groups.js.map +0 -1
  225. package/lib/Socket/index.d.ts.map +0 -1
  226. package/lib/Socket/index.js.map +0 -1
  227. package/lib/Socket/messages-recv.d.ts.map +0 -1
  228. package/lib/Socket/messages-recv.js.map +0 -1
  229. package/lib/Socket/messages-send.d.ts.map +0 -1
  230. package/lib/Socket/messages-send.js.map +0 -1
  231. package/lib/Socket/mex.d.ts.map +0 -1
  232. package/lib/Socket/mex.js.map +0 -1
  233. package/lib/Socket/newsletter.d.ts.map +0 -1
  234. package/lib/Socket/newsletter.js.map +0 -1
  235. package/lib/Socket/socket.d.ts.map +0 -1
  236. package/lib/Socket/socket.js.map +0 -1
  237. package/lib/Socket/usync.d.ts.map +0 -1
  238. package/lib/Socket/usync.js.map +0 -1
  239. package/lib/Types/Auth.d.ts.map +0 -1
  240. package/lib/Types/Auth.js.map +0 -1
  241. package/lib/Types/Call.d.ts.map +0 -1
  242. package/lib/Types/Call.js.map +0 -1
  243. package/lib/Types/Chat.d.ts.map +0 -1
  244. package/lib/Types/Chat.js.map +0 -1
  245. package/lib/Types/Contact.d.ts.map +0 -1
  246. package/lib/Types/Contact.js.map +0 -1
  247. package/lib/Types/Events.d.ts.map +0 -1
  248. package/lib/Types/Events.js.map +0 -1
  249. package/lib/Types/GroupMetadata.d.ts.map +0 -1
  250. package/lib/Types/GroupMetadata.js.map +0 -1
  251. package/lib/Types/Label.d.ts.map +0 -1
  252. package/lib/Types/Label.js.map +0 -1
  253. package/lib/Types/LabelAssociation.d.ts.map +0 -1
  254. package/lib/Types/LabelAssociation.js.map +0 -1
  255. package/lib/Types/Message.d.ts.map +0 -1
  256. package/lib/Types/Message.js.map +0 -1
  257. package/lib/Types/Newsletter.d.ts.map +0 -1
  258. package/lib/Types/Newsletter.js.map +0 -1
  259. package/lib/Types/Product.d.ts.map +0 -1
  260. package/lib/Types/Product.js.map +0 -1
  261. package/lib/Types/Signal.d.ts.map +0 -1
  262. package/lib/Types/Signal.js.map +0 -1
  263. package/lib/Types/Socket.d.ts.map +0 -1
  264. package/lib/Types/Socket.js.map +0 -1
  265. package/lib/Types/State.d.ts.map +0 -1
  266. package/lib/Types/State.js.map +0 -1
  267. package/lib/Types/USync.d.ts.map +0 -1
  268. package/lib/Types/USync.js.map +0 -1
  269. package/lib/Types/index.d.ts.map +0 -1
  270. package/lib/Types/index.js.map +0 -1
  271. package/lib/Utils/auth-utils.d.ts.map +0 -1
  272. package/lib/Utils/auth-utils.js.map +0 -1
  273. package/lib/Utils/baileys-event-stream.d.ts.map +0 -1
  274. package/lib/Utils/baileys-event-stream.js.map +0 -1
  275. package/lib/Utils/business.d.ts.map +0 -1
  276. package/lib/Utils/business.js.map +0 -1
  277. package/lib/Utils/chat-utils.d.ts.map +0 -1
  278. package/lib/Utils/chat-utils.js.map +0 -1
  279. package/lib/Utils/crypto.d.ts.map +0 -1
  280. package/lib/Utils/crypto.js.map +0 -1
  281. package/lib/Utils/decode-wa-message.d.ts.map +0 -1
  282. package/lib/Utils/decode-wa-message.js.map +0 -1
  283. package/lib/Utils/event-buffer.d.ts.map +0 -1
  284. package/lib/Utils/event-buffer.js.map +0 -1
  285. package/lib/Utils/generics.d.ts.map +0 -1
  286. package/lib/Utils/generics.js.map +0 -1
  287. package/lib/Utils/history.d.ts.map +0 -1
  288. package/lib/Utils/history.js.map +0 -1
  289. package/lib/Utils/index.d.ts.map +0 -1
  290. package/lib/Utils/index.js.map +0 -1
  291. package/lib/Utils/link-preview.d.ts.map +0 -1
  292. package/lib/Utils/link-preview.js.map +0 -1
  293. package/lib/Utils/logger.d.ts.map +0 -1
  294. package/lib/Utils/logger.js.map +0 -1
  295. package/lib/Utils/lt-hash.d.ts.map +0 -1
  296. package/lib/Utils/lt-hash.js.map +0 -1
  297. package/lib/Utils/make-mutex.d.ts.map +0 -1
  298. package/lib/Utils/make-mutex.js.map +0 -1
  299. package/lib/Utils/messages-media.d.ts.map +0 -1
  300. package/lib/Utils/messages-media.js.map +0 -1
  301. package/lib/Utils/messages.d.ts.map +0 -1
  302. package/lib/Utils/messages.js.map +0 -1
  303. package/lib/Utils/noise-handler.d.ts.map +0 -1
  304. package/lib/Utils/noise-handler.js.map +0 -1
  305. package/lib/Utils/process-message.d.ts.map +0 -1
  306. package/lib/Utils/process-message.js.map +0 -1
  307. package/lib/Utils/signal.d.ts.map +0 -1
  308. package/lib/Utils/signal.js.map +0 -1
  309. package/lib/Utils/use-multi-file-auth-state.d.ts.map +0 -1
  310. package/lib/Utils/use-multi-file-auth-state.js.map +0 -1
  311. package/lib/Utils/validate-connection.d.ts.map +0 -1
  312. package/lib/Utils/validate-connection.js.map +0 -1
  313. package/lib/WABinary/constants.d.ts.map +0 -1
  314. package/lib/WABinary/constants.js.map +0 -1
  315. package/lib/WABinary/decode.d.ts.map +0 -1
  316. package/lib/WABinary/decode.js.map +0 -1
  317. package/lib/WABinary/encode.d.ts.map +0 -1
  318. package/lib/WABinary/encode.js.map +0 -1
  319. package/lib/WABinary/generic-utils.d.ts.map +0 -1
  320. package/lib/WABinary/generic-utils.js.map +0 -1
  321. package/lib/WABinary/index.d.ts.map +0 -1
  322. package/lib/WABinary/index.js.map +0 -1
  323. package/lib/WABinary/jid-utils.d.ts.map +0 -1
  324. package/lib/WABinary/jid-utils.js.map +0 -1
  325. package/lib/WABinary/types.d.ts.map +0 -1
  326. package/lib/WABinary/types.js.map +0 -1
  327. package/lib/WAM/BinaryInfo.d.ts.map +0 -1
  328. package/lib/WAM/BinaryInfo.js.map +0 -1
  329. package/lib/WAM/constants.d.ts.map +0 -1
  330. package/lib/WAM/constants.js.map +0 -1
  331. package/lib/WAM/encode.d.ts.map +0 -1
  332. package/lib/WAM/encode.js.map +0 -1
  333. package/lib/WAM/index.d.ts.map +0 -1
  334. package/lib/WAM/index.js.map +0 -1
  335. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +0 -1
  336. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +0 -1
  337. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +0 -1
  338. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +0 -1
  339. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +0 -1
  340. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +0 -1
  341. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +0 -1
  342. package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +0 -1
  343. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +0 -1
  344. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +0 -1
  345. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +0 -1
  346. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +0 -1
  347. package/lib/WAUSync/Protocols/index.d.ts.map +0 -1
  348. package/lib/WAUSync/Protocols/index.js.map +0 -1
  349. package/lib/WAUSync/USyncQuery.d.ts.map +0 -1
  350. package/lib/WAUSync/USyncQuery.js.map +0 -1
  351. package/lib/WAUSync/USyncUser.d.ts.map +0 -1
  352. package/lib/WAUSync/USyncUser.js.map +0 -1
  353. package/lib/WAUSync/index.d.ts.map +0 -1
  354. package/lib/WAUSync/index.js.map +0 -1
  355. package/lib/index.d.ts.map +0 -1
  356. package/lib/index.js.map +0 -1
@@ -1,20 +1,26 @@
1
- import NodeCache from '@cacheable/node-cache';
2
- import { Boom } from '@hapi/boom';
3
- import { proto } from '../../WAProto/index.js';
4
- import { DEFAULT_CACHE_TTLS, WA_DEFAULT_EPHEMERAL } from '../Defaults/index.js';
5
- import { aggregateMessageKeysNotFromMe, assertMediaContent, bindWaitForEvent, decryptMediaRetryData, encodeNewsletterMessage, encodeSignedDeviceIdentity, encodeWAMessage, encryptMediaRetryRequest, extractDeviceJids, generateMessageIDV2, generateWAMessage, getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, normalizeMessageContent, parseAndInjectE2ESessions, unixTimestampSeconds } from '../Utils/index.js';
6
- import { getUrlInfo } from '../Utils/link-preview.js';
7
- import { areJidsSameUser, getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, isJidUser, jidDecode, jidEncode, jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary/index.js';
8
- import { USyncQuery, USyncUser } from '../WAUSync/index.js';
9
- import { makeGroupsSocket } from './groups.js';
10
- import { makeNewsletterSocket } from './newsletter.js';
11
- export const makeMessagesSocket = (config) => {
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 WAProto_1 = require("../../WAProto");
10
+ const Defaults_1 = require("../Defaults");
11
+ const Utils_1 = require("../Utils");
12
+ const link_preview_1 = require("../Utils/link-preview");
13
+ const WABinary_1 = require("../WABinary");
14
+ const WAUSync_1 = require("../WAUSync");
15
+ const groups_1 = require("./groups");
16
+ const newsletter_1 = require("./newsletter");
17
+ const makeMessagesSocket = (config) => {
12
18
  const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: axiosOptions, patchMessageBeforeSending, cachedGroupMetadata } = config;
13
- const sock = makeNewsletterSocket(makeGroupsSocket(config));
19
+ const sock = (0, newsletter_1.makeNewsletterSocket)((0, groups_1.makeGroupsSocket)(config));
14
20
  const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, sendNode, groupMetadata, groupToggleEphemeral } = sock;
15
21
  const userDevicesCache = config.userDevicesCache ||
16
- new NodeCache({
17
- stdTTL: DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
22
+ new node_cache_1.default({
23
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
18
24
  useClones: false
19
25
  });
20
26
  let mediaConn;
@@ -27,13 +33,13 @@ export const makeMessagesSocket = (config) => {
27
33
  attrs: {
28
34
  type: 'set',
29
35
  xmlns: 'w:m',
30
- to: S_WHATSAPP_NET
36
+ to: WABinary_1.S_WHATSAPP_NET
31
37
  },
32
38
  content: [{ tag: 'media_conn', attrs: {} }]
33
39
  });
34
- const mediaConnNode = getBinaryNodeChild(result, 'media_conn');
40
+ const mediaConnNode = (0, WABinary_1.getBinaryNodeChild)(result, 'media_conn');
35
41
  const node = {
36
- hosts: getBinaryNodeChildren(mediaConnNode, 'host').map(({ attrs }) => ({
42
+ hosts: (0, WABinary_1.getBinaryNodeChildren)(mediaConnNode, 'host').map(({ attrs }) => ({
37
43
  hostname: attrs.hostname,
38
44
  maxContentLengthBytes: +attrs.maxContentLengthBytes
39
45
  })),
@@ -52,9 +58,6 @@ export const makeMessagesSocket = (config) => {
52
58
  * used for receipts of phone call, read, delivery etc.
53
59
  * */
54
60
  const sendReceipt = async (jid, participant, messageIds, type) => {
55
- if (!messageIds || messageIds.length === 0) {
56
- throw new Boom('missing ids in receipt');
57
- }
58
61
  const node = {
59
62
  tag: 'receipt',
60
63
  attrs: {
@@ -63,9 +66,9 @@ export const makeMessagesSocket = (config) => {
63
66
  };
64
67
  const isReadReceipt = type === 'read' || type === 'read-self';
65
68
  if (isReadReceipt) {
66
- node.attrs.t = unixTimestampSeconds().toString();
69
+ node.attrs.t = (0, Utils_1.unixTimestampSeconds)().toString();
67
70
  }
68
- if (type === 'sender' && isJidUser(jid)) {
71
+ if (type === 'sender' && (0, WABinary_1.isJidUser)(jid)) {
69
72
  node.attrs.recipient = jid;
70
73
  node.attrs.to = participant;
71
74
  }
@@ -96,7 +99,7 @@ export const makeMessagesSocket = (config) => {
96
99
  };
97
100
  /** Correctly bulk send receipts to multiple chats, participants */
98
101
  const sendReceipts = async (keys, type) => {
99
- const recps = aggregateMessageKeysNotFromMe(keys);
102
+ const recps = (0, Utils_1.aggregateMessageKeysNotFromMe)(keys);
100
103
  for (const { jid, participant, messageIds } of recps) {
101
104
  await sendReceipt(jid, participant, messageIds, type);
102
105
  }
@@ -110,6 +113,7 @@ export const makeMessagesSocket = (config) => {
110
113
  };
111
114
  /** Fetch all the devices we've to send a message to */
112
115
  const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
116
+ var _a;
113
117
  const deviceResults = [];
114
118
  if (!useCache) {
115
119
  logger.debug('not using cache for devices');
@@ -117,8 +121,8 @@ export const makeMessagesSocket = (config) => {
117
121
  const toFetch = [];
118
122
  jids = Array.from(new Set(jids));
119
123
  for (let jid of jids) {
120
- const user = jidDecode(jid)?.user;
121
- jid = jidNormalizedUser(jid);
124
+ const user = (_a = (0, WABinary_1.jidDecode)(jid)) === null || _a === void 0 ? void 0 : _a.user;
125
+ jid = (0, WABinary_1.jidNormalizedUser)(jid);
122
126
  if (useCache) {
123
127
  const devices = userDevicesCache.get(user);
124
128
  if (devices) {
@@ -136,17 +140,17 @@ export const makeMessagesSocket = (config) => {
136
140
  if (!toFetch.length) {
137
141
  return deviceResults;
138
142
  }
139
- const query = new USyncQuery().withContext('message').withDeviceProtocol();
143
+ const query = new WAUSync_1.USyncQuery().withContext('message').withDeviceProtocol();
140
144
  for (const jid of toFetch) {
141
- query.withUser(new USyncUser().withId(jid));
145
+ query.withUser(new WAUSync_1.USyncUser().withId(jid));
142
146
  }
143
147
  const result = await sock.executeUSyncQuery(query);
144
148
  if (result) {
145
- const extracted = extractDeviceJids(result?.list, authState.creds.me.id, ignoreZeroDevices);
149
+ const extracted = (0, Utils_1.extractDeviceJids)(result === null || result === void 0 ? void 0 : result.list, authState.creds.me.id, ignoreZeroDevices);
146
150
  const deviceMap = {};
147
151
  for (const item of extracted) {
148
152
  deviceMap[item.user] = deviceMap[item.user] || [];
149
- deviceMap[item.user]?.push(item);
153
+ deviceMap[item.user].push(item);
150
154
  deviceResults.push(item);
151
155
  }
152
156
  for (const key in deviceMap) {
@@ -178,7 +182,7 @@ export const makeMessagesSocket = (config) => {
178
182
  attrs: {
179
183
  xmlns: 'encrypt',
180
184
  type: 'get',
181
- to: S_WHATSAPP_NET
185
+ to: WABinary_1.S_WHATSAPP_NET
182
186
  },
183
187
  content: [
184
188
  {
@@ -191,26 +195,28 @@ export const makeMessagesSocket = (config) => {
191
195
  }
192
196
  ]
193
197
  });
194
- await parseAndInjectE2ESessions(result, signalRepository);
198
+ await (0, Utils_1.parseAndInjectE2ESessions)(result, signalRepository);
195
199
  didFetchNewSession = true;
196
200
  }
197
201
  return didFetchNewSession;
198
202
  };
199
203
  const sendPeerDataOperationMessage = async (pdoMessage) => {
204
+ var _a;
200
205
  //TODO: for later, abstract the logic to send a Peer Message instead of just PDO - useful for App State Key Resync with phone
201
- if (!authState.creds.me?.id) {
202
- throw new Boom('Not authenticated');
206
+ if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
207
+ throw new boom_1.Boom('Not authenticated');
203
208
  }
204
209
  const protocolMessage = {
205
210
  protocolMessage: {
206
211
  peerDataOperationRequestMessage: pdoMessage,
207
- type: proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
212
+ type: WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
208
213
  }
209
214
  };
210
- const meJid = jidNormalizedUser(authState.creds.me.id);
215
+ const meJid = (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id);
211
216
  const msgId = await relayMessage(meJid, protocolMessage, {
212
217
  additionalAttributes: {
213
218
  category: 'peer',
219
+ // eslint-disable-next-line camelcase
214
220
  push_priority: 'high_force'
215
221
  }
216
222
  });
@@ -227,7 +233,7 @@ export const makeMessagesSocket = (config) => {
227
233
  if (!jid) {
228
234
  return {};
229
235
  }
230
- const bytes = encodeWAMessage(patchedMessage);
236
+ const bytes = (0, Utils_1.encodeWAMessage)(patchedMessage);
231
237
  const { type, ciphertext } = await signalRepository.encryptMessage({ jid, data: bytes });
232
238
  if (type === 'pkmsg') {
233
239
  shouldIncludeDeviceIdentity = true;
@@ -252,19 +258,20 @@ export const makeMessagesSocket = (config) => {
252
258
  return { nodes, shouldIncludeDeviceIdentity };
253
259
  };
254
260
  const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }) => {
261
+ var _a;
255
262
  const meId = authState.creds.me.id;
256
263
  let shouldIncludeDeviceIdentity = false;
257
- const { user, server } = jidDecode(jid);
264
+ const { user, server } = (0, WABinary_1.jidDecode)(jid);
258
265
  const statusJid = 'status@broadcast';
259
266
  const isGroup = server === 'g.us';
260
267
  const isStatus = jid === statusJid;
261
268
  const isLid = server === 'lid';
262
269
  const isNewsletter = server === 'newsletter';
263
- msgId = msgId || generateMessageIDV2(sock.user?.id);
270
+ msgId = msgId || (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id);
264
271
  useUserDevicesCache = useUserDevicesCache !== false;
265
272
  useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus;
266
273
  const participants = [];
267
- const destinationJid = !isStatus ? jidEncode(user, isLid ? 'lid' : isGroup ? 'g.us' : 's.whatsapp.net') : statusJid;
274
+ const destinationJid = !isStatus ? (0, WABinary_1.jidEncode)(user, isLid ? 'lid' : isGroup ? 'g.us' : 's.whatsapp.net') : statusJid;
268
275
  const binaryNodeContent = [];
269
276
  const devices = [];
270
277
  const meMsg = {
@@ -282,10 +289,11 @@ export const makeMessagesSocket = (config) => {
282
289
  if (!isGroup && !isStatus) {
283
290
  additionalAttributes = { ...additionalAttributes, device_fanout: 'false' };
284
291
  }
285
- const { user, device } = jidDecode(participant.jid);
292
+ const { user, device } = (0, WABinary_1.jidDecode)(participant.jid);
286
293
  devices.push({ user, device });
287
294
  }
288
295
  await authState.keys.transaction(async () => {
296
+ var _a, _b, _c, _d, _e;
289
297
  const mediaType = getMediaType(message);
290
298
  if (mediaType) {
291
299
  extraAttrs['mediatype'] = mediaType;
@@ -293,7 +301,7 @@ export const makeMessagesSocket = (config) => {
293
301
  if (isNewsletter) {
294
302
  // Patch message if needed, then encode as plaintext
295
303
  const patched = patchMessageBeforeSending ? await patchMessageBeforeSending(message, []) : message;
296
- const bytes = encodeNewsletterMessage(patched);
304
+ const bytes = (0, Utils_1.encodeNewsletterMessage)(patched);
297
305
  binaryNodeContent.push({
298
306
  tag: 'plaintext',
299
307
  attrs: {},
@@ -313,14 +321,14 @@ export const makeMessagesSocket = (config) => {
313
321
  await sendNode(stanza);
314
322
  return;
315
323
  }
316
- if (normalizeMessageContent(message)?.pinInChatMessage) {
324
+ if ((_a = (0, Utils_1.normalizeMessageContent)(message)) === null || _a === void 0 ? void 0 : _a.pinInChatMessage) {
317
325
  extraAttrs['decrypt-fail'] = 'hide';
318
326
  }
319
327
  if (isGroup || isStatus) {
320
328
  const [groupData, senderKeyMap] = await Promise.all([
321
329
  (async () => {
322
330
  let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined;
323
- if (groupData && Array.isArray(groupData?.participants)) {
331
+ if (groupData && Array.isArray(groupData === null || groupData === void 0 ? void 0 : groupData.participants)) {
324
332
  logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
325
333
  }
326
334
  else if (!isStatus) {
@@ -344,7 +352,7 @@ export const makeMessagesSocket = (config) => {
344
352
  if (!isStatus) {
345
353
  additionalAttributes = {
346
354
  ...additionalAttributes,
347
- addressing_mode: groupData?.addressingMode || 'pn'
355
+ addressing_mode: (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) || 'pn'
348
356
  };
349
357
  }
350
358
  const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false);
@@ -352,9 +360,9 @@ export const makeMessagesSocket = (config) => {
352
360
  }
353
361
  const patched = await patchMessageBeforeSending(message);
354
362
  if (Array.isArray(patched)) {
355
- throw new Boom('Per-jid patching is not supported in groups');
363
+ throw new boom_1.Boom('Per-jid patching is not supported in groups');
356
364
  }
357
- const bytes = encodeWAMessage(patched);
365
+ const bytes = (0, Utils_1.encodeWAMessage)(patched);
358
366
  const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
359
367
  group: destinationJid,
360
368
  data: bytes,
@@ -363,7 +371,7 @@ export const makeMessagesSocket = (config) => {
363
371
  const senderKeyJids = [];
364
372
  // ensure a connection is established with every device
365
373
  for (const { user, device } of devices) {
366
- const jid = jidEncode(user, groupData?.addressingMode === 'lid' ? 'lid' : 's.whatsapp.net', device);
374
+ const jid = (0, WABinary_1.jidEncode)(user, (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) === 'lid' ? 'lid' : 's.whatsapp.net', device);
367
375
  if (!senderKeyMap[jid] || !!participant) {
368
376
  senderKeyJids.push(jid);
369
377
  // store that this person has had the sender keys sent to them
@@ -393,13 +401,13 @@ export const makeMessagesSocket = (config) => {
393
401
  await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
394
402
  }
395
403
  else {
396
- const { user: meUser } = jidDecode(meId);
404
+ const { user: meUser } = (0, WABinary_1.jidDecode)(meId);
397
405
  if (!participant) {
398
406
  devices.push({ user });
399
407
  if (user !== meUser) {
400
408
  devices.push({ user: meUser });
401
409
  }
402
- if (additionalAttributes?.['category'] !== 'peer') {
410
+ if ((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) !== 'peer') {
403
411
  const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true);
404
412
  devices.push(...additionalDevices);
405
413
  }
@@ -409,7 +417,7 @@ export const makeMessagesSocket = (config) => {
409
417
  const otherJids = [];
410
418
  for (const { user, device } of devices) {
411
419
  const isMe = user === meUser;
412
- const jid = jidEncode(isMe && isLid ? authState.creds?.me?.lid.split(':')[0] || user : user, isLid ? 'lid' : 's.whatsapp.net', device);
420
+ const jid = (0, WABinary_1.jidEncode)(isMe && isLid ? ((_c = (_b = authState.creds) === null || _b === void 0 ? void 0 : _b.me) === null || _c === void 0 ? void 0 : _c.lid.split(':')[0]) || user : user, isLid ? 'lid' : 's.whatsapp.net', device);
413
421
  if (isMe) {
414
422
  meJids.push(jid);
415
423
  }
@@ -428,8 +436,8 @@ export const makeMessagesSocket = (config) => {
428
436
  shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
429
437
  }
430
438
  if (participants.length) {
431
- if (additionalAttributes?.['category'] === 'peer') {
432
- const peerNode = participants[0]?.content?.[0];
439
+ if ((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) === 'peer') {
440
+ const peerNode = (_e = (_d = participants[0]) === null || _d === void 0 ? void 0 : _d.content) === null || _e === void 0 ? void 0 : _e[0];
433
441
  if (peerNode) {
434
442
  binaryNodeContent.push(peerNode); // push only enc
435
443
  }
@@ -455,11 +463,11 @@ export const makeMessagesSocket = (config) => {
455
463
  // ensure the message is only sent to that person
456
464
  // if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
457
465
  if (participant) {
458
- if (isJidGroup(destinationJid)) {
466
+ if ((0, WABinary_1.isJidGroup)(destinationJid)) {
459
467
  stanza.attrs.to = destinationJid;
460
468
  stanza.attrs.participant = participant.jid;
461
469
  }
462
- else if (areJidsSameUser(participant.jid, meId)) {
470
+ else if ((0, WABinary_1.areJidsSameUser)(participant.jid, meId)) {
463
471
  stanza.attrs.to = participant.jid;
464
472
  stanza.attrs.recipient = destinationJid;
465
473
  }
@@ -475,7 +483,7 @@ export const makeMessagesSocket = (config) => {
475
483
  stanza.content.push({
476
484
  tag: 'device-identity',
477
485
  attrs: {},
478
- content: encodeSignedDeviceIdentity(authState.creds.account, true)
486
+ content: (0, Utils_1.encodeSignedDeviceIdentity)(authState.creds.account, true)
479
487
  });
480
488
  logger.debug({ jid }, 'adding device identity');
481
489
  }
@@ -542,11 +550,11 @@ export const makeMessagesSocket = (config) => {
542
550
  }
543
551
  };
544
552
  const getPrivacyTokens = async (jids) => {
545
- const t = unixTimestampSeconds().toString();
553
+ const t = (0, Utils_1.unixTimestampSeconds)().toString();
546
554
  const result = await query({
547
555
  tag: 'iq',
548
556
  attrs: {
549
- to: S_WHATSAPP_NET,
557
+ to: WABinary_1.S_WHATSAPP_NET,
550
558
  type: 'set',
551
559
  xmlns: 'privacy'
552
560
  },
@@ -557,7 +565,7 @@ export const makeMessagesSocket = (config) => {
557
565
  content: jids.map(jid => ({
558
566
  tag: 'token',
559
567
  attrs: {
560
- jid: jidNormalizedUser(jid),
568
+ jid: (0, WABinary_1.jidNormalizedUser)(jid),
561
569
  t,
562
570
  type: 'trusted_contact'
563
571
  }
@@ -567,8 +575,8 @@ export const makeMessagesSocket = (config) => {
567
575
  });
568
576
  return result;
569
577
  };
570
- const waUploadToServer = getWAUploadToServer(config, refreshMediaConn);
571
- const waitForMsgMediaUpdate = bindWaitForEvent(ev, 'messages.media-update');
578
+ const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
579
+ const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
572
580
  return {
573
581
  ...sock,
574
582
  getPrivacyTokens,
@@ -584,10 +592,10 @@ export const makeMessagesSocket = (config) => {
584
592
  createParticipantNodes,
585
593
  getUSyncDevices,
586
594
  updateMediaMessage: async (message) => {
587
- const content = assertMediaContent(message.message);
595
+ const content = (0, Utils_1.assertMediaContent)(message.message);
588
596
  const mediaKey = content.mediaKey;
589
597
  const meId = authState.creds.me.id;
590
- const node = await encryptMediaRetryRequest(message.key, mediaKey, meId);
598
+ const node = await (0, Utils_1.encryptMediaRetryRequest)(message.key, mediaKey, meId);
591
599
  let error = undefined;
592
600
  await Promise.all([
593
601
  sendNode(node),
@@ -599,16 +607,16 @@ export const makeMessagesSocket = (config) => {
599
607
  }
600
608
  else {
601
609
  try {
602
- const media = await decryptMediaRetryData(result.media, mediaKey, result.key.id);
603
- if (media.result !== proto.MediaRetryNotification.ResultType.SUCCESS) {
604
- const resultStr = proto.MediaRetryNotification.ResultType[media.result];
605
- throw new Boom(`Media re-upload failed by device (${resultStr})`, {
610
+ const media = await (0, Utils_1.decryptMediaRetryData)(result.media, mediaKey, result.key.id);
611
+ if (media.result !== WAProto_1.proto.MediaRetryNotification.ResultType.SUCCESS) {
612
+ const resultStr = WAProto_1.proto.MediaRetryNotification.ResultType[media.result];
613
+ throw new boom_1.Boom(`Media re-upload failed by device (${resultStr})`, {
606
614
  data: media,
607
- statusCode: getStatusCodeForMediaRetry(media.result) || 404
615
+ statusCode: (0, Utils_1.getStatusCodeForMediaRetry)(media.result) || 404
608
616
  });
609
617
  }
610
618
  content.directPath = media.directPath;
611
- content.url = getUrlFromDirectPath(content.directPath);
619
+ content.url = (0, Utils_1.getUrlFromDirectPath)(content.directPath);
612
620
  logger.debug({ directPath: media.directPath, key: result.key }, 'media update successful');
613
621
  }
614
622
  catch (err) {
@@ -626,24 +634,25 @@ export const makeMessagesSocket = (config) => {
626
634
  return message;
627
635
  },
628
636
  sendMessage: async (jid, content, options = {}) => {
637
+ var _a, _b, _c;
629
638
  const userJid = authState.creds.me.id;
630
639
  if (typeof content === 'object' &&
631
640
  'disappearingMessagesInChat' in content &&
632
641
  typeof content['disappearingMessagesInChat'] !== 'undefined' &&
633
- isJidGroup(jid)) {
642
+ (0, WABinary_1.isJidGroup)(jid)) {
634
643
  const { disappearingMessagesInChat } = content;
635
644
  const value = typeof disappearingMessagesInChat === 'boolean'
636
645
  ? disappearingMessagesInChat
637
- ? WA_DEFAULT_EPHEMERAL
646
+ ? Defaults_1.WA_DEFAULT_EPHEMERAL
638
647
  : 0
639
648
  : disappearingMessagesInChat;
640
649
  await groupToggleEphemeral(jid, value);
641
650
  }
642
651
  else {
643
- const fullMsg = await generateWAMessage(jid, content, {
652
+ const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
644
653
  logger,
645
654
  userJid,
646
- getUrlInfo: text => getUrlInfo(text, {
655
+ getUrlInfo: text => (0, link_preview_1.getUrlInfo)(text, {
647
656
  thumbnailWidth: linkPreviewImageThumbnailWidth,
648
657
  fetchOpts: {
649
658
  timeout: 3000,
@@ -657,7 +666,7 @@ export const makeMessagesSocket = (config) => {
657
666
  upload: waUploadToServer,
658
667
  mediaCache: config.mediaCache,
659
668
  options: config.options,
660
- messageId: generateMessageIDV2(sock.user?.id),
669
+ messageId: (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id),
661
670
  ...options
662
671
  });
663
672
  const isDeleteMsg = 'delete' in content && !!content.delete;
@@ -669,7 +678,7 @@ export const makeMessagesSocket = (config) => {
669
678
  // required for delete
670
679
  if (isDeleteMsg) {
671
680
  // if the chat is a group, and I am not the author, then delete the message as an admin
672
- if (isJidGroup(content.delete?.remoteJid) && !content.delete?.fromMe) {
681
+ if ((0, WABinary_1.isJidGroup)((_b = content.delete) === null || _b === void 0 ? void 0 : _b.remoteJid) && !((_c = content.delete) === null || _c === void 0 ? void 0 : _c.fromMe)) {
673
682
  additionalAttributes.edit = '8';
674
683
  }
675
684
  else {
@@ -710,4 +719,4 @@ export const makeMessagesSocket = (config) => {
710
719
  }
711
720
  };
712
721
  };
713
- //# sourceMappingURL=messages-send.js.map
722
+ exports.makeMessagesSocket = makeMessagesSocket;
@@ -1,3 +1,2 @@
1
- import type { BinaryNode } from '../WABinary/index.js';
1
+ import { BinaryNode } from '../WABinary';
2
2
  export declare const executeWMexQuery: <T>(variables: Record<string, unknown>, queryId: string, dataPath: string, query: (node: BinaryNode) => Promise<BinaryNode>, generateMessageTag: () => string) => Promise<T>;
3
- //# sourceMappingURL=mex.d.ts.map
package/lib/Socket/mex.js CHANGED
@@ -1,12 +1,15 @@
1
- import { Boom } from '@hapi/boom';
2
- import { getBinaryNodeChild, S_WHATSAPP_NET } from '../WABinary/index.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.executeWMexQuery = void 0;
4
+ const boom_1 = require("@hapi/boom");
5
+ const WABinary_1 = require("../WABinary");
3
6
  const wMexQuery = (variables, queryId, query, generateMessageTag) => {
4
7
  return query({
5
8
  tag: 'iq',
6
9
  attrs: {
7
10
  id: generateMessageTag(),
8
11
  type: 'get',
9
- to: S_WHATSAPP_NET,
12
+ to: WABinary_1.S_WHATSAPP_NET,
10
13
  xmlns: 'w:mex'
11
14
  },
12
15
  content: [
@@ -18,25 +21,26 @@ const wMexQuery = (variables, queryId, query, generateMessageTag) => {
18
21
  ]
19
22
  });
20
23
  };
21
- export const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
24
+ const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
25
+ var _a, _b;
22
26
  const result = await wMexQuery(variables, queryId, query, generateMessageTag);
23
- const child = getBinaryNodeChild(result, 'result');
24
- if (child?.content) {
27
+ const child = (0, WABinary_1.getBinaryNodeChild)(result, 'result');
28
+ if (child === null || child === void 0 ? void 0 : child.content) {
25
29
  const data = JSON.parse(child.content.toString());
26
30
  if (data.errors && data.errors.length > 0) {
27
31
  const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ');
28
32
  const firstError = data.errors[0];
29
- const errorCode = firstError.extensions?.error_code || 400;
30
- throw new Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError });
33
+ const errorCode = ((_a = firstError.extensions) === null || _a === void 0 ? void 0 : _a.error_code) || 400;
34
+ throw new boom_1.Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError });
31
35
  }
32
- const response = dataPath ? data?.data?.[dataPath] : data?.data;
36
+ const response = dataPath ? (_b = data === null || data === void 0 ? void 0 : data.data) === null || _b === void 0 ? void 0 : _b[dataPath] : data === null || data === void 0 ? void 0 : data.data;
33
37
  if (typeof response !== 'undefined') {
34
38
  return response;
35
39
  }
36
40
  }
37
41
  const action = (dataPath || '').startsWith('xwa2_')
38
42
  ? dataPath.substring(5).replace(/_/g, ' ')
39
- : dataPath?.replace(/_/g, ' ');
40
- throw new Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result });
43
+ : dataPath === null || dataPath === void 0 ? void 0 : dataPath.replace(/_/g, ' ');
44
+ throw new boom_1.Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result });
41
45
  };
42
- //# sourceMappingURL=mex.js.map
46
+ exports.executeWMexQuery = executeWMexQuery;