@neelegirl/baileys 1.5.2 → 1.5.4

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 (419) hide show
  1. package/README.md +26 -18
  2. package/WAProto/GenerateStatics.sh +3 -0
  3. package/WAProto/WAProto.proto +291 -665
  4. package/WAProto/fix-imports.js +29 -0
  5. package/WAProto/index.d.ts +2297 -48040
  6. package/WAProto/index.js +45500 -140101
  7. package/engine-requirements.js +10 -0
  8. package/lib/Defaults/index.d.ts +58 -64
  9. package/lib/Defaults/index.d.ts.map +1 -0
  10. package/lib/Defaults/index.js +74 -96
  11. package/lib/Defaults/index.js.map +1 -0
  12. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  13. package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
  14. package/lib/Signal/Group/ciphertext-message.js +12 -0
  15. package/lib/Signal/Group/ciphertext-message.js.map +1 -0
  16. package/lib/Signal/Group/group-session-builder.d.ts +15 -0
  17. package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
  18. package/lib/Signal/Group/group-session-builder.js +30 -0
  19. package/lib/Signal/Group/group-session-builder.js.map +1 -0
  20. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  21. package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
  22. package/lib/Signal/Group/group_cipher.js +82 -0
  23. package/lib/Signal/Group/group_cipher.js.map +1 -0
  24. package/lib/Signal/Group/index.d.ts +12 -0
  25. package/lib/Signal/Group/index.d.ts.map +1 -0
  26. package/lib/Signal/Group/index.js +12 -0
  27. package/lib/Signal/Group/index.js.map +1 -0
  28. package/lib/Signal/Group/keyhelper.d.ts +11 -0
  29. package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
  30. package/lib/Signal/Group/keyhelper.js +18 -0
  31. package/lib/Signal/Group/keyhelper.js.map +1 -0
  32. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  33. package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
  34. package/lib/Signal/Group/sender-chain-key.js +26 -0
  35. package/lib/Signal/Group/sender-chain-key.js.map +1 -0
  36. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  37. package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
  38. package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
  39. package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
  40. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  41. package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
  42. package/lib/Signal/Group/sender-key-message.js +66 -0
  43. package/lib/Signal/Group/sender-key-message.js.map +1 -0
  44. package/lib/Signal/Group/sender-key-name.d.ts +18 -0
  45. package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
  46. package/lib/Signal/Group/sender-key-name.js +48 -0
  47. package/lib/Signal/Group/sender-key-name.js.map +1 -0
  48. package/lib/Signal/Group/sender-key-record.d.ts +31 -0
  49. package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
  50. package/lib/Signal/Group/sender-key-record.js +41 -0
  51. package/lib/Signal/Group/sender-key-record.js.map +1 -0
  52. package/lib/Signal/Group/sender-key-state.d.ts +39 -0
  53. package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
  54. package/lib/Signal/Group/sender-key-state.js +84 -0
  55. package/lib/Signal/Group/sender-key-state.js.map +1 -0
  56. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  57. package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
  58. package/lib/Signal/{WASignalGroup/sender_message_key.js → Group/sender-message-key.js} +3 -16
  59. package/lib/Signal/Group/sender-message-key.js.map +1 -0
  60. package/lib/Signal/libsignal.d.ts +5 -4
  61. package/lib/Signal/libsignal.d.ts.map +1 -0
  62. package/lib/Signal/libsignal.js +292 -112
  63. package/lib/Signal/libsignal.js.map +1 -0
  64. package/lib/Signal/lid-mapping.d.ts +23 -0
  65. package/lib/Signal/lid-mapping.d.ts.map +1 -0
  66. package/lib/Signal/lid-mapping.js +171 -0
  67. package/lib/Signal/lid-mapping.js.map +1 -0
  68. package/lib/Socket/Client/index.d.ts +3 -2
  69. package/lib/Socket/Client/index.d.ts.map +1 -0
  70. package/lib/Socket/Client/index.js +3 -22
  71. package/lib/Socket/Client/index.js.map +1 -0
  72. package/lib/Socket/Client/types.d.ts +15 -15
  73. package/lib/Socket/Client/types.d.ts.map +1 -0
  74. package/lib/Socket/Client/types.js +8 -15
  75. package/lib/Socket/Client/types.js.map +1 -0
  76. package/lib/Socket/Client/websocket.d.ts +12 -12
  77. package/lib/Socket/Client/websocket.d.ts.map +1 -0
  78. package/lib/Socket/Client/websocket.js +24 -36
  79. package/lib/Socket/Client/websocket.js.map +1 -0
  80. package/lib/Socket/business.d.ts +178 -177
  81. package/lib/Socket/business.d.ts.map +1 -0
  82. package/lib/Socket/business.js +179 -71
  83. package/lib/Socket/business.js.map +1 -0
  84. package/lib/Socket/chats.d.ts +93 -93
  85. package/lib/Socket/chats.d.ts.map +1 -0
  86. package/lib/Socket/chats.js +474 -625
  87. package/lib/Socket/chats.js.map +1 -0
  88. package/lib/Socket/communities.d.ts +83 -62
  89. package/lib/Socket/communities.d.ts.map +1 -0
  90. package/lib/Socket/communities.js +412 -414
  91. package/lib/Socket/communities.js.map +1 -0
  92. package/lib/Socket/groups.d.ts +118 -112
  93. package/lib/Socket/groups.d.ts.map +1 -0
  94. package/lib/Socket/groups.js +146 -171
  95. package/lib/Socket/groups.js.map +1 -0
  96. package/lib/Socket/index.d.ts +222 -182
  97. package/lib/Socket/index.d.ts.map +1 -0
  98. package/lib/Socket/index.js +12 -17
  99. package/lib/Socket/index.js.map +1 -0
  100. package/lib/Socket/messages-recv.d.ts +165 -169
  101. package/lib/Socket/messages-recv.d.ts.map +1 -0
  102. package/lib/Socket/messages-recv.js +1185 -1721
  103. package/lib/Socket/messages-recv.js.map +1 -0
  104. package/lib/Socket/messages-send.d.ts +161 -159
  105. package/lib/Socket/messages-send.d.ts.map +1 -0
  106. package/lib/Socket/messages-send.js +650 -991
  107. package/lib/Socket/messages-send.js.map +1 -0
  108. package/lib/Socket/mex.d.ts +1 -0
  109. package/lib/Socket/mex.d.ts.map +1 -0
  110. package/lib/Socket/mex.js +4 -9
  111. package/lib/Socket/mex.js.map +1 -0
  112. package/lib/Socket/newsletter.d.ts +139 -139
  113. package/lib/Socket/newsletter.d.ts.map +1 -0
  114. package/lib/Socket/newsletter.js +153 -258
  115. package/lib/Socket/newsletter.js.map +1 -0
  116. package/lib/Socket/socket.d.ts +42 -36
  117. package/lib/Socket/socket.d.ts.map +1 -0
  118. package/lib/Socket/socket.js +623 -507
  119. package/lib/Socket/socket.js.map +1 -0
  120. package/lib/Types/Auth.d.ts +87 -96
  121. package/lib/Types/Auth.d.ts.map +1 -0
  122. package/lib/Types/Auth.js +2 -3
  123. package/lib/Types/Auth.js.map +1 -0
  124. package/lib/Types/Bussines.d.ts +25 -0
  125. package/lib/Types/Bussines.d.ts.map +1 -0
  126. package/lib/Types/Bussines.js +2 -0
  127. package/lib/Types/Bussines.js.map +1 -0
  128. package/lib/Types/Call.d.ts +13 -13
  129. package/lib/Types/Call.d.ts.map +1 -0
  130. package/lib/Types/Call.js +2 -3
  131. package/lib/Types/Call.js.map +1 -0
  132. package/lib/Types/Chat.d.ts +79 -94
  133. package/lib/Types/Chat.d.ts.map +1 -0
  134. package/lib/Types/Chat.js +8 -9
  135. package/lib/Types/Chat.js.map +1 -0
  136. package/lib/Types/Contact.d.ts +13 -9
  137. package/lib/Types/Contact.d.ts.map +1 -0
  138. package/lib/Types/Contact.js +2 -3
  139. package/lib/Types/Contact.js.map +1 -0
  140. package/lib/Types/Events.d.ts +152 -179
  141. package/lib/Types/Events.d.ts.map +1 -0
  142. package/lib/Types/Events.js +2 -3
  143. package/lib/Types/Events.js.map +1 -0
  144. package/lib/Types/GroupMetadata.d.ts +49 -48
  145. package/lib/Types/GroupMetadata.d.ts.map +1 -0
  146. package/lib/Types/GroupMetadata.js +2 -3
  147. package/lib/Types/GroupMetadata.js.map +1 -0
  148. package/lib/Types/Label.d.ts +13 -14
  149. package/lib/Types/Label.d.ts.map +1 -0
  150. package/lib/Types/Label.js +24 -30
  151. package/lib/Types/Label.js.map +1 -0
  152. package/lib/Types/LabelAssociation.d.ts +15 -20
  153. package/lib/Types/LabelAssociation.d.ts.map +1 -0
  154. package/lib/Types/LabelAssociation.js +6 -12
  155. package/lib/Types/LabelAssociation.js.map +1 -0
  156. package/lib/Types/Message.d.ts +234 -404
  157. package/lib/Types/Message.d.ts.map +1 -0
  158. package/lib/Types/Message.js +11 -13
  159. package/lib/Types/Message.js.map +1 -0
  160. package/lib/Types/Newsletter.d.ts +130 -104
  161. package/lib/Types/Newsletter.d.ts.map +1 -0
  162. package/lib/Types/Newsletter.js +31 -40
  163. package/lib/Types/Newsletter.js.map +1 -0
  164. package/lib/Types/Product.d.ts +58 -71
  165. package/lib/Types/Product.d.ts.map +1 -0
  166. package/lib/Types/Product.js +2 -3
  167. package/lib/Types/Product.js.map +1 -0
  168. package/lib/Types/Signal.d.ts +63 -55
  169. package/lib/Types/Signal.d.ts.map +1 -0
  170. package/lib/Types/Signal.js +2 -3
  171. package/lib/Types/Signal.js.map +1 -0
  172. package/lib/Types/Socket.d.ts +78 -65
  173. package/lib/Types/Socket.d.ts.map +1 -0
  174. package/lib/Types/Socket.js +3 -3
  175. package/lib/Types/Socket.js.map +1 -0
  176. package/lib/Types/State.d.ts +17 -19
  177. package/lib/Types/State.d.ts.map +1 -0
  178. package/lib/Types/State.js +13 -14
  179. package/lib/Types/State.js.map +1 -0
  180. package/lib/Types/USync.d.ts +8 -8
  181. package/lib/Types/USync.d.ts.map +1 -0
  182. package/lib/Types/USync.js +2 -3
  183. package/lib/Types/USync.js.map +1 -0
  184. package/lib/Types/index.d.ts +47 -61
  185. package/lib/Types/index.d.ts.map +1 -0
  186. package/lib/Types/index.js +26 -48
  187. package/lib/Types/index.js.map +1 -0
  188. package/lib/Utils/auth-utils.d.ts +8 -10
  189. package/lib/Utils/auth-utils.d.ts.map +1 -0
  190. package/lib/Utils/auth-utils.js +206 -154
  191. package/lib/Utils/auth-utils.js.map +1 -0
  192. package/lib/Utils/baileys-event-stream.d.ts +6 -7
  193. package/lib/Utils/baileys-event-stream.d.ts.map +1 -0
  194. package/lib/Utils/baileys-event-stream.js +29 -43
  195. package/lib/Utils/baileys-event-stream.js.map +1 -0
  196. package/lib/Utils/browser-utils.d.ts +4 -0
  197. package/lib/Utils/browser-utils.d.ts.map +1 -0
  198. package/lib/Utils/browser-utils.js +28 -0
  199. package/lib/Utils/browser-utils.js.map +1 -0
  200. package/lib/Utils/business.d.ts +14 -20
  201. package/lib/Utils/business.d.ts.map +1 -0
  202. package/lib/Utils/business.js +110 -134
  203. package/lib/Utils/business.js.map +1 -0
  204. package/lib/Utils/chat-utils.d.ts +57 -69
  205. package/lib/Utils/chat-utils.d.ts.map +1 -0
  206. package/lib/Utils/chat-utils.js +362 -380
  207. package/lib/Utils/chat-utils.js.map +1 -0
  208. package/lib/Utils/crypto.d.ts +30 -45
  209. package/lib/Utils/crypto.d.ts.map +1 -0
  210. package/lib/Utils/crypto.js +141 -178
  211. package/lib/Utils/crypto.js.map +1 -0
  212. package/lib/Utils/decode-wa-message.d.ts +42 -35
  213. package/lib/Utils/decode-wa-message.d.ts.map +1 -0
  214. package/lib/Utils/decode-wa-message.js +176 -150
  215. package/lib/Utils/decode-wa-message.js.map +1 -0
  216. package/lib/Utils/event-buffer.d.ts +12 -17
  217. package/lib/Utils/event-buffer.d.ts.map +1 -0
  218. package/lib/Utils/event-buffer.js +269 -286
  219. package/lib/Utils/event-buffer.js.map +1 -0
  220. package/lib/Utils/generics.d.ts +60 -99
  221. package/lib/Utils/generics.d.ts.map +1 -0
  222. package/lib/Utils/generics.js +244 -487
  223. package/lib/Utils/generics.js.map +1 -0
  224. package/lib/Utils/history.d.ts +18 -22
  225. package/lib/Utils/history.d.ts.map +1 -0
  226. package/lib/Utils/history.js +54 -80
  227. package/lib/Utils/history.js.map +1 -0
  228. package/lib/Utils/index.d.ts +20 -19
  229. package/lib/Utils/index.d.ts.map +1 -0
  230. package/lib/Utils/index.js +19 -39
  231. package/lib/Utils/index.js.map +1 -0
  232. package/lib/Utils/link-preview.d.ts +12 -14
  233. package/lib/Utils/link-preview.d.ts.map +1 -0
  234. package/lib/Utils/link-preview.js +40 -75
  235. package/lib/Utils/link-preview.js.map +1 -0
  236. package/lib/Utils/logger.d.ts +10 -11
  237. package/lib/Utils/logger.d.ts.map +1 -0
  238. package/lib/Utils/logger.js +3 -7
  239. package/lib/Utils/logger.js.map +1 -0
  240. package/lib/Utils/lt-hash.d.ts +12 -13
  241. package/lib/Utils/lt-hash.d.ts.map +1 -0
  242. package/lib/Utils/lt-hash.js +27 -37
  243. package/lib/Utils/lt-hash.js.map +1 -0
  244. package/lib/Utils/make-mutex.d.ts +6 -7
  245. package/lib/Utils/make-mutex.d.ts.map +1 -0
  246. package/lib/Utils/make-mutex.js +20 -29
  247. package/lib/Utils/make-mutex.js.map +1 -0
  248. package/lib/Utils/message-retry-manager.d.ts +82 -0
  249. package/lib/Utils/message-retry-manager.d.ts.map +1 -0
  250. package/lib/Utils/message-retry-manager.js +149 -0
  251. package/lib/Utils/message-retry-manager.js.map +1 -0
  252. package/lib/Utils/messages-media.d.ts +87 -102
  253. package/lib/Utils/messages-media.d.ts.map +1 -0
  254. package/lib/Utils/messages-media.js +427 -570
  255. package/lib/Utils/messages-media.js.map +1 -0
  256. package/lib/Utils/messages.d.ts +37 -64
  257. package/lib/Utils/messages.d.ts.map +1 -0
  258. package/lib/Utils/messages.js +511 -1270
  259. package/lib/Utils/messages.js.map +1 -0
  260. package/lib/Utils/noise-handler.d.ts +18 -18
  261. package/lib/Utils/noise-handler.d.ts.map +1 -0
  262. package/lib/Utils/noise-handler.js +101 -109
  263. package/lib/Utils/noise-handler.js.map +1 -0
  264. package/lib/Utils/pre-key-manager.d.ts +28 -0
  265. package/lib/Utils/pre-key-manager.d.ts.map +1 -0
  266. package/lib/Utils/pre-key-manager.js +106 -0
  267. package/lib/Utils/pre-key-manager.js.map +1 -0
  268. package/lib/Utils/process-message.d.ts +25 -32
  269. package/lib/Utils/process-message.d.ts.map +1 -0
  270. package/lib/Utils/process-message.js +266 -281
  271. package/lib/Utils/process-message.js.map +1 -0
  272. package/lib/Utils/signal.d.ts +24 -32
  273. package/lib/Utils/signal.d.ts.map +1 -0
  274. package/lib/Utils/signal.js +98 -105
  275. package/lib/Utils/signal.js.map +1 -0
  276. package/lib/Utils/use-multi-file-auth-state.d.ts +5 -10
  277. package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
  278. package/lib/Utils/use-multi-file-auth-state.js +69 -186
  279. package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
  280. package/lib/Utils/validate-connection.d.ts +11 -13
  281. package/lib/Utils/validate-connection.d.ts.map +1 -0
  282. package/lib/Utils/validate-connection.js +124 -116
  283. package/lib/Utils/validate-connection.js.map +1 -0
  284. package/lib/WABinary/constants.d.ts +25 -27
  285. package/lib/WABinary/constants.d.ts.map +1 -0
  286. package/lib/WABinary/constants.js +1277 -1292
  287. package/lib/WABinary/constants.js.map +1 -0
  288. package/lib/WABinary/decode.d.ts +7 -9
  289. package/lib/WABinary/decode.d.ts.map +1 -0
  290. package/lib/WABinary/decode.js +139 -189
  291. package/lib/WABinary/decode.js.map +1 -0
  292. package/lib/WABinary/encode.d.ts +3 -3
  293. package/lib/WABinary/encode.d.ts.map +1 -0
  294. package/lib/WABinary/encode.js +105 -154
  295. package/lib/WABinary/encode.js.map +1 -0
  296. package/lib/WABinary/generic-utils.d.ts +14 -27
  297. package/lib/WABinary/generic-utils.d.ts.map +1 -0
  298. package/lib/WABinary/generic-utils.js +62 -102
  299. package/lib/WABinary/generic-utils.js.map +1 -0
  300. package/lib/WABinary/index.d.ts +6 -5
  301. package/lib/WABinary/index.d.ts.map +1 -0
  302. package/lib/WABinary/index.js +6 -25
  303. package/lib/WABinary/index.js.map +1 -0
  304. package/lib/WABinary/jid-utils.d.ts +41 -46
  305. package/lib/WABinary/jid-utils.d.ts.map +1 -0
  306. package/lib/WABinary/jid-utils.js +84 -80
  307. package/lib/WABinary/jid-utils.js.map +1 -0
  308. package/lib/WABinary/types.d.ts +10 -13
  309. package/lib/WABinary/types.d.ts.map +1 -0
  310. package/lib/WABinary/types.js +2 -3
  311. package/lib/WABinary/types.js.map +1 -0
  312. package/lib/WAM/BinaryInfo.d.ts +8 -15
  313. package/lib/WAM/BinaryInfo.d.ts.map +1 -0
  314. package/lib/WAM/BinaryInfo.js +7 -14
  315. package/lib/WAM/BinaryInfo.js.map +1 -0
  316. package/lib/WAM/constants.d.ts +30 -37
  317. package/lib/WAM/constants.d.ts.map +1 -0
  318. package/lib/WAM/constants.js +19193 -11711
  319. package/lib/WAM/constants.js.map +1 -0
  320. package/lib/WAM/encode.d.ts +3 -3
  321. package/lib/WAM/encode.d.ts.map +1 -0
  322. package/lib/WAM/encode.js +95 -110
  323. package/lib/WAM/encode.js.map +1 -0
  324. package/lib/WAM/index.d.ts +4 -3
  325. package/lib/WAM/index.d.ts.map +1 -0
  326. package/lib/WAM/index.js +4 -23
  327. package/lib/WAM/index.js.map +1 -0
  328. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -9
  329. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
  330. package/lib/WAUSync/Protocols/USyncContactProtocol.js +12 -19
  331. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
  332. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +19 -22
  333. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
  334. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +18 -26
  335. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
  336. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +11 -12
  337. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
  338. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -20
  339. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
  340. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +11 -12
  341. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
  342. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +16 -24
  343. package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
  344. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  345. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
  346. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
  347. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
  348. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
  349. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
  350. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
  351. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
  352. package/lib/WAUSync/Protocols/index.d.ts +5 -6
  353. package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
  354. package/lib/WAUSync/Protocols/index.js +5 -26
  355. package/lib/WAUSync/Protocols/index.js.map +1 -0
  356. package/lib/WAUSync/USyncQuery.d.ts +26 -28
  357. package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
  358. package/lib/WAUSync/USyncQuery.js +64 -62
  359. package/lib/WAUSync/USyncQuery.js.map +1 -0
  360. package/lib/WAUSync/USyncUser.d.ts +11 -10
  361. package/lib/WAUSync/USyncUser.d.ts.map +1 -0
  362. package/lib/WAUSync/USyncUser.js +12 -19
  363. package/lib/WAUSync/USyncUser.js.map +1 -0
  364. package/lib/WAUSync/index.d.ts +4 -3
  365. package/lib/WAUSync/index.d.ts.map +1 -0
  366. package/lib/WAUSync/index.js +4 -23
  367. package/lib/WAUSync/index.js.map +1 -0
  368. package/lib/index.d.ts +10 -11
  369. package/lib/index.d.ts.map +1 -0
  370. package/lib/index.js +11 -33
  371. package/lib/index.js.map +1 -0
  372. package/package.json +48 -43
  373. package/lib/Defaults/baileys-version.json +0 -3
  374. package/lib/Defaults/phonenumber-mcc.json +0 -223
  375. package/lib/Signal/WASignalGroup/GroupProtocol.js +0 -1909
  376. package/lib/Signal/WASignalGroup/ciphertext_message.js +0 -16
  377. package/lib/Signal/WASignalGroup/generate-proto.sh +0 -1
  378. package/lib/Signal/WASignalGroup/group.proto +0 -42
  379. package/lib/Signal/WASignalGroup/group_cipher.js +0 -120
  380. package/lib/Signal/WASignalGroup/group_session_builder.js +0 -46
  381. package/lib/Signal/WASignalGroup/index.js +0 -6
  382. package/lib/Signal/WASignalGroup/keyhelper.js +0 -21
  383. package/lib/Signal/WASignalGroup/protobufs.js +0 -3
  384. package/lib/Signal/WASignalGroup/queue_job.js +0 -69
  385. package/lib/Signal/WASignalGroup/readme.md +0 -6
  386. package/lib/Signal/WASignalGroup/sender_chain_key.js +0 -50
  387. package/lib/Signal/WASignalGroup/sender_key_distribution_message.js +0 -78
  388. package/lib/Signal/WASignalGroup/sender_key_message.js +0 -92
  389. package/lib/Signal/WASignalGroup/sender_key_name.js +0 -70
  390. package/lib/Signal/WASignalGroup/sender_key_record.js +0 -56
  391. package/lib/Signal/WASignalGroup/sender_key_state.js +0 -129
  392. package/lib/Socket/Client/abstract-socket-client.d.ts +0 -15
  393. package/lib/Socket/Client/abstract-socket-client.js +0 -13
  394. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -12
  395. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  396. package/lib/Socket/registration.d.ts +0 -266
  397. package/lib/Socket/registration.js +0 -166
  398. package/lib/Socket/usync.d.ts +0 -37
  399. package/lib/Socket/usync.js +0 -83
  400. package/lib/Store/index.d.ts +0 -4
  401. package/lib/Store/index.js +0 -24
  402. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  403. package/lib/Store/make-cache-manager-store.js +0 -90
  404. package/lib/Store/make-in-memory-store.d.ts +0 -123
  405. package/lib/Store/make-in-memory-store.js +0 -429
  406. package/lib/Store/make-ordered-dictionary.d.ts +0 -12
  407. package/lib/Store/make-ordered-dictionary.js +0 -86
  408. package/lib/Store/object-repository.d.ts +0 -10
  409. package/lib/Store/object-repository.js +0 -31
  410. package/lib/Types/MexUpdates.d.ts +0 -9
  411. package/lib/Types/MexUpdates.js +0 -18
  412. package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
  413. package/lib/Utils/use-mongo-file-auth-state.js +0 -84
  414. package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
  415. package/lib/Utils/use-single-file-auth-state.js +0 -80
  416. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
  417. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -69
  418. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -9
  419. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -30
