@queenanya/baileys 9.2.0 → 9.2.4

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 (139) hide show
  1. package/README.md +1272 -359
  2. package/WAProto/fix-imports.js +70 -18
  3. package/WAProto/index.js +197 -160
  4. package/engine-requirements.js +7 -7
  5. package/lib/Defaults/index.d.ts +2 -0
  6. package/lib/Defaults/index.d.ts.map +1 -1
  7. package/lib/Defaults/index.js +5 -5
  8. package/lib/Defaults/index.js.map +1 -1
  9. package/lib/Signal/libsignal.d.ts.map +1 -1
  10. package/lib/Signal/libsignal.js +1 -2
  11. package/lib/Signal/libsignal.js.map +1 -1
  12. package/lib/Signal/lid-mapping.d.ts.map +1 -1
  13. package/lib/Signal/lid-mapping.js +2 -3
  14. package/lib/Signal/lid-mapping.js.map +1 -1
  15. package/lib/Socket/Client/types.d.ts +2 -2
  16. package/lib/Socket/Client/types.d.ts.map +1 -1
  17. package/lib/Socket/Client/websocket.d.ts +1 -1
  18. package/lib/Socket/Client/websocket.d.ts.map +1 -1
  19. package/lib/Socket/Client/websocket.js +5 -1
  20. package/lib/Socket/Client/websocket.js.map +1 -1
  21. package/lib/Socket/business.d.ts +16 -4
  22. package/lib/Socket/business.d.ts.map +1 -1
  23. package/lib/Socket/business.js +11 -8
  24. package/lib/Socket/business.js.map +1 -1
  25. package/lib/Socket/chats.d.ts +14 -3
  26. package/lib/Socket/chats.d.ts.map +1 -1
  27. package/lib/Socket/chats.js +42 -26
  28. package/lib/Socket/chats.js.map +1 -1
  29. package/lib/Socket/communities.d.ts +16 -4
  30. package/lib/Socket/communities.d.ts.map +1 -1
  31. package/lib/Socket/groups.d.ts +14 -3
  32. package/lib/Socket/groups.d.ts.map +1 -1
  33. package/lib/Socket/groups.js +1 -2
  34. package/lib/Socket/groups.js.map +1 -1
  35. package/lib/Socket/index.d.ts +16 -4
  36. package/lib/Socket/index.d.ts.map +1 -1
  37. package/lib/Socket/messages-recv.d.ts +16 -4
  38. package/lib/Socket/messages-recv.d.ts.map +1 -1
  39. package/lib/Socket/messages-recv.js +138 -76
  40. package/lib/Socket/messages-recv.js.map +1 -1
  41. package/lib/Socket/messages-send.d.ts +16 -4
  42. package/lib/Socket/messages-send.d.ts.map +1 -1
  43. package/lib/Socket/messages-send.js +190 -100
  44. package/lib/Socket/messages-send.js.map +1 -1
  45. package/lib/Socket/newsletter.d.ts +15 -5
  46. package/lib/Socket/newsletter.d.ts.map +1 -1
  47. package/lib/Socket/newsletter.js +2 -47
  48. package/lib/Socket/newsletter.js.map +1 -1
  49. package/lib/Socket/socket.d.ts +3 -1
  50. package/lib/Socket/socket.d.ts.map +1 -1
  51. package/lib/Socket/socket.js +64 -27
  52. package/lib/Socket/socket.js.map +1 -1
  53. package/lib/Types/Auth.d.ts +4 -0
  54. package/lib/Types/Auth.d.ts.map +1 -1
  55. package/lib/Types/Events.d.ts +39 -5
  56. package/lib/Types/Events.d.ts.map +1 -1
  57. package/lib/Types/Message.d.ts +2 -0
  58. package/lib/Types/Message.d.ts.map +1 -1
  59. package/lib/Types/Message.js.map +1 -1
  60. package/lib/Types/Newsletter.d.ts +0 -17
  61. package/lib/Types/Newsletter.d.ts.map +1 -1
  62. package/lib/Utils/auth-utils.d.ts.map +1 -1
  63. package/lib/Utils/auth-utils.js +54 -21
  64. package/lib/Utils/auth-utils.js.map +1 -1
  65. package/lib/Utils/chat-utils.d.ts.map +1 -1
  66. package/lib/Utils/chat-utils.js +54 -8
  67. package/lib/Utils/chat-utils.js.map +1 -1
  68. package/lib/Utils/decode-wa-message.d.ts.map +1 -1
  69. package/lib/Utils/decode-wa-message.js +5 -1
  70. package/lib/Utils/decode-wa-message.js.map +1 -1
  71. package/lib/Utils/event-buffer.d.ts.map +1 -1
  72. package/lib/Utils/event-buffer.js +35 -9
  73. package/lib/Utils/event-buffer.js.map +1 -1
  74. package/lib/Utils/generics.d.ts +1 -1
  75. package/lib/Utils/generics.d.ts.map +1 -1
  76. package/lib/Utils/generics.js +4 -4
  77. package/lib/Utils/generics.js.map +1 -1
  78. package/lib/Utils/history.d.ts +3 -1
  79. package/lib/Utils/history.d.ts.map +1 -1
  80. package/lib/Utils/history.js +8 -0
  81. package/lib/Utils/history.js.map +1 -1
  82. package/lib/Utils/index.d.ts +0 -1
  83. package/lib/Utils/index.d.ts.map +1 -1
  84. package/lib/Utils/index.js +0 -1
  85. package/lib/Utils/index.js.map +1 -1
  86. package/lib/Utils/make-mutex.d.ts +1 -0
  87. package/lib/Utils/make-mutex.d.ts.map +1 -1
  88. package/lib/Utils/make-mutex.js +20 -27
  89. package/lib/Utils/make-mutex.js.map +1 -1
  90. package/lib/Utils/message-retry-manager.d.ts +1 -1
  91. package/lib/Utils/message-retry-manager.d.ts.map +1 -1
  92. package/lib/Utils/message-retry-manager.js +1 -6
  93. package/lib/Utils/message-retry-manager.js.map +1 -1
  94. package/lib/Utils/messages-media.d.ts +16 -0
  95. package/lib/Utils/messages-media.d.ts.map +1 -1
  96. package/lib/Utils/messages-media.js +145 -34
  97. package/lib/Utils/messages-media.js.map +1 -1
  98. package/lib/Utils/messages.d.ts +15 -0
  99. package/lib/Utils/messages.d.ts.map +1 -1
  100. package/lib/Utils/messages.js +73 -23
  101. package/lib/Utils/messages.js.map +1 -1
  102. package/lib/Utils/noise-handler.d.ts +3 -3
  103. package/lib/Utils/noise-handler.d.ts.map +1 -1
  104. package/lib/Utils/noise-handler.js +129 -75
  105. package/lib/Utils/noise-handler.js.map +1 -1
  106. package/lib/Utils/process-message.d.ts +20 -2
  107. package/lib/Utils/process-message.d.ts.map +1 -1
  108. package/lib/Utils/process-message.js +101 -10
  109. package/lib/Utils/process-message.js.map +1 -1
  110. package/lib/Utils/reporting-utils.d.ts +11 -0
  111. package/lib/Utils/reporting-utils.d.ts.map +1 -0
  112. package/lib/Utils/reporting-utils.js +258 -0
  113. package/lib/Utils/reporting-utils.js.map +1 -0
  114. package/lib/Utils/sync-action-utils.d.ts +19 -0
  115. package/lib/Utils/sync-action-utils.d.ts.map +1 -0
  116. package/lib/Utils/sync-action-utils.js +48 -0
  117. package/lib/Utils/sync-action-utils.js.map +1 -0
  118. package/lib/Utils/tc-token-utils.d.ts +12 -0
  119. package/lib/Utils/tc-token-utils.d.ts.map +1 -0
  120. package/lib/Utils/tc-token-utils.js +18 -0
  121. package/lib/Utils/tc-token-utils.js.map +1 -0
  122. package/lib/Utils/use-single-file-auth-state.d.ts.map +1 -1
  123. package/lib/Utils/use-single-file-auth-state.js.map +1 -1
  124. package/lib/WABinary/decode.d.ts.map +1 -1
  125. package/lib/WABinary/decode.js +24 -0
  126. package/lib/WABinary/decode.js.map +1 -1
  127. package/lib/WABinary/encode.js +5 -1
  128. package/lib/WABinary/encode.js.map +1 -1
  129. package/lib/WABinary/generic-utils.d.ts +1 -1
  130. package/lib/WABinary/generic-utils.d.ts.map +1 -1
  131. package/lib/WABinary/generic-utils.js +19 -8
  132. package/lib/WABinary/generic-utils.js.map +1 -1
  133. package/lib/WAUSync/USyncQuery.js +1 -1
  134. package/lib/WAUSync/USyncQuery.js.map +1 -1
  135. package/package.json +6 -5
  136. package/lib/Utils/baileys-event-stream.d.ts +0 -17
  137. package/lib/Utils/baileys-event-stream.d.ts.map +0 -1
  138. package/lib/Utils/baileys-event-stream.js +0 -56
  139. package/lib/Utils/baileys-event-stream.js.map +0 -1
