violetics 7.0.6-alpha → 7.0.8-alpha

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 (407) hide show
  1. package/LICENSE +1 -2
  2. package/README.md +456 -978
  3. package/WAProto/GenerateStatics.sh +3 -0
  4. package/WAProto/WAProto.proto +5479 -0
  5. package/WAProto/fix-imports.js +81 -0
  6. package/WAProto/index.d.ts +14017 -0
  7. package/WAProto/index.js +2728 -7894
  8. package/engine-requirements.js +7 -10
  9. package/index.cjs +196 -0
  10. package/index.d.ts +30 -0
  11. package/lib/Defaults/index.d.ts +74 -0
  12. package/lib/Defaults/index.d.ts.map +1 -0
  13. package/lib/Defaults/index.js +16 -25
  14. package/lib/Defaults/index.js.map +1 -0
  15. package/lib/Defaults/phonenumber-mcc.json +223 -0
  16. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  17. package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
  18. package/lib/Signal/Group/ciphertext-message.js +2 -1
  19. package/lib/Signal/Group/ciphertext-message.js.map +1 -0
  20. package/lib/Signal/Group/group-session-builder.d.ts +15 -0
  21. package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
  22. package/lib/Signal/Group/group-session-builder.js +2 -1
  23. package/lib/Signal/Group/group-session-builder.js.map +1 -0
  24. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  25. package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
  26. package/lib/Signal/Group/group_cipher.js +2 -1
  27. package/lib/Signal/Group/group_cipher.js.map +1 -0
  28. package/lib/Signal/Group/index.d.ts +12 -0
  29. package/lib/Signal/Group/index.d.ts.map +1 -0
  30. package/lib/Signal/Group/index.js +2 -1
  31. package/lib/Signal/Group/index.js.map +1 -0
  32. package/lib/Signal/Group/keyhelper.d.ts +11 -0
  33. package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
  34. package/lib/Signal/Group/keyhelper.js +2 -1
  35. package/lib/Signal/Group/keyhelper.js.map +1 -0
  36. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  37. package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
  38. package/lib/Signal/Group/sender-chain-key.js +2 -1
  39. package/lib/Signal/Group/sender-chain-key.js.map +1 -0
  40. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  41. package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
  42. package/lib/Signal/Group/sender-key-distribution-message.js +2 -1
  43. package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
  44. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  45. package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
  46. package/lib/Signal/Group/sender-key-message.js +2 -1
  47. package/lib/Signal/Group/sender-key-message.js.map +1 -0
  48. package/lib/Signal/Group/sender-key-name.d.ts +18 -0
  49. package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
  50. package/lib/Signal/Group/sender-key-name.js +2 -1
  51. package/lib/Signal/Group/sender-key-name.js.map +1 -0
  52. package/lib/Signal/Group/sender-key-record.d.ts +31 -0
  53. package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
  54. package/lib/Signal/Group/sender-key-record.js +2 -1
  55. package/lib/Signal/Group/sender-key-record.js.map +1 -0
  56. package/lib/Signal/Group/sender-key-state.d.ts +39 -0
  57. package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
  58. package/lib/Signal/Group/sender-key-state.js +2 -1
  59. package/lib/Signal/Group/sender-key-state.js.map +1 -0
  60. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  61. package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
  62. package/lib/Signal/Group/sender-message-key.js +2 -1
  63. package/lib/Signal/Group/sender-message-key.js.map +1 -0
  64. package/lib/Signal/libsignal.d.ts +5 -0
  65. package/lib/Signal/libsignal.d.ts.map +1 -0
  66. package/lib/Signal/libsignal.js +44 -8
  67. package/lib/Signal/libsignal.js.map +1 -0
  68. package/lib/Signal/lid-mapping.d.ts +19 -0
  69. package/lib/Signal/lid-mapping.d.ts.map +1 -0
  70. package/lib/Signal/lid-mapping.js +2 -1
  71. package/lib/Signal/lid-mapping.js.map +1 -0
  72. package/lib/Socket/Client/index.d.ts +3 -0
  73. package/lib/Socket/Client/index.d.ts.map +1 -0
  74. package/lib/Socket/Client/index.js +2 -1
  75. package/lib/Socket/Client/index.js.map +1 -0
  76. package/lib/Socket/Client/types.d.ts +16 -0
  77. package/lib/Socket/Client/types.d.ts.map +1 -0
  78. package/lib/Socket/Client/types.js +2 -1
  79. package/lib/Socket/Client/types.js.map +1 -0
  80. package/lib/Socket/Client/websocket.d.ts +13 -0
  81. package/lib/Socket/Client/websocket.d.ts.map +1 -0
  82. package/lib/Socket/Client/websocket.js +3 -11
  83. package/lib/Socket/Client/websocket.js.map +1 -0
  84. package/lib/Socket/business.d.ts +202 -0
  85. package/lib/Socket/business.d.ts.map +1 -0
  86. package/lib/Socket/business.js +2 -1
  87. package/lib/Socket/business.js.map +1 -0
  88. package/lib/Socket/chats.d.ts +111 -0
  89. package/lib/Socket/chats.d.ts.map +1 -0
  90. package/lib/Socket/chats.js +155 -71
  91. package/lib/Socket/chats.js.map +1 -0
  92. package/lib/Socket/communities.d.ts +258 -0
  93. package/lib/Socket/communities.d.ts.map +1 -0
  94. package/lib/Socket/communities.js +2 -1
  95. package/lib/Socket/communities.js.map +1 -0
  96. package/lib/Socket/community.js +361 -0
  97. package/lib/Socket/groups.d.ts +150 -0
  98. package/lib/Socket/groups.d.ts.map +1 -0
  99. package/lib/Socket/groups.js +140 -9
  100. package/lib/Socket/groups.js.map +1 -0
  101. package/lib/Socket/index.d.ts +245 -0
  102. package/lib/Socket/index.d.ts.map +1 -0
  103. package/lib/Socket/index.js +2 -1
  104. package/lib/Socket/index.js.map +1 -0
  105. package/lib/Socket/messages-recv.d.ts +187 -0
  106. package/lib/Socket/messages-recv.d.ts.map +1 -0
  107. package/lib/Socket/messages-recv.js +481 -204
  108. package/lib/Socket/messages-recv.js.map +1 -0
  109. package/lib/Socket/messages-send.d.ts +183 -0
  110. package/lib/Socket/messages-send.d.ts.map +1 -0
  111. package/lib/Socket/messages-send.js +622 -233
  112. package/lib/Socket/messages-send.js.map +1 -0
  113. package/lib/Socket/mex.d.ts +3 -0
  114. package/lib/Socket/mex.d.ts.map +1 -0
  115. package/lib/Socket/mex.js +2 -1
  116. package/lib/Socket/mex.js.map +1 -0
  117. package/lib/Socket/newsletter.d.ts +160 -0
  118. package/lib/Socket/newsletter.d.ts.map +1 -0
  119. package/lib/Socket/newsletter.js +107 -68
  120. package/lib/Socket/newsletter.js.map +1 -0
  121. package/lib/Socket/socket.d.ts +55 -0
  122. package/lib/Socket/socket.d.ts.map +1 -0
  123. package/lib/Socket/socket.js +25 -26
  124. package/lib/Socket/socket.js.map +1 -0
  125. package/lib/Socket/usync.js +76 -0
  126. package/lib/Store/index.js +2 -1
  127. package/lib/Store/make-cache-manager-store.js +77 -0
  128. package/lib/Store/make-in-memory-store.js +44 -65
  129. package/lib/Store/make-ordered-dictionary.js +1 -1
  130. package/lib/Store/object-repository.js +1 -1
  131. package/lib/Types/Auth.d.ts +116 -0
  132. package/lib/Types/Auth.d.ts.map +1 -0
  133. package/lib/Types/Auth.js +2 -1
  134. package/lib/Types/Auth.js.map +1 -0
  135. package/lib/Types/Bussines.d.ts +25 -0
  136. package/lib/Types/Bussines.d.ts.map +1 -0
  137. package/lib/Types/Bussines.js +2 -1
  138. package/lib/Types/Bussines.js.map +1 -0
  139. package/lib/Types/Call.d.ts +15 -0
  140. package/lib/Types/Call.d.ts.map +1 -0
  141. package/lib/Types/Call.js +2 -1
  142. package/lib/Types/Call.js.map +1 -0
  143. package/lib/Types/Chat.d.ts +123 -0
  144. package/lib/Types/Chat.d.ts.map +1 -0
  145. package/lib/Types/Chat.js +2 -1
  146. package/lib/Types/Chat.js.map +1 -0
  147. package/lib/Types/Contact.d.ts +24 -0
  148. package/lib/Types/Contact.d.ts.map +1 -0
  149. package/lib/Types/Contact.js +2 -1
  150. package/lib/Types/Contact.js.map +1 -0
  151. package/lib/Types/Events.d.ts +237 -0
  152. package/lib/Types/Events.d.ts.map +1 -0
  153. package/lib/Types/Events.js +2 -1
  154. package/lib/Types/Events.js.map +1 -0
  155. package/lib/Types/GroupMetadata.d.ts +67 -0
  156. package/lib/Types/GroupMetadata.d.ts.map +1 -0
  157. package/lib/Types/GroupMetadata.js +2 -1
  158. package/lib/Types/GroupMetadata.js.map +1 -0
  159. package/lib/Types/Label.d.ts +47 -0
  160. package/lib/Types/Label.d.ts.map +1 -0
  161. package/lib/Types/Label.js +2 -1
  162. package/lib/Types/Label.js.map +1 -0
  163. package/lib/Types/LabelAssociation.d.ts +30 -0
  164. package/lib/Types/LabelAssociation.d.ts.map +1 -0
  165. package/lib/Types/LabelAssociation.js +2 -1
  166. package/lib/Types/LabelAssociation.js.map +1 -0
  167. package/lib/Types/Message.d.ts +305 -0
  168. package/lib/Types/Message.d.ts.map +1 -0
  169. package/lib/Types/Message.js +2 -8
  170. package/lib/Types/Message.js.map +1 -0
  171. package/lib/Types/MexUpdates.js +9 -0
  172. package/lib/Types/Newsletter.d.ts +135 -0
  173. package/lib/Types/Newsletter.d.ts.map +1 -0
  174. package/lib/Types/Newsletter.js +14 -4
  175. package/lib/Types/Newsletter.js.map +1 -0
  176. package/lib/Types/Product.d.ts +79 -0
  177. package/lib/Types/Product.d.ts.map +1 -0
  178. package/lib/Types/Product.js +2 -1
  179. package/lib/Types/Product.js.map +1 -0
  180. package/lib/Types/Signal.d.ts +76 -0
  181. package/lib/Types/Signal.d.ts.map +1 -0
  182. package/lib/Types/Signal.js +2 -1
  183. package/lib/Types/Signal.js.map +1 -0
  184. package/lib/Types/Socket.d.ts +133 -0
  185. package/lib/Types/Socket.d.ts.map +1 -0
  186. package/lib/Types/Socket.js +2 -1
  187. package/lib/Types/Socket.js.map +1 -0
  188. package/lib/Types/State.d.ts +39 -0
  189. package/lib/Types/State.d.ts.map +1 -0
  190. package/lib/Types/State.js +2 -1
  191. package/lib/Types/State.js.map +1 -0
  192. package/lib/Types/USync.d.ts +26 -0
  193. package/lib/Types/USync.d.ts.map +1 -0
  194. package/lib/Types/USync.js +2 -1
  195. package/lib/Types/USync.js.map +1 -0
  196. package/lib/Types/index.d.ts +65 -0
  197. package/lib/Types/index.d.ts.map +1 -0
  198. package/lib/Types/index.js +3 -1
  199. package/lib/Types/index.js.map +1 -0
  200. package/lib/Utils/audioToBuffer.js +31 -0
  201. package/lib/Utils/auth-utils.d.ts +19 -0
  202. package/lib/Utils/auth-utils.d.ts.map +1 -0
  203. package/lib/Utils/auth-utils.js +2 -1
  204. package/lib/Utils/auth-utils.js.map +1 -0
  205. package/lib/Utils/baileys-event-stream.js +54 -0
  206. package/lib/Utils/browser-utils.d.ts +4 -0
  207. package/lib/Utils/browser-utils.d.ts.map +1 -0
  208. package/lib/Utils/browser-utils.js +35 -22
  209. package/lib/Utils/browser-utils.js.map +1 -0
  210. package/lib/Utils/business.d.ts +23 -0
  211. package/lib/Utils/business.d.ts.map +1 -0
  212. package/lib/Utils/business.js +2 -1
  213. package/lib/Utils/business.js.map +1 -0
  214. package/lib/Utils/chat-utils.d.ts +70 -0
  215. package/lib/Utils/chat-utils.d.ts.map +1 -0
  216. package/lib/Utils/chat-utils.js +2 -1
  217. package/lib/Utils/chat-utils.js.map +1 -0
  218. package/lib/Utils/crypto.d.ts +37 -0
  219. package/lib/Utils/crypto.d.ts.map +1 -0
  220. package/lib/Utils/crypto.js +2 -1
  221. package/lib/Utils/crypto.js.map +1 -0
  222. package/lib/Utils/decode-wa-message.d.ts +48 -0
  223. package/lib/Utils/decode-wa-message.d.ts.map +1 -0
  224. package/lib/Utils/decode-wa-message.js +2 -1
  225. package/lib/Utils/decode-wa-message.js.map +1 -0
  226. package/lib/Utils/event-buffer.d.ts +34 -0
  227. package/lib/Utils/event-buffer.d.ts.map +1 -0
  228. package/lib/Utils/event-buffer.js +4 -3
  229. package/lib/Utils/event-buffer.js.map +1 -0
  230. package/lib/Utils/generics.d.ts +91 -0
  231. package/lib/Utils/generics.d.ts.map +1 -0
  232. package/lib/Utils/generics.js +34 -7
  233. package/lib/Utils/generics.js.map +1 -0
  234. package/lib/Utils/history.d.ts +22 -0
  235. package/lib/Utils/history.d.ts.map +1 -0
  236. package/lib/Utils/history.js +2 -1
  237. package/lib/Utils/history.js.map +1 -0
  238. package/lib/Utils/identity-change-handler.d.ts +37 -0
  239. package/lib/Utils/identity-change-handler.d.ts.map +1 -0
  240. package/lib/Utils/identity-change-handler.js +2 -1
  241. package/lib/Utils/identity-change-handler.js.map +1 -0
  242. package/lib/Utils/index.d.ts +22 -0
  243. package/lib/Utils/index.d.ts.map +1 -0
  244. package/lib/Utils/index.js +8 -1
  245. package/lib/Utils/index.js.map +1 -0
  246. package/lib/Utils/link-preview.d.ts +21 -0
  247. package/lib/Utils/link-preview.d.ts.map +1 -0
  248. package/lib/Utils/link-preview.js +2 -1
  249. package/lib/Utils/link-preview.js.map +1 -0
  250. package/lib/Utils/logger.d.ts +13 -0
  251. package/lib/Utils/logger.d.ts.map +1 -0
  252. package/lib/Utils/logger.js +2 -1
  253. package/lib/Utils/logger.js.map +1 -0
  254. package/lib/Utils/lt-hash.d.ts +8 -0
  255. package/lib/Utils/lt-hash.d.ts.map +1 -0
  256. package/lib/Utils/lt-hash.js +2 -1
  257. package/lib/Utils/lt-hash.js.map +1 -0
  258. package/lib/Utils/make-mutex.d.ts +9 -0
  259. package/lib/Utils/make-mutex.d.ts.map +1 -0
  260. package/lib/Utils/make-mutex.js +2 -1
  261. package/lib/Utils/make-mutex.js.map +1 -0
  262. package/lib/Utils/message-retry-manager.d.ts +110 -0
  263. package/lib/Utils/message-retry-manager.d.ts.map +1 -0
  264. package/lib/Utils/message-retry-manager.js +3 -2
  265. package/lib/Utils/message-retry-manager.js.map +1 -0
  266. package/lib/Utils/messages-media.d.ts +130 -0
  267. package/lib/Utils/messages-media.d.ts.map +1 -0
  268. package/lib/Utils/messages-media.js +186 -180
  269. package/lib/Utils/messages-media.js.map +1 -0
  270. package/lib/Utils/messages-newsletter.d.ts +84 -0
  271. package/lib/Utils/messages-newsletter.js +316 -0
  272. package/lib/Utils/messages.d.ts +92 -0
  273. package/lib/Utils/messages.d.ts.map +1 -0
  274. package/lib/Utils/messages.js +929 -1116
  275. package/lib/Utils/messages.js.map +1 -0
  276. package/lib/Utils/noise-handler.d.ts +20 -0
  277. package/lib/Utils/noise-handler.d.ts.map +1 -0
  278. package/lib/Utils/noise-handler.js +2 -7
  279. package/lib/Utils/noise-handler.js.map +1 -0
  280. package/lib/Utils/pre-key-manager.d.ts +28 -0
  281. package/lib/Utils/pre-key-manager.d.ts.map +1 -0
  282. package/lib/Utils/pre-key-manager.js +2 -1
  283. package/lib/Utils/pre-key-manager.js.map +1 -0
  284. package/lib/Utils/process-message.d.ts +60 -0
  285. package/lib/Utils/process-message.d.ts.map +1 -0
  286. package/lib/Utils/process-message.js +2 -1
  287. package/lib/Utils/process-message.js.map +1 -0
  288. package/lib/Utils/reporting-utils.d.ts +11 -0
  289. package/lib/Utils/reporting-utils.d.ts.map +1 -0
  290. package/lib/Utils/reporting-utils.js +2 -1
  291. package/lib/Utils/reporting-utils.js.map +1 -0
  292. package/lib/Utils/resolve-jid.d.ts +43 -0
  293. package/lib/Utils/resolve-jid.js +101 -0
  294. package/lib/Utils/signal.d.ts +34 -0
  295. package/lib/Utils/signal.d.ts.map +1 -0
  296. package/lib/Utils/signal.js +2 -1
  297. package/lib/Utils/signal.js.map +1 -0
  298. package/lib/Utils/streamToBuffer.js +17 -0
  299. package/lib/Utils/sync-action-utils.d.ts +19 -0
  300. package/lib/Utils/sync-action-utils.d.ts.map +1 -0
  301. package/lib/Utils/sync-action-utils.js +2 -1
  302. package/lib/Utils/sync-action-utils.js.map +1 -0
  303. package/lib/Utils/tc-token-utils.d.ts +12 -0
  304. package/lib/Utils/tc-token-utils.d.ts.map +1 -0
  305. package/lib/Utils/tc-token-utils.js +2 -1
  306. package/lib/Utils/tc-token-utils.js.map +1 -0
  307. package/lib/Utils/use-mongo-file-auth-state.js +77 -0
  308. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  309. package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
  310. package/lib/Utils/use-multi-file-auth-state.js +2 -1
  311. package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
  312. package/lib/Utils/use-single-file-auth-state.js +74 -0
  313. package/lib/Utils/validate-connection.d.ts +11 -0
  314. package/lib/Utils/validate-connection.d.ts.map +1 -0
  315. package/lib/Utils/validate-connection.js +4 -10
  316. package/lib/Utils/validate-connection.js.map +1 -0
  317. package/lib/WABinary/constants.d.ts +28 -0
  318. package/lib/WABinary/constants.d.ts.map +1 -0
  319. package/lib/WABinary/constants.js +2 -1
  320. package/lib/WABinary/constants.js.map +1 -0
  321. package/lib/WABinary/decode.d.ts +7 -0
  322. package/lib/WABinary/decode.d.ts.map +1 -0
  323. package/lib/WABinary/decode.js +2 -1
  324. package/lib/WABinary/decode.js.map +1 -0
  325. package/lib/WABinary/encode.d.ts +3 -0
  326. package/lib/WABinary/encode.d.ts.map +1 -0
  327. package/lib/WABinary/encode.js +2 -1
  328. package/lib/WABinary/encode.js.map +1 -0
  329. package/lib/WABinary/generic-utils.d.ts +15 -0
  330. package/lib/WABinary/generic-utils.d.ts.map +1 -0
  331. package/lib/WABinary/generic-utils.js +15 -97
  332. package/lib/WABinary/generic-utils.js.map +1 -0
  333. package/lib/WABinary/index.d.ts +6 -0
  334. package/lib/WABinary/index.d.ts.map +1 -0
  335. package/lib/WABinary/index.js +3 -1
  336. package/lib/WABinary/index.js.map +1 -0
  337. package/lib/WABinary/jid-utils.d.ts +48 -0
  338. package/lib/WABinary/jid-utils.d.ts.map +1 -0
  339. package/lib/WABinary/jid-utils.js +4 -1
  340. package/lib/WABinary/jid-utils.js.map +1 -0
  341. package/lib/WABinary/types.d.ts +19 -0
  342. package/lib/WABinary/types.d.ts.map +1 -0
  343. package/lib/WABinary/types.js +2 -1
  344. package/lib/WABinary/types.js.map +1 -0
  345. package/lib/WAM/BinaryInfo.d.ts +9 -0
  346. package/lib/WAM/BinaryInfo.d.ts.map +1 -0
  347. package/lib/WAM/BinaryInfo.js +2 -1
  348. package/lib/WAM/BinaryInfo.js.map +1 -0
  349. package/lib/WAM/constants.d.ts +40 -0
  350. package/lib/WAM/constants.d.ts.map +1 -0
  351. package/lib/WAM/constants.js +2 -1
  352. package/lib/WAM/constants.js.map +1 -0
  353. package/lib/WAM/encode.d.ts +3 -0
  354. package/lib/WAM/encode.d.ts.map +1 -0
  355. package/lib/WAM/encode.js +2 -1
  356. package/lib/WAM/encode.js.map +1 -0
  357. package/lib/WAM/index.d.ts +4 -0
  358. package/lib/WAM/index.d.ts.map +1 -0
  359. package/lib/WAM/index.js +2 -1
  360. package/lib/WAM/index.js.map +1 -0
  361. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  362. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
  363. package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -1
  364. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
  365. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  366. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
  367. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +2 -1
  368. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
  369. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  370. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
  371. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -1
  372. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
  373. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  374. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
  375. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -1
  376. package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
  377. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  378. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
  379. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +2 -1
  380. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
  381. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
  382. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
  383. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +2 -1
  384. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
  385. package/lib/WAUSync/Protocols/index.d.ts +5 -0
  386. package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
  387. package/lib/WAUSync/Protocols/index.js +3 -1
  388. package/lib/WAUSync/Protocols/index.js.map +1 -0
  389. package/lib/WAUSync/USyncQuery.d.ts +29 -0
  390. package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
  391. package/lib/WAUSync/USyncQuery.js +2 -1
  392. package/lib/WAUSync/USyncQuery.js.map +1 -0
  393. package/lib/WAUSync/USyncUser.d.ts +13 -0
  394. package/lib/WAUSync/USyncUser.d.ts.map +1 -0
  395. package/lib/WAUSync/USyncUser.js +2 -1
  396. package/lib/WAUSync/USyncUser.js.map +1 -0
  397. package/lib/WAUSync/index.d.ts +4 -0
  398. package/lib/WAUSync/index.d.ts.map +1 -0
  399. package/lib/WAUSync/index.js +2 -1
  400. package/lib/WAUSync/index.js.map +1 -0
  401. package/lib/index.d.ts +12 -0
  402. package/lib/index.d.ts.map +1 -0
  403. package/lib/index.js +22 -2
  404. package/lib/index.js.map +1 -0
  405. package/package.json +75 -72
  406. package/lib/Utils/offline-node-processor.js +0 -39
  407. package/lib/Utils/stanza-ack.js +0 -37
