@queenanya/baileys 8.6.0-beta → 9.0.3

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 (397) hide show
  1. package/WAProto/GenerateStatics.sh +3 -0
  2. package/WAProto/WAProto.proto +4633 -0
  3. package/WAProto/fix-imports.js +29 -0
  4. package/WAProto/index.d.ts +2165 -45253
  5. package/WAProto/index.js +45236 -130529
  6. package/lib/Defaults/index.d.ts +14 -3
  7. package/lib/Defaults/index.d.ts.map +1 -0
  8. package/lib/Defaults/index.js +64 -55
  9. package/lib/Defaults/index.js.map +1 -0
  10. package/lib/Signal/Group/ciphertext-message.d.ts +1 -0
  11. package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
  12. package/lib/Signal/Group/ciphertext-message.js +2 -5
  13. package/lib/Signal/Group/ciphertext-message.js.map +1 -0
  14. package/lib/Signal/Group/group-session-builder.d.ts +4 -3
  15. package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
  16. package/lib/Signal/Group/group-session-builder.js +7 -41
  17. package/lib/Signal/Group/group-session-builder.js.map +1 -0
  18. package/lib/Signal/Group/group_cipher.d.ts +4 -4
  19. package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
  20. package/lib/Signal/Group/group_cipher.js +37 -51
  21. package/lib/Signal/Group/group_cipher.js.map +1 -0
  22. package/lib/Signal/Group/index.d.ts +12 -11
  23. package/lib/Signal/Group/index.d.ts.map +1 -0
  24. package/lib/Signal/Group/index.js +12 -57
  25. package/lib/Signal/Group/index.js.map +1 -0
  26. package/lib/Signal/Group/keyhelper.d.ts +2 -1
  27. package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
  28. package/lib/Signal/Group/keyhelper.js +7 -44
  29. package/lib/Signal/Group/keyhelper.js.map +1 -0
  30. package/lib/Signal/Group/sender-chain-key.d.ts +3 -2
  31. package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
  32. package/lib/Signal/Group/sender-chain-key.js +7 -15
  33. package/lib/Signal/Group/sender-chain-key.js.map +1 -0
  34. package/lib/Signal/Group/sender-key-distribution-message.d.ts +2 -1
  35. package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
  36. package/lib/Signal/Group/sender-key-distribution-message.js +8 -11
  37. package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
  38. package/lib/Signal/Group/sender-key-message.d.ts +2 -1
  39. package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
  40. package/lib/Signal/Group/sender-key-message.js +9 -12
  41. package/lib/Signal/Group/sender-key-message.js.map +1 -0
  42. package/lib/Signal/Group/sender-key-name.d.ts +1 -0
  43. package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
  44. package/lib/Signal/Group/sender-key-name.js +2 -5
  45. package/lib/Signal/Group/sender-key-name.js.map +1 -0
  46. package/lib/Signal/Group/sender-key-record.d.ts +3 -2
  47. package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
  48. package/lib/Signal/Group/sender-key-record.js +9 -21
  49. package/lib/Signal/Group/sender-key-record.js.map +1 -0
  50. package/lib/Signal/Group/sender-key-state.d.ts +7 -6
  51. package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
  52. package/lib/Signal/Group/sender-key-state.js +27 -42
  53. package/lib/Signal/Group/sender-key-state.js.map +1 -0
  54. package/lib/Signal/Group/sender-message-key.d.ts +1 -0
  55. package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
  56. package/lib/Signal/Group/sender-message-key.js +4 -7
  57. package/lib/Signal/Group/sender-message-key.js.map +1 -0
  58. package/lib/Signal/libsignal.d.ts +5 -3
  59. package/lib/Signal/libsignal.d.ts.map +1 -0
  60. package/lib/Signal/libsignal.js +258 -90
  61. package/lib/Signal/libsignal.js.map +1 -0
  62. package/lib/Signal/lid-mapping.d.ts +23 -0
  63. package/lib/Signal/lid-mapping.d.ts.map +1 -0
  64. package/lib/Signal/lid-mapping.js +171 -0
  65. package/lib/Signal/lid-mapping.js.map +1 -0
  66. package/lib/Socket/Client/index.d.ts +3 -2
  67. package/lib/Socket/Client/index.d.ts.map +1 -0
  68. package/lib/Socket/Client/index.js +3 -18
  69. package/lib/Socket/Client/index.js.map +1 -0
  70. package/lib/Socket/Client/types.d.ts +2 -2
  71. package/lib/Socket/Client/types.d.ts.map +1 -0
  72. package/lib/Socket/Client/types.js +4 -6
  73. package/lib/Socket/Client/types.js.map +1 -0
  74. package/lib/Socket/Client/websocket.d.ts +2 -2
  75. package/lib/Socket/Client/websocket.d.ts.map +1 -0
  76. package/lib/Socket/Client/websocket.js +15 -37
  77. package/lib/Socket/Client/websocket.js.map +1 -0
  78. package/lib/Socket/business.d.ts +106 -94
  79. package/lib/Socket/business.d.ts.map +1 -0
  80. package/lib/Socket/business.js +159 -43
  81. package/lib/Socket/business.js.map +1 -0
  82. package/lib/Socket/chats.d.ts +39 -27
  83. package/lib/Socket/chats.d.ts.map +1 -0
  84. package/lib/Socket/chats.js +271 -261
  85. package/lib/Socket/chats.js.map +1 -0
  86. package/lib/Socket/communities.d.ts +111 -86
  87. package/lib/Socket/communities.d.ts.map +1 -0
  88. package/lib/Socket/communities.js +138 -70
  89. package/lib/Socket/communities.js.map +1 -0
  90. package/lib/Socket/groups.d.ts +53 -43
  91. package/lib/Socket/groups.d.ts.map +1 -0
  92. package/lib/Socket/groups.js +94 -99
  93. package/lib/Socket/groups.js.map +1 -0
  94. package/lib/Socket/index.d.ts +133 -108
  95. package/lib/Socket/index.d.ts.map +1 -0
  96. package/lib/Socket/index.js +17 -9
  97. package/lib/Socket/index.js.map +1 -0
  98. package/lib/Socket/messages-recv.d.ts +90 -82
  99. package/lib/Socket/messages-recv.d.ts.map +1 -0
  100. package/lib/Socket/messages-recv.js +635 -480
  101. package/lib/Socket/messages-recv.js.map +1 -0
  102. package/lib/Socket/messages-send.d.ts +90 -76
  103. package/lib/Socket/messages-send.d.ts.map +1 -0
  104. package/lib/Socket/messages-send.js +476 -402
  105. package/lib/Socket/messages-send.js.map +1 -0
  106. package/lib/Socket/mex.d.ts +3 -0
  107. package/lib/Socket/mex.d.ts.map +1 -0
  108. package/lib/Socket/mex.js +42 -0
  109. package/lib/Socket/mex.js.map +1 -0
  110. package/lib/Socket/newsletter.d.ts +83 -73
  111. package/lib/Socket/newsletter.d.ts.map +1 -0
  112. package/lib/Socket/newsletter.js +181 -202
  113. package/lib/Socket/newsletter.js.map +1 -0
  114. package/lib/Socket/socket.d.ts +24 -16
  115. package/lib/Socket/socket.d.ts.map +1 -0
  116. package/lib/Socket/socket.js +402 -196
  117. package/lib/Socket/socket.js.map +1 -0
  118. package/lib/Types/Auth.d.ts +13 -5
  119. package/lib/Types/Auth.d.ts.map +1 -0
  120. package/lib/Types/Auth.js +2 -2
  121. package/lib/Types/Auth.js.map +1 -0
  122. package/lib/Types/Bussines.d.ts +25 -0
  123. package/lib/Types/Bussines.d.ts.map +1 -0
  124. package/lib/Types/Bussines.js +2 -0
  125. package/lib/Types/Bussines.js.map +1 -0
  126. package/lib/Types/Call.d.ts +1 -0
  127. package/lib/Types/Call.d.ts.map +1 -0
  128. package/lib/Types/Call.js +2 -2
  129. package/lib/Types/Call.js.map +1 -0
  130. package/lib/Types/Chat.d.ts +18 -9
  131. package/lib/Types/Chat.d.ts.map +1 -0
  132. package/lib/Types/Chat.js +8 -4
  133. package/lib/Types/Chat.js.map +1 -0
  134. package/lib/Types/Contact.d.ts +5 -4
  135. package/lib/Types/Contact.d.ts.map +1 -0
  136. package/lib/Types/Contact.js +2 -2
  137. package/lib/Types/Contact.js.map +1 -0
  138. package/lib/Types/Events.d.ts +36 -33
  139. package/lib/Types/Events.d.ts.map +1 -0
  140. package/lib/Types/Events.js +2 -2
  141. package/lib/Types/Events.js.map +1 -0
  142. package/lib/Types/GroupMetadata.d.ts +12 -11
  143. package/lib/Types/GroupMetadata.d.ts.map +1 -0
  144. package/lib/Types/GroupMetadata.js +2 -2
  145. package/lib/Types/GroupMetadata.js.map +1 -0
  146. package/lib/Types/Label.d.ts +12 -0
  147. package/lib/Types/Label.d.ts.map +1 -0
  148. package/lib/Types/Label.js +3 -5
  149. package/lib/Types/Label.js.map +1 -0
  150. package/lib/Types/LabelAssociation.d.ts +1 -0
  151. package/lib/Types/LabelAssociation.d.ts.map +1 -0
  152. package/lib/Types/LabelAssociation.js +3 -5
  153. package/lib/Types/LabelAssociation.js.map +1 -0
  154. package/lib/Types/Message.d.ts +51 -148
  155. package/lib/Types/Message.d.ts.map +1 -0
  156. package/lib/Types/Message.js +11 -7
  157. package/lib/Types/Message.js.map +1 -0
  158. package/lib/Types/Newsletter.d.ts +173 -71
  159. package/lib/Types/Newsletter.d.ts.map +1 -0
  160. package/lib/Types/Newsletter.js +54 -11
  161. package/lib/Types/Newsletter.js.map +1 -0
  162. package/lib/Types/Product.d.ts +2 -1
  163. package/lib/Types/Product.d.ts.map +1 -0
  164. package/lib/Types/Product.js +2 -2
  165. package/lib/Types/Product.js.map +1 -0
  166. package/lib/Types/Signal.d.ts +20 -1
  167. package/lib/Types/Signal.d.ts.map +1 -0
  168. package/lib/Types/Signal.js +2 -2
  169. package/lib/Types/Signal.js.map +1 -0
  170. package/lib/Types/Socket.d.ts +34 -20
  171. package/lib/Types/Socket.d.ts.map +1 -0
  172. package/lib/Types/Socket.js +3 -2
  173. package/lib/Types/Socket.js.map +1 -0
  174. package/lib/Types/State.d.ts +14 -2
  175. package/lib/Types/State.d.ts.map +1 -0
  176. package/lib/Types/State.js +13 -2
  177. package/lib/Types/State.js.map +1 -0
  178. package/lib/Types/USync.d.ts +3 -2
  179. package/lib/Types/USync.d.ts.map +1 -0
  180. package/lib/Types/USync.js +2 -2
  181. package/lib/Types/USync.js.map +1 -0
  182. package/lib/Types/index.d.ts +15 -14
  183. package/lib/Types/index.d.ts.map +1 -0
  184. package/lib/Types/index.js +15 -31
  185. package/lib/Types/index.js.map +1 -0
  186. package/lib/Utils/auth-utils.d.ts +5 -4
  187. package/lib/Utils/auth-utils.d.ts.map +1 -0
  188. package/lib/Utils/auth-utils.js +199 -141
  189. package/lib/Utils/auth-utils.js.map +1 -0
  190. package/lib/Utils/baileys-event-stream.d.ts +2 -1
  191. package/lib/Utils/baileys-event-stream.d.ts.map +1 -0
  192. package/lib/Utils/baileys-event-stream.js +15 -22
  193. package/lib/Utils/baileys-event-stream.js.map +1 -0
  194. package/lib/Utils/browser-utils.d.ts +4 -0
  195. package/lib/Utils/browser-utils.d.ts.map +1 -0
  196. package/lib/Utils/browser-utils.js +28 -0
  197. package/lib/Utils/browser-utils.js.map +1 -0
  198. package/lib/Utils/business.d.ts +3 -2
  199. package/lib/Utils/business.d.ts.map +1 -0
  200. package/lib/Utils/business.js +66 -69
  201. package/lib/Utils/business.js.map +1 -0
  202. package/lib/Utils/chat-utils.d.ts +11 -11
  203. package/lib/Utils/chat-utils.d.ts.map +1 -0
  204. package/lib/Utils/chat-utils.js +203 -194
  205. package/lib/Utils/chat-utils.js.map +1 -0
  206. package/lib/Utils/crypto.d.ts +8 -7
  207. package/lib/Utils/crypto.d.ts.map +1 -0
  208. package/lib/Utils/crypto.js +50 -101
  209. package/lib/Utils/crypto.js.map +1 -0
  210. package/lib/Utils/decode-wa-message.d.ts +18 -5
  211. package/lib/Utils/decode-wa-message.d.ts.map +1 -0
  212. package/lib/Utils/decode-wa-message.js +134 -62
  213. package/lib/Utils/decode-wa-message.js.map +1 -0
  214. package/lib/Utils/event-buffer.d.ts +6 -7
  215. package/lib/Utils/event-buffer.d.ts.map +1 -0
  216. package/lib/Utils/event-buffer.js +99 -69
  217. package/lib/Utils/event-buffer.js.map +1 -0
  218. package/lib/Utils/generics.d.ts +57 -68
  219. package/lib/Utils/generics.d.ts.map +1 -0
  220. package/lib/Utils/generics.js +179 -356
  221. package/lib/Utils/generics.js.map +1 -0
  222. package/lib/Utils/history.d.ts +10 -10
  223. package/lib/Utils/history.d.ts.map +1 -0
  224. package/lib/Utils/history.js +37 -50
  225. package/lib/Utils/history.js.map +1 -0
  226. package/lib/Utils/index.d.ts +21 -17
  227. package/lib/Utils/index.d.ts.map +1 -0
  228. package/lib/Utils/index.js +21 -33
  229. package/lib/Utils/index.js.map +1 -0
  230. package/lib/Utils/link-preview.d.ts +4 -4
  231. package/lib/Utils/link-preview.d.ts.map +1 -0
  232. package/lib/Utils/link-preview.js +15 -56
  233. package/lib/Utils/link-preview.js.map +1 -0
  234. package/lib/Utils/logger.d.ts +8 -6
  235. package/lib/Utils/logger.d.ts.map +1 -0
  236. package/lib/Utils/logger.js +3 -7
  237. package/lib/Utils/logger.js.map +1 -0
  238. package/lib/Utils/lt-hash.d.ts +9 -8
  239. package/lib/Utils/lt-hash.d.ts.map +1 -0
  240. package/lib/Utils/lt-hash.js +23 -26
  241. package/lib/Utils/lt-hash.js.map +1 -0
  242. package/lib/Utils/make-mutex.d.ts +1 -0
  243. package/lib/Utils/make-mutex.d.ts.map +1 -0
  244. package/lib/Utils/make-mutex.js +7 -10
  245. package/lib/Utils/make-mutex.js.map +1 -0
  246. package/lib/Utils/message-retry-manager.d.ts +82 -0
  247. package/lib/Utils/message-retry-manager.d.ts.map +1 -0
  248. package/lib/Utils/message-retry-manager.js +149 -0
  249. package/lib/Utils/message-retry-manager.js.map +1 -0
  250. package/lib/Utils/messages-media.d.ts +32 -38
  251. package/lib/Utils/messages-media.d.ts.map +1 -0
  252. package/lib/Utils/messages-media.js +283 -496
  253. package/lib/Utils/messages-media.js.map +1 -0
  254. package/lib/Utils/messages.d.ts +11 -10
  255. package/lib/Utils/messages.d.ts.map +1 -0
  256. package/lib/Utils/messages.js +309 -519
  257. package/lib/Utils/messages.js.map +1 -0
  258. package/lib/Utils/noise-handler.d.ts +5 -4
  259. package/lib/Utils/noise-handler.d.ts.map +1 -0
  260. package/lib/Utils/noise-handler.js +23 -26
  261. package/lib/Utils/noise-handler.js.map +1 -0
  262. package/lib/Utils/pre-key-manager.d.ts +28 -0
  263. package/lib/Utils/pre-key-manager.d.ts.map +1 -0
  264. package/lib/Utils/pre-key-manager.js +106 -0
  265. package/lib/Utils/pre-key-manager.js.map +1 -0
  266. package/lib/Utils/process-message.d.ts +12 -12
  267. package/lib/Utils/process-message.d.ts.map +1 -0
  268. package/lib/Utils/process-message.js +196 -155
  269. package/lib/Utils/process-message.js.map +1 -0
  270. package/lib/Utils/signal.d.ts +7 -6
  271. package/lib/Utils/signal.d.ts.map +1 -0
  272. package/lib/Utils/signal.js +70 -64
  273. package/lib/Utils/signal.js.map +1 -0
  274. package/lib/Utils/use-multi-file-auth-state.d.ts +2 -1
  275. package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
  276. package/lib/Utils/use-multi-file-auth-state.js +23 -27
  277. package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
  278. package/lib/Utils/use-single-file-auth-state.d.ts +3 -2
  279. package/lib/Utils/use-single-file-auth-state.d.ts.map +1 -0
  280. package/lib/Utils/use-single-file-auth-state.js +63 -41
  281. package/lib/Utils/use-single-file-auth-state.js.map +1 -0
  282. package/lib/Utils/validate-connection.d.ts +4 -3
  283. package/lib/Utils/validate-connection.d.ts.map +1 -0
  284. package/lib/Utils/validate-connection.js +99 -77
  285. package/lib/Utils/validate-connection.js.map +1 -0
  286. package/lib/WABinary/constants.d.ts +1 -0
  287. package/lib/WABinary/constants.d.ts.map +1 -0
  288. package/lib/WABinary/constants.js +9 -11
  289. package/lib/WABinary/constants.js.map +1 -0
  290. package/lib/WABinary/decode.d.ts +2 -1
  291. package/lib/WABinary/decode.d.ts.map +1 -0
  292. package/lib/WABinary/decode.js +25 -52
  293. package/lib/WABinary/decode.js.map +1 -0
  294. package/lib/WABinary/encode.d.ts +2 -1
  295. package/lib/WABinary/encode.d.ts.map +1 -0
  296. package/lib/WABinary/encode.js +14 -48
  297. package/lib/WABinary/encode.js.map +1 -0
  298. package/lib/WABinary/generic-utils.d.ts +4 -3
  299. package/lib/WABinary/generic-utils.d.ts.map +1 -0
  300. package/lib/WABinary/generic-utils.js +31 -39
  301. package/lib/WABinary/generic-utils.js.map +1 -0
  302. package/lib/WABinary/index.d.ts +6 -5
  303. package/lib/WABinary/index.d.ts.map +1 -0
  304. package/lib/WABinary/index.js +6 -21
  305. package/lib/WABinary/index.js.map +1 -0
  306. package/lib/WABinary/jid-utils.d.ts +23 -10
  307. package/lib/WABinary/jid-utils.d.ts.map +1 -0
  308. package/lib/WABinary/jid-utils.js +75 -60
  309. package/lib/WABinary/jid-utils.js.map +1 -0
  310. package/lib/WABinary/types.d.ts +2 -1
  311. package/lib/WABinary/types.d.ts.map +1 -0
  312. package/lib/WABinary/types.js +2 -2
  313. package/lib/WABinary/types.js.map +1 -0
  314. package/lib/WAM/BinaryInfo.d.ts +2 -1
  315. package/lib/WAM/BinaryInfo.d.ts.map +1 -0
  316. package/lib/WAM/BinaryInfo.js +2 -5
  317. package/lib/WAM/BinaryInfo.js.map +1 -0
  318. package/lib/WAM/constants.d.ts +5 -3
  319. package/lib/WAM/constants.d.ts.map +1 -0
  320. package/lib/WAM/constants.js +19071 -11568
  321. package/lib/WAM/constants.js.map +1 -0
  322. package/lib/WAM/encode.d.ts +2 -1
  323. package/lib/WAM/encode.d.ts.map +1 -0
  324. package/lib/WAM/encode.js +17 -22
  325. package/lib/WAM/encode.js.map +1 -0
  326. package/lib/WAM/index.d.ts +4 -3
  327. package/lib/WAM/index.d.ts.map +1 -0
  328. package/lib/WAM/index.js +4 -19
  329. package/lib/WAM/index.js.map +1 -0
  330. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +4 -3
  331. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
  332. package/lib/WAUSync/Protocols/USyncContactProtocol.js +8 -11
  333. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
  334. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +3 -2
  335. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
  336. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +11 -14
  337. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
  338. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +3 -2
  339. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
  340. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +8 -11
  341. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
  342. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +3 -2
  343. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
  344. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +9 -13
  345. package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
  346. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +4 -3
  347. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
  348. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +20 -22
  349. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
  350. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +5 -3
  351. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
  352. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +13 -8
  353. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
  354. package/lib/WAUSync/Protocols/index.d.ts +5 -4
  355. package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
  356. package/lib/WAUSync/Protocols/index.js +5 -20
  357. package/lib/WAUSync/Protocols/index.js.map +1 -0
  358. package/lib/WAUSync/USyncQuery.d.ts +5 -4
  359. package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
  360. package/lib/WAUSync/USyncQuery.js +40 -35
  361. package/lib/WAUSync/USyncQuery.js.map +1 -0
  362. package/lib/WAUSync/USyncUser.d.ts +6 -5
  363. package/lib/WAUSync/USyncUser.d.ts.map +1 -0
  364. package/lib/WAUSync/USyncUser.js +2 -5
  365. package/lib/WAUSync/USyncUser.js.map +1 -0
  366. package/lib/WAUSync/index.d.ts +4 -3
  367. package/lib/WAUSync/index.d.ts.map +1 -0
  368. package/lib/WAUSync/index.js +4 -19
  369. package/lib/WAUSync/index.js.map +1 -0
  370. package/lib/index.d.ts +10 -12
  371. package/lib/index.d.ts.map +1 -0
  372. package/lib/index.js +11 -34
  373. package/lib/index.js.map +1 -0
  374. package/package.json +55 -65
  375. package/CHANGELOG.md +0 -4
  376. package/README-anya.md +0 -459
  377. package/README-shizo.md +0 -445
  378. package/README-whiskey.md +0 -44
  379. package/lib/Defaults/baileys-version.json +0 -3
  380. package/lib/Signal/Group/queue-job.d.ts +0 -1
  381. package/lib/Signal/Group/queue-job.js +0 -57
  382. package/lib/Socket/usync.d.ts +0 -36
  383. package/lib/Socket/usync.js +0 -70
  384. package/lib/Store/index.d.ts +0 -2
  385. package/lib/Store/index.js +0 -8
  386. package/lib/Store/make-in-memory-store.d.ts +0 -118
  387. package/lib/Store/make-in-memory-store.js +0 -429
  388. package/lib/Store/make-ordered-dictionary.d.ts +0 -13
  389. package/lib/Store/make-ordered-dictionary.js +0 -81
  390. package/lib/Store/object-repository.d.ts +0 -10
  391. package/lib/Store/object-repository.js +0 -27
  392. package/lib/WAMedia/index.d.ts +0 -2
  393. package/lib/WAMedia/index.js +0 -18
  394. package/lib/WAMedia/media-messages.d.ts +0 -18
  395. package/lib/WAMedia/media-messages.js +0 -102
  396. package/lib/WAMedia/media-set.d.ts +0 -9
  397. package/lib/WAMedia/media-set.js +0 -312