package/README.md CHANGED
@@ -1,479 +1,1392 @@
1
- # 🚀 BAILEYS-ANYA
1
+ <h1 align='center'><img alt="Baileys logo" src="https://raw.githubusercontent.com/WhiskeySockets/Baileys/refs/heads/master/Media/logo.png" height="75"/></h1>
2
2
 
3
- <div align="center">
3
+ <div align='center'>Baileys is a WebSockets-based TypeScript library for interacting with the WhatsApp Web API.</div>
4
4
 
5
- <img src="https://raw.githubusercontent.com/teamolduser/database/refs/heads/main/image/anya.png" width="350px">
5
+ New guide link: https://baileys.wiki
6
6
 
7
- <br>
8
-
9
- <div style="background: linear-gradient(90deg, #6366F1, #3B82F6, #2DD4BF); padding: 8px; border-radius: 10px; margin: 15px 0;">
10
- <span style="font-size: 18px; font-weight: bold; color: white;">🔥 Ultimate WhatsApp Web API Experience 🥵</span>
11
- </div>
12
-
13
- ![TypeScript](https://img.shields.io/badge/-%F0%9F%94%B7%20TypeScript-007ACC?style=for-the-badge&logo=typescript&logoColor=white&labelColor=0D1117)
14
- ![JavaScript](https://img.shields.io/badge/-%F0%9F%94%B8%20JavaScript-F7DF1E?style=for-the-badge&logo=javascript&logoColor=F7DF1E&labelColor=0D1117)
15
- ![WhatsApp](https://img.shields.io/badge/-%F0%9F%92%AC%20WhatsApp-25D366?style=for-the-badge&logo=whatsapp&logoColor=white&labelColor=0D1117)
16
- ![NPM](https://img.shields.io/badge/-%F0%9F%93%A6%20npm-CB3837?style=for-the-badge&logo=npm&logoColor=white&labelColor=0D1117)
17
- </div>
7
+ # Sponsor
18
8
 
19
- <br>
9
+ If you'd like to financially support this project, you can do so by supporting the current maintainer [here](https://purpshell.dev/sponsor).
20
10
 
21
- <div align="center">
22
- <img src="https://capsule-render.vercel.app/api?type=waving&color=gradient&height=60&section=header" width="100%">
23
- </div>
11
+ # Disclaimer
24
12
 
25
- <div style="border-left: 4px solid #3B82F6; padding-left: 15px; margin: 25px 0;">
26
- <h2>⚡️ Supercharged WhatsApp API 🌟</h2>
27
- <p><i>Elevate your messaging experience with the most advanced WhatsApp Web API solution available</i></p>
28
- </div>
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.
29
15
 
30
- ---
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.
31
18
 
32
- ## 🔮 | WHY BAILEYS-ANYA?
19
+ ##
33
20
 
34
- <div style="display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 10px; margin: 20px 0;">
35
- <div style="background: rgba(45, 212, 191, 0.1); border-radius: 10px; padding: 15px; width: 180px; text-align: center;">
36
- <div style="font-weight: bold;">⚡ Lightning Fast</div>
37
- </div>
38
- <div style="background: rgba(99, 102, 241, 0.1); border-radius: 10px; padding: 15px; width: 180px; text-align: center;">
39
- <div style="font-weight: bold;">🛡️ Secure</div>
40
- </div>
41
- <div style="background: rgba(244, 114, 182, 0.1); border-radius: 10px; padding: 15px; width: 180px; text-align: center;">
42
- <div style="font-weight: bold;">🧩 Feature-Rich</div>
43
- </div>
44
- <div style="background: rgba(234, 179, 8, 0.1); border-radius: 10px; padding: 15px; width: 180px; text-align: center;">
45
- <div style="font-weight: bold;">🔄 Active Development</div>
46
- </div>
47
- </div>
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.
48
25
 
49
- ## 📌 | IMPORTANT NOTE
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)**
50
30
 
51
- <div style="background: linear-gradient(90deg, rgba(239, 68, 68, 0.1), rgba(239, 68, 68, 0.05)); border-left: 4px solid #EF4444; padding: 15px; border-radius: 5px; margin: 20px 0;">
52
- <p>⚠️ The original repository was initially removed by its creator and subsequently taken over by <a href="https://github.com/WhiskeySockets" style="color: #60A5FA; text-decoration: none; font-weight: bold;">WhiskeySockets</a>. This enhanced version includes numerous improvements and powerful new features designed to transform your WhatsApp development experience.</p>
53
- </div>
31
+ ## Example
54
32
 
55
- ## 💫 | INSTALLATION
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:
56
36
 
57
- <div style="background: rgba(17, 24, 39, 0.6); border-radius: 8px; padding: 20px; margin: 20px 0;">
37
+ 1. `cd path/to/Baileys`
38
+ 2. `yarn`
39
+ 3. `yarn example`
58
40
 
59
- ### 📂 In package.json:
41
+ ## Install
60
42
 
61
- ```json
62
- "dependencies": {
63
- "baileys-anya": "*"
43
+ Use the stable version:
44
+
45
+ ```
46
+ yarn add @whiskeysockets/baileys
47
+ ```
48
+
49
+ Use the edge version (no guarantee of stability, but latest fixes + features)
50
+
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
+ ```
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)
85
+ - [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)**
185
+
186
+ ```ts
187
+ import makeWASocket from '@whiskeysockets/baileys'
188
+
189
+ const sock = makeWASocket({
190
+ // can provide additional config here
191
+ browser: Browsers.ubuntu('My App'),
192
+ printQRInTerminal: true
193
+ })
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)
64
217
  }
65
218
  ```
66
219
 
67
- ### ⚙️ Terminal Installation:
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:
68
225
 
69
- ```bash
70
- npm install baileys-anya
226
+ ```ts
227
+ const sock = makeWASocket({
228
+ ...otherOpts,
229
+ // can use Windows, Ubuntu here too
230
+ browser: Browsers.macOS('Desktop'),
231
+ syncFullHistory: true
232
+ })
71
233
  ```
72
234
 
73
- or
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')
74
287
 
75
- ```bash
76
- yarn add baileys-anya
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
+ sock.ev.on('creds.update', saveCreds)
77
294
  ```
78
295
 
79
- or
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
80
309
 
81
- ```bash
82
- pnpm add baileys-anya
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()
83
365
  ```
84
366
 
85
- ### 🔌 Import:
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
+ }
390
+ }
391
+ })
392
+ ```
393
+
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.
86
407
 
87
- <div style="display: flex; gap: 20px; flex-wrap: wrap;">
88
- <div style="background: rgba(6, 182, 212, 0.1); border-radius: 5px; padding: 10px; flex: 1;">
408
+ It can be used as follows:
89
409
 
90
- ```typescript
91
- // ESM
92
- import makeWASocket from 'baileys-anya'
410
+ ```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
+ })
93
436
  ```
94
437
 
95
- </div>
96
- <div style="background: rgba(234, 179, 8, 0.1); border-radius: 5px; padding: 10px; flex: 1;">
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
455
+
456
+ ## Sending Messages
457
+
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**
97
461
 
98
- ```javascript
99
- // CommonJS
100
- const { default: makeWASocket } = require('baileys-anya')
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
473
+
474
+ ```ts
475
+ await sock.sendMessage(jid, { text: 'hello word' })
101
476
  ```
