@neelegirl/baileys 1.5.4 → 1.5.5

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 (374) hide show
  1. package/README.md +10 -189
  2. package/index.js +38 -0
  3. package/package.json +11 -94
  4. package/LICENSE +0 -21
  5. package/WAProto/GenerateStatics.sh +0 -3
  6. package/WAProto/WAProto.proto +0 -4633
  7. package/WAProto/fix-imports.js +0 -29
  8. package/WAProto/index.d.ts +0 -11969
  9. package/WAProto/index.js +0 -84368
  10. package/engine-requirements.js +0 -10
  11. package/lib/Defaults/index.d.ts +0 -62
  12. package/lib/Defaults/index.d.ts.map +0 -1
  13. package/lib/Defaults/index.js +0 -115
  14. package/lib/Defaults/index.js.map +0 -1
  15. package/lib/Signal/Group/ciphertext-message.d.ts +0 -10
  16. package/lib/Signal/Group/ciphertext-message.d.ts.map +0 -1
  17. package/lib/Signal/Group/ciphertext-message.js +0 -12
  18. package/lib/Signal/Group/ciphertext-message.js.map +0 -1
  19. package/lib/Signal/Group/group-session-builder.d.ts +0 -15
  20. package/lib/Signal/Group/group-session-builder.d.ts.map +0 -1
  21. package/lib/Signal/Group/group-session-builder.js +0 -30
  22. package/lib/Signal/Group/group-session-builder.js.map +0 -1
  23. package/lib/Signal/Group/group_cipher.d.ts +0 -17
  24. package/lib/Signal/Group/group_cipher.d.ts.map +0 -1
  25. package/lib/Signal/Group/group_cipher.js +0 -82
  26. package/lib/Signal/Group/group_cipher.js.map +0 -1
  27. package/lib/Signal/Group/index.d.ts +0 -12
  28. package/lib/Signal/Group/index.d.ts.map +0 -1
  29. package/lib/Signal/Group/index.js +0 -12
  30. package/lib/Signal/Group/index.js.map +0 -1
  31. package/lib/Signal/Group/keyhelper.d.ts +0 -11
  32. package/lib/Signal/Group/keyhelper.d.ts.map +0 -1
  33. package/lib/Signal/Group/keyhelper.js +0 -18
  34. package/lib/Signal/Group/keyhelper.js.map +0 -1
  35. package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
  36. package/lib/Signal/Group/sender-chain-key.d.ts.map +0 -1
  37. package/lib/Signal/Group/sender-chain-key.js +0 -26
  38. package/lib/Signal/Group/sender-chain-key.js.map +0 -1
  39. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
  40. package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +0 -1
  41. package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
  42. package/lib/Signal/Group/sender-key-distribution-message.js.map +0 -1
  43. package/lib/Signal/Group/sender-key-message.d.ts +0 -19
  44. package/lib/Signal/Group/sender-key-message.d.ts.map +0 -1
  45. package/lib/Signal/Group/sender-key-message.js +0 -66
  46. package/lib/Signal/Group/sender-key-message.js.map +0 -1
  47. package/lib/Signal/Group/sender-key-name.d.ts +0 -18
  48. package/lib/Signal/Group/sender-key-name.d.ts.map +0 -1
  49. package/lib/Signal/Group/sender-key-name.js +0 -48
  50. package/lib/Signal/Group/sender-key-name.js.map +0 -1
  51. package/lib/Signal/Group/sender-key-record.d.ts +0 -31
  52. package/lib/Signal/Group/sender-key-record.d.ts.map +0 -1
  53. package/lib/Signal/Group/sender-key-record.js +0 -41
  54. package/lib/Signal/Group/sender-key-record.js.map +0 -1
  55. package/lib/Signal/Group/sender-key-state.d.ts +0 -39
  56. package/lib/Signal/Group/sender-key-state.d.ts.map +0 -1
  57. package/lib/Signal/Group/sender-key-state.js +0 -84
  58. package/lib/Signal/Group/sender-key-state.js.map +0 -1
  59. package/lib/Signal/Group/sender-message-key.d.ts +0 -12
  60. package/lib/Signal/Group/sender-message-key.d.ts.map +0 -1
  61. package/lib/Signal/Group/sender-message-key.js +0 -26
  62. package/lib/Signal/Group/sender-message-key.js.map +0 -1
  63. package/lib/Signal/libsignal.d.ts +0 -5
  64. package/lib/Signal/libsignal.d.ts.map +0 -1
  65. package/lib/Signal/libsignal.js +0 -342
  66. package/lib/Signal/libsignal.js.map +0 -1
  67. package/lib/Signal/lid-mapping.d.ts +0 -23
  68. package/lib/Signal/lid-mapping.d.ts.map +0 -1
  69. package/lib/Signal/lid-mapping.js +0 -171
  70. package/lib/Signal/lid-mapping.js.map +0 -1
  71. package/lib/Socket/Client/index.d.ts +0 -3
  72. package/lib/Socket/Client/index.d.ts.map +0 -1
  73. package/lib/Socket/Client/index.js +0 -3
  74. package/lib/Socket/Client/index.js.map +0 -1
  75. package/lib/Socket/Client/types.d.ts +0 -16
  76. package/lib/Socket/Client/types.d.ts.map +0 -1
  77. package/lib/Socket/Client/types.js +0 -11
  78. package/lib/Socket/Client/types.js.map +0 -1
  79. package/lib/Socket/Client/websocket.d.ts +0 -13
  80. package/lib/Socket/Client/websocket.d.ts.map +0 -1
  81. package/lib/Socket/Client/websocket.js +0 -50
  82. package/lib/Socket/Client/websocket.js.map +0 -1
  83. package/lib/Socket/business.d.ts +0 -188
  84. package/lib/Socket/business.d.ts.map +0 -1
  85. package/lib/Socket/business.js +0 -376
  86. package/lib/Socket/business.js.map +0 -1
  87. package/lib/Socket/chats.d.ts +0 -98
  88. package/lib/Socket/chats.d.ts.map +0 -1
  89. package/lib/Socket/chats.js +0 -962
  90. package/lib/Socket/chats.js.map +0 -1
  91. package/lib/Socket/communities.d.ts +0 -244
  92. package/lib/Socket/communities.d.ts.map +0 -1
  93. package/lib/Socket/communities.js +0 -431
  94. package/lib/Socket/communities.js.map +0 -1
  95. package/lib/Socket/groups.d.ts +0 -137
  96. package/lib/Socket/groups.d.ts.map +0 -1
  97. package/lib/Socket/groups.js +0 -327
  98. package/lib/Socket/groups.js.map +0 -1
  99. package/lib/Socket/index.d.ts +0 -231
  100. package/lib/Socket/index.d.ts.map +0 -1
  101. package/lib/Socket/index.js +0 -18
  102. package/lib/Socket/index.js.map +0 -1
  103. package/lib/Socket/messages-recv.d.ts +0 -173
  104. package/lib/Socket/messages-recv.d.ts.map +0 -1
  105. package/lib/Socket/messages-recv.js +0 -1228
  106. package/lib/Socket/messages-recv.js.map +0 -1
  107. package/lib/Socket/messages-send.d.ts +0 -169
  108. package/lib/Socket/messages-send.d.ts.map +0 -1
  109. package/lib/Socket/messages-send.js +0 -953
  110. package/lib/Socket/messages-send.js.map +0 -1
  111. package/lib/Socket/mex.d.ts +0 -3
  112. package/lib/Socket/mex.d.ts.map +0 -1
  113. package/lib/Socket/mex.js +0 -42
  114. package/lib/Socket/mex.js.map +0 -1
  115. package/lib/Socket/newsletter.d.ts +0 -147
  116. package/lib/Socket/newsletter.d.ts.map +0 -1
  117. package/lib/Socket/newsletter.js +0 -181
  118. package/lib/Socket/newsletter.js.map +0 -1
  119. package/lib/Socket/socket.d.ts +0 -51
  120. package/lib/Socket/socket.d.ts.map +0 -1
  121. package/lib/Socket/socket.js +0 -864
  122. package/lib/Socket/socket.js.map +0 -1
  123. package/lib/Types/Auth.d.ts +0 -111
  124. package/lib/Types/Auth.d.ts.map +0 -1
  125. package/lib/Types/Auth.js +0 -2
  126. package/lib/Types/Auth.js.map +0 -1
  127. package/lib/Types/Bussines.d.ts +0 -25
  128. package/lib/Types/Bussines.d.ts.map +0 -1
  129. package/lib/Types/Bussines.js +0 -2
  130. package/lib/Types/Bussines.js.map +0 -1
  131. package/lib/Types/Call.d.ts +0 -14
  132. package/lib/Types/Call.d.ts.map +0 -1
  133. package/lib/Types/Call.js +0 -2
  134. package/lib/Types/Call.js.map +0 -1
  135. package/lib/Types/Chat.d.ts +0 -123
  136. package/lib/Types/Chat.d.ts.map +0 -1
  137. package/lib/Types/Chat.js +0 -8
  138. package/lib/Types/Chat.js.map +0 -1
  139. package/lib/Types/Contact.d.ts +0 -24
  140. package/lib/Types/Contact.d.ts.map +0 -1
  141. package/lib/Types/Contact.js +0 -2
  142. package/lib/Types/Contact.js.map +0 -1
  143. package/lib/Types/Events.d.ts +0 -202
  144. package/lib/Types/Events.d.ts.map +0 -1
  145. package/lib/Types/Events.js +0 -2
  146. package/lib/Types/Events.js.map +0 -1
  147. package/lib/Types/GroupMetadata.d.ts +0 -67
  148. package/lib/Types/GroupMetadata.d.ts.map +0 -1
  149. package/lib/Types/GroupMetadata.js +0 -2
  150. package/lib/Types/GroupMetadata.js.map +0 -1
  151. package/lib/Types/Label.d.ts +0 -47
  152. package/lib/Types/Label.d.ts.map +0 -1
  153. package/lib/Types/Label.js +0 -25
  154. package/lib/Types/Label.js.map +0 -1
  155. package/lib/Types/LabelAssociation.d.ts +0 -30
  156. package/lib/Types/LabelAssociation.d.ts.map +0 -1
  157. package/lib/Types/LabelAssociation.js +0 -7
  158. package/lib/Types/LabelAssociation.js.map +0 -1
  159. package/lib/Types/Message.d.ts +0 -303
  160. package/lib/Types/Message.d.ts.map +0 -1
  161. package/lib/Types/Message.js +0 -11
  162. package/lib/Types/Message.js.map +0 -1
  163. package/lib/Types/Newsletter.d.ts +0 -135
  164. package/lib/Types/Newsletter.d.ts.map +0 -1
  165. package/lib/Types/Newsletter.js +0 -31
  166. package/lib/Types/Newsletter.js.map +0 -1
  167. package/lib/Types/Product.d.ts +0 -79
  168. package/lib/Types/Product.d.ts.map +0 -1
  169. package/lib/Types/Product.js +0 -2
  170. package/lib/Types/Product.js.map +0 -1
  171. package/lib/Types/Signal.d.ts +0 -76
  172. package/lib/Types/Signal.d.ts.map +0 -1
  173. package/lib/Types/Signal.js +0 -2
  174. package/lib/Types/Signal.js.map +0 -1
  175. package/lib/Types/Socket.d.ts +0 -133
  176. package/lib/Types/Socket.d.ts.map +0 -1
  177. package/lib/Types/Socket.js +0 -3
  178. package/lib/Types/Socket.js.map +0 -1
  179. package/lib/Types/State.d.ts +0 -39
  180. package/lib/Types/State.d.ts.map +0 -1
  181. package/lib/Types/State.js +0 -13
  182. package/lib/Types/State.js.map +0 -1
  183. package/lib/Types/USync.d.ts +0 -26
  184. package/lib/Types/USync.d.ts.map +0 -1
  185. package/lib/Types/USync.js +0 -2
  186. package/lib/Types/USync.js.map +0 -1
  187. package/lib/Types/index.d.ts +0 -65
  188. package/lib/Types/index.d.ts.map +0 -1
  189. package/lib/Types/index.js +0 -26
  190. package/lib/Types/index.js.map +0 -1
  191. package/lib/Utils/auth-utils.d.ts +0 -19
  192. package/lib/Utils/auth-utils.d.ts.map +0 -1
  193. package/lib/Utils/auth-utils.js +0 -257
  194. package/lib/Utils/auth-utils.js.map +0 -1
  195. package/lib/Utils/baileys-event-stream.d.ts +0 -17
  196. package/lib/Utils/baileys-event-stream.d.ts.map +0 -1
  197. package/lib/Utils/baileys-event-stream.js +0 -56
  198. package/lib/Utils/baileys-event-stream.js.map +0 -1
  199. package/lib/Utils/browser-utils.d.ts +0 -4
  200. package/lib/Utils/browser-utils.d.ts.map +0 -1
  201. package/lib/Utils/browser-utils.js +0 -28
  202. package/lib/Utils/browser-utils.js.map +0 -1
  203. package/lib/Utils/business.d.ts +0 -23
  204. package/lib/Utils/business.d.ts.map +0 -1
  205. package/lib/Utils/business.js +0 -231
  206. package/lib/Utils/business.js.map +0 -1
  207. package/lib/Utils/chat-utils.d.ts +0 -70
  208. package/lib/Utils/chat-utils.d.ts.map +0 -1
  209. package/lib/Utils/chat-utils.js +0 -763
  210. package/lib/Utils/chat-utils.js.map +0 -1
  211. package/lib/Utils/crypto.d.ts +0 -41
  212. package/lib/Utils/crypto.d.ts.map +0 -1
  213. package/lib/Utils/crypto.js +0 -142
  214. package/lib/Utils/crypto.js.map +0 -1
  215. package/lib/Utils/decode-wa-message.d.ts +0 -48
  216. package/lib/Utils/decode-wa-message.d.ts.map +0 -1
  217. package/lib/Utils/decode-wa-message.js +0 -279
  218. package/lib/Utils/decode-wa-message.js.map +0 -1
  219. package/lib/Utils/event-buffer.d.ts +0 -34
  220. package/lib/Utils/event-buffer.d.ts.map +0 -1
  221. package/lib/Utils/event-buffer.js +0 -548
  222. package/lib/Utils/event-buffer.js.map +0 -1
  223. package/lib/Utils/generics.d.ts +0 -90
  224. package/lib/Utils/generics.d.ts.map +0 -1
  225. package/lib/Utils/generics.js +0 -381
  226. package/lib/Utils/generics.js.map +0 -1
  227. package/lib/Utils/history.d.ts +0 -19
  228. package/lib/Utils/history.d.ts.map +0 -1
  229. package/lib/Utils/history.js +0 -84
  230. package/lib/Utils/history.js.map +0 -1
  231. package/lib/Utils/index.d.ts +0 -20
  232. package/lib/Utils/index.d.ts.map +0 -1
  233. package/lib/Utils/index.js +0 -19
  234. package/lib/Utils/index.js.map +0 -1
  235. package/lib/Utils/link-preview.d.ts +0 -21
  236. package/lib/Utils/link-preview.d.ts.map +0 -1
  237. package/lib/Utils/link-preview.js +0 -85
  238. package/lib/Utils/link-preview.js.map +0 -1
  239. package/lib/Utils/logger.d.ts +0 -12
  240. package/lib/Utils/logger.d.ts.map +0 -1
  241. package/lib/Utils/logger.js +0 -3
  242. package/lib/Utils/logger.js.map +0 -1
  243. package/lib/Utils/lt-hash.d.ts +0 -13
  244. package/lib/Utils/lt-hash.d.ts.map +0 -1
  245. package/lib/Utils/lt-hash.js +0 -48
  246. package/lib/Utils/lt-hash.js.map +0 -1
  247. package/lib/Utils/make-mutex.d.ts +0 -8
  248. package/lib/Utils/make-mutex.d.ts.map +0 -1
  249. package/lib/Utils/make-mutex.js +0 -40
  250. package/lib/Utils/make-mutex.js.map +0 -1
  251. package/lib/Utils/message-retry-manager.d.ts +0 -82
  252. package/lib/Utils/message-retry-manager.d.ts.map +0 -1
  253. package/lib/Utils/message-retry-manager.js +0 -149
  254. package/lib/Utils/message-retry-manager.js.map +0 -1
  255. package/lib/Utils/messages-media.d.ts +0 -114
  256. package/lib/Utils/messages-media.d.ts.map +0 -1
  257. package/lib/Utils/messages-media.js +0 -663
  258. package/lib/Utils/messages-media.js.map +0 -1
  259. package/lib/Utils/messages.d.ts +0 -76
  260. package/lib/Utils/messages.d.ts.map +0 -1
  261. package/lib/Utils/messages.js +0 -820
  262. package/lib/Utils/messages.js.map +0 -1
  263. package/lib/Utils/noise-handler.d.ts +0 -20
  264. package/lib/Utils/noise-handler.d.ts.map +0 -1
  265. package/lib/Utils/noise-handler.js +0 -147
  266. package/lib/Utils/noise-handler.js.map +0 -1
  267. package/lib/Utils/pre-key-manager.d.ts +0 -28
  268. package/lib/Utils/pre-key-manager.d.ts.map +0 -1
  269. package/lib/Utils/pre-key-manager.js +0 -106
  270. package/lib/Utils/pre-key-manager.js.map +0 -1
  271. package/lib/Utils/process-message.d.ts +0 -42
  272. package/lib/Utils/process-message.d.ts.map +0 -1
  273. package/lib/Utils/process-message.js +0 -413
  274. package/lib/Utils/process-message.js.map +0 -1
  275. package/lib/Utils/signal.d.ts +0 -34
  276. package/lib/Utils/signal.d.ts.map +0 -1
  277. package/lib/Utils/signal.js +0 -159
  278. package/lib/Utils/signal.js.map +0 -1
  279. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  280. package/lib/Utils/use-multi-file-auth-state.d.ts.map +0 -1
  281. package/lib/Utils/use-multi-file-auth-state.js +0 -121
  282. package/lib/Utils/use-multi-file-auth-state.js.map +0 -1
  283. package/lib/Utils/validate-connection.d.ts +0 -11
  284. package/lib/Utils/validate-connection.d.ts.map +0 -1
  285. package/lib/Utils/validate-connection.js +0 -195
  286. package/lib/Utils/validate-connection.js.map +0 -1
  287. package/lib/WABinary/constants.d.ts +0 -28
  288. package/lib/WABinary/constants.d.ts.map +0 -1
  289. package/lib/WABinary/constants.js +0 -1301
  290. package/lib/WABinary/constants.js.map +0 -1
  291. package/lib/WABinary/decode.d.ts +0 -7
  292. package/lib/WABinary/decode.d.ts.map +0 -1
  293. package/lib/WABinary/decode.js +0 -238
  294. package/lib/WABinary/decode.js.map +0 -1
  295. package/lib/WABinary/encode.d.ts +0 -3
  296. package/lib/WABinary/encode.d.ts.map +0 -1
  297. package/lib/WABinary/encode.js +0 -216
  298. package/lib/WABinary/encode.js.map +0 -1
  299. package/lib/WABinary/generic-utils.d.ts +0 -15
  300. package/lib/WABinary/generic-utils.d.ts.map +0 -1
  301. package/lib/WABinary/generic-utils.js +0 -102
  302. package/lib/WABinary/generic-utils.js.map +0 -1
  303. package/lib/WABinary/index.d.ts +0 -6
  304. package/lib/WABinary/index.d.ts.map +0 -1
  305. package/lib/WABinary/index.js +0 -6
  306. package/lib/WABinary/index.js.map +0 -1
  307. package/lib/WABinary/jid-utils.d.ts +0 -48
  308. package/lib/WABinary/jid-utils.d.ts.map +0 -1
  309. package/lib/WABinary/jid-utils.js +0 -96
  310. package/lib/WABinary/jid-utils.js.map +0 -1
  311. package/lib/WABinary/types.d.ts +0 -19
  312. package/lib/WABinary/types.d.ts.map +0 -1
  313. package/lib/WABinary/types.js +0 -2
  314. package/lib/WABinary/types.js.map +0 -1
  315. package/lib/WAM/BinaryInfo.d.ts +0 -9
  316. package/lib/WAM/BinaryInfo.d.ts.map +0 -1
  317. package/lib/WAM/BinaryInfo.js +0 -10
  318. package/lib/WAM/BinaryInfo.js.map +0 -1
  319. package/lib/WAM/constants.d.ts +0 -40
  320. package/lib/WAM/constants.d.ts.map +0 -1
  321. package/lib/WAM/constants.js +0 -22853
  322. package/lib/WAM/constants.js.map +0 -1
  323. package/lib/WAM/encode.d.ts +0 -3
  324. package/lib/WAM/encode.d.ts.map +0 -1
  325. package/lib/WAM/encode.js +0 -150
  326. package/lib/WAM/encode.js.map +0 -1
  327. package/lib/WAM/index.d.ts +0 -4
  328. package/lib/WAM/index.d.ts.map +0 -1
  329. package/lib/WAM/index.js +0 -4
  330. package/lib/WAM/index.js.map +0 -1
  331. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
  332. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +0 -1
  333. package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -29
  334. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +0 -1
  335. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -23
  336. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +0 -1
  337. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -54
  338. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +0 -1
  339. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -13
  340. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +0 -1
  341. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -27
  342. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +0 -1
  343. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -13
  344. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +0 -1
  345. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -38
  346. package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +0 -1
  347. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -26
  348. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +0 -1
  349. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -51
  350. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +0 -1
  351. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -10
  352. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +0 -1
  353. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -29
  354. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +0 -1
  355. package/lib/WAUSync/Protocols/index.d.ts +0 -5
  356. package/lib/WAUSync/Protocols/index.d.ts.map +0 -1
  357. package/lib/WAUSync/Protocols/index.js +0 -5
  358. package/lib/WAUSync/Protocols/index.js.map +0 -1
  359. package/lib/WAUSync/USyncQuery.d.ts +0 -29
  360. package/lib/WAUSync/USyncQuery.d.ts.map +0 -1
  361. package/lib/WAUSync/USyncQuery.js +0 -94
  362. package/lib/WAUSync/USyncQuery.js.map +0 -1
  363. package/lib/WAUSync/USyncUser.d.ts +0 -13
  364. package/lib/WAUSync/USyncUser.d.ts.map +0 -1
  365. package/lib/WAUSync/USyncUser.js +0 -23
  366. package/lib/WAUSync/USyncUser.js.map +0 -1
  367. package/lib/WAUSync/index.d.ts +0 -4
  368. package/lib/WAUSync/index.d.ts.map +0 -1
  369. package/lib/WAUSync/index.js +0 -4
  370. package/lib/WAUSync/index.js.map +0 -1
  371. package/lib/index.d.ts +0 -12
  372. package/lib/index.d.ts.map +0 -1
  373. package/lib/index.js +0 -11
  374. package/lib/index.js.map +0 -1
