@periskope/baileys 6.7.1-8.13

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 (361) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1303 -0
  3. package/WAProto/GenerateStatics.sh +2 -0
  4. package/WAProto/WAProto.proto +4633 -0
  5. package/WAProto/index.d.ts +53473 -0
  6. package/WAProto/index.js +165029 -0
  7. package/engine-requirements.js +10 -0
  8. package/lib/Defaults/baileys-version.json +3 -0
  9. package/lib/Defaults/index.d.ts +51 -0
  10. package/lib/Defaults/index.d.ts.map +1 -0
  11. package/lib/Defaults/index.js +106 -0
  12. package/lib/Defaults/index.js.map +1 -0
  13. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  14. package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
  15. package/lib/Signal/Group/ciphertext-message.js +15 -0
  16. package/lib/Signal/Group/ciphertext-message.js.map +1 -0
  17. package/lib/Signal/Group/group-session-builder.d.ts +14 -0
  18. package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
  19. package/lib/Signal/Group/group-session-builder.js +64 -0
  20. package/lib/Signal/Group/group-session-builder.js.map +1 -0
  21. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  22. package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
  23. package/lib/Signal/Group/group_cipher.js +96 -0
  24. package/lib/Signal/Group/group_cipher.js.map +1 -0
  25. package/lib/Signal/Group/index.d.ts +11 -0
  26. package/lib/Signal/Group/index.d.ts.map +1 -0
  27. package/lib/Signal/Group/index.js +57 -0
  28. package/lib/Signal/Group/index.js.map +1 -0
  29. package/lib/Signal/Group/keyhelper.d.ts +10 -0
  30. package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
  31. package/lib/Signal/Group/keyhelper.js +55 -0
  32. package/lib/Signal/Group/keyhelper.js.map +1 -0
  33. package/lib/Signal/Group/queue-job.d.ts +1 -0
  34. package/lib/Signal/Group/queue-job.d.ts.map +1 -0
  35. package/lib/Signal/Group/queue-job.js +57 -0
  36. package/lib/Signal/Group/queue-job.js.map +1 -0
  37. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  38. package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
  39. package/lib/Signal/Group/sender-chain-key.js +34 -0
  40. package/lib/Signal/Group/sender-chain-key.js.map +1 -0
  41. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  42. package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
  43. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  44. package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
  45. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  46. package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
  47. package/lib/Signal/Group/sender-key-message.js +69 -0
  48. package/lib/Signal/Group/sender-key-message.js.map +1 -0
  49. package/lib/Signal/Group/sender-key-name.d.ts +17 -0
  50. package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
  51. package/lib/Signal/Group/sender-key-name.js +51 -0
  52. package/lib/Signal/Group/sender-key-name.js.map +1 -0
  53. package/lib/Signal/Group/sender-key-record.d.ts +30 -0
  54. package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
  55. package/lib/Signal/Group/sender-key-record.js +53 -0
  56. package/lib/Signal/Group/sender-key-record.js.map +1 -0
  57. package/lib/Signal/Group/sender-key-state.d.ts +38 -0
  58. package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
  59. package/lib/Signal/Group/sender-key-state.js +99 -0
  60. package/lib/Signal/Group/sender-key-state.js.map +1 -0
  61. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  62. package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
  63. package/lib/Signal/Group/sender-message-key.js +29 -0
  64. package/lib/Signal/Group/sender-message-key.js.map +1 -0
  65. package/lib/Signal/libsignal.d.ts +3 -0
  66. package/lib/Signal/libsignal.d.ts.map +1 -0
  67. package/lib/Signal/libsignal.js +174 -0
  68. package/lib/Signal/libsignal.js.map +1 -0
  69. package/lib/Socket/Client/index.d.ts +2 -0
  70. package/lib/Socket/Client/index.d.ts.map +1 -0
  71. package/lib/Socket/Client/index.js +18 -0
  72. package/lib/Socket/Client/index.js.map +1 -0
  73. package/lib/Socket/Client/types.d.ts +15 -0
  74. package/lib/Socket/Client/types.d.ts.map +1 -0
  75. package/lib/Socket/Client/types.js +13 -0
  76. package/lib/Socket/Client/types.js.map +1 -0
  77. package/lib/Socket/Client/websocket.d.ts +12 -0
  78. package/lib/Socket/Client/websocket.d.ts.map +1 -0
  79. package/lib/Socket/Client/websocket.js +62 -0
  80. package/lib/Socket/Client/websocket.js.map +1 -0
  81. package/lib/Socket/business.d.ts +174 -0
  82. package/lib/Socket/business.d.ts.map +1 -0
  83. package/lib/Socket/business.js +260 -0
  84. package/lib/Socket/business.js.map +1 -0
  85. package/lib/Socket/chats.d.ts +90 -0
  86. package/lib/Socket/chats.d.ts.map +1 -0
  87. package/lib/Socket/chats.js +899 -0
  88. package/lib/Socket/chats.js.map +1 -0
  89. package/lib/Socket/communities.d.ts +218 -0
  90. package/lib/Socket/communities.d.ts.map +1 -0
  91. package/lib/Socket/communities.js +351 -0
  92. package/lib/Socket/communities.js.map +1 -0
  93. package/lib/Socket/groups.d.ts +130 -0
  94. package/lib/Socket/groups.d.ts.map +1 -0
  95. package/lib/Socket/groups.js +332 -0
  96. package/lib/Socket/groups.js.map +1 -0
  97. package/lib/Socket/index.d.ts +174 -0
  98. package/lib/Socket/index.d.ts.map +1 -0
  99. package/lib/Socket/index.js +10 -0
  100. package/lib/Socket/index.js.map +1 -0
  101. package/lib/Socket/messages-recv.d.ts +163 -0
  102. package/lib/Socket/messages-recv.d.ts.map +1 -0
  103. package/lib/Socket/messages-recv.js +1119 -0
  104. package/lib/Socket/messages-recv.js.map +1 -0
  105. package/lib/Socket/messages-send.d.ts +158 -0
  106. package/lib/Socket/messages-send.d.ts.map +1 -0
  107. package/lib/Socket/messages-send.js +722 -0
  108. package/lib/Socket/messages-send.js.map +1 -0
  109. package/lib/Socket/mex.d.ts +2 -0
  110. package/lib/Socket/mex.d.ts.map +1 -0
  111. package/lib/Socket/mex.js +46 -0
  112. package/lib/Socket/mex.js.map +1 -0
  113. package/lib/Socket/newsletter.d.ts +141 -0
  114. package/lib/Socket/newsletter.d.ts.map +1 -0
  115. package/lib/Socket/newsletter.js +183 -0
  116. package/lib/Socket/newsletter.js.map +1 -0
  117. package/lib/Socket/socket.d.ts +42 -0
  118. package/lib/Socket/socket.d.ts.map +1 -0
  119. package/lib/Socket/socket.js +616 -0
  120. package/lib/Socket/socket.js.map +1 -0
  121. package/lib/Socket/usync.d.ts +36 -0
  122. package/lib/Socket/usync.d.ts.map +1 -0
  123. package/lib/Socket/usync.js +65 -0
  124. package/lib/Socket/usync.js.map +1 -0
  125. package/lib/Types/Auth.d.ts +103 -0
  126. package/lib/Types/Auth.d.ts.map +1 -0
  127. package/lib/Types/Auth.js +2 -0
  128. package/lib/Types/Auth.js.map +1 -0
  129. package/lib/Types/Call.d.ts +13 -0
  130. package/lib/Types/Call.d.ts.map +1 -0
  131. package/lib/Types/Call.js +2 -0
  132. package/lib/Types/Call.js.map +1 -0
  133. package/lib/Types/Chat.d.ts +115 -0
  134. package/lib/Types/Chat.d.ts.map +1 -0
  135. package/lib/Types/Chat.js +10 -0
  136. package/lib/Types/Chat.js.map +1 -0
  137. package/lib/Types/Contact.d.ts +23 -0
  138. package/lib/Types/Contact.d.ts.map +1 -0
  139. package/lib/Types/Contact.js +2 -0
  140. package/lib/Types/Contact.js.map +1 -0
  141. package/lib/Types/Events.d.ts +216 -0
  142. package/lib/Types/Events.d.ts.map +1 -0
  143. package/lib/Types/Events.js +2 -0
  144. package/lib/Types/Events.js.map +1 -0
  145. package/lib/Types/GroupMetadata.d.ts +66 -0
  146. package/lib/Types/GroupMetadata.d.ts.map +1 -0
  147. package/lib/Types/GroupMetadata.js +2 -0
  148. package/lib/Types/GroupMetadata.js.map +1 -0
  149. package/lib/Types/Label.d.ts +46 -0
  150. package/lib/Types/Label.d.ts.map +1 -0
  151. package/lib/Types/Label.js +27 -0
  152. package/lib/Types/Label.js.map +1 -0
  153. package/lib/Types/LabelAssociation.d.ts +29 -0
  154. package/lib/Types/LabelAssociation.d.ts.map +1 -0
  155. package/lib/Types/LabelAssociation.js +9 -0
  156. package/lib/Types/LabelAssociation.js.map +1 -0
  157. package/lib/Types/Message.d.ts +277 -0
  158. package/lib/Types/Message.d.ts.map +1 -0
  159. package/lib/Types/Message.js +7 -0
  160. package/lib/Types/Message.js.map +1 -0
  161. package/lib/Types/Newsletter.d.ts +134 -0
  162. package/lib/Types/Newsletter.d.ts.map +1 -0
  163. package/lib/Types/Newsletter.js +33 -0
  164. package/lib/Types/Newsletter.js.map +1 -0
  165. package/lib/Types/Product.d.ts +78 -0
  166. package/lib/Types/Product.d.ts.map +1 -0
  167. package/lib/Types/Product.js +2 -0
  168. package/lib/Types/Product.js.map +1 -0
  169. package/lib/Types/Signal.d.ts +57 -0
  170. package/lib/Types/Signal.d.ts.map +1 -0
  171. package/lib/Types/Signal.js +2 -0
  172. package/lib/Types/Signal.js.map +1 -0
  173. package/lib/Types/Socket.d.ts +121 -0
  174. package/lib/Types/Socket.d.ts.map +1 -0
  175. package/lib/Types/Socket.js +2 -0
  176. package/lib/Types/Socket.js.map +1 -0
  177. package/lib/Types/State.d.ts +27 -0
  178. package/lib/Types/State.d.ts.map +1 -0
  179. package/lib/Types/State.js +2 -0
  180. package/lib/Types/State.js.map +1 -0
  181. package/lib/Types/USync.d.ts +25 -0
  182. package/lib/Types/USync.d.ts.map +1 -0
  183. package/lib/Types/USync.js +2 -0
  184. package/lib/Types/USync.js.map +1 -0
  185. package/lib/Types/index.d.ts +64 -0
  186. package/lib/Types/index.d.ts.map +1 -0
  187. package/lib/Types/index.js +42 -0
  188. package/lib/Types/index.js.map +1 -0
  189. package/lib/Utils/auth-utils.d.ts +18 -0
  190. package/lib/Utils/auth-utils.d.ts.map +1 -0
  191. package/lib/Utils/auth-utils.js +199 -0
  192. package/lib/Utils/auth-utils.js.map +1 -0
  193. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  194. package/lib/Utils/baileys-event-stream.d.ts.map +1 -0
  195. package/lib/Utils/baileys-event-stream.js +63 -0
  196. package/lib/Utils/baileys-event-stream.js.map +1 -0
  197. package/lib/Utils/business.d.ts +22 -0
  198. package/lib/Utils/business.d.ts.map +1 -0
  199. package/lib/Utils/business.js +240 -0
  200. package/lib/Utils/business.js.map +1 -0
  201. package/lib/Utils/chat-utils.d.ts +70 -0
  202. package/lib/Utils/chat-utils.d.ts.map +1 -0
  203. package/lib/Utils/chat-utils.js +756 -0
  204. package/lib/Utils/chat-utils.js.map +1 -0
  205. package/lib/Utils/crypto.d.ts +40 -0
  206. package/lib/Utils/crypto.d.ts.map +1 -0
  207. package/lib/Utils/crypto.js +187 -0
  208. package/lib/Utils/crypto.js.map +1 -0
  209. package/lib/Utils/decode-wa-message.d.ts +35 -0
  210. package/lib/Utils/decode-wa-message.d.ts.map +1 -0
  211. package/lib/Utils/decode-wa-message.js +201 -0
  212. package/lib/Utils/decode-wa-message.js.map +1 -0
  213. package/lib/Utils/event-buffer.d.ts +35 -0
  214. package/lib/Utils/event-buffer.d.ts.map +1 -0
  215. package/lib/Utils/event-buffer.js +516 -0
  216. package/lib/Utils/event-buffer.js.map +1 -0
  217. package/lib/Utils/generics.d.ts +91 -0
  218. package/lib/Utils/generics.d.ts.map +1 -0
  219. package/lib/Utils/generics.js +400 -0
  220. package/lib/Utils/generics.js.map +1 -0
  221. package/lib/Utils/history.d.ts +19 -0
  222. package/lib/Utils/history.d.ts.map +1 -0
  223. package/lib/Utils/history.js +93 -0
  224. package/lib/Utils/history.js.map +1 -0
  225. package/lib/Utils/index.d.ts +17 -0
  226. package/lib/Utils/index.d.ts.map +1 -0
  227. package/lib/Utils/index.js +33 -0
  228. package/lib/Utils/index.js.map +1 -0
  229. package/lib/Utils/link-preview.d.ts +21 -0
  230. package/lib/Utils/link-preview.d.ts.map +1 -0
  231. package/lib/Utils/link-preview.js +128 -0
  232. package/lib/Utils/link-preview.js.map +1 -0
  233. package/lib/Utils/logger.d.ts +11 -0
  234. package/lib/Utils/logger.d.ts.map +1 -0
  235. package/lib/Utils/logger.js +7 -0
  236. package/lib/Utils/logger.js.map +1 -0
  237. package/lib/Utils/lt-hash.d.ts +12 -0
  238. package/lib/Utils/lt-hash.d.ts.map +1 -0
  239. package/lib/Utils/lt-hash.js +51 -0
  240. package/lib/Utils/lt-hash.js.map +1 -0
  241. package/lib/Utils/make-mutex.d.ts +7 -0
  242. package/lib/Utils/make-mutex.d.ts.map +1 -0
  243. package/lib/Utils/make-mutex.js +44 -0
  244. package/lib/Utils/make-mutex.js.map +1 -0
  245. package/lib/Utils/messages-media.d.ts +112 -0
  246. package/lib/Utils/messages-media.d.ts.map +1 -0
  247. package/lib/Utils/messages-media.js +722 -0
  248. package/lib/Utils/messages-media.js.map +1 -0
  249. package/lib/Utils/messages.d.ts +75 -0
  250. package/lib/Utils/messages.d.ts.map +1 -0
  251. package/lib/Utils/messages.js +799 -0
  252. package/lib/Utils/messages.js.map +1 -0
  253. package/lib/Utils/noise-handler.d.ts +19 -0
  254. package/lib/Utils/noise-handler.d.ts.map +1 -0
  255. package/lib/Utils/noise-handler.js +150 -0
  256. package/lib/Utils/noise-handler.js.map +1 -0
  257. package/lib/Utils/process-message.d.ts +42 -0
  258. package/lib/Utils/process-message.d.ts.map +1 -0
  259. package/lib/Utils/process-message.js +375 -0
  260. package/lib/Utils/process-message.js.map +1 -0
  261. package/lib/Utils/signal.d.ts +33 -0
  262. package/lib/Utils/signal.d.ts.map +1 -0
  263. package/lib/Utils/signal.js +155 -0
  264. package/lib/Utils/signal.js.map +1 -0
  265. package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
  266. package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
  267. package/lib/Utils/use-multi-file-auth-state.js +124 -0
  268. package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
  269. package/lib/Utils/validate-connection.d.ts +10 -0
  270. package/lib/Utils/validate-connection.d.ts.map +1 -0
  271. package/lib/Utils/validate-connection.js +170 -0
  272. package/lib/Utils/validate-connection.js.map +1 -0
  273. package/lib/WABinary/constants.d.ts +27 -0
  274. package/lib/WABinary/constants.d.ts.map +1 -0
  275. package/lib/WABinary/constants.js +1303 -0
  276. package/lib/WABinary/constants.js.map +1 -0
  277. package/lib/WABinary/decode.d.ts +6 -0
  278. package/lib/WABinary/decode.d.ts.map +1 -0
  279. package/lib/WABinary/decode.js +266 -0
  280. package/lib/WABinary/decode.js.map +1 -0
  281. package/lib/WABinary/encode.d.ts +2 -0
  282. package/lib/WABinary/encode.d.ts.map +1 -0
  283. package/lib/WABinary/encode.js +252 -0
  284. package/lib/WABinary/encode.js.map +1 -0
  285. package/lib/WABinary/generic-utils.d.ts +14 -0
  286. package/lib/WABinary/generic-utils.d.ts.map +1 -0
  287. package/lib/WABinary/generic-utils.js +110 -0
  288. package/lib/WABinary/generic-utils.js.map +1 -0
  289. package/lib/WABinary/index.d.ts +5 -0
  290. package/lib/WABinary/index.d.ts.map +1 -0
  291. package/lib/WABinary/index.js +21 -0
  292. package/lib/WABinary/index.js.map +1 -0
  293. package/lib/WABinary/jid-utils.d.ts +35 -0
  294. package/lib/WABinary/jid-utils.d.ts.map +1 -0
  295. package/lib/WABinary/jid-utils.js +66 -0
  296. package/lib/WABinary/jid-utils.js.map +1 -0
  297. package/lib/WABinary/types.d.ts +18 -0
  298. package/lib/WABinary/types.d.ts.map +1 -0
  299. package/lib/WABinary/types.js +2 -0
  300. package/lib/WABinary/types.js.map +1 -0
  301. package/lib/WAM/BinaryInfo.d.ts +8 -0
  302. package/lib/WAM/BinaryInfo.d.ts.map +1 -0
  303. package/lib/WAM/BinaryInfo.js +13 -0
  304. package/lib/WAM/BinaryInfo.js.map +1 -0
  305. package/lib/WAM/constants.d.ts +39 -0
  306. package/lib/WAM/constants.d.ts.map +1 -0
  307. package/lib/WAM/constants.js +15243 -0
  308. package/lib/WAM/constants.js.map +1 -0
  309. package/lib/WAM/encode.d.ts +2 -0
  310. package/lib/WAM/encode.d.ts.map +1 -0
  311. package/lib/WAM/encode.js +153 -0
  312. package/lib/WAM/encode.js.map +1 -0
  313. package/lib/WAM/index.d.ts +3 -0
  314. package/lib/WAM/index.d.ts.map +1 -0
  315. package/lib/WAM/index.js +19 -0
  316. package/lib/WAM/index.js.map +1 -0
  317. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  318. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
  319. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  320. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
  321. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  322. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
  323. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  324. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
  325. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  326. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
  327. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  328. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
  329. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  330. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
  331. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  332. package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
  333. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
  334. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
  335. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
  336. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
  337. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
  338. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
  339. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
  340. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
  341. package/lib/WAUSync/Protocols/index.d.ts +4 -0
  342. package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
  343. package/lib/WAUSync/Protocols/index.js +20 -0
  344. package/lib/WAUSync/Protocols/index.js.map +1 -0
  345. package/lib/WAUSync/USyncQuery.d.ts +28 -0
  346. package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
  347. package/lib/WAUSync/USyncQuery.js +93 -0
  348. package/lib/WAUSync/USyncQuery.js.map +1 -0
  349. package/lib/WAUSync/USyncUser.d.ts +12 -0
  350. package/lib/WAUSync/USyncUser.d.ts.map +1 -0
  351. package/lib/WAUSync/USyncUser.js +26 -0
  352. package/lib/WAUSync/USyncUser.js.map +1 -0
  353. package/lib/WAUSync/index.d.ts +3 -0
  354. package/lib/WAUSync/index.d.ts.map +1 -0
  355. package/lib/WAUSync/index.js +19 -0
  356. package/lib/WAUSync/index.js.map +1 -0
  357. package/lib/index.d.ts +11 -0
  358. package/lib/index.d.ts.map +1 -0
  359. package/lib/index.js +30 -0
  360. package/lib/index.js.map +1 -0
  361. package/package.json +104 -0