102
477
 
103
- </div>
104
- </div>
105
- </div>
478
+ #### Quote Message (works with all types)
106
479
 
107
- <div align="center">
108
- <img src="https://capsule-render.vercel.app/api?type=rect&color=gradient&height=2&section=header" width="100%">
109
- </div>
480
+ ```ts
481
+ await sock.sendMessage(jid, { text: 'hello word' }, { quoted: message })
482
+ ```
110
483
 
111
- ## | FEATURE SHOWCASE
484
+ #### Mention User (works with most types)
112
485
 
113
- <div style="background: linear-gradient(45deg, rgba(124, 58, 237, 0.05), rgba(139, 92, 246, 0.05)); border-radius: 10px; padding: 15px; margin: 20px 0;">
486
+ - @number is to mention in text, it's optional
114
487
 
115
- ### 🎀 Enhanced Features Matrix
488
+ ```ts
489
+ await sock.sendMessage(jid, {
490
+ text: '@12345678901',
491
+ mentions: ['12345678901@s.whatsapp.net']
492
+ })
493
+ ```
116
494
 
117
- | Feature | Description | Status |
118
- | -------------------------------- | -------------------------------------------- | ------ |
119
- | 🔊 **Channel Messaging** | Send & manage WhatsApp channel content | ✅ |
120
- | 🎛️ **Interactive Messages** | Create rich button-based experiences | ✅ |
121
- | 🤖 **AI Message Icon** | Brand your bot messages with AI icon | ✅ |
122
- | 🖼️ **Enhanced Media** | Uncropped profile pictures & optimized media | ✅ |
123
- | 🔐 **Custom Pairing** | Personalized device pairing codes | ✅ |
124
- | 🔧 **Performance Optimizations** | Cleaner logs & improved signal handling | ✅ |
125
- | 📱 **Cross-Platform** | Works on all NodeJS supported platforms | ✅ |
495
+ #### Forward Messages
126
496
 