@@ -1,80 +1,65 @@
1
- "use strict"
2
-
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod }
5
- }
6
-
7
- Object.defineProperty(exports, "__esModule", { value: true })
8
-
9
- const node_cache_1 = __importDefault(require("@cacheable/node-cache"))
10
- const boom_1 = require("@hapi/boom")
11
- const WAProto_1 = require("../../WAProto")
12
- const Defaults_1 = require("../Defaults")
13
- const Types_1 = require("../Types")
14
- const Utils_1 = require("../Utils")
15
- const make_mutex_1 = require("../Utils/make-mutex")
16
- const WABinary_1 = require("../WABinary")
17
- const WAUSync_1 = require("../WAUSync")
18
- const usync_1 = require("./usync")
19
- const MAX_SYNC_ATTEMPTS = 2
20
-
21
- const makeChatsSocket = (config) => {
22
- const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage, } = config
23
- const Neele = usync_1.makeUSyncSocket(config)
24
- const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError, groupFetchAllParticipating } = Neele
25
-
26
- let privacySettings
27
- let syncState = Types_1.SyncState.Connecting
28
-
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';
13
+ const MAX_SYNC_ATTEMPTS = 2;
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;
18
+ let privacySettings;
19
+ let syncState = SyncState.Connecting;
29
20
  /** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
30
- const processingMutex = make_mutex_1.makeMutex()
31
-
32
- // Timeout for AwaitingInitialSync State
33
- let awaitingSyncTimeout
34
-
35
- const placeholderResendCache = config.placeholderResendCache || new node_cache_1.default({
36
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
37
- useClones: false
38
- })
39
-
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
+ });
40
29
  if (!config.placeholderResendCache) {
41
- config.placeholderResendCache = placeholderResendCache
30
+ config.placeholderResendCache = placeholderResendCache;
42
31
  }
43
-
44
32
  /** helper function to fetch the given app state sync key */
