lordceaser-baileys 2.0.37 → 2.0.39

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 (439) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +660 -1073
  3. package/WAProto/GenerateStatics.sh +4 -3
  4. package/WAProto/WAProto.proto +359 -2494
  5. package/WAProto/index.d.ts +31460 -8461
  6. package/WAProto/index.js +96236 -92883
  7. package/WASignalGroup/GroupProtocol.js +1697 -0
  8. package/WASignalGroup/ciphertext_message.js +16 -0
  9. package/WASignalGroup/group_cipher.js +120 -0
  10. package/WASignalGroup/group_session_builder.js +46 -0
  11. package/WASignalGroup/index.js +5 -0
  12. package/WASignalGroup/keyhelper.js +21 -0
  13. package/WASignalGroup/protobufs.js +3 -0
  14. package/WASignalGroup/queue_job.js +69 -0
  15. package/WASignalGroup/sender_chain_key.js +50 -0
  16. package/WASignalGroup/sender_key_distribution_message.js +78 -0
  17. package/WASignalGroup/sender_key_message.js +92 -0
  18. package/WASignalGroup/sender_key_name.js +70 -0
  19. package/WASignalGroup/sender_key_record.js +56 -0
  20. package/WASignalGroup/sender_key_state.js +129 -0
  21. package/{lib/Signal/Group/sender-message-key.js → WASignalGroup/sender_message_key.js} +16 -3
  22. package/lib/Defaults/baileys-version.json +3 -0
  23. package/lib/Defaults/index.d.ts +245 -37
  24. package/lib/Defaults/index.js +74 -82
  25. package/lib/Defaults/phonenumber-mcc.json +223 -0
  26. package/lib/Signal/libsignal.d.ts +3 -5
  27. package/lib/Signal/libsignal.js +80 -359
  28. package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +5 -4
  29. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  30. package/lib/Socket/Client/index.d.ts +3 -3
  31. package/lib/Socket/Client/index.js +19 -3
  32. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  33. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  34. package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +2 -3
  35. package/lib/Socket/Client/web-socket-client.js +62 -0
  36. package/lib/Socket/business.d.ts +87 -156
  37. package/lib/Socket/business.js +43 -162
  38. package/lib/Socket/chats.d.ts +40 -82
  39. package/lib/Socket/chats.js +284 -603
  40. package/lib/Socket/groups.d.ts +58 -96
  41. package/lib/Socket/groups.js +82 -115
  42. package/lib/Socket/index.d.ts +94 -204
  43. package/lib/Socket/index.js +9 -11
  44. package/lib/Socket/messages-recv.d.ts +77 -145
  45. package/lib/Socket/messages-recv.js +400 -1305
  46. package/lib/Socket/messages-send.d.ts +70 -141
  47. package/lib/Socket/messages-send.js +249 -717
  48. package/lib/Socket/registration.d.ts +242 -0
  49. package/lib/Socket/registration.js +166 -0
  50. package/lib/Socket/socket.d.ts +18 -34
  51. package/lib/Socket/socket.js +206 -557
  52. package/lib/Store/index.d.ts +3 -0
  53. package/lib/Store/index.js +10 -0
  54. package/lib/Store/make-cache-manager-store.d.ts +14 -0
  55. package/lib/Store/make-cache-manager-store.js +83 -0
  56. package/lib/Store/make-in-memory-store.d.ts +118 -0
  57. package/lib/Store/make-in-memory-store.js +422 -0
  58. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  59. package/lib/Store/make-ordered-dictionary.js +81 -0
  60. package/lib/Store/object-repository.d.ts +10 -0
  61. package/lib/Store/object-repository.js +27 -0
  62. package/lib/Types/Auth.d.ts +12 -19
  63. package/lib/Types/Auth.js +2 -2
  64. package/lib/Types/Call.d.ts +1 -3
  65. package/lib/Types/Call.js +2 -2
  66. package/lib/Types/Chat.d.ts +14 -31
  67. package/lib/Types/Chat.js +4 -8
  68. package/lib/Types/Contact.d.ts +1 -8
  69. package/lib/Types/Contact.js +2 -2
  70. package/lib/Types/Events.d.ts +17 -101
  71. package/lib/Types/Events.js +2 -2
  72. package/lib/Types/GroupMetadata.d.ts +3 -18
  73. package/lib/Types/GroupMetadata.js +2 -2
  74. package/lib/Types/Label.d.ts +0 -1
  75. package/lib/Types/Label.js +5 -3
  76. package/lib/Types/LabelAssociation.d.ts +0 -1
  77. package/lib/Types/LabelAssociation.js +5 -3
  78. package/lib/Types/Message.d.ts +29 -81
  79. package/lib/Types/Message.js +9 -11
  80. package/lib/Types/Product.d.ts +1 -2
  81. package/lib/Types/Product.js +2 -2
  82. package/lib/Types/Signal.d.ts +2 -32
  83. package/lib/Types/Signal.js +2 -2
  84. package/lib/Types/Socket.d.ts +26 -46
  85. package/lib/Types/Socket.js +2 -3
  86. package/lib/Types/State.d.ts +2 -72
  87. package/lib/Types/State.js +2 -56
  88. package/lib/Types/index.d.ts +13 -16
  89. package/lib/Types/index.js +30 -15
  90. package/lib/Utils/auth-utils.d.ts +6 -12
  91. package/lib/Utils/auth-utils.js +143 -239
  92. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  93. package/lib/Utils/baileys-event-stream.js +63 -0
  94. package/lib/Utils/business.d.ts +2 -3
  95. package/lib/Utils/business.js +69 -66
  96. package/lib/Utils/chat-utils.d.ts +23 -52
  97. package/lib/Utils/chat-utils.js +248 -380
  98. package/lib/Utils/crypto.d.ts +21 -17
  99. package/lib/Utils/crypto.js +92 -57
  100. package/lib/Utils/decode-wa-message.d.ts +8 -54
  101. package/lib/Utils/decode-wa-message.js +57 -186
  102. package/lib/Utils/event-buffer.d.ts +8 -9
  103. package/lib/Utils/event-buffer.js +76 -178
  104. package/lib/Utils/generics.d.ts +23 -26
  105. package/lib/Utils/generics.js +166 -165
  106. package/lib/Utils/history.d.ts +11 -16
  107. package/lib/Utils/history.js +53 -93
  108. package/lib/Utils/index.d.ts +17 -22
  109. package/lib/Utils/index.js +33 -22
  110. package/lib/Utils/link-preview.d.ts +5 -5
  111. package/lib/Utils/link-preview.js +24 -16
  112. package/lib/Utils/logger.d.ts +3 -11
  113. package/lib/Utils/logger.js +7 -3
  114. package/lib/Utils/lt-hash.d.ts +12 -8
  115. package/lib/Utils/lt-hash.js +46 -3
  116. package/lib/Utils/make-mutex.d.ts +2 -4
  117. package/lib/Utils/make-mutex.js +34 -24
  118. package/lib/Utils/messages-media.d.ts +35 -61
  119. package/lib/Utils/messages-media.js +301 -415
  120. package/lib/Utils/messages.d.ts +18 -32
  121. package/lib/Utils/messages.js +261 -396
  122. package/lib/Utils/noise-handler.d.ts +13 -12
  123. package/lib/Utils/noise-handler.js +98 -144
  124. package/lib/Utils/process-message.d.ts +12 -30
  125. package/lib/Utils/process-message.js +163 -439
  126. package/lib/Utils/signal.d.ts +5 -20
  127. package/lib/Utils/signal.js +74 -114
  128. package/lib/Utils/use-multi-file-auth-state.d.ts +1 -2
  129. package/lib/Utils/use-multi-file-auth-state.js +33 -61
  130. package/lib/Utils/validate-connection.d.ts +6 -6
  131. package/lib/Utils/validate-connection.js +114 -119
  132. package/lib/WABinary/constants.d.ts +4 -5
  133. package/lib/WABinary/constants.js +20 -1281
  134. package/lib/WABinary/decode.d.ts +4 -4
  135. package/lib/WABinary/decode.js +43 -51
  136. package/lib/WABinary/encode.d.ts +3 -3
  137. package/lib/WABinary/encode.js +44 -32
  138. package/lib/WABinary/generic-utils.d.ts +6 -6
  139. package/lib/WABinary/generic-utils.js +43 -46
  140. package/lib/WABinary/index.d.ts +5 -6
  141. package/lib/WABinary/index.js +21 -6
  142. package/lib/WABinary/jid-utils.d.ts +6 -23
  143. package/lib/WABinary/jid-utils.js +39 -73
  144. package/lib/WABinary/types.d.ts +1 -2
  145. package/lib/WABinary/types.js +2 -2
  146. package/lib/WAM/BinaryInfo.d.ts +11 -3
  147. package/lib/WAM/BinaryInfo.js +5 -2
  148. package/lib/WAM/constants.d.ts +3 -5
  149. package/lib/WAM/constants.js +11958 -19461
  150. package/lib/WAM/encode.d.ts +3 -3
  151. package/lib/WAM/encode.js +22 -17
  152. package/lib/WAM/index.d.ts +3 -4
  153. package/lib/WAM/index.js +19 -4
  154. package/lib/index.d.ts +8 -9
  155. package/lib/index.js +30 -11
  156. package/package.json +2 -2
  157. package/WAProto/WAProto/GenerateStatics.sh +0 -3
  158. package/WAProto/WAProto/WAProto.proto +0 -5479
  159. package/WAProto/WAProto/fix-imports.js +0 -85
  160. package/WAProto/WAProto/index.d.ts +0 -14017
  161. package/WAProto/WAProto/index.js +0 -97691
  162. package/WAProto/fix-imports.js +0 -85
  163. package/lib/Defaults/index.d.ts.map +0 -1
  164. package/lib/Defaults/index.js.map +0 -1
  165. package/lib/Signal/Group/ciphertext-message.d.ts +0 -10
  166. package/lib/Signal/Group/ciphertext-message.d.ts.map +0 -1
  167. package/lib/Signal/Group/ciphertext-message.js +0 -12
  168. package/lib/Signal/Group/ciphertext-message.js.map +0 -1
  169. package/lib/Signal/Group/group-session-builder.d.ts +0 -15
  170. package/lib/Signal/Group/group-session-builder.d.ts.map +0 -1
  171. package/lib/Signal/Group/group-session-builder.js +0 -30
  172. package/lib/Signal/Group/group-session-builder.js.map +0 -1
  173. package/lib/Signal/Group/group_cipher.d.ts +0 -17
  174. package/lib/Signal/Group/group_cipher.d.ts.map +0 -1
  175. package/lib/Signal/Group/group_cipher.js +0 -82
  176. package/lib/Signal/Group/group_cipher.js.map +0 -1
  177. package/lib/Signal/Group/index.d.ts +0 -12
  178. package/lib/Signal/Group/index.d.ts.map +0 -1
  179. package/lib/Signal/Group/index.js +0 -12
  180. package/lib/Signal/Group/index.js.map +0 -1
  181. package/lib/Signal/Group/keyhelper.d.ts +0 -11
  182. package/lib/Signal/Group/keyhelper.d.ts.map +0 -1
  183. package/lib/Signal/Group/keyhelper.js +0 -18
  184. package/lib/Signal/Group/keyhelper.js.map +0 -1
  185. package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
  186. package/lib/Signal/Group/sender-chain-key.d.ts.map +0 -1
  187. package/lib/Signal/Group/sender-chain-key.js +0 -26
  188. package/lib/Signal/Group/sender-chain-key.js.map +0 -1
  189. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
  190. package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +0 -1
  191. package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
  192. package/lib/Signal/Group/sender-key-distribution-message.js.map +0 -1
  193. package/lib/Signal/Group/sender-key-message.d.ts +0 -19
  194. package/lib/Signal/Group/sender-key-message.d.ts.map +0 -1
  195. package/lib/Signal/Group/sender-key-message.js +0 -66
  196. package/lib/Signal/Group/sender-key-message.js.map +0 -1
  197. package/lib/Signal/Group/sender-key-name.d.ts +0 -18
  198. package/lib/Signal/Group/sender-key-name.d.ts.map +0 -1
  199. package/lib/Signal/Group/sender-key-name.js +0 -48
  200. package/lib/Signal/Group/sender-key-name.js.map +0 -1
  201. package/lib/Signal/Group/sender-key-record.d.ts +0 -31
  202. package/lib/Signal/Group/sender-key-record.d.ts.map +0 -1
  203. package/lib/Signal/Group/sender-key-record.js +0 -41
  204. package/lib/Signal/Group/sender-key-record.js.map +0 -1
  205. package/lib/Signal/Group/sender-key-state.d.ts +0 -39
  206. package/lib/Signal/Group/sender-key-state.d.ts.map +0 -1
  207. package/lib/Signal/Group/sender-key-state.js +0 -84
  208. package/lib/Signal/Group/sender-key-state.js.map +0 -1
  209. package/lib/Signal/Group/sender-message-key.d.ts +0 -12
  210. package/lib/Signal/Group/sender-message-key.d.ts.map +0 -1
  211. package/lib/Signal/Group/sender-message-key.js.map +0 -1
  212. package/lib/Signal/libsignal.d.ts.map +0 -1
  213. package/lib/Signal/libsignal.js.map +0 -1
  214. package/lib/Signal/lid-mapping.d.ts +0 -23
  215. package/lib/Signal/lid-mapping.d.ts.map +0 -1
  216. package/lib/Signal/lid-mapping.js +0 -277
  217. package/lib/Signal/lid-mapping.js.map +0 -1
  218. package/lib/Socket/Client/index.d.ts.map +0 -1
  219. package/lib/Socket/Client/index.js.map +0 -1
  220. package/lib/Socket/Client/types.d.ts.map +0 -1
  221. package/lib/Socket/Client/types.js +0 -11
  222. package/lib/Socket/Client/types.js.map +0 -1
  223. package/lib/Socket/Client/websocket.d.ts.map +0 -1
  224. package/lib/Socket/Client/websocket.js +0 -54
  225. package/lib/Socket/Client/websocket.js.map +0 -1
  226. package/lib/Socket/business.d.ts.map +0 -1
  227. package/lib/Socket/business.js.map +0 -1
  228. package/lib/Socket/chats.d.ts.map +0 -1
  229. package/lib/Socket/chats.js.map +0 -1
  230. package/lib/Socket/communities.d.ts +0 -273
  231. package/lib/Socket/communities.d.ts.map +0 -1
  232. package/lib/Socket/communities.js +0 -431
  233. package/lib/Socket/communities.js.map +0 -1
  234. package/lib/Socket/groups.d.ts.map +0 -1
  235. package/lib/Socket/groups.js.map +0 -1
  236. package/lib/Socket/index.d.ts.map +0 -1
  237. package/lib/Socket/index.js.map +0 -1
  238. package/lib/Socket/messages-recv.d.ts.map +0 -1
  239. package/lib/Socket/messages-recv.js.map +0 -1
  240. package/lib/Socket/messages-send.d.ts.map +0 -1
  241. package/lib/Socket/messages-send.js.map +0 -1
  242. package/lib/Socket/mex.d.ts +0 -3
  243. package/lib/Socket/mex.d.ts.map +0 -1
  244. package/lib/Socket/mex.js +0 -42
  245. package/lib/Socket/mex.js.map +0 -1
  246. package/lib/Socket/newsletter.d.ts +0 -170
  247. package/lib/Socket/newsletter.d.ts.map +0 -1
  248. package/lib/Socket/newsletter.js +0 -181
  249. package/lib/Socket/newsletter.js.map +0 -1
  250. package/lib/Socket/socket.d.ts.map +0 -1
  251. package/lib/Socket/socket.js.map +0 -1
  252. package/lib/Types/Auth.d.ts.map +0 -1
  253. package/lib/Types/Auth.js.map +0 -1
  254. package/lib/Types/Bussines.d.ts +0 -25
  255. package/lib/Types/Bussines.d.ts.map +0 -1
  256. package/lib/Types/Bussines.js +0 -2
  257. package/lib/Types/Bussines.js.map +0 -1
  258. package/lib/Types/Call.d.ts.map +0 -1
  259. package/lib/Types/Call.js.map +0 -1
  260. package/lib/Types/Chat.d.ts.map +0 -1
  261. package/lib/Types/Chat.js.map +0 -1
  262. package/lib/Types/Contact.d.ts.map +0 -1
  263. package/lib/Types/Contact.js.map +0 -1
  264. package/lib/Types/Events.d.ts.map +0 -1
  265. package/lib/Types/Events.js.map +0 -1
  266. package/lib/Types/GroupMetadata.d.ts.map +0 -1
  267. package/lib/Types/GroupMetadata.js.map +0 -1
  268. package/lib/Types/Label.d.ts.map +0 -1
  269. package/lib/Types/Label.js.map +0 -1
  270. package/lib/Types/LabelAssociation.d.ts.map +0 -1
  271. package/lib/Types/LabelAssociation.js.map +0 -1
  272. package/lib/Types/Message.d.ts.map +0 -1
  273. package/lib/Types/Message.js.map +0 -1
  274. package/lib/Types/Mex.d.ts +0 -141
  275. package/lib/Types/Mex.d.ts.map +0 -1
  276. package/lib/Types/Mex.js +0 -37
  277. package/lib/Types/Mex.js.map +0 -1
  278. package/lib/Types/Product.d.ts.map +0 -1
  279. package/lib/Types/Product.js.map +0 -1
  280. package/lib/Types/Signal.d.ts.map +0 -1
  281. package/lib/Types/Signal.js.map +0 -1
  282. package/lib/Types/Socket.d.ts.map +0 -1
  283. package/lib/Types/Socket.js.map +0 -1
  284. package/lib/Types/State.d.ts.map +0 -1
  285. package/lib/Types/State.js.map +0 -1
  286. package/lib/Types/USync.d.ts +0 -26
  287. package/lib/Types/USync.d.ts.map +0 -1
  288. package/lib/Types/USync.js +0 -2
  289. package/lib/Types/USync.js.map +0 -1
  290. package/lib/Types/index.d.ts.map +0 -1
  291. package/lib/Types/index.js.map +0 -1
  292. package/lib/Utils/auth-utils.d.ts.map +0 -1
  293. package/lib/Utils/auth-utils.js.map +0 -1
  294. package/lib/Utils/browser-utils.d.ts +0 -4
  295. package/lib/Utils/browser-utils.d.ts.map +0 -1
  296. package/lib/Utils/browser-utils.js +0 -29
  297. package/lib/Utils/browser-utils.js.map +0 -1
  298. package/lib/Utils/business.d.ts.map +0 -1
  299. package/lib/Utils/business.js.map +0 -1
  300. package/lib/Utils/chat-utils.d.ts.map +0 -1
  301. package/lib/Utils/chat-utils.js.map +0 -1
  302. package/lib/Utils/companion-reg-client-utils.d.ts +0 -17
  303. package/lib/Utils/companion-reg-client-utils.d.ts.map +0 -1
  304. package/lib/Utils/companion-reg-client-utils.js +0 -35
  305. package/lib/Utils/companion-reg-client-utils.js.map +0 -1
  306. package/lib/Utils/crypto.d.ts.map +0 -1
  307. package/lib/Utils/crypto.js.map +0 -1
  308. package/lib/Utils/decode-wa-message.d.ts.map +0 -1
  309. package/lib/Utils/decode-wa-message.js.map +0 -1
  310. package/lib/Utils/event-buffer.d.ts.map +0 -1
  311. package/lib/Utils/event-buffer.js.map +0 -1
  312. package/lib/Utils/generics.d.ts.map +0 -1
  313. package/lib/Utils/generics.js.map +0 -1
  314. package/lib/Utils/history.d.ts.map +0 -1
  315. package/lib/Utils/history.js.map +0 -1
  316. package/lib/Utils/identity-change-handler.d.ts +0 -44
  317. package/lib/Utils/identity-change-handler.d.ts.map +0 -1
  318. package/lib/Utils/identity-change-handler.js +0 -50
  319. package/lib/Utils/identity-change-handler.js.map +0 -1
  320. package/lib/Utils/index.d.ts.map +0 -1
  321. package/lib/Utils/index.js.map +0 -1
  322. package/lib/Utils/link-preview.d.ts.map +0 -1
  323. package/lib/Utils/link-preview.js.map +0 -1
  324. package/lib/Utils/logger.d.ts.map +0 -1
  325. package/lib/Utils/logger.js.map +0 -1
  326. package/lib/Utils/lt-hash.d.ts.map +0 -1
  327. package/lib/Utils/lt-hash.js.map +0 -1
  328. package/lib/Utils/make-mutex.d.ts.map +0 -1
  329. package/lib/Utils/make-mutex.js.map +0 -1
  330. package/lib/Utils/message-retry-manager.d.ts +0 -115
  331. package/lib/Utils/message-retry-manager.d.ts.map +0 -1
  332. package/lib/Utils/message-retry-manager.js +0 -265
  333. package/lib/Utils/message-retry-manager.js.map +0 -1
  334. package/lib/Utils/messages-media.d.ts.map +0 -1
  335. package/lib/Utils/messages-media.js.map +0 -1
  336. package/lib/Utils/messages.d.ts.map +0 -1
  337. package/lib/Utils/messages.js.map +0 -1
  338. package/lib/Utils/noise-handler.d.ts.map +0 -1
  339. package/lib/Utils/noise-handler.js.map +0 -1
  340. package/lib/Utils/offline-node-processor.d.ts +0 -17
  341. package/lib/Utils/offline-node-processor.d.ts.map +0 -1
  342. package/lib/Utils/offline-node-processor.js +0 -40
  343. package/lib/Utils/offline-node-processor.js.map +0 -1
  344. package/lib/Utils/pre-key-manager.d.ts +0 -28
  345. package/lib/Utils/pre-key-manager.d.ts.map +0 -1
  346. package/lib/Utils/pre-key-manager.js +0 -106
  347. package/lib/Utils/pre-key-manager.js.map +0 -1
  348. package/lib/Utils/process-message.d.ts.map +0 -1
  349. package/lib/Utils/process-message.js.map +0 -1
  350. package/lib/Utils/reporting-utils.d.ts +0 -11
  351. package/lib/Utils/reporting-utils.d.ts.map +0 -1
  352. package/lib/Utils/reporting-utils.js +0 -258
  353. package/lib/Utils/reporting-utils.js.map +0 -1
  354. package/lib/Utils/signal.d.ts.map +0 -1
  355. package/lib/Utils/signal.js.map +0 -1
  356. package/lib/Utils/stanza-ack.d.ts +0 -11
  357. package/lib/Utils/stanza-ack.d.ts.map +0 -1
  358. package/lib/Utils/stanza-ack.js +0 -38
  359. package/lib/Utils/stanza-ack.js.map +0 -1
  360. package/lib/Utils/sync-action-utils.d.ts +0 -19
  361. package/lib/Utils/sync-action-utils.d.ts.map +0 -1
  362. package/lib/Utils/sync-action-utils.js +0 -49
  363. package/lib/Utils/sync-action-utils.js.map +0 -1
  364. package/lib/Utils/tc-token-utils.d.ts +0 -37
  365. package/lib/Utils/tc-token-utils.d.ts.map +0 -1
  366. package/lib/Utils/tc-token-utils.js +0 -164
  367. package/lib/Utils/tc-token-utils.js.map +0 -1
  368. package/lib/Utils/use-multi-file-auth-state.d.ts.map +0 -1
  369. package/lib/Utils/use-multi-file-auth-state.js.map +0 -1
  370. package/lib/Utils/validate-connection.d.ts.map +0 -1
  371. package/lib/Utils/validate-connection.js.map +0 -1
  372. package/lib/WABinary/constants.d.ts.map +0 -1
  373. package/lib/WABinary/constants.js.map +0 -1
  374. package/lib/WABinary/decode.d.ts.map +0 -1
  375. package/lib/WABinary/decode.js.map +0 -1
  376. package/lib/WABinary/encode.d.ts.map +0 -1
  377. package/lib/WABinary/encode.js.map +0 -1
  378. package/lib/WABinary/generic-utils.d.ts.map +0 -1
  379. package/lib/WABinary/generic-utils.js.map +0 -1
  380. package/lib/WABinary/index.d.ts.map +0 -1
  381. package/lib/WABinary/index.js.map +0 -1
  382. package/lib/WABinary/jid-utils.d.ts.map +0 -1
  383. package/lib/WABinary/jid-utils.js.map +0 -1
  384. package/lib/WABinary/types.d.ts.map +0 -1
  385. package/lib/WABinary/types.js.map +0 -1
  386. package/lib/WAM/BinaryInfo.d.ts.map +0 -1
  387. package/lib/WAM/BinaryInfo.js.map +0 -1
  388. package/lib/WAM/constants.d.ts.map +0 -1
  389. package/lib/WAM/constants.js.map +0 -1
  390. package/lib/WAM/encode.d.ts.map +0 -1
  391. package/lib/WAM/encode.js.map +0 -1
  392. package/lib/WAM/index.d.ts.map +0 -1
  393. package/lib/WAM/index.js.map +0 -1
  394. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
  395. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +0 -1
  396. package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -52
  397. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +0 -1
  398. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -23
  399. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +0 -1
  400. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -54
  401. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +0 -1
  402. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -13
  403. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +0 -1
  404. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -27
  405. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +0 -1
  406. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -13
  407. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +0 -1
  408. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -38
  409. package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +0 -1
  410. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +0 -10
  411. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +0 -1
  412. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +0 -25
  413. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +0 -1
  414. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -26
  415. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +0 -1
  416. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -51
  417. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +0 -1
  418. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -10
  419. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +0 -1
  420. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -29
  421. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +0 -1
  422. package/lib/WAUSync/Protocols/index.d.ts +0 -6
  423. package/lib/WAUSync/Protocols/index.d.ts.map +0 -1
  424. package/lib/WAUSync/Protocols/index.js +0 -6
  425. package/lib/WAUSync/Protocols/index.js.map +0 -1
  426. package/lib/WAUSync/USyncQuery.d.ts +0 -30
  427. package/lib/WAUSync/USyncQuery.d.ts.map +0 -1
  428. package/lib/WAUSync/USyncQuery.js +0 -98
  429. package/lib/WAUSync/USyncQuery.js.map +0 -1
  430. package/lib/WAUSync/USyncUser.d.ts +0 -17
  431. package/lib/WAUSync/USyncUser.d.ts.map +0 -1
  432. package/lib/WAUSync/USyncUser.js +0 -31
  433. package/lib/WAUSync/USyncUser.js.map +0 -1
  434. package/lib/WAUSync/index.d.ts +0 -4
  435. package/lib/WAUSync/index.d.ts.map +0 -1
  436. package/lib/WAUSync/index.js +0 -4
  437. package/lib/WAUSync/index.js.map +0 -1
  438. package/lib/index.d.ts.map +0 -1
  439. package/lib/index.js.map +0 -1