@@ -1,35 +1,31 @@
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.makeChatsSocket = void 0;
7
- const boom_1 = require("@hapi/boom");
8
- const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
9
- const WAProto_1 = require("../../WAProto");
10
- const Defaults_1 = require("../Defaults");
11
- const Types_1 = require("../Types");
12
- const Utils_1 = require("../Utils");
13
- const make_mutex_1 = require("../Utils/make-mutex");
14
- const process_message_1 = __importDefault(require("../Utils/process-message"));
15
- const WABinary_1 = require("../WABinary");
16
- const WAMedia_1 = require("../WAMedia");
17
- const WAUSync_1 = require("../WAUSync");
18
- const usync_1 = require("./usync");
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, PROCESSABLE_HISTORY_TYPES } from '../Defaults/index.js';
5
+ import { ALL_WA_PATCH_NAMES } from '../Types/index.js';
6
+ import { SyncState } from '../Types/State.js';
7
+ import { chatModificationToAppPatch, decodePatches, decodeSyncdSnapshot, encodeSyncdPatch, extractSyncdPatches, generateProfilePicture, getHistoryMsg, newLTHashState, processSyncAction } from '../Utils/index.js';
8
+ import { makeMutex } from '../Utils/make-mutex.js';
9
+ import processMessage from '../Utils/process-message.js';
10
+ import { getBinaryNodeChild, getBinaryNodeChildren, jidDecode, jidNormalizedUser, reduceBinaryNodeToDictionary, S_WHATSAPP_NET } from '../WABinary/index.js';
11
+ import { USyncQuery, USyncUser } from '../WAUSync/index.js';
12
+ import { makeSocket } from './socket.js';
19
13
  const MAX_SYNC_ATTEMPTS = 2;
