@queenanya/baileys 7.3.7 → 7.4.1

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 (390) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +931 -0
  3. package/WAProto/GenerateStatics.sh +4 -0
  4. package/WAProto/WAProto.proto +3344 -0
  5. package/WAProto/index.d.ts +37016 -0
  6. package/WAProto/index.js +101044 -0
  7. package/WASignalGroup/GroupProtocol.js +1697 -0
  8. package/WASignalGroup/ciphertext_message.js +16 -0
  9. package/WASignalGroup/group_cipher.js +120 -0
  10. package/WASignalGroup/group_session_builder.js +46 -0
  11. package/WASignalGroup/index.js +5 -0
  12. package/WASignalGroup/keyhelper.js +21 -0
  13. package/WASignalGroup/protobufs.js +3 -0
  14. package/WASignalGroup/queue_job.js +69 -0
  15. package/WASignalGroup/sender_chain_key.js +50 -0
  16. package/WASignalGroup/sender_key_distribution_message.js +78 -0
  17. package/WASignalGroup/sender_key_message.js +92 -0
  18. package/WASignalGroup/sender_key_name.js +70 -0
  19. package/WASignalGroup/sender_key_record.js +56 -0
  20. package/WASignalGroup/sender_key_state.js +129 -0
  21. package/WASignalGroup/sender_message_key.js +39 -0
  22. package/lib/Defaults/baileys-version.json +3 -0
  23. package/lib/Defaults/index.d.ts +53 -0
  24. package/lib/Defaults/index.js +106 -0
  25. package/lib/Signal/libsignal.d.ts +3 -0
  26. package/lib/Signal/libsignal.js +152 -0
  27. package/lib/Socket/Client/index.d.ts +2 -0
  28. package/lib/Socket/Client/index.js +18 -0
  29. package/lib/Socket/Client/types.d.ts +17 -0
  30. package/lib/Socket/Client/types.js +13 -0
  31. package/lib/Socket/Client/websocket.d.ts +12 -0
  32. package/lib/Socket/Client/websocket.js +62 -0
  33. package/lib/Socket/business.d.ts +177 -0
  34. package/lib/Socket/business.js +260 -0
  35. package/lib/Socket/chats.d.ts +91 -0
  36. package/lib/Socket/chats.js +949 -0
  37. package/lib/Socket/groups.d.ts +131 -0
  38. package/lib/Socket/groups.js +314 -0
  39. package/lib/Socket/index.d.ts +177 -0
  40. package/lib/Socket/index.js +10 -0
  41. package/lib/Socket/messages-recv.d.ts +164 -0
  42. package/lib/Socket/messages-recv.js +918 -0
  43. package/lib/Socket/messages-send.d.ts +157 -0
  44. package/lib/Socket/messages-send.js +794 -0
  45. package/lib/Socket/newsletter.d.ts +143 -0
  46. package/lib/Socket/newsletter.js +249 -0
  47. package/lib/Socket/socket.d.ts +45 -0
  48. package/lib/Socket/socket.js +615 -0
  49. package/lib/Store/index.d.ts +3 -0
  50. package/lib/Store/index.js +10 -0
  51. package/lib/Store/make-cache-manager-store.d.ts +14 -0
  52. package/lib/Store/make-cache-manager-store.js +83 -0
  53. package/lib/Store/make-in-memory-store.d.ts +118 -0
  54. package/lib/Store/make-in-memory-store.js +420 -0
  55. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  56. package/lib/Store/make-ordered-dictionary.js +81 -0
  57. package/lib/Store/object-repository.d.ts +10 -0
  58. package/lib/Store/object-repository.js +27 -0
  59. package/lib/Types/Auth.d.ts +105 -0
  60. package/lib/Types/Auth.js +2 -0
  61. package/lib/Types/Call.d.ts +13 -0
  62. package/lib/Types/Call.js +2 -0
  63. package/lib/Types/Chat.d.ts +107 -0
  64. package/lib/Types/Chat.js +4 -0
  65. package/lib/Types/Contact.d.ts +19 -0
  66. package/lib/Types/Contact.js +2 -0
  67. package/lib/Types/Events.d.ts +199 -0
  68. package/lib/Types/Events.js +2 -0
  69. package/lib/Types/GroupMetadata.d.ts +56 -0
  70. package/lib/Types/GroupMetadata.js +2 -0
  71. package/lib/Types/Label.d.ts +46 -0
  72. package/lib/Types/Label.js +27 -0
  73. package/lib/Types/LabelAssociation.d.ts +29 -0
  74. package/lib/Types/LabelAssociation.js +9 -0
  75. package/lib/Types/Message.d.ts +280 -0
  76. package/lib/Types/Message.js +9 -0
  77. package/lib/Types/Newsletter.d.ts +79 -0
  78. package/lib/Types/Newsletter.js +18 -0
  79. package/lib/Types/Product.d.ts +78 -0
  80. package/lib/Types/Product.js +2 -0
  81. package/lib/Types/Signal.d.ts +57 -0
  82. package/lib/Types/Signal.js +2 -0
  83. package/lib/Types/Socket.d.ts +118 -0
  84. package/lib/Types/Socket.js +2 -0
  85. package/lib/Types/State.d.ts +27 -0
  86. package/lib/Types/State.js +2 -0
  87. package/lib/Types/index.d.ts +65 -0
  88. package/lib/Types/index.js +42 -0
  89. package/lib/Utils/auth-utils.d.ts +18 -0
  90. package/lib/Utils/auth-utils.js +200 -0
  91. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  92. package/lib/Utils/baileys-event-stream.js +63 -0
  93. package/lib/Utils/business.d.ts +22 -0
  94. package/lib/Utils/business.js +234 -0
  95. package/lib/Utils/chat-utils.d.ts +72 -0
  96. package/lib/Utils/chat-utils.js +745 -0
  97. package/lib/Utils/crypto.d.ts +42 -0
  98. package/lib/Utils/crypto.js +153 -0
  99. package/lib/Utils/decode-wa-message.d.ts +20 -0
  100. package/lib/Utils/decode-wa-message.js +218 -0
  101. package/lib/Utils/event-buffer.d.ts +35 -0
  102. package/lib/Utils/event-buffer.js +520 -0
  103. package/lib/Utils/generics.d.ts +119 -0
  104. package/lib/Utils/generics.js +467 -0
  105. package/lib/Utils/history.d.ts +19 -0
  106. package/lib/Utils/history.js +94 -0
  107. package/lib/Utils/index.d.ts +17 -0
  108. package/lib/Utils/index.js +33 -0
  109. package/lib/Utils/link-preview.d.ts +21 -0
  110. package/lib/Utils/link-preview.js +116 -0
  111. package/lib/Utils/logger.d.ts +2 -0
  112. package/lib/Utils/logger.js +7 -0
  113. package/lib/Utils/lt-hash.d.ts +12 -0
  114. package/lib/Utils/lt-hash.js +51 -0
  115. package/lib/Utils/make-mutex.d.ts +7 -0
  116. package/lib/Utils/make-mutex.js +44 -0
  117. package/lib/Utils/messages-media.d.ts +131 -0
  118. package/lib/Utils/messages-media.js +786 -0
  119. package/lib/Utils/messages.d.ts +78 -0
  120. package/lib/Utils/messages.js +767 -0
  121. package/lib/Utils/noise-handler.d.ts +21 -0
  122. package/lib/Utils/noise-handler.js +150 -0
  123. package/lib/Utils/process-message.d.ts +42 -0
  124. package/lib/Utils/process-message.js +355 -0
  125. package/lib/Utils/signal.d.ts +32 -0
  126. package/lib/Utils/signal.js +158 -0
  127. package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
  128. package/lib/Utils/use-multi-file-auth-state.js +94 -0
  129. package/lib/Utils/validate-connection.d.ts +10 -0
  130. package/lib/Utils/validate-connection.js +171 -0
  131. package/lib/WABinary/constants.d.ts +27 -0
  132. package/lib/WABinary/constants.js +40 -0
  133. package/lib/WABinary/decode.d.ts +8 -0
  134. package/lib/WABinary/decode.js +254 -0
  135. package/lib/WABinary/encode.d.ts +2 -0
  136. package/lib/WABinary/encode.js +230 -0
  137. package/lib/WABinary/generic-utils.d.ts +16 -0
  138. package/lib/WABinary/generic-utils.js +110 -0
  139. package/lib/WABinary/index.d.ts +5 -0
  140. package/lib/WABinary/index.js +21 -0
  141. package/lib/WABinary/jid-utils.d.ts +31 -0
  142. package/lib/WABinary/jid-utils.js +62 -0
  143. package/lib/WABinary/types.d.ts +18 -0
  144. package/lib/WABinary/types.js +2 -0
  145. package/lib/WAM/BinaryInfo.d.ts +18 -0
  146. package/lib/WAM/BinaryInfo.js +13 -0
  147. package/lib/WAM/constants.d.ts +39 -0
  148. package/lib/WAM/constants.js +15350 -0
  149. package/lib/WAM/encode.d.ts +4 -0
  150. package/lib/WAM/encode.js +155 -0
  151. package/lib/WAM/index.d.ts +3 -0
  152. package/lib/WAM/index.js +19 -0
  153. package/lib/index.d.ts +11 -0
  154. package/lib/index.js +30 -0
  155. package/package.json +101 -2
  156. package/.anya-md/.replit +0 -2
  157. package/.anya-md/.temp/.temp +0 -1
  158. package/.anya-md/Dockerfile +0 -16
  159. package/.anya-md/LICENCE +0 -674
  160. package/.anya-md/README.md +0 -301
  161. package/.anya-md/app.json +0 -81
  162. package/.anya-md/config.js +0 -74
  163. package/.anya-md/heroku.yml +0 -5
  164. package/.anya-md/index.js +0 -47
  165. package/.anya-md/koyeb.yaml +0 -14
  166. package/.anya-md/lib/.dev.js +0 -47
  167. package/.anya-md/lib/Assets/aliveMedia.mp4 +0 -0
  168. package/.anya-md/lib/Assets/goodbyeBG.jpg +0 -0
  169. package/.anya-md/lib/Assets/image_1.jpg +0 -0
  170. package/.anya-md/lib/Assets/image_2.jpg +0 -0
  171. package/.anya-md/lib/Assets/menuMedia.mp4 +0 -0
  172. package/.anya-md/lib/Assets/ownerMentionMp3.mp3 +0 -0
  173. package/.anya-md/lib/Assets/port.html +0 -36
  174. package/.anya-md/lib/Assets/reaction/angry/angry108202410.jpeg +0 -0
  175. package/.anya-md/lib/Assets/reaction/angry/angry108202412.jpeg +0 -0
  176. package/.anya-md/lib/Assets/reaction/angry/angry108202413.jpeg +0 -0
  177. package/.anya-md/lib/Assets/reaction/angry/angry108202414.jpeg +0 -0
  178. package/.anya-md/lib/Assets/reaction/angry/angry108202415.jpeg +0 -0
  179. package/.anya-md/lib/Assets/reaction/angry/angry108202416.jpeg +0 -0
  180. package/.anya-md/lib/Assets/reaction/angry/angry108202417.jpeg +0 -0
  181. package/.anya-md/lib/Assets/reaction/angry/angry108202418.jpeg +0 -0
  182. package/.anya-md/lib/Assets/reaction/angry/angry108202419.jpeg +0 -0
  183. package/.anya-md/lib/Assets/reaction/angry/angry108202420.jpeg +0 -0
  184. package/.anya-md/lib/Assets/reaction/angry/angry108202421.jpeg +0 -0
  185. package/.anya-md/lib/Assets/reaction/angry/angry108202423.jpeg +0 -0
  186. package/.anya-md/lib/Assets/reaction/angry/angry108202425.jpeg +0 -0
  187. package/.anya-md/lib/Assets/reaction/angry/angry108202426.jpeg +0 -0
  188. package/.anya-md/lib/Assets/reaction/angry/angry108202427.jpeg +0 -0
  189. package/.anya-md/lib/Assets/reaction/angry/angry108202428.jpeg +0 -0
  190. package/.anya-md/lib/Assets/reaction/angry/angry108202429.jpeg +0 -0
  191. package/.anya-md/lib/Assets/reaction/angry/angry108202430.jpeg +0 -0
  192. package/.anya-md/lib/Assets/reaction/angry/angry108202431.jpeg +0 -0
  193. package/.anya-md/lib/Assets/reaction/angry/angry108202469.jpeg +0 -0
  194. package/.anya-md/lib/Assets/reaction/angry/angry10820249.jpeg +0 -0
  195. package/.anya-md/lib/Assets/reaction/angry/angry11.mp4 +0 -0
  196. package/.anya-md/lib/Assets/reaction/angry/angry12.mp4 +0 -0
  197. package/.anya-md/lib/Assets/reaction/angry/angry14.jpg +0 -0
  198. package/.anya-md/lib/Assets/reaction/angry/angry2.mp4 +0 -0
  199. package/.anya-md/lib/Assets/reaction/angry/angry3.mp4 +0 -0
  200. package/.anya-md/lib/Assets/reaction/angry/angry5.jpg +0 -0
  201. package/.anya-md/lib/Assets/reaction/angry/angry6.png +0 -0
  202. package/.anya-md/lib/Assets/reaction/angry/angry8.png +0 -0
  203. package/.anya-md/lib/Assets/reaction/angry/angry9.jpg +0 -0
  204. package/.anya-md/lib/Assets/reaction/confused/confused1.png +0 -0
  205. package/.anya-md/lib/Assets/reaction/confused/confused2.jpg +0 -0
  206. package/.anya-md/lib/Assets/reaction/confused/confused3.jpg +0 -0
  207. package/.anya-md/lib/Assets/reaction/confused/confused4.mp4 +0 -0
  208. package/.anya-md/lib/Assets/reaction/confused/confused5.jpg +0 -0
  209. package/.anya-md/lib/Assets/reaction/confused/confused6.webp +0 -0
  210. package/.anya-md/lib/Assets/reaction/confused/confused7.png +0 -0
  211. package/.anya-md/lib/Assets/reaction/confused/confused8.jpg +0 -0
  212. package/.anya-md/lib/Assets/reaction/cry/cry1.jpeg +0 -0
  213. package/.anya-md/lib/Assets/reaction/cry/cry12.jpeg +0 -0
  214. package/.anya-md/lib/Assets/reaction/cry/cry13.jpeg +0 -0
  215. package/.anya-md/lib/Assets/reaction/cry/cry14.jpeg +0 -0
  216. package/.anya-md/lib/Assets/reaction/cry/cry15.jpeg +0 -0
  217. package/.anya-md/lib/Assets/reaction/cry/cry16.jpeg +0 -0
  218. package/.anya-md/lib/Assets/reaction/cry/cry17.jpeg +0 -0
  219. package/.anya-md/lib/Assets/reaction/cry/cry18.jpeg +0 -0
  220. package/.anya-md/lib/Assets/reaction/cry/cry19.jpeg +0 -0
  221. package/.anya-md/lib/Assets/reaction/cry/cry22.jpeg +0 -0
  222. package/.anya-md/lib/Assets/reaction/cry/cry23.jpeg +0 -0
  223. package/.anya-md/lib/Assets/reaction/cry/cry5.jpeg +0 -0
  224. package/.anya-md/lib/Assets/reaction/cry/cry9.jpeg +0 -0
  225. package/.anya-md/lib/Assets/reaction/happy/happyrect1.jpeg +0 -0
  226. package/.anya-md/lib/Assets/reaction/no/_pika +0 -1
  227. package/.anya-md/lib/Assets/reaction/no/no1.jpg +0 -0
  228. package/.anya-md/lib/Assets/reaction/no/no2.png +0 -0
  229. package/.anya-md/lib/Assets/reaction/no/no3.jpg +0 -0
  230. package/.anya-md/lib/Assets/reaction/no/no4.png +0 -0
  231. package/.anya-md/lib/Assets/reaction/no/no5.png +0 -0
  232. package/.anya-md/lib/Assets/reaction/no/no6.jpg +0 -0
  233. package/.anya-md/lib/Assets/reaction/no/no7.jpg +0 -0
  234. package/.anya-md/lib/Assets/reaction/no/no8.jpg +0 -0
  235. package/.anya-md/lib/Assets/reaction/no/no9.mp4 +0 -0
  236. package/.anya-md/lib/Assets/reaction/smug/059e1bdc-e62a-4943-b85e-ea372709f6a7.jpeg +0 -0
  237. package/.anya-md/lib/Assets/reaction/smug/8fda90b3-bc98-4d24-ac10-4402c4e7be93.jpeg +0 -0
  238. package/.anya-md/lib/Assets/reaction/smug/Aqua.jpeg +0 -0
  239. package/.anya-md/lib/Assets/reaction/smug/Karasuma Chitose.jpeg +0 -0
  240. package/.anya-md/lib/Assets/reaction/smug/Smug Face - Fibel Sistine.jpeg +0 -0
  241. package/.anya-md/lib/Assets/reaction/smug/bf8d78ec-4fcc-4ff7-b3c3-91a0c5f22567.jpeg +0 -0
  242. package/.anya-md/lib/Assets/reaction/smug//330/247/330/255/331/204/330/247/331/213 /330/247/330/250/330/252/330/263/330/247/331/205/331/207 /330/264/330/261/331/212/330/261/331/207/360/237/230/255/360/237/230/255/360/237/230/255.jpeg +0 -0
  243. package/.anya-md/lib/Assets/verifyIMG.jpg +0 -0
  244. package/.anya-md/lib/Assets/welcomeGIF.mp4 +0 -0
  245. package/.anya-md/lib/database/categories.json +0 -77
  246. package/.anya-md/lib/database/cooldown.json +0 -1
  247. package/.anya-md/lib/database/disk/main.js +0 -43
  248. package/.anya-md/lib/database/emoji.js +0 -23
  249. package/.anya-md/lib/database/games/quiz/Questions.js +0 -44
  250. package/.anya-md/lib/database/games/quiz/Quiz.js +0 -169
  251. package/.anya-md/lib/database/games/quiz/database.json +0 -1
  252. package/.anya-md/lib/database/games/quiz/index.js +0 -7
  253. package/.anya-md/lib/database/json/.pika.js +0 -3
  254. package/.anya-md/lib/database/json/animeQuotes.json +0 -51062
  255. package/.anya-md/lib/database/json/bioQuotes.json +0 -5744
  256. package/.anya-md/lib/database/json/cogan.json +0 -102
  257. package/.anya-md/lib/database/json/countries.json +0 -21210
  258. package/.anya-md/lib/database/json/countries2.json +0 -1
  259. package/.anya-md/lib/database/json/couplepp.json +0 -725
  260. package/.anya-md/lib/database/json/flaming.json +0 -7
  261. package/.anya-md/lib/database/json/ganpati.json +0 -102
  262. package/.anya-md/lib/database/json/husbu.json +0 -1967
  263. package/.anya-md/lib/database/json/islamicWall.json +0 -501
  264. package/.anya-md/lib/database/json/pickupLines.json +0 -118
  265. package/.anya-md/lib/database/json/shreeram.json +0 -49
  266. package/.anya-md/lib/database/json/truthDare.json +0 -643
  267. package/.anya-md/lib/database/mongodb/README.md +0 -142
  268. package/.anya-md/lib/database/mongodb/bot.js +0 -12
  269. package/.anya-md/lib/database/mongodb/cmd.js +0 -17
  270. package/.anya-md/lib/database/mongodb/group.js +0 -22
  271. package/.anya-md/lib/database/mongodb/index.js +0 -24
  272. package/.anya-md/lib/database/mongodb/plugins.js +0 -124
  273. package/.anya-md/lib/database/mongodb/system.js +0 -34
  274. package/.anya-md/lib/database/mongodb/ui.js +0 -15
  275. package/.anya-md/lib/database/mongodb/user.js +0 -17
  276. package/.anya-md/lib/database/mongodb/warn.js +0 -136
  277. package/.anya-md/lib/database/sessions/.pika.js +0 -3
  278. package/.anya-md/lib/frameworks/index.js +0 -5
  279. package/.anya-md/lib/frameworks/reactionMedia.js +0 -91
  280. package/.anya-md/lib/lib/README.md +0 -29
  281. package/.anya-md/lib/lib/ai/README.md +0 -35
  282. package/.anya-md/lib/lib/ai/aiArt.js +0 -47
  283. package/.anya-md/lib/lib/ai/index.js +0 -7
  284. package/.anya-md/lib/lib/buttons.js +0 -530
  285. package/.anya-md/lib/lib/connectionMsg.js +0 -72
  286. package/.anya-md/lib/lib/converter.js +0 -355
  287. package/.anya-md/lib/lib/cooldown.js +0 -46
  288. package/.anya-md/lib/lib/events.js +0 -47
  289. package/.anya-md/lib/lib/functions.js +0 -47
  290. package/.anya-md/lib/lib/greeting.js +0 -115
  291. package/.anya-md/lib/lib/index.js +0 -381
  292. package/.anya-md/lib/lib/logger.js +0 -7
  293. package/.anya-md/lib/lib/maker/remini.js +0 -35
  294. package/.anya-md/lib/lib/mongoUrlFix.js +0 -46
  295. package/.anya-md/lib/lib/myfunc.js +0 -47
  296. package/.anya-md/lib/lib/plugins.js +0 -20
  297. package/.anya-md/lib/lib/prefix.js +0 -47
  298. package/.anya-md/lib/lib/scraper/README.md +0 -35
  299. package/.anya-md/lib/lib/scraper/SoundCloud.js +0 -47
  300. package/.anya-md/lib/lib/scraper/WebToons.js +0 -47
  301. package/.anya-md/lib/lib/scraper/android1.js +0 -47
  302. package/.anya-md/lib/lib/scraper/happymodSearch.js +0 -47
  303. package/.anya-md/lib/lib/scraper/index.js +0 -27
  304. package/.anya-md/lib/lib/scraper/konaChanSearch.js +0 -47
  305. package/.anya-md/lib/lib/scraper/pinterest.js +0 -47
  306. package/.anya-md/lib/lib/scraper/playstore.js +0 -47
  307. package/.anya-md/lib/lib/scraper/ringtone.js +0 -47
  308. package/.anya-md/lib/lib/scraper/steam.js +0 -47
  309. package/.anya-md/lib/lib/scraper/trendingTwitter.js +0 -51
  310. package/.anya-md/lib/lib/scraper/wattpad.js +0 -61
  311. package/.anya-md/lib/lib/scraper/wikipediaSearch.js +0 -42
  312. package/.anya-md/lib/lib/scraper.js +0 -47
  313. package/.anya-md/lib/lib/session.js +0 -47
  314. package/.anya-md/lib/lib/session2.js +0 -47
  315. package/.anya-md/lib/lib/similar.js +0 -47
  316. package/.anya-md/lib/lib/stylish-font.js +0 -2302
  317. package/.anya-md/lib/lib/unicode.js +0 -877
  318. package/.anya-md/lib/lib/upload/index.js +0 -3
  319. package/.anya-md/lib/lib/upload/webp2mp4File.js +0 -56
  320. package/.anya-md/lib/lib/ytdl-core.js +0 -47
  321. package/.anya-md/lib/plugins/README.md +0 -83
  322. package/.anya-md/lib/plugins/_menu.js +0 -810
  323. package/.anya-md/lib/plugins/_plugins.js +0 -239
  324. package/.anya-md/lib/plugins/admins.js +0 -689
  325. package/.anya-md/lib/plugins/ai.js +0 -160
  326. package/.anya-md/lib/plugins/autoreply.js +0 -101
  327. package/.anya-md/lib/plugins/broadcast.js +0 -204
  328. package/.anya-md/lib/plugins/convert.js +0 -293
  329. package/.anya-md/lib/plugins/core.js +0 -941
  330. package/.anya-md/lib/plugins/download.js +0 -373
  331. package/.anya-md/lib/plugins/fun.js +0 -75
  332. package/.anya-md/lib/plugins/games.js +0 -33
  333. package/.anya-md/lib/plugins/gcswitches.js +0 -204
  334. package/.anya-md/lib/plugins/general.js +0 -456
  335. package/.anya-md/lib/plugins/maker.js +0 -41
  336. package/.anya-md/lib/plugins/owner.js +0 -1049
  337. package/.anya-md/lib/plugins/religious.js +0 -81
  338. package/.anya-md/lib/plugins/search.js +0 -902
  339. package/.anya-md/lib/plugins/stalker.js +0 -187
  340. package/.anya-md/lib/plugins/sticker.js +0 -125
  341. package/.anya-md/lib/plugins/tools.js +0 -193
  342. package/.anya-md/lib/plugins/youtube.js +0 -204
  343. package/.anya-md/package.json +0 -75
  344. package/.anya-md/railway.json +0 -12
  345. package/.anya-md/render.yaml +0 -48
  346. package/.anya-md/replit.nix +0 -18
  347. package/.bash_history +0 -500
  348. package/.config/gh/config.yml +0 -19
  349. package/.config/gh/hosts.yml +0 -11
  350. package/.config/ngrok/ngrok.yml +0 -3
  351. package/.config/yarn/global/package.json +0 -5
  352. package/.gitconfig +0 -772
  353. package/.node_repl_history +0 -0
  354. package/.npm/_cacache/content-v2/sha512/02/b3/d1abf5af06222f7de440ab1b057deb21f9dfb0ce0a8f5064b2ba00595933bbcbbaa040b4616f951d9f8ba48d67491df1198a4831fbd8ee26eb27dde36511 +0 -0
  355. package/.npm/_cacache/content-v2/sha512/49/7b/0cdbb4861f7c9358a7367ca478498371b269efb8143d75de901ed1169a267f56a68e60f008952f3ebcc727dbb60bb401011af3514a1dd33cdbed8d981fa8 +0 -0
  356. package/.npm/_cacache/content-v2/sha512/54/3a/647bceb49b7632e6e700cb9f1b66f0f528d4ca71f4f73e76a1e7c8c50b563a2d0bb7734c18f93e6c03b7ea93167db35db0e1999ab13b08ed6b250eed2d2a +0 -1
  357. package/.npm/_cacache/content-v2/sha512/56/7c/4d5820233a7278225351642f7355d9889af42e7efbbfe27d6b201727efad972a59fa32063c7e1159d01dbf27ba014095ca1349ec0d0767746c39441178fa +0 -1
  358. package/.npm/_cacache/content-v2/sha512/89/88/d295c7e4f4d0f4621676d4c499bea2a1c72b0c31a84ff78a8bb8f83042da2bcf596e664c021d21025b296cdd4aecb57a036ea366e39466df5a129fa471df +0 -0
  359. package/.npm/_cacache/content-v2/sha512/8b/46/42882ebb46a975b0ce6b9cdea357190c41b51bb59a21df41c575418850b28115921e130709846d8ff9cabeae72544ec37a48ee7ccb074fe94da925250e55 +0 -1
  360. package/.npm/_cacache/content-v2/sha512/dd/0d/f856b793da0619d18260556498dfff13391593abb6d6a582bf052f03ba35a03a1444bf5c2d40b7515d268ec2cb3e67a17a42f09f5e668c3bb9b743e3b8a7 +0 -1
  361. package/.npm/_cacache/content-v2/sha512/dd/15/702501c36ce653a003d2b101034a0cb9c0fd262fa77797f1a286a161a0b2dce51ef13199e9a3fa58008bdbbf4646a33b6f1a24a2807691093cb89beefb00 +0 -1
  362. package/.npm/_cacache/index-v5/35/f9/e8cc076ef93c1bc40804d3fe05171053366095c922f515b1fab2b580116f +0 -4
  363. package/.npm/_cacache/index-v5/6a/a2/780c77f928115d4dad58a9dc4fa241de8d914abfff994e44602cc93a697c +0 -2
  364. package/.npm/_cacache/index-v5/71/ba/d0bb16fddeb617bbbb3713f46750d1bf5b57742abb6feb6dee4d16c68da4 +0 -4
  365. package/.npm/_cacache/index-v5/72/ae/c69532318093b3bd13618450ca5c26adc018a4afc0e020786207068593cf +0 -2
  366. package/.npm/_cacache/index-v5/7e/5e/9683ad4854f4201d7e53bf9beb2aefafa7b1efbb2c6ac7b36b78d0b218c8 +0 -2
  367. package/.npm/_cacache/index-v5/eb/a0/19e529094c594367a9e1aa68096a313d3dc5509d410761bf50122826a6d2 +0 -4
  368. package/.npm/_cacache/index-v5/f1/fa/2d2f12de549683d1275ec0f2ff15610b408fd89d1b7a755ddb7b77c00371 +0 -2
  369. package/.npm/_logs/2024-10-03T05_52_01_853Z-debug-0.log +0 -52
  370. package/.npm/_logs/2024-10-03T05_52_08_135Z-debug-0.log +0 -52
  371. package/.npm/_logs/2024-10-03T05_52_14_087Z-debug-0.log +0 -52
  372. package/.npm/_logs/2024-10-03T05_52_22_730Z-debug-0.log +0 -52
  373. package/.npm/_logs/2024-10-03T05_52_29_410Z-debug-0.log +0 -52
  374. package/.npm/_logs/2024-10-03T05_52_35_375Z-debug-0.log +0 -52
  375. package/.npm/_logs/2024-10-03T15_32_57_465Z-debug-0.log +0 -20
  376. package/.npm/_logs/2024-10-10T05_40_23_847Z-debug-0.log +0 -254
  377. package/.npm/_logs/2024-10-10T05_40_50_397Z-debug-0.log +0 -73
  378. package/.npm/_logs/2024-10-10T05_40_59_931Z-debug-0.log +0 -52
  379. package/.npm/_logs/2024-10-10T05_42_07_969Z-debug-0.log +0 -52
  380. package/.pm2/logs/anya-error.log +0 -0
  381. package/.pm2/logs/anya-out.log +0 -59
  382. package/.pm2/logs/anya-v2-error.log +0 -2184
  383. package/.pm2/logs/anya-v2-out.log +0 -362
  384. package/.pm2/module_conf.json +0 -1
  385. package/.pm2/pm2.log +0 -919
  386. package/.pm2/pm2.pid +0 -1
  387. package/.pm2/touch +0 -1
  388. package/.ssh/authorized_keys +0 -0
  389. package/.termux/termux.properties +0 -180
  390. package/.wget-hsts +0 -5
