@queenanya/baileys 9.2.4 → 9.4.1

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