45
33
  const getAppStateSyncKey = async (keyId) => {
46
- const { [keyId]: key } = await authState.keys.get('app-state-sync-key', [keyId])
47
- return key
48
- }
49
-
34
+ const { [keyId]: key } = await authState.keys.get('app-state-sync-key', [keyId]);
35
+ return key;
36
+ };
50
37
  const fetchPrivacySettings = async (force = false) => {
51
38
  if (!privacySettings || force) {
52
39
  const { content } = await query({
53
40
  tag: 'iq',
54
41
  attrs: {
55
42
  xmlns: 'privacy',
56
- to: WABinary_1.S_WHATSAPP_NET,
43
+ to: S_WHATSAPP_NET,
57
44
  type: 'get'
58
45
  },
59
- content: [
60
- { tag: 'privacy', attrs: {} }
61
- ]
62
- })
63
- privacySettings = WABinary_1.reduceBinaryNodeToDictionary(content?.[0], 'category')
46
+ content: [{ tag: 'privacy', attrs: {} }]
47
+ });
48
+ privacySettings = reduceBinaryNodeToDictionary(content?.[0], 'category');
64
49
  }
65
- return privacySettings
66
- }
67
-
50
+ return privacySettings;
51
+ };
68
52
  /** helper function to run a privacy IQ query */