127
- </div>
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
128
498
 
129
- <br>
499
+ ```ts
500
+ const msg = getMessageFromStore() // implement this on your end
501
+ await sock.sendMessage(jid, { forward: msg }) // WA forward the message!
502
+ ```
130
503
 
131
- <div style="display: flex; justify-content: center; margin: 30px 0;">
132
- <div style="background: linear-gradient(135deg, #0EA5E9, #2DD4BF); color: white; padding: 12px 25px; border-radius: 25px; font-weight: bold; font-size: 16px;">🌱 SMALL BUT POWERFUL FEATURES 🎉</div>
133
- </div>
504
+ #### Location Message
134
505
 
135
- ## 📰 | NEWSLETTER MANAGEMENT
506
+ ```ts
507
+ await sock.sendMessage(jid, {
508
+ location: {
509
+ degreesLatitude: 24.121231,
510
+ degreesLongitude: 55.1121221
511
+ }
512
+ })
513
+ ```
136
514
 
137
- <details>
138
- <summary style="background: linear-gradient(90deg, #4F46E5, #7C3AED); color: white; padding: 10px 15px; border-radius: 5px; cursor: pointer; font-weight: bold;">📚 Expand Newsletter Features</summary>
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
+ ```
139
533
 
140
- <div style="padding: 15px; background: rgba(79, 70, 229, 0.05); border-radius: 0 0 10px 10px; margin-top: -5px;">
534
+ #### Reaction Message
141
535
 
142
- ### 📊 Get Newsletter Info
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
143
537
 
144
- ```typescript
145
- // By invite
146
- const metadata = await sock.newsletterMetadata('invite', 'xxxxx')
147
- // By JID
148
- const metadata = await sock.newsletterMetadata('jid', 'abcd@newsletter')
149
- console.log(metadata)
538
+ ```ts
539
+ await sock.sendMessage(jid, {
540
+ react: {
541
+ text: '💖', // use an empty string to remove the reaction
542
+ key: message.key
543
+ }
544
+ })
150
545
  ```
151
546
 
152
- ### 📝 Update Newsletter Content
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
+ ```
153
571
 
154
- ```typescript
155
- // Update description
156
- await sock.newsletterUpdateDescription('abcd@newsletter', 'New Description')
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
+ ```
157
587
 
158
- // Update name
159
- await sock.newsletterUpdateName('abcd@newsletter', 'New Name')
588
+ ### Sending Messages with Link Previews
160
589
 
161
- // Update picture
162
- await sock.newsletterUpdatePicture('abcd@newsletter', buffer)
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:
163
594
 
164
- // Remove picture
165
- await sock.newsletterRemovePicture('abcd@newsletter')
595
+ ```ts
596
+ await sock.sendMessage(jid, {
597
+ text: 'Hi, this was sent using https://github.com/whiskeysockets/baileys'
598
+ })
166
599
  ```
167
600
 
168
- ### 🔔 Notification Management
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.
169
609
 
170
- ```typescript
171
- // Unmute newsletter
172
- await sock.newsletterUnmute('abcd@newsletter')
610
+ > [!TIP]
611
+ > It's recommended to use Stream or Url to save memory
173
612
 
174
- // Mute newsletter
175
- await sock.newsletterMute('abcd@newsletter')
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
+
617
+ ```ts
618
+ await sock.sendMessage(jid, {
619
+ video: fs.readFileSync('Media/ma_gif.mp4'),
620
+ caption: 'hello word',
621
+ gifPlayback: true
622
+ })
176
623
  ```
177
624
 