20
- const makeChatsSocket = (config) => {
21
- const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage, } = config;
22
- const sock = (0, usync_1.makeUSyncSocket)(config);
23
- const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError, } = sock;
14
+ export const makeChatsSocket = (config) => {
15
+ const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage } = config;
16
+ const sock = makeSocket(config);
17
+ const { ev, ws, authState, generateMessageTag, sendNode, query, signalRepository, onUnexpectedError } = sock;
24
18
  let privacySettings;
25
- let needToFlushWithAppStateSync = false;
26
- let pendingAppStateSync = false;
19
+ let syncState = SyncState.Connecting;
27
20
  /** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
28
- const processingMutex = (0, make_mutex_1.makeMutex)();
29
- const placeholderResendCache = (config.placeholderResendCache || new node_cache_1.default({
30
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
31
- useClones: false
32
- }));
21
+ const processingMutex = makeMutex();
22
+ // Timeout for AwaitingInitialSync state
23
+ let awaitingSyncTimeout;
24
+ const placeholderResendCache = config.placeholderResendCache ||
25
+ new NodeCache({
26
+ stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
27
+ useClones: false
28
+ });
33
29
  if (!config.placeholderResendCache) {
34
30
  config.placeholderResendCache = placeholderResendCache;
35
31
  }
@@ -44,14 +40,12 @@ const makeChatsSocket = (config) => {
44
40
  tag: 'iq',
45
41
  attrs: {
46
42
  xmlns: 'privacy',
47
- to: WABinary_1.S_WHATSAPP_NET,
43
+ to: S_WHATSAPP_NET,
48
44
  type: 'get'
49
45
  },
50
- content: [
51
- { tag: 'privacy', attrs: {} }
52
- ]
46
+ content: [{ tag: 'privacy', attrs: {} }]
53
47
  });
54
- privacySettings = (0, WABinary_1.reduceBinaryNodeToDictionary)(content === null || content === void 0 ? void 0 : content[0], 'category');
48
+ privacySettings = reduceBinaryNodeToDictionary(content?.[0], 'category');
55
49
  }
56
50
  return privacySettings;
57
51
  };
@@ -61,10 +55,11 @@ const makeChatsSocket = (config) => {
61
55
  tag: 'iq',
62
56
  attrs: {
63
57
  xmlns: 'privacy',
64
- to: WABinary_1.S_WHATSAPP_NET,
58
+ to: S_WHATSAPP_NET,
65
59
  type: 'set'
66
60
  },
67
- content: [{
61
+ content: [
62
+ {
68
63
  tag: 'privacy',
69
64
  attrs: {},
70
65
  content: [
@@ -73,7 +68,8 @@ const makeChatsSocket = (config) => {
73
68
  attrs: { name, value }
74
69
  }
75
70
  ]
76
- }]
71
+ }
72
+ ]
77
73
  });
78
74
  };
79
75
  const updateMessagesPrivacy = async (value) => {
@@ -105,15 +101,17 @@ const makeChatsSocket = (config) => {
105
101
  tag: 'iq',
106
102
  attrs: {
107
103
  xmlns: 'disappearing_mode',
108
- to: WABinary_1.S_WHATSAPP_NET,
104
+ to: S_WHATSAPP_NET,
109
105
  type: 'set'
110
106
  },
111
- content: [{
107
+ content: [
108
+ {
112
109
  tag: 'disappearing_mode',
113
110
  attrs: {
114
111
  duration: duration.toString()
115
112
  }
116
- }]
113
+ }
114
+ ]
117
115
  });
118
116
  };
119
117
  const getBotListV2 = async () => {
@@ -121,21 +119,23 @@ const makeChatsSocket = (config) => {
121
119
  tag: 'iq',
122
120
  attrs: {
123
121
  xmlns: 'bot',
124
- to: WABinary_1.S_WHATSAPP_NET,
122
+ to: S_WHATSAPP_NET,
125
123
  type: 'get'
126
124
  },
127
- content: [{
125
+ content: [
126
+ {
128
127
  tag: 'bot',
129
128
  attrs: {
130
129
  v: '2'
131
130
  }
132
- }]
131
+ }
132
+ ]
133
133
  });
134
- const botNode = (0, WABinary_1.getBinaryNodeChild)(resp, 'bot');
134
+ const botNode = getBinaryNodeChild(resp, 'bot');
135
135
  const botList = [];
136
- for (const section of (0, WABinary_1.getBinaryNodeChildren)(botNode, 'section')) {
136
+ for (const section of getBinaryNodeChildren(botNode, 'section')) {
137
137
  if (section.attrs.type === 'all') {
138
- for (const bot of (0, WABinary_1.getBinaryNodeChildren)(section, 'bot')) {
138
+ for (const bot of getBinaryNodeChildren(section, 'bot')) {
139
139
  botList.push({
140
140
  jid: bot.attrs.jid,
141
141
  personaId: bot.attrs['persona_id']
@@ -145,24 +145,10 @@ const makeChatsSocket = (config) => {
145
145
  }
146
146
  return botList;
147
147
  };
148
- const onWhatsApp = async (...jids) => {
149
- const usyncQuery = new WAUSync_1.USyncQuery()
150
- .withContactProtocol()
151
- .withLIDProtocol();
152
- for (const jid of jids) {
153
- const phone = `+${jid.replace('+', '').split('@')[0].split(':')[0]}`;
154
- usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone));
155
- }
156
- const results = await sock.executeUSyncQuery(usyncQuery);
157
- if (results) {
158
- return results.list.filter((a) => !!a.contact).map(({ contact, id, lid }) => ({ jid: id, exists: contact, lid }));
159
- }
160
- };
161
148
  const fetchStatus = async (...jids) => {
162
- const usyncQuery = new WAUSync_1.USyncQuery()
163
- .withStatusProtocol();
149
+ const usyncQuery = new USyncQuery().withStatusProtocol();
164
150
  for (const jid of jids) {
165
- usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
151
+ usyncQuery.withUser(new USyncUser().withId(jid));
166
152
  }
167
153
  const result = await sock.executeUSyncQuery(usyncQuery);
168
154
  if (result) {
@@ -170,10 +156,9 @@ const makeChatsSocket = (config) => {
170
156
  }
171
157
  };
172
158
  const fetchDisappearingDuration = async (...jids) => {
173
- const usyncQuery = new WAUSync_1.USyncQuery()
174
- .withDisappearingModeProtocol();
159
+ const usyncQuery = new USyncQuery().withDisappearingModeProtocol();
175
160
  for (const jid of jids) {
176
- usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
161
+ usyncQuery.withUser(new USyncUser().withId(jid));
177
162
  }
178
163
  const result = await sock.executeUSyncQuery(usyncQuery);
179
164
  if (result) {
@@ -181,49 +166,25 @@ const makeChatsSocket = (config) => {
181
166
  }
182
167
  };
183
168
  /** update the profile picture for yourself or a group */