69
53
  const privacyQuery = async (name, value) => {
70
54
  await query({
71
55
  tag: 'iq',
72
56
  attrs: {
73
57
  xmlns: 'privacy',
74
- to: WABinary_1.S_WHATSAPP_NET,
58
+ to: S_WHATSAPP_NET,
75
59
  type: 'set'
76
60
  },
77
- content: [{
61
+ content: [
62
+ {
78
63
  tag: 'privacy',
79
64
  attrs: {},
80
65
  content: [
@@ -83,187 +68,123 @@ const makeChatsSocket = (config) => {
83
68
  attrs: { name, value }
84
69
  }
85
70
  ]
86
- }]
87
- })
88
- }
89
-
71
+ }
72
+ ]
73
+ });
74
+ };
90
75
  const updateMessagesPrivacy = async (value) => {
91
- await privacyQuery('messages', value)
92
- }
93
-
76
+ await privacyQuery('messages', value);
77
+ };
94
78
  const updateCallPrivacy = async (value) => {
95
- await privacyQuery('calladd', value)
96
- }
97
-
79
+ await privacyQuery('calladd', value);
80
+ };
98
81
  const updateLastSeenPrivacy = async (value) => {
99
- await privacyQuery('last', value)
100
- }
101
-
82
+ await privacyQuery('last', value);
83
+ };
102
84
  const updateOnlinePrivacy = async (value) => {
103
- await privacyQuery('online', value)
104
- }
105
-
85
+ await privacyQuery('online', value);
86
+ };
106
87
  const updateProfilePicturePrivacy = async (value) => {
107
- await privacyQuery('profile', value)
108
- }
109
-
88
+ await privacyQuery('profile', value);
89
+ };
110
90
  const updateStatusPrivacy = async (value) => {
111
- await privacyQuery('status', value)
112
- }
113
-
91
+ await privacyQuery('status', value);
92
+ };
114
93
  const updateReadReceiptsPrivacy = async (value) => {
115
- await privacyQuery('readreceipts', value)
116
- }
117
-
94
+ await privacyQuery('readreceipts', value);
95
+ };
118
96
  const updateGroupsAddPrivacy = async (value) => {
119
- await privacyQuery('groupadd', value)
120
- }
121
-
97
+ await privacyQuery('groupadd', value);
98
+ };
122
99
  const updateDefaultDisappearingMode = async (duration) => {
123
100
  await query({
124
101
  tag: 'iq',
125
102
  attrs: {
126
103
  xmlns: 'disappearing_mode',
127
- to: WABinary_1.S_WHATSAPP_NET,
104
+ to: S_WHATSAPP_NET,
128
105
  type: 'set'
129
106
  },
130
- content: [{
107
+ content: [
108
+ {
131
109
  tag: 'disappearing_mode',
132
110
  attrs: {
133
111
  duration: duration.toString()
134
112
  }
135
- }]
136
- })
137
- }
138
-
113
+ }
114
+ ]
115
+ });
116
+ };
139
117
  const getBotListV2 = async () => {
140
- const resp = await query({
141
- tag: 'iq',
142
- attrs: {
143
- xmlns: 'bot',
144
- to: WABinary_1.S_WHATSAPP_NET,
145
- type: 'get'
146
- },
147
- content: [{
148
- tag: 'bot',
149
- attrs: {
150
- v: '2'
151
- }
152
- }]
153
- })
154
-
155
- const botNode = WABinary_1.getBinaryNodeChild(resp, 'bot')
156
-
157
- const botList = []
158
-
159
- for(const section of WABinary_1.getBinaryNodeChildren(botNode, 'section')) {
160
- if(section.attrs.type === 'all') {
161
- for(const bot of WABinary_1.getBinaryNodeChildren(section, 'bot')) {
162
- botList.push({
163
- jid: bot.attrs.jid,
164
- personaId: bot.attrs['persona_id']
165
- })
166
- }
167
- }
168
- }
169
- return botList
170
- }
171
-
172
- const getLidUser = async (jid) => {
173
- if (!jid) {
174
- throw new boom_1.Boom('Please input a jid user')
175
- }
176
-
177
- if (!WABinary_1.isJidUser(jid)) {
178
- throw new boom_1.Boom('Invalid JID: Not a user JID!')
179
- }
180
-
181
- const targetJid = WABinary_1.jidNormalizedUser(jid)
182
-
183
- const usyncQuery = new WAUSync_1.USyncQuery()
184
- usyncQuery.protocols.push({
185
- name: 'lid',
186
- getQueryElement: () => ({
187
- tag: 'lid',
188
- attrs: {},
189
- content: undefined
190
- }),
191
- getUserElement: () => null,
192
- parser: (node) => node.attrs.val
193
- })
194
- usyncQuery.users.push({
195
- id: targetJid
196
- })
197
-
198
- const result = await Neele.executeUSyncQuery(usyncQuery)
199
-
200
- if (result) {
201
- return result.list
202
- }
203
- }
204
-
205
- const onWhatsApp = async (...jids) => {
206
- const usyncQuery = new WAUSync_1.USyncQuery().withContactProtocol().withLIDProtocol()
207
-
208
- for (const jid of jids) {
209
- const phone = `+${jid.replace('+', '').split('@')[0].split(':')[0]}`
210
- usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone))
211
- }
212
-
213
- const results = await Neele.executeUSyncQuery(usyncQuery)
214
-
215
- if (results) {
216
- return results.list.filter((a) => !!a.contact).map(({ contact, id, lid }) => ({ jid: id, exists: contact, lid }))
118
+ const resp = await query({
119
+ tag: 'iq',
120
+ attrs: {
121
+ xmlns: 'bot',
122
+ to: S_WHATSAPP_NET,
123
+ type: 'get'
124
+ },
125
+ content: [
126
+ {
127
+ tag: 'bot',
128
+ attrs: {
129
+ v: '2'
130
+ }
131
+ }
132
+ ]
133
+ });
134
+ const botNode = getBinaryNodeChild(resp, 'bot');
135
+ const botList = [];
136
+ for (const section of getBinaryNodeChildren(botNode, 'section')) {
137
+ if (section.attrs.type === 'all') {
138
+ for (const bot of getBinaryNodeChildren(section, 'bot')) {
139
+ botList.push({
140
+ jid: bot.attrs.jid,
141
+ personaId: bot.attrs['persona_id']
142
+ });
143
+ }
144
+ }
217
145
  }
218
- }
219
-
146
+ return botList;
147
+ };
220
148
  const fetchStatus = async (...jids) => {
221
- const usyncQuery = new WAUSync_1.USyncQuery().withStatusProtocol()
222
-
149
+ const usyncQuery = new USyncQuery().withStatusProtocol();
223
150
  for (const jid of jids) {
224
- usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid))
151
+ usyncQuery.withUser(new USyncUser().withId(jid));
225
152
  }
226
-
227
- const result = await Neele.executeUSyncQuery(usyncQuery)
228
-
153
+ const result = await sock.executeUSyncQuery(usyncQuery);
229
154
  if (result) {
230
- return result.list
155
+ return result.list;
231
156
  }
232
- }
233
- const fetchDisappearingDuration = async (...jids) => {
234
- const usyncQuery = new WAUSync_1.USyncQuery().withDisappearingModeProtocol()
235
-
157
+ };
158
+ const fetchDisappearingDuration = async (...jids) => {
159
+ const usyncQuery = new USyncQuery().withDisappearingModeProtocol();
236
160
  for (const jid of jids) {
237
- usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid))
161
+ usyncQuery.withUser(new USyncUser().withId(jid));
238
162
  }
239
-
240
- const result = await Neele.executeUSyncQuery(usyncQuery)
163
+ const result = await sock.executeUSyncQuery(usyncQuery);
241
164
  if (result) {
242
- return result.list
165
+ return result.list;
243
166
  }
244
- }
245
-
167
+ };
246
168
  /** update the profile picture for yourself or a group */
247
- const updateProfilePicture = async (jid, content) => {
248
- let targetJid
249
-
169
+ const updateProfilePicture = async (jid, content, dimensions) => {
170
+ let targetJid;
250
171
  if (!jid) {
251
- 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');
173
+ }
174
+ if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
175
+ targetJid = jidNormalizedUser(jid); // in case it is someone other than us
252
176
  }
253
-
254
- if (WABinary_1.jidNormalizedUser(jid) !== WABinary_1.jidNormalizedUser(authState.creds.me.id)) {
255
- targetJid = WABinary_1.jidNormalizedUser(jid) // in case it is someone other than us
177
+ else {
178
+ targetJid = undefined;
256
179
  }
257
-
258
- const { img } = await Utils_1.generateProfilePicture(content)
259
-
180
+ const { img } = await generateProfilePicture(content, dimensions);
260
181
  await query({
261
182
  tag: 'iq',
262
183
  attrs: {
263
- target: targetJid,
264
- to: WABinary_1.S_WHATSAPP_NET,
184
+ to: S_WHATSAPP_NET,
265
185
  type: 'set',
266
- xmlns: 'w:profile:picture'
186
+ xmlns: 'w:profile:picture',
187
+ ...(targetJid ? { target: targetJid } : {})
267
188
  },
268
189
  content: [
269
190
  {
@@ -272,38 +193,36 @@ const makeChatsSocket = (config) => {
272
193
  content: img
273
194
  }
274
195
  ]
275
- })
276
- }
277
-
196
+ });
197
+ };
278
198
  /** remove the profile picture for yourself or a group */
279
199
  const removeProfilePicture = async (jid) => {
280
- let targetJid
281
-
200
+ let targetJid;
282
201
  if (!jid) {
283
- 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');
203
+ }
204
+ if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
205
+ targetJid = jidNormalizedUser(jid); // in case it is someone other than us
284
206
  }
285
-
286
- if (WABinary_1.jidNormalizedUser(jid) !== WABinary_1.jidNormalizedUser(authState.creds.me.id)) {
287
- targetJid = WABinary_1.jidNormalizedUser(jid) // in case it is someone other than us
207
+ else {
208
+ targetJid = undefined;
288
209
  }
289
-
290
210
  await query({
291
211
  tag: 'iq',
292
212
  attrs: {
293
- target: targetJid,
294
- to: WABinary_1.S_WHATSAPP_NET,
213
+ to: S_WHATSAPP_NET,
295
214
  type: 'set',
296
- xmlns: 'w:profile:picture'
215
+ xmlns: 'w:profile:picture',
216
+ ...(targetJid ? { target: targetJid } : {})
297
217
  }
298
- })
299
- }
300
-
218
+ });
219
+ };
301
220
  /** update the profile status for yourself */