package/README.md CHANGED
@@ -1,48 +1,25 @@
1
- <h1 align='center'><img alt="Baileys logo" src="https://raw.githubusercontent.com/WhiskeySockets/Baileys/refs/heads/master/Media/logo.png" height="75"/></h1>
1
+ # Baileys - Typescript/Javascript WhatsApp Web API
2
2
 
3
- <div align='center'>Baileys is a WebSockets-based TypeScript library for interacting with the WhatsApp Web API.</div>
3
+ ### Important Note
4
4
 
5
+ This library was originally a project for **CS-2362 at Ashoka University** and is in no way affiliated with or endorsed by WhatsApp. Use at your own discretion. Do not spam people with this. We discourage any stalkerware, bulk or automated messaging usage.
5
6
 
6
- > [!CAUTION]
7
- > NOTICE OF BREAKING CHANGE.
8
- >
9
- > As of 7.0.0, multiple breaking changes were introduced into the library.
10
- >
11
- > Please check out https://whiskey.so/migrate-latest for more information.
12
-
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).
15
-
16
- New guide link: https://baileys.wiki
17
-
18
- # Get Support
19
-
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.
21
-
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.
23
-
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).
26
-
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.
30
-
7
+ #### Liability and License Notice
8
+ Baileys and its maintainers cannot be held liable for misuse of this application, as stated in the [MIT license](https://github.com/WhiskeySockets/Baileys/blob/master/LICENSE).
31
9
  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.
33
-
34
10
  ##
35
11
 
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.
12
+ Baileys does not require Selenium or any other browser to be interface with WhatsApp Web, it does so directly using a **WebSocket**.
13
+ Not running Selenium or Chromimum saves you like **half a gig** of ram :/
14
+ Baileys supports interacting with the multi-device & web versions of WhatsApp.
15
+ 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.
16
+
17
+ ## Please Read
40
18
 
41
- > [!IMPORTANT]
42
- > The original repository had to be removed by the original author - we now continue development in this repository here.
19
+ The original repository had to be removed by the original author - we now continue development in this repository here.
43
20
  This is the only official repository and is maintained by the community.
44
- > **Join the Discord [here](https://discord.gg/WeJM5FP9GG)**
45
-
21
+ **Join the Discord [here](https://discord.gg/WeJM5FP9GG)**
22
+
46
23
  ## Example
47
24
 
48
25
  Do check out & run [example.ts](Example/example.ts) to see an example usage of the library.
@@ -65,354 +42,272 @@ yarn add github:WhiskeySockets/Baileys
65
42
  ```
66
43
 
67
44
  Then import your code using:
68
- ```ts
69
- import makeWASocket from '@whiskeysockets/baileys'
70
- ```
71
-
72
- # Links
73
-
74
- - [Discord](https://discord.gg/WeJM5FP9GG)
75
- - [Docs](https://baileys.wiki/docs/intro/)
76
-
77
- # Index
78
-
79
- - [Connecting Account](#connecting-account)
80
- - [Connect with QR-CODE](#starting-socket-with-qr-code)
81
- - [Connect with Pairing Code](#starting-socket-with-pairing-code)
82
- - [Receive Full History](#receive-full-history)
83
- - [Important Notes About Socket Config](#important-notes-about-socket-config)
84
- - [Caching Group Metadata (Recommended)](#caching-group-metadata-recommended)
85
- - [Improve Retry System & Decrypt Poll Votes](#improve-retry-system--decrypt-poll-votes)
86
- - [Receive Notifications in Whatsapp App](#receive-notifications-in-whatsapp-app)
87
-
88
- - [Save Auth Info](#saving--restoring-sessions)
89
- - [Handling Events](#handling-events)
90
- - [Example to Start](#example-to-start)
91
- - [Decrypt Poll Votes](#decrypt-poll-votes)
92
- - [Summary of Events on First Connection](#summary-of-events-on-first-connection)
93
- - [Implementing a Data Store](#implementing-a-data-store)
94
- - [Whatsapp IDs Explain](#whatsapp-ids-explain)
95
- - [Utility Functions](#utility-functions)
96
- - [Sending Messages](#sending-messages)
97
- - [Non-Media Messages](#non-media-messages)
98
- - [Text Message](#text-message)
99
- - [Quote Message](#quote-message-works-with-all-types)
100
- - [Mention User](#mention-user-works-with-most-types)
101
- - [Forward Messages](#forward-messages)
102
- - [Location Message](#location-message)
103
- - [Contact Message](#contact-message)
104
- - [Reaction Message](#reaction-message)
105
- - [Pin Message](#pin-message)
106
- - [Poll Message](#poll-message)
107
- - [Sending with Link Preview](#sending-messages-with-link-previews)
108
- - [Media Messages](#media-messages)
109
- - [Gif Message](#gif-message)
110
- - [Video Message](#video-message)
111
- - [Audio Message](#audio-message)
112
- - [Image Message](#image-message)
113
- - [ViewOnce Message](#view-once-message)
114
- - [Modify Messages](#modify-messages)
115
- - [Delete Messages (for everyone)](#deleting-messages-for-everyone)
116
- - [Edit Messages](#editing-messages)
117
- - [Manipulating Media Messages](#manipulating-media-messages)
118
- - [Thumbnail in Media Messages](#thumbnail-in-media-messages)
119
- - [Downloading Media Messages](#downloading-media-messages)
120
- - [Re-upload Media Message to Whatsapp](#re-upload-media-message-to-whatsapp)
121
- - [Reject Call](#reject-call)
122
- - [Send States in Chat](#send-states-in-chat)
123
- - [Reading Messages](#reading-messages)
124
- - [Update Presence](#update-presence)
125
- - [Modifying Chats](#modifying-chats)
126
- - [Archive a Chat](#archive-a-chat)
127
- - [Mute/Unmute a Chat](#muteunmute-a-chat)
128
- - [Mark a Chat Read/Unread](#mark-a-chat-readunread)
129
- - [Delete a Message for Me](#delete-a-message-for-me)
130
- - [Delete a Chat](#delete-a-chat)
131
- - [Star/Unstar a Message](#starunstar-a-message)
132
- - [Disappearing Messages](#disappearing-messages)
133
- - [User Querys](#user-querys)
134
- - [Check If ID Exists in Whatsapp](#check-if-id-exists-in-whatsapp)
135
- - [Query Chat History (groups too)](#query-chat-history-groups-too)
136
- - [Fetch Status](#fetch-status)
137
- - [Fetch Profile Picture (groups too)](#fetch-profile-picture-groups-too)
138
- - [Fetch Bussines Profile (such as description or category)](#fetch-bussines-profile-such-as-description-or-category)
139
- - [Fetch Someone's Presence (if they're typing or online)](#fetch-someones-presence-if-theyre-typing-or-online)
140
- - [Change Profile](#change-profile)
141
- - [Change Profile Status](#change-profile-status)
142
- - [Change Profile Name](#change-profile-name)
143
- - [Change Display Picture (groups too)](#change-display-picture-groups-too)
144
- - [Remove display picture (groups too)](#remove-display-picture-groups-too)
145
- - [Groups](#groups)
146
- - [Create a Group](#create-a-group)
147
- - [Add/Remove or Demote/Promote](#addremove-or-demotepromote)
148
- - [Change Subject (name)](#change-subject-name)
149
- - [Change Description](#change-description)
150
- - [Change Settings](#change-settings)
151
- - [Leave a Group](#leave-a-group)
152
- - [Get Invite Code](#get-invite-code)
153
- - [Revoke Invite Code](#revoke-invite-code)
154
- - [Join Using Invitation Code](#join-using-invitation-code)
155
- - [Get Group Info by Invite Code](#get-group-info-by-invite-code)
156
- - [Query Metadata (participants, name, description...)](#query-metadata-participants-name-description)
157
- - [Join using groupInviteMessage](#join-using-groupinvitemessage)
158
- - [Get Request Join List](#get-request-join-list)
159
- - [Approve/Reject Request Join](#approvereject-request-join)
160
- - [Get All Participating Groups Metadata](#get-all-participating-groups-metadata)
161
- - [Toggle Ephemeral](#toggle-ephemeral)
162
- - [Change Add Mode](#change-add-mode)
163
- - [Privacy](#privacy)
164
- - [Block/Unblock User](#blockunblock-user)
165
- - [Get Privacy Settings](#get-privacy-settings)
166
- - [Get BlockList](#get-blocklist)
167
- - [Update LastSeen Privacy](#update-lastseen-privacy)
168
- - [Update Online Privacy](#update-online-privacy)
169
- - [Update Profile Picture Privacy](#update-profile-picture-privacy)
170
- - [Update Status Privacy](#update-status-privacy)
171
- - [Update Read Receipts Privacy](#update-read-receipts-privacy)
172
- - [Update Groups Add Privacy](#update-groups-add-privacy)
173
- - [Update Default Disappearing Mode](#update-default-disappearing-mode)
174
- - [Broadcast Lists & Stories](#broadcast-lists--stories)
175
- - [Send Broadcast & Stories](#send-broadcast--stories)
176
- - [Query a Broadcast List's Recipients & Name](#query-a-broadcast-lists-recipients--name)
177
- - [Writing Custom Functionality](#writing-custom-functionality)
178
- - [Enabling Debug Level in Baileys Logs](#enabling-debug-level-in-baileys-logs)
179
- - [How Whatsapp Communicate With Us](#how-whatsapp-communicate-with-us)
180
- - [Register a Callback for Websocket Events](#register-a-callback-for-websocket-events)
181
-
182
- ## Connecting Account
183
-
184
- 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.
185
-
186
- > [!NOTE]
187
- > **[Here](#example-to-start) is a simple example of event handling**
188
-
189
- > [!TIP]
190
- > **You can see all supported socket configs in the [SocketConfig type alias](https://baileys.wiki/docs/api/type-aliases/SocketConfig/) (Recommended)**
191
-
192
- ### Starting socket with **QR-CODE**
193
-
194
- > [!TIP]
195
- > You can customize browser name if you connect with **QR-CODE**, with `Browser` constant, we have some browsers config, **see the [BrowsersMap type alias](https://baileys.wiki/docs/api/type-aliases/BrowsersMap/)**
196
-
197
- ```ts
45
+ ``` ts
198
46
  import makeWASocket from '@whiskeysockets/baileys'
199
-
200
- const sock = makeWASocket({
201
- // can provide additional config here
202
- browser: Browsers.ubuntu('My App'),
203
- printQRInTerminal: true
204
- })
205
47
  ```
206
48
 
207
- 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!
208
-
209
- ### Starting socket with **Pairing Code**
49
+ ## Unit Tests
210
50
 
51
+ TODO
211
52
 
212
- > [!IMPORTANT]
213
- > 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)
53
+ ## Connecting multi device (recommended)
214
54
 
215
- The phone number can't have `+` or `()` or `-`, only numbers, you must provide country code
55
+ WhatsApp provides a multi-device API that allows Baileys to be authenticated as a second WhatsApp client by scanning a QR code with WhatsApp on your phone.
216
56
 
217
- ```ts
218
- import makeWASocket from '@whiskeysockets/baileys'
57
+ ``` ts
58
+ import makeWASocket, { DisconnectReason } from '@whiskeysockets/baileys'
59
+ import { Boom } from '@hapi/boom'
219
60
 
220
- const sock = makeWASocket({
221
- // can provide additional config here
222
- printQRInTerminal: false //need to be false
223
- })
61
+ async function connectToWhatsApp () {
62
+ const sock = makeWASocket({
63
+ // can provide additional config here
64
+ printQRInTerminal: true
65
+ })
66
+ sock.ev.on('connection.update', (update) => {
67
+ const { connection, lastDisconnect } = update
68
+ if(connection === 'close') {
69
+ const shouldReconnect = (lastDisconnect.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut
70
+ console.log('connection closed due to ', lastDisconnect.error, ', reconnecting ', shouldReconnect)
71
+ // reconnect if not logged out
72
+ if(shouldReconnect) {
73
+ connectToWhatsApp()
74
+ }
75
+ } else if(connection === 'open') {
76
+ console.log('opened connection')
77
+ }
78
+ })
79
+ sock.ev.on('messages.upsert', m => {
80
+ console.log(JSON.stringify(m, undefined, 2))
224
81
 
225
- if (!sock.authState.creds.registered) {
226
- const number = 'XXXXXXXXXXX'
227
- const code = await sock.requestPairingCode(number)
228
- console.log(code)
82
+ console.log('replying to', m.messages[0].key.remoteJid)
83
+ await sock.sendMessage(m.messages[0].key.remoteJid!, { text: 'Hello there!' })
84
+ })
229
85
  }
230
- ```
231
-
232
- ### Receive Full History
86
+ // run in main file
87
+ connectToWhatsApp()
88
+ ```
233
89
 
234
- 1. Set `syncFullHistory` as `true`
235
- 2. Baileys, by default, use chrome browser config
236
- - If you'd like to emulate a desktop connection (and receive more message history), this browser setting to your Socket config:
90
+ 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!
237
91
 
238
- ```ts
239
- const sock = makeWASocket({
240
- ...otherOpts,
241
- // can use Windows, Ubuntu here too
242
- browser: Browsers.macOS('Desktop'),
243
- syncFullHistory: true
244
- })
92
+ **Note:** install `qrcode-terminal` using `yarn add qrcode-terminal` to auto-print the QR to the terminal.
93
+
94
+ **Note:** the code to support the legacy version of WA Web (pre multi-device) has been removed in v5. Only the standard multi-device connection is now supported. This is done as WA seems to have completely dropped support for the legacy version.
95
+
96
+ ## Connecting native mobile api
97
+
98
+ Baileys also supports the native mobile API, which allows users to authenticate as a standalone WhatsApp client using their phone number.
99
+
100
+ Run the [example](Example/example.ts) file with ``--mobile`` cli flag to use the native mobile API.
101
+
102
+ ## Configuring the Connection
103
+
104
+ You can configure the connection by passing a `SocketConfig` object.
105
+
106
+ The entire `SocketConfig` structure is mentioned here with default values:
107
+ ``` ts
108
+ type SocketConfig = {
109
+ /** the WS url to connect to WA */
110
+ waWebSocketUrl: string | URL
111
+ /** Fails the connection if the socket times out in this interval */
112
+ connectTimeoutMs: number
113
+ /** Default timeout for queries, undefined for no timeout */
114
+ defaultQueryTimeoutMs: number | undefined
115
+ /** ping-pong interval for WS connection */
116
+ keepAliveIntervalMs: number
117
+ /** proxy agent */
118
+ agent?: Agent
119
+ /** pino logger */
120
+ logger: Logger
121
+ /** version to connect with */
122
+ version: WAVersion
123
+ /** override browser config */
124
+ browser: WABrowserDescription
125
+ /** agent used for fetch requests -- uploading/downloading media */
126
+ fetchAgent?: Agent
127
+ /** should the QR be printed in the terminal */
128
+ printQRInTerminal: boolean
129
+ /** should events be emitted for actions done by this socket connection */
130
+ emitOwnEvents: boolean
131
+ /** provide a cache to store media, so does not have to be re-uploaded */
132
+ mediaCache?: NodeCache
133
+ /** custom upload hosts to upload media to */
134
+ customUploadHosts: MediaConnInfo['hosts']
135
+ /** time to wait between sending new retry requests */
136
+ retryRequestDelayMs: number
137
+ /** max msg retry count */
138
+ maxMsgRetryCount: number
139
+ /** time to wait for the generation of the next QR in ms */
140
+ qrTimeout?: number;
141
+ /** provide an auth state object to maintain the auth state */
142
+ auth: AuthenticationState
143
+ /** manage history processing with this control; by default will sync up everything */
144
+ shouldSyncHistoryMessage: (msg: proto.Message.IHistorySyncNotification) => boolean
145
+ /** transaction capability options for SignalKeyStore */
146
+ transactionOpts: TransactionCapabilityOptions
147
+ /** provide a cache to store a user's device list */
148
+ userDevicesCache?: NodeCache
149
+ /** marks the client as online whenever the socket successfully connects */
150
+ markOnlineOnConnect: boolean
151
+ /**
152
+ * map to store the retry counts for failed messages;
153
+ * used to determine whether to retry a message or not */
154
+ msgRetryCounterMap?: MessageRetryMap
155
+ /** width for link preview images */
156
+ linkPreviewImageThumbnailWidth: number
157
+ /** Should Baileys ask the phone for full history, will be received async */
158
+ syncFullHistory: boolean
159
+ /** Should baileys fire init queries automatically, default true */
160
+ fireInitQueries: boolean
161
+ /**
162
+ * generate a high quality link preview,
163
+ * entails uploading the jpegThumbnail to WA
164
+ * */
165
+ generateHighQualityLinkPreview: boolean
166
+
167
+ /** options for axios */
168
+ options: AxiosRequestConfig<any>
169
+ /**
170
+ * fetch a message from your store
171
+ * implement this so that messages failed to send (solves the "this message can take a while" issue) can be retried
172
+ * */
173
+ getMessage: (key: proto.IMessageKey) => Promise<proto.IMessage | undefined>
174
+ }
245
175
  ```
246
176
 
247
- ## Important Notes About Socket Config
248
-
249
- ### Caching Group Metadata (Recommended)
250
- - If you use baileys for groups, we recommend you to set `cachedGroupMetadata` in socket config, you need to implement a cache like this:
177
+ ### Emulating the Desktop app instead of the web
251
178
 
252
- ```ts
253
- const groupCache = new NodeCache({stdTTL: 5 * 60, useClones: false})
254
-
255
- const sock = makeWASocket({
256
- cachedGroupMetadata: async (jid) => groupCache.get(jid)
257
- })
258
-
259
- sock.ev.on('groups.update', async ([event]) => {
260
- const metadata = await sock.groupMetadata(event.id)
261
- groupCache.set(event.id, metadata)
262
- })
263
-
264
- sock.ev.on('group-participants.update', async (event) => {
265
- const metadata = await sock.groupMetadata(event.id)
266
- groupCache.set(event.id, metadata)
179
+ 1. Baileys, by default, emulates a chrome web session
180
+ 2. If you'd like to emulate a desktop connection (and receive more message history), add this to your Socket config:
181
+ ``` ts
182
+ const conn = makeWASocket({
183
+ ...otherOpts,
184
+ // can use Windows, Ubuntu here too
185
+ browser: Browsers.macOS('Desktop'),
186
+ syncFullHistory: true
267
187
  })
268
188
  ```
269
189
 
270
- ### Improve Retry System & Decrypt Poll Votes
271
- - 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:
272
- ```ts
273
- const sock = makeWASocket({
274
- getMessage: async (key) => await getMessageFromStore(key)
275
- })
276
- ```
277
-
278
- ### Receive Notifications in Whatsapp App
279
- - If you want to receive notifications in whatsapp app, set `markOnlineOnConnect` to `false`
280
- ```ts
281
- const sock = makeWASocket({
282
- markOnlineOnConnect: false
283
- })
284
- ```
285
190
  ## Saving & Restoring Sessions
286
191
 
287
- You obviously don't want to keep scanning the QR code every time you want to connect.
192
+ You obviously don't want to keep scanning the QR code every time you want to connect.
288
193
 
289
194
  So, you can load the credentials to log back in:
290
- ```ts
291
- import makeWASocket, { useMultiFileAuthState } from '@whiskeysockets/baileys'
195
+ ``` ts
196
+ import makeWASocket, { BufferJSON, useMultiFileAuthState } from '@whiskeysockets/baileys'
197
+ import * as fs from 'fs'
292
198
 
199
+ // utility function to help save the auth state in a single folder
200
+ // 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
293
201
  const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
294
-
295
202
  // will use the given state to connect
296
203
  // so if valid credentials are available -- it'll connect without QR
297
- const sock = makeWASocket({ auth: state })
298
-
204
+ const conn = makeWASocket({ auth: state })
299
205
  // this will be called as soon as the credentials are updated
300
- sock.ev.on('creds.update', saveCreds)
206
+ conn.ev.on ('creds.update', saveCreds)
207
+ ```
208
+
209
+ **Note:** 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.
210
+
211
+ ## Listening to Connection Updates
212
+
213
+ Baileys now fires the `connection.update` event to let you know something has updated in the connection. This data has the following structure:
214
+ ``` ts
215
+ type ConnectionState = {
216
+ /** connection is now open, connecting or closed */
217
+ connection: WAConnectionState
218
+ /** the error that caused the connection to close */
219
+ lastDisconnect?: {
220
+ error: Error
221
+ date: Date
222
+ }
223
+ /** is this a new login */
224
+ isNewLogin?: boolean
225
+ /** the current QR code */
226
+ qr?: string
227
+ /** has the device received all pending notifications while it was offline */
228
+ receivedPendingNotifications?: boolean
229
+ }
301
230
  ```
302
231
 
303
- > [!IMPORTANT]
304
- > `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.
305
-
306
- > [!NOTE]
307
- > 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.
232
+ **Note:** this also offers any updates to the QR
308
233
 
309
234
  ## Handling Events
310
235
 
311
- - Baileys uses the EventEmitter syntax for events.
236
+ Baileys uses the EventEmitter syntax for events.
312
237
  They're all nicely typed up, so you shouldn't have any issues with an Intellisense editor like VS Code.
313
238
 
314
- > [!IMPORTANT]
315
- > **The events are in the [BaileysEventMap type alias](https://baileys.wiki/docs/api/type-aliases/BaileysEventMap/)**, it's important you see all events
239
+ The events are typed as mentioned here:
240
+
241
+ ``` ts
242
+
243
+ export type BaileysEventMap = {
244
+ /** connection state has been updated -- WS closed, opened, connecting etc. */
245
+ 'connection.update': Partial<ConnectionState>
246
+ /** credentials updated -- some metadata, keys or something */
247
+ 'creds.update': Partial<AuthenticationCreds>
248
+ /** history sync, everything is reverse chronologically sorted */
249
+ 'messaging-history.set': {
250
+ chats: Chat[]
251
+ contacts: Contact[]
252
+ messages: WAMessage[]
253
+ isLatest: boolean
254
+ }
255
+ /** upsert chats */
256
+ 'chats.upsert': Chat[]
257
+ /** update the given chats */
258
+ 'chats.update': Partial<Chat>[]
259
+ /** delete chats with given ID */
260
+ 'chats.delete': string[]
261
+ 'labels.association': LabelAssociation
262
+ 'labels.edit': Label
263
+ /** presence of contact in a chat updated */
264
+ 'presence.update': { id: string, presences: { [participant: string]: PresenceData } }
265
+
266
+ 'contacts.upsert': Contact[]
267
+ 'contacts.update': Partial<Contact>[]
268
+
269
+ 'messages.delete': { keys: WAMessageKey[] } | { jid: string, all: true }
270
+ 'messages.update': WAMessageUpdate[]
271
+ 'messages.media-update': { key: WAMessageKey, media?: { ciphertext: Uint8Array, iv: Uint8Array }, error?: Boom }[]
272
+ /**
273
+ * add/update the given messages. If they were received while the connection was online,
274
+ * the update will have type: "notify"
275
+ * */
276
+ 'messages.upsert': { messages: WAMessage[], type: MessageUpsertType }
277
+ /** message was reacted to. If reaction was removed -- then "reaction.text" will be falsey */
278
+ 'messages.reaction': { key: WAMessageKey, reaction: proto.IReaction }[]
279
+
280
+ 'message-receipt.update': MessageUserReceiptUpdate[]
281
+
282
+ 'groups.upsert': GroupMetadata[]
283
+ 'groups.update': Partial<GroupMetadata>[]
284
+ /** apply an action to participants in a group */
285
+ 'group-participants.update': { id: string, participants: string[], action: ParticipantAction }
286
+
287
+ 'blocklist.set': { blocklist: string[] }
288
+ 'blocklist.update': { blocklist: string[], type: 'add' | 'remove' }
289
+ /** Receive an update on a call, including when the call was received, rejected, accepted */
290
+ 'call': WACallEvent[]
291
+ }
292
+ ```
316
293
 
317
294
  You can listen to these events like this:
318
- ```ts
295
+ ``` ts
296
+
319
297
  const sock = makeWASocket()
320
298
  sock.ev.on('messages.upsert', ({ messages }) => {
321
299
  console.log('got messages', messages)
322
300
  })
323
- ```
324
-
325
- ### Example to Start
326
-
327
- > [!NOTE]
328
- > This example includes basic auth storage too
329
-
330
- > [!NOTE]
331
- > For reliable serialization of the authentication state, especially when storing as JSON, always use the BufferJSON utility.
332
-
333
- ```ts
334
- import makeWASocket, { DisconnectReason, useMultiFileAuthState } from '@whiskeysockets/baileys'
335
- import { Boom } from '@hapi/boom'
336
-
337
- async function connectToWhatsApp () {
338
- const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
339
- const sock = makeWASocket({
340
- // can provide additional config here
341
- auth: state,
342
- printQRInTerminal: true
343
- })
344
- sock.ev.on('connection.update', (update) => {
345
- const { connection, lastDisconnect } = update
346
- if(connection === 'close') {
347
- const shouldReconnect = (lastDisconnect.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut
348
- console.log('connection closed due to ', lastDisconnect.error, ', reconnecting ', shouldReconnect)
349
- // reconnect if not logged out
350
- if(shouldReconnect) {
351
- connectToWhatsApp()
352
- }
353
- } else if(connection === 'open') {
354
- console.log('opened connection')
355
- }
356
- })
357
- sock.ev.on('messages.upsert', event => {
358
- for (const m of event.messages) {
359
- console.log(JSON.stringify(m, undefined, 2))
360
-
361
- console.log('replying to', m.key.remoteJid)
362
- await sock.sendMessage(m.key.remoteJid!, { text: 'Hello Word' })
363
- }
364
- })
365
301
 
366
- // to storage creds (session info) when it updates
367
- sock.ev.on('creds.update', saveCreds)
368
- }
369
- // run in main file
370
- connectToWhatsApp()
371
- ```
372
-
373
- > [!IMPORTANT]
374
- > In `messages.upsert` it's recommended to use a loop like `for (const message of event.messages)` to handle all messages in array
375
-
376
- ### Decrypt Poll Votes
377
-
378
- - By default poll votes are encrypted and handled in `messages.update`
379
- - That's a simple example
380
- ```ts
381
- sock.ev.on('messages.update', event => {
382
- for(const { key, update } of event) {
383
- if(update.pollUpdates) {
384
- const pollCreation = await getMessage(key)
385
- if(pollCreation) {
386
- console.log(
387
- 'got poll update, aggregation: ',
388
- getAggregateVotesInPollMessage({
389
- message: pollCreation,
390
- pollUpdates: update.pollUpdates,
391
- })
392
- )
393
- }
394
- }
395
- }
396
- })
397
302
  ```
398
303
 
399
- - `getMessage` is a [store](#implementing-a-data-store) implementation (in your end)
400
-
401
- ### Summary of Events on First Connection
402
-
403
- 1. When you connect first time, `connection.update` will be fired requesting you to restart sock
404
- 2. Then, history messages will be received in `messaging.history-set`
405
-
406
304
  ## Implementing a Data Store
407
305
 
408
- - 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.
409
-
410
- > [!IMPORTANT]
411
- > I highly recommend building your own data store, as storing someone's entire chat history in memory is a terrible waste of RAM.
306
+ 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.
412
307
 
413
308
  It can be used as follows:
414
309
 
415
- ```ts
310
+ ``` ts
416
311
  import makeWASocket, { makeInMemoryStore } from '@whiskeysockets/baileys'
417
312
  // the store maintains the data of the WA connection in memory
418
313
  // can be written out to a file & read from it
@@ -430,8 +325,8 @@ const sock = makeWASocket({ })
430
325
  store.bind(sock.ev)
431
326
 
432
327
  sock.ev.on('chats.upsert', () => {
433
- // can use 'store.chats' however you want, even after the socket dies out
434
- // 'chats' => a KeyedDB instance
328
+ // can use "store.chats" however you want, even after the socket dies out
329
+ // "chats" => a KeyedDB instance
435
330
  console.log('got chats', store.chats.all())
436
331
  })
437
332
 
@@ -443,306 +338,198 @@ sock.ev.on('contacts.upsert', () => {
443
338
 
444
339
  The store also provides some simple functions such as `loadMessages` that utilize the store to speed up data retrieval.
445
340
 
446
- ## Whatsapp IDs Explain
447
-
448
- - `id` is the WhatsApp ID, called `jid` too, of the person or group you're sending the message to.
449
- - It must be in the format ```[country code][phone number]@s.whatsapp.net```
450
- - Example for people: ```+19999999999@s.whatsapp.net```.
451
- - For groups, it must be in the format ``` 123456789-123345@g.us ```.
452
- - For broadcast lists, it's `[timestamp of creation]@broadcast`.
453
- - For stories, the ID is `status@broadcast`.
454
-
455
- ## Utility Functions
456
-
457
- - `getContentType`, returns the content type for any message
458
- - `getDevice`, returns the device from message
459
- - `makeCacheableSignalKeyStore`, make auth store more fast
460
- - `downloadContentFromMessage`, download content from any message
341
+ **Note:** I highly recommend building your own data store especially for MD connections, as storing someone's entire chat history in memory is a terrible waste of RAM.
461
342
 
462
343
  ## Sending Messages
463
344
 
464
- - Send all types of messages with a single function
465
- - **In the [AnyMessageContent type alias](https://baileys.wiki/docs/api/type-aliases/AnyMessageContent/) you can see all message contents supported, like text message**
466
- - **In the [MiscMessageGenerationOptions type alias](https://baileys.wiki/docs/api/type-aliases/MiscMessageGenerationOptions/) you can see all options supported, like quote message**
467
-
468
- ```ts
469
- const jid: string
470
- const content: AnyMessageContent
471
- const options: MiscMessageGenerationOptions
472
-
473
- sock.sendMessage(jid, content, options)
474
- ```
345
+ **Send all types of messages with a single function:**
475
346
 
476
347
  ### Non-Media Messages
477
348
 
478
- #### Text Message
479
- ```ts
480
- await sock.sendMessage(jid, { text: 'hello word' })
481
- ```
482
-
483
- #### Quote Message (works with all types)
484
- ```ts
485
- await sock.sendMessage(jid, { text: 'hello word' }, { quoted: message })
486
- ```
487
-
488
- #### Mention User (works with most types)
489
- - @number is to mention in text, it's optional
490
- ```ts
491
- await sock.sendMessage(
492
- jid,
493
- {
494
- text: '@12345678901',
495
- mentions: ['12345678901@s.whatsapp.net']
496
- }
349
+ ``` ts
350
+ import { MessageType, MessageOptions, Mimetype } from '@whiskeysockets/baileys'
351
+
352
+ const id = 'abcd@s.whatsapp.net' // the WhatsApp ID
353
+ // send a simple text!
354
+ const sentMsg = await sock.sendMessage(id, { text: 'oh hello there' })
355
+ // send a reply messagge
356
+ const sentMsg = await sock.sendMessage(id, { text: 'oh hello there' }, { quoted: message })
357
+ // send a mentions message
358
+ const sentMsg = await sock.sendMessage(id, { text: '@12345678901', mentions: ['12345678901@s.whatsapp.net'] })
359
+ // send a location!
360
+ const sentMsg = await sock.sendMessage(
361
+ id,
362
+ { location: { degreesLatitude: 24.121231, degreesLongitude: 55.1121221 } }
497
363
  )
498
- ```
499
-
500
- #### Forward Messages
501
- - You need to have message object, can be retrieved from [store](#implementing-a-data-store) or use a [message](https://baileys.wiki/docs/api/type-aliases/WAMessage/) object
502
- ```ts
503
- const msg = getMessageFromStore() // implement this on your end
504
- await sock.sendMessage(jid, { forward: msg }) // WA forward the message!
505
- ```
506
-
507
- #### Location Message
508
- ```ts
509
- await sock.sendMessage(
510
- jid,
511
- {
512
- location: {
513
- degreesLatitude: 24.121231,
514
- degreesLongitude: 55.1121221
515
- }
516
- }
517
- )
518
- ```
519
- #### Contact Message
520
- ```ts
364
+ // send a contact!
521
365
  const vcard = 'BEGIN:VCARD\n' // metadata of the contact card
522
- + 'VERSION:3.0\n'
366
+ + 'VERSION:3.0\n'
523
367
  + 'FN:Jeff Singh\n' // full name
524
368
  + 'ORG:Ashoka Uni;\n' // the organization of the contact
525
369
  + 'TEL;type=CELL;type=VOICE;waid=911234567890:+91 12345 67890\n' // WhatsApp ID + phone number
526
370
  + 'END:VCARD'
527
-
528
- await sock.sendMessage(
371
+ const sentMsg = await sock.sendMessage(
529
372
  id,
530
- {
531
- contacts: {
532
- displayName: 'Jeff',
533
- contacts: [{ vcard }]
534
- }
535
- }
536
- )
537
- ```
538
-
539
- #### Reaction Message
540
- - You need to pass the key of message, you can retrieve from [store](#implementing-a-data-store) or use a [key](https://baileys.wiki/docs/api/type-aliases/WAMessageKey/) object
541
- ```ts
542
- await sock.sendMessage(
543
- jid,
544
- {
545
- react: {
546
- text: '💖', // use an empty string to remove the reaction
547
- key: message.key
373
+ {
374
+ contacts: {
375
+ displayName: 'Jeff',
376
+ contacts: [{ vcard }]
548
377
  }
549
378
  }
550
379
  )
551
- ```
552
-
553
- #### Pin Message
554
- - You need to pass the key of message, you can retrieve from [store](#implementing-a-data-store) or use a [key](https://baileys.wiki/docs/api/type-aliases/WAMessageKey/) object
555
380
 
556
- - Time can be:
557
-
558
- | Time | Seconds |
559
- |-------|----------------|
560
- | 24h | 86.400 |
561
- | 7d | 604.800 |
562
- | 30d | 2.592.000 |
563
-
564
- ```ts
565
- await sock.sendMessage(
566
- jid,
567
- {
568
- pin: {
569
- type: 1, // 0 to remove
570
- time: 86400
571
- key: message.key
572
- }
381
+ const reactionMessage = {
382
+ react: {
383
+ text: "💖", // use an empty string to remove the reaction
384
+ key: message.key
573
385
  }
574
- )
575
- ```
386
+ }
576
387
 
577
- #### Poll Message
578
- ```ts
579
- await sock.sendMessage(
580
- jid,
581
- {
582
- poll: {
583
- name: 'My Poll',
584
- values: ['Option 1', 'Option 2', ...],
585
- selectableCount: 1,
586
- toAnnouncementGroup: false // or true
587
- }
588
- }
589
- )
388
+ const sendMsg = await sock.sendMessage(id, reactionMessage)
590
389
  ```
591
390
 
592
- ### Sending Messages with Link Previews
391
+ ### Sending messages with link previews
593
392
 
594
- 1. By default, wa does not have link generation when sent from the web
393
+ 1. By default, WA MD does not have link generation when sent from the web
595
394
  2. Baileys has a function to generate the content for these link previews
596
395
  3. To enable this function's usage, add `link-preview-js` as a dependency to your project with `yarn add link-preview-js`
597
396
  4. Send a link:
598
- ```ts
599
- await sock.sendMessage(
600
- jid,
601
- {
602
- text: 'Hi, this was sent using https://github.com/whiskeysockets/baileys'
603
- }
604
- )
397
+ ``` ts
398
+ // send a link
399
+ const sentMsg = await sock.sendMessage(id, { text: 'Hi, this was sent using https://github.com/adiwajshing/baileys' })
605
400
  ```
606
401
 
607
402
  ### Media Messages
608
403
 
609
- Sending media (video, stickers, images) is easier & more efficient than ever.
610
-
611
- > [!NOTE]
612
- > In media messages, you can pass `{ stream: Stream }` or `{ url: Url }` or `Buffer` directly, you can see more in the [WAMediaUpload type alias](https://baileys.wiki/docs/api/type-aliases/WAMediaUpload/)
613
-
404
+ Sending media (video, stickers, images) is easier & more efficient than ever.
405
+ - You can specify a buffer, a local url or even a remote url.
614
406
  - When specifying a media url, Baileys never loads the entire buffer into memory; it even encrypts the media as a readable stream.
615
407
 
616
- > [!TIP]
617
- > It's recommended to use Stream or Url to save memory
618
-
619
- #### Gif Message
620
- - Whatsapp doesn't support `.gif` files, that's why we send gifs as common `.mp4` video with `gifPlayback` flag
621
- ```ts
408
+ ``` ts
409
+ import { MessageType, MessageOptions, Mimetype } from '@whiskeysockets/baileys'
410
+ // Sending gifs
622
411
  await sock.sendMessage(
623
- jid,
624
- {
625
- video: fs.readFileSync('Media/ma_gif.mp4'),
626
- caption: 'hello word',
412
+ id,
413
+ {
414
+ video: fs.readFileSync("Media/ma_gif.mp4"),
415
+ caption: "hello!",
627
416
  gifPlayback: true
628
417
  }
629
418
  )
630
- ```
631
419
 
632
- #### Video Message
633
- ```ts
634
420
  await sock.sendMessage(
635
- id,
636
- {
637
- video: {
638
- url: './Media/ma_gif.mp4'
639
- },
640
- caption: 'hello word',
641
- ptv: false // if set to true, will send as a `video note`
421
+ id,
422
+ {
423
+ video: "./Media/ma_gif.mp4",
424
+ caption: "hello!",
425
+ gifPlayback: true,
426
+ ptv: false // if set to true, will send as a `video note`
642
427
  }
643
428
  )
644
- ```
645
429
 
646
- #### Audio Message
647
- - To audio message work in all devices you need to convert with some tool like `ffmpeg` with this flags:
648
- ```bash
649
- codec: libopus //ogg file
650
- ac: 1 //one channel
651
- avoid_negative_ts
652
- make_zero
653
- ```
654
- - Example:
655
- ```bash
656
- ffmpeg -i input.mp4 -avoid_negative_ts make_zero -ac 1 output.ogg
657
- ```
658
- ```ts
430
+ // send an audio file
659
431
  await sock.sendMessage(
660
- jid,
661
- {
662
- audio: {
663
- url: './Media/audio.mp3'
664
- },
665
- mimetype: 'audio/mp4'
666
- }
432
+ id,
433
+ { audio: { url: "./Media/audio.mp3" }, mimetype: 'audio/mp4' }
434
+ { url: "Media/audio.mp3" }, // can send mp3, mp4, & ogg
667
435
  )
668
436
  ```
669
437
 
670
- #### Image Message
671
- ```ts
672
- await sock.sendMessage(
673
- id,
674
- {
675
- image: {
676
- url: './Media/ma_img.png'
677
- },
678
- caption: 'hello word'
438
+ ### Notes
439
+
440
+ - `id` is the WhatsApp ID of the person or group you're sending the message to.
441
+ - It must be in the format ```[country code][phone number]@s.whatsapp.net```
442
+ - Example for people: ```+19999999999@s.whatsapp.net```.
443
+ - For groups, it must be in the format ``` 123456789-123345@g.us ```.
444
+ - For broadcast lists, it's `[timestamp of creation]@broadcast`.
445
+ - For stories, the ID is `status@broadcast`.
446
+ - For media messages, the thumbnail can be generated automatically for images & stickers provided you add `jimp` or `sharp` as a dependency in your project using `yarn add jimp` or `yarn add sharp`. Thumbnails for videos can also be generated automatically, though, you need to have `ffmpeg` installed on your system.
447
+ - **MiscGenerationOptions**: some extra info about the message. It can have the following __optional__ values:
448
+ ``` ts
449
+ const info: MessageOptions = {
450
+ quoted: quotedMessage, // the message you want to quote
451
+ contextInfo: { forwardingScore: 2, isForwarded: true }, // some random context info (can show a forwarded message with this too)
452
+ timestamp: Date(), // optional, if you want to manually set the timestamp of the message
453
+ caption: "hello there!", // (for media messages) the caption to send with the media (cannot be sent with stickers though)
454
+ jpegThumbnail: "23GD#4/==", /* (for location & media messages) has to be a base 64 encoded JPEG if you want to send a custom thumb,
455
+ or set to null if you don't want to send a thumbnail.
456
+ Do not enter this field if you want to automatically generate a thumb
457
+ */
458
+ mimetype: Mimetype.pdf, /* (for media messages) specify the type of media (optional for all media types except documents),
459
+ import {Mimetype} from '@whiskeysockets/baileys'
460
+ */
461
+ fileName: 'somefile.pdf', // (for media messages) file name for the media
462
+ /* will send audio messages as voice notes, if set to true */
463
+ ptt: true,
464
+ /** Should it send as a disappearing messages.
465
+ * By default 'chat' -- which follows the setting of the chat */
466
+ ephemeralExpiration: WA_DEFAULT_EPHEMERAL
679
467
  }
680
- )
468
+ ```
469
+ ## Forwarding Messages
470
+
471
+ ``` ts
472
+ const msg = getMessageFromStore('455@s.whatsapp.net', 'HSJHJWH7323HSJSJ') // implement this on your end
473
+ await sock.sendMessage('1234@s.whatsapp.net', { forward: msg }) // WA forward the message!
681
474
  ```
682
475
 
683
- #### View Once Message
476
+ ## Reading Messages
684
477
 
685
- - You can send all messages above as `viewOnce`, you only need to pass `viewOnce: true` in content object
478
+ A set of message keys must be explicitly marked read now.
479
+ In multi-device, you cannot mark an entire "chat" read as it were with Baileys Web.
480
+ This means you have to keep track of unread messages.
686
481
 
687
- ```ts
688
- await sock.sendMessage(
689
- id,
690
- {
691
- image: {
692
- url: './Media/ma_img.png'
693
- },
694
- viewOnce: true, //works with video, audio too
695
- caption: 'hello word'
696
- }
697
- )
482
+ ``` ts
483
+ const key = {
484
+ remoteJid: '1234-123@g.us',
485
+ id: 'AHASHH123123AHGA', // id of the message you want to read
486
+ participant: '912121232@s.whatsapp.net' // the ID of the user that sent the message (undefined for individual chats)
487
+ }
488
+ // pass to readMessages function
489
+ // can pass multiple keys to read multiple messages as well
490
+ await sock.readMessages([key])
698
491
  ```
699
492
 
700
- ## Modify Messages
493
+ The message ID is the unique identifier of the message that you are marking as read.
494
+ On a `WAMessage`, the `messageID` can be accessed using ```messageID = message.key.id```.
701
495
 
702
- ### Deleting Messages (for everyone)
496
+ ## Update Presence
703
497
 
704
- ```ts
705
- const msg = await sock.sendMessage(jid, { text: 'hello word' })
706
- await sock.sendMessage(jid, { delete: msg.key })
707
- ```
498
+ ``` ts
499
+ await sock.sendPresenceUpdate('available', id)
708
500
 
709
- **Note:** deleting for oneself is supported via `chatModify`, see in [this section](#modifying-chats)
710
-
711
- ### Editing Messages
501
+ ```
502
+ This lets the person/group with ``` id ``` know whether you're online, offline, typing etc.
712
503
 
713
- - You can pass all editable contents here
714
- ```ts
715
- await sock.sendMessage(jid, {
716
- text: 'updated text goes here',
717
- edit: response.key,
718
- });
504
+ ``` presence ``` can be one of the following:
505
+ ``` ts
506
+ type WAPresence = 'unavailable' | 'available' | 'composing' | 'recording' | 'paused'
719
507
  ```
720
508
 
721
- ## Manipulating Media Messages
509
+ The presence expires after about 10 seconds.
722
510
 
723
- ### Thumbnail in Media Messages
724
- - For media messages, the thumbnail can be generated automatically for images & stickers provided you add `jimp` or `sharp` as a dependency in your project using `yarn add jimp` or `yarn add sharp`.
725
- - Thumbnails for videos can also be generated automatically, though, you need to have `ffmpeg` installed on your system.
511
+ **Note:** In the multi-device version of WhatsApp -- if a desktop client is active, WA doesn't send push notifications to the device. If you would like to receive said notifications -- mark your Baileys client offline using `sock.sendPresenceUpdate('unavailable')`
726
512
 
727
- ### Downloading Media Messages
513
+ ## Downloading Media Messages
728
514
 
729
515
  If you want to save the media you received
730
- ```ts
731
- import { createWriteStream } from 'fs'
732
- import { downloadMediaMessage, getContentType } from '@whiskeysockets/baileys'
516
+ ``` ts
517
+ import { writeFile } from 'fs/promises'
518
+ import { downloadMediaMessage } from '@whiskeysockets/baileys'
733
519
 
734
- sock.ev.on('messages.upsert', async ({ [m] }) => {
735
- if (!m.message) return // if there is no text or media message
736
- const messageType = getContentType(m) // get what type of message it is (text, image, video...)
520
+ sock.ev.on('messages.upsert', async ({ messages }) => {
521
+ const m = messages[0]
737
522
 
523
+ if (!m.message) return // if there is no text or media message
524
+ const messageType = Object.keys (m.message)[0]// get what type of message it is -- text, image, video
738
525
  // if the message is an image
739
526
  if (messageType === 'imageMessage') {
740
527
  // download the message
741
- const stream = await downloadMediaMessage(
528
+ const buffer = await downloadMediaMessage(
742
529
  m,
743
- 'stream', // can be 'buffer' too
530
+ 'buffer',
744
531
  { },
745
- {
532
+ {
746
533
  logger,
747
534
  // pass this so that baileys can request a reupload of media
748
535
  // that has been deleted
@@ -750,563 +537,363 @@ sock.ev.on('messages.upsert', async ({ [m] }) => {
750
537
  }
751
538
  )
752
539
  // save to file
753
- const writeStream = createWriteStream('./my-download.jpeg')
754
- stream.pipe(writeStream)
540
+ await writeFile('./my-download.jpeg', buffer)
755
541
  }
756
542
  }
757
543
  ```
758
544
 
759
- ### Re-upload Media Message to Whatsapp
760
-
761
- - WhatsApp automatically removes old media from their servers. For the device to access said media -- a re-upload is required by another device that has it. This can be accomplished using:
762
- ```ts
763
- await sock.updateMediaMessage(msg)
764
- ```
765
-
766
- ## Reject Call
767
-
768
- - You can obtain `callId` and `callFrom` from `call` event
769
-
770
- ```ts
771
- await sock.rejectCall(callId, callFrom)
545
+ **Note:** WhatsApp automatically removes old media from their servers. For the device to access said media -- a re-upload is required by another device that has it. This can be accomplished using:
546
+ ``` ts
547
+ const updatedMediaMsg = await sock.updateMediaMessage(msg)
772
548
  ```
773
549
 
774
- ## Send States in Chat
550
+ ## Deleting Messages
775
551
 
776
- ### Reading Messages
777
- - A set of message [keys](https://baileys.wiki/docs/api/type-aliases/WAMessageKey/) must be explicitly marked read now.
778
- - You cannot mark an entire 'chat' read as it were with Baileys Web.
779
- This means you have to keep track of unread messages.
780
-
781
- ```ts
782
- const key: WAMessageKey
783
- // can pass multiple keys to read multiple messages as well
784
- await sock.readMessages([key])
552
+ ``` ts
553
+ const jid = '1234@s.whatsapp.net' // can also be a group
554
+ const response = await sock.sendMessage(jid, { text: 'hello!' }) // send a message
555
+ // sends a message to delete the given message
556
+ // this deletes the message for everyone
557
+ await sock.sendMessage(jid, { delete: response.key })
785
558
  ```
786
559
 
787
- The message ID is the unique identifier of the message that you are marking as read.
788
- On a `WAMessage`, the `messageID` can be accessed using ```messageID = message.key.id```.
560
+ **Note:** deleting for oneself is supported via `chatModify` (next section)
789
561
 
790
- ### Update Presence
562
+ ## Updating Messages
791
563
 
792
- - ``` presence ``` can be one of the values in the [WAPresence type alias](https://baileys.wiki/docs/api/type-aliases/WAPresence/)
793
- - The presence expires after about 10 seconds.
794
- - This lets the person/group with `jid` know whether you're online, offline, typing etc.
564
+ ``` ts
565
+ const jid = '1234@s.whatsapp.net'
795
566
 
796
- ```ts
797
- await sock.sendPresenceUpdate('available', jid)
567
+ await sock.sendMessage(jid, {
568
+ text: 'updated text goes here',
569
+ edit: response.key,
570
+ });
798
571
  ```
799
572
 
800
- > [!NOTE]
801
- > If a desktop client is active, WA doesn't send push notifications to the device. If you would like to receive said notifications -- mark your Baileys client offline using `sock.sendPresenceUpdate('unavailable')`
802
-
803
573
  ## Modifying Chats
804
574
 
805
575
  WA uses an encrypted form of communication to send chat/app updates. This has been implemented mostly and you can send the following updates:
806
576
 
807
- > [!IMPORTANT]
808
- > If you mess up one of your updates, WA can log you out of all your devices and you'll have to log in again.
809
-
810
- ### Archive a Chat
811
- ```ts
812
- const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
813
- await sock.chatModify({ archive: true, lastMessages: [lastMsgInChat] }, jid)
814
- ```
815
- ### Mute/Unmute a Chat
816
-
817
- - Supported times:
818
-
819
- | Time | Miliseconds |
820
- |-------|-----------------|
821
- | Remove | null |
822
- | 8h | 86.400.000 |
823
- | 7d | 604.800.000 |
824
-
825
- ```ts
826
- // mute for 8 hours
827
- await sock.chatModify({ mute: 8 * 60 * 60 * 1000 }, jid)
828
- // unmute
829
- await sock.chatModify({ mute: null }, jid)
830
- ```
831
- ### Mark a Chat Read/Unread
832
- ```ts
833
- const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
834
- // mark it unread
835
- await sock.chatModify({ markRead: false, lastMessages: [lastMsgInChat] }, jid)
836
- ```
837
-
838
- ### Delete a Message for Me
839
- ```ts
840
- await sock.chatModify(
841
- {
842
- clear: {
843
- messages: [
844
- {
845
- id: 'ATWYHDNNWU81732J',
846
- fromMe: true,
847
- timestamp: '1654823909'
848
- }
849
- ]
850
- }
851
- },
852
- jid
853
- )
854
-
855
- ```
856
- ### Delete a Chat
857
- ```ts
858
- const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
859
- await sock.chatModify({
860
- delete: true,
861
- lastMessages: [
862
- {
863
- key: lastMsgInChat.key,
864
- messageTimestamp: lastMsgInChat.messageTimestamp
865
- }
866
- ]
867
- },
868
- jid
869
- )
870
- ```
871
- ### Pin/Unpin a Chat
872
- ```ts
873
- await sock.chatModify({
874
- pin: true // or `false` to unpin
875
- },
876
- jid
877
- )
878
- ```
879
- ### Star/Unstar a Message
880
- ```ts
881
- await sock.chatModify({
882
- star: {
883
- messages: [
884
- {
885
- id: 'messageID',
886
- fromMe: true // or `false`
887
- }
888
- ],
889
- star: true // - true: Star Message; false: Unstar Message
890
- }
891
- },
892
- jid
893
- )
894
- ```
895
-
896
- ### Disappearing Messages
897
-
898
- - Ephemeral can be:
899
-
900
- | Time | Seconds |
901
- |-------|----------------|
902
- | Remove | 0 |
903
- | 24h | 86.400 |
904
- | 7d | 604.800 |
905
- | 90d | 7.776.000 |
906
-
907
- - You need to pass in **Seconds**, default is 7 days
908
-
909
- ```ts
577
+ - Archive a chat
578
+ ``` ts
579
+ const lastMsgInChat = await getLastMessageInChat('123456@s.whatsapp.net') // implement this on your end
580
+ await sock.chatModify({ archive: true, lastMessages: [lastMsgInChat] }, '123456@s.whatsapp.net')
581
+ ```
582
+ - Mute/unmute a chat
583
+ ``` ts
584
+ // mute for 8 hours
585
+ await sock.chatModify({ mute: 8*60*60*1000 }, '123456@s.whatsapp.net', [])
586
+ // unmute
587
+ await sock.chatModify({ mute: null }, '123456@s.whatsapp.net', [])
588
+ ```
589
+ - Mark a chat read/unread
590
+ ``` ts
591
+ const lastMsgInChat = await getLastMessageInChat('123456@s.whatsapp.net') // implement this on your end
592
+ // mark it unread
593
+ await sock.chatModify({ markRead: false, lastMessages: [lastMsgInChat] }, '123456@s.whatsapp.net')
594
+ ```
595
+
596
+ - Delete a message for me
597
+ ``` ts
598
+ await sock.chatModify(
599
+ { clear: { messages: [{ id: 'ATWYHDNNWU81732J', fromMe: true, timestamp: "1654823909" }] } },
600
+ '123456@s.whatsapp.net',
601
+ []
602
+ )
603
+
604
+ ```
605
+
606
+ - Delete a chat
607
+ ``` ts
608
+ const lastMsgInChat = await getLastMessageInChat('123456@s.whatsapp.net') // implement this on your end
609
+ await sock.chatModify({
610
+ delete: true,
611
+ lastMessages: [{ key: lastMsgInChat.key, messageTimestamp: lastMsgInChat.messageTimestamp }]
612
+ },
613
+ '123456@s.whatsapp.net')
614
+ ```
615
+
616
+ - Pin/unpin a chat
617
+ ``` ts
618
+ await sock.chatModify({
619
+ pin: true // or `false` to unpin
620
+ },
621
+ '123456@s.whatsapp.net')
622
+ ```
623
+
624
+ - Star/unstar a message
625
+ ``` ts
626
+ await sock.chatModify({
627
+ star: {
628
+ messages: [{ id: 'messageID', fromMe: true // or `false` }],
629
+ star: true // - true: Star Message; false: Unstar Message
630
+ }},'123456@s.whatsapp.net');
631
+ ```
632
+
633
+ **Note:** if you mess up one of your updates, WA can log you out of all your devices and you'll have to log in again.
634
+
635
+ ## Disappearing Messages
636
+
637
+ ``` ts
638
+ const jid = '1234@s.whatsapp.net' // can also be a group
910
639
  // turn on disappearing messages
911
640
  await sock.sendMessage(
912
- jid,
641
+ jid,
913
642
  // this is 1 week in seconds -- how long you want messages to appear for
914
643
  { disappearingMessagesInChat: WA_DEFAULT_EPHEMERAL }
915
644
  )
916
-
917
645
  // will send as a disappearing message
918
646
  await sock.sendMessage(jid, { text: 'hello' }, { ephemeralExpiration: WA_DEFAULT_EPHEMERAL })
919
-
920
647
  // turn off disappearing messages
921
648
  await sock.sendMessage(
922
- jid,
649
+ jid,
923
650
  { disappearingMessagesInChat: false }
924
651
  )
925
- ```
926
-
927
- ## User Querys
928
-
929
- ### Check If ID Exists in Whatsapp
930
- ```ts
931
- const [result] = await sock.onWhatsApp(jid)
932
- if (result.exists) console.log (`${jid} exists on WhatsApp, as jid: ${result.jid}`)
933
- ```
934
652
 
935
- ### Query Chat History (groups too)
936
-
937
- - You need to have oldest message in chat
938
- ```ts
939
- const msg = await getOldestMessageInChat(jid) // implement this on your end
940
- await sock.fetchMessageHistory(
941
- 50, //quantity (max: 50 per query)
942
- msg.key,
943
- msg.messageTimestamp
944
- )
945
653
  ```
946
- - Messages will be received in `messaging.history-set` event
947
654
 
948
- ### Fetch Status
949
- ```ts
950
- const status = await sock.fetchStatus(jid)
951
- console.log('status: ' + status)
952
- ```
655
+ ## Misc
953
656
 
954
- ### Fetch Profile Picture (groups too)
657
+ - To check if a given ID is on WhatsApp
658
+ ``` ts
659
+ const id = '123456'
660
+ const [result] = await sock.onWhatsApp(id)
661
+ if (result.exists) console.log (`${id} exists on WhatsApp, as jid: ${result.jid}`)
662
+ ```
663
+ - To query chat history on a group or with someone
664
+ TODO, if possible
665
+ - To get the status of some person
666
+ ``` ts
667
+ const status = await sock.fetchStatus("xyz@s.whatsapp.net")
668
+ console.log("status: " + status)
669
+ ```
670
+ - To change your profile status
671
+ ``` ts
672
+ const status = 'Hello World!'
673
+ await sock.updateProfileStatus(status)
674
+ ```
675
+ - To change your profile name
676
+ ``` ts
677
+ const name = 'My name'
678
+ await sock.updateProfileName(name)
679
+ ```
955
680
  - To get the display picture of some person/group
956
- ```ts
957
- // for low res picture
958
- const ppUrl = await sock.profilePictureUrl(jid)
959
- console.log(ppUrl)
960
-
961
- // for high res picture
962
- const ppUrl = await sock.profilePictureUrl(jid, 'image')
963
- ```
964
-
965
- ### Fetch Bussines Profile (such as description or category)
966
- ```ts
967
- const profile = await sock.getBusinessProfile(jid)
968
- console.log('business description: ' + profile.description + ', category: ' + profile.category)
969
- ```
970
-
971
- ### Fetch Someone's Presence (if they're typing or online)
972
- ```ts
973
- // the presence update is fetched and called here
974
- sock.ev.on('presence.update', console.log)
975
-
976
- // request updates for a chat
977
- await sock.presenceSubscribe(jid)
978
- ```
979
-
980
- ## Change Profile
981
-
982
- ### Change Profile Status
983
- ```ts
984
- await sock.updateProfileStatus('Hello World!')
985
- ```
986
- ### Change Profile Name
987
- ```ts
988
- await sock.updateProfileName('My name')
989
- ```
990
- ### Change Display Picture (groups too)
681
+ ``` ts
682
+ // for low res picture
683
+ const ppUrl = await sock.profilePictureUrl("xyz@g.us")
684
+ console.log("download profile picture from: " + ppUrl)
685
+ // for high res picture
686
+ const ppUrl = await sock.profilePictureUrl("xyz@g.us", 'image')
687
+ ```
991
688
  - To change your display picture or a group's
992
-
993
- > [!NOTE]
994
- > Like media messages, you can pass `{ stream: Stream }` or `{ url: Url }` or `Buffer` directly, you can see more in the [WAMediaUpload type alias](https://baileys.wiki/docs/api/type-aliases/WAMediaUpload/)
995
-
996
- ```ts
997
- await sock.updateProfilePicture(jid, { url: './new-profile-picture.jpeg' })
998
- ```
999
- ### Remove display picture (groups too)
1000
- ```ts
1001
- await sock.removeProfilePicture(jid)
1002
- ```
689
+ ``` ts
690
+ const jid = '111234567890-1594482450@g.us' // can be your own too
691
+ await sock.updateProfilePicture(jid, { url: './new-profile-picture.jpeg' })
692
+ ```
693
+ - To remove your display picture or a group's
694
+ ``` ts
695
+ const jid = '111234567890-1594482450@g.us' // can be your own too
696
+ await sock.removeProfilePicture(jid)
697
+ ```
698
+ - To get someone's presence (if they're typing or online)
699
+ ``` ts
700
+ // the presence update is fetched and called here
701
+ sock.ev.on('presence.update', json => console.log(json))
702
+ // request updates for a chat
703
+ await sock.presenceSubscribe("xyz@s.whatsapp.net")
704
+ ```
705
+ - To block or unblock user
706
+ ``` ts
707
+ await sock.updateBlockStatus("xyz@s.whatsapp.net", "block") // Block user
708
+ await sock.updateBlockStatus("xyz@s.whatsapp.net", "unblock") // Unblock user
709
+ ```
710
+ - To get a business profile, such as description or category
711
+ ```ts
712
+ const profile = await sock.getBusinessProfile("xyz@s.whatsapp.net")
713
+ console.log("business description: " + profile.description + ", category: " + profile.category)
714
+ ```
715
+ Of course, replace ``` xyz ``` with an actual ID.
1003
716
 
1004
717
  ## Groups
718
+ - To create a group
719
+ ``` ts
720
+ // title & participants
721
+ const group = await sock.groupCreate("My Fab Group", ["1234@s.whatsapp.net", "4564@s.whatsapp.net"])
722
+ console.log ("created group with id: " + group.gid)
723
+ sock.sendMessage(group.id, { text: 'hello there' }) // say hello to everyone on the group
724
+ ```
725
+ - To add/remove people to a group or demote/promote people
726
+ ``` ts
727
+ // id & people to add to the group (will throw error if it fails)
728
+ const response = await sock.groupParticipantsUpdate(
729
+ "abcd-xyz@g.us",
730
+ ["abcd@s.whatsapp.net", "efgh@s.whatsapp.net"],
731
+ "add" // replace this parameter with "remove", "demote" or "promote"
732
+ )
733
+ ```
734
+ - To change the group's subject
735
+ ``` ts
736
+ await sock.groupUpdateSubject("abcd-xyz@g.us", "New Subject!")
737
+ ```
738
+ - To change the group's description
739
+ ``` ts
740
+ await sock.groupUpdateDescription("abcd-xyz@g.us", "New Description!")
741
+ ```
742
+ - To change group settings
743
+ ``` ts
744
+ // only allow admins to send messages
745
+ await sock.groupSettingUpdate("abcd-xyz@g.us", 'announcement')
746
+ // allow everyone to send messages
747
+ await sock.groupSettingUpdate("abcd-xyz@g.us", 'not_announcement')
748
+ // allow everyone to modify the group's settings -- like display picture etc.
749
+ await sock.groupSettingUpdate("abcd-xyz@g.us", 'unlocked')
750
+ // only allow admins to modify the group's settings
751
+ await sock.groupSettingUpdate("abcd-xyz@g.us", 'locked')
752
+ ```
753
+ - To leave a group
754
+ ``` ts
755
+ await sock.groupLeave("abcd-xyz@g.us") // (will throw error if it fails)
756
+ ```
757
+ - To get the invite code for a group
758
+ ``` ts
759
+ const code = await sock.groupInviteCode("abcd-xyz@g.us")
760
+ console.log("group code: " + code)
761
+ ```
762
+ - To revoke the invite code in a group
763
+ ```ts
764
+ const code = await sock.groupRevokeInvite("abcd-xyz@g.us")
765
+ console.log("New group code: " + code)
766
+ ```
767
+ - To query the metadata of a group
768
+ ``` ts
769
+ const metadata = await sock.groupMetadata("abcd-xyz@g.us")
770
+ console.log(metadata.id + ", title: " + metadata.subject + ", description: " + metadata.desc)
771
+ ```
772
+ - To join the group using the invitation code
773
+ ``` ts
774
+ const response = await sock.groupAcceptInvite("xxx")
775
+ console.log("joined to: " + response)
776
+ ```
777
+ Of course, replace ``` xxx ``` with invitation code.
778
+ - To get group info by invite code
779
+ ```ts
780
+ const response = await sock.groupGetInviteInfo("xxx")
781
+ console.log("group information: " + response)
782
+ ```
783
+ - To join the group using groupInviteMessage
784
+ ``` ts
785
+ const response = await sock.groupAcceptInviteV4("abcd@s.whatsapp.net", groupInviteMessage)
786
+ console.log("joined to: " + response)
787
+ ```
788
+ Of course, replace ``` xxx ``` with invitation code.
1005
789
 
1006
- - To change group properties you need to be admin
1007
-
1008
- ### Create a Group
1009
- ```ts
1010
- // title & participants
1011
- const group = await sock.groupCreate('My Fab Group', ['1234@s.whatsapp.net', '4564@s.whatsapp.net'])
1012
- console.log('created group with id: ' + group.gid)
1013
- await sock.sendMessage(group.id, { text: 'hello there' }) // say hello to everyone on the group
1014
- ```
1015
- ### Add/Remove or Demote/Promote
1016
- ```ts
1017
- // id & people to add to the group (will throw error if it fails)
1018
- await sock.groupParticipantsUpdate(
1019
- jid,
1020
- ['abcd@s.whatsapp.net', 'efgh@s.whatsapp.net'],
1021
- 'add' // replace this parameter with 'remove' or 'demote' or 'promote'
1022
- )
1023
- ```
1024
- ### Change Subject (name)
1025
- ```ts
1026
- await sock.groupUpdateSubject(jid, 'New Subject!')
1027
- ```
1028
- ### Change Description
1029
- ```ts
1030
- await sock.groupUpdateDescription(jid, 'New Description!')
1031
- ```
1032
- ### Change Settings
1033
- ```ts
1034
- // only allow admins to send messages
1035
- await sock.groupSettingUpdate(jid, 'announcement')
1036
- // allow everyone to send messages
1037
- await sock.groupSettingUpdate(jid, 'not_announcement')
1038
- // allow everyone to modify the group's settings -- like display picture etc.
1039
- await sock.groupSettingUpdate(jid, 'unlocked')
1040
- // only allow admins to modify the group's settings
1041
- await sock.groupSettingUpdate(jid, 'locked')
1042
- ```
1043
- ### Leave a Group
1044
- ```ts
1045
- // will throw error if it fails
1046
- await sock.groupLeave(jid)
1047
- ```
1048
- ### Get Invite Code
1049
- - To create link with code use `'https://chat.whatsapp.com/' + code`
1050
- ```ts
1051
- const code = await sock.groupInviteCode(jid)
1052
- console.log('group code: ' + code)
1053
- ```
1054
- ### Revoke Invite Code
1055
- ```ts
1056
- const code = await sock.groupRevokeInvite(jid)
1057
- console.log('New group code: ' + code)
1058
- ```
1059
- ### Join Using Invitation Code
1060
- - Code can't have `https://chat.whatsapp.com/`, only code
1061
- ```ts
1062
- const response = await sock.groupAcceptInvite(code)
1063
- console.log('joined to: ' + response)
1064
- ```
1065
- ### Get Group Info by Invite Code
1066
- ```ts
1067
- const response = await sock.groupGetInviteInfo(code)
1068
- console.log('group information: ' + response)
1069
- ```
1070
- ### Query Metadata (participants, name, description...)
1071
- ```ts
1072
- const metadata = await sock.groupMetadata(jid)
1073
- console.log(metadata.id + ', title: ' + metadata.subject + ', description: ' + metadata.desc)
1074
- ```
1075
- ### Join using `groupInviteMessage`
1076
- ```ts
1077
- const response = await sock.groupAcceptInviteV4(jid, groupInviteMessage)
1078
- console.log('joined to: ' + response)
1079
- ```
1080
- ### Get Request Join List
1081
- ```ts
1082
- const response = await sock.groupRequestParticipantsList(jid)
1083
- console.log(response)
1084
- ```
1085
- ### Approve/Reject Request Join
1086
- ```ts
1087
- const response = await sock.groupRequestParticipantsUpdate(
1088
- jid, // group id
1089
- ['abcd@s.whatsapp.net', 'efgh@s.whatsapp.net'],
1090
- 'approve' // or 'reject'
1091
- )
1092
- console.log(response)
1093
- ```
1094
- ### Get All Participating Groups Metadata
1095
- ```ts
1096
- const response = await sock.groupFetchAllParticipating()
1097
- console.log(response)
1098
- ```
1099
- ### Toggle Ephemeral
1100
-
1101
- - Ephemeral can be:
1102
-
1103
- | Time | Seconds |
1104
- |-------|----------------|
1105
- | Remove | 0 |
1106
- | 24h | 86.400 |
1107
- | 7d | 604.800 |
1108
- | 90d | 7.776.000 |
1109
-
1110
- ```ts
1111
- await sock.groupToggleEphemeral(jid, 86400)
1112
- ```
1113
-
1114
- ### Change Add Mode
1115
- ```ts
1116
- await sock.groupMemberAddMode(
1117
- jid,
1118
- 'all_member_add' // or 'admin_add'
1119
- )
1120
- ```
790
+ - To get list request join
791
+ ``` ts
792
+ const response = await sock.groupRequestParticipantsList("abcd-xyz@g.us")
793
+ console.log(response)
794
+ ```
795
+ - To approve/reject request join
796
+ ``` ts
797
+ const response = await sock.groupRequestParticipantsUpdate(
798
+ "abcd-xyz@g.us", // id group,
799
+ ["abcd@s.whatsapp.net", "efgh@s.whatsapp.net"],
800
+ "approve" // replace this parameter with "reject"
801
+ )
802
+ console.log(response)
803
+ ```
1121
804
 
1122
805
  ## Privacy
1123
-
1124
- ### Block/Unblock User
1125
- ```ts
1126
- await sock.updateBlockStatus(jid, 'block') // Block user
1127
- await sock.updateBlockStatus(jid, 'unblock') // Unblock user
1128
- ```
1129
- ### Get Privacy Settings
1130
- ```ts
1131
- const privacySettings = await sock.fetchPrivacySettings(true)
1132
- console.log('privacy settings: ' + privacySettings)
1133
- ```
1134
- ### Get BlockList
1135
- ```ts
1136
- const response = await sock.fetchBlocklist()
1137
- console.log(response)
1138
- ```
1139
- ### Update LastSeen Privacy
1140
- ```ts
1141
- const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
1142
- await sock.updateLastSeenPrivacy(value)
1143
- ```
1144
- ### Update Online Privacy
1145
- ```ts
1146
- const value = 'all' // 'match_last_seen'
1147
- await sock.updateOnlinePrivacy(value)
1148
- ```
1149
- ### Update Profile Picture Privacy
1150
- ```ts
1151
- const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
1152
- await sock.updateProfilePicturePrivacy(value)
1153
- ```
1154
- ### Update Status Privacy
1155
- ```ts
1156
- const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
1157
- await sock.updateStatusPrivacy(value)
1158
- ```
1159
- ### Update Read Receipts Privacy
1160
- ```ts
1161
- const value = 'all' // 'none'
1162
- await sock.updateReadReceiptsPrivacy(value)
1163
- ```
1164
- ### Update Groups Add Privacy
1165
- ```ts
1166
- const value = 'all' // 'contacts' | 'contact_blacklist'
1167
- await sock.updateGroupsAddPrivacy(value)
1168
- ```
1169
- ### Update Default Disappearing Mode
1170
-
1171
- - Like [this](#disappearing-messages), ephemeral can be:
1172
-
1173
- | Time | Seconds |
1174
- |-------|----------------|
1175
- | Remove | 0 |
1176
- | 24h | 86.400 |
1177
- | 7d | 604.800 |
1178
- | 90d | 7.776.000 |
1179
-
1180
- ```ts
1181
- const ephemeral = 86400
1182
- await sock.updateDefaultDisappearingMode(ephemeral)
1183
- ```
1184
-
806
+ - To get the privacy settings
807
+ ``` ts
808
+ const privacySettings = await sock.fetchPrivacySettings(true)
809
+ console.log("privacy settings: " + privacySettings)
810
+ ```
811
+ - To update the LastSeen privacy
812
+ ``` ts
813
+ const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
814
+ await sock.updateLastSeenPrivacy(value)
815
+ ```
816
+ - To update the Online privacy
817
+ ``` ts
818
+ const value = 'all' // 'match_last_seen'
819
+ await sock.updateOnlinePrivacy(value)
820
+ ```
821
+ - To update the Profile Picture privacy
822
+ ``` ts
823
+ const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
824
+ await sock.updateProfilePicturePrivacy(value)
825
+ ```
826
+ - To update the Status privacy
827
+ ``` ts
828
+ const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
829
+ await sock.updateStatusPrivacy(value)
830
+ ```
831
+ - To update the Read Receipts privacy
832
+ ``` ts
833
+ const value = 'all' // 'none'
834
+ await sock.updateReadReceiptsPrivacy(value)
835
+ ```
836
+ - To update the Groups Add privacy
837
+ ``` ts
838
+ const value = 'all' // 'contacts' | 'contact_blacklist'
839
+ await sock.updateGroupsAddPrivacy(value)
840
+ ```
841
+ - To update the Default Disappearing Mode
842
+ ``` ts
843
+ const duration = 86400 // 604800 | 7776000 | 0
844
+ await sock.updateDefaultDisappearingMode(duration)
845
+ ```
1185
846
  ## Broadcast Lists & Stories
1186
847
 
1187
- ### Send Broadcast & Stories
1188
- - Messages can be sent to broadcasts & stories. You need to add the following message options in sendMessage, like this:
848
+ Messages can be sent to broadcasts & stories.
849
+ you need to add the following message options in sendMessage, like this:
1189
850
  ```ts
1190
- await sock.sendMessage(
1191
- jid,
1192
- {
1193
- image: {
1194
- url: url
1195
- },
1196
- caption: caption
1197
- },
1198
- {
1199
- backgroundColor: backgroundColor,
1200
- font: font,
1201
- statusJidList: statusJidList,
1202
- broadcast: true
1203
- }
1204
- )
851
+ sock.sendMessage(jid, {image: {url: url}, caption: caption}, {backgroundColor : backgroundColor, font : font, statusJidList: statusJidList, broadcast : true})
1205
852
  ```
1206
- - Message body can be a `extendedTextMessage` or `imageMessage` or `videoMessage` or `voiceMessage`, see the [AnyRegularMessageContent type alias](https://baileys.wiki/docs/api/type-aliases/AnyRegularMessageContent/)
1207
- - You can add `backgroundColor` and other options in the message options, see the [MiscMessageGenerationOptions type alias](https://baileys.wiki/docs/api/type-aliases/MiscMessageGenerationOptions/)
1208
- - `broadcast: true` enables broadcast mode
1209
- - `statusJidList`: a list of people that you can get which you need to provide, which are the people who will get this status message.
853
+ - the message body can be a extendedTextMessage or imageMessage or videoMessage or voiceMessage
854
+ - You can add backgroundColor and other options in the message options
855
+ - broadcast: true enables broadcast mode
856
+ - statusJidList: a list of people that you can get which you need to provide, which are the people who will get this status message.
1210
857
 
1211
858
  - You can send messages to broadcast lists the same way you send messages to groups & individual chats.
1212
859
  - Right now, WA Web does not support creating broadcast lists, but you can still delete them.
1213
860
  - Broadcast IDs are in the format `12345678@broadcast`
1214
- ### Query a Broadcast List's Recipients & Name
1215
- ```ts
1216
- const bList = await sock.getBroadcastListInfo('1234@broadcast')
1217
- console.log (`list name: ${bList.name}, recps: ${bList.recipients}`)
1218
- ```
861
+ - To query a broadcast list's recipients & name:
862
+ ``` ts
863
+ const bList = await sock.getBroadcastListInfo("1234@broadcast")
864
+ console.log (`list name: ${bList.name}, recps: ${bList.recipients}`)
865
+ ```
1219
866
 
1220
867
  ## Writing Custom Functionality
1221
868
  Baileys is written with custom functionality in mind. Instead of forking the project & re-writing the internals, you can simply write your own extensions.
1222
869
 
1223
- ### Enabling Debug Level in Baileys Logs
1224
870
  First, enable the logging of unhandled messages from WhatsApp by setting:
1225
- ```ts
871
+ ``` ts
1226
872
  const sock = makeWASocket({
1227
873
  logger: P({ level: 'debug' }),
1228
874
  })
1229
875
  ```
1230
- This will enable you to see all sorts of messages WhatsApp sends in the console.
1231
-
1232
- ### How Whatsapp Communicate With Us
1233
-
1234
- > [!TIP]
1235
- > If you want to learn whatsapp protocol, we recommend to study about Libsignal Protocol and Noise Protocol
1236
-
1237
- - **Example:** Functionality to track the battery percentage of your phone. You enable logging and you'll see a message about your battery pop up in the console:
1238
- ```
1239
- {
1240
- "level": 10,
1241
- "fromMe": false,
1242
- "frame": {
1243
- "tag": "ib",
1244
- "attrs": {
1245
- "from": "@s.whatsapp.net"
1246
- },
1247
- "content": [
1248
- {
1249
- "tag": "edge_routing",
1250
- "attrs": {},
1251
- "content": [
1252
- {
1253
- "tag": "routing_info",
1254
- "attrs": {},
1255
- "content": {
1256
- "type": "Buffer",
1257
- "data": [8,2,8,5]
1258
- }
1259
- }
1260
- ]
1261
- }
1262
- ]
1263
- },
1264
- "msg":"communication"
1265
- }
876
+ This will enable you to see all sorts of messages WhatsApp sends in the console.
877
+
878
+ Some examples:
879
+
880
+ 1. Functionality to track the battery percentage of your phone.
881
+ You enable logging and you'll see a message about your battery pop up in the console:
882
+ ```{"level":10,"fromMe":false,"frame":{"tag":"ib","attrs":{"from":"@s.whatsapp.net"},"content":[{"tag":"edge_routing","attrs":{},"content":[{"tag":"routing_info","attrs":{},"content":{"type":"Buffer","data":[8,2,8,5]}}]}]},"msg":"communication"} ```
883
+
884
+ The "frame" is what the message received is, it has three components:
885
+ - `tag` -- what this frame is about (eg. message will have "message")
886
+ - `attrs` -- a string key-value pair with some metadata (contains ID of the message usually)
887
+ - `content` -- the actual data (eg. a message node will have the actual message content in it)
888
+ - read more about this format [here](/src/WABinary/readme.md)
889
+
890
+ You can register a callback for an event using the following:
891
+ ``` ts
892
+ // for any message with tag 'edge_routing'
893
+ sock.ws.on(`CB:edge_routing`, (node: BinaryNode) => { })
894
+ // for any message with tag 'edge_routing' and id attribute = abcd
895
+ sock.ws.on(`CB:edge_routing,id:abcd`, (node: BinaryNode) => { })
896
+ // for any message with tag 'edge_routing', id attribute = abcd & first content node routing_info
897
+ sock.ws.on(`CB:edge_routing,id:abcd,routing_info`, (node: BinaryNode) => { })
1266
898
  ```
1267
-
1268
- The `'frame'` is what the message received is, it has three components:
1269
- - `tag` -- what this frame is about (eg. message will have 'message')
1270
- - `attrs` -- a string key-value pair with some metadata (contains ID of the message usually)
1271
- - `content` -- the actual data (eg. a message node will have the actual message content in it)
1272
- - read more about this format [here](/src/WABinary/readme.md)
1273
-
1274
- ### Register a Callback for Websocket Events
1275
-
1276
- > [!TIP]
1277
- > Recommended to see `onMessageReceived` function in `socket.ts` file to understand how websockets events are fired
1278
-
1279
- ```ts
1280
- // for any message with tag 'edge_routing'
1281
- sock.ws.on('CB:edge_routing', (node: BinaryNode) => { })
1282
-
1283
- // for any message with tag 'edge_routing' and id attribute = abcd
1284
- sock.ws.on('CB:edge_routing,id:abcd', (node: BinaryNode) => { })
1285
-
1286
- // for any message with tag 'edge_routing', id attribute = abcd & first content node routing_info
1287
- sock.ws.on('CB:edge_routing,id:abcd,routing_info', (node: BinaryNode) => { })
1288
- ```
1289
-
1290
- # License
1291
- Copyright (c) 2025 Rajeh Taher/WhiskeySockets
1292
-
1293
- Licensed under the MIT License:
1294
- Permission is hereby granted, free of charge, to any person obtaining a copy
1295
- of this software and associated documentation files (the "Software"), to deal
1296
- in the Software without restriction, including without limitation the rights
1297
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1298
- copies of the Software, and to permit persons to whom the Software is
1299
- furnished to do so, subject to the following conditions:
1300
-
1301
- The above copyright notice and this permission notice shall be included in all
1302
- copies or substantial portions of the Software.
1303
-
1304
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1305
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1306
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1307
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1308
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1309
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1310
- SOFTWARE.
1311
-
1312
- Thus, the maintainers of the project can't be held liable for any potential misuse of this project.
899
+ Also, this repo is now licenced under GPL 3 since it uses [libsignal-node](https://git.questbook.io/backend/service-coderunner/-/merge_requests/1)