178
- ### 🔄 Newsletter Management
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`
634
+ })
635
+ ```
179
636
 
180
- ```typescript
181
- // Create new newsletter
182
- const metadata = await sock.newsletterCreate('Newsletter Name', 'Newsletter Description')
183
- console.log(metadata)
637
+ #### Audio Message
184
638
 
185
- // Delete newsletter
186
- await sock.newsletterDelete('abcd@newsletter')
639
+ - To audio message work in all devices you need to convert with some tool like `ffmpeg` with this flags:
187
640
 
188
- // Follow newsletter
189
- await sock.newsletterFollow('abcd@newsletter')
641
+ ```bash
642
+ codec: libopus //ogg file
643
+ ac: 1 //one channel
644
+ avoid_negative_ts
645
+ make_zero
646
+ ```
190
647
 
191
- // Unfollow newsletter
192
- await sock.newsletterUnfollow('abcd@newsletter')
648
+ - Example:
649
+
650
+ ```bash
651
+ ffmpeg -i input.mp4 -avoid_negative_ts make_zero -ac 1 output.ogg
652
+ ```
653
+
654
+ ```ts
655
+ await sock.sendMessage(jid, {
656
+ audio: {
657
+ url: './Media/audio.mp3'
658
+ },
659
+ mimetype: 'audio/mp4'
660
+ })
193
661
  ```
194
662
 
195
- ### 😀 Engagement Features
663
+ #### Image Message
196
664
 
197
- ```typescript
198
- // Send reaction to newsletter post
199
- // Get ID from message URL: https://whatsapp.com/channel/xxxxx/175
200
- const id = '175'
201
- await sock.newsletterReactMessage('abcd@newsletter', id, '🥳')
665
+ ```ts
666
+ await sock.sendMessage(id, {
667
+ image: {
668
+ url: './Media/ma_img.png'
669
+ },
670
+ caption: 'hello word'
671
+ })
202
672
  ```
203
673
 
204
- </div>
205
- </details>
674
+ #### View Once Message
206
675
 
207
- ## 🎛️ | INTERACTIVE MESSAGING
676
+ - You can send all messages above as `viewOnce`, you only need to pass `viewOnce: true` in content object
208
677
 
209
- <details>
210
- <summary style="background: linear-gradient(90deg, #EC4899, #F43F5E); color: white; padding: 10px 15px; border-radius: 5px; cursor: pointer; font-weight: bold;">🎯 Expand Button & Interactive Features</summary>
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'
685
+ })
686
+ ```
687
+
688
+ ## Modify Messages
211
689
 
212
- <div style="padding: 15px; background: rgba(236, 72, 153, 0.05); border-radius: 0 0 10px 10px; margin-top: -5px;">
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
+ ```
213
696
 
214
- ### 📝 Text Buttons
697
+ **Note:** deleting for oneself is supported via `chatModify`, see in [this section](#modifying-chats)
215
698
 
216
- ```typescript
217
- const buttons = [
218
- { buttonId: 'id1', buttonText: { displayText: 'Button 1' }, type: 1 },
219
- { buttonId: 'id2', buttonText: { displayText: 'Button 2' }, type: 1 }
220
- ]
699
+ ### Editing Messages
221
700
 
222
- const buttonMessage = {
223
- text: "Hi it's button message",
224
- footer: 'Hello World',
225
- buttons,
226
- headerType: 1,
227
- viewOnce: true
701
+ - You can pass all editable contents here
702
+
703
+ ```ts
704
+ await sock.sendMessage(jid, {
705
+ text: 'updated text goes here',
706
+ edit: response.key
707
+ })
708
+ ```
709
+
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
+ }
228
747
  }
748
+ ```
229
749
 
230
- await sock.sendMessage(id, buttonMessage, { quoted: null })
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)
231
756
  ```
232
757
 
233
- ### 🖼️ Image Buttons
758
+ ## Reject Call
234
759
 
235
- ```typescript
236
- const buttons = [
237
- { buttonId: 'id1', buttonText: { displayText: 'Button 1' }, type: 1 },
238
- { buttonId: 'id2', buttonText: { displayText: 'Button 2' }, type: 1 }
239
- ]
760
+ - You can obtain `callId` and `callFrom` from `call` event
240
761
 
241
- const buttonMessage = {
242
- image: { url: 'https://example.com/abcd.jpg' }, // image: buffer or path
243
- caption: "Hi it's button message with image",
244
- footer: 'Hello World',
245
- buttons,
246
- headerType: 1,
247
- viewOnce: true
248
- }
762
+ ```ts
763
+ await sock.rejectCall(callId, callFrom)
764
+ ```
249
765
 
250
- await sock.sendMessage(id, buttonMessage, { quoted: null })
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])
251
778
  ```
252
779
 
253
- ### 🎬 Video Buttons
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`.
254
782
 
255
- ```typescript
256
- const buttons = [
257
- { buttonId: 'id1', buttonText: { displayText: 'Button 1' }, type: 1 },
258
- { buttonId: 'id2', buttonText: { displayText: 'Button 2' }, type: 1 }
259
- ]
783
+ ### Update Presence
260
784
 
261
- const buttonMessage = {
262
- video: { url: 'https://example.com/abcd.mp4' }, // video: buffer or path
263
- caption: "Hi it's button message with video",
264
- footer: 'Hello World',
265
- buttons,
266
- headerType: 1,
267
- viewOnce: true
268
- }
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.
269
788
 
270
- await sock.sendMessage(id, buttonMessage, { quoted: null })
789
+ ```ts
790
+ await sock.sendPresenceUpdate('available', jid)
271
791
  ```
272
792
 
273
- ### 🔄 Advanced Interactive Messages
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')`
274
795
 