302
221
  const updateProfileStatus = async (status) => {
303
222
  await query({
304
223
  tag: 'iq',
305
224
  attrs: {
306
- to: WABinary_1.S_WHATSAPP_NET,
225
+ to: S_WHATSAPP_NET,
307
226
  type: 'set',
308
227
  xmlns: 'status'
309
228
  },
@@ -314,34 +233,29 @@ const makeChatsSocket = (config) => {
314
233
  content: Buffer.from(status, 'utf-8')
315
234
  }
316
235
  ]
317
- })
318
- }
319
-
236
+ });
237
+ };
320
238
  const updateProfileName = async (name) => {
321
- await chatModify({ pushNameSetting: name }, '')
322
- }
323
-
239
+ await chatModify({ pushNameSetting: name }, '');
240
+ };
324
241
  const fetchBlocklist = async () => {
325
242
  const result = await query({
326
243
  tag: 'iq',
327
244
  attrs: {
328
245
  xmlns: 'blocklist',
329
- to: WABinary_1.S_WHATSAPP_NET,
246
+ to: S_WHATSAPP_NET,
330
247
  type: 'get'
331
248
  }
332
- })
333
-
334
- const listNode = WABinary_1.getBinaryNodeChild(result, 'list')
335
-
336
- return WABinary_1.getBinaryNodeChildren(listNode, 'item').map((n) => n.attrs.jid)
337
- }
338
-
249
+ });
250
+ const listNode = getBinaryNodeChild(result, 'list');
251
+ return getBinaryNodeChildren(listNode, 'item').map(n => n.attrs.jid);
252
+ };
339
253
  const updateBlockStatus = async (jid, action) => {
340
254
  await query({
341
255
  tag: 'iq',
342
256
  attrs: {
343
257
  xmlns: 'blocklist',
344
- to: WABinary_1.S_WHATSAPP_NET,
258
+ to: S_WHATSAPP_NET,
345
259
  type: 'set'
346
260
  },
347
261
  content: [
@@ -353,9 +267,8 @@ const makeChatsSocket = (config) => {
353
267
  }
354
268
  }
355
269
  ]
356
- })
357
- }
358
-
270
+ });
271
+ };
359
272
  const getBusinessProfile = async (jid) => {
360
273
  const results = await query({
361
274
  tag: 'iq',
@@ -364,121 +277,116 @@ const makeChatsSocket = (config) => {
364
277
  xmlns: 'w:biz',
365
278
  type: 'get'
366
279
  },
367
- content: [{
280
+ content: [
281
+ {
368
282
  tag: 'business_profile',
369
283
  attrs: { v: '244' },
370
- content: [{
284
+ content: [
285
+ {
371
286
  tag: 'profile',
372
287
  attrs: { jid }
373
- }]
374
- }]
375
- })
376
-
377
- const profileNode = WABinary_1.getBinaryNodeChild(results, 'business_profile')
378
-
379
- const profiles = WABinary_1.getBinaryNodeChild(profileNode, 'profile')
380
-
288
+ }
289
+ ]
290
+ }
291
+ ]
292
+ });
293
+ const profileNode = getBinaryNodeChild(results, 'business_profile');
294
+ const profiles = getBinaryNodeChild(profileNode, 'profile');
381
295
  if (profiles) {
382
- const address = WABinary_1.getBinaryNodeChild(profiles, 'address')
383
- const description = WABinary_1.getBinaryNodeChild(profiles, 'description')
384
- const website = WABinary_1.getBinaryNodeChild(profiles, 'website')
385
- const email = WABinary_1.getBinaryNodeChild(profiles, 'email')
386
- const category = WABinary_1.getBinaryNodeChild(WABinary_1.getBinaryNodeChild(profiles, 'categories'), 'category')
387
- const businessHours = 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');
388
302
  const businessHoursConfig = businessHours
389
- ? WABinary_1.getBinaryNodeChildren(businessHours, 'business_hours_config')
390
- : undefined
391
- const websiteStr = website?.content?.toString()
392
-
303
+ ? getBinaryNodeChildren(businessHours, 'business_hours_config')
304
+ : undefined;
305
+ const websiteStr = website?.content?.toString();
393
306
  return {
394
- wid: profiles?.attrs?.jid,
307
+ wid: profiles.attrs?.jid,
395
308
  address: address?.content?.toString(),
396
309
  description: description?.content?.toString() || '',
397
310
  website: websiteStr ? [websiteStr] : [],
398
311
  email: email?.content?.toString(),
399
312
  category: category?.content?.toString(),
400
- 'business_hours': {
313
+ business_hours: {
401
314
  timezone: businessHours?.attrs?.timezone,
402
- 'business_config': businessHoursConfig?.map(({ attrs }) => attrs)
315
+ business_config: businessHoursConfig?.map(({ attrs }) => attrs)
403
316
  }
404
- }
317
+ };
405
318
  }
406
- }
407
-
319
+ };
408
320
  const cleanDirtyBits = async (type, fromTimestamp) => {
409
- logger.info({ fromTimestamp }, 'clean dirty bits ' + type)
321
+ logger.info({ fromTimestamp }, 'clean dirty bits ' + type);
410
322
  await sendNode({
411
323
  tag: 'iq',
412
324
  attrs: {
413
- to: WABinary_1.S_WHATSAPP_NET,
325
+ to: S_WHATSAPP_NET,
414
326
  type: 'set',
415
327
  xmlns: 'urn:xmpp:whatsapp:dirty',
416
- id: generateMessageTag(),
328
+ id: generateMessageTag()
417
329
  },
418
330
  content: [
419
331
  {
420
332
  tag: 'clean',
421
333
  attrs: {
422
334
  type,
423
- ...(fromTimestamp ? { timestamp: fromTimestamp.toString() } : null),
335
+ ...(fromTimestamp ? { timestamp: fromTimestamp.toString() } : null)
424
336
  }
425
337
  }
426
338
  ]
427
- })
428
- }
429
-
339
+ });
340
+ };
430
341
  const newAppStateChunkHandler = (isInitialSync) => {
431
342
  return {
432
343
  onMutation(mutation) {
433
- 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);
434
345
  }
435
- }
436
- }
437
-
346
+ };
347
+ };
438
348
  const resyncAppState = ev.createBufferedFunction(async (collections, isInitialSync) => {
439
349
  // we use this to determine which events to fire
440
350
  // otherwise when we resync from scratch -- all notifications will fire
441
- const initialVersionMap = {}
442
- const globalMutationMap = {}
351
+ const initialVersionMap = {};
352
+ const globalMutationMap = {};
443
353
  await authState.keys.transaction(async () => {
444
- const collectionsToHandle = new Set(collections)
354
+ const collectionsToHandle = new Set(collections);
445
355
  // in case something goes wrong -- ensure we don't enter a loop that cannot be exited from
446
- const attemptsMap = {}
356
+ const attemptsMap = {};
447
357
  // keep executing till all collections are done
448
358
  // sometimes a single patch request will not return all the patches (God knows why)
449
359
  // so we fetch till they're all done (this is determined by the "has_more_patches" flag)
450
360
  while (collectionsToHandle.size) {
451
- const states = {}
452
- const nodes = []
453
-
361
+ const states = {};
362
+ const nodes = [];
454
363
  for (const name of collectionsToHandle) {
455
- const result = await authState.keys.get('app-state-sync-version', [name])
456
- let state = result[name]
364
+ const result = await authState.keys.get('app-state-sync-version', [name]);
365
+ let state = result[name];
457
366
  if (state) {
458
367
  if (typeof initialVersionMap[name] === 'undefined') {
459
- initialVersionMap[name] = state.version
368
+ initialVersionMap[name] = state.version;
460
369
  }
461
370
  }
462
371
  else {
463
- state = Utils_1.newLTHashState()
372
+ state = newLTHashState();
464
373
  }
465
- states[name] = state
466
- logger.info(`resyncing ${name} from v${state.version}`)
374
+ states[name] = state;
375
+ logger.info(`resyncing ${name} from v${state.version}`);
467
376
  nodes.push({
468
377
  tag: 'collection',
469
378
  attrs: {
470
379
  name,
471
380
  version: state.version.toString(),
472
381
  // return snapshot if being synced from scratch
473
- 'return_snapshot': (!state.version).toString()
382
+ return_snapshot: (!state.version).toString()
474
383
  }
475
- })
384
+ });
476
385
  }
477
-
478
386
  const result = await query({
479
387
  tag: 'iq',
480
388
  attrs: {
481
- to: WABinary_1.S_WHATSAPP_NET,
389
+ to: S_WHATSAPP_NET,
482
390
  xmlns: 'w:sync:app:state',
483
391
  type: 'set'
484
392
  },
@@ -489,125 +397,121 @@ const makeChatsSocket = (config) => {
489
397
  content: nodes
490
398
  }
491
399
  ]
492
- })
493
-
400
+ });
494
401
  // extract from binary node