@@ -1,953 +0,0 @@
1
- import NodeCache from '@cacheable/node-cache';
2
- import { Boom } from '@hapi/boom';
3
- import { proto } from '../../WAProto/index.js';
4
- import { DEFAULT_CACHE_TTLS, WA_DEFAULT_EPHEMERAL } from '../Defaults/index.js';
5
- import { aggregateMessageKeysNotFromMe, assertMediaContent, bindWaitForEvent, decryptMediaRetryData, encodeNewsletterMessage, encodeSignedDeviceIdentity, encodeWAMessage, encryptMediaRetryRequest, extractDeviceJids, generateMessageIDV2, generateParticipantHashV2, generateWAMessage, getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, MessageRetryManager, normalizeMessageContent, parseAndInjectE2ESessions, unixTimestampSeconds } from '../Utils/index.js';
6
- import { getUrlInfo } from '../Utils/link-preview.js';
7
- import { makeKeyedMutex } from '../Utils/make-mutex.js';
8
- import { areJidsSameUser, getBinaryNodeChild, getBinaryNodeChildren, isHostedLidUser, isHostedPnUser, isJidGroup, isLidUser, isPnUser, jidDecode, jidEncode, jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary/index.js';
9
- import { USyncQuery, USyncUser } from '../WAUSync/index.js';
10
- import { makeNewsletterSocket } from './newsletter.js';
11
- export const makeMessagesSocket = (config) => {
12
- const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: httpRequestOptions, patchMessageBeforeSending, cachedGroupMetadata, enableRecentMessageCache, maxMsgRetryCount } = config;
13
- const sock = makeNewsletterSocket(config);
14
- const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, sendNode, groupMetadata, groupToggleEphemeral } = sock;
15
- const userDevicesCache = config.userDevicesCache ||
16
- new NodeCache({
17
- stdTTL: DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
18
- useClones: false
19
- });
20
- const peerSessionsCache = new NodeCache({
21
- stdTTL: DEFAULT_CACHE_TTLS.USER_DEVICES,
22
- useClones: false
23
- });
24
- // Initialize message retry manager if enabled
25
- const messageRetryManager = enableRecentMessageCache ? new MessageRetryManager(logger, maxMsgRetryCount) : null;
26
- // Prevent race conditions in Signal session encryption by user
27
- const encryptionMutex = makeKeyedMutex();
28
- let mediaConn;
29
- const refreshMediaConn = async (forceGet = false) => {
30
- const media = await mediaConn;
31
- if (!media || forceGet || new Date().getTime() - media.fetchDate.getTime() > media.ttl * 1000) {
32
- mediaConn = (async () => {
33
- const result = await query({
34
- tag: 'iq',
35
- attrs: {
36
- type: 'set',
37
- xmlns: 'w:m',
38
- to: S_WHATSAPP_NET
39
- },
40
- content: [{ tag: 'media_conn', attrs: {} }]
41
- });
42
- const mediaConnNode = getBinaryNodeChild(result, 'media_conn');
43
- // TODO: explore full length of data that whatsapp provides
44
- const node = {
45
- hosts: getBinaryNodeChildren(mediaConnNode, 'host').map(({ attrs }) => ({
46
- hostname: attrs.hostname,
47
- maxContentLengthBytes: +attrs.maxContentLengthBytes
48
- })),
49
- auth: mediaConnNode.attrs.auth,
50
- ttl: +mediaConnNode.attrs.ttl,
51
- fetchDate: new Date()
52
- };
53
- logger.debug('fetched media conn');
54
- return node;
55
- })();
56
- }
57
- return mediaConn;
58
- };
59
- /**
60
- * generic send receipt function
61
- * used for receipts of phone call, read, delivery etc.
62
- * */
63
- const sendReceipt = async (jid, participant, messageIds, type) => {
64
- if (!messageIds || messageIds.length === 0) {
65
- throw new Boom('missing ids in receipt');
66
- }
67
- const node = {
68
- tag: 'receipt',
69
- attrs: {
70
- id: messageIds[0]
71
- }
72
- };
73
- const isReadReceipt = type === 'read' || type === 'read-self';
74
- if (isReadReceipt) {
75
- node.attrs.t = unixTimestampSeconds().toString();
76
- }
77
- if (type === 'sender' && (isPnUser(jid) || isLidUser(jid))) {
78
- node.attrs.recipient = jid;
79
- node.attrs.to = participant;
80
- }
81
- else {
82
- node.attrs.to = jid;
83
- if (participant) {
84
- node.attrs.participant = participant;
85
- }
86
- }
87
- if (type) {
88
- node.attrs.type = type;
89
- }
90
- const remainingMessageIds = messageIds.slice(1);
91
- if (remainingMessageIds.length) {
92
- node.content = [
93
- {
94
- tag: 'list',
95
- attrs: {},
96
- content: remainingMessageIds.map(id => ({
97
- tag: 'item',
98
- attrs: { id }
99
- }))
100
- }
101
- ];
102
- }
103
- logger.debug({ attrs: node.attrs, messageIds }, 'sending receipt for messages');
104
- await sendNode(node);
105
- };
106
- /** Correctly bulk send receipts to multiple chats, participants */
107
- const sendReceipts = async (keys, type) => {
108
- const recps = aggregateMessageKeysNotFromMe(keys);
109
- for (const { jid, participant, messageIds } of recps) {
110
- await sendReceipt(jid, participant, messageIds, type);
111
- }
112
- };
113
- /** Bulk read messages. Keys can be from different chats & participants */
114
- const readMessages = async (keys) => {
115
- const privacySettings = await fetchPrivacySettings();
116
- // based on privacy settings, we have to change the read type
117
- const readType = privacySettings.readreceipts === 'all' ? 'read' : 'read-self';
118
- await sendReceipts(keys, readType);
119
- };
120
- /** Fetch all the devices we've to send a message to */
121
- const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
122
- const deviceResults = [];
123
- if (!useCache) {
124
- logger.debug('not using cache for devices');
125
- }
126
- const toFetch = [];
127
- const jidsWithUser = jids
128
- .map(jid => {
129
- const decoded = jidDecode(jid);
130
- const user = decoded?.user;
131
- const device = decoded?.device;
132
- const isExplicitDevice = typeof device === 'number' && device >= 0;
133
- if (isExplicitDevice && user) {
134
- deviceResults.push({
135
- user,
136
- device,
137
- jid
138
- });
139
- return null;
140
- }
141
- jid = jidNormalizedUser(jid);
142
- return { jid, user };
143
- })
144
- .filter(jid => jid !== null);
145
- let mgetDevices;
146
- if (useCache && userDevicesCache.mget) {
147
- const usersToFetch = jidsWithUser.map(j => j?.user).filter(Boolean);
148
- mgetDevices = await userDevicesCache.mget(usersToFetch);
149
- }
150
- for (const { jid, user } of jidsWithUser) {
151
- if (useCache) {
152
- const devices = mgetDevices?.[user] ||
153
- (userDevicesCache.mget ? undefined : (await userDevicesCache.get(user)));
154
- if (devices) {
155
- const devicesWithJid = devices.map(d => ({
156
- ...d,
157
- jid: jidEncode(d.user, d.server, d.device)
158
- }));
159
- deviceResults.push(...devicesWithJid);
160
- logger.trace({ user }, 'using cache for devices');
161
- }
162
- else {
163
- toFetch.push(jid);
164
- }
165
- }
166
- else {
167
- toFetch.push(jid);
168
- }
169
- }
170
- if (!toFetch.length) {
171
- return deviceResults;
172
- }
173
- const requestedLidUsers = new Set();
174
- for (const jid of toFetch) {
175
- if (isLidUser(jid) || isHostedLidUser(jid)) {
176
- const user = jidDecode(jid)?.user;
177
- if (user)
178
- requestedLidUsers.add(user);
179
- }
180
- }
181
- const query = new USyncQuery().withContext('message').withDeviceProtocol().withLIDProtocol();
182
- for (const jid of toFetch) {
183
- query.withUser(new USyncUser().withId(jid)); // todo: investigate - the idea here is that <user> should have an inline lid field with the lid being the pn equivalent
184
- }
185
- const result = await sock.executeUSyncQuery(query);
186
- if (result) {
187
- // TODO: LID MAP this stuff (lid protocol will now return lid with devices)
188
- const lidResults = result.list.filter(a => !!a.lid);
189
- if (lidResults.length > 0) {
190
- logger.trace('Storing LID maps from device call');
191
- await signalRepository.lidMapping.storeLIDPNMappings(lidResults.map(a => ({ lid: a.lid, pn: a.id })));
192
- }
193
- const extracted = extractDeviceJids(result?.list, authState.creds.me.id, authState.creds.me.lid, ignoreZeroDevices);
194
- const deviceMap = {};
195
- for (const item of extracted) {
196
- deviceMap[item.user] = deviceMap[item.user] || [];
197
- deviceMap[item.user]?.push(item);
198
- }
199
- // Process each user's devices as a group for bulk LID migration
200
- for (const [user, userDevices] of Object.entries(deviceMap)) {
201
- const isLidUser = requestedLidUsers.has(user);
202
- // Process all devices for this user
203
- for (const item of userDevices) {
204
- const finalJid = isLidUser
205
- ? jidEncode(user, item.server, item.device)
206
- : jidEncode(item.user, item.server, item.device);
207
- deviceResults.push({
208
- ...item,
209
- jid: finalJid
210
- });
211
- logger.debug({
212
- user: item.user,
213
- device: item.device,
214
- finalJid,
215
- usedLid: isLidUser
216
- }, 'Processed device with LID priority');
217
- }
218
- }
219
- if (userDevicesCache.mset) {
220
- // if the cache supports mset, we can set all devices in one go
221
- await userDevicesCache.mset(Object.entries(deviceMap).map(([key, value]) => ({ key, value })));
222
- }
223
- else {
224
- for (const key in deviceMap) {
225
- if (deviceMap[key])
226
- await userDevicesCache.set(key, deviceMap[key]);
227
- }
228
- }
229
- const userDeviceUpdates = {};
230
- for (const [userId, devices] of Object.entries(deviceMap)) {
231
- if (devices && devices.length > 0) {
232
- userDeviceUpdates[userId] = devices.map(d => d.device?.toString() || '0');
233
- }
234
- }
235
- if (Object.keys(userDeviceUpdates).length > 0) {
236
- try {
237
- await authState.keys.set({ 'device-list': userDeviceUpdates });
238
- logger.debug({ userCount: Object.keys(userDeviceUpdates).length }, 'stored user device lists for bulk migration');
239
- }
240
- catch (error) {
241
- logger.warn({ error }, 'failed to store user device lists');
242
- }
243
- }
244
- }
245
- return deviceResults;
246
- };
247
- const assertSessions = async (jids) => {
248
- let didFetchNewSession = false;
249
- const uniqueJids = [...new Set(jids)]; // Deduplicate JIDs
250
- const jidsRequiringFetch = [];
251
- logger.debug({ jids }, 'assertSessions call with jids');
252
- // Check peerSessionsCache and validate sessions using libsignal loadSession
253
- for (const jid of uniqueJids) {
254
- const signalId = signalRepository.jidToSignalProtocolAddress(jid);
255
- const cachedSession = peerSessionsCache.get(signalId);
256
- if (cachedSession !== undefined) {
257
- if (cachedSession) {
258
- continue; // Session exists in cache
259
- }
260
- }
261
- else {
262
- const sessionValidation = await signalRepository.validateSession(jid);
263
- const hasSession = sessionValidation.exists;
264
- peerSessionsCache.set(signalId, hasSession);
265
- if (hasSession) {
266
- continue;
267
- }
268
- }
269
- jidsRequiringFetch.push(jid);
270
- }
271
- if (jidsRequiringFetch.length) {
272
- // LID if mapped, otherwise original
273
- const wireJids = [
274
- ...jidsRequiringFetch.filter(jid => !!isLidUser(jid) || !!isHostedLidUser(jid)),
275
- ...((await signalRepository.lidMapping.getLIDsForPNs(jidsRequiringFetch.filter(jid => !!isPnUser(jid) || !!isHostedPnUser(jid)))) || []).map(a => a.lid)
276
- ];
277
- logger.debug({ jidsRequiringFetch, wireJids }, 'fetching sessions');
278
- const result = await query({
279
- tag: 'iq',
280
- attrs: {
281
- xmlns: 'encrypt',
282
- type: 'get',
283
- to: S_WHATSAPP_NET
284
- },
285
- content: [
286
- {
287
- tag: 'key',
288
- attrs: {},
289
- content: wireJids.map(jid => ({
290
- tag: 'user',
291
- attrs: { jid }
292
- }))
293
- }
294
- ]
295
- });
296
- await parseAndInjectE2ESessions(result, signalRepository);
297
- didFetchNewSession = true;
298
- // Cache fetched sessions using wire JIDs
299
- for (const wireJid of wireJids) {
300
- const signalId = signalRepository.jidToSignalProtocolAddress(wireJid);
301
- peerSessionsCache.set(signalId, true);
302
- }
303
- }
304
- return didFetchNewSession;
305
- };
306
- const sendPeerDataOperationMessage = async (pdoMessage) => {
307
- //TODO: for later, abstract the logic to send a Peer Message instead of just PDO - useful for App State Key Resync with phone
308
- if (!authState.creds.me?.id) {
309
- throw new Boom('Not authenticated');
310
- }
311
- const protocolMessage = {
312
- protocolMessage: {
313
- peerDataOperationRequestMessage: pdoMessage,
314
- type: proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
315
- }
316
- };
317
- const meJid = jidNormalizedUser(authState.creds.me.id);
318
- const msgId = await relayMessage(meJid, protocolMessage, {
319
- additionalAttributes: {
320
- category: 'peer',
321
- push_priority: 'high_force'
322
- },
323
- additionalNodes: [
324
- {
325
- tag: 'meta',
326
- attrs: { appdata: 'default' }
327
- }
328
- ]
329
- });
330
- return msgId;
331
- };
332
- const createParticipantNodes = async (recipientJids, message, extraAttrs, dsmMessage) => {
333
- if (!recipientJids.length) {
334
- return { nodes: [], shouldIncludeDeviceIdentity: false };
335
- }
336
- const patched = await patchMessageBeforeSending(message, recipientJids);
337
- const patchedMessages = Array.isArray(patched)
338
- ? patched
339
- : recipientJids.map(jid => ({ recipientJid: jid, message: patched }));
340
- let shouldIncludeDeviceIdentity = false;
341
- const meId = authState.creds.me.id;
342
- const meLid = authState.creds.me?.lid;
343
- const meLidUser = meLid ? jidDecode(meLid)?.user : null;
344
- const encryptionPromises = patchedMessages.map(async ({ recipientJid: jid, message: patchedMessage }) => {
345
- if (!jid)
346
- return null;
347
- let msgToEncrypt = patchedMessage;
348
- if (dsmMessage) {
349
- const { user: targetUser } = jidDecode(jid);
350
- const { user: ownPnUser } = jidDecode(meId);
351
- const ownLidUser = meLidUser;
352
- const isOwnUser = targetUser === ownPnUser || (ownLidUser && targetUser === ownLidUser);
353
- const isExactSenderDevice = jid === meId || (meLid && jid === meLid);
354
- if (isOwnUser && !isExactSenderDevice) {
355
- msgToEncrypt = dsmMessage;
356
- logger.debug({ jid, targetUser }, 'Using DSM for own device');
357
- }
358
- }
359
- const bytes = encodeWAMessage(msgToEncrypt);
360
- const mutexKey = jid;
361
- const node = await encryptionMutex.mutex(mutexKey, async () => {
362
- const { type, ciphertext } = await signalRepository.encryptMessage({
363
- jid,
364
- data: bytes
365
- });
366
- if (type === 'pkmsg') {
367
- shouldIncludeDeviceIdentity = true;
368
- }
369
- return {
370
- tag: 'to',
371
- attrs: { jid },
372
- content: [
373
- {
374
- tag: 'enc',
375
- attrs: {
376
- v: '2',
377
- type,
378
- ...(extraAttrs || {})
379
- },
380
- content: ciphertext
381
- }
382
- ]
383
- };
384
- });
385
- return node;
386
- });
387
- const nodes = (await Promise.all(encryptionPromises)).filter(node => node !== null);
388
- return { nodes, shouldIncludeDeviceIdentity };
389
- };
390
- const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }) => {
391
- const meId = authState.creds.me.id;
392
- const meLid = authState.creds.me?.lid;
393
- const isRetryResend = Boolean(participant?.jid);
394
- let shouldIncludeDeviceIdentity = isRetryResend;
395
- const statusJid = 'status@broadcast';
396
- const { user, server } = jidDecode(jid);
397
- const isGroup = server === 'g.us';
398
- const isStatus = jid === statusJid;
399
- const isLid = server === 'lid';
400
- const isNewsletter = server === 'newsletter';
401
- const finalJid = jid;
402
- msgId = msgId || generateMessageIDV2(meId);
403
- useUserDevicesCache = useUserDevicesCache !== false;
404
- useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus;
405
- const participants = [];
406
- const destinationJid = !isStatus ? finalJid : statusJid;
407
- const binaryNodeContent = [];
408
- const devices = [];
409
- const meMsg = {
410
- deviceSentMessage: {
411
- destinationJid,
412
- message
413
- },
414
- messageContextInfo: message.messageContextInfo
415
- };
416
- const extraAttrs = {};
417
- if (participant) {
418
- if (!isGroup && !isStatus) {
419
- additionalAttributes = { ...additionalAttributes, device_fanout: 'false' };
420
- }
421
- const { user, device } = jidDecode(participant.jid);
422
- devices.push({
423
- user,
424
- device,
425
- jid: participant.jid
426
- });
427
- }
428
- await authState.keys.transaction(async () => {
429
- const mediaType = getMediaType(message);
430
- if (mediaType) {
431
- extraAttrs['mediatype'] = mediaType;
432
- }
433
- if (isNewsletter) {
434
- const patched = patchMessageBeforeSending ? await patchMessageBeforeSending(message, []) : message;
435
- const bytes = encodeNewsletterMessage(patched);
436
- binaryNodeContent.push({
437
- tag: 'plaintext',
438
- attrs: {},
439
- content: bytes
440
- });
441
- const stanza = {
442
- tag: 'message',
443
- attrs: {
444
- to: jid,
445
- id: msgId,
446
- type: getMessageType(message),
447
- ...(additionalAttributes || {})
448
- },
449
- content: binaryNodeContent
450
- };
451
- logger.debug({ msgId }, `sending newsletter message to ${jid}`);
452
- await sendNode(stanza);
453
- return;
454
- }
455
- if (normalizeMessageContent(message)?.pinInChatMessage) {
456
- extraAttrs['decrypt-fail'] = 'hide'; // todo: expand for reactions and other types
457
- }
458
- if (isGroup || isStatus) {
459
- const [groupData, senderKeyMap] = await Promise.all([
460
- (async () => {
461
- let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined; // todo: should we rely on the cache specially if the cache is outdated and the metadata has new fields?
462
- if (groupData && Array.isArray(groupData?.participants)) {
463
- logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
464
- }
465
- else if (!isStatus) {
466
- groupData = await groupMetadata(jid); // TODO: start storing group participant list + addr mode in Signal & stop relying on this
467
- }
468
- return groupData;
469
- })(),
470
- (async () => {
471
- if (!participant && !isStatus) {
472
- // what if sender memory is less accurate than the cached metadata
473
- // on participant change in group, we should do sender memory manipulation
474
- const result = await authState.keys.get('sender-key-memory', [jid]); // TODO: check out what if the sender key memory doesn't include the LID stuff now?
475
- return result[jid] || {};
476
- }
477
- return {};
478
- })()
479
- ]);
480
- if (!participant) {
481
- const participantsList = [];
482
- if (isStatus) {
483
- if (statusJidList?.length)
484
- participantsList.push(...statusJidList);
485
- }
486
- else {
487
- // default to LID based groups
488
- let groupAddressingMode = 'lid';
489
- if (groupData) {
490
- participantsList.push(...groupData.participants.map(p => p.id));
491
- groupAddressingMode = groupData?.addressingMode || groupAddressingMode;
492
- }
493
- // default to lid addressing mode in a group
494
- additionalAttributes = {
495
- ...additionalAttributes,
496
- addressing_mode: groupAddressingMode
497
- };
498
- }
499
- const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false);
500
- devices.push(...additionalDevices);
501
- }
502
- if (groupData?.ephemeralDuration && groupData.ephemeralDuration > 0) {
503
- additionalAttributes = {
504
- ...additionalAttributes,
505
- expiration: groupData.ephemeralDuration.toString()
506
- };
507
- }
508
- const patched = await patchMessageBeforeSending(message);
509
- if (Array.isArray(patched)) {
510
- throw new Boom('Per-jid patching is not supported in groups');
511
- }
512
- const bytes = encodeWAMessage(patched);
513
- const groupAddressingMode = additionalAttributes?.['addressing_mode'] || groupData?.addressingMode || 'lid';
514
- const groupSenderIdentity = groupAddressingMode === 'lid' && meLid ? meLid : meId;
515
- const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
516
- group: destinationJid,
517
- data: bytes,
518
- meId: groupSenderIdentity
519
- });
520
- const senderKeyRecipients = [];
521
- for (const device of devices) {
522
- const deviceJid = device.jid;
523
- const hasKey = !!senderKeyMap[deviceJid];
524
- if ((!hasKey || !!participant) &&
525
- !isHostedLidUser(deviceJid) &&
526
- !isHostedPnUser(deviceJid) &&
527
- device.device !== 99) {
528
- //todo: revamp all this logic
529
- // the goal is to follow with what I said above for each group, and instead of a true false map of ids, we can set an array full of those the app has already sent pkmsgs
530
- senderKeyRecipients.push(deviceJid);
531
- senderKeyMap[deviceJid] = true;
532
- }
533
- }
534
- if (senderKeyRecipients.length) {
535
- logger.debug({ senderKeyJids: senderKeyRecipients }, 'sending new sender key');
536
- const senderKeyMsg = {
537
- senderKeyDistributionMessage: {
538
- axolotlSenderKeyDistributionMessage: senderKeyDistributionMessage,
539
- groupId: destinationJid
540
- }
541
- };
542
- const senderKeySessionTargets = senderKeyRecipients;
543
- await assertSessions(senderKeySessionTargets);
544
- const result = await createParticipantNodes(senderKeyRecipients, senderKeyMsg, extraAttrs);
545
- shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity;
546
- participants.push(...result.nodes);
547
- }
548
- if (isRetryResend) {
549
- const { type, ciphertext: encryptedContent } = await signalRepository.encryptMessage({
550
- data: bytes,
551
- jid: participant?.jid
552
- });
553
- binaryNodeContent.push({
554
- tag: 'enc',
555
- attrs: {
556
- v: '2',
557
- type,
558
- count: participant.count.toString()
559
- },
560
- content: encryptedContent
561
- });
562
- }
563
- else {
564
- binaryNodeContent.push({
565
- tag: 'enc',
566
- attrs: { v: '2', type: 'skmsg', ...extraAttrs },
567
- content: ciphertext
568
- });
569
- await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
570
- }
571
- }
572
- else {
573
- // ADDRESSING CONSISTENCY: Match own identity to conversation context
574
- // TODO: investigate if this is true
575
- let ownId = meId;
576
- if (isLid && meLid) {
577
- ownId = meLid;
578
- logger.debug({ to: jid, ownId }, 'Using LID identity for @lid conversation');
579
- }
580
- else {
581
- logger.debug({ to: jid, ownId }, 'Using PN identity for @s.whatsapp.net conversation');
582
- }
583
- const { user: ownUser } = jidDecode(ownId);
584
- if (!participant) {
585
- const targetUserServer = isLid ? 'lid' : 's.whatsapp.net';
586
- devices.push({
587
- user,
588
- device: 0,
589
- jid: jidEncode(user, targetUserServer, 0) // rajeh, todo: this entire logic is convoluted and weird.
590
- });
591
- if (user !== ownUser) {
592
- const ownUserServer = isLid ? 'lid' : 's.whatsapp.net';
593
- const ownUserForAddressing = isLid && meLid ? jidDecode(meLid).user : jidDecode(meId).user;
594
- devices.push({
595
- user: ownUserForAddressing,
596
- device: 0,
597
- jid: jidEncode(ownUserForAddressing, ownUserServer, 0)
598
- });
599
- }
600
- if (additionalAttributes?.['category'] !== 'peer') {
601
- // Clear placeholders and enumerate actual devices
602
- devices.length = 0;
603
- // Use conversation-appropriate sender identity
604
- const senderIdentity = isLid && meLid
605
- ? jidEncode(jidDecode(meLid)?.user, 'lid', undefined)
606
- : jidEncode(jidDecode(meId)?.user, 's.whatsapp.net', undefined);
607
- // Enumerate devices for sender and target with consistent addressing
608
- const sessionDevices = await getUSyncDevices([senderIdentity, jid], true, false);
609
- devices.push(...sessionDevices);
610
- logger.debug({
611
- deviceCount: devices.length,
612
- devices: devices.map(d => `${d.user}:${d.device}@${jidDecode(d.jid)?.server}`)
613
- }, 'Device enumeration complete with unified addressing');
614
- }
615
- }
616
- const allRecipients = [];
617
- const meRecipients = [];
618
- const otherRecipients = [];
619
- const { user: mePnUser } = jidDecode(meId);
620
- const { user: meLidUser } = meLid ? jidDecode(meLid) : { user: null };
621
- for (const { user, jid } of devices) {
622
- const isExactSenderDevice = jid === meId || (meLid && jid === meLid);
623
- if (isExactSenderDevice) {
624
- logger.debug({ jid, meId, meLid }, 'Skipping exact sender device (whatsmeow pattern)');
625
- continue;
626
- }
627
- // Check if this is our device (could match either PN or LID user)
628
- const isMe = user === mePnUser || user === meLidUser;
629
- if (isMe) {
630
- meRecipients.push(jid);
631
- }
632
- else {
633
- otherRecipients.push(jid);
634
- }
635
- allRecipients.push(jid);
636
- }
637
- await assertSessions(allRecipients);
638
- const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
639
- // For own devices: use DSM if available (1:1 chats only)
640
- createParticipantNodes(meRecipients, meMsg || message, extraAttrs),
641
- createParticipantNodes(otherRecipients, message, extraAttrs, meMsg)
642
- ]);
643
- participants.push(...meNodes);
644
- participants.push(...otherNodes);
645
- if (meRecipients.length > 0 || otherRecipients.length > 0) {
646
- extraAttrs['phash'] = generateParticipantHashV2([...meRecipients, ...otherRecipients]);
647
- }
648
- shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
649
- }
650
- if (participants.length) {
651
- if (additionalAttributes?.['category'] === 'peer') {
652
- const peerNode = participants[0]?.content?.[0];
653
- if (peerNode) {
654
- binaryNodeContent.push(peerNode); // push only enc
655
- }
656
- }
657
- else {
658
- binaryNodeContent.push({
659
- tag: 'participants',
660
- attrs: {},
661
- content: participants
662
- });
663
- }
664
- }
665
- const stanza = {
666
- tag: 'message',
667
- attrs: {
668
- id: msgId,
669
- to: destinationJid,
670
- type: getMessageType(message),
671
- ...(additionalAttributes || {})
672
- },
673
- content: binaryNodeContent
674
- };
675
- // if the participant to send to is explicitly specified (generally retry recp)
676
- // ensure the message is only sent to that person
677
- // if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
678
- if (participant) {
679
- if (isJidGroup(destinationJid)) {
680
- stanza.attrs.to = destinationJid;
681
- stanza.attrs.participant = participant.jid;
682
- }
683
- else if (areJidsSameUser(participant.jid, meId)) {
684
- stanza.attrs.to = participant.jid;
685
- stanza.attrs.recipient = destinationJid;
686
- }
687
- else {
688
- stanza.attrs.to = participant.jid;
689
- }
690
- }
691
- else {
692
- stanza.attrs.to = destinationJid;
693
- }
694
- if (shouldIncludeDeviceIdentity) {
695
- ;
696
- stanza.content.push({
697
- tag: 'device-identity',
698
- attrs: {},
699
- content: encodeSignedDeviceIdentity(authState.creds.account, true)
700
- });
701
- logger.debug({ jid }, 'adding device identity');
702
- }
703
- if (additionalNodes && additionalNodes.length > 0) {
704
- ;
705
- stanza.content.push(...additionalNodes);
706
- }
707
- logger.debug({ msgId }, `sending message to ${participants.length} devices`);
708
- await sendNode(stanza);
709
- // Add message to retry cache if enabled
710
- if (messageRetryManager && !participant) {
711
- messageRetryManager.addRecentMessage(destinationJid, msgId, message);
712
- }
713
- }, meId);
714
- return msgId;
715
- };
716
- const getMessageType = (message) => {
717
- if (message.pollCreationMessage || message.pollCreationMessageV2 || message.pollCreationMessageV3) {
718
- return 'poll';
719
- }
720
- if (message.eventMessage) {
721
- return 'event';
722
- }
723
- if (getMediaType(message) !== '') {
724
- return 'media';
725
- }
726
- return 'text';
727
- };
728
- const getMediaType = (message) => {
729
- if (message.imageMessage) {
730
- return 'image';
731
- }
732
- else if (message.videoMessage) {
733
- return message.videoMessage.gifPlayback ? 'gif' : 'video';
734
- }
735
- else if (message.audioMessage) {
736
- return message.audioMessage.ptt ? 'ptt' : 'audio';
737
- }
738
- else if (message.contactMessage) {
739
- return 'vcard';
740
- }
741
- else if (message.documentMessage) {
742
- return 'document';
743
- }
744
- else if (message.contactsArrayMessage) {
745
- return 'contact_array';
746
- }
747
- else if (message.liveLocationMessage) {
748
- return 'livelocation';
749
- }
750
- else if (message.stickerMessage) {
751
- return 'sticker';
752
- }
753
- else if (message.listMessage) {
754
- return 'list';
755
- }
756
- else if (message.listResponseMessage) {
757
- return 'list_response';
758
- }
759
- else if (message.buttonsResponseMessage) {
760
- return 'buttons_response';
761
- }
762
- else if (message.orderMessage) {
763
- return 'order';
764
- }
765
- else if (message.productMessage) {
766
- return 'product';
767
- }
768
- else if (message.interactiveResponseMessage) {
769
- return 'native_flow_response';
770
- }
771
- else if (message.groupInviteMessage) {
772
- return 'url';
773
- }
774
- return '';
775
- };
776
- const getPrivacyTokens = async (jids) => {
777
- const t = unixTimestampSeconds().toString();
778
- const result = await query({
779
- tag: 'iq',
780
- attrs: {
781
- to: S_WHATSAPP_NET,
782
- type: 'set',
783
- xmlns: 'privacy'
784
- },
785
- content: [
786
- {
787
- tag: 'tokens',
788
- attrs: {},
789
- content: jids.map(jid => ({
790
- tag: 'token',
791
- attrs: {
792
- jid: jidNormalizedUser(jid),
793
- t,
794
- type: 'trusted_contact'
795
- }
796
- }))
797
- }
798
- ]
799
- });
800
- return result;
801
- };
802
- const waUploadToServer = getWAUploadToServer(config, refreshMediaConn);
803
- const waitForMsgMediaUpdate = bindWaitForEvent(ev, 'messages.media-update');
804
- return {
805
- ...sock,
806
- getPrivacyTokens,
807
- assertSessions,
808
- relayMessage,
809
- sendReceipt,
810
- sendReceipts,
811
- readMessages,
812
- refreshMediaConn,
813
- waUploadToServer,
814
- fetchPrivacySettings,
815
- sendPeerDataOperationMessage,
816
- createParticipantNodes,
817
- getUSyncDevices,
818
- messageRetryManager,
819
- updateMediaMessage: async (message) => {
820
- const content = assertMediaContent(message.message);
821
- const mediaKey = content.mediaKey;
822
- const meId = authState.creds.me.id;
823
- const node = await encryptMediaRetryRequest(message.key, mediaKey, meId);
824
- let error = undefined;
825
- await Promise.all([
826
- sendNode(node),
827
- waitForMsgMediaUpdate(async (update) => {
828
- const result = update.find(c => c.key.id === message.key.id);
829
- if (result) {
830
- if (result.error) {
831
- error = result.error;
832
- }
833
- else {
834
- try {
835
- const media = await decryptMediaRetryData(result.media, mediaKey, result.key.id);
836
- if (media.result !== proto.MediaRetryNotification.ResultType.SUCCESS) {
837
- const resultStr = proto.MediaRetryNotification.ResultType[media.result];
838
- throw new Boom(`Media re-upload failed by device (${resultStr})`, {
839
- data: media,
840
- statusCode: getStatusCodeForMediaRetry(media.result) || 404
841
- });
842
- }
843
- content.directPath = media.directPath;
844
- content.url = getUrlFromDirectPath(content.directPath);
845
- logger.debug({ directPath: media.directPath, key: result.key }, 'media update successful');
846
- }
847
- catch (err) {
848
- error = err;
849
- }
850
- }
851
- return true;
852
- }
853
- })
854
- ]);
855
- if (error) {
856
- throw error;
857
- }
858
- ev.emit('messages.update', [{ key: message.key, update: { message: message.message } }]);
859
- return message;
860
- },
861
- sendMessage: async (jid, content, options = {}) => {
862
- const userJid = authState.creds.me.id;
863
- if (typeof content === 'object' &&
864
- 'disappearingMessagesInChat' in content &&
865
- typeof content['disappearingMessagesInChat'] !== 'undefined' &&
866
- isJidGroup(jid)) {
867
- const { disappearingMessagesInChat } = content;
868
- const value = typeof disappearingMessagesInChat === 'boolean'
869
- ? disappearingMessagesInChat
870
- ? WA_DEFAULT_EPHEMERAL
871
- : 0
872
- : disappearingMessagesInChat;
873
- await groupToggleEphemeral(jid, value);
874
- }
875
- else {
876
- const fullMsg = await generateWAMessage(jid, content, {
877
- logger,
878
- userJid,
879
- getUrlInfo: text => getUrlInfo(text, {
880
- thumbnailWidth: linkPreviewImageThumbnailWidth,
881
- fetchOpts: {
882
- timeout: 3000,
883
- ...(httpRequestOptions || {})
884
- },
885
- logger,
886
- uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
887
- }),
888
- //TODO: CACHE
889
- getProfilePicUrl: sock.profilePictureUrl,
890
- getCallLink: sock.createCallLink,
891
- upload: waUploadToServer,
892
- mediaCache: config.mediaCache,
893
- options: config.options,
894
- messageId: generateMessageIDV2(sock.user?.id),
895
- ...options
896
- });
897
- const isEventMsg = 'event' in content && !!content.event;
898
- const isDeleteMsg = 'delete' in content && !!content.delete;
899
- const isEditMsg = 'edit' in content && !!content.edit;
900
- const isPinMsg = 'pin' in content && !!content.pin;
901
- const isPollMessage = 'poll' in content && !!content.poll;
902
- const additionalAttributes = {};
903
- const additionalNodes = [];
904
- // required for delete
905
- if (isDeleteMsg) {
906
- // if the chat is a group, and I am not the author, then delete the message as an admin
907
- if (isJidGroup(content.delete?.remoteJid) && !content.delete?.fromMe) {
908
- additionalAttributes.edit = '8';
909
- }
910
- else {
911
- additionalAttributes.edit = '7';
912
- }
913
- }
914
- else if (isEditMsg) {
915
- additionalAttributes.edit = '1';
916
- }
917
- else if (isPinMsg) {
918
- additionalAttributes.edit = '2';
919
- }
920
- else if (isPollMessage) {
921
- additionalNodes.push({
922
- tag: 'meta',
923
- attrs: {
924
- polltype: 'creation'
925
- }
926
- });
927
- }
928
- else if (isEventMsg) {
929
- additionalNodes.push({
930
- tag: 'meta',
931
- attrs: {
932
- event_type: 'creation'
933
- }
934
- });
935
- }
936
- await relayMessage(jid, fullMsg.message, {
937
- messageId: fullMsg.key.id,
938
- useCachedGroupMetadata: options.useCachedGroupMetadata,
939
- additionalAttributes,
940
- statusJidList: options.statusJidList,
941
- additionalNodes
942
- });
943
- if (config.emitOwnEvents) {
944
- process.nextTick(() => {
945
- processingMutex.mutex(() => upsertMessage(fullMsg, 'append'));
946
- });
947
- }
948
- return fullMsg;
949
- }
950
- }
951
- };
952
- };
953
- //# sourceMappingURL=messages-send.js.map