angularsockets 1.0.1 → 1.0.2

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 (131) hide show
  1. package/README.md +1880 -36
  2. package/WAProto/index.d.ts +50383 -0
  3. package/WAProto/index.js +37203 -11791
  4. package/WASignalGroup/GroupProtocol.js +1697 -0
  5. package/WASignalGroup/ciphertext_message.js +16 -0
  6. package/WASignalGroup/group_cipher.js +120 -0
  7. package/WASignalGroup/group_session_builder.js +46 -0
  8. package/WASignalGroup/index.js +5 -0
  9. package/WASignalGroup/keyhelper.js +21 -0
  10. package/WASignalGroup/protobufs.js +3 -0
  11. package/WASignalGroup/queue_job.js +69 -0
  12. package/WASignalGroup/sender_chain_key.js +50 -0
  13. package/WASignalGroup/sender_key_distribution_message.js +78 -0
  14. package/WASignalGroup/sender_key_message.js +92 -0
  15. package/WASignalGroup/sender_key_name.js +70 -0
  16. package/WASignalGroup/sender_key_record.js +56 -0
  17. package/WASignalGroup/sender_key_state.js +129 -0
  18. package/{lib/Signal/Group/sender-message-key.js → WASignalGroup/sender_message_key.js} +16 -6
  19. package/lib/Defaults/baileys-version.json +1 -1
  20. package/lib/Defaults/index.js +79 -101
  21. package/lib/Signal/libsignal.js +29 -51
  22. package/lib/Socket/Client/web-socket-client.js +0 -2
  23. package/lib/Socket/business.d.ts +42 -43
  24. package/lib/Socket/chats.d.ts +9 -8
  25. package/lib/Socket/chats.js +107 -21
  26. package/lib/Socket/groups.d.ts +7 -7
  27. package/lib/Socket/groups.js +24 -25
  28. package/lib/Socket/index.d.ts +51 -52
  29. package/lib/Socket/messages-recv.d.ts +34 -37
  30. package/lib/Socket/messages-recv.js +37 -175
  31. package/lib/Socket/messages-send.d.ts +16 -10
  32. package/lib/Socket/messages-send.js +540 -346
  33. package/lib/Socket/newsletter.d.ts +26 -28
  34. package/lib/Socket/newsletter.js +4 -4
  35. package/lib/Socket/registration.d.ts +49 -52
  36. package/lib/Socket/registration.js +7 -7
  37. package/lib/Socket/socket.d.ts +1 -0
  38. package/lib/Socket/socket.js +36 -23
  39. package/lib/Socket/usync.d.ts +11 -10
  40. package/lib/Store/make-cache-manager-store.d.ts +2 -1
  41. package/lib/Store/make-in-memory-store.d.ts +2 -2
  42. package/lib/Store/make-in-memory-store.js +5 -1
  43. package/lib/Store/make-ordered-dictionary.js +2 -2
  44. package/lib/Types/Auth.d.ts +0 -1
  45. package/lib/Types/Call.d.ts +1 -1
  46. package/lib/Types/Chat.d.ts +12 -7
  47. package/lib/Types/Events.d.ts +17 -2
  48. package/lib/Types/GroupMetadata.d.ts +3 -2
  49. package/lib/Types/Label.d.ts +11 -0
  50. package/lib/Types/Label.js +1 -1
  51. package/lib/Types/LabelAssociation.js +1 -1
  52. package/lib/Types/Message.d.ts +170 -10
  53. package/lib/Types/Newsletter.js +3 -3
  54. package/lib/Types/Socket.d.ts +7 -2
  55. package/lib/Types/index.d.ts +9 -0
  56. package/lib/Types/index.js +1 -1
  57. package/lib/Utils/auth-utils.js +35 -14
  58. package/lib/Utils/business.d.ts +1 -1
  59. package/lib/Utils/business.js +2 -2
  60. package/lib/Utils/chat-utils.d.ts +11 -12
  61. package/lib/Utils/chat-utils.js +52 -36
  62. package/lib/Utils/crypto.d.ts +15 -16
  63. package/lib/Utils/crypto.js +74 -26
  64. package/lib/Utils/decode-wa-message.d.ts +17 -0
  65. package/lib/Utils/decode-wa-message.js +53 -17
  66. package/lib/Utils/event-buffer.js +10 -7
  67. package/lib/Utils/generics.d.ts +13 -17
  68. package/lib/Utils/generics.js +26 -15
  69. package/lib/Utils/history.d.ts +6 -2
  70. package/lib/Utils/history.js +4 -6
  71. package/lib/Utils/logger.d.ts +1 -3
  72. package/lib/Utils/lt-hash.js +12 -12
  73. package/lib/Utils/make-mutex.d.ts +2 -2
  74. package/lib/Utils/messages-media.d.ts +25 -28
  75. package/lib/Utils/messages-media.js +47 -57
  76. package/lib/Utils/messages.js +461 -44
  77. package/lib/Utils/noise-handler.d.ts +4 -5
  78. package/lib/Utils/noise-handler.js +19 -14
  79. package/lib/Utils/process-message.d.ts +5 -5
  80. package/lib/Utils/process-message.js +75 -23
  81. package/lib/Utils/signal.d.ts +2 -1
  82. package/lib/Utils/signal.js +43 -35
  83. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -1
  84. package/lib/Utils/use-multi-file-auth-state.js +251 -36
  85. package/lib/Utils/use-single-file-auth-state.d.ts +12 -0
  86. package/lib/Utils/use-single-file-auth-state.js +75 -0
  87. package/lib/Utils/validate-connection.d.ts +1 -1
  88. package/lib/Utils/validate-connection.js +1 -1
  89. package/lib/WABinary/decode.d.ts +1 -2
  90. package/lib/WABinary/decode.js +23 -11
  91. package/lib/WABinary/encode.d.ts +1 -2
  92. package/lib/WABinary/encode.js +46 -22
  93. package/lib/WABinary/generic-utils.d.ts +2 -4
  94. package/lib/WABinary/generic-utils.js +2 -10
  95. package/lib/WABinary/jid-utils.d.ts +1 -1
  96. package/lib/WAM/BinaryInfo.d.ts +2 -11
  97. package/lib/WAM/encode.d.ts +1 -2
  98. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -3
  99. package/lib/WAUSync/USyncUser.d.ts +0 -2
  100. package/lib/index.js +0 -6
  101. package/package.json +96 -104
  102. package/engine-requirements.js +0 -10
  103. package/lib/Defaults/phonenumber-mcc.json +0 -223
  104. package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
  105. package/lib/Signal/Group/ciphertext-message.js +0 -15
  106. package/lib/Signal/Group/group-session-builder.d.ts +0 -14
  107. package/lib/Signal/Group/group-session-builder.js +0 -64
  108. package/lib/Signal/Group/group_cipher.d.ts +0 -17
  109. package/lib/Signal/Group/group_cipher.js +0 -96
  110. package/lib/Signal/Group/index.d.ts +0 -11
  111. package/lib/Signal/Group/index.js +0 -57
  112. package/lib/Signal/Group/keyhelper.d.ts +0 -10
  113. package/lib/Signal/Group/keyhelper.js +0 -55
  114. package/lib/Signal/Group/queue-job.d.ts +0 -1
  115. package/lib/Signal/Group/queue-job.js +0 -57
  116. package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
  117. package/lib/Signal/Group/sender-chain-key.js +0 -34
  118. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
  119. package/lib/Signal/Group/sender-key-distribution-message.js +0 -66
  120. package/lib/Signal/Group/sender-key-message.d.ts +0 -18
  121. package/lib/Signal/Group/sender-key-message.js +0 -69
  122. package/lib/Signal/Group/sender-key-name.d.ts +0 -17
  123. package/lib/Signal/Group/sender-key-name.js +0 -51
  124. package/lib/Signal/Group/sender-key-record.d.ts +0 -30
  125. package/lib/Signal/Group/sender-key-record.js +0 -53
  126. package/lib/Signal/Group/sender-key-state.d.ts +0 -38
  127. package/lib/Signal/Group/sender-key-state.js +0 -99
  128. package/lib/Signal/Group/sender-message-key.d.ts +0 -11
  129. package/lib/Socket/dugong.d.ts +0 -175
  130. package/lib/Socket/dugong.js +0 -342
  131. package/lib/index.d.ts +0 -12
package/README.md CHANGED
@@ -1,56 +1,1900 @@
1
- # Angular Sockets - WhatsApp Baileys
1
+ # <div align='center'>WhatsApp Web API</div>
2
2
 
3
- `MODIFIED BY MR FRANK`
3
+ <div align='center'>
4
4
 