495
- const decoded = await Utils_1.extractSyncdPatches(result, config?.options)
496
-
402
+ const decoded = await extractSyncdPatches(result, config?.options);
497
403
  for (const key in decoded) {
498
- const name = key
499
- const { patches, hasMorePatches, snapshot } = decoded[name]
404
+ const name = key;
405
+ const { patches, hasMorePatches, snapshot } = decoded[name];
500
406
  try {
501
407
  if (snapshot) {
502
- const { state: newState, mutationMap } = await Utils_1.decodeSyncdSnapshot(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot)
503
- states[name] = newState
504
- Object.assign(globalMutationMap, mutationMap)
505
- logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`)
506
- await authState.keys.set({ 'app-state-sync-version': { [name]: newState } })
408
+ const { state: newState, mutationMap } = await decodeSyncdSnapshot(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot);
409
+ states[name] = newState;
410
+ Object.assign(globalMutationMap, mutationMap);
411
+ logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
412
+ await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
507
413
  }
508
-
509
414
  // only process if there are syncd patches
510
415
  if (patches.length) {
511
- const { state: newState, mutationMap } = await Utils_1.decodePatches(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch)
512
- await authState.keys.set({ 'app-state-sync-version': { [name]: newState } })
513
- logger.info(`synced ${name} to v${newState.version}`)
514
- initialVersionMap[name] = newState.version
515
- Object.assign(globalMutationMap, mutationMap)
416
+ const { state: newState, mutationMap } = await decodePatches(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
417
+ await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
418
+ logger.info(`synced ${name} to v${newState.version}`);
419
+ initialVersionMap[name] = newState.version;
420
+ Object.assign(globalMutationMap, mutationMap);
516
421
  }
517
-
518
422
  if (hasMorePatches) {
519
- logger.info(`${name} has more patches...`)
520
- }
521
- else { // collection is done with sync
522
- collectionsToHandle.delete(name)
423
+ logger.info(`${name} has more patches...`);
523
424
  }
524
- }
425
+ else {
426
+ // collection is done with sync
427
+ collectionsToHandle.delete(name);
428
+ }
429
+ }
525
430
  catch (error) {
526
431
  // if retry attempts overshoot
527
432
  // or key not found
528
- const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS
529
- || error.output?.statusCode === 404
530
- || error.name === 'TypeError'
531
- logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`)
532
- await authState.keys.set({ 'app-state-sync-version': { [name]: null } })
433
+ const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS ||
434
+ error.output?.statusCode === 404 ||
435
+ error.name === 'TypeError';
436
+ logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
437
+ await authState.keys.set({ 'app-state-sync-version': { [name]: null } });
533
438
  // increment number of retries
534
- attemptsMap[name] = (attemptsMap[name] || 0) + 1
535
-
439
+ attemptsMap[name] = (attemptsMap[name] || 0) + 1;
536
440
  if (isIrrecoverableError) {
537
441
  // stop retrying
538
- collectionsToHandle.delete(name)
442
+ collectionsToHandle.delete(name);
539
443
  }
540
444
  }
541
445
  }
542
446
  }
543
- })
544
-
545
- const { onMutation } = newAppStateChunkHandler(isInitialSync)
546
-
447
+ }, authState?.creds?.me?.id || 'resync-app-state');
448
+ const { onMutation } = newAppStateChunkHandler(isInitialSync);
547
449
  for (const key in globalMutationMap) {
548
- onMutation(globalMutationMap[key])
450
+ onMutation(globalMutationMap[key]);
549
451
  }
550
- })
551
-
552
- // source: https://github.com/WhiskeySockets/Baileys/pull/1677
452
+ });
453
+ /**
454
+ * fetch the profile picture of a user/group
455
+ * type = "preview" for a low res picture
456
+ * type = "image for the high res picture"
457
+ */
458
+ const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
459
+ // TOOD: Add support for tctoken, existingID, and newsletter + group options
460
+ jid = jidNormalizedUser(jid);
461
+ const result = await query({
462
+ tag: 'iq',
463
+ attrs: {
464
+ target: jid,
465
+ to: S_WHATSAPP_NET,
466
+ type: 'get',
467
+ xmlns: 'w:profile:picture'
468
+ },
469
+ content: [{ tag: 'picture', attrs: { type, query: 'url' } }]
470
+ }, timeoutMs);
471
+ const child = getBinaryNodeChild(result, 'picture');
472
+ return child?.attrs?.url;
473
+ };
553
474
  const createCallLink = async (type, event, timeoutMs) => {
554
- type = type?.toLowerCase()
555
-
556
- if (!type || (type !== 'audio' && type !== 'video')) {
557
- throw new Error('Make sure the type is audio or video!')
558
- }
559
-
560
- const result = await query({
561
- tag: 'call',
562
- attrs: {
563
- id: generateMessageTag(),
564
- to: '@call'
565
- },
566
- content: [{
567
- tag: 'link_create',
568
- attrs: {
569
- media: type
570
- },
571
- content: event ? [{
572
- tag: 'event',
573
- attrs: {
574
- start_time: String(event)
575
- }
576
- }] : undefined
577
- }]
578
- }, timeoutMs)
579
-
580
- const child = WABinary_1.getBinaryNodeChild(result, 'link_create')
581
- const token = child?.attrs?.token
582
-
583
- return type === 'audio' ? Defaults_1.CALL_AUDIO_PREFIX + token : Defaults_1.CALL_VIDEO_PREFIX + token
584
- }
585
-
475
+ const result = await query({
476
+ tag: 'call',
477
+ attrs: {
478
+ id: generateMessageTag(),
479
+ to: '@call'
480
+ },
481
+ content: [
482
+ {
483
+ tag: 'link_create',
484
+ attrs: { media: type },
485
+ content: event ? [{ tag: 'event', attrs: { start_time: String(event.startTime) } }] : undefined
486
+ }
487
+ ]
488
+ }, timeoutMs);
489
+ const child = getBinaryNodeChild(result, 'link_create');
490
+ return child?.attrs?.token;
491
+ };
586
492
  const sendPresenceUpdate = async (type, toJid) => {
587
- const me = authState.creds.me
588
-
493
+ const me = authState.creds.me;
589
494
  if (type === 'available' || type === 'unavailable') {
590
495
  if (!me.name) {
591
- logger.warn('no name present, ignoring presence update request...')
592
- return
496
+ logger.warn('no name present, ignoring presence update request...');
497
+ return;
593
498
  }
594
-
595
- ev.emit('connection.update', { isOnline: type === 'available' })
499
+ ev.emit('connection.update', { isOnline: type === 'available' });
596
500
  await sendNode({
597
501
  tag: 'presence',
598
502
  attrs: {
599
503
  name: me.name.replace(/@/g, ''),
600
504
  type
601
505
  }
602
- })
506
+ });
603
507
  }
604
508
  else {
605
- const { server } = WABinary_1.jidDecode(toJid)
606
-
509
+ const { server } = jidDecode(toJid);
510
+ const isLid = server === 'lid';
607
511
  await sendNode({
608
512
  tag: 'chatstate',
609
513
  attrs: {
610
- from: server === 'lid' ? me.lid : me.id,
514
+ from: isLid ? me.lid : me.id,
611
515
  to: toJid
612
516
  },
613
517
  content: [
@@ -616,15 +520,14 @@ const makeChatsSocket = (config) => {
616
520
  attrs: type === 'recording' ? { media: 'audio' } : {}
617
521
  }
618
522
  ]
619
- })
523
+ });
620
524
  }
621
- }
622
-
525
+ };
623
526
  /**
624
527
  * @param toJid the jid to subscribe to
625
528
  * @param tcToken token for subscription, use if present
626
529
  */
627
- const presenceSubscribe = (toJid, tcToken) => (sendNode({
530
+ const presenceSubscribe = (toJid, tcToken) => sendNode({
628
531
  tag: 'presence',
629
532
  attrs: {
630
533
  to: toJid,
@@ -640,72 +543,58 @@ const makeChatsSocket = (config) => {
640
543
  }
641
544
  ]
642
545
  : undefined
643
- }))
644
-
546
+ });
645
547
  const handlePresenceUpdate = ({ tag, attrs, content }) => {
646
- let presence
647
- const jid = attrs.from
648
- const participant = attrs.participant || attrs.from
649
-
650
- if (shouldIgnoreJid(jid) && jid !== '@s.whatsapp.net') {
651
- return
548
+ let presence;
549
+ const jid = attrs.from;
550
+ const participant = attrs.participant || attrs.from;
551
+ if (shouldIgnoreJid(jid) && jid !== S_WHATSAPP_NET) {
552
+ return;
652
553
  }
653
-
654
554
  if (tag === 'presence') {
655
555
  presence = {
656
556
  lastKnownPresence: attrs.type === 'unavailable' ? 'unavailable' : 'available',
657
557
  lastSeen: attrs.last && attrs.last !== 'deny' ? +attrs.last : undefined
658
- }
558
+ };
659
559
  }
660
-
661
560
  else if (Array.isArray(content)) {
662
- const [firstChild] = content
663
- let type = firstChild.tag
664
-
561
+ const [firstChild] = content;
562
+ let type = firstChild.tag;
665
563
  if (type === 'paused') {
666
- type = 'available'
564
+ type = 'available';
667
565
  }
668
-
669
566
  if (firstChild.attrs?.media === 'audio') {
670
- type = 'recording'
567
+ type = 'recording';
671
568
  }
672
-
673
- presence = { lastKnownPresence: type }
569
+ presence = { lastKnownPresence: type };
674
570
  }
675
-
676
571
  else {
677
- logger.error({ tag, attrs, content }, 'recv invalid presence node')
572
+ logger.error({ tag, attrs, content }, 'recv invalid presence node');
678
573
  }
679
-
680
574
  if (presence) {
681
- ev.emit('presence.update', { id: jid, presences: { [participant]: presence } })
575
+ ev.emit('presence.update', { id: jid, presences: { [participant]: presence } });
682
576
  }
683
- }
684
-
577
+ };
685
578
  const appPatch = async (patchCreate) => {
686
- const name = patchCreate.type
687
- const myAppStateKeyId = authState.creds.myAppStateKeyId
688
-
579
+ const name = patchCreate.type;
580
+ const myAppStateKeyId = authState.creds.myAppStateKeyId;
689
581
  if (!myAppStateKeyId) {
690
- throw new boom_1.Boom('App state key not present!', { statusCode: 400 })
582
+ throw new Boom('App state key not present!', { statusCode: 400 });
691
583
  }
692
-
693
- let initial
694
- let encodeResult
695
-
584
+ let initial;
585
+ let encodeResult;
696
586
  await processingMutex.mutex(async () => {
697
587
  await authState.keys.transaction(async () => {
698
- logger.debug({ patch: patchCreate }, 'applying app patch')
699
- await resyncAppState([name], false)
700
- const { [name]: currentSyncVersion } = await authState.keys.get('app-state-sync-version', [name])
701
- initial = currentSyncVersion || Utils_1.newLTHashState()
702
- encodeResult = await Utils_1.encodeSyncdPatch(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey)
703
- const { patch, state } = encodeResult
704
-
588
+ logger.debug({ patch: patchCreate }, 'applying app patch');
589
+ await resyncAppState([name], false);
590
+ const { [name]: currentSyncVersion } = await authState.keys.get('app-state-sync-version', [name]);
591
+ initial = currentSyncVersion || newLTHashState();
592
+ encodeResult = await encodeSyncdPatch(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey);
593
+ const { patch, state } = encodeResult;
705
594
  const node = {
706
595
  tag: 'iq',
707
596
  attrs: {
708
- to: WABinary_1.S_WHATSAPP_NET,
597
+ to: S_WHATSAPP_NET,
709
598
  type: 'set',
710
599
  xmlns: 'w:sync:app:state'
711
600
  },
@@ -719,88 +608,82 @@ const makeChatsSocket = (config) => {
719
608
  attrs: {
720
609
  name,
721
610
  version: (state.version - 1).toString(),
722
- 'return_snapshot': 'false'
611
+ return_snapshot: 'false'
723
612
  },
724
613
  content: [
725
614
  {
726
615
  tag: 'patch',
727
616
  attrs: {},
728
- content: WAProto_1.proto.SyncdPatch.encode(patch).finish()
617
+ content: proto.SyncdPatch.encode(patch).finish()
729
618
  }
730
619
  ]
731
620
  }
732
621
  ]
733
622
  }
734
623
  ]
735
- }
736
- await query(node)
737
- await authState.keys.set({ 'app-state-sync-version': { [name]: state } })
738
- })
739
- })
740
-
624
+ };
625
+ await query(node);
626
+ await authState.keys.set({ 'app-state-sync-version': { [name]: state } });
627
+ }, authState?.creds?.me?.id || 'app-patch');
628
+ });
741
629
  if (config.emitOwnEvents) {
742
- const { onMutation } = newAppStateChunkHandler(false)
743
- const { mutationMap } = await Utils_1.decodePatches(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version }, }], initial, getAppStateSyncKey, config.options, undefined, logger)
744
-
630
+ const { onMutation } = newAppStateChunkHandler(false);
631
+ const { mutationMap } = await decodePatches(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version } }], initial, getAppStateSyncKey, config.options, undefined, logger);
745
632
  for (const key in mutationMap) {
746
- onMutation(mutationMap[key])
633
+ onMutation(mutationMap[key]);
747
634
  }