@@ -0,0 +1,1119 @@
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.makeMessagesRecvSocket = void 0;
7
+ const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
8
+ const boom_1 = require("@hapi/boom");
9
+ const crypto_1 = require("crypto");
10
+ const WAProto_1 = require("../../WAProto");
11
+ const Defaults_1 = require("../Defaults");
12
+ const Types_1 = require("../Types");
13
+ const Utils_1 = require("../Utils");
14
+ const make_mutex_1 = require("../Utils/make-mutex");
15
+ const WABinary_1 = require("../WABinary");
16
+ const groups_1 = require("./groups");
17
+ const messages_send_1 = require("./messages-send");
18
+ const makeMessagesRecvSocket = (config) => {
19
+ const { logger, retryRequestDelayMs, maxMsgRetryCount, getMessage, shouldIgnoreJid } = config;
20
+ const sock = (0, messages_send_1.makeMessagesSocket)(config);
21
+ const { ev, authState, ws, processingMutex, signalRepository, query, upsertMessage, resyncAppState, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, sendPeerDataOperationMessage } = sock;
22
+ /** this mutex ensures that each retryRequest will wait for the previous one to finish */
23
+ const retryMutex = (0, make_mutex_1.makeMutex)();
24
+ const msgRetryCache = config.msgRetryCounterCache ||
25
+ new node_cache_1.default({
26
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
27
+ useClones: false
28
+ });
29
+ const callOfferCache = config.callOfferCache ||
30
+ new node_cache_1.default({
31
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.CALL_OFFER, // 5 mins
32
+ useClones: false
33
+ });
34
+ const placeholderResendCache = config.placeholderResendCache ||
35
+ new node_cache_1.default({
36
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
37
+ useClones: false
38
+ });
39
+ let sendActiveReceipts = false;
40
+ const sendMessageAck = async ({ tag, attrs, content }, errorCode) => {
41
+ var _a, _b, _c, _d, _e;
42
+ const stanza = {
43
+ tag: 'ack',
44
+ attrs: {
45
+ id: attrs.id,
46
+ to: attrs.from,
47
+ class: tag
48
+ }
49
+ };
50
+ if (!!errorCode) {
51
+ stanza.attrs.error = errorCode.toString();
52
+ }
53
+ if (!!attrs.participant) {
54
+ stanza.attrs.participant = attrs.participant;
55
+ }
56
+ if (!!attrs.recipient) {
57
+ stanza.attrs.recipient = attrs.recipient;
58
+ }
59
+ if (!!attrs.type &&
60
+ (tag !== 'message' || (0, WABinary_1.getBinaryNodeChild)({ tag, attrs, content }, 'unavailable') || errorCode !== 0)) {
61
+ stanza.attrs.type = attrs.type;
62
+ }
63
+ if (tag === 'message' && (0, WABinary_1.getBinaryNodeChild)({ tag, attrs, content }, 'unavailable')) {
64
+ stanza.attrs.from = authState.creds.me.id;
65
+ }
66
+ if (tag === 'receipt' && ((_a = attrs.from) === null || _a === void 0 ? void 0 : _a.includes('broadcast'))) {
67
+ ev.emit('broadcast-receipt.update', {
68
+ id: attrs.id,
69
+ participant: attrs.participant,
70
+ timestamp: Number(attrs.t),
71
+ broadcast: attrs.from,
72
+ type: attrs.type === 'read' ? 'read' : 'delivered'
73
+ });
74
+ if (content) {
75
+ for (const child of content) {
76
+ for (const c of child === null || child === void 0 ? void 0 : child.content) {
77
+ ev.emit('broadcast-receipt.update', {
78
+ id: (_b = child === null || child === void 0 ? void 0 : child.attrs) === null || _b === void 0 ? void 0 : _b.key,
79
+ participant: (_c = c === null || c === void 0 ? void 0 : c.attrs) === null || _c === void 0 ? void 0 : _c.jid,
80
+ timestamp: Number((_d = c === null || c === void 0 ? void 0 : c.attrs) === null || _d === void 0 ? void 0 : _d.t),
81
+ broadcast: attrs.from,
82
+ type: ((_e = c === null || c === void 0 ? void 0 : c.attrs) === null || _e === void 0 ? void 0 : _e.type) === 'read' ? 'read' : 'delivered'
83
+ });
84
+ }
85
+ }
86
+ }
87
+ }
88
+ logger.debug({ recv: { tag, attrs }, sent: stanza.attrs }, 'sent ack');
89
+ await sendNode(stanza);
90
+ };
91
+ const rejectCall = async (callId, callFrom) => {
92
+ const stanza = {
93
+ tag: 'call',
94
+ attrs: {
95
+ from: authState.creds.me.id,
96
+ to: callFrom
97
+ },
98
+ content: [
99
+ {
100
+ tag: 'reject',
101
+ attrs: {
102
+ 'call-id': callId,
103
+ 'call-creator': callFrom,
104
+ count: '0'
105
+ },
106
+ content: undefined
107
+ }
108
+ ]
109
+ };
110
+ await query(stanza);
111
+ };
112
+ const sendRetryRequest = async (node, forceIncludeKeys = false) => {
113
+ const { fullMessage } = (0, Utils_1.decodeMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '');
114
+ const { key: msgKey } = fullMessage;
115
+ const msgId = msgKey.id;
116
+ const key = `${msgId}:${msgKey === null || msgKey === void 0 ? void 0 : msgKey.participant}`;
117
+ let retryCount = msgRetryCache.get(key) || 0;
118
+ if (retryCount >= maxMsgRetryCount) {
119
+ logger.debug({ retryCount, msgId }, 'reached retry limit, clearing');
120
+ msgRetryCache.del(key);
121
+ return;
122
+ }
123
+ retryCount += 1;
124
+ msgRetryCache.set(key, retryCount);
125
+ const { account, signedPreKey, signedIdentityKey: identityKey } = authState.creds;
126
+ if (retryCount === 1) {
127
+ //request a resend via phone
128
+ const msgId = await requestPlaceholderResend(msgKey);
129
+ logger.debug(`sendRetryRequest: requested placeholder resend for message ${msgId}`);
130
+ }
131
+ const deviceIdentity = (0, Utils_1.encodeSignedDeviceIdentity)(account, true);
132
+ await authState.keys.transaction(async () => {
133
+ const receipt = {
134
+ tag: 'receipt',
135
+ attrs: {
136
+ id: msgId,
137
+ type: 'retry',
138
+ to: node.attrs.from
139
+ },
140
+ content: [
141
+ {
142
+ tag: 'retry',
143
+ attrs: {
144
+ count: retryCount.toString(),
145
+ id: node.attrs.id,
146
+ t: node.attrs.t,
147
+ v: '1'
148
+ }
149
+ },
150
+ {
151
+ tag: 'registration',
152
+ attrs: {},
153
+ content: (0, Utils_1.encodeBigEndian)(authState.creds.registrationId)
154
+ }
155
+ ]
156
+ };
157
+ if (node.attrs.recipient) {
158
+ receipt.attrs.recipient = node.attrs.recipient;
159
+ }
160
+ if (node.attrs.participant) {
161
+ receipt.attrs.participant = node.attrs.participant;
162
+ }
163
+ if (retryCount > 1 || forceIncludeKeys) {
164
+ const { update, preKeys } = await (0, Utils_1.getNextPreKeys)(authState, 1);
165
+ const [keyId] = Object.keys(preKeys);
166
+ const key = preKeys[+keyId];
167
+ const content = receipt.content;
168
+ content.push({
169
+ tag: 'keys',
170
+ attrs: {},
171
+ content: [
172
+ { tag: 'type', attrs: {}, content: Buffer.from(Defaults_1.KEY_BUNDLE_TYPE) },
173
+ { tag: 'identity', attrs: {}, content: identityKey.public },
174
+ (0, Utils_1.xmppPreKey)(key, +keyId),
175
+ (0, Utils_1.xmppSignedPreKey)(signedPreKey),
176
+ { tag: 'device-identity', attrs: {}, content: deviceIdentity }
177
+ ]
178
+ });
179
+ ev.emit('creds.update', update);
180
+ }
181
+ await sendNode(receipt);
182
+ logger.info({ msgAttrs: node.attrs, retryCount }, 'sent retry receipt');
183
+ });
184
+ };
185
+ const handleEncryptNotification = async (node) => {
186
+ const from = node.attrs.from;
187
+ if (from === WABinary_1.S_WHATSAPP_NET) {
188
+ const countChild = (0, WABinary_1.getBinaryNodeChild)(node, 'count');
189
+ const count = +countChild.attrs.value;
190
+ const shouldUploadMorePreKeys = count < Defaults_1.MIN_PREKEY_COUNT;
191
+ logger.debug({ count, shouldUploadMorePreKeys }, 'recv pre-key count');
192
+ if (shouldUploadMorePreKeys) {
193
+ await uploadPreKeys();
194
+ }
195
+ }
196
+ else {
197
+ const identityNode = (0, WABinary_1.getBinaryNodeChild)(node, 'identity');
198
+ if (identityNode) {
199
+ logger.info({ jid: from }, 'identity changed');
200
+ // not handling right now
201
+ // signal will override new identity anyway
202
+ }
203
+ else {
204
+ logger.info({ node }, 'unknown encrypt notification');
205
+ }
206
+ }
207
+ };
208
+ const handleGroupNotification = (participant, child, msg) => {
209
+ var _a, _b, _c, _d;
210
+ const participantJid = ((_b = (_a = (0, WABinary_1.getBinaryNodeChild)(child, 'participant')) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.jid) || participant;
211
+ switch (child === null || child === void 0 ? void 0 : child.tag) {
212
+ case 'create':
213
+ const metadata = (0, groups_1.extractGroupMetadata)(child);
214
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_CREATE;
215
+ msg.messageStubParameters = [metadata.subject];
216
+ msg.key = { participant: metadata.owner };
217
+ ev.emit('chats.upsert', [
218
+ {
219
+ id: metadata.id,
220
+ name: metadata.subject,
221
+ conversationTimestamp: metadata.creation
222
+ }
223
+ ]);
224
+ ev.emit('groups.upsert', [
225
+ {
226
+ ...metadata,
227
+ author: participant
228
+ }
229
+ ]);
230
+ break;
231
+ case 'ephemeral':
232
+ case 'not_ephemeral':
233
+ msg.message = {
234
+ protocolMessage: {
235
+ type: WAProto_1.proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING,
236
+ ephemeralExpiration: +(child.attrs.expiration || 0)
237
+ }
238
+ };
239
+ break;
240
+ case 'modify':
241
+ const oldNumber = (0, WABinary_1.getBinaryNodeChildren)(child, 'participant').map(p => p.attrs.jid);
242
+ msg.messageStubParameters = oldNumber || [];
243
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER;
244
+ break;
245
+ case 'promote':
246
+ case 'demote':
247
+ case 'remove':
248
+ case 'add':
249
+ case 'leave':
250
+ const stubType = `GROUP_PARTICIPANT_${child.tag.toUpperCase()}`;
251
+ msg.messageStubType = Types_1.WAMessageStubType[stubType];
252
+ const participants = (0, WABinary_1.getBinaryNodeChildren)(child, 'participant').map(p => p.attrs.jid);
253
+ if (participants.length === 1 &&
254
+ // if recv. "remove" message and sender removed themselves
255
+ // mark as left
256
+ (0, WABinary_1.areJidsSameUser)(participants[0], participant) &&
257
+ child.tag === 'remove') {
258
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE;
259
+ }
260
+ msg.messageStubParameters = participants;
261
+ break;
262
+ case 'subject':
263
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT;
264
+ msg.messageStubParameters = [child.attrs.subject];
265
+ break;
266
+ case 'description':
267
+ const description = (_d = (_c = (0, WABinary_1.getBinaryNodeChild)(child, 'body')) === null || _c === void 0 ? void 0 : _c.content) === null || _d === void 0 ? void 0 : _d.toString();
268
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_DESCRIPTION;
269
+ msg.messageStubParameters = description ? [description] : undefined;
270
+ break;
271
+ case 'announcement':
272
+ case 'not_announcement':
273
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE;
274
+ msg.messageStubParameters = [child.tag === 'announcement' ? 'on' : 'off'];
275
+ break;
276
+ case 'locked':
277
+ case 'unlocked':
278
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_RESTRICT;
279
+ msg.messageStubParameters = [child.tag === 'locked' ? 'on' : 'off'];
280
+ break;
281
+ case 'invite':
282
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK;
283
+ msg.messageStubParameters = [child.attrs.code];
284
+ break;
285
+ case 'member_add_mode':
286
+ const addMode = child.content;
287
+ if (addMode) {
288
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_MEMBER_ADD_MODE;
289
+ msg.messageStubParameters = [addMode.toString()];
290
+ }
291
+ break;
292
+ case 'membership_approval_mode':
293
+ const approvalMode = (0, WABinary_1.getBinaryNodeChild)(child, 'group_join');
294
+ if (approvalMode) {
295
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE;
296
+ msg.messageStubParameters = [approvalMode.attrs.state];
297
+ }
298
+ break;
299
+ case 'created_membership_requests':
300
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
301
+ msg.messageStubParameters = [participantJid, 'created', child.attrs.request_method];
302
+ break;
303
+ case 'revoked_membership_requests':
304
+ const isDenied = (0, WABinary_1.areJidsSameUser)(participantJid, participant);
305
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
306
+ msg.messageStubParameters = [participantJid, isDenied ? 'revoked' : 'rejected'];
307
+ break;
308
+ }
309
+ };
310
+ const processNotification = async (node) => {
311
+ var _a, _b, _c;
312
+ const result = {};
313
+ const [child] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
314
+ const nodeType = node.attrs.type;
315
+ const from = (0, WABinary_1.jidNormalizedUser)(node.attrs.from);
316
+ switch (nodeType) {
317
+ case 'privacy_token':
318
+ const tokenList = (0, WABinary_1.getBinaryNodeChildren)(child, 'token');
319
+ for (const { attrs, content } of tokenList) {
320
+ const jid = attrs.jid;
321
+ ev.emit('chats.update', [
322
+ {
323
+ id: jid,
324
+ tcToken: content
325
+ }
326
+ ]);
327
+ logger.debug({ jid }, 'got privacy token update');
328
+ }
329
+ break;
330
+ case 'newsletter':
331
+ await handleNewsletterNotification(node);
332
+ break;
333
+ case 'mex':
334
+ await handleMexNewsletterNotification(node);
335
+ break;
336
+ case 'w:gp2':
337
+ handleGroupNotification(node.attrs.participant, child, result);
338
+ break;
339
+ case 'mediaretry':
340
+ const event = (0, Utils_1.decodeMediaRetryNode)(node);
341
+ ev.emit('messages.media-update', [event]);
342
+ break;
343
+ case 'encrypt':
344
+ await handleEncryptNotification(node);
345
+ break;
346
+ case 'devices':
347
+ const devices = (0, WABinary_1.getBinaryNodeChildren)(child, 'device');
348
+ if ((0, WABinary_1.areJidsSameUser)(child.attrs.jid, authState.creds.me.id)) {
349
+ const deviceJids = devices.map(d => d.attrs.jid);
350
+ logger.info({ deviceJids }, 'got my own devices');
351
+ }
352
+ break;
353
+ case 'server_sync':
354
+ const update = (0, WABinary_1.getBinaryNodeChild)(node, 'collection');
355
+ if (update) {
356
+ const name = update.attrs.name;
357
+ await resyncAppState([name], false);
358
+ }
359
+ break;
360
+ case 'picture':
361
+ const setPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'set');
362
+ const delPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'delete');
363
+ ev.emit('contacts.update', [
364
+ {
365
+ id: (0, WABinary_1.jidNormalizedUser)((_a = node === null || node === void 0 ? void 0 : node.attrs) === null || _a === void 0 ? void 0 : _a.from) || ((_c = (_b = (setPicture || delPicture)) === null || _b === void 0 ? void 0 : _b.attrs) === null || _c === void 0 ? void 0 : _c.hash) || '',
366
+ imgUrl: setPicture ? 'changed' : 'removed'
367
+ }
368
+ ]);
369
+ if ((0, WABinary_1.isJidGroup)(from)) {
370
+ const node = setPicture || delPicture;
371
+ result.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_ICON;
372
+ if (setPicture) {
373
+ result.messageStubParameters = [setPicture.attrs.id];
374
+ }
375
+ result.participant = node === null || node === void 0 ? void 0 : node.attrs.author;
376
+ result.key = {
377
+ ...(result.key || {}),
378
+ participant: setPicture === null || setPicture === void 0 ? void 0 : setPicture.attrs.author
379
+ };
380
+ }
381
+ break;
382
+ case 'account_sync':
383
+ if (child.tag === 'disappearing_mode') {
384
+ const newDuration = +child.attrs.duration;
385
+ const timestamp = +child.attrs.t;
386
+ logger.info({ newDuration }, 'updated account disappearing mode');
387
+ ev.emit('creds.update', {
388
+ accountSettings: {
389
+ ...authState.creds.accountSettings,
390
+ defaultDisappearingMode: {
391
+ ephemeralExpiration: newDuration,
392
+ ephemeralSettingTimestamp: timestamp
393
+ }
394
+ }
395
+ });
396
+ }
397
+ else if (child.tag === 'blocklist') {
398
+ const blocklists = (0, WABinary_1.getBinaryNodeChildren)(child, 'item');
399
+ for (const { attrs } of blocklists) {
400
+ const blocklist = [attrs.jid];
401
+ const type = attrs.action === 'block' ? 'add' : 'remove';
402
+ ev.emit('blocklist.update', { blocklist, type });
403
+ }
404
+ }
405
+ break;
406
+ case 'link_code_companion_reg':
407
+ const linkCodeCompanionReg = (0, WABinary_1.getBinaryNodeChild)(node, 'link_code_companion_reg');
408
+ const ref = toRequiredBuffer((0, WABinary_1.getBinaryNodeChildBuffer)(linkCodeCompanionReg, 'link_code_pairing_ref'));
409
+ const primaryIdentityPublicKey = toRequiredBuffer((0, WABinary_1.getBinaryNodeChildBuffer)(linkCodeCompanionReg, 'primary_identity_pub'));
410
+ const primaryEphemeralPublicKeyWrapped = toRequiredBuffer((0, WABinary_1.getBinaryNodeChildBuffer)(linkCodeCompanionReg, 'link_code_pairing_wrapped_primary_ephemeral_pub'));
411
+ const codePairingPublicKey = await decipherLinkPublicKey(primaryEphemeralPublicKeyWrapped);
412
+ const companionSharedKey = Utils_1.Curve.sharedKey(authState.creds.pairingEphemeralKeyPair.private, codePairingPublicKey);
413
+ const random = (0, crypto_1.randomBytes)(32);
414
+ const linkCodeSalt = (0, crypto_1.randomBytes)(32);
415
+ const linkCodePairingExpanded = await (0, Utils_1.hkdf)(companionSharedKey, 32, {
416
+ salt: linkCodeSalt,
417
+ info: 'link_code_pairing_key_bundle_encryption_key'
418
+ });
419
+ const encryptPayload = Buffer.concat([
420
+ Buffer.from(authState.creds.signedIdentityKey.public),
421
+ primaryIdentityPublicKey,
422
+ random
423
+ ]);
424
+ const encryptIv = (0, crypto_1.randomBytes)(12);
425
+ const encrypted = (0, Utils_1.aesEncryptGCM)(encryptPayload, linkCodePairingExpanded, encryptIv, Buffer.alloc(0));
426
+ const encryptedPayload = Buffer.concat([linkCodeSalt, encryptIv, encrypted]);
427
+ const identitySharedKey = Utils_1.Curve.sharedKey(authState.creds.signedIdentityKey.private, primaryIdentityPublicKey);
428
+ const identityPayload = Buffer.concat([companionSharedKey, identitySharedKey, random]);
429
+ authState.creds.advSecretKey = (await (0, Utils_1.hkdf)(identityPayload, 32, { info: 'adv_secret' })).toString('base64');
430
+ await query({
431
+ tag: 'iq',
432
+ attrs: {
433
+ to: WABinary_1.S_WHATSAPP_NET,
434
+ type: 'set',
435
+ id: sock.generateMessageTag(),
436
+ xmlns: 'md'
437
+ },
438
+ content: [
439
+ {
440
+ tag: 'link_code_companion_reg',
441
+ attrs: {
442
+ jid: authState.creds.me.id,
443
+ stage: 'companion_finish'
444
+ },
445
+ content: [
446
+ {
447
+ tag: 'link_code_pairing_wrapped_key_bundle',
448
+ attrs: {},
449
+ content: encryptedPayload
450
+ },
451
+ {
452
+ tag: 'companion_identity_public',
453
+ attrs: {},
454
+ content: authState.creds.signedIdentityKey.public
455
+ },
456
+ {
457
+ tag: 'link_code_pairing_ref',
458
+ attrs: {},
459
+ content: ref
460
+ }
461
+ ]
462
+ }
463
+ ]
464
+ });
465
+ authState.creds.registered = true;
466
+ ev.emit('creds.update', authState.creds);
467
+ }
468
+ if (Object.keys(result).length) {
469
+ return result;
470
+ }
471
+ };
472
+ async function decipherLinkPublicKey(data) {
473
+ const buffer = toRequiredBuffer(data);
474
+ const salt = buffer.slice(0, 32);
475
+ const secretKey = await (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
476
+ const iv = buffer.slice(32, 48);
477
+ const payload = buffer.slice(48, 80);
478
+ return (0, Utils_1.aesDecryptCTR)(payload, secretKey, iv);
479
+ }
480
+ function toRequiredBuffer(data) {
481
+ if (data === undefined) {
482
+ throw new boom_1.Boom('Invalid buffer', { statusCode: 400 });
483
+ }
484
+ return data instanceof Buffer ? data : Buffer.from(data);
485
+ }
486
+ const willSendMessageAgain = (id, participant) => {
487
+ const key = `${id}:${participant}`;
488
+ const retryCount = msgRetryCache.get(key) || 0;
489
+ return retryCount < maxMsgRetryCount;
490
+ };
491
+ const updateSendMessageAgainCount = (id, participant) => {
492
+ const key = `${id}:${participant}`;
493
+ const newValue = (msgRetryCache.get(key) || 0) + 1;
494
+ msgRetryCache.set(key, newValue);
495
+ };
496
+ const sendMessagesAgain = async (key, ids, retryNode) => {
497
+ var _a;
498
+ // todo: implement a cache to store the last 256 sent messages (copy whatsmeow)
499
+ const msgs = await Promise.all(ids.map(id => getMessage({ ...key, id })));
500
+ const remoteJid = key.remoteJid;
501
+ const participant = key.participant || remoteJid;
502
+ // if it's the primary jid sending the request
503
+ // just re-send the message to everyone
504
+ // prevents the first message decryption failure
505
+ const sendToAll = !((_a = (0, WABinary_1.jidDecode)(participant)) === null || _a === void 0 ? void 0 : _a.device);
506
+ await assertSessions([participant], true);
507
+ if ((0, WABinary_1.isJidGroup)(remoteJid)) {
508
+ await authState.keys.set({ 'sender-key-memory': { [remoteJid]: null } });
509
+ }
510
+ logger.debug({ participant, sendToAll }, 'forced new session for retry recp');
511
+ for (const [i, msg] of msgs.entries()) {
512
+ if (msg) {
513
+ updateSendMessageAgainCount(ids[i], participant);
514
+ const msgRelayOpts = { messageId: ids[i] };
515
+ if (sendToAll) {
516
+ msgRelayOpts.useUserDevicesCache = false;
517
+ }
518
+ else {
519
+ msgRelayOpts.participant = {
520
+ jid: participant,
521
+ count: +retryNode.attrs.count
522
+ };
523
+ }
524
+ await relayMessage(key.remoteJid, msg, msgRelayOpts);
525
+ }
526
+ else {
527
+ logger.debug({ jid: key.remoteJid, id: ids[i] }, 'recv retry request, but message not available');
528
+ }
529
+ }
530
+ };
531
+ const handleReceipt = async (node) => {
532
+ var _a, _b;
533
+ const { attrs, content } = node;
534
+ const isLid = attrs.from.includes('lid');
535
+ const isNodeFromMe = (0, WABinary_1.areJidsSameUser)(attrs.participant || attrs.from, isLid ? (_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.lid : (_b = authState.creds.me) === null || _b === void 0 ? void 0 : _b.id);
536
+ const remoteJid = !isNodeFromMe || (0, WABinary_1.isJidGroup)(attrs.from) ? attrs.from : attrs.recipient;
537
+ const fromMe = !attrs.recipient || ((attrs.type === 'retry' || attrs.type === 'sender') && isNodeFromMe);
538
+ const key = {
539
+ remoteJid,
540
+ id: '',
541
+ fromMe,
542
+ participant: attrs.participant
543
+ };
544
+ if (shouldIgnoreJid(remoteJid) && remoteJid !== '@s.whatsapp.net') {
545
+ logger.debug({ remoteJid }, 'ignoring receipt from jid');
546
+ await sendMessageAck(node);
547
+ return;
548
+ }
549
+ const ids = [attrs.id];
550
+ if (Array.isArray(content)) {
551
+ const items = (0, WABinary_1.getBinaryNodeChildren)(content[0], 'item');
552
+ ids.push(...items.map(i => i.attrs.id));
553
+ }
554
+ try {
555
+ await Promise.all([
556
+ processingMutex.mutex(async () => {
557
+ var _a, _b, _c;
558
+ const status = (0, Utils_1.getStatusFromReceiptType)(attrs.type);
559
+ if (typeof status !== 'undefined' &&
560
+ // basically, we only want to know when a message from us has been delivered to/read by the other person
561
+ // or another device of ours has read some messages
562
+ (status >= WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK || !isNodeFromMe)) {
563
+ if ((0, WABinary_1.isJidGroup)(remoteJid) || (0, WABinary_1.isJidStatusBroadcast)(remoteJid)) {
564
+ const updateKey = status === WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK ? 'receiptTimestamp' : 'readTimestamp';
565
+ if (attrs.participant) {
566
+ ev.emit('message-receipt.update', ids.map(id => ({
567
+ key: { ...key, id },
568
+ receipt: {
569
+ userJid: (0, WABinary_1.jidNormalizedUser)(attrs.participant),
570
+ [updateKey]: +attrs.t
571
+ }
572
+ })));
573
+ }
574
+ if (Array.isArray(content)) {
575
+ const group_receipt = (_a = content[0]) === null || _a === void 0 ? void 0 : _a.content;
576
+ const id = (_c = (_b = content[0]) === null || _b === void 0 ? void 0 : _b.attrs) === null || _c === void 0 ? void 0 : _c.key;
577
+ if (id && group_receipt && Array.isArray(group_receipt)) {
578
+ ev.emit('message-receipt.update', group_receipt.map(item => ({
579
+ key: { ...key, id },
580
+ receipt: {
581
+ userJid: (0, WABinary_1.jidNormalizedUser)(item.attrs.jid),
582
+ [updateKey]: +item.attrs.t
583
+ }
584
+ })));
585
+ }
586
+ }
587
+ }
588
+ else {
589
+ ev.emit('messages.update', ids.map(id => ({
590
+ key: { ...key, id },
591
+ update: { status }
592
+ })));
593
+ }
594
+ if (attrs.type === 'read' && isNodeFromMe) {
595
+ ev.emit('messages.read', ids.map(id => ({
596
+ key: { ...key, id }
597
+ })));
598
+ }
599
+ }
600
+ if (attrs.type === 'retry') {
601
+ // correctly set who is asking for the retry
602
+ key.participant = key.participant || attrs.from;
603
+ const retryNode = (0, WABinary_1.getBinaryNodeChild)(node, 'retry');
604
+ if (willSendMessageAgain(ids[0], key.participant)) {
605
+ if (key.fromMe) {
606
+ try {
607
+ logger.debug({ attrs, key }, 'recv retry request');
608
+ await sendMessagesAgain(key, ids, retryNode);
609
+ }
610
+ catch (error) {
611
+ logger.error({ key, ids, trace: error.stack }, 'error in sending message again');
612
+ }
613
+ }
614
+ else {
615
+ logger.info({ attrs, key }, 'recv retry for not fromMe message');
616
+ }
617
+ }
618
+ else {
619
+ logger.info({ attrs, key }, 'will not send message again, as sent too many times');
620
+ }
621
+ }
622
+ })
623
+ ]);
624
+ }
625
+ finally {
626
+ await sendMessageAck(node);
627
+ }
628
+ };
629
+ const handleNotification = async (node) => {
630
+ const remoteJid = node.attrs.from;
631
+ if (shouldIgnoreJid(remoteJid) && remoteJid !== '@s.whatsapp.net') {
632
+ logger.debug({ remoteJid, id: node.attrs.id }, 'ignored notification');
633
+ await sendMessageAck(node);
634
+ return;
635
+ }
636
+ try {
637
+ await Promise.all([
638
+ processingMutex.mutex(async () => {
639
+ var _a;
640
+ const msg = await processNotification(node);
641
+ if (msg) {
642
+ const fromMe = (0, WABinary_1.areJidsSameUser)(node.attrs.participant || remoteJid, authState.creds.me.id);
643
+ msg.key = {
644
+ remoteJid,
645
+ fromMe,
646
+ participant: node.attrs.participant,
647
+ id: node.attrs.id,
648
+ ...(msg.key || {})
649
+ };
650
+ (_a = msg.participant) !== null && _a !== void 0 ? _a : (msg.participant = node.attrs.participant);
651
+ msg.messageTimestamp = +node.attrs.t;
652
+ const fullMsg = WAProto_1.proto.WebMessageInfo.fromObject(msg);
653
+ await upsertMessage(fullMsg, 'append');
654
+ }
655
+ })
656
+ ]);
657
+ }
658
+ finally {
659
+ await sendMessageAck(node);
660
+ }
661
+ };
662
+ const handleMessage = async (node) => {
663
+ var _a, _b, _c;
664
+ if (shouldIgnoreJid(node.attrs.from) && node.attrs.from !== '@s.whatsapp.net') {
665
+ logger.debug({ key: node.attrs.key }, 'ignored message');
666
+ await sendMessageAck(node);
667
+ return;
668
+ }
669
+ const encNode = (0, WABinary_1.getBinaryNodeChild)(node, 'enc');
670
+ // TODO: temporary fix for crashes and issues resulting of failed msmsg decryption
671
+ if (encNode && encNode.attrs.type === 'msmsg') {
672
+ logger.debug({ key: node.attrs.key }, 'ignored msmsg');
673
+ await sendMessageAck(node);
674
+ return;
675
+ }
676
+ let response;
677
+ if ((0, WABinary_1.getBinaryNodeChild)(node, 'unavailable') && !encNode) {
678
+ await sendMessageAck(node);
679
+ const { key } = (0, Utils_1.decodeMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '').fullMessage;
680
+ response = await requestPlaceholderResend(key);
681
+ if (response === 'RESOLVED') {
682
+ return;
683
+ }
684
+ logger.debug('received unavailable message, acked and requested resend from phone');
685
+ }
686
+ else {
687
+ if (placeholderResendCache.get(node.attrs.id)) {
688
+ placeholderResendCache.del(node.attrs.id);
689
+ }
690
+ }
691
+ const { fullMessage: msg, category, author, decrypt } = (0, Utils_1.decryptMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, logger);
692
+ if (response && ((_a = msg === null || msg === void 0 ? void 0 : msg.messageStubParameters) === null || _a === void 0 ? void 0 : _a[0]) === Utils_1.NO_MESSAGE_FOUND_ERROR_TEXT) {
693
+ msg.messageStubParameters = [Utils_1.NO_MESSAGE_FOUND_ERROR_TEXT, response];
694
+ }
695
+ if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.type) === WAProto_1.proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER &&
696
+ node.attrs.sender_pn) {
697
+ ev.emit('chats.phoneNumberShare', { lid: node.attrs.from, jid: node.attrs.sender_pn });
698
+ }
699
+ try {
700
+ await Promise.all([
701
+ processingMutex.mutex(async () => {
702
+ var _a;
703
+ await decrypt();
704
+ // message failed to decrypt
705
+ if (msg.messageStubType === WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT) {
706
+ if (((_a = msg === null || msg === void 0 ? void 0 : msg.messageStubParameters) === null || _a === void 0 ? void 0 : _a[0]) === Utils_1.MISSING_KEYS_ERROR_TEXT) {
707
+ return sendMessageAck(node, Utils_1.NACK_REASONS.ParsingError);
708
+ }
709
+ retryMutex.mutex(async () => {
710
+ if (ws.isOpen) {
711
+ if ((0, WABinary_1.getBinaryNodeChild)(node, 'unavailable')) {
712
+ return;
713
+ }
714
+ const encNode = (0, WABinary_1.getBinaryNodeChild)(node, 'enc');
715
+ await sendRetryRequest(node, !encNode);
716
+ if (retryRequestDelayMs) {
717
+ await (0, Utils_1.delay)(retryRequestDelayMs);
718
+ }
719
+ }
720
+ else {
721
+ logger.debug({ node }, 'connection closed, ignoring retry req');
722
+ }
723
+ });
724
+ }
725
+ else {
726
+ // no type in the receipt => message delivered
727
+ let type = undefined;
728
+ let participant = msg.key.participant;
729
+ if (category === 'peer') {
730
+ // special peer message
731
+ type = 'peer_msg';
732
+ }
733
+ else if (msg.key.fromMe) {
734
+ // message was sent by us from a different device
735
+ type = 'sender';
736
+ // need to specially handle this case
737
+ if ((0, WABinary_1.isJidUser)(msg.key.remoteJid)) {
738
+ participant = author;
739
+ }
740
+ }
741
+ else if (!sendActiveReceipts) {
742
+ type = 'inactive';
743
+ }
744
+ await sendReceipt(msg.key.remoteJid, participant, [msg.key.id], type);
745
+ // send ack for history message
746
+ const isAnyHistoryMsg = (0, Utils_1.getHistoryMsg)(msg.message);
747
+ if (isAnyHistoryMsg) {
748
+ const jid = (0, WABinary_1.jidNormalizedUser)(msg.key.remoteJid);
749
+ await sendReceipt(jid, undefined, [msg.key.id], 'hist_sync');
750
+ }
751
+ }
752
+ (0, Utils_1.cleanMessage)(msg, authState.creds.me.id);
753
+ await sendMessageAck(node);
754
+ await upsertMessage(msg, node.attrs.offline ? 'append' : 'notify');
755
+ })
756
+ ]);
757
+ }
758
+ catch (error) {
759
+ logger.error({ error, node }, 'error in handling message');
760
+ }
761
+ };
762
+ const fetchMessageHistory = async (count, oldestMsgKey, oldestMsgTimestamp) => {
763
+ var _a;
764
+ if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
765
+ throw new boom_1.Boom('Not authenticated');
766
+ }
767
+ const pdoMessage = {
768
+ historySyncOnDemandRequest: {
769
+ chatJid: oldestMsgKey.remoteJid,
770
+ oldestMsgFromMe: oldestMsgKey.fromMe,
771
+ oldestMsgId: oldestMsgKey.id,
772
+ oldestMsgTimestampMs: oldestMsgTimestamp,
773
+ onDemandMsgCount: count
774
+ },
775
+ peerDataOperationRequestType: WAProto_1.proto.Message.PeerDataOperationRequestType.HISTORY_SYNC_ON_DEMAND
776
+ };
777
+ return sendPeerDataOperationMessage(pdoMessage);
778
+ };
779
+ const requestPlaceholderResend = async (messageKey) => {
780
+ var _a;
781
+ if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
782
+ throw new boom_1.Boom('Not authenticated');
783
+ }
784
+ if (placeholderResendCache.get(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id)) {
785
+ logger.debug({ messageKey }, 'already requested resend');
786
+ return;
787
+ }
788
+ else {
789
+ placeholderResendCache.set(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id, true);
790
+ }
791
+ await (0, Utils_1.delay)(5000);
792
+ if (!placeholderResendCache.get(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id)) {
793
+ logger.debug({ messageKey }, 'message received while resend requested');
794
+ return 'RESOLVED';
795
+ }
796
+ const pdoMessage = {
797
+ placeholderMessageResendRequest: [
798
+ {
799
+ messageKey
800
+ }
801
+ ],
802
+ peerDataOperationRequestType: WAProto_1.proto.Message.PeerDataOperationRequestType.PLACEHOLDER_MESSAGE_RESEND
803
+ };
804
+ setTimeout(() => {
805
+ if (placeholderResendCache.get(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id)) {
806
+ logger.debug({ messageKey }, 'PDO message without response after 15 seconds. Phone possibly offline');
807
+ placeholderResendCache.del(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id);
808
+ }
809
+ }, 15000);
810
+ return sendPeerDataOperationMessage(pdoMessage);
811
+ };
812
+ const handleCall = async (node) => {
813
+ const { attrs } = node;
814
+ const [infoChild] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
815
+ const callId = infoChild.attrs['call-id'];
816
+ const from = infoChild.attrs.from || infoChild.attrs['call-creator'];
817
+ const status = (0, Utils_1.getCallStatusFromNode)(infoChild);
818
+ const call = {
819
+ chatId: attrs.from,
820
+ from,
821
+ id: callId,
822
+ date: new Date(+attrs.t * 1000),
823
+ offline: !!attrs.offline,
824
+ status
825
+ };
826
+ if (status === 'offer') {
827
+ call.isVideo = !!(0, WABinary_1.getBinaryNodeChild)(infoChild, 'video');
828
+ call.isGroup = infoChild.attrs.type === 'group' || !!infoChild.attrs['group-jid'];
829
+ call.groupJid = infoChild.attrs['group-jid'];
830
+ callOfferCache.set(call.id, call);
831
+ }
832
+ const existingCall = callOfferCache.get(call.id);
833
+ // use existing call info to populate this event
834
+ if (existingCall) {
835
+ call.isVideo = existingCall.isVideo;
836
+ call.isGroup = existingCall.isGroup;
837
+ }
838
+ // delete data once call has ended
839
+ if (status === 'reject' || status === 'accept' || status === 'timeout' || status === 'terminate') {
840
+ callOfferCache.del(call.id);
841
+ }
842
+ ev.emit('call', [call]);
843
+ await sendMessageAck(node);
844
+ };
845
+ const handleBadAck = async ({ attrs }) => {
846
+ const key = { remoteJid: attrs.from, fromMe: true, id: attrs.id };
847
+ // WARNING: REFRAIN FROM ENABLING THIS FOR NOW. IT WILL CAUSE A LOOP
848
+ // // current hypothesis is that if pash is sent in the ack
849
+ // // it means -- the message hasn't reached all devices yet
850
+ // // we'll retry sending the message here
851
+ // if(attrs.phash) {
852
+ // logger.info({ attrs }, 'received phash in ack, resending message...')
853
+ // const msg = await getMessage(key)
854
+ // if(msg) {
855
+ // await relayMessage(key.remoteJid!, msg, { messageId: key.id!, useUserDevicesCache: false })
856
+ // } else {
857
+ // logger.warn({ attrs }, 'could not send message again, as it was not found')
858
+ // }
859
+ // }
860
+ // error in acknowledgement,
861
+ // device could not display the message
862
+ if (attrs.error) {
863
+ logger.warn({ attrs }, 'received error in ack');
864
+ ev.emit('messages.update', [
865
+ {
866
+ key,
867
+ update: {
868
+ status: Types_1.WAMessageStatus.ERROR,
869
+ messageStubParameters: [attrs.error]
870
+ }
871
+ }
872
+ ]);
873
+ }
874
+ };
875
+ /// processes a node with the given function
876
+ /// and adds the task to the existing buffer if we're buffering events
877
+ const processNodeWithBuffer = async (node, identifier, exec) => {
878
+ ev.buffer();
879
+ await execTask();
880
+ ev.flush();
881
+ function execTask() {
882
+ return exec(node, false).catch(err => onUnexpectedError(err, identifier));
883
+ }
884
+ };
885
+ const makeOfflineNodeProcessor = () => {
886
+ const nodeProcessorMap = new Map([
887
+ ['message', handleMessage],
888
+ ['call', handleCall],
889
+ ['receipt', handleReceipt],
890
+ ['notification', handleNotification]
891
+ ]);
892
+ const nodes = [];
893
+ let isProcessing = false;
894
+ const enqueue = (type, node) => {
895
+ nodes.push({ type, node });
896
+ if (isProcessing) {
897
+ return;
898
+ }
899
+ isProcessing = true;
900
+ const promise = async () => {
901
+ while (nodes.length && ws.isOpen) {
902
+ const { type, node } = nodes.shift();
903
+ const nodeProcessor = nodeProcessorMap.get(type);
904
+ if (!nodeProcessor) {
905
+ onUnexpectedError(new Error(`unknown offline node type: ${type}`), 'processing offline node');
906
+ continue;
907
+ }
908
+ await nodeProcessor(node);
909
+ }
910
+ isProcessing = false;
911
+ };
912
+ promise().catch(error => onUnexpectedError(error, 'processing offline nodes'));
913
+ };
914
+ return { enqueue };
915
+ };
916
+ const offlineNodeProcessor = makeOfflineNodeProcessor();
917
+ const processNode = (type, node, identifier, exec) => {
918
+ const isOffline = !!node.attrs.offline;
919
+ if (isOffline) {
920
+ offlineNodeProcessor.enqueue(type, node);
921
+ }
922
+ else {
923
+ processNodeWithBuffer(node, identifier, exec);
924
+ }
925
+ };
926
+ // Handles newsletter notifications
927
+ async function handleNewsletterNotification(node) {
928
+ var _a;
929
+ const from = node.attrs.from;
930
+ const [child] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
931
+ const author = node.attrs.participant;
932
+ logger.info({ from, child }, 'got newsletter notification');
933
+ switch (child.tag) {
934
+ case 'reaction':
935
+ const reactionUpdate = {
936
+ id: from,
937
+ server_id: child.attrs.message_id,
938
+ reaction: {
939
+ code: (0, WABinary_1.getBinaryNodeChildString)(child, 'reaction'),
940
+ count: 1
941
+ }
942
+ };
943
+ ev.emit('newsletter.reaction', reactionUpdate);
944
+ break;
945
+ case 'view':
946
+ const viewUpdate = {
947
+ id: from,
948
+ server_id: child.attrs.message_id,
949
+ count: parseInt(((_a = child.content) === null || _a === void 0 ? void 0 : _a.toString()) || '0', 10)
950
+ };
951
+ ev.emit('newsletter.view', viewUpdate);
952
+ break;
953
+ case 'participant':
954
+ const participantUpdate = {
955
+ id: from,
956
+ author,
957
+ user: child.attrs.jid,
958
+ action: child.attrs.action,
959
+ new_role: child.attrs.role
960
+ };
961
+ ev.emit('newsletter-participants.update', participantUpdate);
962
+ break;
963
+ case 'update':
964
+ const settingsNode = (0, WABinary_1.getBinaryNodeChild)(child, 'settings');
965
+ if (settingsNode) {
966
+ const update = {};
967
+ const nameNode = (0, WABinary_1.getBinaryNodeChild)(settingsNode, 'name');
968
+ if (nameNode === null || nameNode === void 0 ? void 0 : nameNode.content)
969
+ update.name = nameNode.content.toString();
970
+ const descriptionNode = (0, WABinary_1.getBinaryNodeChild)(settingsNode, 'description');
971
+ if (descriptionNode === null || descriptionNode === void 0 ? void 0 : descriptionNode.content)
972
+ update.description = descriptionNode.content.toString();
973
+ ev.emit('newsletter-settings.update', {
974
+ id: from,
975
+ update
976
+ });
977
+ }
978
+ break;
979
+ case 'message':
980
+ const plaintextNode = (0, WABinary_1.getBinaryNodeChild)(child, 'plaintext');
981
+ if (plaintextNode === null || plaintextNode === void 0 ? void 0 : plaintextNode.content) {
982
+ try {
983
+ const contentBuf = typeof plaintextNode.content === 'string'
984
+ ? Buffer.from(plaintextNode.content, 'binary')
985
+ : Buffer.from(plaintextNode.content);
986
+ const messageProto = WAProto_1.proto.Message.decode(contentBuf);
987
+ const fullMessage = WAProto_1.proto.WebMessageInfo.fromObject({
988
+ key: {
989
+ remoteJid: from,
990
+ id: child.attrs.message_id || child.attrs.server_id,
991
+ fromMe: false
992
+ },
993
+ message: messageProto,
994
+ messageTimestamp: +child.attrs.t
995
+ });
996
+ await upsertMessage(fullMessage, 'append');
997
+ logger.info('Processed plaintext newsletter message');
998
+ }
999
+ catch (error) {
1000
+ logger.error({ error }, 'Failed to decode plaintext newsletter message');
1001
+ }
1002
+ }
1003
+ break;
1004
+ default:
1005
+ logger.warn({ node }, 'Unknown newsletter notification');
1006
+ break;
1007
+ }
1008
+ }
1009
+ // Handles mex newsletter notifications
1010
+ async function handleMexNewsletterNotification(node) {
1011
+ const mexNode = (0, WABinary_1.getBinaryNodeChild)(node, 'mex');
1012
+ if (!(mexNode === null || mexNode === void 0 ? void 0 : mexNode.content)) {
1013
+ logger.warn({ node }, 'Invalid mex newsletter notification');
1014
+ return;
1015
+ }
1016
+ let data;
1017
+ try {
1018
+ data = JSON.parse(mexNode.content.toString());
1019
+ }
1020
+ catch (error) {
1021
+ logger.error({ err: error, node }, 'Failed to parse mex newsletter notification');
1022
+ return;
1023
+ }
1024
+ const operation = data === null || data === void 0 ? void 0 : data.operation;
1025
+ const updates = data === null || data === void 0 ? void 0 : data.updates;
1026
+ if (!updates || !operation) {
1027
+ logger.warn({ data }, 'Invalid mex newsletter notification content');
1028
+ return;
1029
+ }
1030
+ logger.info({ operation, updates }, 'got mex newsletter notification');
1031
+ switch (operation) {
1032
+ case 'NotificationNewsletterUpdate':
1033
+ for (const update of updates) {
1034
+ if (update.jid && update.settings && Object.keys(update.settings).length > 0) {
1035
+ ev.emit('newsletter-settings.update', {
1036
+ id: update.jid,
1037
+ update: update.settings
1038
+ });
1039
+ }
1040
+ }
1041
+ break;
1042
+ case 'NotificationNewsletterAdminPromote':
1043
+ for (const update of updates) {
1044
+ if (update.jid && update.user) {
1045
+ ev.emit('newsletter-participants.update', {
1046
+ id: update.jid,
1047
+ author: node.attrs.from,
1048
+ user: update.user,
1049
+ new_role: 'ADMIN',
1050
+ action: 'promote'
1051
+ });
1052
+ }
1053
+ }
1054
+ break;
1055
+ default:
1056
+ logger.info({ operation, data }, 'Unhandled mex newsletter notification');
1057
+ break;
1058
+ }
1059
+ }
1060
+ // recv a message
1061
+ ws.on('CB:message', (node) => {
1062
+ processNode('message', node, 'processing message', handleMessage);
1063
+ });
1064
+ ws.on('CB:call', async (node) => {
1065
+ processNode('call', node, 'handling call', handleCall);
1066
+ });
1067
+ ws.on('CB:receipt', node => {
1068
+ processNode('receipt', node, 'handling receipt', handleReceipt);
1069
+ });
1070
+ ws.on('CB:notification', async (node) => {
1071
+ processNode('notification', node, 'handling notification', handleNotification);
1072
+ });
1073
+ ws.on('CB:ack,class:message', (node) => {
1074
+ handleBadAck(node).catch(error => onUnexpectedError(error, 'handling bad ack'));
1075
+ });
1076
+ ev.on('call', ([call]) => {
1077
+ // missed call + group call notification message generation
1078
+ if (call.status === 'timeout' || (call.status === 'offer' && call.isGroup)) {
1079
+ const msg = {
1080
+ key: {
1081
+ remoteJid: call.chatId,
1082
+ id: call.id,
1083
+ fromMe: false
1084
+ },
1085
+ messageTimestamp: (0, Utils_1.unixTimestampSeconds)(call.date)
1086
+ };
1087
+ if (call.status === 'timeout') {
1088
+ if (call.isGroup) {
1089
+ msg.messageStubType = call.isVideo
1090
+ ? Types_1.WAMessageStubType.CALL_MISSED_GROUP_VIDEO
1091
+ : Types_1.WAMessageStubType.CALL_MISSED_GROUP_VOICE;
1092
+ }
1093
+ else {
1094
+ msg.messageStubType = call.isVideo ? Types_1.WAMessageStubType.CALL_MISSED_VIDEO : Types_1.WAMessageStubType.CALL_MISSED_VOICE;
1095
+ }
1096
+ }
1097
+ else {
1098
+ msg.message = { call: { callKey: Buffer.from(call.id) } };
1099
+ }
1100
+ const protoMsg = WAProto_1.proto.WebMessageInfo.fromObject(msg);
1101
+ upsertMessage(protoMsg, call.offline ? 'append' : 'notify');
1102
+ }
1103
+ });
1104
+ ev.on('connection.update', ({ isOnline }) => {
1105
+ if (typeof isOnline !== 'undefined') {
1106
+ sendActiveReceipts = isOnline;
1107
+ logger.trace(`sendActiveReceipts set to "${sendActiveReceipts}"`);
1108
+ }
1109
+ });
1110
+ return {
1111
+ ...sock,
1112
+ sendMessageAck,
1113
+ sendRetryRequest,
1114
+ rejectCall,
1115
+ fetchMessageHistory,
1116
+ requestPlaceholderResend
1117
+ };
1118
+ };
1119
+ exports.makeMessagesRecvSocket = makeMessagesRecvSocket;