violetics 7.0.7-alpha → 7.0.9-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 (411) hide show
  1. package/LICENSE +1 -2
  2. package/README.md +493 -980
  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 +2670 -9199
  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 +14 -22
  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 +2 -1
  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 +154 -69
  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 +471 -253
  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 +620 -226
  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 +109 -62
  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 +12 -3
  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 +2 -1
  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 -6
  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 +7 -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 +2 -1
  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 +185 -185
  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 +932 -1120
  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 -1
  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 +55 -77
  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 +14 -113
  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 +5 -2
  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 -53
  406. package/.github/workflows/publish.yml +0 -75
  407. package/.pnp.cjs +0 -8572
  408. package/.pnp.loader.mjs +0 -2126
  409. package/.yarn/install-state.gz +0 -0
  410. package/lib/Utils/offline-node-processor.js +0 -39
  411. package/lib/Utils/stanza-ack.js +0 -37
package/README.md CHANGED
@@ -1,1087 +1,600 @@
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.
5
+ > [!CAUTION]
6
+ > NOTICE OF BREAKING CHANGE.
29
7
  >
30
- > 😞 And, really sorry for my bad english.
31
-
32
- ### 📥 Installation
8
+ > As of 1.0.0, multiple breaking changes were introduced into the library.
9
+ >
10
+ > Please check out https://whiskey.so/migrate-latest for more information.
33
11
 
34
- - 📄 Via `package.json`
12
+ # Important Note
35
13
 
36
- ```json
37
- # NPM
38
- "dependencies": {
39
- "violetics": "latest"
40
- }
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).
41
15
 
42
- # GitHub
43
- "dependencies": {
44
- "violetics": "github:cv3inx/violetics"
45
- }
46
- ```
16
+ New guide link: https://baileys.wiki
47
17
 
48
- - ⌨️ Via terminal
18
+ # Get Support
49
19
 
50
- ```bash
51
- # NPM
52
- npm i violetics@latest
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.
53
21
 
54
- # GitHub
55
- npm i github:cv3inx/violetics
56
- ```
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.
57
23
 
58
- #### 🧩 Import (ESM & CJS)
24
+ # Sponsor
59
25
 
60
- ```javascript
61
- // --- ESM
62
- import { makeWASocket } from 'violetics'
26
+ If you'd like to financially support this project, you can do so by supporting the current maintainer [here](https://purpshell.dev/sponsor).
63
27
 
64
- // --- CJS (tested and working on Node.js 24 ✅)
65
- const { makeWASocket } = require('violetics')
66
- ```
28
+ # Disclaimer
67
29
 
68
- ### 🔧 Usage
30
+ 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.
31
+ 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.
69
32
 
70
- #### 🌐 Connect to WhatsApp (Quick Step)
33
+ 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.
34
+ Use at your own discretion. Do not spam people with this. We discourage any stalkerware, bulk or automated messaging usage.
71
35
 
72
- ```javascript
73
- import { makeWASocket, delay, DisconnectReason, useMultiFileAuthState } from 'violetics'
74
- import { Boom } from '@hapi/boom'
75
- import pino from 'pino'
36
+ ##
76
37
 
77
- // --- Connect with pairing code
78
- const myPhoneNumber = '6288888888888'
38
+ - Baileys does not require Selenium or any other browser to be interface with WhatsApp Web, it does so directly using a **WebSocket**.
39
+ - Not running Selenium or Chromium saves you like **half a gig** of ram :/
40
+ - Baileys supports interacting with the multi-device & web versions of WhatsApp.
41
+ - 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.
79
42
 
80
- const logger = pino({ level: 'silent' })
43
+ > [!IMPORTANT]
44
+ > The original repository had to be removed by the original author - we now continue development in this repository here.
45
+ > This is the only official repository and is maintained by the community.
46
+ > **Join the Discord [here](https://discord.gg/WeJM5FP9GG)**
81
47
 
82
- const connectToWhatsApp = async () => {
83
- const { state, saveCreds } = await useMultiFileAuthState('session')
84
-
85
- const sock = makeWASocket({
86
- logger,
87
- auth: state
88
- })
48
+ ## Example
89
49
 
90
- sock.ev.on('creds.update', saveCreds)
50
+ Do check out & run [example.ts](Example/example.ts) to see an example usage of the library.
51
+ The script covers most common use cases.
52
+ To run the example script, download or clone the repo and then type the following in a terminal:
91
53
 
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
- })
54
+ 1. `cd path/to/Baileys`
55
+ 2. `yarn`
56
+ 3. `yarn example`
110
57
 
111
- sock.ev.on('messages.upsert', async ({ messages }) => {
112
- for (const message of messages) {
113
- if (!message.message) continue
58
+ ## Install
114
59
 
115
- console.log('🔔 Got new message', ':', message)
116
- await sock.sendMessage(message.key.remoteJid, {
117
- text: '👋🏻 Hello world'
118
- })
119
- }
120
- })
121
- }
60
+ Install dari file `.tgz` lokal (versi modified blckrose):
122
61
 
123
- connectToWhatsApp()
62
+ ```
63
+ npm install ./blckrose-baileys-1.2.9.tgz
124
64
  ```
125
65
 
126
- #### 🗄️ Implementing a Data Store
127
-
128
- > [!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)
66
+ Atau tambahkan ke `package.json`:
189
67
 
190
- // --- Save store every 3 minutes
191
- setInterval(() => {
192
- store.writeToFile(storePath)
193
- }, 180000)
68
+ ```json
69
+ {
70
+ "dependencies": {
71
+ "violetics": ""
72
+ }
194
73
  }