275
- ```typescript
276
- const interactiveButtons = [
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(
277
859
  {
278
- name: 'quick_reply',
279
- buttonParamsJson: JSON.stringify({
280
- display_text: 'Quick Reply',
281
- id: 'ID'
282
- })
860
+ delete: true,
861
+ lastMessages: [
862
+ {
863
+ key: lastMsgInChat.key,
864
+ messageTimestamp: lastMsgInChat.messageTimestamp
865
+ }
866
+ ]
283
867
  },
868
+ jid
869
+ )
870
+ ```
871
+
872
+ ### Pin/Unpin a Chat
873
+
874
+ ```ts
875
+ await sock.chatModify(
284
876
  {
285
- name: 'cta_url',
286
- buttonParamsJson: JSON.stringify({
287
- display_text: 'Tap Here!',
288
- url: 'https://www.example.com/'
289
- })
877
+ pin: true // or `false` to unpin
290
878
  },
879
+ jid
880
+ )
881
+ ```
882
+
883
+ ### Star/Unstar a Message
884
+
885
+ ```ts
886
+ await sock.chatModify(
291
887
  {
292
- name: 'cta_copy',
293
- buttonParamsJson: JSON.stringify({
294
- display_text: 'Copy Code',
295
- id: '12345',
296
- copy_code: '12345'
297
- })
298
- }
299
- ]
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
+ ```
300
901
 
301
- const interactiveMessage = {
302
- text: 'Hello World!',
303
- title: 'this is the title',
304
- footer: 'this is the footer',
305
- interactiveButtons
306
- }
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
+ )
307
922
 
308
- await sock.sendMessage(id, interactiveMessage, { quoted: null })
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!')
997
+ ```
998
+
999
+ ### Change Profile Name
1000
+
1001
+ ```ts
1002
+ await sock.updateProfileName('My name')
1003
+ ```
1004
+
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)
1011
+
1012
+ ```ts
1013
+ await sock.updateProfilePicture(jid, { url: './new-profile-picture.jpeg' })
1014
+ ```
1015
+
1016
+ ### Remove display picture (groups too)
1017
+
1018
+ ```ts
1019
+ await sock.removeProfilePicture(jid)
1020
+ ```
1021
+
1022
+ ## Groups
1023
+
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
1036
+
1037
+ ```ts
1038
+ // id & people to add to the group (will throw error if it fails)
1039
+ await sock.groupParticipantsUpdate(
1040
+ jid,
1041
+ ['abcd@s.whatsapp.net', 'efgh@s.whatsapp.net'],
1042
+ 'add' // replace this parameter with 'remove' or 'demote' or 'promote'
1043
+ )
1044
+ ```
1045
+
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
1104
+
1105
+ ```ts
1106
+ const response = await sock.groupGetInviteInfo(code)
1107
+ console.log('group information: ' + response)
1108
+ ```
1109
+
1110
+ ### Query Metadata (participants, name, description...)
1111
+
1112
+ ```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)
309
1122
  ```
310
1123
 
311
- ### 🖼️ Rich Media Interactive Messages
1124
+ ### Get Request Join List
1125
+
1126
+ ```ts
1127
+ const response = await sock.groupRequestParticipantsList(jid)
1128
+ console.log(response)
1129
+ ```
1130
+
1131
+ ### Approve/Reject Request Join
1132
+
1133
+ ```ts
1134
+ const response = await sock.groupRequestParticipantsUpdate(
1135
+ jid, // group id
1136
+ ['abcd@s.whatsapp.net', 'efgh@s.whatsapp.net'],
1137
+ 'approve' // or 'reject'
1138
+ )
1139
+ console.log(response)
1140
+ ```
1141
+
1142
+ ### Get All Participating Groups Metadata
1143
+
1144
+ ```ts
1145
+ const response = await sock.groupFetchAllParticipating()
1146
+ console.log(response)
1147
+ ```
312
1148
 
313
- ```typescript
314
- const interactiveButtons = [
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 |
1159
+
1160
+ ```ts
1161
+ await sock.groupToggleEphemeral(jid, 86400)
1162
+ ```
1163
+
1164
+ ### Change Add Mode
1165
+
1166
+ ```ts
1167
+ await sock.groupMemberAddMode(
1168
+ jid,
1169
+ 'all_member_add' // or 'admin_add'
1170
+ )
1171
+ ```
1172
+
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
1183
+
1184
+ ```ts
1185
+ const privacySettings = await sock.fetchPrivacySettings(true)
1186
+ console.log('privacy settings: ' + privacySettings)
1187
+ ```
1188
+
1189
+ ### Get BlockList
1190
+
1191
+ ```ts
1192
+ const response = await sock.fetchBlocklist()
1193
+ console.log(response)
1194
+ ```
1195
+
1196
+ ### Update LastSeen Privacy
1197
+
1198
+ ```ts
1199
+ const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
1200
+ await sock.updateLastSeenPrivacy(value)
1201
+ ```
1202
+
1203
+ ### Update Online Privacy
1204
+
1205
+ ```ts
1206
+ const value = 'all' // 'match_last_seen'
1207
+ await sock.updateOnlinePrivacy(value)
1208
+ ```
1209
+
1210
+ ### Update Profile Picture Privacy
1211
+
1212
+ ```ts
1213
+ const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
1214
+ await sock.updateProfilePicturePrivacy(value)
1215
+ ```
1216
+
1217
+ ### Update Status Privacy
1218
+
1219
+ ```ts
1220
+ const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
1221
+ await sock.updateStatusPrivacy(value)
1222
+ ```
1223
+
1224
+ ### Update Read Receipts Privacy
1225
+
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)
1236
+ ```
1237
+
1238
+ ### Update Default Disappearing Mode
1239
+
1240
+ - Like [this](#disappearing-messages), ephemeral can be:
1241
+
1242
+ | Time | Seconds |
1243
+ | ------ | --------- |
1244
+ | Remove | 0 |
1245
+ | 24h | 86.400 |
1246
+ | 7d | 604.800 |
1247
+ | 90d | 7.776.000 |
1248
+
1249
+ ```ts
1250
+ const ephemeral = 86400
1251
+ await sock.updateDefaultDisappearingMode(ephemeral)
1252
+ ```
1253
+
1254
+ ## Broadcast Lists & Stories
1255
+
1256
+ ### Send Broadcast & Stories
1257
+
1258
+ - Messages can be sent to broadcasts & stories. You need to add the following message options in sendMessage, like this:
1259
+
1260
+ ```ts
1261
+ await sock.sendMessage(
1262
+ jid,
315
1263
  {
316
- name: 'quick_reply',
317
- buttonParamsJson: JSON.stringify({
318
- display_text: 'Quick Reply',
319
- id: 'ID'
320
- })
1264
+ image: {
1265
+ url: url
1266
+ },
1267
+ caption: caption
321
1268
  },
322
1269
  {
323
- name: 'cta_url',
324
- buttonParamsJson: JSON.stringify({
325
- display_text: 'Visit Website',
326
- url: 'https://www.example.com/'
327
- })
1270
+ backgroundColor: backgroundColor,
1271
+ font: font,
1272
+ statusJidList: statusJidList,
1273
+ broadcast: true
328
1274
  }
329
- ]
330
-
331
- // With Image
332
- const imageInteractiveMessage = {
333
- image: { url: 'https://example.com/abcd.jpg' },
334
- caption: 'Check out this amazing photo!',
335
- title: 'Photo Showcase',
336
- footer: 'Tap a button below',
337
- interactiveButtons
338
- }
1275
+ )
1276
+ ```
339
1277
 
340
- await sock.sendMessage(id, imageInteractiveMessage, { quoted: null })
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.
341
1282
 
342
- // With Video
343
- const videoInteractiveMessage = {
344
- video: { url: 'https://example.com/abcd.mp4' },
345
- caption: 'Watch this awesome video!',
346
- title: 'Video Showcase',
347
- footer: 'Tap a button below',
348
- interactiveButtons
349
- }
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`
350
1286
 
