@vinzsocket/baileys 3.0.0 → 3.0.15

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