@@ -0,0 +1,918 @@
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 boom_1 = require("@hapi/boom");
8
+ const crypto_1 = require("crypto");
9
+ const node_cache_1 = __importDefault(require("node-cache"));
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 Utils_2 = require("../Utils");
15
+ const make_mutex_1 = require("../Utils/make-mutex");
16
+ const WABinary_1 = require("../WABinary");
17
+ const groups_1 = require("./groups");
18
+ const messages_send_1 = require("./messages-send");
19
+ const makeMessagesRecvSocket = (config) => {
20
+ const { logger, retryRequestDelayMs, maxMsgRetryCount, ignoreMsgLoading, getMessage, shouldIgnoreJid } = config;
21
+ const sock = (0, messages_send_1.makeMessagesSocket)(config);
22
+ const { ev, authState, ws, processingMutex, signalRepository, query, upsertMessage, resyncAppState, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, sendPeerDataOperationMessage, } = sock;
23
+ /** this mutex ensures that each retryRequest will wait for the previous one to finish */
24
+ const retryMutex = (0, make_mutex_1.makeMutex)();
25
+ const msgRetryCache = config.msgRetryCounterCache || new node_cache_1.default({
26
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
27
+ useClones: false
28
+ });
29
+ const callOfferCache = config.callOfferCache || new node_cache_1.default({
30
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.CALL_OFFER,
31
+ useClones: false
32
+ });
33
+ const placeholderResendCache = config.placeholderResendCache || new node_cache_1.default({
34
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
35
+ useClones: false
36
+ });
37
+ let sendActiveReceipts = false;
38
+ const sendMessageAck = async ({ tag, attrs, content }) => {
39
+ const stanza = {
40
+ tag: 'ack',
41
+ attrs: {
42
+ id: attrs.id,
43
+ to: attrs.from,
44
+ class: tag,
45
+ }
46
+ };
47
+ if (!!attrs.participant) {
48
+ stanza.attrs.participant = attrs.participant;
49
+ }
50
+ if (!!attrs.recipient) {
51
+ stanza.attrs.recipient = attrs.recipient;
52
+ }
53
+ if (!!attrs.type && (tag !== 'message' || (0, WABinary_1.getBinaryNodeChild)({ tag, attrs, content }, 'unavailable'))) {
54
+ stanza.attrs.type = attrs.type;
55
+ }
56
+ if (tag === 'message' && (0, WABinary_1.getBinaryNodeChild)({ tag, attrs, content }, 'unavailable')) {
57
+ stanza.attrs.from = authState.creds.me.id;
58
+ }
59
+ logger.debug({ recv: { tag, attrs }, sent: stanza.attrs }, 'sent ack');
60
+ await sendNode(stanza);
61
+ };
62
+ const rejectCall = async (callId, callFrom) => {
63
+ const stanza = ({
64
+ tag: 'call',
65
+ attrs: {
66
+ from: authState.creds.me.id,
67
+ to: callFrom,
68
+ },
69
+ content: [{
70
+ tag: 'reject',
71
+ attrs: {
72
+ 'call-id': callId,
73
+ 'call-creator': callFrom,
74
+ count: '0',
75
+ },
76
+ content: undefined,
77
+ }],
78
+ });
79
+ await query(stanza);
80
+ };
81
+ const sendRetryRequest = async (node, forceIncludeKeys = false) => {
82
+ const { fullMessage } = (0, Utils_1.decodeMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '');
83
+ const { key: msgKey } = fullMessage;
84
+ const msgId = msgKey.id;
85
+ const key = `${msgId}:${msgKey === null || msgKey === void 0 ? void 0 : msgKey.participant}`;
86
+ let retryCount = msgRetryCache.get(key) || 0;
87
+ if (retryCount >= maxMsgRetryCount) {
88
+ logger.debug({ retryCount, msgId }, 'reached retry limit, clearing');
89
+ msgRetryCache.del(key);
90
+ return;
91
+ }
92
+ retryCount += 1;
93
+ msgRetryCache.set(key, retryCount);
94
+ const { account, signedPreKey, signedIdentityKey: identityKey } = authState.creds;
95
+ if (retryCount === 1) {
96
+ //request a resend via phone
97
+ const msgId = await requestPlaceholderResend(msgKey);
98
+ logger.debug(`sendRetryRequest: requested placeholder resend for message ${msgId}`);
99
+ }
100
+ const deviceIdentity = (0, Utils_1.encodeSignedDeviceIdentity)(account, true);
101
+ await authState.keys.transaction(async () => {
102
+ const receipt = {
103
+ tag: 'receipt',
104
+ attrs: {
105
+ id: msgId,
106
+ type: 'retry',
107
+ to: node.attrs.from
108
+ },
109
+ content: [
110
+ {
111
+ tag: 'retry',
112
+ attrs: {
113
+ count: retryCount.toString(),
114
+ id: node.attrs.id,
115
+ t: node.attrs.t,
116
+ v: '1'
117
+ }
118
+ },
119
+ {
120
+ tag: 'registration',
121
+ attrs: {},
122
+ content: (0, Utils_1.encodeBigEndian)(authState.creds.registrationId)
123
+ }
124
+ ]
125
+ };
126
+ if (node.attrs.recipient) {
127
+ receipt.attrs.recipient = node.attrs.recipient;
128
+ }
129
+ if (node.attrs.participant) {
130
+ receipt.attrs.participant = node.attrs.participant;
131
+ }
132
+ if (retryCount > 1 || forceIncludeKeys) {
133
+ const { update, preKeys } = await (0, Utils_1.getNextPreKeys)(authState, 1);
134
+ const [keyId] = Object.keys(preKeys);
135
+ const key = preKeys[+keyId];
136
+ const content = receipt.content;
137
+ content.push({
138
+ tag: 'keys',
139
+ attrs: {},
140
+ content: [
141
+ { tag: 'type', attrs: {}, content: Buffer.from(Defaults_1.KEY_BUNDLE_TYPE) },
142
+ { tag: 'identity', attrs: {}, content: identityKey.public },
143
+ (0, Utils_1.xmppPreKey)(key, +keyId),
144
+ (0, Utils_1.xmppSignedPreKey)(signedPreKey),
145
+ { tag: 'device-identity', attrs: {}, content: deviceIdentity }
146
+ ]
147
+ });
148
+ ev.emit('creds.update', update);
149
+ }
150
+ await sendNode(receipt);
151
+ logger.info({ msgAttrs: node.attrs, retryCount }, 'sent retry receipt');
152
+ });
153
+ };
154
+ const handleEncryptNotification = async (node) => {
155
+ const from = node.attrs.from;
156
+ if (from === WABinary_1.S_WHATSAPP_NET) {
157
+ const countChild = (0, WABinary_1.getBinaryNodeChild)(node, 'count');
158
+ const count = +countChild.attrs.value;
159
+ const shouldUploadMorePreKeys = count < Defaults_1.MIN_PREKEY_COUNT;
160
+ logger.debug({ count, shouldUploadMorePreKeys }, 'recv pre-key count');
161
+ if (shouldUploadMorePreKeys) {
162
+ await uploadPreKeys();
163
+ }
164
+ }
165
+ else {
166
+ const identityNode = (0, WABinary_1.getBinaryNodeChild)(node, 'identity');
167
+ if (identityNode) {
168
+ logger.info({ jid: from }, 'identity changed');
169
+ // not handling right now
170
+ // signal will override new identity anyway
171
+ }
172
+ else {
173
+ logger.info({ node }, 'unknown encrypt notification');
174
+ }
175
+ }
176
+ };
177
+ const handleGroupNotification = (participant, child, msg) => {
178
+ var _a, _b, _c, _d;
179
+ 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;
180
+ switch (child === null || child === void 0 ? void 0 : child.tag) {
181
+ case 'create':
182
+ const metadata = (0, groups_1.extractGroupMetadata)(child);
183
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_CREATE;
184
+ msg.messageStubParameters = [metadata.subject];
185
+ msg.key = { participant: metadata.owner };
186
+ ev.emit('chats.upsert', [{
187
+ id: metadata.id,
188
+ name: metadata.subject,
189
+ conversationTimestamp: metadata.creation,
190
+ }]);
191
+ ev.emit('groups.upsert', [{
192
+ ...metadata,
193
+ author: participant
194
+ }]);
195
+ break;
196
+ case 'ephemeral':
197
+ case 'not_ephemeral':
198
+ msg.message = {
199
+ protocolMessage: {
200
+ type: WAProto_1.proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING,
201
+ ephemeralExpiration: +(child.attrs.expiration || 0)
202
+ }
203
+ };
204
+ break;
205
+ case 'modify':
206
+ const oldNumber = (0, WABinary_1.getBinaryNodeChildren)(child, 'participant').map(p => p.attrs.jid);
207
+ msg.messageStubParameters = oldNumber || [];
208
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER;
209
+ break;
210
+ case 'promote':
211
+ case 'demote':
212
+ case 'remove':
213
+ case 'add':
214
+ case 'leave':
215
+ const stubType = `GROUP_PARTICIPANT_${child.tag.toUpperCase()}`;
216
+ msg.messageStubType = Types_1.WAMessageStubType[stubType];
217
+ const participants = (0, WABinary_1.getBinaryNodeChildren)(child, 'participant').map(p => p.attrs.jid);
218
+ if (participants.length === 1 &&
219
+ // if recv. "remove" message and sender removed themselves
220
+ // mark as left
221
+ (0, WABinary_1.areJidsSameUser)(participants[0], participant) &&
222
+ child.tag === 'remove') {
223
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE;
224
+ }
225
+ msg.messageStubParameters = participants;
226
+ break;
227
+ case 'subject':
228
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT;
229
+ msg.messageStubParameters = [child.attrs.subject];
230
+ break;
231
+ case 'description':
232
+ 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();
233
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_DESCRIPTION;
234
+ msg.messageStubParameters = description ? [description] : undefined;
235
+ break;
236
+ case 'announcement':
237
+ case 'not_announcement':
238
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE;
239
+ msg.messageStubParameters = [(child.tag === 'announcement') ? 'on' : 'off'];
240
+ break;
241
+ case 'locked':
242
+ case 'unlocked':
243
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_RESTRICT;
244
+ msg.messageStubParameters = [(child.tag === 'locked') ? 'on' : 'off'];
245
+ break;
246
+ case 'invite':
247
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK;
248
+ msg.messageStubParameters = [child.attrs.code];
249
+ break;
250
+ case 'member_add_mode':
251
+ const addMode = child.content;
252
+ if (addMode) {
253
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_MEMBER_ADD_MODE;
254
+ msg.messageStubParameters = [addMode.toString()];
255
+ }
256
+ break;
257
+ case 'membership_approval_mode':
258
+ const approvalMode = (0, WABinary_1.getBinaryNodeChild)(child, 'group_join');
259
+ if (approvalMode) {
260
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE;
261
+ msg.messageStubParameters = [approvalMode.attrs.state];
262
+ }
263
+ break;
264
+ case 'created_membership_requests':
265
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
266
+ msg.messageStubParameters = [participantJid, 'created', child.attrs.request_method];
267
+ break;
268
+ case 'revoked_membership_requests':
269
+ const isDenied = (0, WABinary_1.areJidsSameUser)(participantJid, participant);
270
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
271
+ msg.messageStubParameters = [participantJid, isDenied ? 'revoked' : 'rejected'];
272
+ break;
273
+ }
274
+ };
275
+ const handleNewsletterNotification = (id, node) => {
276
+ const messages = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
277
+ const message = (0, WABinary_1.getBinaryNodeChild)(messages, 'message');
278
+ const server_id = message.attrs.server_id;
279
+ const reactionsList = (0, WABinary_1.getBinaryNodeChild)(message, 'reactions');
280
+ const viewsList = (0, WABinary_1.getBinaryNodeChildren)(message, 'views_count');
281
+ if (reactionsList) {
282
+ const reactions = (0, WABinary_1.getBinaryNodeChildren)(reactionsList, 'reaction');
283
+ if (reactions.length === 0) {
284
+ ev.emit('newsletter.reaction', { id, server_id, reaction: { removed: true } });
285
+ }
286
+ reactions.forEach(item => {
287
+ var _a, _b;
288
+ ev.emit('newsletter.reaction', { id, server_id, reaction: { code: (_a = item.attrs) === null || _a === void 0 ? void 0 : _a.code, count: +((_b = item.attrs) === null || _b === void 0 ? void 0 : _b.count) } });
289
+ });
290
+ }
291
+ if (viewsList.length) {
292
+ viewsList.forEach(item => {
293
+ ev.emit('newsletter.view', { id, server_id, count: +item.attrs.count });
294
+ });
295
+ }
296
+ };
297
+ const handleMexNewsletterNotification = (id, node) => {
298
+ var _a;
299
+ const operation = node === null || node === void 0 ? void 0 : node.attrs.op_name;
300
+ const content = JSON.parse((_a = node === null || node === void 0 ? void 0 : node.content) === null || _a === void 0 ? void 0 : _a.toString());
301
+ let contentPath;
302
+ if (operation === Types_1.MexOperations.PROMOTE || operation === Types_1.MexOperations.DEMOTE) {
303
+ let action;
304
+ if (operation === Types_1.MexOperations.PROMOTE) {
305
+ action = 'promote';
306
+ contentPath = content.data[Types_1.XWAPaths.PROMOTE];
307
+ }
308
+ if (operation === Types_1.MexOperations.DEMOTE) {
309
+ action = 'demote';
310
+ contentPath = content.data[Types_1.XWAPaths.DEMOTE];
311
+ }
312
+ ev.emit('newsletter-participants.update', { id, author: contentPath.actor.pn, user: contentPath.user.pn, new_role: contentPath.user_new_role, action });
313
+ }
314
+ if (operation === Types_1.MexOperations.UPDATE) {
315
+ contentPath = content.data[Types_1.XWAPaths.METADATA_UPDATE];
316
+ ev.emit('newsletter-settings.update', { id, update: contentPath.thread_metadata.settings });
317
+ }
318
+ };
319
+ const processNotification = async (node) => {
320
+ var _a, _b, _c;
321
+ const result = {};
322
+ const [child] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
323
+ const nodeType = node.attrs.type;
324
+ const from = (0, WABinary_1.jidNormalizedUser)(node.attrs.from);
325
+ switch (nodeType) {
326
+ case 'privacy_token':
327
+ const tokenList = (0, WABinary_1.getBinaryNodeChildren)(child, 'token');
328
+ for (const { attrs, content } of tokenList) {
329
+ const jid = attrs.jid;
330
+ ev.emit('chats.update', [
331
+ {
332
+ id: jid,
333
+ tcToken: content
334
+ }
335
+ ]);
336
+ logger.debug({ jid }, 'got privacy token update');
337
+ }
338
+ break;
339
+ case 'newsletter':
340
+ handleNewsletterNotification(node.attrs.from, child);
341
+ break;
342
+ case 'mex':
343
+ handleMexNewsletterNotification(node.attrs.from, child);
344
+ break;
345
+ case 'w:gp2':
346
+ handleGroupNotification(node.attrs.participant, child, result);
347
+ break;
348
+ case 'mediaretry':
349
+ const event = (0, Utils_1.decodeMediaRetryNode)(node);
350
+ ev.emit('messages.media-update', [event]);
351
+ break;
352
+ case 'encrypt':
353
+ await handleEncryptNotification(node);
354
+ break;
355
+ case 'newsletter':
356
+ // TO DO
357
+ break;
358
+ case 'devices':
359
+ const devices = (0, WABinary_1.getBinaryNodeChildren)(child, 'device');
360
+ if ((0, WABinary_1.areJidsSameUser)(child.attrs.jid, authState.creds.me.id)) {
361
+ const deviceJids = devices.map(d => d.attrs.jid);
362
+ logger.info({ deviceJids }, 'got my own devices');
363
+ }
364
+ break;
365
+ case 'server_sync':
366
+ const update = (0, WABinary_1.getBinaryNodeChild)(node, 'collection');
367
+ if (update) {
368
+ const name = update.attrs.name;
369
+ await resyncAppState([name], false);
370
+ }
371
+ break;
372
+ case 'picture':
373
+ const setPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'set');
374
+ const delPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'delete');
375
+ ev.emit('contacts.update', [{
376
+ 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) || '',
377
+ imgUrl: setPicture ? 'changed' : 'removed'
378
+ }]);
379
+ if ((0, WABinary_1.isJidGroup)(from)) {
380
+ const node = setPicture || delPicture;
381
+ result.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_ICON;
382
+ if (setPicture) {
383
+ result.messageStubParameters = [setPicture.attrs.id];
384
+ }
385
+ result.participant = node === null || node === void 0 ? void 0 : node.attrs.author;
386
+ result.key = {
387
+ ...result.key || {},
388
+ participant: setPicture === null || setPicture === void 0 ? void 0 : setPicture.attrs.author
389
+ };
390
+ }
391
+ break;
392
+ case 'account_sync':
393
+ if (child.tag === 'disappearing_mode') {
394
+ const newDuration = +child.attrs.duration;
395
+ const timestamp = +child.attrs.t;
396
+ logger.info({ newDuration }, 'updated account disappearing mode');
397
+ ev.emit('creds.update', {
398
+ accountSettings: {
399
+ ...authState.creds.accountSettings,
400
+ defaultDisappearingMode: {
401
+ ephemeralExpiration: newDuration,
402
+ ephemeralSettingTimestamp: timestamp,
403
+ },
404
+ }
405
+ });
406
+ }
407
+ else if (child.tag === 'blocklist') {
408
+ const blocklists = (0, WABinary_1.getBinaryNodeChildren)(child, 'item');
409
+ for (const { attrs } of blocklists) {
410
+ const blocklist = [attrs.jid];
411
+ const type = (attrs.action === 'block') ? 'add' : 'remove';
412
+ ev.emit('blocklist.update', { blocklist, type });
413
+ }
414
+ }
415
+ break;
416
+ case 'link_code_companion_reg':
417
+ const linkCodeCompanionReg = (0, WABinary_1.getBinaryNodeChild)(node, 'link_code_companion_reg');
418
+ const ref = toRequiredBuffer((0, WABinary_1.getBinaryNodeChildBuffer)(linkCodeCompanionReg, 'link_code_pairing_ref'));
419
+ const primaryIdentityPublicKey = toRequiredBuffer((0, WABinary_1.getBinaryNodeChildBuffer)(linkCodeCompanionReg, 'primary_identity_pub'));
420
+ const primaryEphemeralPublicKeyWrapped = toRequiredBuffer((0, WABinary_1.getBinaryNodeChildBuffer)(linkCodeCompanionReg, 'link_code_pairing_wrapped_primary_ephemeral_pub'));
421
+ const codePairingPublicKey = await decipherLinkPublicKey(primaryEphemeralPublicKeyWrapped);
422
+ const companionSharedKey = Utils_1.Curve.sharedKey(authState.creds.pairingEphemeralKeyPair.private, codePairingPublicKey);
423
+ const random = (0, crypto_1.randomBytes)(32);
424
+ const linkCodeSalt = (0, crypto_1.randomBytes)(32);
425
+ const linkCodePairingExpanded = (0, Utils_1.hkdf)(companionSharedKey, 32, {
426
+ salt: linkCodeSalt,
427
+ info: 'link_code_pairing_key_bundle_encryption_key'
428
+ });
429
+ const encryptPayload = Buffer.concat([Buffer.from(authState.creds.signedIdentityKey.public), primaryIdentityPublicKey, random]);
430
+ const encryptIv = (0, crypto_1.randomBytes)(12);
431
+ const encrypted = (0, Utils_1.aesEncryptGCM)(encryptPayload, linkCodePairingExpanded, encryptIv, Buffer.alloc(0));
432
+ const encryptedPayload = Buffer.concat([linkCodeSalt, encryptIv, encrypted]);
433
+ const identitySharedKey = Utils_1.Curve.sharedKey(authState.creds.signedIdentityKey.private, primaryIdentityPublicKey);
434
+ const identityPayload = Buffer.concat([companionSharedKey, identitySharedKey, random]);
435
+ authState.creds.advSecretKey = (0, Utils_1.hkdf)(identityPayload, 32, { info: 'adv_secret' }).toString('base64');
436
+ await query({
437
+ tag: 'iq',
438
+ attrs: {
439
+ to: WABinary_1.S_WHATSAPP_NET,
440
+ type: 'set',
441
+ id: sock.generateMessageTag(),
442
+ xmlns: 'md'
443
+ },
444
+ content: [
445
+ {
446
+ tag: 'link_code_companion_reg',
447
+ attrs: {
448
+ jid: authState.creds.me.id,
449
+ stage: 'companion_finish',
450
+ },
451
+ content: [
452
+ {
453
+ tag: 'link_code_pairing_wrapped_key_bundle',
454
+ attrs: {},
455
+ content: encryptedPayload
456
+ },
457
+ {
458
+ tag: 'companion_identity_public',
459
+ attrs: {},
460
+ content: authState.creds.signedIdentityKey.public
461
+ },
462
+ {
463
+ tag: 'link_code_pairing_ref',
464
+ attrs: {},
465
+ content: ref
466
+ }
467
+ ]
468
+ }
469
+ ]
470
+ });
471
+ authState.creds.registered = true;
472
+ ev.emit('creds.update', authState.creds);
473
+ }
474
+ if (Object.keys(result).length) {
475
+ return result;
476
+ }
477
+ };
478
+ async function decipherLinkPublicKey(data) {
479
+ const buffer = toRequiredBuffer(data);
480
+ const salt = buffer.slice(0, 32);
481
+ const secretKey = await (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
482
+ const iv = buffer.slice(32, 48);
483
+ const payload = buffer.slice(48, 80);
484
+ return (0, Utils_1.aesDecryptCTR)(payload, secretKey, iv);
485
+ }
486
+ function toRequiredBuffer(data) {
487
+ if (data === undefined) {
488
+ throw new boom_1.Boom('Invalid buffer', { statusCode: 400 });
489
+ }
490
+ return data instanceof Buffer ? data : Buffer.from(data);
491
+ }
492
+ const willSendMessageAgain = (id, participant) => {
493
+ const key = `${id}:${participant}`;
494
+ const retryCount = msgRetryCache.get(key) || 0;
495
+ return retryCount < maxMsgRetryCount;
496
+ };
497
+ const updateSendMessageAgainCount = (id, participant) => {
498
+ const key = `${id}:${participant}`;
499
+ const newValue = (msgRetryCache.get(key) || 0) + 1;
500
+ msgRetryCache.set(key, newValue);
501
+ };
502
+ const sendMessagesAgain = async (key, ids, retryNode) => {
503
+ var _a;
504
+ const msgs = await Promise.all(ids.map(id => getMessage({ ...key, id })));
505
+ const remoteJid = key.remoteJid;
506
+ const participant = key.participant || remoteJid;
507
+ // if it's the primary jid sending the request
508
+ // just re-send the message to everyone
509
+ // prevents the first message decryption failure
510
+ const sendToAll = !((_a = (0, WABinary_1.jidDecode)(participant)) === null || _a === void 0 ? void 0 : _a.device);
511
+ await assertSessions([participant], true);
512
+ if ((0, WABinary_1.isJidGroup)(remoteJid)) {
513
+ await authState.keys.set({ 'sender-key-memory': { [remoteJid]: null } });
514
+ }
515
+ logger.debug({ participant, sendToAll }, 'forced new session for retry recp');
516
+ for (const [i, msg] of msgs.entries()) {
517
+ if (msg) {
518
+ updateSendMessageAgainCount(ids[i], participant);
519
+ const msgRelayOpts = { messageId: ids[i] };
520
+ if (sendToAll) {
521
+ msgRelayOpts.useUserDevicesCache = false;
522
+ }
523
+ else {
524
+ msgRelayOpts.participant = {
525
+ jid: participant,
526
+ count: +retryNode.attrs.count
527
+ };
528
+ }
529
+ await relayMessage(key.remoteJid, msg, msgRelayOpts);
530
+ }
531
+ else {
532
+ logger.debug({ jid: key.remoteJid, id: ids[i] }, 'recv retry request, but message not available');
533
+ }
534
+ }
535
+ };
536
+ const handleReceipt = async (node) => {
537
+ var _a, _b;
538
+ const { attrs, content } = node;
539
+ const isLid = attrs.from.includes('lid');
540
+ 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);
541
+ const remoteJid = !isNodeFromMe || (0, WABinary_1.isJidGroup)(attrs.from) ? attrs.from : attrs.recipient;
542
+ const fromMe = !attrs.recipient || (attrs.type === 'retry' && isNodeFromMe);
543
+ const key = {
544
+ remoteJid,
545
+ id: '',
546
+ fromMe,
547
+ participant: attrs.participant
548
+ };
549
+ if (shouldIgnoreJid(remoteJid) && remoteJid !== '@s.whatsapp.net') {
550
+ logger.debug({ remoteJid }, 'ignoring receipt from jid');
551
+ await sendMessageAck(node);
552
+ return;
553
+ }
554
+ const ids = [attrs.id];
555
+ if (Array.isArray(content)) {
556
+ const items = (0, WABinary_1.getBinaryNodeChildren)(content[0], 'item');
557
+ ids.push(...items.map(i => i.attrs.id));
558
+ }
559
+ try {
560
+ await Promise.all([
561
+ processingMutex.mutex(async () => {
562
+ const status = (0, Utils_1.getStatusFromReceiptType)(attrs.type);
563
+ if (typeof status !== 'undefined' &&
564
+ (
565
+ // basically, we only want to know when a message from us has been delivered to/read by the other person
566
+ // or another device of ours has read some messages
567
+ status > WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK ||
568
+ !isNodeFromMe)) {
569
+ if ((0, WABinary_1.isJidGroup)(remoteJid) || (0, WABinary_1.isJidStatusBroadcast)(remoteJid)) {
570
+ if (attrs.participant) {
571
+ const updateKey = status === WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK ? 'receiptTimestamp' : 'readTimestamp';
572
+ ev.emit('message-receipt.update', ids.map(id => ({
573
+ key: { ...key, id },
574
+ receipt: {
575
+ userJid: (0, WABinary_1.jidNormalizedUser)(attrs.participant),
576
+ [updateKey]: +attrs.t
577
+ }
578
+ })));
579
+ }
580
+ }
581
+ else {
582
+ ev.emit('messages.update', ids.map(id => ({
583
+ key: { ...key, id },
584
+ update: { status }
585
+ })));
586
+ }
587
+ }
588
+ if (attrs.type === 'retry') {
589
+ // correctly set who is asking for the retry
590
+ key.participant = key.participant || attrs.from;
591
+ const retryNode = (0, WABinary_1.getBinaryNodeChild)(node, 'retry');
592
+ if (willSendMessageAgain(ids[0], key.participant)) {
593
+ if (key.fromMe) {
594
+ try {
595
+ logger.debug({ attrs, key }, 'recv retry request');
596
+ await sendMessagesAgain(key, ids, retryNode);
597
+ }
598
+ catch (error) {
599
+ logger.error({ key, ids, trace: error.stack }, 'error in sending message again');
600
+ }
601
+ }
602
+ else {
603
+ logger.info({ attrs, key }, 'recv retry for not fromMe message');
604
+ }
605
+ }
606
+ else {
607
+ logger.info({ attrs, key }, 'will not send message again, as sent too many times');
608
+ }
609
+ }
610
+ })
611
+ ]);
612
+ }
613
+ finally {
614
+ await sendMessageAck(node);
615
+ }
616
+ };
617
+ const handleNotification = async (node) => {
618
+ const remoteJid = node.attrs.from;
619
+ if (shouldIgnoreJid(remoteJid) && remoteJid !== '@s.whatsapp.net') {
620
+ logger.debug({ remoteJid, id: node.attrs.id }, 'ignored notification');
621
+ await sendMessageAck(node);
622
+ return;
623
+ }
624
+ try {
625
+ await Promise.all([
626
+ processingMutex.mutex(async () => {
627
+ var _a;
628
+ const msg = await processNotification(node);
629
+ if (msg) {
630
+ const fromMe = (0, WABinary_1.areJidsSameUser)(node.attrs.participant || remoteJid, authState.creds.me.id);
631
+ msg.key = {
632
+ remoteJid,
633
+ fromMe,
634
+ participant: node.attrs.participant,
635
+ id: node.attrs.id,
636
+ ...(msg.key || {})
637
+ };
638
+ (_a = msg.participant) !== null && _a !== void 0 ? _a : (msg.participant = node.attrs.participant);
639
+ msg.messageTimestamp = +node.attrs.t;
640
+ const fullMsg = WAProto_1.proto.WebMessageInfo.fromObject(msg);
641
+ await upsertMessage(fullMsg, 'append');
642
+ }
643
+ })
644
+ ]);
645
+ }
646
+ finally {
647
+ await sendMessageAck(node);
648
+ }
649
+ };
650
+ const handleMessage = async (node) => {
651
+ var _a, _b, _c;
652
+ if (shouldIgnoreJid(node.attrs.from) && node.attrs.from !== '@s.whatsapp.net') {
653
+ logger.debug({ key: node.attrs.key }, 'ignored message');
654
+ await sendMessageAck(node);
655
+ return;
656
+ }
657
+ let response;
658
+ if ((0, WABinary_1.getBinaryNodeChild)(node, 'unavailable') && !(0, WABinary_1.getBinaryNodeChild)(node, 'enc')) {
659
+ await sendMessageAck(node);
660
+ const { key } = (0, Utils_1.decodeMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '').fullMessage;
661
+ response = await requestPlaceholderResend(key);
662
+ if (response === 'RESOLVED') {
663
+ return;
664
+ }
665
+ logger.debug('received unavailable message, acked and requested resend from phone');
666
+ }
667
+ else {
668
+ if (placeholderResendCache.get(node.attrs.id)) {
669
+ placeholderResendCache.del(node.attrs.id);
670
+ }
671
+ }
672
+ const { fullMessage: msg, category, author, decrypt } = (0, Utils_1.decryptMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, logger);
673
+ 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) {
674
+ msg.messageStubParameters = [Utils_1.NO_MESSAGE_FOUND_ERROR_TEXT, response];
675
+ }
676
+ 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 && node.attrs.sender_pn) {
677
+ ev.emit('chats.phoneNumberShare', { lid: node.attrs.from, jid: node.attrs.sender_pn });
678
+ }
679
+ try {
680
+ await Promise.all([
681
+ processingMutex.mutex(async () => {
682
+ await decrypt();
683
+ // message failed to decrypt
684
+ if (msg.messageStubType === WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT) {
685
+ retryMutex.mutex(async () => {
686
+ if (ws.isOpen) {
687
+ if ((0, WABinary_1.getBinaryNodeChild)(node, 'unavailable')) {
688
+ return;
689
+ }
690
+ const encNode = (0, WABinary_1.getBinaryNodeChild)(node, 'enc');
691
+ await sendRetryRequest(node, !encNode);
692
+ if (retryRequestDelayMs) {
693
+ await (0, Utils_1.delay)(retryRequestDelayMs);
694
+ }
695
+ }
696
+ else {
697
+ logger.debug({ node }, 'connection closed, ignoring retry req');
698
+ }
699
+ });
700
+ }
701
+ else {
702
+ // no type in the receipt => message delivered
703
+ let type = undefined;
704
+ let participant = msg.key.participant;
705
+ if (category === 'peer') { // special peer message
706
+ type = 'peer_msg';
707
+ }
708
+ else if (msg.key.fromMe) { // message was sent by us from a different device
709
+ type = 'sender';
710
+ // need to specially handle this case
711
+ if ((0, WABinary_1.isJidUser)(msg.key.remoteJid)) {
712
+ participant = author;
713
+ }
714
+ }
715
+ else if (!sendActiveReceipts) {
716
+ type = 'inactive';
717
+ }
718
+ await sendReceipt(msg.key.remoteJid, participant, [msg.key.id], type);
719
+ // send ack for history message
720
+ const isAnyHistoryMsg = (0, Utils_1.getHistoryMsg)(msg.message);
721
+ if (isAnyHistoryMsg) {
722
+ const jid = (0, WABinary_1.jidNormalizedUser)(msg.key.remoteJid);
723
+ await sendReceipt(jid, undefined, [msg.key.id], 'hist_sync');
724
+ }
725
+ }
726
+ (0, Utils_2.cleanMessage)(msg, authState.creds.me.id);
727
+ await upsertMessage(msg, node.attrs.offline ? 'append' : 'notify');
728
+ })
729
+ ]);
730
+ }
731
+ finally {
732
+ await sendMessageAck(node);
733
+ }
734
+ };
735
+ const fetchMessageHistory = async (count, oldestMsgKey, oldestMsgTimestamp) => {
736
+ var _a;
737
+ if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
738
+ throw new boom_1.Boom('Not authenticated');
739
+ }
740
+ const pdoMessage = {
741
+ historySyncOnDemandRequest: {
742
+ chatJid: oldestMsgKey.remoteJid,
743
+ oldestMsgFromMe: oldestMsgKey.fromMe,
744
+ oldestMsgId: oldestMsgKey.id,
745
+ oldestMsgTimestampMs: oldestMsgTimestamp,
746
+ onDemandMsgCount: count
747
+ },
748
+ peerDataOperationRequestType: WAProto_1.proto.Message.PeerDataOperationRequestType.HISTORY_SYNC_ON_DEMAND
749
+ };
750
+ return sendPeerDataOperationMessage(pdoMessage);
751
+ };
752
+ const requestPlaceholderResend = async (messageKey) => {
753
+ var _a;
754
+ if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
755
+ throw new boom_1.Boom('Not authenticated');
756
+ }
757
+ if (placeholderResendCache.get(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id)) {
758
+ logger.debug('already requested resend', { messageKey });
759
+ return;
760
+ }
761
+ else {
762
+ placeholderResendCache.set(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id, true);
763
+ }
764
+ await (0, Utils_1.delay)(5000);
765
+ if (!placeholderResendCache.get(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id)) {
766
+ logger.debug('message received while resend requested', { messageKey });
767
+ return 'RESOLVED';
768
+ }
769
+ const pdoMessage = {
770
+ placeholderMessageResendRequest: [{
771
+ messageKey
772
+ }],
773
+ peerDataOperationRequestType: WAProto_1.proto.Message.PeerDataOperationRequestType.PLACEHOLDER_MESSAGE_RESEND
774
+ };
775
+ setTimeout(() => {
776
+ if (placeholderResendCache.get(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id)) {
777
+ logger.debug('PDO message without response after 15 seconds. Phone possibly offline', { messageKey });
778
+ placeholderResendCache.del(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id);
779
+ }
780
+ }, 15000);
781
+ return sendPeerDataOperationMessage(pdoMessage);
782
+ };
783
+ const handleCall = async (node) => {
784
+ const { attrs } = node;
785
+ const [infoChild] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
786
+ const callId = infoChild.attrs['call-id'];
787
+ const from = infoChild.attrs.from || infoChild.attrs['call-creator'];
788
+ const status = (0, Utils_1.getCallStatusFromNode)(infoChild);
789
+ const call = {
790
+ chatId: attrs.from,
791
+ from,
792
+ id: callId,
793
+ date: new Date(+attrs.t * 1000),
794
+ offline: !!attrs.offline,
795
+ status,
796
+ };
797
+ if (status === 'offer') {
798
+ call.isVideo = !!(0, WABinary_1.getBinaryNodeChild)(infoChild, 'video');
799
+ call.isGroup = infoChild.attrs.type === 'group' || !!infoChild.attrs['group-jid'];
800
+ call.groupJid = infoChild.attrs['group-jid'];
801
+ callOfferCache.set(call.id, call);
802
+ }
803
+ const existingCall = callOfferCache.get(call.id);
804
+ // use existing call info to populate this event
805
+ if (existingCall) {
806
+ call.isVideo = existingCall.isVideo;
807
+ call.isGroup = existingCall.isGroup;
808
+ }
809
+ // delete data once call has ended
810
+ if (status === 'reject' || status === 'accept' || status === 'timeout' || status === 'terminate') {
811
+ callOfferCache.del(call.id);
812
+ }
813
+ ev.emit('call', [call]);
814
+ await sendMessageAck(node);
815
+ };
816
+ const handleBadAck = async ({ attrs }) => {
817
+ // const key: WAMessageKey = { remoteJid: attrs.from, fromMe: true, id: attrs.id }
818
+ const key = { remoteJid: attrs.from, fromMe: true, id: attrs.id, server_id: attrs === null || attrs === void 0 ? void 0 : attrs.server_id };
819
+ // current hypothesis is that if pash is sent in the ack
820
+ // it means -- the message hasn't reached all devices yet
821
+ // we'll retry sending the message here
822
+ if (attrs.phash) {
823
+ logger.info({ attrs }, 'received phash in ack, resending message...');
824
+ const msg = await getMessage(key);
825
+ if (msg) {
826
+ await relayMessage(key.remoteJid, msg, { messageId: key.id, useUserDevicesCache: false });
827
+ }
828
+ else {
829
+ logger.warn({ attrs }, 'could not send message again, as it was not found');
830
+ }
831
+ }
832
+ // error in acknowledgement,
833
+ // device could not display the message
834
+ if (attrs.error) {
835
+ logger.warn({ attrs }, 'received error in ack');
836
+ ev.emit('messages.update', [
837
+ {
838
+ key,
839
+ update: {
840
+ status: Types_1.WAMessageStatus.ERROR,
841
+ messageStubParameters: [
842
+ attrs.error
843
+ ]
844
+ }
845
+ }
846
+ ]);
847
+ }
848
+ };
849
+ /// processes a node with the given function
850
+ /// and adds the task to the existing buffer if we're buffering events
851
+ const processNodeWithBuffer = async (node, identifier, exec) => {
852
+ ev.buffer();
853
+ await execTask();
854
+ ev.flush();
855
+ function execTask() {
856
+ return exec(node)
857
+ .catch(err => onUnexpectedError(err, identifier));
858
+ }
859
+ };
860
+ // recv a message
861
+ ws.on('CB:message', (node) => {
862
+ processNodeWithBuffer(node, 'processing message', handleMessage);
863
+ });
864
+ ws.on('CB:call', async (node) => {
865
+ processNodeWithBuffer(node, 'handling call', handleCall);
866
+ });
867
+ ws.on('CB:receipt', node => {
868
+ processNodeWithBuffer(node, 'handling receipt', handleReceipt);
869
+ });
870
+ ws.on('CB:notification', async (node) => {
871
+ processNodeWithBuffer(node, 'handling notification', handleNotification);
872
+ });
873
+ ws.on('CB:ack,class:message', (node) => {
874
+ handleBadAck(node)
875
+ .catch(error => onUnexpectedError(error, 'handling bad ack'));
876
+ });
877
+ ev.on('call', ([call]) => {
878
+ // missed call + group call notification message generation
879
+ if (call.status === 'timeout' || (call.status === 'offer' && call.isGroup)) {
880
+ const msg = {
881
+ key: {
882
+ remoteJid: call.chatId,
883
+ id: call.id,
884
+ fromMe: false
885
+ },
886
+ messageTimestamp: (0, Utils_1.unixTimestampSeconds)(call.date),
887
+ };
888
+ if (call.status === 'timeout') {
889
+ if (call.isGroup) {
890
+ msg.messageStubType = call.isVideo ? Types_1.WAMessageStubType.CALL_MISSED_GROUP_VIDEO : Types_1.WAMessageStubType.CALL_MISSED_GROUP_VOICE;
891
+ }
892
+ else {
893
+ msg.messageStubType = call.isVideo ? Types_1.WAMessageStubType.CALL_MISSED_VIDEO : Types_1.WAMessageStubType.CALL_MISSED_VOICE;
894
+ }
895
+ }
896
+ else {
897
+ msg.message = { call: { callKey: Buffer.from(call.id) } };
898
+ }
899
+ const protoMsg = WAProto_1.proto.WebMessageInfo.fromObject(msg);
900
+ upsertMessage(protoMsg, call.offline ? 'append' : 'notify');
901
+ }
902
+ });
903
+ ev.on('connection.update', ({ isOnline }) => {
904
+ if (typeof isOnline !== 'undefined') {
905
+ sendActiveReceipts = isOnline;
906
+ logger.trace(`sendActiveReceipts set to "${sendActiveReceipts}"`);
907
+ }
908
+ });
909
+ return {
910
+ ...sock,
911
+ sendMessageAck,
912
+ sendRetryRequest,
913
+ rejectCall,
914
+ fetchMessageHistory,
915
+ requestPlaceholderResend,
916
+ };
917
+ };
918
+ exports.makeMessagesRecvSocket = makeMessagesRecvSocket;