351
- await sock.sendMessage(id, videoInteractiveMessage, { quoted: null })
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}`)
352
1292
  ```
353
1293
 
354
- </div>
355
- </details>
1294
+ ## Writing Custom Functionality
356
1295
 
357
- ## 🤖 | AI MESSAGING
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.
358
1297
 
359
- <div style="background: linear-gradient(135deg, rgba(16, 185, 129, 0.1), rgba(5, 150, 105, 0.1)); border-radius: 10px; padding: 20px; margin: 20px 0;">
1298
+ ### Enabling Debug Level in Baileys Logs
360
1299
 
361
- ### AI Icon Feature
1300
+ First, enable the logging of unhandled messages from WhatsApp by setting:
362
1301
 
363
- ```typescript
364
- // Simply add "ai: true" to display AI icon with your message
365
- await sock.sendMessage(id, { text: "Hello! I'm your AI assistant.", ai: true })
1302
+ ```ts
1303
+ const sock = makeWASocket({
1304
+ logger: P({ level: 'debug' })
1305
+ })
366
1306
  ```
367
1307
 
368
- <div style="background: rgba(16, 185, 129, 0.2); border-radius: 5px; padding: 10px; margin-top: 15px;">
369
- <strong>💡 Pro Tip:</strong> AI icons make your bot messages stand out and indicate automated responses to users.
370
- </div>
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
+
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) => {})
1367
+ ```
371
1368
 
372
- </div>
1369
+ # License
373
1370
 
374
- ## 🔐 | CUSTOM PAIRING
1371
+ Copyright (c) 2025 Rajeh Taher/WhiskeySockets
375
1372
 
376
- <div style="background: linear-gradient(135deg, rgba(245, 158, 11, 0.1), rgba(217, 119, 6, 0.1)); border-radius: 10px; padding: 20px; margin: 20px 0;">
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:
377
1380
 
378
- ### Custom Code Implementation
1381
+ The above copyright notice and this permission notice shall be included in all
1382
+ copies or substantial portions of the Software.
379
1383
 
380
- ```typescript
381
- if (usePairingCode && !sock.authState.creds.registered) {
382
- const phoneNumber = await question('Please enter your mobile phone number:\n')
383
- const custom = '4NY4P8KA' // must be 8 digits, can be letters or numbers
384
- const code = await sock.requestPairingCode(phoneNumber, custom)
385
- console.log(`Pairing code: ${code?.match(/.{1,4}/g)?.join('-') || code}`)
386
- }
387
- ```
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.
388
1391
 