package/README.md CHANGED
@@ -1,1087 +1,565 @@
1
- # 🌱 Violetics
1
+ <h1 align='center'><img alt="Baileys logo" src="https://raw.githubusercontent.com/WhiskeySockets/Baileys/refs/heads/master/Media/logo.png" height="75"/></h1>
2
2
 
3
- ![Logo](https://files.catbox.moe/c5s9g0.jpg)
3
+ <div align='center'>Baileys is a WebSockets-based TypeScript library for interacting with WhatsApp Web.</div>
4
4
 
5
- A lightweight fork of Baileys with a few fixes and a small adjustment.
6
-
7
- ### ⚙️ Changes
8
-
9
- #### 🛠️ Internal Adjustments
10
- - 🖼️ Fixed an issue where media could not be sent to newsletters due to an upstream issue.
11
- - 📁 Reintroduced [`makeInMemoryStore`](#%EF%B8%8F-implementing-a-data-store) with a minimal ESM adaptation and small adjustments for Baileys v7.
12
- - 📦 Switched FFmpeg execution from `exec` to `spawn` for safer process handling.
13
- - 🗃️ Added `@napi-rs/image` as a supported image processing backend in `getImageProcessingLibrary()`, offering a balance between performance and compatibility.
14
-
15
- #### 📨 Message Handling & Compatibility
16
- - 👉🏻 Added support for sending [interactive message](#-sending-interactive-messages) types (button, list, interactive, template, carousel).
17
- - 📩 Added support for [album messages](#%EF%B8%8F-album-image--video), [group status messages](#4%EF%B8%8F⃣-group-status), [status mention messages](#%EF%B8%8F-status-mention), [sticker pack messages](#-sticker-pack), and several [payment-related messages](#-sending-payment-messages) (request payment, payment invite, order, invoice).
18
- - 📰 Simplified sending messages with ad thumbnails via [`externalAdReply`](#3%EF%B8%8F⃣-external-ad-reply) without requiring manual `contextInfo`.
19
-
20
- #### 🧩 Additional Message Options
21
- - 👁️ Added optional boolean flags for message handling:
22
- - [`ai`](#1%EF%B8%8F⃣-ai-label) - AI label on message
23
- - [`mentionAll`](#-mention) - Mentions all group participants without requiring their JIDs in `mentions` or `mentionedJid`
24
- - [`ephemeral`](#2%EF%B8%8F⃣-ephemeral), [`groupStatus`](#4%EF%B8%8F⃣-group-status), [`viewOnceV2`](#7%EF%B8%8F⃣-view-once-v2), [`viewOnceV2Extension`](#8%EF%B8%8F⃣-view-once-v2-extension), [`interactiveAsTemplate`](#3%EF%B8%8F⃣-interactive) - Message wrappers
25
- - [`raw`](#5%EF%B8%8F⃣-raw) - Build your message manually **(DO NOT USE FOR EXPLOITATION)**
26
-
27
- > [!NOTE]
28
- 📄 This project is maintained with limited scope and is not intended to replace upstream Baileys.
29
- >
30
- > 😞 And, really sorry for my bad english.
31
-
32
- ### 📥 Installation
33
-
34
- - 📄 Via `package.json`
35
-
36
- ```json
37
- # NPM
38
- "dependencies": {
39
- "violetics": "latest"
40
- }
41
-
42
- # GitHub
43
- "dependencies": {
44
- "violetics": "github:cv3inx/violetics"
45
- }
46
- ```
47
-
48
- - ⌨️ Via terminal
49
-
50
- ```bash
51
- # NPM
52
- npm i violetics@latest
53
-
54
- # GitHub
55
- npm i github:cv3inx/violetics
56
- ```
57
-
58
- #### 🧩 Import (ESM & CJS)
59
-
60
- ```javascript
61
- // --- ESM
62
- import { makeWASocket } from 'violetics'
63
-
64
- // --- CJS (tested and working on Node.js 24 ✅)
65
- const { makeWASocket } = require('violetics')
66
- ```
67
-
68
- ### 🔧 Usage
69
-
70
- #### 🌐 Connect to WhatsApp (Quick Step)
71
-
72
- ```javascript
73
- import { makeWASocket, delay, DisconnectReason, useMultiFileAuthState } from 'violetics'
74
- import { Boom } from '@hapi/boom'
75
- import pino from 'pino'
76
-
77
- // --- Connect with pairing code
78
- const myPhoneNumber = '6288888888888'
79
-
80
- const logger = pino({ level: 'silent' })
81
-
82
- const connectToWhatsApp = async () => {
83
- const { state, saveCreds } = await useMultiFileAuthState('session')
84
-
85
- const sock = makeWASocket({
86
- logger,
87
- auth: state
88
- })
89
-
90
- sock.ev.on('creds.update', saveCreds)
91
-
92
- sock.ev.on('connection.update', (update) => {
93
- const { connection, lastDisconnect } = update
94
- if (connection === 'connecting' && !sock.authState.creds.registered) {
95
- await delay(1500)
96
- const code = await sock.requestPairingCode(myPhoneNumber)
97
- console.log('🔗 Pairing code', ':', code)
98
- }
99
- else if (connection === 'close') {
100
- const shouldReconnect = new Boom(connection?.lastDisconnect?.error)?.output?.statusCode !== DisconnectReason.loggedOut
101
- console.log('⚠️ Connection closed because', lastDisconnect.error, ', reconnecting ', shouldReconnect)
102
- if (shouldReconnect) {
103
- connectToWhatsApp()
104
- }
105
- }
106
- else if (connection === 'open') {
107
- console.log('✅ Successfully connected to WhatsApp')
108
- }
109
- })
110
-
111
- sock.ev.on('messages.upsert', async ({ messages }) => {
112
- for (const message of messages) {
113
- if (!message.message) continue
114
-
115
- console.log('🔔 Got new message', ':', message)
116
- await sock.sendMessage(message.key.remoteJid, {
117
- text: '👋🏻 Hello world'
118
- })
119
- }
120
- })
121
- }
122
-
123
- connectToWhatsApp()
124
- ```
125
-
126
- #### 🗄️ Implementing a Data Store
127
5
 
128
6
  > [!CAUTION]
129
- I highly recommend building your own data store, as keeping an entire chat history in memory can lead to excessive RAM usage.
130
-
131
- ```javascript
132
- import { makeWASocket, makeInMemoryStore, delay, DisconnectReason, useMultiFileAuthState } from 'violetics'
133
- import { Boom } from '@hapi/boom'
134
- import pino from 'pino'
135
-
136
- const myPhoneNumber = '6288888888888'
137
-
138
- // --- Create your store path
139
- const storePath = './store.json'
140
-
141
- const logger = pino({ level: 'silent' })
142
-
143
- const connectToWhatsApp = async () => {
144
- const { state, saveCreds } = await useMultiFileAuthState('session')
145
-
146
- const sock = makeWASocket({
147
- logger,
148
- auth: state
149
- })
150
-
151
- const store = makeInMemoryStore({
152
- logger,
153
- socket: sock
154
- })
155
-
156
- store.bind(sock.ev)
157
-
158
- sock.ev.on('creds.update', saveCreds)
159
-
160
- sock.ev.on('connection.update', (update) => {
161
- const { connection, lastDisconnect } = update
162
- if (connection === 'connecting' && !sock.authState.creds.registered) {
163
- await delay(1500)
164
- const code = await sock.requestPairingCode(myPhoneNumber)
165
- console.log('🔗 Pairing code', ':', code)
166
- }
167
- else if (connection === 'close') {
168
- const shouldReconnect = new Boom(connection?.lastDisconnect?.error)?.output?.statusCode !== DisconnectReason.loggedOut
169
- console.log('⚠️ Connection closed because', lastDisconnect.error, ', reconnecting ', shouldReconnect)
170
- if (shouldReconnect) {
171
- connectToWhatsApp()
172
- }
173
- }
174
- else if (connection === 'open') {
175
- console.log('✅ Successfully connected to WhatsApp')
176
- }
177
- })
178
-
179
- sock.ev.on('chats.upsert', () => {
180
- console.log('✉️ Got chats', store.chats.all())
181
- })
182
-
183
- sock.ev.on('contacts.upsert', () => {
184
- console.log('👥 Got contacts', Object.values(store.contacts))
185
- })
186
-
187
- // --- Read store from file
188
- store.readFromFile(storePath)
189
-
190
- // --- Save store every 3 minutes
191
- setInterval(() => {
192
- store.writeToFile(storePath)
193
- }, 180000)
194
- }
195
-
196
- connectToWhatsApp()
197
- ```
7
+ > NOTICE OF BREAKING CHANGE.
8
+ >
9
+ > As of 1.0.0, multiple breaking changes were introduced into the library.
10
+ >
11
+ > Please check out https://whiskey.so/migrate-latest for more information.
198
12
 
199
- #### 🪪 WhatsApp IDs Explain
13
+ # Important Note
14
+ This is a temporary README.md, the new guide is in development and will this file will be replaced with .github/README.md (already a default on GitHub).
200
15
 
201
- `id` is the WhatsApp ID, called `jid` and `lid` too, of the person or group you're sending the message to.
202
- - It must be in the format `[country code][phone number]@s.whatsapp.net`
203
- - Example for people: `19999999999@s.whatsapp.net` and `12699999999@lid`.
204
- - For groups, it must be in the format `123456789-123345@g.us`.
205
- - For Meta AI, it's `11111111111@bot`.
206
- - For broadcast lists, it's `[timestamp of creation]@broadcast`.
207
- - For stories, the ID is `status@broadcast`.
16
+ New guide link: https://baileys.wiki
208
17
 
209
- #### ✉️ Sending Messages
18
+ # Get Support
210
19
 
211
- > [!NOTE]
212
- You can get the `jid` from `message.key.remoteJid` in the first example.
20
+ If you'd like business to enterprise-level support from Rajeh, the current maintainer of Baileys, you can book a video chat. Book a 1 hour time slot by contacting him on Discord or pre-ordering [here](https://purpshell.dev/book). The earlier you pre-order the better, as his time slots usually fill up very quickly. He offers immense value per hour and will answer all your questions before the time runs out.
213
21
 
214
- ##### 🔠 Text
22
+ If you are a business, we encourage you to contribute back to the high development costs of the project and to feed the maintainers who dump tens of hours a week on this. You can do so by booking meetings or sponsoring below. All support, even in bona fide / contribution hours, is welcome by businesses of all sizes. This is not condoning or endorsing businesses to use the library. See the Disclaimer below.
215
23
 
216
- ```javascript
217
- sock.sendMessage(jid, {
218
- text: '👋🏻 Hello'
219
- }, {
220
- quoted: message
221
- })
222
- ```
24
+ # Sponsor
25
+ If you'd like to financially support this project, you can do so by supporting the current maintainer [here](https://purpshell.dev/sponsor).
223
26
 
224
- ##### 🔔 Mention
27
+ # Disclaimer
28
+ This project is not affiliated, associated, authorized, endorsed by, or in any way officially connected with WhatsApp or any of its subsidiaries or its affiliates.
29
+ The official WhatsApp website can be found at whatsapp.com. "WhatsApp" as well as related names, marks, emblems and images are registered trademarks of their respective owners.
225
30
 
226
- ```javascript
227
- // --- Regular mention
228
- sock.sendMessage(jid, {
229
- text: '👋🏻 Hello @628123456789',
230
- mentions: ['628123456789@s.whatsapp.net']
231
- }, {
232
- quoted: message
233
- })
31
+ The maintainers of Baileys do not in any way condone the use of this application in practices that violate the Terms of Service of WhatsApp. The maintainers of this application call upon the personal responsibility of its users to use this application in a fair way, as it is intended to be used.
32
+ Use at your own discretion. Do not spam people with this. We discourage any stalkerware, bulk or automated messaging usage.
234
33
 
235
- // --- Mention all
236
- sock.sendMessage(jid, {
237
- text: '👋🏻 Hello @all',
238
- mentionAll: true
239
- }, {
240
- quoted: message
241
- })
242
- ```
34
+ ##
243
35
 
244
- ##### 😁 Reaction
36
+ - Baileys does not require Selenium or any other browser to be interface with WhatsApp Web, it does so directly using a **WebSocket**.
37
+ - Not running Selenium or Chromium saves you like **half a gig** of ram :/
38
+ - Baileys supports interacting with the multi-device & web versions of WhatsApp.
39
+ - Thank you to [@pokearaujo](https://github.com/pokearaujo/multidevice) for writing his observations on the workings of WhatsApp Multi-Device. Also, thank you to [@Sigalor](https://github.com/sigalor/whatsapp-web-reveng) for writing his observations on the workings of WhatsApp Web and thanks to [@Rhymen](https://github.com/Rhymen/go-whatsapp/) for the __go__ implementation.
245
40
 
246
- ```javascript
247
- sock.sendMessage(jid, {
248
- react: {
249
- key: message.key,
250
- text: '✨'
251
- }
252
- }, {
253
- quoted: message
254
- })
255
- ```
41
+ > [!IMPORTANT]
42
+ > The original repository had to be removed by the original author - we now continue development in this repository here.
43
+ This is the only official repository and is maintained by the community.
44
+ > **Join the Discord [here](https://discord.gg/WeJM5FP9GG)**
256
45
 
257
- ##### 📌 Pin Message
46
+ ## Example
258
47
 
259
- ```javascript
260
- sock.sendMessage(jid, {
261
- pin: message.key,
262
- time: 86400, // --- Set the value in seconds: 86400 (1d), 604800 (7d), or 2592000 (30d)
263
- type: 1 // --- Or 0 to remove
264
- }, {
265
- quoted: message
266
- })
267
- ```
48
+ Do check out & run [example.ts](Example/example.ts) to see an example usage of the library.
49
+ The script covers most common use cases.
50
+ To run the example script, download or clone the repo and then type the following in a terminal:
51
+ 1. ``` cd path/to/Baileys ```
52
+ 2. ``` yarn ```
53
+ 3. ``` yarn example ```
268
54
 
269
- ##### 👤 Contact
270
-
271
- ```javascript
272
- const vcard = 'BEGIN:VCARD\n'
273
- + 'VERSION:3.0\n'
274
- + 'FN:Lia Wynn\n'
275
- + 'ORG:Waiters;\n'
276
- + 'TEL;type=CELL;type=VOICE;waid=628123456789:+62 8123 4567 89\n'
277
- + 'END:VCARD'
278
-
279
- sock.sendMessage(jid, {
280
- contacts: {
281
- displayName: 'Lia',
282
- contacts: [
283
- { vcard }
284
- ]
285
- }
286
- }, {
287
- quoted: message
288
- })
289
- ```
55
+ ## Install
290
56
 
291
- ##### 📍 Location
292
-
293
- ```javascript
294
- sock.sendMessage(jid, {
295
- location: {
296
- degreesLatitude: 24.121231,
297
- degreesLongitude: 55.1121221,
298
- name: '👋🏻 I am here'
299
- }
300
- }, {
301
- quoted: message
302
- })
57
+ Install dari file `.tgz` lokal (versi modified blckrose):
303
58
  ```
304
-
305
- ##### 📊 Poll
306
-
307
- ```javascript
308
- // --- Regular poll message
309
- sock.sendMessage(jid, {
310
- poll: {
311
- name: '🔥 Voting time',
312
- values: ['Yes', 'No'],
313
- selectableCount: 1,
314
- toAnnouncementGroup: false
315
- }
316
- }, {
317
- quoted: message
318
- })
319
-
320
- // --- Quiz (only for newsletter)
321
- sock.sendMessage('1211111111111@newsletter', {
322
- poll: {
323
- name: '🔥 Quiz',
324
- values: ['Yes', 'No'],
325
- correctAnswer: 'Yes',
326
- pollType: 1
327
- }
328
- }, {
329
- quoted: message
330
- })
331
-
332
- // --- Poll result
333
- sock.sendMessage(jid, {
334
- pollResult: {
335
- name: '📝 Poll Result',
336
- votes: [{
337
- name: 'Nice',
338
- voteCount: 10
339
- }, {
340
- name: 'Nah',
341
- voteCount: 2
342
- }],
343
- pollType: 0 // Or 1 for quiz
344
- }
345
- }, {
346
- quoted: message
347
- })
348
-
349
- // --- Poll update
350
- sock.sendMessage(jid, {
351
- pollUpdate: {
352
- metadata: {},
353
- key: message.key,
354
- vote: {
355
- enclv: /* <Buffer> */,
356
- encPayload: /* <Buffer> */
357
- }
358
- }
359
- }, {
360
- quoted: message
361
- })
59
+ npm install ./blckrose-baileys-1.2.9.tgz
362
60
  ```
363
61
 
364
- ##### 🎞️ Status Mention
365
-
366
- ```javascript
367
- sock.sendMessage([jidA, jidB, jidC], {
368
- text: 'Hello! 👋🏻'
369
- })
62
+ Atau tambahkan ke `package.json`:
63
+ ```json
64
+ {
65
+ "dependencies": {
66
+ "@blckrose/baileys": "file:./blckrose-baileys-1.2.9.tgz"
67
+ }
68
+ }
370
69
  ```
371
70
 
372
- #### 📁 Sending Media Messages
71
+ Kemudian jalankan:
72
+ ```
73
+ npm install
74
+ ```
75
+
76
+ **ESM:**
77
+ ```ts
78
+ import makeWASocket from '@blckrose/baileys'
79
+ ```
80
+
81
+ **CJS (destructure langsung, tanpa top-level await):**
82
+ ```js
83
+ const { makeWASocket, useMultiFileAuthState, Browsers, DisconnectReason } = require('@blckrose/baileys')
84
+ // global apocalypse otomatis tersedia setelah baris di atas
85
+ ```
86
+
87
+ # Links
88
+
89
+ - [Discord](https://discord.gg/WeJM5FP9GG)
90
+ - [Docs](https://guide.whiskeysockets.io/)
91
+
92
+ # Index
93
+
94
+ - [Connecting Account](#connecting-account)
95
+ - [Connect with QR-CODE](#starting-socket-with-qr-code)
96
+ - [Connect with Pairing Code](#starting-socket-with-pairing-code)
97
+ - [Receive Full History](#receive-full-history)
98
+ - [Important Notes About Socket Config](#important-notes-about-socket-config)
99
+ - [Caching Group Metadata (Recommended)](#caching-group-metadata-recommended)
100
+ - [Improve Retry System & Decrypt Poll Votes](#improve-retry-system--decrypt-poll-votes)
101
+ - [Receive Notifications in Whatsapp App](#receive-notifications-in-whatsapp-app)
102
+
103
+ - [Save Auth Info](#saving--restoring-sessions)
104
+ - [Handling Events](#handling-events)
105
+ - [Example to Start](#example-to-start)
106
+ - [Decrypt Poll Votes](#decrypt-poll-votes)
107
+ - [Summary of Events on First Connection](#summary-of-events-on-first-connection)
108
+ - [Implementing a Data Store](#implementing-a-data-store)
109
+ - [Whatsapp IDs Explain](#whatsapp-ids-explain)
110
+ - [Utility Functions](#utility-functions)
111
+ - [Newsletter / Channel](#newsletter--channel)
112
+ - [Kirim Media ke Channel](#kirim-media-ke-channel)
113
+ - [Button di Channel](#button-di-channel)
114
+ - [Edit & Hapus Pesan Channel](#edit--hapus-pesan-channel)
115
+ - [Resolve JID (LID → Phone)](#resolve-jid)
116
+ - [Sending Messages](#sending-messages)
117
+ - [Non-Media Messages](#non-media-messages)
118
+ - [Text Message](#text-message)
119
+ - [Quote Message](#quote-message-works-with-all-types)
120
+ - [Mention User](#mention-user-works-with-most-types)
121
+ - [Forward Messages](#forward-messages)
122
+ - [Location Message](#location-message)
123
+ - [Live Location Message](#live-location-message)
124
+ - [Contact Message](#contact-message)
125
+ - [Reaction Message](#reaction-message)
126
+ - [Pin Message](#pin-message)
127
+ - [Keep Message](#keep-message)
128
+ - [Poll Message](#poll-message)
129
+ - [Poll Result Message](#poll-result-message)
130
+ - [Call Message](#call-message)
131
+ - [Event Message](#event-message)
132
+ - [Order Message](#order-message)
133
+ - [Product Message](#product-message)
134
+ - [Payment Message](#payment-message)
135
+ - [Payment Invite Message](#payment-invite-message)
136
+ - [Admin Invite Message](#admin-invite-message)
137
+ - [Group Invite Message](#group-invite-message)
138
+ - [Sticker Pack Message](#sticker-pack-message)
139
+ - [Share Phone Number Message](#share-phone-number-message)
140
+ - [Request Phone Number Message](#request-phone-number-message)
141
+ - [Buttons Reply Message](#buttons-reply-message)
142
+ - [Buttons Message](#buttons-message)
143
+ - [Buttons List Message](#buttons-list-message)
144
+ - [Buttons Product List Message](#buttons-product-list-message)
145
+ - [Buttons Cards Message](#buttons-cards-message)
146
+ - [Buttons Template Message](#buttons-template-message)
147
+ - [Buttons Interactive Message](#buttons-interactive-message)
148
+ - [Buttons Interactive Message PIX](#buttons-interactive-message-pix)
149
+ - [Buttons Interactive Message PAY](#buttons-interactive-message-pay)
150
+ - [Status Mentions Message](#status-mentions-message)
151
+ - [Shop Message](#shop-message)
152
+ - [Collection Message](#collection-message)
153
+ - [AI Icon Feature](#ai-icon-feature)
154
+ - [Sending with Link Preview](#sending-messages-with-link-previews)
155
+ - [Media Messages](#media-messages)
156
+ - [Gif Message](#gif-message)
157
+ - [Video Message](#video-message)
158
+ - [Audio Message](#audio-message)
159
+ - [Image Message](#image-message)
160
+ - [Album Message](#album-message)
161
+ - [Ptv Video Message](#ptv-video-message)
162
+ - [View Once Message](#view-once-message)
163
+ - [Modify Messages](#modify-messages)
164
+ - [Delete Messages (for everyone)](#deleting-messages-for-everyone)
165
+ - [Edit Messages](#editing-messages)
166
+ - [Manipulating Media Messages](#manipulating-media-messages)
167
+ - [Thumbnail in Media Messages](#thumbnail-in-media-messages)
168
+ - [Downloading Media Messages](#downloading-media-messages)
169
+ - [Re-upload Media Message to Whatsapp](#re-upload-media-message-to-whatsapp)
170
+ - [Reject Call](#reject-call)
171
+ - [Send States in Chat](#send-states-in-chat)
172
+ - [Reading Messages](#reading-messages)
173
+ - [Update Presence](#update-presence)
174
+ - [Modifying Chats](#modifying-chats)
175
+ - [Archive a Chat](#archive-a-chat)
176
+ - [Mute/Unmute a Chat](#muteunmute-a-chat)
177
+ - [Mark a Chat Read/Unread](#mark-a-chat-readunread)
178
+ - [Delete a Message for Me](#delete-a-message-for-me)
179
+ - [Delete a Chat](#delete-a-chat)
180
+ - [Star/Unstar a Message](#starunstar-a-message)
181
+ - [Disappearing Messages](#disappearing-messages)
182
+ - [Clear Messages](#clear-messages)
183
+ - [User Querys](#user-querys)
184
+ - [Check If ID Exists in Whatsapp](#check-if-id-exists-in-whatsapp)
185
+ - [Query Chat History (groups too)](#query-chat-history-groups-too)
186
+ - [Fetch Status](#fetch-status)
187
+ - [Fetch Profile Picture (groups too)](#fetch-profile-picture-groups-too)
188
+ - [Fetch Bussines Profile (such as description or category)](#fetch-bussines-profile-such-as-description-or-category)
189
+ - [Fetch Someone's Presence (if they're typing or online)](#fetch-someones-presence-if-theyre-typing-or-online)
190
+ - [Change Profile](#change-profile)
191
+ - [Change Profile Status](#change-profile-status)
192
+ - [Change Profile Name](#change-profile-name)
193
+ - [Change Display Picture (groups too)](#change-display-picture-groups-too)
194
+ - [Remove display picture (groups too)](#remove-display-picture-groups-too)
195
+ - [Groups](#groups)
196
+ - [Create a Group](#create-a-group)
197
+ - [Add/Remove or Demote/Promote](#addremove-or-demotepromote)
198
+ - [Change Subject (name)](#change-subject-name)
199
+ - [Change Description](#change-description)
200
+ - [Change Settings](#change-settings)
201
+ - [Leave a Group](#leave-a-group)
202
+ - [Get Invite Code](#get-invite-code)
203
+ - [Revoke Invite Code](#revoke-invite-code)
204
+ - [Join Using Invitation Code](#join-using-invitation-code)
205
+ - [Get Group Info by Invite Code](#get-group-info-by-invite-code)
206
+ - [Query Metadata (participants, name, description...)](#query-metadata-participants-name-description)
207
+ - [Join using groupInviteMessage](#join-using-groupinvitemessage)
208
+ - [Get Request Join List](#get-request-join-list)
209
+ - [Approve/Reject Request Join](#approvereject-request-join)
210
+ - [Get All Participating Groups Metadata](#get-all-participating-groups-metadata)
211
+ - [Toggle Ephemeral](#toggle-ephemeral)
212
+ - [Change Add Mode](#change-add-mode)
213
+ - [Privacy](#privacy)
214
+ - [Block/Unblock User](#blockunblock-user)
215
+ - [Get Privacy Settings](#get-privacy-settings)
216
+ - [Get BlockList](#get-blocklist)
217
+ - [Update LastSeen Privacy](#update-lastseen-privacy)
218
+ - [Update Online Privacy](#update-online-privacy)
219
+ - [Update Profile Picture Privacy](#update-profile-picture-privacy)
220
+ - [Update Status Privacy](#update-status-privacy)
221
+ - [Update Read Receipts Privacy](#update-read-receipts-privacy)
222
+ - [Update Groups Add Privacy](#update-groups-add-privacy)
223
+ - [Update Default Disappearing Mode](#update-default-disappearing-mode)
224
+ - [Broadcast Lists & Stories](#broadcast-lists--stories)
225
+ - [Send Broadcast & Stories](#send-broadcast--stories)
226
+ - [Query a Broadcast List's Recipients & Name](#query-a-broadcast-lists-recipients--name)
227
+ - [Writing Custom Functionality](#writing-custom-functionality)
228
+ - [Enabling Debug Level in Baileys Logs](#enabling-debug-level-in-baileys-logs)
229
+ - [How Whatsapp Communicate With Us](#how-whatsapp-communicate-with-us)
230
+ - [Register a Callback for Websocket Events](#register-a-callback-for-websocket-events)
231
+
232
+ ## Connecting Account
233
+
234
+ WhatsApp provides a multi-device API that allows Baileys to be authenticated as a second WhatsApp client by scanning a **QR code** or **Pairing Code** with WhatsApp on your phone.
373
235
 
374
236
  > [!NOTE]
375
- For media messages, you can pass a `Buffer` directly, or an object with either `{ stream: Readable }` or `{ url: string }` (local file path or HTTP/HTTPS URL).
376
-
377
- ##### 🖼️ Image
378
-
379
- ```javascript
380
- sock.sendMessage(jid, {
381
- image: {
382
- url: './path/to/image.jpg'
383
- },
384
- caption: '🔥 Superb'
385
- }, {
386
- quoted: message
387
- })
388
- ```
237
+ > **[Here](#example-to-start) is a simple example of event handling**
389
238
 
390
- ##### 🎥 Video
391
-
392
- ```javascript
393
- sock.sendMessage(jid, {
394
- video: {
395
- url: './path/to/video.mp4'
396
- },
397
- gifPlayback: false, // --- Set true if you want to send video as GIF
398
- ptv: false, // --- Set true if you want to send video as PTV
399
- caption: '🔥 Superb'
400
- }, {
401
- quoted: message
402
- })
403
- ```
239
+ > [!TIP]
240
+ > **You can see all supported socket configs [here](https://baileys.whiskeysockets.io/types/SocketConfig.html) (Recommended)**
404
241
 
405
- ##### 📃 Sticker
406
-
407
- ```javascript
408
- sock.sendMessage(jid, {
409
- sticker: {
410
- url: './path/to/sticker.webp'
411
- }
412
- }, {
413
- quoted: message
414
- })
415
- ```
242
+ ### Starting socket with **QR-CODE**
416
243
 
417
- ##### 💽 Audio
244
+ > [!TIP]
245
+ > You can customize browser name if you connect with **QR-CODE**, with `Browser` constant, we have some browsers config, **see [here](https://baileys.whiskeysockets.io/types/BrowsersMap.html)**
418
246
 
419
- ```javascript
420
- sock.sendMessage(jid, {
421
- audio: {
422
- url: './path/to/audio.mp3'
423
- },
424
- ptt: false, // --- Set true if you want to send audio as Voice Note
425
- }, {
426
- quoted: message
427
- })
428
- ```
247
+ ```ts
248
+ import makeWASocket from '@blckrose/baileys'
429
249
 
430
- ##### 🖼️ Album (Image & Video)
431
-
432
- ```javascript
433
- sock.sendMessage(jid, {
434
- album: [{
435
- image: {
436
- url: './path/to/image.jpg'
437
- },
438
- caption: '1st image'
439
- }, {
440
- video: {
441
- url: './path/to/video.mp4'
442
- },
443
- caption: '1st video'
444
- }, {
445
- image: {
446
- url: './path/to/image.jpg'
447
- },
448
- caption: '2nd image'
449
- }, {
450
- video: {
451
- url: './path/to/video.mp4'
452
- },
453
- caption: '2nd video'
454
- }]
455
- }, {
456
- quoted: message
250
+ const sock = makeWASocket({
251
+ // can provide additional config here
252
+ browser: Browsers.ubuntu('My App'),
253
+ printQRInTerminal: true
457
254
  })
458
255
  ```
459
256
 
460
- ##### 📦 Sticker Pack
461
-
462
- > [!IMPORTANT]
463
- If `sharp` or `@napi-rs/image` is not installed, the `cover` and `stickers` must already be in WebP format.
464
-
465
- ```javascript
466
- sock.sendMessage(jid, {
467
- cover: {
468
- url: './path/to/image.webp'
469
- },
470
- stickers: [{
471
- data: {
472
- url: './path/to/image.webp'
473
- }
474
- }, {
475
- data: {
476
- url: './path/to/image.webp'
477
- }
478
- }, {
479
- data: {
480
- url: './path/to/image.webp'
481
- }
482
- }],
483
- name: '📦 My Sticker Pack',
484
- publisher: '🌟 Lia Wynn',
485
- description: 'violetics'
486
- }, {
487
- quoted: message
488
- })
489
- ```
257
+ If the connection is successful, you will see a QR code printed on your terminal screen, scan it with WhatsApp on your phone and you'll be logged in!
490
258
 
491
- #### 👉🏻 Sending Interactive Messages
492
-
493
- ##### 1️⃣ Buttons
494
-
495
- ```javascript
496
- // --- Regular buttons message
497
- sock.sendMessage(jid, {
498
- text: '👆🏻 Buttons!',
499
- footer: 'violetics',
500
- buttons: [{
501
- text: '👋🏻 SignUp',
502
- id: '#SignUp'
503
- }]
504
- }, {
505
- quoted: message
506
- })
259
+ ### Starting socket with **Pairing Code**
507
260
 
508
- // --- Buttons with Media & Native Flow
509
- sock.sendMessage(jid, {
510
- image: {
511
- url: './path/to/image.jpg'
512
- },
513
- caption: '👆🏻 Buttons and Native Flow!',
514
- footer: 'violetics',
515
- buttons: [{
516
- text: '👋🏻 Rating',
517
- id: '#Rating'
518
- }, {
519
- text: '📋 Select',
520
- sections: [{
521
- title: '✨ Section 1',
522
- rows: [{
523
- header: '',
524
- title: '💭 Secret Ingredient',
525
- description: '',
526
- id: '#SecretIngredient'
527
- }]
528
- }, {
529
- title: '✨ Section 2',
530
- highlight_label: '🔥 Popular',
531
- rows: [{
532
- header: '',
533
- title: '🏷️ Coupon',
534
- description: '',
535
- id: '#CouponCode'
536
- }]
537
- }]
538
- }]
539
- }, {
540
- quoted: message
541
- })
542
- ```
543
261
 
544
- ##### 2️⃣ List
262
+ > [!IMPORTANT]
263
+ > Pairing Code isn't Mobile API, it's a method to connect Whatsapp Web without QR-CODE, you can connect only with one device, see [here](https://faq.whatsapp.com/1324084875126592/?cms_platform=web)
545
264
 
546
- > [!NOTE]
547
- It only works in private chat (`@s.whatsapp.net`).
548
-
549
- ```javascript
550
- sock.sendMessage(jid, {
551
- text: '📋 List!',
552
- footer: 'violetics',
553
- buttonText: '📋 Select',
554
- title: '👋🏻 Hello',
555
- sections: [{
556
- title: '🚀 Menu 1',
557
- rows: [{
558
- title: '✨ AI',
559
- description: '',
560
- rowId: '#AI'
561
- }]
562
- }, {
563
- title: '🌱 Menu 2',
564
- rows: [{
565
- title: '🔍 Search',
566
- description: '',
567
- rowId: '#Search'
568
- }]
569
- }]
570
- }, {
571
- quoted: message
572
- })
573
- ```
265
+ The phone number can't have `+` or `()` or `-`, only numbers, you must provide country code
574
266
 
575
- ##### 3️⃣ Interactive
576
-
577
- ```javascript
578
- // --- Native Flow
579
- sock.sendMessage(jid, {
580
- image: {
581
- url: './path/to/image.jpg'
582
- },
583
- caption: '🗄️ Interactive!',
584
- footer: 'violetics',
585
- optionText: '👉🏻 Select Options', // --- Optional, wrap all native flow into a single list
586
- optionTitle: '📄 Select Options', // --- Optional
587
- couponText: '🏷️ Newest Coupon!', // --- Optional, add coupon into message
588
- couponCode: 'violetics', // --- Optional
589
- nativeFlow: [{
590
- text: '👋🏻 Greeting',
591
- id: '#Greeting'
592
- }, {
593
- text: '📞 Call',
594
- call: '628123456789'
595
- }, {
596
- text: '📋 Copy',
597
- copy: 'violetics'
598
- }, {
599
- text: '🌐 Source',
600
- url: 'https://www.npmjs.com/package/baileys'
601
- }, {
602
- text: '📋 Select',
603
- sections: [{
604
- title: '✨ Section 1',
605
- rows: [{
606
- header: '',
607
- title: '🏷️ Coupon',
608
- description: '',
609
- id: '#CouponCode'
610
- }]
611
- }, {
612
- title: '✨ Section 2',
613
- highlight_label: '🔥 Popular',
614
- rows: [{
615
- header: '',
616
- title: '💭 Secret Ingredient',
617
- description: '',
618
- id: '#SecretIngredient'
619
- }]
620
- }]
621
- }],
622
- interactiveAsTemplate: false, // --- Optional, wrap the interactive message into a template
623
- }, {
624
- quoted: message
625
- })
267
+ ```ts
268
+ import makeWASocket from '@blckrose/baileys'
626
269
 
627
- // --- Carousel & Native Flow
628
- sock.sendMessage(jid, {
629
- text: '🗂️ Interactive with Carousel!',
630
- footer: 'violetics',
631
- cards: [{
632
- image: {
633
- url: './path/to/image.jpg'
634
- },
635
- caption: '🖼️ Image 1',
636
- footer: '🏷️️ Pinterest',
637
- nativeFlow: [{
638
- text: '🌐 Source',
639
- url: 'https://www.npmjs.com/package/baileys'
640
- }]
641
- }, {
642
- image: {
643
- url: './path/to/image.jpg'
644
- },
645
- caption: '🖼️ Image 2',
646
- footer: '🏷️ Pinterest',
647
- couponText: '🏷️ New Coupon!',
648
- couponCode: 'violetics',
649
- nativeFlow: [{
650
- text: '🌐 Source',
651
- url: 'https://www.npmjs.com/package/baileys'
652
- }]
653
- }, {
654
- image: {
655
- url: './path/to/image.jpg'
656
- },
657
- caption: '🖼️ Image 3',
658
- footer: '🏷️ Pinterest',
659
- optionText: '👉🏻 Select Options',
660
- optionTitle: '📄 Select Options',
661
- couponText: '🏷️ New Coupon!',
662
- couponCode: 'violetics',
663
- nativeFlow: [{
664
- text: '🛒 Product',
665
- id: '#Product'
666
- }, {
667
- text: '🌐 Source',
668
- url: 'https://www.npmjs.com/package/baileys'
669
- }]
670
- }]
671
- }, {
672
- quoted: message
270
+ const sock = makeWASocket({
271
+ // can provide additional config here
272
+ printQRInTerminal: false //need to be false
673
273
  })
674
- ```
675
274
 
676
- ##### 4️⃣ Hydrated Template
677
-
678
- ```javascript
679
- sock.sendMessage(jid, {
680
- title: '👋🏻 Hello',
681
- image: {
682
- url: './path/to/image.jpg'
683
- },
684
- caption: '🫙 Template!',
685
- footer: 'violetics',
686
- templateButtons: [{
687
- text: '👉🏻 Tap Here',
688
- id: '#Order'
689
- }, {
690
- text: '🌐 Source',
691
- url: 'https://www.npmjs.com/package/baileys'
692
- }, {
693
- text: '📞 Call',
694
- call: '628123456789'
695
- }]
696
- }, {
697
- quoted: message
698
- })
275
+ if (!sock.authState.creds.registered) {
276
+ const number = 'XXXXXXXXXXX'
277
+ const code = await sock.requestPairingCode(number)
278
+ console.log(code)
279
+ }
699
280
  ```
700
281
 
701
- #### 💳 Sending Payment Messages
282
+ ### Receive Full History
702
283
 
703
- ##### 1️⃣ Invite Payment
284
+ 1. Set `syncFullHistory` as `true`
285
+ 2. Baileys, by default, use chrome browser config
286
+ - If you'd like to emulate a desktop connection (and receive more message history), this browser setting to your Socket config:
704
287
 
705
- ```javascript
706
- sock.sendMessage(jid, {
707
- paymentInviteServiceType: 3 // 1, 2, or 3
288
+ ```ts
289
+ const sock = makeWASocket({
290
+ ...otherOpts,
291
+ // can use Windows, Ubuntu here too
292
+ browser: Browsers.macOS('Desktop'),
293
+ syncFullHistory: true
708
294
  })
709
295
  ```
710
296
 
711
- ##### 2️⃣ Invoice
297
+ ## Important Notes About Socket Config
712
298
 
713
- > [!NOTE]
714
- Invoice message are not supported yet.
715
-
716
- ```javascript
717
- sock.sendMessage(jid, {
718
- image: {
719
- url: './path/to/image.jpg'
720
- },
721
- invoiceNote: '🏷️ Invoice'
722
- })
723
- ```
299
+ ### Caching Group Metadata (Recommended)
300
+ - If you use baileys for groups, we recommend you to set `cachedGroupMetadata` in socket config, you need to implement a cache like this:
724
301
 
725
- ##### 3️⃣ Order
302
+ ```ts
303
+ const groupCache = new NodeCache({stdTTL: 5 * 60, useClones: false})
726
304
 
727
- ```javascript
728
- sock.sendMessage(chat, {
729
- orderText: '🛍️ Order',
730
- thumbnail: fs.readFileSync('./path/to/image.jpg') // --- Must in buffer format
731
- }, {
732
- quoted: message
733
- })
734
- ```
305
+ const sock = makeWASocket({
306
+ cachedGroupMetadata: async (jid) => groupCache.get(jid)
307
+ })
735
308
 
736
- ##### 4️⃣ Product
737
-
738
- ```javascript
739
- sock.sendMessage(jid, {
740
- image: {
741
- url: './path/to/image.jpg'
742
- },
743
- product: {
744
- title: '🛒 My Product'
745
- },
746
- businessOwnerJid: '0@s.whatsapp.net' // --- Must included
747
- }, {
748
- quoted: message
749
- })
750
- ```
309
+ sock.ev.on('groups.update', async ([event]) => {
310
+ const metadata = await sock.groupMetadata(event.id)
311
+ groupCache.set(event.id, metadata)
312
+ })
751
313
 
752
- ##### 5️⃣ Request Payment
314
+ sock.ev.on('group-participants.update', async (event) => {
315
+ const metadata = await sock.groupMetadata(event.id)
316
+ groupCache.set(event.id, metadata)
317
+ })
318
+ ```
753
319
 
754
- ```javascript
755
- sock.sendMessage(jid, {
756
- text: '💳 Request Payment',
757
- requestPaymentFrom: '0@s.whatsapp.net'
758
- })
759
- ```
320
+ ### Improve Retry System & Decrypt Poll Votes
321
+ - If you want to improve sending message, retrying when error occurs and decrypt poll votes, you need to have a store and set `getMessage` config in socket like this:
322
+ ```ts
323
+ const sock = makeWASocket({
324
+ getMessage: async (key) => await getMessageFromStore(key)
325
+ })
326
+ ```
760
327
 
761
- #### 👁️ Other Message Options
328
+ ### Receive Notifications in Whatsapp App
329
+ - If you want to receive notifications in whatsapp app, set `markOnlineOnConnect` to `false`
330
+ ```ts
331
+ const sock = makeWASocket({
332
+ markOnlineOnConnect: false
333
+ })
334
+ ```
335
+ ## Saving & Restoring Sessions
762
336
 
763
- ##### 1️⃣ AI Label
337
+ You obviously don't want to keep scanning the QR code every time you want to connect.
764
338
 
765
- > [!NOTE]
766
- It only works in private chat (`@s.whatsapp.net`).
767
-
768
- ```javascript
769
- sock.sendMessage(jid, {
770
- image: {
771
- url: './path/to/image.jpg'
772
- },
773
- caption: '🤖 AI Labeled!',
774
- ai: true
775
- }, {
776
- quoted: message
777
- })
778
- ```
339
+ So, you can load the credentials to log back in:
340
+ ```ts
341
+ import makeWASocket, { useMultiFileAuthState } from '@blckrose/baileys'
779
342
 
780
- ##### 2️⃣ Ephemeral
343
+ const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
781
344
 
782
- > [!NOTE]
783
- Wrap message into `ephemeralMessage`
784
-
785
- ```javascript
786
- sock.sendMessage(jid, {
787
- image: {
788
- url: './path/to/image.jpg'
789
- },
790
- caption: '👁️ Ephemeral',
791
- ephemeral: true
792
- })
793
- ```
794
-
795
- ##### 3️⃣ External Ad Reply
345
+ // will use the given state to connect
346
+ // so if valid credentials are available -- it'll connect without QR
347
+ const sock = makeWASocket({ auth: state })
796
348
 
797
- > [!NOTE]
798
- Add an ad thumbnail to messages (may not be displayed on some WhatsApp versions).
799
-
800
- ```javascript
801
- sock.sendMessage(jid, {
802
- text: '📰 External Ad Reply',
803
- externalAdReply: {
804
- title: '📝 Did you know?',
805
- body: '❓ I dont know',
806
- thumbnail: fs.readFileSync('./path/to/image.jpg'), // --- Must in buffer format
807
- largeThumbnail: false, // --- Or true for bigger thumbnail
808
- url: 'https://www.npmjs.com/package/baileys' // --- Optional, used for WhatsApp internal thumbnail caching and direct URL
809
- }
810
- }, {
811
- quoted: message
812
- })
349
+ // this will be called as soon as the credentials are updated
350
+ sock.ev.on('creds.update', saveCreds)
813
351
  ```
814
352
 
815
- ##### 4️⃣ Group Status
353
+ > [!IMPORTANT]
354
+ > `useMultiFileAuthState` is a utility function to help save the auth state in a single folder, this function serves as a good guide to help write auth & key states for SQL/no-SQL databases, which I would recommend in any production grade system.
816
355
 
817
356
  > [!NOTE]
818
- It only works in group chat (`@g.us`)
819
-
820
- ```javascript
821
- sock.sendMessage(jid, {
822
- image: {
823
- url: './path/to/image.jpg'
824
- },
825
- caption: '👥 Group Status!',
826
- groupStatus: true
827
- })
828
- ```
829
-
830
- ##### 5️⃣ Raw
831
-
832
- ```javascript
833
- sock.sendMessage(jid, {
834
- extendedTextMessage: {
835
- text: '📃 Built manually from scratch using the raw WhatsApp proto structure',
836
- contextInfo: {
837
- externalAdReply: {
838
- title: 'violetics',
839
- thumbnail: fs.readFileSync('./path/to/image.jpg'),
840
- sourceApp: 'whatsapp',
841
- showAdAttribution: true,
842
- mediaType: 1
843
- }
844
- }
845
- },
846
- raw: true
847
- }, {
848
- quoted: message
849
- })
850
- ```
357
+ > When a message is received/sent, due to signal sessions needing updating, the auth keys (`authState.keys`) will update. Whenever that happens, you must save the updated keys (`authState.keys.set()` is called). Not doing so will prevent your messages from reaching the recipient & cause other unexpected consequences. The `useMultiFileAuthState` function automatically takes care of that, but for any other serious implementation -- you will need to be very careful with the key state management.
851
358
 
852
- ##### 6️⃣ View Once
359
+ ## Handling Events
853
360
 
854
- > [!NOTE]
855
- Wrap message into `viewOnceMessage`
856
-
857
- ```javascript
858
- sock.sendMessage(jid, {
859
- image: {
860
- url: './path/to/image.jpg'
861
- },
862
- caption: '👁️ View Once',
863
- viewOnce: true
864
- })
865
- ```
361
+ - Baileys uses the EventEmitter syntax for events.
362
+ They're all nicely typed up, so you shouldn't have any issues with an Intellisense editor like VS Code.
866
363
 
867
- ##### 7️⃣ View Once V2
364
+ > [!IMPORTANT]
365
+ > **The events are [these](https://baileys.whiskeysockets.io/types/BaileysEventMap.html)**, it's important you see all events
868
366
 
869
- > [!NOTE]
870
- Wrap message into `viewOnceMessageV2`
871
-
872
- ```javascript
873
- sock.sendMessage(jid, {
874
- image: {
875
- url: './path/to/image.jpg'
876
- },
877
- caption: '👁️ View Once V2',
878
- viewOnceV2: true
367
+ You can listen to these events like this:
368
+ ```ts
369
+ const sock = makeWASocket()
370
+ sock.ev.on('messages.upsert', ({ messages }) => {
371
+ console.log('got messages', messages)
879
372
  })
880
373
  ```
881
374
 
882
- ##### 8️⃣ View Once V2 Extension
375
+ ### Example to Start
883
376
 
884
377
  > [!NOTE]
885
- Wrap message into `viewOnceMessageV2Extension`
886
-
887
- ```javascript
888
- sock.sendMessage(jid, {
889
- image: {
890
- url: './path/to/image.jpg'
891
- },
892
- caption: '👁️ View Once V2 Extension',
893
- viewOnceV2Extension: true
894
- })
895
- ```
896
-
897
- #### 🧰 Additional Contents
898
-
899
- ##### 🏷️ Find User ID (JID|PN/LID)
378
+ > This example includes basic auth storage too
900
379
 
901
380
  > [!NOTE]
902
- The ID must contain numbers only (no +, (), or -) and must include the country code with WhatsApp ID format.
381
+ > For reliable serialization of the authentication state, especially when storing as JSON, always use the BufferJSON utility.
903
382
 
904
- ```javascript
905
- // --- PN (Phone Number)
906
- const phoneNumber = '6281111111111@s.whatsapp.net'
907
-
908
- const ids = await sock.findUserId(phoneNumber)
909
-
910
- console.log('🏷️ Got user ID', ':', ids)
911
-
912
- // --- LID (Local Identifier)
913
- const lid = '43411111111111@lid'
914
-
915
- const ids = await sock.findUserId(lid)
916
-
917
- console.log('🏷️ Got user ID', ':', ids)
383
+ ```ts
384
+ import makeWASocket, { DisconnectReason, useMultiFileAuthState } from '@blckrose/baileys'
385
+ import { Boom } from '@hapi/boom'
918
386
 
919
- // --- Output
920
- // {
921
- // phoneNumber: '6281111111111@s.whatsapp.net',
922
- // lid: '43411111111111@lid'
923
- // }
924
- // --- Output when failed
925
- // {
926
- // phoneNumber: '6281111111111@s.whatsapp.net',
927
- // lid: 'id-not-found'
928
- // }
929
- // --- Same output shape regardless of input type
387
+ async function connectToWhatsApp () {
388
+ const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
389
+ const sock = makeWASocket({
390
+ // can provide additional config here
391
+ auth: state,
392
+ printQRInTerminal: true
393
+ })
394
+ sock.ev.on('connection.update', (update) => {
395
+ const { connection, lastDisconnect } = update
396
+ if(connection === 'close') {
397
+ const shouldReconnect = (lastDisconnect.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut
398
+ console.log('connection closed due to ', lastDisconnect.error, ', reconnecting ', shouldReconnect)
399
+ // reconnect if not logged out
400
+ if(shouldReconnect) {
401
+ connectToWhatsApp()
402
+ }
403
+ } else if(connection === 'open') {
404
+ console.log('opened connection')
405
+ }
406
+ })
407
+ sock.ev.on('messages.upsert', event => {
408
+ for (const m of event.messages) {
409
+ console.log(JSON.stringify(m, undefined, 2))
410
+
411
+ console.log('replying to', m.key.remoteJid)
412
+ await sock.sendMessage(m.key.remoteJid!, { text: 'Hello Word' })
413
+ }
414
+ })
415
+
416
+ // to storage creds (session info) when it updates
417
+ sock.ev.on('creds.update', saveCreds)
418
+ }
419
+ // run in main file
420
+ connectToWhatsApp()
930
421
  ```
931
422
 
932
- ##### 🔑 Request Custom Pairing Code
933
-
934
- > [!NOTE]
935
- The phone number must contain numbers only (no +, (), or -) and must include the country code.
936
-
937
- ```javascript
938
- const phoneNumber = '6281111111111'
939
- const customPairingCode = 'STARFALL'
423
+ ### For example if you use useSingleFileAuthState and useMongoFileAuthState
424
+ ```ts
425
+ import makeWASocket, { useSingleFileAuthState, useMongoFileAuthState } from '@blckrose/baileys'
426
+
427
+ // Single Auth
428
+ const { state, saveState } = await useSingleFileAuthState('./auth_info_baileys.json')
429
+ const sock = makeWASocket({
430
+ auth: state,
431
+ printQRInTerminal: true
432
+ })
433
+
434
+ sock.ev.on('creds.update', saveState)
435
+
436
+ // Mongo Auth
437
+ import { MongoClient } from "mongodb"
438
+
439
+ const connectAuth = async() => {
440
+ global.client = new MongoClient('mongoURL')
441
+ global.client.connect(err => {
442
+ if (err) {
443
+ console.warn("Warning: MongoDB link is invalid or cannot be connected.")
444
+ } else {
445
+ console.log('Successfully Connected To MongoDB Server')
446
+ }
447
+ })
448
+ await client.connect()
449
+ const collection = client.db("@blckrose").collection("sessions")
450
+ return collection
451
+ }
940
452
 
941
- await sock.requestPairingCode(phoneNumber, customPairingCode)
453
+ const Authentication = await connectAuth()
454
+ const { state, saveCreds } = await useMongoFileAuthState(Authentication)
455
+ const sock = makeWASocket({
456
+ auth: state,
457
+ printQRInTerminal: true
458
+ })
942
459
 
943
- console.log('🔗 Pairing code', ':', customPairingCode)
460
+ sock.ev.on('creds.update', saveCreds)
944
461
  ```
945
462
 
946
- ##### 📣 Newsletter Management
947
-
948
- ```javascript
949
- // --- Create a new one
950
- sock.newsletterCreate('violetics')
951
-
952
- // --- Get info
953
- sock.newsletterMetadata('1231111111111@newsletter')
954
-
955
- // --- Demote admin
956
- sock.newsletterDemote('1231111111111@newsletter', '6281111111111@s.whatsapp.net')
957
-
958
- // --- Change owner
959
- sock.newsletterChangeOwner('1231111111111@newsletter', '6281111111111@s.whatsapp.net')
960
-
961
- // --- Change name
962
- sock.newsletterUpdateName('1231111111111@newsletter', '📦 violetics')
463
+ > [!IMPORTANT]
464
+ > In `messages.upsert` it's recommended to use a loop like `for (const message of event.messages)` to handle all messages in array
963
465
 
964
- // --- Change description
965
- sock.newsletterUpdateDescription('1231111111111@newsletter', '📣 Fresh updates weekly')
466
+ ### Decrypt Poll Votes
966
467
 
967
- // --- Change photo
968
- sock.newsletterUpdatePicture('1231111111111@newsletter', {
969
- url: 'path/to/image.jpg'
468
+ - By default poll votes are encrypted and handled in `messages.update`
469
+ - That's a simple example
470
+ ```ts
471
+ sock.ev.on('messages.update', event => {
472
+ for(const { key, update } of event) {
473
+ if(update.pollUpdates) {
474
+ const pollCreation = await getMessage(key)
475
+ if(pollCreation) {
476
+ console.log(
477
+ 'got poll update, aggregation: ',
478
+ getAggregateVotesInPollMessage({
479
+ message: pollCreation,
480
+ pollUpdates: update.pollUpdates,
481
+ })
482
+ )
483
+ }
484
+ }
485
+ }
970
486
  })
971
-
972
- // --- Remove photo
973
- sock.newsletterRemovePicture('1231111111111@newsletter')
974
-
975
- // --- React to a message
976
- sock.newsletterReactMessage('1231111111111@newsletter', '100', '💛')
977
-
978
- // --- Get all subscribed newsletters
979
- const newsletters = await sock.newsletterSubscribed()
980
-
981
- console.dir(newsletters, { depth: null })
982
487
  ```
983
488
 
984
- ##### 👥 Group Management
985
-
986
- ```javascript
987
- // --- Create a new one and add participants using their JIDs
988
- sock.groupCreate('violetics', ['628123456789@s.whatsapp.net'])
989
-
990
- // --- Get info
991
- sock.groupMetadata(jid)
489
+ - `getMessage` is a [store](#implementing-a-data-store) implementation (in your end)
992
490
 
993
- // --- Get invite code
994
- sock.groupInviteCode(jid)
491
+ ### Summary of Events on First Connection
995
492
 
996
- // --- Revoke invite link
997
- sock.groupRevokeInvite(jid)
493
+ 1. When you connect first time, `connection.update` will be fired requesting you to restart sock
494
+ 2. Then, history messages will be received in `messaging.history-set`
998
495
 
999
- // --- Leave group
1000
- sock.groupLeave(jid)
496
+ ## Implementing a Data Store
1001
497
 
1002
- // --- Add participants
1003
- sock.groupParticipantsUpdate(jid, ['628123456789@s.whatsapp.net'], 'add')
498
+ - Baileys does not come with a defacto storage for chats, contacts, or messages. However, a simple in-memory implementation has been provided. The store listens for chat updates, new messages, message updates, etc., to always have an up-to-date version of the data.
1004
499
 
1005
- // --- Remove participants
1006
- sock.groupParticipantsUpdate(jid, ['628123456789@s.whatsapp.net'], 'remove')
1007
-
1008
- // --- Promote to admin
1009
- sock.groupParticipantsUpdate(jid, ['628123456789@s.whatsapp.net'], 'promote')
500
+ > [!IMPORTANT]
501
+ > I highly recommend building your own data store, as storing someone's entire chat history in memory is a terrible waste of RAM.
1010
502
 
1011
- // --- Demote from admin
1012
- sock.groupParticipantsUpdate(jid, ['628123456789@s.whatsapp.net'], 'demote')
503
+ It can be used as follows:
1013
504
 
1014
- // --- Change name
1015
- sock.groupUpdateSubject(jid, '📦 violetics')
505
+ ```ts
506
+ import makeWASocket, { makeInMemoryStore } from '@blckrose/baileys'
507
+ // the store maintains the data of the WA connection in memory
508
+ // can be written out to a file & read from it
509
+ const store = makeInMemoryStore({ })
510
+ // can be read from a file
511
+ store.readFromFile('./baileys_store.json')
512
+ // saves the state to a file every 10s
513
+ setInterval(() => {
514
+ store.writeToFile('./baileys_store.json')
515
+ }, 10_000)
1016
516
 
1017
- // --- Change description
1018
- sock.groupUpdateDescription(jid, 'Updated description')
517
+ const sock = makeWASocket({ })
518
+ // will listen from this socket
519
+ // the store can listen from a new socket once the current socket outlives its lifetime
520
+ store.bind(sock.ev)
1019
521
 
1020
- // --- Change photo
1021
- sock.updateProfilePicture(jid, {
1022
- url: 'path/to/image.jpg'
522
+ sock.ev.on('chats.upsert', () => {
523
+ // can use 'store.chats' however you want, even after the socket dies out
524
+ // 'chats' => a KeyedDB instance
525
+ console.log('got chats', store.chats.all())
1023
526
  })
1024
527
 
1025
- // --- Remove photo
1026
- sock.removeProfilePicture(jid)
1027
-
1028
- // --- Set group as admin only for chatting
1029
- sock.groupSettingUpdate(jid, 'announcement')
1030
-
1031
- // --- Set group as open to all for chatting
1032
- sock.groupSettingUpdate(jid, 'not_announcement')
1033
-
1034
- // --- Set admin only can edit group info
1035
- sock.groupSettingUpdate(jid, 'locked')
1036
-
1037
- // --- Set all participants can edit group info
1038
- sock.groupSettingUpdate(jid, 'unlocked')
1039
-
1040
- // --- Set admin only can add participants
1041
- sock.groupMemberAddMode(jid, 'admin_add')
1042
-
1043
- // --- Set all participants can add participants
1044
- sock.groupMemberAddMode(jid, 'all_member_add')
1045
-
1046
- // --- Enable or disable temporary messages with seconds format
1047
- sock.groupToggleEphemeral(jid, 86400)
1048
-
1049
- // --- Disable temporary messages
1050
- sock.groupToggleEphemeral(jid, 0)
1051
-
1052
- // --- Enable or disable membership approval mode
1053
- sock.groupJoinApprovalMode(jid, 'on')
1054
- sock.groupJoinApprovalMode(jid, 'off')
1055
-
1056
- // --- Get all groups metadata
1057
- const groups = await sock.groupFetchAllParticipating()
528
+ sock.ev.on('contacts.upsert', () => {
529
+ console.log('got contacts', Object.values(store.contacts))
530
+ })
1058
531
 
1059
- console.dir(groups, { depth: null })
532
+ ```
1060
533
 
1061
- // --- Get pending invites
1062
- const invites = await sock.groupGetInviteInfo(code)
534
+ The store also provides some simple functions such as `loadMessages` that utilize the store to speed up data retrieval.
1063
535
 
1064
- console.dir(invites, { depth: null })
536
+ ## Whatsapp IDs Explain
1065
537
 
1066
- // --- Accept group invite
1067
- sock.groupAcceptInvite(code)
538
+ - `id` is the WhatsApp ID, called `jid` too, of the person or group you're sending the message to.
539
+ - It must be in the format ```[country code][phone number]@s.whatsapp.net```
540
+ - Example for people: ```+19999999999@s.whatsapp.net```.
541
+ - For groups, it must be in the format ``` 123456789-123345@g.us ```.
542
+ - For broadcast lists, it's `[timestamp of creation]@broadcast`.
543
+ - For stories, the ID is `status@broadcast`.
1068
544
 
1069
- // --- Get group info from link
1070
- const group = await sock.groupGetInviteInfo('https://chat.whatsapp.com/ABC123')
545
+ ## Utility Functions
1071
546
 
1072
- console.log('👥 Got group info from link', ':', group)
547
+ ### Resize Image
548
+ ```ts
549
+ // Resize an image (Buffer, URL, or stream) to given dimensions
550
+ const resized = await sock.resize('https://example.com/image.jpg', 320, 320)
551
+ // or
552
+ const resized = await sock.resize(buffer, 320, 320)
1073
553
  ```
1074
554
 
1075
- ## 📦 Fork Base
1076
- > [!NOTE]
1077
- This fork is based on [Baileys (GitHub)](https://github.com/WhiskeySockets/Baileys)
555
+ - `getContentType`, returns the content type for any message
556
+ - `getDevice`, returns the device from message
557
+ - `makeCacheableSignalKeyStore`, make auth store more fast
558
+ - `downloadContentFromMessage`, download content from any message
559
+ - `makeNewsletterUtils`, helper lengkap untuk kirim ke newsletter/channel
560
+ - `resolveJid`, resolve LID / participant ID ke JID @s.whatsapp.net
561
+ - `resolveJids`, resolve banyak JID sekaligus
1078
562
 
1079
- ## 📣 Credits
1080
- > [!IMPORTANT]
1081
- This fork uses Protocol Buffer definitions maintained by [WPP Connect](https://github.com/wppconnect-team) via [`wa-proto`](https://github.com/wppconnect-team/wa-proto)
1082
- >
1083
- > All rights belong to the original Baileys maintainers and contributors:
1084
- > - [WhiskeySockets/Baileys](https://github.com/WhiskeySockets/Baileys)
1085
- > - [purpshell](https://github.com/purpshell)
1086
- > - [jlucaso1](https://github.com/jlucaso1)
1087
- > - [adiwajshing](https://github.com/adiwajshing)
563
+ ---
564
+
565
+ <p align="center">Made with by <a href="https://github.com/blckrose">@blckrose</a></p>