5
- <p align="center">
6
- <img src="https://mrfrankk-cdn.hf.space/ice/file_1756322106540.jpg" alt="Thumbnail" />
7
- </p>
5
+ ![WhatsApp API](https://raw.githubusercontent.com/Bell575/Upload/main/uploads/1742387351904.png)
8
6
 
9
- WhatsApp Baileys is an open-source library designed to help developers build automation solutions and integrations with WhatsApp efficiently and directly. Using websocket technology without the need for a browser, this library supports a wide range of features such as message management, chat handling, group administration, as well as interactive messages and action buttons for a more dynamic user experience.
7
+ </div>
10
8
 
11
- Actively developed and maintained, baileys continuously receives updates to enhance stability and performance. One of the main focuses is to improve the pairing and authentication processes to be more stable and secure. Pairing features can be customized with your own codes, making the process more reliable and less prone to interruptions.
9
+ **Baileys** is a WebSockets-based TypeScript library for interacting with the WhatsApp Web API.
10
+ This is **not the official Baileys library**, but a **modified and extended version** developed independently to add functionalities that many developers have requested. These enhancements aim to improve flexibility, offer better developer experience, and provide tools that are missing from the original version.
12
11
 
13
- This library is highly suitable for building business bots, chat automation systems, customer service solutions, and various other communication automation applications that require high stability and comprehensive features. With a lightweight and modular design, baileys is easy to integrate into different systems and platforms.
12
+ # Disclaimer
13
+ This project is **not affiliated with, endorsed by, or officially connected to WhatsApp Inc., Meta Platforms, Inc., or any of their subsidiaries**. The official WhatsApp website can be found at [whatsapp.com](https://whatsapp.com). "WhatsApp," along with related names, marks, and logos, are registered trademarks and the intellectual property of their respective owners.
14
14
 
15
- ---
15
+ This modified version of Baileys was created with the intention of empowering developers, but it **must be used responsibly**. The maintainers **strongly discourage** any usage that goes against WhatsApp’s [Terms of Service](https://www.whatsapp.com/legal/terms-of-service). This includes—but is not limited to—spamming, bulk or automated messaging, stalking, scraping user data, or deploying it in any way that violates privacy, consent, or platform integrity.
16
16
 
17
- ### Main Features and Advantages
17
+ This project is provided **as-is** and should be used with **extreme caution**.
18
+ **You are solely responsible** for how you choose to use this library. Always ensure your use case is ethical, legal, and respects the rights and privacy of others.
18
19
 
19
- - Supports automatic and custom pairing processes
20
- - Fixes previous pairing issues that often caused failures or disconnections
21
- - Supports interactive messages, action buttons, and dynamic menus
22
- - Efficient automatic session management for reliable operation
23
- - Compatible with the latest multi-device features from WhatsApp
24
- - Lightweight, stable, and easy to integrate into various systems
25
- - Suitable for developing bots, automation, and complete communication solutions
26
- - Comprehensive documentation and example codes to facilitate development
20
+ **Use at your own discretion.** Respect platform rules, user boundaries, and stay within legal and moral lines.
27
21
 
28
- ---
22
+ ## Example
29
23
 
30
- ### Getting Started
24
+ Here is an example you can use: [example.ts](Example/example.ts) or here is a tutorial for running the Baileys WhatsApp API code
25
+ 1. ``` cd path/to/Baileys ```
26
+ 2. ``` npm install```
27
+ 3. ``` node example.js```
31
28
 
32
- Begin by installing the library via your preferred package manager, then follow the provided configuration guide. You can also utilize the ready-made example codes to understand how the features work. Use session storage and interactive messaging features to build complete, stable solutions tailored to your business or project needs.
29
+ ## Install
33
30
 
34
- ---
31
+ Use the stable version:
32
+ ```bash
33
+ npm install baileys-pro
34
+ ```
35
35
 
36
- ### Why Choose whatsapp baileys?
36
+ Use the edge version (no guarantee of stability, but latest fixes + features)
37
+ ```bash
38
+ yarn add baileys-pro@latest
39
+ ```
37
40
 
38
- Because this library offers high stability, full features, and an actively improved pairing process. It is ideal for developers aiming to create professional and secure WhatsApp automation solutions. Support for the latest WhatsApp features ensures compatibility with platform updates.
41
+ Then import your code using:
42
+ ```javascript
43
+ const { default: makeWASocket } = require("baileys-pro")
44
+ ```
45
+ # Links
39
46
 
40
- ---
47
+ #### Official
48
+ - [Discord](https://discord.gg/WeJM5FP9GG)
49
+ - [Docs](https://guide.whiskeysockets.io/)
41
50
 
42
- ## Technical Notes
51
+ #### Baileys Pro
52
+ - [WhatsApp](https://whatsapp.com/channel/0029Vb89ifxH5JM0fh2VvM2U)
43
53
 
44
- - Supports custom pairing codes that are stable and secure
45
- - Fixes previous issues related to pairing and authentication
46
- - Features interactive messages and action buttons for dynamic menu creation
47
- - Automatic and efficient session management for long-term stability
48
- - Compatible with the latest multi-device features from WhatsApp
49
- - Easy to integrate and customize based on your needs
50
- - Perfect for developing bots, customer service automation, and other communication applications
54
+ # Index
51
55
 
52
- ---
56
+ - [Connecting Account](#connecting-account)
57
+ - [Connect with QR-CODE](#starting-socket-with-qr-code)
58
+ - [Connect with Pairing Code](#starting-socket-with-pairing-code)
59
+ - [Receive Full History](#receive-full-history)
60
+ - [Important Notes About Socket Config](#important-notes-about-socket-config)
61
+ - [Caching Group Metadata (Recommended)](#caching-group-metadata-recommended)
62
+ - [Improve Retry System & Decrypt Poll Votes](#improve-retry-system--decrypt-poll-votes)
63
+ - [Receive Notifications in Whatsapp App](#receive-notifications-in-whatsapp-app)
64
+ - [Custom generateMessageID Function](#custom-generatemessageid-function)
65
+ - [Save Auth Info](#saving--restoring-sessions)
66
+ - [Handling Events](#handling-events)
67
+ - [Example to Start](#example-to-start)
68
+ - [Decrypt Poll Votes](#decrypt-poll-votes)
69
+ - [Summary of Events on First Connection](#summary-of-events-on-first-connection)
70
+ - [Implementing a Data Store](#implementing-a-data-store)
71
+ - [Whatsapp IDs Explain](#whatsapp-ids-explain)
72
+ - [Utility Functions](#utility-functions)
73
+ - [Sending Messages](#sending-messages)
74
+ - [Non-Media Messages](#non-media-messages)
75
+ - [Buttons Message](#buttons-message)
76
+ - [Buttons Flow](#buttons-flow)
77
+ - [Interactive Message](#interactive-message)
78
+ - [Text Message](#text-message)
79
+ - [Quote Message](#quote-message-works-with-all-types)
80
+ - [Mention User](#mention-user-works-with-most-types)
81
+ - [Mention Status](#mention-status)
82
+ - [Result Poll From Newsletter](#result-poll-from-newsletter)
83
+ - [SendAlbumMessage](#send-album-message)
84
+ - [List Message](#list-message)
85
+ - [Carousel Message](#carousel-message)
86
+ - [Interactive Response](#interactive-response)
87
+ - [Request Payment](#request-payment)
88
+ - [Event Message](#event-message)
89
+ - [Interactive](#interactive)
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
+ - [Newsletter](#newsletter)
153
+ - [Subscribe to Newsletter Updates](#subscribe-to-newsletter-updates)
154
+ - [Update Reaction Mode](#update-reaction-mode)
155
+ - [Update Newsletter Description](#update-newsletter-description)
156
+ - [Update Newsletter Name](#update-newsletter-name)
157
+ - [Update Newsletter Picture](#update-newsletter-picture)
158
+ - [Remove Newsletter Picture](#remove-newsletter-picture)
159
+ - [Follow a Newsletter](#follow-a-newsletter)
160
+ - [Unfollow a Newsletter](#unfollow-a-newsletter)
161
+ - [Mute a Newsletter](#mute-a-newsletter)
162
+ - [Unmute a Newsletter](#unmute-a-newsletter)
163
+ - [Perform a Newsletter Action (Generic)](#perform-a-newsletter-action-generic)
164
+ - [Create a Newsletter](#create-a-newsletter)
165
+ - [Fetch Newsletter Metadata](#fetch-newsletter-metadata)
166
+ - [Get Admin Count](#get-admin-count)
167
+ - [Change Newsletter Owner](#change-newsletter-owner)
168
+ - [Demote Newsletter Admin](#demote-newsletter-admin)
169
+ - [Delete Newsletter](#delete-newsletter)
170
+ - [React to a Message in Newsletter](#react-to-a-message-in-newsletter)
171
+ - [Fetch Messages in Newsletter](#fetch-messages-in-newsletter)
172
+ - [Fetch Updates in Newsletter](#fetch-updates-in-newsletter)
173
+ - [Privacy](#privacy)
174
+ - [Block/Unblock User](#blockunblock-user)
175
+ - [Get Privacy Settings](#get-privacy-settings)
176
+ - [Get BlockList](#get-blocklist)
177
+ - [Update LastSeen Privacy](#update-lastseen-privacy)
178
+ - [Update Online Privacy](#update-online-privacy)
179
+ - [Update Profile Picture Privacy](#update-profile-picture-privacy)
180
+ - [Update Status Privacy](#update-status-privacy)
181
+ - [Update Read Receipts Privacy](#update-read-receipts-privacy)
182
+ - [Update Groups Add Privacy](#update-groups-add-privacy)
183
+ - [Update Default Disappearing Mode](#update-default-disappearing-mode)
184
+ - [Broadcast Lists & Stories](#broadcast-lists--stories)
185
+ - [Send Broadcast & Stories](#send-broadcast--stories)
186
+ - [Query a Broadcast List's Recipients & Name](#query-a-broadcast-lists-recipients--name)
187
+ - [Writing Custom Functionality](#writing-custom-functionality)
188
+ - [Enabling Debug Level in Baileys Logs](#enabling-debug-level-in-baileys-logs)
189
+ - [How Whatsapp Communicate With Us](#how-whatsapp-communicate-with-us)
190
+ - [Register a Callback for Websocket Events](#register-a-callback-for-websocket-events)
53
191
 
54
- For complete documentation, installation guides, and implementation examples, please visit the official repository and community forums. We continually update and improve this library to meet the needs of developers and users of modern WhatsApp automation solutions.
192
+ ## Connecting Account
55
193
 
56
- Thank you for choosing WhatsApp Baileys as your WhatsApp automation solution!
194
+ 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.
195
+
196
+ ### Starting socket with **QR-CODE**
197
+
198
+ > [!TIP]
199
+ > 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)**
200
+
201
+ ```javascript
202
+ const { default: makeWASocket } = require("baileys-pro")
203
+
204
+
205
+ const sock = makeWASocket({
206
+ // can provide additional config here
207
+ browser: Browsers.ubuntu('My App'),
208
+ printQRInTerminal: true
209
+ })
210
+ ```
211
+
212
+ 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!
213
+
214
+ ### Starting socket with **Pairing Code**
215
+
216
+
217
+ > [!IMPORTANT]
218
+ > 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)
219
+
220
+ The phone number can't have `+` or `()` or `-`, only numbers, you must provide country code
221
+
222
+ ```javascript
223
+ const { default: makeWASocket } = require("baileys-pro")
224
+
225
+ const sock = makeWASocket({
226
+ // can provide additional config here
227
+ printQRInTerminal: false //need to be false
228
+ })
229
+
230
+ - Normal Pairing
231
+ if (!sock.authState.creds.registered) {
232
+ const number = 'XXXXXXXXXXX'
233
+ const code = await sock.requestPairingCode(number)
234
+ console.log(code)
235
+ }
236
+
237
+ - Costum Pairing
238
+ if (!sock.authState.creds.registered) {
239
+ const pair = "AB123C4D" // only 8 alphanumeric (no more or less)
240
+ const number = 'XXXXXXXXXXX'
241
+ const code = await sock.requestPairingCode(number, pair)
242
+ console.log(code)
243
+ }
244
+ ```
245
+
246
+ ### Receive Full History
247
+
248
+ 1. Set `syncFullHistory` as `true`
249
+ 2. Baileys, by default, use chrome browser config
250
+ - If you'd like to emulate a desktop connection (and receive more message history), this browser setting to your Socket config:
251
+
252
+ ```javascript
253
+ const sock = makeWASocket({
254
+ ...otherOpts,
255
+ // can use Windows, Ubuntu here too
256
+ browser: Browsers.macOS('Desktop'),
257
+ syncFullHistory: true
258
+ })
259
+ ```
260
+
261
+ ## Important Notes About Socket Config
262
+
263
+ ### Caching Group Metadata (Recommended)
264
+ - If you use baileys for groups, we recommend you to set `cachedGroupMetadata` in socket config, you need to implement a cache like this:
265
+
266
+ ```javascript
267
+ const groupCache = new NodeCache({stdTTL: 5 * 60, useClones: false})
268
+
269
+ const sock = makeWASocket({
270
+ cachedGroupMetadata: async (jid) => groupCache.get(jid)
271
+ })
272
+
273
+ sock.ev.on('groups.update', async ([event]) => {
274
+ const metadata = await sock.groupMetadata(event.id)
275
+ groupCache.set(event.id, metadata)
276
+ })
277
+
278
+ sock.ev.on('group-participants.update', async (event) => {
279
+ const metadata = await sock.groupMetadata(event.id)
280
+ groupCache.set(event.id, metadata)
281
+ })
282
+ ```
283
+
284
+ ### Improve Retry System & Decrypt Poll Votes
285
+ - 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:
286
+ ```javascript
287
+ const sock = makeWASocket({
288
+ getMessage: async (key) => await getMessageFromStore(key)
289
+ })
290
+ ```
291
+
292
+ ### Receive Notifications in Whatsapp App
293
+ - If you want to receive notifications in whatsapp app, set `markOnlineOnConnect` to `false`
294
+ ```javascript
295
+ const sock = makeWASocket({
296
+ markOnlineOnConnect: false
297
+ })
298
+ ```
299
+
300
+ ### Custom generateMessageID Function
301
+ - you can modify the messageId generator function against the socket
302
+ ```javascript
303
+ const sock = makeWASocket({
304
+ generateMessageID: () => crypto.randomBytes(11).toString('hex').toUpperCase(),
305
+ generateMessageIDV2: (userId) => {
306
+ const hash = crypto.createHash('sha256').update(userId).digest('hex').toUpperCase();
307
+ const randomPart = crypto.randomBytes(11).toString('hex').toUpperCase();
308
+ const combined = hash + randomPart;
309
+ let result = '';
310
+ for (let i = 0; i < 22; i++) {
311
+ const randomIndex = crypto.randomBytes(1)[0] % combined.length;
312
+ result += combined[randomIndex];
313
+ }
314
+ return result;
315
+ }
316
+ })
317
+ ```
318
+ ## Saving & Restoring Sessions
319
+
320
+ You obviously don't want to keep scanning the QR code every time you want to connect.
321
+
322
+ So, you can load the credentials to log back in:
323
+ ```javascript
324
+ const makeWASocket = require("baileys-pro").default;
325
+ const { useMultiFileAuthState } = require("baileys-pro");
326
+
327
+ // enable authDebug to display session logs
328
+ const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys', { authDebug: true })
329
+
330
+ // will use the given state to connect
331
+ // so if valid credentials are available -- it'll connect without QR
332
+ const sock = makeWASocket({ auth: state })
333
+
334
+ // this will be called as soon as the credentials are updated
335
+ sock.ev.on('creds.update', saveCreds)
336
+ ```
337
+
338
+ You can sync cache on MultiFileAuthState
339
+ ```javascript
340
+ const { state, saveCreds, cache: authCache } = await useMultiFileAuthState('auth_info_baileys', { syncCache: true })
341
+
342
+ const sock = makeWASocket({
343
+ auth: {
344
+ creds: state.creds,
345
+ keys: makeCacheableSignalKeyStore(
346
+ state.keys,
347
+ pino().child({ level: "silent", stream: "store" }),
348
+ authCache
349
+ )
350
+ }
351
+ })
352
+
353
+ sock.ev.on('creds.update', saveCreds)
354
+ ```
355
+
356
+ > [!IMPORTANT]
357
+ > `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.
358
+
359
+ > [!NOTE]
360
+ > 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.
361
+
362
+ ## Handling Events
363
+
364
+ - Baileys uses the EventEmitter syntax for events.
365
+ They're all nicely typed up, so you shouldn't have any issues with an Intellisense editor like VS Code.
366
+
367
+ > [!IMPORTANT]
368
+ > **The events are [these](https://baileys.whiskeysockets.io/types/BaileysEventMap.html)**, it's important you see all events
369
+
370
+ You can listen to these events like this:
371
+ ```javascript
372
+ const sock = makeWASocket()
373
+ sock.ev.on('messages.upsert', ({ messages }) => {
374
+ console.log('got messages', messages)
375
+ })
376
+ ```
377
+
378
+ ### Example to Start
379
+
380
+ > [!NOTE]
381
+ > This example includes basic auth storage too
382
+
383
+ ```javascript
384
+ const makeWASocket = require("baileys-pro").default;
385
+ const { DisconnectReason, useMultiFileAuthState } = require("baileys-pro");
386
+ const Boom = require('@hapi/boom');
387
+
388
+ async function connectToWhatsApp () {
389
+ const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
390
+ const sock = makeWASocket({
391
+ // can provide additional config here
392
+ auth: state,
393
+ printQRInTerminal: true
394
+ })
395
+ sock.ev.on('connection.update', (update) => {
396
+ const { connection, lastDisconnect } = update
397
+ if(connection === 'close') {
398
+ const shouldReconnect = (lastDisconnect.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut
399
+ console.log('connection closed due to ', lastDisconnect.error, ', reconnecting ', shouldReconnect)
400
+ // reconnect if not logged out
401
+ if(shouldReconnect) {
402
+ connectToWhatsApp()
403
+ }
404
+ } else if(connection === 'open') {
405
+ console.log('opened connection')
406
+ }
407
+ })
408
+ sock.ev.on('messages.upsert', event => {
409
+ for (const m of event.messages) {
410
+ console.log(JSON.stringify(m, undefined, 2))
411
+
412
+ console.log('replying to', m.key.remoteJid)
413
+ await sock.sendMessage(m.key.remoteJid!, { text: 'Hello Word' })
414
+ }
415
+ })
416
+
417
+ // to storage creds (session info) when it updates
418
+ sock.ev.on('creds.update', saveCreds)
419
+ }
420
+ // run in main file
421
+ connectToWhatsApp()
422
+ ```
423
+
424
+ > [!IMPORTANT]
425
+ > In `messages.upsert` it's recommended to use a loop like `for (const message of event.messages)` to handle all messages in array
426
+
427
+ ### Decrypt Poll Votes
428
+
429
+ - By default poll votes are encrypted and handled in `messages.update`
430
+ - That's a simple example
431
+ ```javascript
432
+ sock.ev.on('messages.update', event => {
433
+ for(const { key, update } of event) {
434
+ if(update.pollUpdates) {
435
+ const pollCreation = await getMessage(key)
436
+ if(pollCreation) {
437
+ console.log(
438
+ 'got poll update, aggregation: ',
439
+ getAggregateVotesInPollMessage({
440
+ message: pollCreation,
441
+ pollUpdates: update.pollUpdates,
442
+ })
443
+ )
444
+ }
445
+ }
446
+ }
447
+ })
448
+ ```
449
+
450
+ - `getMessage` is a [store](#implementing-a-data-store) implementation (in your end)
451
+
452
+ ### Summary of Events on First Connection
453
+
454
+ 1. When you connect first time, `connection.update` will be fired requesting you to restart sock
455
+ 2. Then, history messages will be received in `messaging.history-set`
456
+
457
+ ## Implementing a Data Store
458
+
459
+ - 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.
460
+
461
+ > [!IMPORTANT]
462
+ > I highly recommend building your own data store, as storing someone's entire chat history in memory is a terrible waste of RAM.
463
+
464
+ It can be used as follows:
465
+
466
+ ```javascript
467
+ const makeWASocket = require("baileys-pro").default;
468
+ const { makeInMemoryStore } = require("baileys-pro");
469
+ // the store maintains the data of the WA connection in memory
470
+ // can be written out to a file & read from it
471
+ const store = makeInMemoryStore({ })
472
+ // can be read from a file
473
+ store.readFromFile('./baileys_store.json')
474
+ // saves the state to a file every 10s
475
+ setInterval(() => {
476
+ store.writeToFile('./baileys_store.json')
477
+ }, 10_000)
478
+
479
+ const sock = makeWASocket({ })
480
+ // will listen from this socket
481
+ // the store can listen from a new socket once the current socket outlives its lifetime
482
+ store.bind(sock.ev)
483
+
484
+ sock.ev.on('chats.upsert', () => {
485
+ // can use 'store.chats' however you want, even after the socket dies out
486
+ // 'chats' => a KeyedDB instance
487
+ console.log('got chats', store.chats.all())
488
+ })
489
+
490
+ sock.ev.on('contacts.upsert', () => {
491
+ console.log('got contacts', Object.values(store.contacts))
492
+ })
493
+
494
+ ```
495
+
496
+ The store also provides some simple functions such as `loadMessages` that utilize the store to speed up data retrieval.
497
+
498
+ ## Whatsapp IDs Explain
499
+
500
+ - `id` is the WhatsApp ID, called `jid` too, of the person or group you're sending the message to.
501
+ - It must be in the format ```[country code][phone number]@s.whatsapp.net```
502
+ - Example for people: ```+19999999999@s.whatsapp.net```.
503
+ - For groups, it must be in the format ``` 123456789-123345@g.us ```.
504
+ - For broadcast lists, it's `[timestamp of creation]@broadcast`.
505
+ - For stories, the ID is `status@broadcast`.
506
+
507
+ ## Utility Functions
508
+
509
+ - `getContentType`, returns the content type for any message
510
+ - `getDevice`, returns the device from message
511
+ - `makeCacheableSignalKeyStore`, make auth store more fast
512
+ - `downloadContentFromMessage`, download content from any message
513
+
514
+ ## Sending Messages
515
+
516
+ - Send all types of messages with a single function
517
+ - **[Here](https://baileys.whiskeysockets.io/types/AnyMessageContent.html) you can see all message contents supported, like text message**
518
+ - **[Here](https://baileys.whiskeysockets.io/types/MiscMessageGenerationOptions.html) you can see all options supported, like quote message**
519
+
520
+ ```javascript
521
+ const jid: string
522
+ const content: AnyMessageContent
523
+ const options: MiscMessageGenerationOptions
524
+
525
+ sock.sendMessage(jid, content, options)
526
+ ```
527
+
528
+ ### Non-Media Messages
529
+
530
+ #### Buttons Message
531
+ ```javascript
532
+ // send a buttons message!
533
+ sock.sendMessage(jid, {
534
+ text: "Hello World !",
535
+ footer: "Baileys - 2025",
536
+ buttons: [
537
+ {
538
+ buttonId: `🚀`,
539
+ buttonText: {
540
+ displayText: '🗿'
541
+ },
542
+ type: 1
543
+ }
544
+ ],
545
+ headerType: 1,
546
+ viewOnce: true
547
+ },{ quoted: null })
548
+ ```
549
+
550
+ #### Buttons Flow
551
+ ```javascript
552
+ sock.sendMessage(jid, {
553
+ text: "Hello Wolrd !;",
554
+ footer: "© Baileys Pro",
555
+ buttons: [
556
+ {
557
+ buttonId: '.tes',
558
+ buttonText: {
559
+ displayText: 'TESTING BOT'
560
+ },
561
+ type: 1,
562
+ },
563
+ {
564
+ buttonId: ' ',
565
+ buttonText: {
566
+ displayText: 'PRIVATE SCRIPT'
567
+ },
568
+ type: 1,
569
+ },
570
+ {
571
+ buttonId: 'action',
572
+ buttonText: {
573
+ displayText: 'ini pesan interactiveMeta'
574
+ },
575
+ type: 4,
576
+ nativeFlowInfo: {
577
+ name: 'single_select',
578
+ paramsJson: JSON.stringify({
579
+ title: 'message',
580
+ sections: [
581
+ {
582
+ title: 'Baileys - 2025',
583
+ highlight_label: '😜',
584
+ rows: [
585
+ {
586
+ header: 'HEADER',
587
+ title: 'TITLE',
588
+ description: 'DESCRIPTION',
589
+ id: 'YOUR ID',
590
+ },
591
+ {
592
+ header: 'HEADER',
593
+ title: 'TITLE',
594
+ description: 'DESCRIPTION',
595
+ id: 'YOUR ID',
596
+ },
597
+ ],
598
+ },
599
+ ],
600
+ }),
601
+ },
602
+ },
603
+ ],
604
+ headerType: 1,
605
+ viewOnce: true
606
+ }, { quoted: m });
607
+ ```
608
+
609
+ #### Interactive Message
610
+ ```javascript
611
+ let msg = generateWAMessageFromContent(m.chat, {
612
+ viewOnceMessage: {
613
+ message: {
614
+ "messageContextInfo": {
615
+ "deviceListMetadata": {},
616
+ "deviceListMetadataVersion": 2
617
+ },
618
+ interactiveMessage: proto.Message.InteractiveMessage.create({
619
+ body: proto.Message.InteractiveMessage.Body.create({
620
+ text: "Baileys Pro"
621
+ }),
622
+ footer: proto.Message.InteractiveMessage.Footer.create({
623
+ text: "Bot"
624
+ }),
625
+ header: proto.Message.InteractiveMessage.Header.create({
626
+ title: "Igna",
627
+ subtitle: "test",
628
+ hasMediaAttachment: false
629
+ }),
630
+ nativeFlowMessage: proto.Message.InteractiveMessage.NativeFlowMessage.create({
631
+ buttons: [
632
+ {
633
+ "name": "single_select",
634
+ "buttonParamsJson": "{\"title\":\"title\",\"sections\":[{\".menu\":\".play dj webito\",\"highlight_label\":\"label\",\"rows\":[{\"header\":\"header\",\"title\":\"title\",\"description\":\"description\",\"id\":\"id\"},{\"header\":\"header\",\"title\":\"title\",\"description\":\"description\",\"id\":\"id\"}]}]}"
635
+ },
636
+ {
637
+ "name": "cta_reply",
638
+ "buttonParamsJson": "{\"display_text\":\"quick_reply\",\"id\":\"message\"}"
639
+ },
640
+ {
641
+ "name": "cta_url",
642
+ "buttonParamsJson": "{\"display_text\":\"url\",\"url\":\"https://www.google.com\",\"merchant_url\":\"https://www.google.com\"}"
643
+ },
644
+ {
645
+ "name": "cta_call",
646
+ "buttonParamsJson": "{\"display_text\":\"call\",\"id\":\"message\"}"
647
+ },
648
+ {
649
+ "name": "cta_copy",
650
+ "buttonParamsJson": "{\"display_text\":\"copy\",\"id\":\"123456789\",\"copy_code\":\"message\"}"
651
+ },
652
+ {
653
+ "name": "cta_reminder",
654
+ "buttonParamsJson": "{\"display_text\":\"Recordatorio\",\"id\":\"message\"}"
655
+ },
656
+ {
657
+ "name": "cta_cancel_reminder",
658
+ "buttonParamsJson": "{\"display_text\":\"cta_cancel_reminder\",\"id\":\"message\"}"
659
+ },
660
+ {
661
+ "name": "address_message",
662
+ "buttonParamsJson": "{\"display_text\":\"address_message\",\"id\":\"message\"}"
663
+ },
664
+ {
665
+ "name": "send_location",
666
+ "buttonParamsJson": ""
667
+ }
668
+ ],
669
+ })
670
+ })
671
+ }
672
+ }
673
+ }, {})
674
+
675
+ return sock.relayMessage(msg.key.remoteJid, msg.message, { messageId: msg.key.id })
676
+ ```
677
+
678
+ #### Text Message
679
+ ```javascript
680
+ await sock.sendMessage(jid, { text: 'hello word' })
681
+ ```
682
+
683
+ #### Quote Message (works with all types)
684
+ ```javascript
685
+ await sock.sendMessage(jid, { text: 'hello word' }, { quoted: message })
686
+ ```
687
+
688
+ #### Mention User (works with most types)
689
+ - @number is to mention in text, it's optional
690
+ ```javascript
691
+ await sock.sendMessage(
692
+ jid,
693
+ {
694
+ text: '@12345678901',
695
+ mentions: ['12345678901@s.whatsapp.net']
696
+ }
697
+ )
698
+ ```
699
+
700
+ #### Mention Status
701
+ - [ jid ] If the Jid Group and Jid Private Chat are included in the JID list, try to make the JID group first starting from the Jid Private Chat or Jid Private Chat in the middle between the group Jid
702
+ ```javascript
703
+ await sock.sendStatusMentions(
704
+ {
705
+ text: "Hello", // or image / video / audio ( url or buffer )
706
+ },
707
+ [
708
+ "123456789123456789@g.us",
709
+ "123456789@s.whatsapp.net",
710
+ // Enter jid chat here
711
+ ]
712
+ )
713
+ ```
714
+
715
+ #### Result Poll From Newsletter
716
+ ```javascript
717
+ await sock.sendMessage(
718
+ jid,
719
+ {
720
+ pollResult: {
721
+ name: "Text poll",
722
+ votes: [["Options 1", 10], ["Options 2", 10]], // 10 For Fake Polling Count Results
723
+ }
724
+ }, { quoted : message }
725
+ )
726
+ ```
727
+
728
+ #### Send Album Message
729
+ - url or buffer ( image or video )
730
+ ```javascript
731
+ await sock.sendAlbumMessage(
732
+ jid,
733
+ [
734
+ {
735
+ image: { url: "https://example.jpg" }, // or buffer
736
+ caption: "Hello World",
737
+ },
738
+ {
739
+ video: { url: "https://example.mp4" }, // or buffer
740
+ caption: "Hello World",
741
+ },
742
+ ],
743
+ {
744
+ quoted : message,
745
+ delay : 2000 // number in seconds
746
+ }
747
+ )
748
+
749
+ ```
750
+
751
+ #### List Message
752
+ ```javascript
753
+ const sections = [
754
+ {
755
+ title: "Section 1",
756
+ rows: [
757
+ {title: "Option 1", rowId: "option1"},
758
+ {title: "Option 2", rowId: "option2", description: "This is a description"}
759
+ ]
760
+ },
761
+ {
762
+ title: "Section 2",
763
+ rows: [
764
+ {title: "Option 3", rowId: "option3"},
765
+ {title: "Option 4", rowId: "option4", description: "This is a description V2"}
766
+ ]
767
+ },
768
+ ]
769
+
770
+ const listMessage = {
771
+ text: "This is a list",
772
+ footer: "nice footer, link: https://google.com",
773
+ title: "Amazing boldfaced list title",
774
+ buttonText: "Required, text on the button to view the list",
775
+ sections
776
+ }
777
+
778
+ await sock.sendMessage(jid, listMessage)
779
+ ```
780
+
781
+ #### Carousel Message
782
+ ```javascript
783
+ sock.sendMessage(jid, {
784
+ text: 'hah',
785
+ footer: 'ya',
786
+ cards: [
787
+ {
788
+ title: 'oke',
789
+ image: { url: 'https://example.com/image.jpeg' },
790
+ caption: 'tes'
791
+ },
792
+ {
793
+ title: 'oke',
794
+ image: { url: 'https://example.com/image.jpeg' },
795
+ caption: 'tes'
796
+ }
797
+ ],
798
+ viewOnce: true
799
+ })
800
+ ```
801
+
802
+ #### Interactive Response
803
+ ```javascript
804
+ await sock.sendMessage(
805
+ jid,
806
+ {
807
+ buttonReply: {
808
+ text: 'Text',
809
+ nativeFlow: {
810
+ version: 3,
811
+ },
812
+ },
813
+ type: 'interactive',
814
+ ephemeral: true,
815
+ }
816
+ )
817
+
818
+ ```
819
+
820
+ #### Request Payment
821
+ ```javascript
822
+ - Example non media sticker
823
+ await sock.sendMessage(
824
+ jid,
825
+ {
826
+ requestPayment: {
827
+ currency: "IDR",
828
+ amount: "10000000",
829
+ from: "123456@s.whatsapp.net",
830
+ note: "Hai Guys",
831
+ background: { ...background of the message }
832
+ }
833
+ },
834
+ { quoted : message }
835
+ )
836
+
837
+ - with media sticker buffer
838
+ await sock.sendMessage(
839
+ jid,
840
+ {
841
+ requestPayment: {
842
+ currency: "IDR",
843
+ amount: "10000000",
844
+ from: "123456@s.whatsapp.net",
845
+ sticker: Buffer,
846
+ background: { ...background of the message }
847
+ }
848
+ },
849
+ { quoted : message }
850
+ )
851
+
852
+ - with media sticker url
853
+ await sock.sendMessage(
854
+ jid,
855
+ {
856
+ requestPayment: {
857
+ currency: "IDR",
858
+ amount: "10000000",
859
+ from: "123456@s.whatsapp.net",
860
+ sticker: { url: Sticker Url },
861
+ background: { ...background of the message }
862
+ }
863
+ },
864
+ { quoted : message }
865
+ )
866
+ ```
867
+
868
+ #### Event Message
869
+ ```javascript
870
+ await sock.sendMessage(
871
+ jid,
872
+ {
873
+ event: {
874
+ isCanceled: false, // or true for cancel event
875
+ name: "Name Event",
876
+ description: "Description Event",
877
+ location: {
878
+ degressLatitude: -0,
879
+ degressLongitude: - 0
880
+ },
881
+ link: Call Link,
882
+ startTime: m.messageTimestamp.low,
883
+ endTime: m.messageTimestamp.low + 86400, // 86400 is day in seconds
884
+ extraGuestsAllowed: true // or false
885
+ }
886
+ },
887
+ { quoted : message }
888
+ )
889
+ ```
890
+
891
+ #### Interactive
892
+ ```javascript
893
+ - Example non header media
894
+ await sock.sendMessage(
895
+ jid,
896
+ {
897
+ text: "Description Of Messages", //Additional information
898
+ title: "Title Of Messages",
899
+ subtitle: "Subtitle Message",
900
+ footer: "Footer Messages",
901
+ interactiveButtons: [
902
+ {
903
+ name: "quick_reply",
904
+ buttonParamsJson: JSON.stringify({
905
+ display_text: "Display Button",
906
+ id: "ID"
907
+ })
908
+ },
909
+ {
910
+ name: "cta_url",
911
+ buttonParamsJson: JSON.stringify({
912
+ display_text: "Display Button",
913
+ url: "https://www.example.com"
914
+ })
915
+ }
916
+ ]
917
+ },
918
+ {
919
+ quoted : message
920
+ }
921
+ )
922
+
923
+ // Example with media
924
+ await sock.sendMessage(
925
+ jid,
926
+ {
927
+ image: { url : "https://example.jpg" }, // Can buffer
928
+ caption: "Description Of Messages", //Additional information
929
+ title: "Title Of Messages",
930
+ subtitle: "Subtile Message",
931
+ footer: "Footer Messages",
932
+ media: true,
933
+ interactiveButtons: [
934
+ {
935
+ name: "quick_reply",
936
+ buttonParamsJson: JSON.stringify({
937
+ display_text: "Display Button",
938
+ id: "ID"
939
+ })
940
+ },
941
+ {
942
+ name: "cta_url",
943
+ buttonParamsJson: JSON.stringify({
944
+ display_text: "Display Button",
945
+ url: "https://www.example.com"
946
+ })
947
+ }
948
+ ]
949
+ },
950
+ {
951
+ quoted : message
952
+ }
953
+ )
954
+
955
+ // Example with header product
956
+ await sock.sendMessage(
957
+ jid,
958
+ {
959
+ product: {
960
+ productImage: { url: "https://example.jpg }, //or buffer
961
+ productImageCount: 1,
962
+ title: "Title Product",
963
+ description: "Description Product",
964
+ priceAmount1000: 20000 * 1000,
965
+ currencyCode: "IDR",
966
+ retailerId: "Retail",
967
+ url: "https://example.com",
968
+ },
969
+ businessOwnerJid: "1234@s.whatsapp.net",
970
+ caption: "Description Of Messages", //Additional information
971
+ title: "Title Of Messages",
972
+ footer: "Footer Messages",
973
+ media: true,
974
+ interactiveButtons: [
975
+ {
976
+ name: "quick_reply",
977
+ buttonParamsJson: JSON.stringify({
978
+ display_text: "Display Button",
979
+ id: "ID"
980
+ })
981
+ },
982
+ {
983
+ name: "cta_url",
984
+ buttonParamsJson: JSON.stringify({
985
+ display_text: "Display Button",
986
+ url: "https://www.example.com"
987
+ })
988
+ }
989
+ ]
990
+ },
991
+ {
992
+ quoted : message
993
+ }
994
+ )
995
+ ```
996
+
997
+ #### Forward Messages
998
+ - 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
999
+ ```javascript
1000
+ const msg = getMessageFromStore() // implement this on your end
1001
+ await sock.sendMessage(jid, { forward: msg }) // WA forward the message!
1002
+ ```
1003
+
1004
+ #### Location Message
1005
+ ```javascript
1006
+ await sock.sendMessage(
1007
+ jid,
1008
+ {
1009
+ location: {
1010
+ degreesLatitude: 24.121231,
1011
+ degreesLongitude: 55.1121221
1012
+ }
1013
+ }
1014
+ )
1015
+ ```
1016
+ #### Contact Message
1017
+ ```javascript
1018
+ const vcard = 'BEGIN:VCARD\n' // metadata of the contact card
1019
+ + 'VERSION:3.0\n'
1020
+ + 'FN:Jeff Singh\n' // full name
1021
+ + 'ORG:Ashoka Uni;\n' // the organization of the contact
1022
+ + 'TEL;type=CELL;type=VOICE;waid=911234567890:+91 12345 67890\n' // WhatsApp ID + phone number
1023
+ + 'END:VCARD'
1024
+
1025
+ await sock.sendMessage(
1026
+ id,
1027
+ {
1028
+ contacts: {
1029
+ displayName: 'Jeff',
1030
+ contacts: [{ vcard }]
1031
+ }
1032
+ }
1033
+ )
1034
+ ```
1035
+
1036
+ #### Reaction Message
1037
+ - 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
1038
+ ```javascript
1039
+ await sock.sendMessage(
1040
+ jid,
1041
+ {
1042
+ react: {
1043
+ text: '💖', // use an empty string to remove the reaction
1044
+ key: message.key
1045
+ }
1046
+ }
1047
+ )
1048
+ ```
1049
+
1050
+ #### Pin Message
1051
+ - 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
1052
+
1053
+ - Time can be:
1054
+
1055
+ | Time | Seconds |
1056
+ |-------|----------------|
1057
+ | 24h | 86.400 |
1058
+ | 7d | 604.800 |
1059
+ | 30d | 2.592.000 |
1060
+
1061
+ ```javascript
1062
+ await sock.sendMessage(
1063
+ jid,
1064
+ {
1065
+ pin: {
1066
+ type: 1, // 0 to remove
1067
+ time: 86400
1068
+ key: message.key
1069
+ }
1070
+ }
1071
+ )
1072
+ ```
1073
+
1074
+ #### Poll Message
1075
+ ```javascript
1076
+ await sock.sendMessage(
1077
+ jid,
1078
+ {
1079
+ poll: {
1080
+ name: 'My Poll',
1081
+ values: ['Option 1', 'Option 2', ...],
1082
+ selectableCount: 1,
1083
+ toAnnouncementGroup: false // or true
1084
+ }
1085
+ }
1086
+ )
1087
+ ```
1088
+
1089
+ ### Sending Messages with Link Previews
1090
+
1091
+ 1. By default, wa does not have link generation when sent from the web
1092
+ 2. Baileys has a function to generate the content for these link previews
1093
+ 3. To enable this function's usage, add `link-preview-js` as a dependency to your project with `yarn add link-preview-js`
1094
+ 4. Send a link:
1095
+ ```javascript
1096
+ await sock.sendMessage(
1097
+ jid,
1098
+ {
1099
+ text: 'Hi, this was sent using https://github.com/whiskeysockets/baileys'
1100
+ }
1101
+ )
1102
+ ```
1103
+
1104
+ ### Media Messages
1105
+
1106
+ Sending media (video, stickers, images) is easier & more efficient than ever.
1107
+
1108
+ > [!NOTE]
1109
+ > 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)
1110
+
1111
+ - When specifying a media url, Baileys never loads the entire buffer into memory; it even encrypts the media as a readable stream.
1112
+
1113
+ > [!TIP]
1114
+ > It's recommended to use Stream or Url to save memory
1115
+
1116
+ #### Gif Message
1117
+ - Whatsapp doesn't support `.gif` files, that's why we send gifs as common `.mp4` video with `gifPlayback` flag
1118
+ ```javascript
1119
+ await sock.sendMessage(
1120
+ jid,
1121
+ {
1122
+ video: fs.readFileSync('Media/ma_gif.mp4'),
1123
+ caption: 'hello word',
1124
+ gifPlayback: true
1125
+ }
1126
+ )
1127
+ ```
1128
+
1129
+ #### Video Message
1130
+ ```javascript
1131
+ await sock.sendMessage(
1132
+ id,
1133
+ {
1134
+ video: {
1135
+ url: './Media/ma_gif.mp4'
1136
+ },
1137
+ caption: 'hello word',
1138
+ ptv: false // if set to true, will send as a `video note`
1139
+ }
1140
+ )
1141
+ ```
1142
+
1143
+ #### Audio Message
1144
+ - To audio message work in all devices you need to convert with some tool like `ffmpeg` with this flags:
1145
+ ```bash
1146
+ codec: libopus //ogg file
1147
+ ac: 1 //one channel
1148
+ avoid_negative_ts
1149
+ make_zero
1150
+ ```
1151
+ - Example:
1152
+ ```bash
1153
+ ffmpeg -i input.mp4 -avoid_negative_ts make_zero -ac 1 output.ogg
1154
+ ```
1155
+ ```javascript
1156
+ await sock.sendMessage(
1157
+ jid,
1158
+ {
1159
+ audio: {
1160
+ url: './Media/audio.mp3'
1161
+ },
1162
+ mimetype: 'audio/mp4'
1163
+ }
1164
+ )
1165
+ ```
1166
+
1167
+ #### Image Message
1168
+ ```javascript
1169
+ await sock.sendMessage(
1170
+ id,
1171
+ {
1172
+ image: {
1173
+ url: './Media/ma_img.png'
1174
+ },
1175
+ caption: 'hello word'
1176
+ }
1177
+ )
1178
+ ```
1179
+
1180
+ #### View Once Message
1181
+
1182
+ - You can send all messages above as `viewOnce`, you only need to pass `viewOnce: true` in content object
1183
+
1184
+ ```javascript
1185
+ await sock.sendMessage(
1186
+ id,
1187
+ {
1188
+ image: {
1189
+ url: './Media/ma_img.png'
1190
+ },
1191
+ viewOnce: true, //works with video, audio too
1192
+ caption: 'hello word'
1193
+ }
1194
+ )
1195
+ ```
1196
+
1197
+ ## Modify Messages
1198
+
1199
+ ### Deleting Messages (for everyone)
1200
+
1201
+ ```javascript
1202
+ const msg = await sock.sendMessage(jid, { text: 'hello word' })
1203
+ await sock.sendMessage(jid, { delete: msg.key })
1204
+ ```
1205
+
1206
+ **Note:** deleting for oneself is supported via `chatModify`, see in [this section](#modifying-chats)
1207
+
1208
+ ### Editing Messages
1209
+
1210
+ - You can pass all editable contents here
1211
+ ```javascript
1212
+ await sock.sendMessage(jid, {
1213
+ text: 'updated text goes here',
1214
+ edit: response.key,
1215
+ });
1216
+ ```
1217
+
1218
+ ## Manipulating Media Messages
1219
+
1220
+ ### Thumbnail in Media Messages
1221
+ - 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`.
1222
+ - Thumbnails for videos can also be generated automatically, though, you need to have `ffmpeg` installed on your system.
1223
+
1224
+ ### Downloading Media Messages
1225
+
1226
+ If you want to save the media you received
1227
+ ```javascript
1228
+ const { createWriteStream } = require('fs');
1229
+ const { downloadMediaMessage, getContentType } = require("baileys-pro");
1230
+
1231
+ sock.ev.on('messages.upsert', async ({ [m] }) => {
1232
+ if (!m.message) return // if there is no text or media message
1233
+ const messageType = getContentType(m) // get what type of message it is (text, image, video...)
1234
+
1235
+ // if the message is an image
1236
+ if (messageType === 'imageMessage') {
1237
+ // download the message
1238
+ const stream = await downloadMediaMessage(
1239
+ m,
1240
+ 'stream', // can be 'buffer' too
1241
+ { },
1242
+ {
1243
+ logger,
1244
+ // pass this so that baileys can request a reupload of media
1245
+ // that has been deleted
1246
+ reuploadRequest: sock.updateMediaMessage
1247
+ }
1248
+ )
1249
+ // save to file
1250
+ const writeStream = createWriteStream('./my-download.jpeg')
1251
+ stream.pipe(writeStream)
1252
+ }
1253
+ }
1254
+ ```
1255
+
1256
+ ### Re-upload Media Message to Whatsapp
1257
+
1258
+ - 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:
1259
+ ```javascript
1260
+ await sock.updateMediaMessage(msg)
1261
+ ```
1262
+
1263
+ ## Reject Call
1264
+
1265
+ - You can obtain `callId` and `callFrom` from `call` event
1266
+
1267
+ ```javascript
1268
+ await sock.rejectCall(callId, callFrom)
1269
+ ```
1270
+
1271
+ ## Send States in Chat
1272
+
1273
+ ### Reading Messages
1274
+ - A set of message [keys](https://baileys.whiskeysockets.io/types/WAMessageKey.html) must be explicitly marked read now.
1275
+ - You cannot mark an entire 'chat' read as it were with Baileys Web.
1276
+ This means you have to keep track of unread messages.
1277
+
1278
+ ```javascript
1279
+ const key: WAMessageKey
1280
+ // can pass multiple keys to read multiple messages as well
1281
+ await sock.readMessages([key])
1282
+ ```
1283
+
1284
+ The message ID is the unique identifier of the message that you are marking as read.
1285
+ On a `WAMessage`, the `messageID` can be accessed using ```messageID = message.key.id```.
1286
+
1287
+ ### Update Presence
1288
+
1289
+ - ``` presence ``` can be one of [these](https://baileys.whiskeysockets.io/types/WAPresence.html)
1290
+ - The presence expires after about 10 seconds.
1291
+ - This lets the person/group with `jid` know whether you're online, offline, typing etc.
1292
+
1293
+ ```javascript
1294
+ await sock.sendPresenceUpdate('available', jid)
1295
+ ```
1296
+
1297
+ > [!NOTE]
1298
+ > 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')`
1299
+
1300
+ ## Modifying Chats
1301
+
1302
+ WA uses an encrypted form of communication to send chat/app updates. This has been implemented mostly and you can send the following updates:
1303
+
1304
+ > [!IMPORTANT]
1305
+ > 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.
1306
+
1307
+ ### Archive a Chat
1308
+ ```javascript
1309
+ const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
1310
+ await sock.chatModify({ archive: true, lastMessages: [lastMsgInChat] }, jid)
1311
+ ```
1312
+ ### Mute/Unmute a Chat
1313
+
1314
+ - Supported times:
1315
+
1316
+ | Time | Miliseconds |
1317
+ |-------|-----------------|
1318
+ | Remove | null |
1319
+ | 8h | 86.400.000 |
1320
+ | 7d | 604.800.000 |
1321
+
1322
+ ```javascript
1323
+ // mute for 8 hours
1324
+ await sock.chatModify({ mute: 8 * 60 * 60 * 1000 }, jid)
1325
+ // unmute
1326
+ await sock.chatModify({ mute: null }, jid)
1327
+ ```
1328
+ ### Mark a Chat Read/Unread
1329
+ ```javascript
1330
+ const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
1331
+ // mark it unread
1332
+ await sock.chatModify({ markRead: false, lastMessages: [lastMsgInChat] }, jid)
1333
+ ```
1334
+
1335
+ ### Delete a Message for Me
1336
+ ```javascript
1337
+ await sock.chatModify(
1338
+ {
1339
+ clear: {
1340
+ messages: [
1341
+ {
1342
+ id: 'ATWYHDNNWU81732J',
1343
+ fromMe: true,
1344
+ timestamp: '1654823909'
1345
+ }
1346
+ ]
1347
+ }
1348
+ },
1349
+ jid
1350
+ )
1351
+
1352
+ ```
1353
+ ### Delete a Chat
1354
+ ```javascript
1355
+ const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
1356
+ await sock.chatModify({
1357
+ delete: true,
1358
+ lastMessages: [
1359
+ {
1360
+ key: lastMsgInChat.key,
1361
+ messageTimestamp: lastMsgInChat.messageTimestamp
1362
+ }
1363
+ ]
1364
+ },
1365
+ jid
1366
+ )
1367
+ ```
1368
+ ### Pin/Unpin a Chat
1369
+ ```javascript
1370
+ await sock.chatModify({
1371
+ pin: true // or `false` to unpin
1372
+ },
1373
+ jid
1374
+ )
1375
+ ```
1376
+ ### Star/Unstar a Message
1377
+ ```javascript
1378
+ await sock.chatModify({
1379
+ star: {
1380
+ messages: [
1381
+ {
1382
+ id: 'messageID',
1383
+ fromMe: true // or `false`
1384
+ }
1385
+ ],
1386
+ star: true // - true: Star Message; false: Unstar Message
1387
+ }
1388
+ },
1389
+ jid
1390
+ )
1391
+ ```
1392
+
1393
+ ### Disappearing Messages
1394
+
1395
+ - Ephemeral can be:
1396
+
1397
+ | Time | Seconds |
1398
+ |-------|----------------|
1399
+ | Remove | 0 |
1400
+ | 24h | 86.400 |
1401
+ | 7d | 604.800 |
1402
+ | 90d | 7.776.000 |
1403
+
1404
+ - You need to pass in **Seconds**, default is 7 days
1405
+
1406
+ ```javascript
1407
+ // turn on disappearing messages
1408
+ await sock.sendMessage(
1409
+ jid,
1410
+ // this is 1 week in seconds -- how long you want messages to appear for
1411
+ { disappearingMessagesInChat: WA_DEFAULT_EPHEMERAL }
1412
+ )
1413
+
1414
+ // will send as a disappearing message
1415
+ await sock.sendMessage(jid, { text: 'hello' }, { ephemeralExpiration: WA_DEFAULT_EPHEMERAL })
1416
+
1417
+ // turn off disappearing messages
1418
+ await sock.sendMessage(
1419
+ jid,
1420
+ { disappearingMessagesInChat: false }
1421
+ )
1422
+ ```
1423
+
1424
+ ## User Querys
1425
+
1426
+ ### Check If ID Exists in Whatsapp
1427
+ ```javascript
1428
+ const [result] = await sock.onWhatsApp(jid)
1429
+ if (result.exists) console.log (`${jid} exists on WhatsApp, as jid: ${result.jid}`)
1430
+ ```
1431
+
1432
+ ### Query Chat History (groups too)
1433
+
1434
+ - You need to have oldest message in chat
1435
+ ```javascript
1436
+ const msg = await getOldestMessageInChat(jid)
1437
+ await sock.fetchMessageHistory(
1438
+ 50, //quantity (max: 50 per query)
1439
+ msg.key,
1440
+ msg.messageTimestamp
1441
+ )
1442
+ ```
1443
+ - Messages will be received in `messaging.history-set` event
1444
+
1445
+ ### Fetch Status
1446
+ ```javascript
1447
+ const status = await sock.fetchStatus(jid)
1448
+ console.log('status: ' + status)
1449
+ ```
1450
+
1451
+ ### Fetch Profile Picture (groups too)
1452
+ - To get the display picture of some person/group
1453
+ ```javascript
1454
+ // for low res picture
1455
+ const ppUrl = await sock.profilePictureUrl(jid)
1456
+ console.log(ppUrl)
1457
+
1458
+ // for high res picture
1459
+ const ppUrl = await sock.profilePictureUrl(jid, 'image')
1460
+ ```
1461
+
1462
+ ### Fetch Bussines Profile (such as description or category)
1463
+ ```javascript
1464
+ const profile = await sock.getBusinessProfile(jid)
1465
+ console.log('business description: ' + profile.description + ', category: ' + profile.category)
1466
+ ```
1467
+
1468
+ ### Fetch Someone's Presence (if they're typing or online)
1469
+ ```javascript
1470
+ // the presence update is fetched and called here
1471
+ sock.ev.on('presence.update', console.log)
1472
+
1473
+ // request updates for a chat
1474
+ await sock.presenceSubscribe(jid)
1475
+ ```
1476
+
1477
+ ## Change Profile
1478
+
1479
+ ### Change Profile Status
1480
+ ```javascript
1481
+ await sock.updateProfileStatus('Hello World!')
1482
+ ```
1483
+ ### Change Profile Name
1484
+ ```javascript
1485
+ await sock.updateProfileName('My name')
1486
+ ```
1487
+ ### Change Display Picture (groups too)
1488
+ - To change your display picture or a group's
1489
+
1490
+ > [!NOTE]
1491
+ > 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)
1492
+
1493
+ ```javascript
1494
+ await sock.updateProfilePicture(jid, { url: './new-profile-picture.jpeg' })
1495
+ ```
1496
+ ### Remove display picture (groups too)
1497
+ ```javascript
1498
+ await sock.removeProfilePicture(jid)
1499
+ ```
1500
+
1501
+ ## Groups
1502
+
1503
+ - To change group properties you need to be admin
1504
+
1505
+ ### Create a Group
1506
+ ```javascript
1507
+ // title & participants
1508
+ const group = await sock.groupCreate('My Fab Group', ['1234@s.whatsapp.net', '4564@s.whatsapp.net'])
1509
+ console.log('created group with id: ' + group.gid)
1510
+ await sock.sendMessage(group.id, { text: 'hello there' }) // say hello to everyone on the group
1511
+ ```
1512
+ ### Add/Remove or Demote/Promote
1513
+ ```javascript
1514
+ // id & people to add to the group (will throw error if it fails)
1515
+ await sock.groupParticipantsUpdate(
1516
+ jid,
1517
+ ['abcd@s.whatsapp.net', 'efgh@s.whatsapp.net'],
1518
+ 'add' // replace this parameter with 'remove' or 'demote' or 'promote'
1519
+ )
1520
+ ```
1521
+ ### Change Subject (name)
1522
+ ```javascript
1523
+ await sock.groupUpdateSubject(jid, 'New Subject!')
1524
+ ```
1525
+ ### Change Description
1526
+ ```javascript
1527
+ await sock.groupUpdateDescription(jid, 'New Description!')
1528
+ ```
1529
+ ### Change Settings
1530
+ ```javascript
1531
+ // only allow admins to send messages
1532
+ await sock.groupSettingUpdate(jid, 'announcement')
1533
+ // allow everyone to send messages
1534
+ await sock.groupSettingUpdate(jid, 'not_announcement')
1535
+ // allow everyone to modify the group's settings -- like display picture etc.
1536
+ await sock.groupSettingUpdate(jid, 'unlocked')
1537
+ // only allow admins to modify the group's settings
1538
+ await sock.groupSettingUpdate(jid, 'locked')
1539
+ ```
1540
+ ### Leave a Group
1541
+ ```javascript
1542
+ // will throw error if it fails
1543
+ await sock.groupLeave(jid)
1544
+ ```
1545
+ ### Get Invite Code
1546
+ - To create link with code use `'https://chat.whatsapp.com/' + code`
1547
+ ```javascript
1548
+ const code = await sock.groupInviteCode(jid)
1549
+ console.log('group code: ' + code)
1550
+ ```
1551
+ ### Revoke Invite Code
1552
+ ```javascript
1553
+ const code = await sock.groupRevokeInvite(jid)
1554
+ console.log('New group code: ' + code)
1555
+ ```
1556
+ ### Join Using Invitation Code
1557
+ - Code can't have `https://chat.whatsapp.com/`, only code
1558
+ ```javascript
1559
+ const response = await sock.groupAcceptInvite(code)
1560
+ console.log('joined to: ' + response)
1561
+ ```
1562
+ ### Get Group Info by Invite Code
1563
+ ```javascript
1564
+ const response = await sock.groupGetInviteInfo(code)
1565
+ console.log('group information: ' + response)
1566
+ ```
1567
+ ### Query Metadata (participants, name, description...)
1568
+ ```javascript
1569
+ const metadata = await sock.groupMetadata(jid)
1570
+ console.log(metadata.id + ', title: ' + metadata.subject + ', description: ' + metadata.desc)
1571
+ ```
1572
+ ### Join using `groupInviteMessage`
1573
+ ```javascript
1574
+ const response = await sock.groupAcceptInviteV4(jid, groupInviteMessage)
1575
+ console.log('joined to: ' + response)
1576
+ ```
1577
+ ### Get Request Join List
1578
+ ```javascript
1579
+ const response = await sock.groupRequestParticipantsList(jid)
1580
+ console.log(response)
1581
+ ```
1582
+ ### Approve/Reject Request Join
1583
+ ```javascript
1584
+ const response = await sock.groupRequestParticipantsUpdate(
1585
+ jid, // group id
1586
+ ['abcd@s.whatsapp.net', 'efgh@s.whatsapp.net'],
1587
+ 'approve' // or 'reject'
1588
+ )
1589
+ console.log(response)
1590
+ ```
1591
+ ### Get All Participating Groups Metadata
1592
+ ```javascript
1593
+ const response = await sock.groupFetchAllParticipating()
1594
+ console.log(response)
1595
+ ```
1596
+ ### Toggle Ephemeral
1597
+
1598
+ - Ephemeral can be:
1599
+
1600
+ | Time | Seconds |
1601
+ |-------|----------------|
1602
+ | Remove | 0 |
1603
+ | 24h | 86.400 |
1604
+ | 7d | 604.800 |
1605
+ | 90d | 7.776.000 |
1606
+
1607
+ ```javascript
1608
+ await sock.groupToggleEphemeral(jid, 86400)
1609
+ ```
1610
+
1611
+ ### Change Add Mode
1612
+ ```javascript
1613
+ await sock.groupMemberAddMode(
1614
+ jid,
1615
+ 'all_member_add' // or 'admin_add'
1616
+ )
1617
+ ```
1618
+
1619
+ ## Newsletter
1620
+
1621
+ - To perform most actions you must be the newsletter creator or admin
1622
+
1623
+ ### Subscribe to Newsletter Updates
1624
+ ```javascript
1625
+ await sock.subscribeNewsletterUpdates(jid)
1626
+ ```
1627
+
1628
+ ### Update Reaction Mode
1629
+ ```javascript
1630
+ await sock.newsletterReactionMode(jid, mode) // e.g., 'enabled', 'disabled'
1631
+ ```
1632
+
1633
+ ### Update Newsletter Description
1634
+ ```javascript
1635
+ await sock.newsletterUpdateDescription(jid, 'Your new description')
1636
+ ```
1637
+
1638
+ ### Update Newsletter Name
1639
+ ```javascript
1640
+ await sock.newsletterUpdateName(jid, 'New Name')
1641
+ ```
1642
+
1643
+ ### Update Newsletter Picture
1644
+ ```javascript
1645
+ await sock.newsletterUpdatePicture(jid, content)
1646
+ ```
1647
+
1648
+ ### Remove Newsletter Picture
1649
+ ```javascript
1650
+ await sock.newsletterRemovePicture(jid)
1651
+ ```
1652
+
1653
+ ### Follow a Newsletter
1654
+ ```javascript
1655
+ await sock.newsletterFollow(jid)
1656
+ ```
1657
+
1658
+ ### Unfollow a Newsletter
1659
+ ```javascript
1660
+ await sock.newsletterUnfollow(jid)
1661
+ ```
1662
+
1663
+ ### Mute a Newsletter
1664
+ ```javascript
1665
+ await sock.newsletterMute(jid)
1666
+ ```
1667
+
1668
+ ### Unmute a Newsletter
1669
+ ```javascript
1670
+ await sock.newsletterUnmute(jid)
1671
+ ```
1672
+
1673
+ ### Perform a Newsletter Action (Generic)
1674
+ ```javascript
1675
+ await sock.newsletterAction(jid, 'mute' | 'unmute' | 'follow' | 'unfollow')
1676
+ ```
1677
+
1678
+ ### Create a Newsletter
1679
+ ```javascript
1680
+ const newsletter = await sock.newsletterCreate('Newsletter Name', 'Newsletter Description')
1681
+ console.log(newsletter)
1682
+ ```
1683
+
1684
+ ### Fetch Newsletter Metadata
1685
+ ```javascript
1686
+ // https://whatsapp.com/channel/$key
1687
+ const metadata = await sock.newsletterMetadata(type, key, role) // type: 'invite' or 'direct', role: 'GUEST', etc.
1688
+ ```
1689
+
1690
+ ### Get Admin Count
1691
+ ```javascript
1692
+ const count = await sock.newsletterAdminCount(jid)
1693
+ ```
1694
+
1695
+ ### Change Newsletter Owner
1696
+ ```javascript
1697
+ /**user is Lid, not Jid */
1698
+ await sock.newsletterChangeOwner(jid, userLid)
1699
+ ```
1700
+
1701
+ ### Demote Newsletter Admin
1702
+ ```javascript
1703
+ /**user is Lid, not Jid */
1704
+ await sock.newsletterDemote(jid, userLid)
1705
+ ```
1706
+
1707
+ ### Delete Newsletter
1708
+ ```javascript
1709
+ await sock.newsletterDelete(jid)
1710
+ ```
1711
+
1712
+ ### React to a Message in Newsletter
1713
+ ```javascript
1714
+ // Copying the message link in the Newsletter will get
1715
+ // https://whatsapp.com/channel/XXXXXXXXX/$serverId
1716
+
1717
+ await sock.newsletterReactMessage(jid, serverId, '❤️')
1718
+ // pass null or empty to remove reaction
1719
+ ```
1720
+
1721
+ ### Fetch Messages in Newsletter
1722
+ ```javascript
1723
+ const messages = await sock.newsletterFetchMessages('direct' | 'invite', key, count, after)
1724
+ ```
1725
+
1726
+ ### Fetch Updates in Newsletter
1727
+ ```javascript
1728
+ const updates = await sock.newsletterFetchUpdates(jid, count, after, since)
1729
+ ```
1730
+
1731
+ ## Privacy
1732
+
1733
+ ### Block/Unblock User
1734
+ ```javascript
1735
+ await sock.updateBlockStatus(jid, 'block') // Block user
1736
+ await sock.updateBlockStatus(jid, 'unblock') // Unblock user
1737
+ ```
1738
+ ### Get Privacy Settings
1739
+ ```javascript
1740
+ const privacySettings = await sock.fetchPrivacySettings(true)
1741
+ console.log('privacy settings: ' + privacySettings)
1742
+ ```
1743
+ ### Get BlockList
1744
+ ```javascript
1745
+ const response = await sock.fetchBlocklist()
1746
+ console.log(response)
1747
+ ```
1748
+ ### Update LastSeen Privacy
1749
+ ```javascript
1750
+ const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
1751
+ await sock.updateLastSeenPrivacy(value)
1752
+ ```
1753
+ ### Update Online Privacy
1754
+ ```javascript
1755
+ const value = 'all' // 'match_last_seen'
1756
+ await sock.updateOnlinePrivacy(value)
1757
+ ```
1758
+ ### Update Profile Picture Privacy
1759
+ ```javascript
1760
+ const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
1761
+ await sock.updateProfilePicturePrivacy(value)
1762
+ ```
1763
+ ### Update Status Privacy
1764
+ ```javascript
1765
+ const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
1766
+ await sock.updateStatusPrivacy(value)
1767
+ ```
1768
+ ### Update Read Receipts Privacy
1769
+ ```javascript
1770
+ const value = 'all' // 'none'
1771
+ await sock.updateReadReceiptsPrivacy(value)
1772
+ ```
1773
+ ### Update Groups Add Privacy
1774
+ ```javascript
1775
+ const value = 'all' // 'contacts' | 'contact_blacklist'
1776
+ await sock.updateGroupsAddPrivacy(value)
1777
+ ```
1778
+ ### Update Default Disappearing Mode
1779
+
1780
+ - Like [this](#disappearing-messages), ephemeral can be:
1781
+
1782
+ | Time | Seconds |
1783
+ |-------|----------------|
1784
+ | Remove | 0 |
1785
+ | 24h | 86.400 |
1786
+ | 7d | 604.800 |
1787
+ | 90d | 7.776.000 |
1788
+
1789
+ ```javascript
1790
+ const ephemeral = 86400
1791
+ await sock.updateDefaultDisappearingMode(ephemeral)
1792
+ ```
1793
+
1794
+ ## Broadcast Lists & Stories
1795
+
1796
+ ### Send Broadcast & Stories
1797
+ - Messages can be sent to broadcasts & stories. You need to add the following message options in sendMessage, like this:
1798
+ ```javascript
1799
+ await sock.sendMessage(
1800
+ jid,
1801
+ {
1802
+ image: {
1803
+ url: url
1804
+ },
1805
+ caption: caption
1806
+ },
1807
+ {
1808
+ backgroundColor: backgroundColor,
1809
+ font: font,
1810
+ statusJidList: statusJidList,
1811
+ broadcast: true
1812
+ }
1813
+ )
1814
+ ```
1815
+ - Message body can be a `extendedTextMessage` or `imageMessage` or `videoMessage` or `voiceMessage`, see [here](https://baileys.whiskeysockets.io/types/AnyRegularMessageContent.html)
1816
+ - You can add `backgroundColor` and other options in the message options, see [here](https://baileys.whiskeysockets.io/types/MiscMessageGenerationOptions.html)
1817
+ - `broadcast: true` enables broadcast mode
1818
+ - `statusJidList`: a list of people that you can get which you need to provide, which are the people who will get this status message.
1819
+
1820
+ - You can send messages to broadcast lists the same way you send messages to groups & individual chats.
1821
+ - Right now, WA Web does not support creating broadcast lists, but you can still delete them.
1822
+ - Broadcast IDs are in the format `12345678@broadcast`
1823
+ ### Query a Broadcast List's Recipients & Name
1824
+ ```javascript
1825
+ const bList = await sock.getBroadcastListInfo('1234@broadcast')
1826
+ console.log (`list name: ${bList.name}, recps: ${bList.recipients}`)
1827
+ ```
1828
+
1829
+ ## Writing Custom Functionality
1830
+ Baileys is written with custom functionality in mind. Instead of forking the project & re-writing the internals, you can simply write your own extensions.
1831
+
1832
+ ### Enabling Debug Level in Baileys Logs
1833
+ First, enable the logging of unhandled messages from WhatsApp by setting:
1834
+ ```javascript
1835
+ const sock = makeWASocket({
1836
+ logger: P({ level: 'debug' }),
1837
+ })
1838
+ ```
1839
+ This will enable you to see all sorts of messages WhatsApp sends in the console.
1840
+
1841
+ ### How Whatsapp Communicate With Us
1842
+
1843
+ > [!TIP]
1844
+ > If you want to learn whatsapp protocol, we recommend to study about Libsignal Protocol and Noise Protocol
1845
+
1846
+ - **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:
1847
+ ```json
1848
+ {
1849
+ "level": 10,
1850
+ "fromMe": false,
1851
+ "frame": {
1852
+ "tag": "ib",
1853
+ "attrs": {
1854
+ "from": "@s.whatsapp.net"
1855
+ },
1856
+ "content": [
1857
+ {
1858
+ "tag": "edge_routing",
1859
+ "attrs": {},
1860
+ "content": [
1861
+ {
1862
+ "tag": "routing_info",
1863
+ "attrs": {},
1864
+ "content": {
1865
+ "type": "Buffer",
1866
+ "data": [8,2,8,5]
1867
+ }
1868
+ }
1869
+ ]
1870
+ }
1871
+ ]
1872
+ },
1873
+ "msg":"communication"
1874
+ }
1875
+ ```
1876
+
1877
+ The `'frame'` is what the message received is, it has three components:
1878
+ - `tag` -- what this frame is about (eg. message will have 'message')
1879
+ - `attrs` -- a string key-value pair with some metadata (contains ID of the message usually)
1880
+ - `content` -- the actual data (eg. a message node will have the actual message content in it)
1881
+ - read more about this format [here](/src/WABinary/readme.md)
1882
+
1883
+ ### Register a Callback for Websocket Events
1884
+
1885
+ > [!TIP]
1886
+ > Recommended to see `onMessageReceived` function in `socket.ts` file to understand how websockets events are fired
1887
+
1888
+ ```javascript
1889
+ // for any message with tag 'edge_routing'
1890
+ sock.ws.on('CB:edge_routing', (node: BinaryNode) => { })
1891
+
1892
+ // for any message with tag 'edge_routing' and id attribute = abcd
1893
+ sock.ws.on('CB:edge_routing,id:abcd', (node: BinaryNode) => { })
1894
+
1895
+ // for any message with tag 'edge_routing', id attribute = abcd & first content node routing_info
1896
+ sock.ws.on('CB:edge_routing,id:abcd,routing_info', (node: BinaryNode) => { })
1897
+ ```
1898
+
1899
+ > [!NOTE]
1900
+ > Also, this repo is now licenced under GPL 3 since it uses [libsignal-node](https://git.questbook.io/backend/service-coderunner/-/merge_requests/1)