748
635
  }
749
- }
750
-
636
+ };
751
637
  /** sending non-abt props may fix QR scan fail if server expects */
752
638
  const fetchProps = async () => {
639
+ //TODO: implement both protocol 1 and protocol 2 prop fetching, specially for abKey for WM
753
640
  const resultNode = await query({
754
641
  tag: 'iq',
755
642
  attrs: {
756
- to: WABinary_1.S_WHATSAPP_NET,
643
+ to: S_WHATSAPP_NET,
757
644
  xmlns: 'w',
758
- type: 'get',
645
+ type: 'get'
759
646
  },
760
647
  content: [
761
- { tag: 'props', attrs: {
648
+ {
649
+ tag: 'props',
650
+ attrs: {
762
651
  protocol: '2',
763
652
  hash: authState?.creds?.lastPropHash || ''
764
- } }
653
+ }
654
+ }
765
655
  ]
766
- })
767
-
768
- const propsNode = WABinary_1.getBinaryNodeChild(resultNode, 'props')
769
- let props = {}
770
-
656
+ });
657
+ const propsNode = getBinaryNodeChild(resultNode, 'props');
658
+ let props = {};
771
659
  if (propsNode) {
772
- if (propsNode.attrs?.hash) { // on some clients, the hash is returning as undefined
773
- authState.creds.lastPropHash = propsNode?.attrs?.hash
774
- ev.emit('creds.update', authState.creds)
660
+ if (propsNode.attrs?.hash) {
661
+ // on some clients, the hash is returning as undefined
662
+ authState.creds.lastPropHash = propsNode?.attrs?.hash;
663
+ ev.emit('creds.update', authState.creds);
775
664
  }
776
-
777
- props = WABinary_1.reduceBinaryNodeToDictionary(propsNode, 'prop')
665
+ props = reduceBinaryNodeToDictionary(propsNode, 'prop');
778
666
  }
779
- logger.debug('fetched props')
780
- return props
781
- }
782
-
667
+ logger.debug('fetched props');
668
+ return props;
669
+ };
783
670
  /**
784
671
  * modify a chat -- mark unread, read etc.
785
672
  * lastMessages must be sorted in reverse chronologically
786
- * requires the last messages till the last message received required for archive & unread
787
- */
673
+ * requires the last messages till the last message received; required for archive & unread
674
+ */
788
675
  const chatModify = (mod, jid) => {
789
- const patch = Utils_1.chatModificationToAppPatch(mod, jid)
790
- return appPatch(patch)
791
- }
792
-
676
+ const patch = chatModificationToAppPatch(mod, jid);
677
+ return appPatch(patch);
678
+ };
793
679
  /**
794
680
  * Enable/Disable link preview privacy, not related to baileys link preview generation
795
681
  */
796
682
  const updateDisableLinkPreviewsPrivacy = (isPreviewsDisabled) => {
797
- return chatModify({
798
- disableLinkPreviews: {
799
- isPreviewsDisabled
800
- }
801
- }, '')
802
- }
803
-
683
+ return chatModify({
684
+ disableLinkPreviews: { isPreviewsDisabled }
685
+ }, '');
686
+ };
804
687
  /**
805
688
  * Star or Unstar a message
806
689
  */
@@ -810,27 +693,24 @@ const makeChatsSocket = (config) => {
810
693
  messages,
811
694
  star
812
695
  }
813
- }, jid)
814
- }
815
-
696
+ }, jid);
697
+ };
816
698
  /**
817
- * Add Or Edit Contact
699
+ * Add or Edit Contact
818
700
  */
819
701
  const addOrEditContact = (jid, contact) => {
820
- return chatModify({
821
- contact
822
- }, jid)
823
- }
824
-
702
+ return chatModify({
703
+ contact
704
+ }, jid);
705
+ };
825
706
  /**
826
707
  * Remove Contact
827
708
  */
828
- const removeContact = (jid) => {
829
- return chatModify({
830
- contact: null
831
- }, jid)
832
- }
833
-
709
+ const removeContact = (jid) => {
710
+ return chatModify({
711
+ contact: null
712
+ }, jid);
713
+ };
834
714
  /**
835
715
  * Adds label
836
716
  */
@@ -839,9 +719,8 @@ const makeChatsSocket = (config) => {
839
719
  addLabel: {
840
720
  ...labels
841
721
  }
842
- }, jid)
843
- }
844
-
722
+ }, jid);
723
+ };
845
724
  /**
846
725
  * Adds label for the chats
847
726
  */
@@ -850,9 +729,8 @@ const makeChatsSocket = (config) => {
850
729
  addChatLabel: {
851
730
  labelId
852
731
  }
853
- }, jid)
854
- }
855
-
732
+ }, jid);
733
+ };
856
734
  /**
857
735
  * Removes label for the chat
858
736
  */
@@ -861,9 +739,8 @@ const makeChatsSocket = (config) => {
861
739
  removeChatLabel: {
862
740
  labelId
863
741
  }
864
- }, jid)
865
- }
866
-
742
+ }, jid);
743
+ };
867
744
  /**
868
745
  * Adds label for the message
869
746
  */
@@ -873,9 +750,8 @@ const makeChatsSocket = (config) => {
873
750
  messageId,
874
751
  labelId
875
752
  }
876
- }, jid)
877
- }
878
-
753
+ }, jid);
754
+ };
879
755
  /**
880
756
  * Removes label for the message
881
757
  */
@@ -885,198 +761,170 @@ const makeChatsSocket = (config) => {
885
761
  messageId,
886
762
  labelId
887
763
  }
888
- }, jid)
889
- }
890
-
764
+ }, jid);
765
+ };
891
766
  /**
892
- * Removes Chats
767
+ * Add or Edit Quick Reply
893
768
  */
894
- const clearMessage = (jid, key, timeStamp) => {
895
- return chatModify({
896
- delete: true,
897
- lastMessages: [{
898
- key: key,
899
- messageTimestamp: timeStamp
900
- }],
901
- }, jid)
902
- }
903
-
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
+ };
904
782
  /**
905
783
  * queries need to be fired on connection open
906
784
  * help ensure parity with WA Web
907
785
  * */