184
- const updateProfilePicture = async (jid, content) => {
169
+ const updateProfilePicture = async (jid, content, dimensions) => {
185
170
  let targetJid;
186
171
  if (!jid) {
187
- throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
172
+ throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
188
173
  }
189
- if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
190
- targetJid = (0, WABinary_1.jidNormalizedUser)(jid); // in case it is someone other than us
174
+ if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
175
+ targetJid = jidNormalizedUser(jid); // in case it is someone other than us
191
176
  }
192
- const { img } = await (0, Utils_1.generateProfilePicture)(content);
193
- await query({
194
- tag: 'iq',
195
- attrs: {
196
- target: targetJid,
197
- to: WABinary_1.S_WHATSAPP_NET,
198
- type: 'set',
199
- xmlns: 'w:profile:picture'
200
- },
201
- content: [
202
- {
203
- tag: 'picture',
204
- attrs: { type: 'image' },
205
- content: img
206
- }
207
- ]
208
- });
209
- };
210
- /** update the full profile picture for yourself or a group */
211
- const updateProfilePictureFull = async (jid, content) => {
212
- let targetJid;
213
- if (!jid) {
214
- throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
215
- }
216
- if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
217
- targetJid = (0, WABinary_1.jidNormalizedUser)(jid); // in case it is someone other than us
177
+ else {
178
+ targetJid = undefined;
218
179
  }
219
- const { img } = await (0, WAMedia_1.generateProfilePictureFP)(content);
180
+ const { img } = await generateProfilePicture(content, dimensions);
220
181
  await query({
221
182
  tag: 'iq',
222
183
  attrs: {
223
- target: targetJid,
224
- to: WABinary_1.S_WHATSAPP_NET,
184
+ to: S_WHATSAPP_NET,
225
185
  type: 'set',
226
- xmlns: 'w:profile:picture'
186
+ xmlns: 'w:profile:picture',
187
+ ...(targetJid ? { target: targetJid } : {})
227
188
  },
228
189
  content: [
229
190
  {
@@ -234,48 +195,25 @@ const makeChatsSocket = (config) => {
234
195
  ]
235
196
  });
236
197
  };
237
- const updateProfilePictureFullV2 = async (jid, content) => {
238
- let targetJid;
239
- if (!jid) {
240
- throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
241
- }
242
- if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
243
- targetJid = (0, WABinary_1.jidNormalizedUser)(jid); // in case it is someone other than us
244
- }
245
- const { preview } = await (0, WAMedia_1.generatePP)(content);
246
- await query({
247
- tag: 'iq',
248
- attrs: {
249
- target: targetJid,
250
- to: WABinary_1.S_WHATSAPP_NET,
251
- type: 'set',
252
- xmlns: 'w:profile:picture'
253
- },
254
- content: [
255
- {
256
- tag: 'picture',
257
- attrs: { type: 'image' },
258
- content: preview
259
- }
260
- ]
261
- });
262
- };
263
198
  /** remove the profile picture for yourself or a group */
264
199
  const removeProfilePicture = async (jid) => {
265
200
  let targetJid;
266
201
  if (!jid) {
267
- throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
202
+ throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
268
203
  }
269
- if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
270
- targetJid = (0, WABinary_1.jidNormalizedUser)(jid); // in case it is someone other than us
204
+ if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
205
+ targetJid = jidNormalizedUser(jid); // in case it is someone other than us
206
+ }
207
+ else {
208
+ targetJid = undefined;
271
209
  }
272
210
  await query({
273
211
  tag: 'iq',
274
212
  attrs: {
275
- target: targetJid,
276
- to: WABinary_1.S_WHATSAPP_NET,
213
+ to: S_WHATSAPP_NET,
277
214
  type: 'set',
278
- xmlns: 'w:profile:picture'
215
+ xmlns: 'w:profile:picture',
216
+ ...(targetJid ? { target: targetJid } : {})
279
217
  }
280
218
  });
281
219
  };