389
- <div style="background: rgba(245, 158, 11, 0.2); border-radius: 5px; padding: 10px; margin-top: 15px;">
390
- <strong>🔒 Security Note:</strong> Custom pairing codes enhance security while providing a personalized experience.
391
- </div>
392
-
393
- </div>
394
-
395
- <div align="center">
396
- <img src="https://capsule-render.vercel.app/api?type=rect&color=gradient&height=2&section=header" width="100%">
397
- </div>
398
-
399
- ## 🛠️ | QUICK IMPLEMENTATION GUIDE
400
-
401
- <div style="display: flex; flex-wrap: wrap; gap: 15px; margin: 20px 0;">
402
- <div style="flex: 1; min-width: 250px; background: rgba(59, 130, 246, 0.05); border-radius: 10px; padding: 15px;">
403
- <h3>🚀 Step 1: Install</h3>
404
- <p>Add baileys-anya to your project using npm</p>
405
- <div style="background: rgba(0, 0, 0, 0.2); padding: 10px; border-radius: 5px;">
406
- <code>npm install baileys-anya</code>
407
- <p>OR</p>
408
- <code>yarn add baileys-anya</code>
409
- <p>OR</p>
410
- <code>pnpm add baileys-anya</code>
411
- </div>
412
- </div>
413
-
414
- <div style="flex: 1; min-width: 250px; background: rgba(59, 130, 246, 0.05); border-radius: 10px; padding: 15px;">
415
- <h3>🔄 Step 2: Import</h3>
416
- <p>Import the library into your project</p>
417
- <div style="background: rgba(0, 0, 0, 0.2); padding: 10px; border-radius: 5px;">
418
- <code>import makeWASocket from 'baileys-anya'</code>
419
- </div>
420
- </div>
421
-
422
- <div style="flex: 1; min-width: 250px; background: rgba(59, 130, 246, 0.05); border-radius: 10px; padding: 15px;">
423
- <h3>⚙️ Step 3: Configure</h3>
424
- <p>Set up your WhatsApp connection</p>
425
- <div style="background: rgba(0, 0, 0, 0.2); padding: 10px; border-radius: 5px;">
426
- <code>const sock = makeWASocket({...})</code>
427
- </div>
428
- </div>
429
-
430
- <div style="flex: 1; min-width: 250px; background: rgba(59, 130, 246, 0.05); border-radius: 10px; padding: 15px;">
431
- <h3>🚀 Step 4: Implement</h3>
432
- <p>Start using the enhanced features</p>
433
- <div style="background: rgba(0, 0, 0, 0.2); padding: 10px; border-radius: 5px;">
434
- <code>await sock.sendMessage(id, {...})</code>
435
- </div>
436
- </div>
437
- </div>
438
-
439
- ## 🐛 | REPORTING ISSUES
440
-
441
- <div style="background: linear-gradient(135deg, rgba(239, 68, 68, 0.05), rgba(220, 38, 38, 0.05)); border-radius: 10px; padding: 20px; margin: 20px 0;">
442
- <h3>Found a bug? Have a suggestion?</h3>
443
- <p>If you encounter any issues while using this repository, please feel free to open a <a href="https://github.com/teamolduser/bail/issues" style="color: #60A5FA; text-decoration: none; font-weight: bold;">new issue</a>.</p>
444
-
445
- <div style="display: flex; align-items: center; gap: 10px; margin-top: 15px; background: rgba(239, 68, 68, 0.1); padding: 10px; border-radius: 5px;">
446
- <span style="font-size: 24px;">👾</span>
447
- <span>Our team actively monitors and responds to all issues.</span>
448
- </div>
449
- </div>
450
-
451
- ## 📝 | NOTES
452
-
453
- <div style="background: linear-gradient(135deg, rgba(107, 114, 128, 0.05), rgba(75, 85, 99, 0.05)); border-radius: 10px; padding: 20px; margin: 20px 0;">
454
- <p>Everything other than the modifications mentioned above remains the same as the original repository. You can check out the original repository at <a href="https://github.com/WhiskeySockets/Baileys" style="color: #60A5FA; text-decoration: none; font-weight: bold;">WhiskeySockets</a>.</p>
455
- </div>
456
-
457
- <div align="center">
458
- <img src="https://capsule-render.vercel.app/api?type=waving&color=gradient&height=100&section=footer" width="100%">
459
- </div>
460
-
461
- <div align="center" style="margin-top: -40px;">
462
- <div style="background: linear-gradient(90deg, #6366F1, #3B82F6, #2DD4BF); -webkit-background-clip: text; -webkit-text-fill-color: transparent; font-size: 24px; font-weight: bold; margin-bottom: 10px;">
463
- ⭐ STAR THIS REPOSITORY ⭐
464
- </div>
465
-
466
- <div style="display: flex; justify-content: center; gap: 10px; margin: 20px 0;">
467
- <div style="background: rgba(6, 182, 212, 0.1); border-radius: 5px; padding: 8px 15px;">
468
- <span style="font-size: 20px;">👨‍💻</span> <span>Developers</span>
469
- </div>
470
- <div style="background: rgba(16, 185, 129, 0.1); border-radius: 5px; padding: 8px 15px;">
471
- <span style="font-size: 20px;">🤖</span> <span>Bot Creators</span>
472
- </div>
473
- <div style="background: rgba(245, 158, 11, 0.1); border-radius: 5px; padding: 8px 15px;">
474
- <span style="font-size: 20px;">🚀</span> <span>Innovators</span>
475
- </div>
476
- </div>
477
-
478
- <p style="font-style: italic; max-width: 600px; margin: 0 auto;">Powered by Baileys-Anya - The Ultimate WhatsApp Web API Experience</p>
479
- </div>
1392
+ Thus, the maintainers of the project can't be held liable for any potential misuse of this project.