908
786
  const executeInitQueries = async () => {
909
- await Promise.all([
910
- fetchProps(),
911
- fetchBlocklist(),
912
- fetchPrivacySettings(),
913
- ])
914
- }
915
-
787
+ await Promise.all([fetchProps(), fetchBlocklist(), fetchPrivacySettings()]);
788
+ };
916
789
  const upsertMessage = ev.createBufferedFunction(async (msg, type) => {
917
- ev.emit('messages.upsert', { messages: [msg], type })
790
+ ev.emit('messages.upsert', { messages: [msg], type });
918
791
  if (!!msg.pushName) {
919
- let jid = msg.key.fromMe ? authState.creds.me.id : (msg.key.participant || msg.key.remoteJid)
920
- jid = WABinary_1.jidNormalizedUser(jid)
921
-
792
+ let jid = msg.key.fromMe ? authState.creds.me.id : msg.key.participant || msg.key.remoteJid;
793
+ jid = jidNormalizedUser(jid);
922
794
  if (!msg.key.fromMe) {
923
- ev.emit('contacts.update', [{ id: jid, notify: msg.pushName, verifiedName: msg.verifiedBizName }])
795
+ ev.emit('contacts.update', [{ id: jid, notify: msg.pushName, verifiedName: msg.verifiedBizName }]);
924
796
  }
925
-
926
797
  // update our pushname too
927
798
  if (msg.key.fromMe && msg.pushName && authState.creds.me?.name !== msg.pushName) {
928
- ev.emit('creds.update', { me: { ...authState.creds.me, name: msg.pushName } })
799
+ ev.emit('creds.update', { me: { ...authState.creds.me, name: msg.pushName } });
929
800
  }
930
801
  }
931
-
932
- const historyMsg = Utils_1.getHistoryMsg(msg.message)
802
+ const historyMsg = getHistoryMsg(msg.message);
933
803
  const shouldProcessHistoryMsg = historyMsg
934
- ? (shouldSyncHistoryMessage(historyMsg)
935
- && Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType))
936
- : false
937
-
938
- if (historyMsg && syncState === Types_1.SyncState.AwaitingInitialSync) {
804
+ ? shouldSyncHistoryMessage(historyMsg) && PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType)
805
+ : false;
806
+ // State machine: decide on sync and flush
807
+ if (historyMsg && syncState === SyncState.AwaitingInitialSync) {
939
808
  if (awaitingSyncTimeout) {
940
- clearTimeout(awaitingSyncTimeout)
941
- awaitingSyncTimeout = undefined
809
+ clearTimeout(awaitingSyncTimeout);
810
+ awaitingSyncTimeout = undefined;
942
811
  }
943
-
944
812
  if (shouldProcessHistoryMsg) {
945
- syncState = Types_1.SyncState.Syncing
946
- logger.info('Transitioned to Syncing state')
947
- // Let doAppStateSync handle the final flush after it`s done
948
- } else {
949
- syncState = Types_1.SyncState.Online
950
- logger.info('History sync skipped, transitioning to Online state and flushing buffer')
951
- ev.flush()
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();
952
821
  }
953
822
  }
954
-
955
823
  const doAppStateSync = async () => {
956
- if (syncState === Types_1.SyncState.Syncing) {
957
- logger.info('Doing app state sync')
958
- await resyncAppState(Types_1.ALL_WA_PATCH_NAMES, true)
959
-
960
- // Sync is complete, go online and flush everything
961
- syncState = Types_1.SyncState.Online
962
- logger.info('App state sync complete, transitioning to Online state and flushing buffer')
963
- ev.flush()
964
-
965
- const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1
966
- ev.emit('creds.update', { accountSyncCounter })
967
- }
968
- }
969
-
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
+ };
970
835
  await Promise.all([
971
836
  (async () => {
972
837
  if (shouldProcessHistoryMsg) {
973
- await doAppStateSync()
838
+ await doAppStateSync();
974
839
  }
975
840
  })(),
976
- Utils_1.processMessage(msg, {
841
+ processMessage(msg, {
842
+ signalRepository,
977
843
  shouldProcessHistoryMsg,
978
844
  placeholderResendCache,
979
845
  ev,
980
846
  creds: authState.creds,
981
847
  keyStore: authState.keys,
982
848
  logger,
983
- options: config.options,
984
- getMessage: config.getMessage,
849
+ options: config.options
985
850
  })
986
- ])
987
-
988
- if (msg.message?.protocolMessage?.appStateSyncKeyShare && syncState === Types_1.SyncState.Syncing) {
989
- logger.info('App state sync key arrived, triggering app state sync')
990
- await doAppStateSync()
991
- }
992
- })
993
-
994
- ws.on('CB:presence', handlePresenceUpdate)
995
- ws.on('CB:chatstate', handlePresenceUpdate)
851
+ ]);
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');
855
+ await doAppStateSync();
856
+ }
857
+ });
858
+ ws.on('CB:presence', handlePresenceUpdate);
859
+ ws.on('CB:chatstate', handlePresenceUpdate);
996
860
  ws.on('CB:ib,,dirty', async (node) => {
997
- const { attrs } = WABinary_1.getBinaryNodeChild(node, 'dirty')
998
- const type = attrs.type
999
-
861
+ const { attrs } = getBinaryNodeChild(node, 'dirty');
862
+ const type = attrs.type;
1000
863
  switch (type) {
1001
864
  case 'account_sync':
1002
865
  if (attrs.timestamp) {
1003
- let { lastAccountSyncTimestamp } = authState.creds
866
+ let { lastAccountSyncTimestamp } = authState.creds;
1004
867
  if (lastAccountSyncTimestamp) {
1005
- await cleanDirtyBits('account_sync', lastAccountSyncTimestamp)
868
+ await cleanDirtyBits('account_sync', lastAccountSyncTimestamp);
1006
869
  }
1007
- lastAccountSyncTimestamp = +attrs.timestamp
1008
- ev.emit('creds.update', { lastAccountSyncTimestamp })
870
+ lastAccountSyncTimestamp = +attrs.timestamp;
871
+ ev.emit('creds.update', { lastAccountSyncTimestamp });
1009
872
  }
1010
- break
873
+ break;
1011
874
  case 'groups':
1012
- await groupFetchAllParticipating()
1013
- await cleanDirtyBits('groups')
1014
- break
875
+ // handled in groups.ts
876
+ break;
1015
877
  default:
1016
- logger.info({ node }, 'received unknown sync')
1017
- break
878
+ logger.info({ node }, 'received unknown sync');
879
+ break;
1018
880
  }
1019
- })
1020
-
881
+ });
1021
882
  ev.on('connection.update', ({ connection, receivedPendingNotifications }) => {
1022
883
  if (connection === 'open') {
1023
884
  if (fireInitQueries) {
1024
- executeInitQueries()
1025
- .catch(error => onUnexpectedError(error, 'init queries'))
885
+ executeInitQueries().catch(error => onUnexpectedError(error, 'init queries'));
1026
886
  }
1027
- sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
1028
- .catch(error => onUnexpectedError(error, 'presence update requests'))
887
+ sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable').catch(error => onUnexpectedError(error, 'presence update requests'));
1029
888
  }
1030
-
1031
- if (!receivedPendingNotifications || syncState !== Types_1.SyncState.Connecting) {
1032
- return
889
+ if (!receivedPendingNotifications || syncState !== SyncState.Connecting) {
890
+ return;
1033
891
  }
1034
-
1035
- syncState = Types_1.AwaitingInitialSync
1036
- logger.info('Connection is now AwaitingInitialSync, buffering events')
1037
- ev.buffer()
1038
-
1039
- const willSyncHistory = shouldSyncHistoryMessage(WAProto_1.proto.Message.HistorySyncNotification.fromObject({
1040
- syncType: WAProto_1.proto.HistorySync.HistorySyncType.RECENT
1041
- }))
1042
-
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
+ }));
1043
898
  if (!willSyncHistory) {
1044
- logger.info('History sync is disabled by config, not waiting for notification. Transitioning to Online.')
1045
- syncState = Types_1.SyncState.Online
1046
- setTimeout(() => ev.flush(), 0)
1047
- return
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;
1048
903
  }
1049
-
1050
- logger.info('History sync is enabled, awaiting notification with a 20s timeout.')
1051
-
904
+ logger.info('History sync is enabled, awaiting notification with a 20s timeout.');
1052
905
  if (awaitingSyncTimeout) {
1053
- clearTimeout(awaitingSyncTimeout)
906
+ clearTimeout(awaitingSyncTimeout);
1054
907
  }
1055
-
1056
908
  awaitingSyncTimeout = setTimeout(() => {
1057
- if (syncState === Types_1.SyncState.AwaitingInitialSync) {
1058
- logger.warn('Timeout in AwaitingInitialSync, forcing state to Online and flushing buffer')
1059
- syncState = Types_1.SyncState.Online
1060
- ev.flush()
1061
- }
1062
- }, 20_000)
1063
- })
1064
-
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);
916
+ });
1065
917
  return {
1066
- ...Neele,
1067
- star,
1068
- addOrEditContact,
1069
- removeContact,
918
+ ...sock,
919
+ createCallLink,
920
+ getBotListV2,
1070
921
  processingMutex,
1071
922
  fetchPrivacySettings,
1072
923
  upsertMessage,
1073
924
  appPatch,
1074
- createCallLink,
1075
925
  sendPresenceUpdate,
1076
- presenceSubscribe,
1077
- getBotListV2,
1078
- getLidUser,
1079
- onWhatsApp,
926
+ presenceSubscribe,
927
+ profilePictureUrl,
1080
928
  fetchBlocklist,
1081
929
  fetchStatus,
1082
930
  fetchDisappearingDuration,
@@ -1085,8 +933,9 @@ const makeChatsSocket = (config) => {
1085
933
  updateProfileStatus,
1086
934
  updateProfileName,
1087
935
  updateBlockStatus,
936
+ updateDisableLinkPreviewsPrivacy,
1088
937
  updateCallPrivacy,
1089
- updateMessagesPrivacy,
938
+ updateMessagesPrivacy,
1090
939
  updateLastSeenPrivacy,
1091
940
  updateOnlinePrivacy,
1092
941
  updateProfilePicturePrivacy,
@@ -1094,20 +943,20 @@ const makeChatsSocket = (config) => {
1094
943
  updateReadReceiptsPrivacy,
1095
944
  updateGroupsAddPrivacy,
1096
945
  updateDefaultDisappearingMode,
1097
- updateDisableLinkPreviewsPrivacy,
1098
946
  getBusinessProfile,
1099
947
  resyncAppState,
1100
948
  chatModify,
1101
949
  cleanDirtyBits,
950
+ addOrEditContact,
951
+ removeContact,
1102
952
  addLabel,
1103
953
  addChatLabel,
1104
954
  removeChatLabel,
1105
955
  addMessageLabel,
1106
956
  removeMessageLabel,
1107
- clearMessage
1108
- }
1109
- }
1110
-
1111
- module.exports = {
1112
- makeChatsSocket
1113
- }
957
+ star,
958
+ addOrEditQuickReply,
959
+ removeQuickReply
960
+ };
961
+ };
962
+ //# sourceMappingURL=chats.js.map