195
-
196
- connectToWhatsApp()
197
74
  ```
198
75
 
199
- #### 🪪 WhatsApp IDs Explain
200
-
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`.
208
-
209
- #### ✉️ Sending Messages
76
+ Kemudian jalankan:
77
+
78
+ ```
79
+ npm install
80
+ ```
81
+
82
+ **ESM:**
83
+
84
+ ```ts
85
+ import makeWASocket from "violetics";
86
+ ```
87
+
88
+ **CJS (destructure langsung, tanpa top-level await):**
89
+
90
+ ```js
91
+ const {
92
+ makeWASocket,
93
+ useMultiFileAuthState,
94
+ Browsers,
95
+ DisconnectReason,
96
+ } = require("violetics");
97
+ // global apocalypse otomatis tersedia setelah baris di atas
98
+ ```
99
+
100
+ # Links
101
+
102
+ - [Discord](https://discord.gg/WeJM5FP9GG)
103
+ - [Docs](https://guide.whiskeysockets.io/)
104
+
105
+ # Index
106
+
107
+ - [Connecting Account](#connecting-account)
108
+ - [Connect with QR-CODE](#starting-socket-with-qr-code)
109
+ - [Connect with Pairing Code](#starting-socket-with-pairing-code)
110
+ - [Receive Full History](#receive-full-history)
111
+ - [Important Notes About Socket Config](#important-notes-about-socket-config)
112
+ - [Caching Group Metadata (Recommended)](#caching-group-metadata-recommended)
113
+ - [Improve Retry System & Decrypt Poll Votes](#improve-retry-system--decrypt-poll-votes)
114
+ - [Receive Notifications in Whatsapp App](#receive-notifications-in-whatsapp-app)
115
+
116
+ - [Save Auth Info](#saving--restoring-sessions)
117
+ - [Handling Events](#handling-events)
118
+ - [Example to Start](#example-to-start)
119
+ - [Decrypt Poll Votes](#decrypt-poll-votes)
120
+ - [Summary of Events on First Connection](#summary-of-events-on-first-connection)
121
+ - [Implementing a Data Store](#implementing-a-data-store)
122
+ - [Whatsapp IDs Explain](#whatsapp-ids-explain)
123
+ - [Utility Functions](#utility-functions)
124
+ - [Newsletter / Channel](#newsletter--channel)
125
+ - [Kirim Media ke Channel](#kirim-media-ke-channel)
126
+ - [Button di Channel](#button-di-channel)
127
+ - [Edit & Hapus Pesan Channel](#edit--hapus-pesan-channel)
128
+ - [Resolve JID (LID → Phone)](#resolve-jid)
129
+ - [Sending Messages](#sending-messages)
130
+ - [Non-Media Messages](#non-media-messages)
131
+ - [Text Message](#text-message)
132
+ - [Quote Message](#quote-message-works-with-all-types)
133
+ - [Mention User](#mention-user-works-with-most-types)
134
+ - [Forward Messages](#forward-messages)
135
+ - [Location Message](#location-message)
136
+ - [Live Location Message](#live-location-message)
137
+ - [Contact Message](#contact-message)
138
+ - [Reaction Message](#reaction-message)
139
+ - [Pin Message](#pin-message)
140
+ - [Keep Message](#keep-message)
141
+ - [Poll Message](#poll-message)
142
+ - [Poll Result Message](#poll-result-message)
143
+ - [Call Message](#call-message)
144
+ - [Event Message](#event-message)
145
+ - [Order Message](#order-message)
146
+ - [Product Message](#product-message)
147
+ - [Payment Message](#payment-message)
148
+ - [Payment Invite Message](#payment-invite-message)
149
+ - [Admin Invite Message](#admin-invite-message)
150
+ - [Group Invite Message](#group-invite-message)
151
+ - [Sticker Pack Message](#sticker-pack-message)
152
+ - [Share Phone Number Message](#share-phone-number-message)
153
+ - [Request Phone Number Message](#request-phone-number-message)
154
+ - [Buttons Reply Message](#buttons-reply-message)
155
+ - [Buttons Message](#buttons-message)
156
+ - [Buttons List Message](#buttons-list-message)
157
+ - [Buttons Product List Message](#buttons-product-list-message)
158
+ - [Buttons Cards Message](#buttons-cards-message)
159
+ - [Buttons Template Message](#buttons-template-message)
160
+ - [Buttons Interactive Message](#buttons-interactive-message)
161
+ - [Buttons Interactive Message PIX](#buttons-interactive-message-pix)
162
+ - [Buttons Interactive Message PAY](#buttons-interactive-message-pay)
163
+ - [Status Mentions Message](#status-mentions-message)
164
+ - [Shop Message](#shop-message)
165
+ - [Collection Message](#collection-message)
166
+ - [AI Icon Feature](#ai-icon-feature)
167
+ - [Sending with Link Preview](#sending-messages-with-link-previews)
168
+ - [Media Messages](#media-messages)
169
+ - [Gif Message](#gif-message)
170
+ - [Video Message](#video-message)
171
+ - [Audio Message](#audio-message)
172
+ - [Image Message](#image-message)
173
+ - [Album Message](#album-message)
174
+ - [Ptv Video Message](#ptv-video-message)
175
+ - [View Once Message](#view-once-message)
176
+ - [Modify Messages](#modify-messages)
177
+ - [Delete Messages (for everyone)](#deleting-messages-for-everyone)
178
+ - [Edit Messages](#editing-messages)
179
+ - [Manipulating Media Messages](#manipulating-media-messages)
180
+ - [Thumbnail in Media Messages](#thumbnail-in-media-messages)
181
+ - [Downloading Media Messages](#downloading-media-messages)
182
+ - [Re-upload Media Message to Whatsapp](#re-upload-media-message-to-whatsapp)
183
+ - [Reject Call](#reject-call)
184
+ - [Send States in Chat](#send-states-in-chat)
185
+ - [Reading Messages](#reading-messages)
186
+ - [Update Presence](#update-presence)
187
+ - [Modifying Chats](#modifying-chats)
188
+ - [Archive a Chat](#archive-a-chat)
189
+ - [Mute/Unmute a Chat](#muteunmute-a-chat)
190
+ - [Mark a Chat Read/Unread](#mark-a-chat-readunread)
191
+ - [Delete a Message for Me](#delete-a-message-for-me)
192
+ - [Delete a Chat](#delete-a-chat)
193
+ - [Star/Unstar a Message](#starunstar-a-message)
194
+ - [Disappearing Messages](#disappearing-messages)
195
+ - [Clear Messages](#clear-messages)
196
+ - [User Querys](#user-querys)
197
+ - [Check If ID Exists in Whatsapp](#check-if-id-exists-in-whatsapp)
198
+ - [Query Chat History (groups too)](#query-chat-history-groups-too)
199
+ - [Fetch Status](#fetch-status)
200
+ - [Fetch Profile Picture (groups too)](#fetch-profile-picture-groups-too)
201
+ - [Fetch Bussines Profile (such as description or category)](#fetch-bussines-profile-such-as-description-or-category)
202
+ - [Fetch Someone's Presence (if they're typing or online)](#fetch-someones-presence-if-theyre-typing-or-online)
203
+ - [Change Profile](#change-profile)
204
+ - [Change Profile Status](#change-profile-status)
205
+ - [Change Profile Name](#change-profile-name)
206
+ - [Change Display Picture (groups too)](#change-display-picture-groups-too)
207
+ - [Remove display picture (groups too)](#remove-display-picture-groups-too)
208
+ - [Groups](#groups)
209
+ - [Create a Group](#create-a-group)
210
+ - [Add/Remove or Demote/Promote](#addremove-or-demotepromote)
211
+ - [Change Subject (name)](#change-subject-name)
212
+ - [Change Description](#change-description)
213
+ - [Change Settings](#change-settings)
214
+ - [Leave a Group](#leave-a-group)
215
+ - [Get Invite Code](#get-invite-code)
216
+ - [Revoke Invite Code](#revoke-invite-code)
217
+ - [Join Using Invitation Code](#join-using-invitation-code)
218
+ - [Get Group Info by Invite Code](#get-group-info-by-invite-code)
219
+ - [Query Metadata (participants, name, description...)](#query-metadata-participants-name-description)
220
+ - [Join using groupInviteMessage](#join-using-groupinvitemessage)
221
+ - [Get Request Join List](#get-request-join-list)
222
+ - [Approve/Reject Request Join](#approvereject-request-join)
223
+ - [Get All Participating Groups Metadata](#get-all-participating-groups-metadata)
224
+ - [Toggle Ephemeral](#toggle-ephemeral)
225
+ - [Change Add Mode](#change-add-mode)
226
+ - [Privacy](#privacy)
227
+ - [Block/Unblock User](#blockunblock-user)
228
+ - [Get Privacy Settings](#get-privacy-settings)
229
+ - [Get BlockList](#get-blocklist)
230
+ - [Update LastSeen Privacy](#update-lastseen-privacy)
231
+ - [Update Online Privacy](#update-online-privacy)
232
+ - [Update Profile Picture Privacy](#update-profile-picture-privacy)
233
+ - [Update Status Privacy](#update-status-privacy)
234
+ - [Update Read Receipts Privacy](#update-read-receipts-privacy)
235
+ - [Update Groups Add Privacy](#update-groups-add-privacy)
236
+ - [Update Default Disappearing Mode](#update-default-disappearing-mode)
237
+ - [Broadcast Lists & Stories](#broadcast-lists--stories)
238
+ - [Send Broadcast & Stories](#send-broadcast--stories)
239
+ - [Query a Broadcast List's Recipients & Name](#query-a-broadcast-lists-recipients--name)
240
+ - [Writing Custom Functionality](#writing-custom-functionality)
241
+ - [Enabling Debug Level in Baileys Logs](#enabling-debug-level-in-baileys-logs)
242
+ - [How Whatsapp Communicate With Us](#how-whatsapp-communicate-with-us)
243
+ - [Register a Callback for Websocket Events](#register-a-callback-for-websocket-events)
244
+
245
+ ## Connecting Account
246
+
247
+ 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.
210
248
 
211
249
  > [!NOTE]
212
- You can get the `jid` from `message.key.remoteJid` in the first example.
250
+ > **[Here](#example-to-start) is a simple example of event handling**
213
251
 
214
- ##### 🔠 Text
215
-
216
- ```javascript
217
- sock.sendMessage(jid, {
218
- text: '👋🏻 Hello'
219
- }, {
220
- quoted: message
221
- })
222
- ```
252
+ > [!TIP]
253
+ > **You can see all supported socket configs [here](https://baileys.whiskeysockets.io/types/SocketConfig.html) (Recommended)**
223
254
 
224
- ##### 🔔 Mention
225
-
226
- ```javascript
227
- // --- Regular mention
228
- sock.sendMessage(jid, {
229
- text: '👋🏻 Hello @628123456789',
230
- mentions: ['628123456789@s.whatsapp.net']
231
- }, {
232
- quoted: message
233
- })
234
-
235
- // --- Mention all
236
- sock.sendMessage(jid, {
237
- text: '👋🏻 Hello @all',
238
- mentionAll: true
239
- }, {
240
- quoted: message
241
- })
242
- ```
255
+ ### Starting socket with **QR-CODE**
243
256
 
244
- ##### 😁 Reaction
245
-
246
- ```javascript
247
- sock.sendMessage(jid, {
248
- react: {
249
- key: message.key,
250
- text: '✨'
251
- }
252
- }, {
253
- quoted: message
254
- })
255
- ```
257
+ > [!TIP]
258
+ > 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)**
256
259
 
257
- ##### 📌 Pin Message
260
+ ```ts
261
+ import makeWASocket from "violetics";
258
262
 
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
- })
263
+ const sock = makeWASocket({
264
+ // can provide additional config here
265
+ browser: Browsers.ubuntu("My App"),
266
+ printQRInTerminal: true,
267
+ });
267
268
  ```
268
269
 
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
- ```
270
+ 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!
290
271
 
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
- })
303
- ```
272
+ ### Starting socket with **Pairing Code**
304
273
 
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
- })
362
- ```
274
+ > [!IMPORTANT]
275
+ > 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)
363
276
 
364
- ##### 🎞️ Status Mention
277
+ The phone number can't have `+` or `()` or `-`, only numbers, you must provide country code
365
278
 
366
- ```javascript
367
- sock.sendMessage([jidA, jidB, jidC], {
368
- text: 'Hello! 👋🏻'
369
- })
370
- ```
279
+ ```ts
280
+ import makeWASocket from "violetics";
371
281
 
372
- #### 📁 Sending Media Messages
282
+ const sock = makeWASocket({
283
+ // can provide additional config here
284
+ printQRInTerminal: false, //need to be false
285
+ });
373
286
 
374
- > [!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
- })
287
+ if (!sock.authState.creds.registered) {
288
+ const number = "XXXXXXXXXXX";
289
+ const code = await sock.requestPairingCode(number);
290
+ console.log(code);
291
+ }
388
292
  ```
389
293
 
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
- ```
294
+ ### Receive Full History
404
295
 
405
- ##### 📃 Sticker
296
+ 1. Set `syncFullHistory` as `true`
297
+ 2. Baileys, by default, use chrome browser config
298
+ - If you'd like to emulate a desktop connection (and receive more message history), this browser setting to your Socket config:
406
299
 
407
- ```javascript
408
- sock.sendMessage(jid, {
409
- sticker: {
410
- url: './path/to/sticker.webp'
411
- }
412
- }, {
413
- quoted: message
414
- })
300
+ ```ts
301
+ const sock = makeWASocket({
302
+ ...otherOpts,
303
+ // can use Windows, Ubuntu here too
304
+ browser: Browsers.macOS("Desktop"),
305
+ syncFullHistory: true,
306
+ });
415
307
  ```
416
308
 
417
- ##### 💽 Audio
418
-
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
- ```
309
+ ## Important Notes About Socket Config
429
310
 
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
457
- })
458
- ```
311
+ ### Caching Group Metadata (Recommended)
459
312
 
460
- ##### 📦 Sticker Pack
313
+ - If you use baileys for groups, we recommend you to set `cachedGroupMetadata` in socket config, you need to implement a cache like this:
461
314
 
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
- ```
315
+ ```ts
316
+ const groupCache = new NodeCache({ stdTTL: 5 * 60, useClones: false });
490
317
 
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
- })
507
-
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
- ```
318
+ const sock = makeWASocket({
319
+ cachedGroupMetadata: async (jid) => groupCache.get(jid),
320
+ });
543
321
 
544
- ##### 2️⃣ List
322
+ sock.ev.on("groups.update", async ([event]) => {
323
+ const metadata = await sock.groupMetadata(event.id);
324
+ groupCache.set(event.id, metadata);
325
+ });
545
326
 
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
- ```
327
+ sock.ev.on("group-participants.update", async (event) => {
328
+ const metadata = await sock.groupMetadata(event.id);
329
+ groupCache.set(event.id, metadata);
330
+ });
331
+ ```
574
332
 
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
- })
626
-
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
673
- })
674
- ```
333
+ ### Improve Retry System & Decrypt Poll Votes
675
334
 
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
- })
699
- ```
335
+ - 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:
336
+ ```ts
337
+ const sock = makeWASocket({
338
+ getMessage: async (key) => await getMessageFromStore(key),
339
+ });
340
+ ```
700
341
 
701
- #### 💳 Sending Payment Messages
342
+ ### Receive Notifications in Whatsapp App
702
343
 
703
- ##### 1️⃣ Invite Payment
344
+ - If you want to receive notifications in whatsapp app, set `markOnlineOnConnect` to `false`
345
+ ```ts
346
+ const sock = makeWASocket({
347
+ markOnlineOnConnect: false,
348
+ });
349
+ ```
704
350
 
705
- ```javascript
706
- sock.sendMessage(jid, {
707
- paymentInviteServiceType: 3 // 1, 2, or 3
708
- })
709
- ```
351
+ ## Saving & Restoring Sessions
710
352
 
711
- ##### 2️⃣ Invoice
353
+ You obviously don't want to keep scanning the QR code every time you want to connect.
712
354
 
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
- ```
355
+ So, you can load the credentials to log back in:
724
356
 
725
- ##### 3️⃣ Order
357
+ ```ts
358
+ import makeWASocket, { useMultiFileAuthState } from "violetics";
726
359
 
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
- ```
735
-
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
- ```
360
+ const { state, saveCreds } = await useMultiFileAuthState("auth_info_baileys");
751
361
 
752
- ##### 5️⃣ Request Payment
362
+ // will use the given state to connect
363
+ // so if valid credentials are available -- it'll connect without QR
364
+ const sock = makeWASocket({ auth: state });
753
365
 
754
- ```javascript
755
- sock.sendMessage(jid, {
756
- text: '💳 Request Payment',
757
- requestPaymentFrom: '0@s.whatsapp.net'
758
- })
366
+ // this will be called as soon as the credentials are updated
367
+ sock.ev.on("creds.update", saveCreds);
759
368
  ```
760
369
 
761
- #### 👁️ Other Message Options
762
-
763
- ##### 1️⃣ AI Label
764
-
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
- ```
779
-
780
- ##### 2️⃣ Ephemeral
370
+ > [!IMPORTANT]
371
+ > `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.
781
372
 
782
373
  > [!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
- ```
374
+ > 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.
794
375
 
795
- ##### 3️⃣ External Ad Reply
376
+ ## Handling Events
796
377
 
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
- })
813
- ```
378
+ - Baileys uses the EventEmitter syntax for events.
379
+ They're all nicely typed up, so you shouldn't have any issues with an Intellisense editor like VS Code.
814
380
 
815
- ##### 4️⃣ Group Status
381
+ > [!IMPORTANT]
382
+ > **The events are [these](https://baileys.whiskeysockets.io/types/BaileysEventMap.html)**, it's important you see all events
816
383
 
817
- > [!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
- ```
384
+ You can listen to these events like this:
829
385
 
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
- })
386
+ ```ts
387
+ const sock = makeWASocket();
388
+ sock.ev.on("messages.upsert", ({ messages }) => {
389
+ console.log("got messages", messages);
390
+ });
850
391
  ```
851
392
 
852
- ##### 6️⃣ View Once
393
+ ### Example to Start
853
394
 
854
395
  > [!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
- ```
866
-
867
- ##### 7️⃣ View Once V2
396
+ > This example includes basic auth storage too
868
397
 
869
398
  > [!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
879
- })
399
+ > For reliable serialization of the authentication state, especially when storing as JSON, always use the BufferJSON utility.
400
+
401
+ ```ts
402
+ import makeWASocket, {
403
+ DisconnectReason,
404
+ useMultiFileAuthState,
405
+ } from "violetics";
406
+ import { Boom } from "@hapi/boom";
407
+
408
+ async function connectToWhatsApp() {
409
+ const { state, saveCreds } = await useMultiFileAuthState("auth_info_baileys");
410
+ const sock = makeWASocket({
411
+ // can provide additional config here
412
+ auth: state,
413
+ printQRInTerminal: true,
414
+ });
415
+ sock.ev.on("connection.update", (update) => {
416
+ const { connection, lastDisconnect } = update;
417
+ if (connection === "close") {
418
+ const shouldReconnect =
419
+ (lastDisconnect.error as Boom)?.output?.statusCode !==
420
+ DisconnectReason.loggedOut;
421
+ console.log(
422
+ "connection closed due to ",
423
+ lastDisconnect.error,
424
+ ", reconnecting ",
425
+ shouldReconnect,
426
+ );
427
+ // reconnect if not logged out
428
+ if (shouldReconnect) {
429
+ connectToWhatsApp();
430
+ }
431
+ } else if (connection === "open") {
432
+ console.log("opened connection");
433
+ }
434
+ });
435
+ sock.ev.on("messages.upsert", (event) => {
436
+ for (const m of event.messages) {
437
+ console.log(JSON.stringify(m, undefined, 2));
438
+
439
+ console.log("replying to", m.key.remoteJid);
440
+ await sock.sendMessage(m.key.remoteJid!, { text: "Hello Word" });
441
+ }
442
+ });
443
+
444
+ // to storage creds (session info) when it updates
445
+ sock.ev.on("creds.update", saveCreds);
446
+ }
447
+ // run in main file
448
+ connectToWhatsApp();
449
+ ```
450
+
451
+ ### For example if you use useSingleFileAuthState and useMongoFileAuthState
452
+
453
+ ```ts
454
+ import makeWASocket, {
455
+ useSingleFileAuthState,
456
+ useMongoFileAuthState,
457
+ } from "violetics";
458
+
459
+ // Single Auth
460
+ const { state, saveState } = await useSingleFileAuthState(
461
+ "./auth_info_baileys.json",
462
+ );
463
+ const sock = makeWASocket({
464
+ auth: state,
465
+ printQRInTerminal: true,
466
+ });
467
+
468
+ sock.ev.on("creds.update", saveState);
469
+
470
+ // Mongo Auth
471
+ import { MongoClient } from "mongodb";
472
+
473
+ const connectAuth = async () => {
474
+ global.client = new MongoClient("mongoURL");
475
+ global.client.connect((err) => {
476
+ if (err) {
477
+ console.warn("Warning: MongoDB link is invalid or cannot be connected.");
478
+ } else {
479
+ console.log("Successfully Connected To MongoDB Server");
480
+ }
481
+ });
482
+ await client.connect();
483
+ const collection = client.db("@blckrose").collection("sessions");
484
+ return collection;
485
+ };
486
+
487
+ const Authentication = await connectAuth();
488
+ const { state, saveCreds } = await useMongoFileAuthState(Authentication);
489
+ const sock = makeWASocket({
490
+ auth: state,
491
+ printQRInTerminal: true,
492
+ });
493
+
494
+ sock.ev.on("creds.update", saveCreds);
880
495
  ```
881
496
 
882
- ##### 8️⃣ View Once V2 Extension
883
-
884
- > [!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
- })
497
+ > [!IMPORTANT]
498
+ > In `messages.upsert` it's recommended to use a loop like `for (const message of event.messages)` to handle all messages in array
499
+
500
+ ### Decrypt Poll Votes
501
+
502
+ - By default poll votes are encrypted and handled in `messages.update`
503
+ - That's a simple example
504
+
505
+ ```ts
506
+ sock.ev.on("messages.update", (event) => {
507
+ for (const { key, update } of event) {
508
+ if (update.pollUpdates) {
509
+ const pollCreation = await getMessage(key);
510
+ if (pollCreation) {
511
+ console.log(
512
+ "got poll update, aggregation: ",
513
+ getAggregateVotesInPollMessage({
514
+ message: pollCreation,
515
+ pollUpdates: update.pollUpdates,
516
+ }),
517
+ );
518
+ }
519
+ }
520
+ }
521
+ });
895
522
  ```
896
523
 
897
- #### 🧰 Additional Contents
898
-
899
- ##### 🏷️ Find User ID (JID|PN/LID)
900
-
901
- > [!NOTE]
902
- The ID must contain numbers only (no +, (), or -) and must include the country code with WhatsApp ID format.
524
+ - `getMessage` is a [store](#implementing-a-data-store) implementation (in your end)
903
525
 
904
- ```javascript
905
- // --- PN (Phone Number)
906
- const phoneNumber = '6281111111111@s.whatsapp.net'
526
+ ### Summary of Events on First Connection
907
527
 
908
- const ids = await sock.findUserId(phoneNumber)
528
+ 1. When you connect first time, `connection.update` will be fired requesting you to restart sock
529
+ 2. Then, history messages will be received in `messaging.history-set`
909
530
 
910
- console.log('🏷️ Got user ID', ':', ids)
531
+ ## Implementing a Data Store
911
532
 
912
- // --- LID (Local Identifier)
913
- const lid = '43411111111111@lid'
533
+ - 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.
914
534
 
915
- const ids = await sock.findUserId(lid)
916
-
917
- console.log('🏷️ Got user ID', ':', ids)
918
-
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
930
- ```
535
+ > [!IMPORTANT]
536
+ > I highly recommend building your own data store, as storing someone's entire chat history in memory is a terrible waste of RAM.
931
537
 
932
- ##### 🔑 Request Custom Pairing Code
538
+ It can be used as follows:
933
539
 
934
- > [!NOTE]
935
- The phone number must contain numbers only (no +, (), or -) and must include the country code.
540
+ ```ts
541
+ import makeWASocket, { makeInMemoryStore } from "violetics";
542
+ // the store maintains the data of the WA connection in memory
543
+ // can be written out to a file & read from it
544
+ const store = makeInMemoryStore({});
545
+ // can be read from a file
546
+ store.readFromFile("./baileys_store.json");
547
+ // saves the state to a file every 10s
548
+ setInterval(() => {
549
+ store.writeToFile("./baileys_store.json");
550
+ }, 10_000);
936
551
 
937
- ```javascript
938
- const phoneNumber = '6281111111111'
939
- const customPairingCode = 'STARFALL'
552
+ const sock = makeWASocket({});
553
+ // will listen from this socket
554
+ // the store can listen from a new socket once the current socket outlives its lifetime
555
+ store.bind(sock.ev);
940
556
 
941
- await sock.requestPairingCode(phoneNumber, customPairingCode)
557
+ sock.ev.on("chats.upsert", () => {
558
+ // can use 'store.chats' however you want, even after the socket dies out
559
+ // 'chats' => a KeyedDB instance
560
+ console.log("got chats", store.chats.all());
561
+ });
942
562
 
943
- console.log('🔗 Pairing code', ':', customPairingCode)
563
+ sock.ev.on("contacts.upsert", () => {
564
+ console.log("got contacts", Object.values(store.contacts));
565
+ });
944
566
  ```
945
567
 
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')
568
+ The store also provides some simple functions such as `loadMessages` that utilize the store to speed up data retrieval.
957
569
 
958
- // --- Change owner
959
- sock.newsletterChangeOwner('1231111111111@newsletter', '6281111111111@s.whatsapp.net')
570
+ ## Whatsapp IDs Explain
960
571
 
961
- // --- Change name
962
- sock.newsletterUpdateName('1231111111111@newsletter', '📦 violetics')
572
+ - `id` is the WhatsApp ID, called `jid` too, of the person or group you're sending the message to.
573
+ - It must be in the format `[country code][phone number]@s.whatsapp.net`
574
+ - Example for people: `+19999999999@s.whatsapp.net`.
575
+ - For groups, it must be in the format `123456789-123345@g.us`.
576
+ - For broadcast lists, it's `[timestamp of creation]@broadcast`.
577
+ - For stories, the ID is `status@broadcast`.
963
578
 
964
- // --- Change description
965
- sock.newsletterUpdateDescription('1231111111111@newsletter', '📣 Fresh updates weekly')
579
+ ## Utility Functions
966
580
 
967
- // --- Change photo
968
- sock.newsletterUpdatePicture('1231111111111@newsletter', {
969
- url: 'path/to/image.jpg'
970
- })
581
+ ### Resize Image
971
582
 
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 })
583
+ ```ts
584
+ // Resize an image (Buffer, URL, or stream) to given dimensions
585
+ const resized = await sock.resize("https://example.com/image.jpg", 320, 320);
586
+ // or
587
+ const resized = await sock.resize(buffer, 320, 320);
982
588
  ```
983
589
 
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)
992
-
993
- // --- Get invite code
994
- sock.groupInviteCode(jid)
995
-
996
- // --- Revoke invite link
997
- sock.groupRevokeInvite(jid)
998
-
999
- // --- Leave group
1000
- sock.groupLeave(jid)
1001
-
1002
- // --- Add participants
1003
- sock.groupParticipantsUpdate(jid, ['628123456789@s.whatsapp.net'], 'add')
1004
-
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')
1010
-
1011
- // --- Demote from admin
1012
- sock.groupParticipantsUpdate(jid, ['628123456789@s.whatsapp.net'], 'demote')
1013
-
1014
- // --- Change name
1015
- sock.groupUpdateSubject(jid, '📦 violetics')
1016
-
1017
- // --- Change description
1018
- sock.groupUpdateDescription(jid, 'Updated description')
1019
-
1020
- // --- Change photo
1021
- sock.updateProfilePicture(jid, {
1022
- url: 'path/to/image.jpg'
1023
- })
1024
-
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')
590
+ - `getContentType`, returns the content type for any message
591
+ - `getDevice`, returns the device from message
592
+ - `makeCacheableSignalKeyStore`, make auth store more fast
593
+ - `downloadContentFromMessage`, download content from any message
594
+ - `makeNewsletterUtils`, helper lengkap untuk kirim ke newsletter/channel
595
+ - `resolveJid`, resolve LID / participant ID ke JID @s.whatsapp.net
596
+ - `resolveJids`, resolve banyak JID sekaligus
1033
597
 
1034
- // --- Set admin only can edit group info
1035
- sock.groupSettingUpdate(jid, 'locked')
598
+ ---
1036
599
 
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()
1058
-
1059
- console.dir(groups, { depth: null })
1060
-
1061
- // --- Get pending invites
1062
- const invites = await sock.groupGetInviteInfo(code)
1063
-
1064
- console.dir(invites, { depth: null })
1065
-
1066
- // --- Accept group invite
1067
- sock.groupAcceptInvite(code)
1068
-
1069
- // --- Get group info from link
1070
- const group = await sock.groupGetInviteInfo('https://chat.whatsapp.com/ABC123')
1071
-
1072
- console.log('👥 Got group info from link', ':', group)
1073
- ```
1074
-
1075
- ## 📦 Fork Base
1076
- > [!NOTE]
1077
- This fork is based on [Baileys (GitHub)](https://github.com/WhiskeySockets/Baileys)
1078
-
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)
600
+ <p align="center">Made with by <a href="https://github.com/blckrose">@blckrose</a></p>