@@ -284,7 +222,7 @@ const makeChatsSocket = (config) => {
284
222
  await query({
285
223
  tag: 'iq',
286
224
  attrs: {
287
- to: WABinary_1.S_WHATSAPP_NET,
225
+ to: S_WHATSAPP_NET,
288
226
  type: 'set',
289
227
  xmlns: 'status'
290
228
  },
@@ -305,20 +243,19 @@ const makeChatsSocket = (config) => {
305
243
  tag: 'iq',
306
244
  attrs: {
307
245
  xmlns: 'blocklist',
308
- to: WABinary_1.S_WHATSAPP_NET,
246
+ to: S_WHATSAPP_NET,
309
247
  type: 'get'
310
248
  }
311
249
  });
312
- const listNode = (0, WABinary_1.getBinaryNodeChild)(result, 'list');
313
- return (0, WABinary_1.getBinaryNodeChildren)(listNode, 'item')
314
- .map(n => n.attrs.jid);
250
+ const listNode = getBinaryNodeChild(result, 'list');
251
+ return getBinaryNodeChildren(listNode, 'item').map(n => n.attrs.jid);
315
252
  };
316
253
  const updateBlockStatus = async (jid, action) => {
317
254
  await query({
318
255
  tag: 'iq',
319
256
  attrs: {
320
257
  xmlns: 'blocklist',
321
- to: WABinary_1.S_WHATSAPP_NET,
258
+ to: S_WHATSAPP_NET,
322
259
  type: 'set'
323
260
  },
324
261
  content: [
@@ -333,7 +270,6 @@ const makeChatsSocket = (config) => {
333
270
  });
334
271
  };
335
272
  const getBusinessProfile = async (jid) => {
336
- var _a, _b, _c, _d, _e, _f, _g;
337
273
  const results = await query({
338
274
  tag: 'iq',
339
275
  attrs: {
@@ -341,38 +277,42 @@ const makeChatsSocket = (config) => {
341
277
  xmlns: 'w:biz',
342
278
  type: 'get'
343
279
  },
344
- content: [{
280
+ content: [
281
+ {
345
282
  tag: 'business_profile',
346
283
  attrs: { v: '244' },
347
- content: [{
284
+ content: [
285
+ {
348
286
  tag: 'profile',
349
287
  attrs: { jid }
350
- }]
351
- }]
288
+ }
289
+ ]
290
+ }
291
+ ]
352
292
  });
353
- const profileNode = (0, WABinary_1.getBinaryNodeChild)(results, 'business_profile');
354
- const profiles = (0, WABinary_1.getBinaryNodeChild)(profileNode, 'profile');
293
+ const profileNode = getBinaryNodeChild(results, 'business_profile');
294
+ const profiles = getBinaryNodeChild(profileNode, 'profile');
355
295
  if (profiles) {
356
- const address = (0, WABinary_1.getBinaryNodeChild)(profiles, 'address');
357
- const description = (0, WABinary_1.getBinaryNodeChild)(profiles, 'description');
358
- const website = (0, WABinary_1.getBinaryNodeChild)(profiles, 'website');
359
- const email = (0, WABinary_1.getBinaryNodeChild)(profiles, 'email');
360
- const category = (0, WABinary_1.getBinaryNodeChild)((0, WABinary_1.getBinaryNodeChild)(profiles, 'categories'), 'category');
361
- const businessHours = (0, WABinary_1.getBinaryNodeChild)(profiles, 'business_hours');
296
+ const address = getBinaryNodeChild(profiles, 'address');
297
+ const description = getBinaryNodeChild(profiles, 'description');
298
+ const website = getBinaryNodeChild(profiles, 'website');
299
+ const email = getBinaryNodeChild(profiles, 'email');
300
+ const category = getBinaryNodeChild(getBinaryNodeChild(profiles, 'categories'), 'category');
301
+ const businessHours = getBinaryNodeChild(profiles, 'business_hours');
362
302
  const businessHoursConfig = businessHours
363
- ? (0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config')
303
+ ? getBinaryNodeChildren(businessHours, 'business_hours_config')
364
304
  : undefined;
365
- const websiteStr = (_a = website === null || website === void 0 ? void 0 : website.content) === null || _a === void 0 ? void 0 : _a.toString();
305
+ const websiteStr = website?.content?.toString();
366
306
  return {
367
- wid: (_b = profiles.attrs) === null || _b === void 0 ? void 0 : _b.jid,
368
- address: (_c = address === null || address === void 0 ? void 0 : address.content) === null || _c === void 0 ? void 0 : _c.toString(),
369
- description: ((_d = description === null || description === void 0 ? void 0 : description.content) === null || _d === void 0 ? void 0 : _d.toString()) || '',
307
+ wid: profiles.attrs?.jid,
308
+ address: address?.content?.toString(),
309
+ description: description?.content?.toString() || '',
370
310
  website: websiteStr ? [websiteStr] : [],
371
- email: (_e = email === null || email === void 0 ? void 0 : email.content) === null || _e === void 0 ? void 0 : _e.toString(),
372
- category: (_f = category === null || category === void 0 ? void 0 : category.content) === null || _f === void 0 ? void 0 : _f.toString(),
373
- 'business_hours': {
374
- timezone: (_g = businessHours === null || businessHours === void 0 ? void 0 : businessHours.attrs) === null || _g === void 0 ? void 0 : _g.timezone,
375
- 'business_config': businessHoursConfig === null || businessHoursConfig === void 0 ? void 0 : businessHoursConfig.map(({ attrs }) => attrs)
311
+ email: email?.content?.toString(),
312
+ category: category?.content?.toString(),
313
+ business_hours: {
314
+ timezone: businessHours?.attrs?.timezone,
315
+ business_config: businessHoursConfig?.map(({ attrs }) => attrs)
376
316
  }
377
317
  };
378
318
  }
@@ -382,17 +322,17 @@ const makeChatsSocket = (config) => {
382
322
  await sendNode({
383
323
  tag: 'iq',
384
324
  attrs: {
385
- to: WABinary_1.S_WHATSAPP_NET,
325
+ to: S_WHATSAPP_NET,
386
326
  type: 'set',
387
327
  xmlns: 'urn:xmpp:whatsapp:dirty',
388
- id: generateMessageTag(),
328
+ id: generateMessageTag()
389
329
  },
390
330
  content: [
391
331
  {
392
332
  tag: 'clean',
393
333
  attrs: {
394
334
  type,
395
- ...(fromTimestamp ? { timestamp: fromTimestamp.toString() } : null),
335
+ ...(fromTimestamp ? { timestamp: fromTimestamp.toString() } : null)
396
336
  }
397
337
  }
398
338
  ]
@@ -401,7 +341,7 @@ const makeChatsSocket = (config) => {
401
341
  const newAppStateChunkHandler = (isInitialSync) => {
402
342
  return {
403
343
  onMutation(mutation) {
404
- (0, Utils_1.processSyncAction)(mutation, ev, authState.creds.me, isInitialSync ? { accountSettings: authState.creds.accountSettings } : undefined, logger);
344
+ processSyncAction(mutation, ev, authState.creds.me, isInitialSync ? { accountSettings: authState.creds.accountSettings } : undefined, logger);
405
345
  }
406
346
  };
407
347
  };
@@ -411,7 +351,6 @@ const makeChatsSocket = (config) => {
411
351
  const initialVersionMap = {};
412
352
  const globalMutationMap = {};
413
353
  await authState.keys.transaction(async () => {
414
- var _a;
415
354
  const collectionsToHandle = new Set(collections);
416
355
  // in case something goes wrong -- ensure we don't enter a loop that cannot be exited from
417
356
  const attemptsMap = {};
@@ -430,7 +369,7 @@ const makeChatsSocket = (config) => {
430
369
  }
431
370
  }
432
371
  else {
433
- state = (0, Utils_1.newLTHashState)();
372
+ state = newLTHashState();
434
373
  }
435
374
  states[name] = state;
436
375
  logger.info(`resyncing ${name} from v${state.version}`);
@@ -440,14 +379,14 @@ const makeChatsSocket = (config) => {
440
379
  name,
441
380
  version: state.version.toString(),
442
381
  // return snapshot if being synced from scratch
443
- 'return_snapshot': (!state.version).toString()
382
+ return_snapshot: (!state.version).toString()
444
383
  }
445
384
  });
446
385
  }
447
386
  const result = await query({
448
387
  tag: 'iq',
449
388
  attrs: {
450
- to: WABinary_1.S_WHATSAPP_NET,
389
+ to: S_WHATSAPP_NET,
451
390
  xmlns: 'w:sync:app:state',
452
391
  type: 'set'
453
392
  },
@@ -460,13 +399,13 @@ const makeChatsSocket = (config) => {
460
399
  ]
461
400
  });
462
401
  // extract from binary node
463
- const decoded = await (0, Utils_1.extractSyncdPatches)(result, config === null || config === void 0 ? void 0 : config.options);
402
+ const decoded = await extractSyncdPatches(result, config?.options);
464
403
  for (const key in decoded) {
465
404
  const name = key;
466
405
  const { patches, hasMorePatches, snapshot } = decoded[name];
467
406
  try {
468
407
  if (snapshot) {
469
- const { state: newState, mutationMap } = await (0, Utils_1.decodeSyncdSnapshot)(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot);
408
+ const { state: newState, mutationMap } = await decodeSyncdSnapshot(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot);
470
409
  states[name] = newState;
471
410
  Object.assign(globalMutationMap, mutationMap);
472
411
  logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
@@ -474,7 +413,7 @@ const makeChatsSocket = (config) => {
474
413
  }
475
414
  // only process if there are syncd patches
476
415
  if (patches.length) {
477
- const { state: newState, mutationMap } = await (0, Utils_1.decodePatches)(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
416
+ const { state: newState, mutationMap } = await decodePatches(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
478
417
  await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
479
418
  logger.info(`synced ${name} to v${newState.version}`);
480
419
  initialVersionMap[name] = newState.version;
@@ -483,16 +422,17 @@ const makeChatsSocket = (config) => {
483
422
  if (hasMorePatches) {
484
423
  logger.info(`${name} has more patches...`);
485
424
  }
486
- else { // collection is done with sync
425
+ else {
426
+ // collection is done with sync
487
427
  collectionsToHandle.delete(name);
488
428
  }
489
429
  }
490
430
  catch (error) {
491
431
  // if retry attempts overshoot
492
432
  // or key not found
493
- const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS
494
- || ((_a = error.output) === null || _a === void 0 ? void 0 : _a.statusCode) === 404
495
- || error.name === 'TypeError';
433
+ const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS ||
434
+ error.output?.statusCode === 404 ||
435
+ error.name === 'TypeError';
496
436
  logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
497
437
  await authState.keys.set({ 'app-state-sync-version': { [name]: null } });
498
438
  // increment number of retries
@@ -504,7 +444,7 @@ const makeChatsSocket = (config) => {
504
444
  }
505
445
  }
506
446
  }
507
- });
447
+ }, authState?.creds?.me?.id || 'resync-app-state');
508
448
  const { onMutation } = newAppStateChunkHandler(isInitialSync);
509
449
  for (const key in globalMutationMap) {
510
450
  onMutation(globalMutationMap[key]);
@@ -516,22 +456,38 @@ const makeChatsSocket = (config) => {
516
456
  * type = "image for the high res picture"
517
457
  */
518
458
  const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
519
- var _a;
520
- jid = (0, WABinary_1.jidNormalizedUser)(jid);
459
+ // TOOD: Add support for tctoken, existingID, and newsletter + group options
460
+ jid = jidNormalizedUser(jid);
521
461
  const result = await query({
522
462
  tag: 'iq',
523
463
  attrs: {
524
464
  target: jid,
525
- to: WABinary_1.S_WHATSAPP_NET,
465
+ to: S_WHATSAPP_NET,
526
466
  type: 'get',
527
467
  xmlns: 'w:profile:picture'
528
468
  },
469
+ content: [{ tag: 'picture', attrs: { type, query: 'url' } }]
470
+ }, timeoutMs);
471
+ const child = getBinaryNodeChild(result, 'picture');
472
+ return child?.attrs?.url;
473
+ };
474
+ const createCallLink = async (type, event, timeoutMs) => {
475
+ const result = await query({
476
+ tag: 'call',
477
+ attrs: {
478
+ id: generateMessageTag(),
479
+ to: '@call'
480
+ },
529
481
  content: [
530
- { tag: 'picture', attrs: { type, query: 'url' } }
482
+ {
483
+ tag: 'link_create',
484
+ attrs: { media: type },
485
+ content: event ? [{ tag: 'event', attrs: { start_time: String(event.startTime) } }] : undefined
486
+ }
531
487
  ]
532
488
  }, timeoutMs);
533
- const child = (0, WABinary_1.getBinaryNodeChild)(result, 'picture');
534
- return (_a = child === null || child === void 0 ? void 0 : child.attrs) === null || _a === void 0 ? void 0 : _a.url;
489
+ const child = getBinaryNodeChild(result, 'link_create');
490
+ return child?.attrs?.token;
535
491
  };
536
492
  const sendPresenceUpdate = async (type, toJid) => {
537
493
  const me = authState.creds.me;
@@ -550,13 +506,13 @@ const makeChatsSocket = (config) => {
550
506
  });
551
507
  }
552
508
  else {
553
- const { server } = (0, WABinary_1.jidDecode)(toJid);
509
+ const { server } = jidDecode(toJid);
554
510
  const isLid = server === 'lid';
555
511
  await sendNode({
556
512
  tag: 'chatstate',
557
513
  attrs: {
558
514
  from: isLid ? me.lid : me.id,
559
- to: toJid,
515
+ to: toJid
560
516
  },
561
517
  content: [
562
518
  {
@@ -571,7 +527,7 @@ const makeChatsSocket = (config) => {
571
527
  * @param toJid the jid to subscribe to
572
528
  * @param tcToken token for subscription, use if present
573
529
  */
574
- const presenceSubscribe = (toJid, tcToken) => (sendNode({
530
+ const presenceSubscribe = (toJid, tcToken) => sendNode({
575
531
  tag: 'presence',
576
532
  attrs: {
577
533
  to: toJid,
@@ -587,13 +543,12 @@ const makeChatsSocket = (config) => {
587
543
  }
588
544
  ]
589
545
  : undefined
590
- }));
546
+ });
591
547
  const handlePresenceUpdate = ({ tag, attrs, content }) => {
592
- var _a;
593
548
  let presence;
594
549
  const jid = attrs.from;
595
550
  const participant = attrs.participant || attrs.from;
596
- if (shouldIgnoreJid(jid) && jid != '@s.whatsapp.net') {
551
+ if (shouldIgnoreJid(jid) && jid !== S_WHATSAPP_NET) {
597
552
  return;
598
553
  }
599
554
  if (tag === 'presence') {
@@ -608,7 +563,7 @@ const makeChatsSocket = (config) => {
608
563
  if (type === 'paused') {
609
564
  type = 'available';
610
565
  }
611
- if (((_a = firstChild.attrs) === null || _a === void 0 ? void 0 : _a.media) === 'audio') {
566
+ if (firstChild.attrs?.media === 'audio') {
612
567
  type = 'recording';
613
568
  }
614
569
  presence = { lastKnownPresence: type };
@@ -624,7 +579,7 @@ const makeChatsSocket = (config) => {
624
579
  const name = patchCreate.type;
625
580
  const myAppStateKeyId = authState.creds.myAppStateKeyId;
626
581
  if (!myAppStateKeyId) {
627
- throw new boom_1.Boom('App state key not present!', { statusCode: 400 });
582
+ throw new Boom('App state key not present!', { statusCode: 400 });
628
583
  }
629
584
  let initial;
630
585
  let encodeResult;
@@ -633,13 +588,13 @@ const makeChatsSocket = (config) => {
633
588
  logger.debug({ patch: patchCreate }, 'applying app patch');
634
589
  await resyncAppState([name], false);
635
590
  const { [name]: currentSyncVersion } = await authState.keys.get('app-state-sync-version', [name]);
636
- initial = currentSyncVersion || (0, Utils_1.newLTHashState)();
637
- encodeResult = await (0, Utils_1.encodeSyncdPatch)(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey);
591
+ initial = currentSyncVersion || newLTHashState();
592
+ encodeResult = await encodeSyncdPatch(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey);
638
593
  const { patch, state } = encodeResult;
639
594
  const node = {
640
595
  tag: 'iq',
641
596
  attrs: {
642
- to: WABinary_1.S_WHATSAPP_NET,
597
+ to: S_WHATSAPP_NET,
643
598
  type: 'set',
644
599
  xmlns: 'w:sync:app:state'
645
600
  },
@@ -653,13 +608,13 @@ const makeChatsSocket = (config) => {
653
608
  attrs: {
654
609
  name,
655
610
  version: (state.version - 1).toString(),
656
- 'return_snapshot': 'false'
611
+ return_snapshot: 'false'
657
612
  },
658
613
  content: [
659
614
  {
660
615
  tag: 'patch',
661
616
  attrs: {},
662
- content: WAProto_1.proto.SyncdPatch.encode(patch).finish()
617
+ content: proto.SyncdPatch.encode(patch).finish()
663
618
  }
664
619
  ]
665
620
  }
@@ -669,11 +624,11 @@ const makeChatsSocket = (config) => {
669
624
  };
670
625
  await query(node);
671
626
  await authState.keys.set({ 'app-state-sync-version': { [name]: state } });
672
- });
627
+ }, authState?.creds?.me?.id || 'app-patch');
673
628
  });
674
629
  if (config.emitOwnEvents) {
675
630
  const { onMutation } = newAppStateChunkHandler(false);
676
- const { mutationMap } = await (0, Utils_1.decodePatches)(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version }, }], initial, getAppStateSyncKey, config.options, undefined, logger);
631
+ const { mutationMap } = await decodePatches(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version } }], initial, getAppStateSyncKey, config.options, undefined, logger);
677
632
  for (const key in mutationMap) {
678
633
  onMutation(mutationMap[key]);
679
634
  }
@@ -681,29 +636,33 @@ const makeChatsSocket = (config) => {
681
636
  };
682
637
  /** sending non-abt props may fix QR scan fail if server expects */
683
638
  const fetchProps = async () => {
684
- var _a, _b, _c;
639
+ //TODO: implement both protocol 1 and protocol 2 prop fetching, specially for abKey for WM
685
640
  const resultNode = await query({
686
641
  tag: 'iq',
687
642
  attrs: {
688
- to: WABinary_1.S_WHATSAPP_NET,
643
+ to: S_WHATSAPP_NET,
689
644
  xmlns: 'w',
690
- type: 'get',
645
+ type: 'get'
691
646
  },
692
647
  content: [
693
- { tag: 'props', attrs: {
648
+ {
649
+ tag: 'props',
650
+ attrs: {
694
651
  protocol: '2',
695
- hash: ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.lastPropHash) || ''
696
- } }
652
+ hash: authState?.creds?.lastPropHash || ''
653
+ }
654
+ }
697
655
  ]
698
656
  });
699
- const propsNode = (0, WABinary_1.getBinaryNodeChild)(resultNode, 'props');
657
+ const propsNode = getBinaryNodeChild(resultNode, 'props');
700
658
  let props = {};
701
659
  if (propsNode) {
702
- if ((_b = propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash) { // on some clients, the hash is returning as undefined
703
- authState.creds.lastPropHash = (_c = propsNode === null || propsNode === void 0 ? void 0 : propsNode.attrs) === null || _c === void 0 ? void 0 : _c.hash;
660
+ if (propsNode.attrs?.hash) {
661
+ // on some clients, the hash is returning as undefined
662
+ authState.creds.lastPropHash = propsNode?.attrs?.hash;
704
663
  ev.emit('creds.update', authState.creds);
705
664
  }
706
- props = (0, WABinary_1.reduceBinaryNodeToDictionary)(propsNode, 'prop');
665
+ props = reduceBinaryNodeToDictionary(propsNode, 'prop');
707
666
  }
708
667
  logger.debug('fetched props');
709
668
  return props;
@@ -712,9 +671,9 @@ const makeChatsSocket = (config) => {
712
671
  * modify a chat -- mark unread, read etc.
713
672
  * lastMessages must be sorted in reverse chronologically
714
673
  * requires the last messages till the last message received; required for archive & unread
715
- */
674
+ */
716
675
  const chatModify = (mod, jid) => {
717
- const patch = (0, Utils_1.chatModificationToAppPatch)(mod, jid);
676
+ const patch = chatModificationToAppPatch(mod, jid);
718
677
  return appPatch(patch);
719
678
  };
720
679
  /**
@@ -752,6 +711,16 @@ const makeChatsSocket = (config) => {
752
711
  contact: null
753
712
  }, jid);
754
713
  };
714
+ /**
715
+ * Adds label
716
+ */
717
+ const addLabel = (jid, labels) => {
718
+ return chatModify({
719
+ addLabel: {
720
+ ...labels
721
+ }
722
+ }, jid);
723
+ };
755
724
  /**
756
725
  * Adds label for the chats
757
726
  */
@@ -794,81 +763,102 @@ const makeChatsSocket = (config) => {
794
763
  }
795
764
  }, jid);
796
765
  };
766
+ /**
767
+ * Add or Edit Quick Reply
768
+ */
769
+ const addOrEditQuickReply = (quickReply) => {
770
+ return chatModify({
771
+ quickReply
772
+ }, '');
773
+ };
774
+ /**
775
+ * Remove Quick Reply
776
+ */
777
+ const removeQuickReply = (timestamp) => {
778
+ return chatModify({
779
+ quickReply: { timestamp, deleted: true }
780
+ }, '');
781
+ };
797
782
  /**
798
783
  * queries need to be fired on connection open
799
784
  * help ensure parity with WA Web
800
785
  * */
801
786
  const executeInitQueries = async () => {
802
- await Promise.all([
803
- fetchProps(),
804
- fetchBlocklist(),
805
- fetchPrivacySettings(),
806
- ]);
787
+ await Promise.all([fetchProps(), fetchBlocklist(), fetchPrivacySettings()]);
807
788
  };
808
789
  const upsertMessage = ev.createBufferedFunction(async (msg, type) => {
809
- var _a, _b, _c;
810
790
  ev.emit('messages.upsert', { messages: [msg], type });
811
791
  if (!!msg.pushName) {
812
- let jid = msg.key.fromMe ? authState.creds.me.id : (msg.key.participant || msg.key.remoteJid);
813
- jid = (0, WABinary_1.jidNormalizedUser)(jid);
792
+ let jid = msg.key.fromMe ? authState.creds.me.id : msg.key.participant || msg.key.remoteJid;
793
+ jid = jidNormalizedUser(jid);
814
794
  if (!msg.key.fromMe) {
815
795
  ev.emit('contacts.update', [{ id: jid, notify: msg.pushName, verifiedName: msg.verifiedBizName }]);
816
796
  }
817
797
  // update our pushname too
818
- if (msg.key.fromMe && msg.pushName && ((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.name) !== msg.pushName) {
798
+ if (msg.key.fromMe && msg.pushName && authState.creds.me?.name !== msg.pushName) {
819
799
  ev.emit('creds.update', { me: { ...authState.creds.me, name: msg.pushName } });
820
800
  }
821
801
  }
822
- const historyMsg = (0, Utils_1.getHistoryMsg)(msg.message);
802
+ const historyMsg = getHistoryMsg(msg.message);
823
803
  const shouldProcessHistoryMsg = historyMsg
824
- ? (shouldSyncHistoryMessage(historyMsg)
825
- && Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType))
804
+ ? shouldSyncHistoryMessage(historyMsg) && PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType)
826
805
  : false;
827
- if (historyMsg && !authState.creds.myAppStateKeyId) {
828
- logger.warn('skipping app state sync, as myAppStateKeyId is not set');
829
- pendingAppStateSync = true;
806
+ // State machine: decide on sync and flush
807
+ if (historyMsg && syncState === SyncState.AwaitingInitialSync) {
808
+ if (awaitingSyncTimeout) {
809
+ clearTimeout(awaitingSyncTimeout);
810
+ awaitingSyncTimeout = undefined;
811
+ }
812
+ if (shouldProcessHistoryMsg) {
813
+ syncState = SyncState.Syncing;
814
+ logger.info('Transitioned to Syncing state');
815
+ // Let doAppStateSync handle the final flush after it's done
816
+ }
817
+ else {
818
+ syncState = SyncState.Online;
819
+ logger.info('History sync skipped, transitioning to Online state and flushing buffer');
820
+ ev.flush();
821
+ }
830
822
  }
823
+ const doAppStateSync = async () => {
824
+ if (syncState === SyncState.Syncing) {
825
+ logger.info('Doing app state sync');
826
+ await resyncAppState(ALL_WA_PATCH_NAMES, true);
827
+ // Sync is complete, go online and flush everything
828
+ syncState = SyncState.Online;
829
+ logger.info('App state sync complete, transitioning to Online state and flushing buffer');
830
+ ev.flush();
831
+ const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
832
+ ev.emit('creds.update', { accountSyncCounter });
833
+ }
834
+ };
831
835
  await Promise.all([
832
836
  (async () => {
833
- if (historyMsg
834
- && authState.creds.myAppStateKeyId) {
835
- pendingAppStateSync = false;
837
+ if (shouldProcessHistoryMsg) {
836
838
  await doAppStateSync();
837
839
  }
838
840
  })(),
839
- (0, process_message_1.default)(msg, {
841
+ processMessage(msg, {
842
+ signalRepository,
840
843
  shouldProcessHistoryMsg,
841
844
  placeholderResendCache,
842
845
  ev,
843
846
  creds: authState.creds,
844
847
  keyStore: authState.keys,
845
848
  logger,
846
- options: config.options,
847
- getMessage: config.getMessage,
849
+ options: config.options
848
850
  })
849
851
  ]);
850
- if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare)
851
- && pendingAppStateSync) {
852
+ // If the app state key arrives and we are waiting to sync, trigger the sync now.
853
+ if (msg.message?.protocolMessage?.appStateSyncKeyShare && syncState === SyncState.Syncing) {
854
+ logger.info('App state sync key arrived, triggering app state sync');
852
855
  await doAppStateSync();
853
- pendingAppStateSync = false;
854
- }
855
- async function doAppStateSync() {
856
- if (!authState.creds.accountSyncCounter) {
857
- logger.info('doing initial app state sync');
858
- await resyncAppState(Types_1.ALL_WA_PATCH_NAMES, true);
859
- const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
860
- ev.emit('creds.update', { accountSyncCounter });
861
- if (needToFlushWithAppStateSync) {
862
- logger.debug('flushing with app state sync');
863
- ev.flush();
864
- }
865
- }
866
856
  }
867
857
  });
868
858
  ws.on('CB:presence', handlePresenceUpdate);
869
859
  ws.on('CB:chatstate', handlePresenceUpdate);
870
860
  ws.on('CB:ib,,dirty', async (node) => {
871
- const { attrs } = (0, WABinary_1.getBinaryNodeChild)(node, 'dirty');
861
+ const { attrs } = getBinaryNodeChild(node, 'dirty');
872
862
  const type = attrs.type;
873
863
  switch (type) {
874
864
  case 'account_sync':
@@ -890,25 +880,43 @@ const makeChatsSocket = (config) => {
890
880
  }
891
881
  });
892
882
  ev.on('connection.update', ({ connection, receivedPendingNotifications }) => {
893
- var _a;
894
883
  if (connection === 'open') {
895
884
  if (fireInitQueries) {
896
- executeInitQueries()
897
- .catch(error => onUnexpectedError(error, 'init queries'));
885
+ executeInitQueries().catch(error => onUnexpectedError(error, 'init queries'));
898
886
  }
899
- sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
900
- .catch(error => onUnexpectedError(error, 'presence update requests'));
887
+ sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable').catch(error => onUnexpectedError(error, 'presence update requests'));
901
888
  }
902
- if (receivedPendingNotifications && // if we don't have the app state key
903
- // we keep buffering events until we finally have
904
- // the key and can sync the messages
905
- !((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId)) {
906
- ev.buffer();
907
- needToFlushWithAppStateSync = true;
889
+ if (!receivedPendingNotifications || syncState !== SyncState.Connecting) {
890
+ return;
891
+ }
892
+ syncState = SyncState.AwaitingInitialSync;
893
+ logger.info('Connection is now AwaitingInitialSync, buffering events');
894
+ ev.buffer();
895
+ const willSyncHistory = shouldSyncHistoryMessage(proto.Message.HistorySyncNotification.create({
896
+ syncType: proto.HistorySync.HistorySyncType.RECENT
897
+ }));
898
+ if (!willSyncHistory) {
899
+ logger.info('History sync is disabled by config, not waiting for notification. Transitioning to Online.');
900
+ syncState = SyncState.Online;
901
+ setTimeout(() => ev.flush(), 0);
902
+ return;
903
+ }
904
+ logger.info('History sync is enabled, awaiting notification with a 20s timeout.');
905
+ if (awaitingSyncTimeout) {
906
+ clearTimeout(awaitingSyncTimeout);
908
907
  }
908
+ awaitingSyncTimeout = setTimeout(() => {
909
+ if (syncState === SyncState.AwaitingInitialSync) {
910
+ // TODO: investigate
911
+ logger.warn('Timeout in AwaitingInitialSync, forcing state to Online and flushing buffer');
912
+ syncState = SyncState.Online;
913
+ ev.flush();
914
+ }
915
+ }, 20000);
909
916
  });
910
917
  return {
911
918
  ...sock,
919
+ createCallLink,
912
920
  getBotListV2,
913
921
  processingMutex,
914
922
  fetchPrivacySettings,
@@ -917,10 +925,9 @@ const makeChatsSocket = (config) => {
917
925
  sendPresenceUpdate,
918
926
  presenceSubscribe,
919
927
  profilePictureUrl,
920
- onWhatsApp,
921
928
  fetchBlocklist,
922
- fetchDisappearingDuration,
923
929
  fetchStatus,
930
+ fetchDisappearingDuration,
924
931
  updateProfilePicture,
925
932
  removeProfilePicture,
926
933
  updateProfileStatus,
@@ -942,11 +949,14 @@ const makeChatsSocket = (config) => {
942
949
  cleanDirtyBits,
943
950
  addOrEditContact,
944
951
  removeContact,
952
+ addLabel,
945
953
  addChatLabel,
946
954
  removeChatLabel,
947
955
  addMessageLabel,
948
956
  removeMessageLabel,
949
- star
957
+ star,
958
+ addOrEditQuickReply,
959
+ removeQuickReply
950
960
  };
951
961
  };
952
- exports.makeChatsSocket = makeChatsSocket;
962
+ //# sourceMappingURL=chats.js.map