@nexustechpro/baileys 2.0.1 → 2.0.5

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 (102) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +924 -1299
  3. package/lib/Defaults/baileys-version.json +6 -2
  4. package/lib/Defaults/index.js +172 -172
  5. package/lib/Signal/libsignal.js +380 -292
  6. package/lib/Signal/lid-mapping.js +264 -171
  7. package/lib/Socket/Client/index.js +2 -2
  8. package/lib/Socket/Client/types.js +10 -10
  9. package/lib/Socket/Client/websocket.js +45 -310
  10. package/lib/Socket/business.js +375 -375
  11. package/lib/Socket/chats.js +909 -963
  12. package/lib/Socket/communities.js +430 -430
  13. package/lib/Socket/groups.js +342 -342
  14. package/lib/Socket/index.js +22 -22
  15. package/lib/Socket/messages-recv.js +777 -743
  16. package/lib/Socket/messages-send.js +667 -393
  17. package/lib/Socket/mex.js +50 -50
  18. package/lib/Socket/newsletter.js +148 -148
  19. package/lib/Socket/nexus-handler.js +75 -261
  20. package/lib/Socket/socket.js +709 -1201
  21. package/lib/Store/index.js +5 -5
  22. package/lib/Store/make-cache-manager-store.js +81 -81
  23. package/lib/Store/make-in-memory-store.js +416 -416
  24. package/lib/Store/make-ordered-dictionary.js +81 -81
  25. package/lib/Store/object-repository.js +30 -30
  26. package/lib/Types/Auth.js +1 -1
  27. package/lib/Types/Bussines.js +1 -1
  28. package/lib/Types/Call.js +1 -1
  29. package/lib/Types/Chat.js +7 -7
  30. package/lib/Types/Contact.js +1 -1
  31. package/lib/Types/Events.js +1 -1
  32. package/lib/Types/GroupMetadata.js +1 -1
  33. package/lib/Types/Label.js +24 -24
  34. package/lib/Types/LabelAssociation.js +6 -6
  35. package/lib/Types/Message.js +10 -10
  36. package/lib/Types/Newsletter.js +28 -28
  37. package/lib/Types/Product.js +1 -1
  38. package/lib/Types/Signal.js +1 -1
  39. package/lib/Types/Socket.js +2 -2
  40. package/lib/Types/State.js +12 -12
  41. package/lib/Types/USync.js +1 -1
  42. package/lib/Types/index.js +25 -25
  43. package/lib/Utils/auth-utils.js +264 -256
  44. package/lib/Utils/baileys-event-stream.js +55 -55
  45. package/lib/Utils/browser-utils.js +27 -27
  46. package/lib/Utils/business.js +228 -230
  47. package/lib/Utils/chat-utils.js +694 -764
  48. package/lib/Utils/crypto.js +109 -135
  49. package/lib/Utils/decode-wa-message.js +310 -314
  50. package/lib/Utils/event-buffer.js +547 -547
  51. package/lib/Utils/generics.js +297 -297
  52. package/lib/Utils/history.js +91 -83
  53. package/lib/Utils/index.js +21 -20
  54. package/lib/Utils/key-store.js +17 -0
  55. package/lib/Utils/link-preview.js +97 -88
  56. package/lib/Utils/logger.js +2 -2
  57. package/lib/Utils/lt-hash.js +47 -47
  58. package/lib/Utils/make-mutex.js +39 -39
  59. package/lib/Utils/message-retry-manager.js +148 -148
  60. package/lib/Utils/messages-media.js +534 -532
  61. package/lib/Utils/messages.js +705 -705
  62. package/lib/Utils/noise-handler.js +255 -255
  63. package/lib/Utils/pre-key-manager.js +105 -105
  64. package/lib/Utils/process-message.js +412 -412
  65. package/lib/Utils/signal.js +160 -158
  66. package/lib/Utils/use-multi-file-auth-state.js +120 -120
  67. package/lib/Utils/validate-connection.js +194 -194
  68. package/lib/WABinary/constants.js +1300 -1300
  69. package/lib/WABinary/decode.js +237 -237
  70. package/lib/WABinary/encode.js +232 -232
  71. package/lib/WABinary/generic-utils.js +252 -211
  72. package/lib/WABinary/index.js +5 -5
  73. package/lib/WABinary/jid-utils.js +279 -95
  74. package/lib/WABinary/types.js +1 -1
  75. package/lib/WAM/BinaryInfo.js +9 -9
  76. package/lib/WAM/constants.js +22852 -22852
  77. package/lib/WAM/encode.js +149 -149
  78. package/lib/WAM/index.js +3 -3
  79. package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -28
  80. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -53
  81. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -26
  82. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -37
  83. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -50
  84. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -28
  85. package/lib/WAUSync/Protocols/index.js +4 -4
  86. package/lib/WAUSync/USyncQuery.js +93 -93
  87. package/lib/WAUSync/USyncUser.js +22 -22
  88. package/lib/WAUSync/index.js +3 -3
  89. package/lib/index.js +66 -66
  90. package/package.json +171 -144
  91. package/lib/Signal/Group/ciphertext-message.js +0 -12
  92. package/lib/Signal/Group/group-session-builder.js +0 -30
  93. package/lib/Signal/Group/group_cipher.js +0 -100
  94. package/lib/Signal/Group/index.js +0 -12
  95. package/lib/Signal/Group/keyhelper.js +0 -18
  96. package/lib/Signal/Group/sender-chain-key.js +0 -26
  97. package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
  98. package/lib/Signal/Group/sender-key-message.js +0 -66
  99. package/lib/Signal/Group/sender-key-name.js +0 -48
  100. package/lib/Signal/Group/sender-key-record.js +0 -41
  101. package/lib/Signal/Group/sender-key-state.js +0 -84
  102. package/lib/Signal/Group/sender-message-key.js +0 -26
package/README.md CHANGED
@@ -1,104 +1,82 @@
1
- # 🚀 NexusTechPro Baileys
2
-
3
1
  <div align="center">
4
-
5
- ![NexusTechPro Banner](https://files.catbox.moe/1rjzor.jpeg)
6
-
7
- **Advanced WhatsApp Web API Built on WhiskeySockets/Baileys**
8
-
9
- [![NPM Version](https://img.shields.io/npm/v/@nexustechpro/baileys?color=success&logo=npm)](https://www.npmjs.com/package/@nexustechpro/baileys)
10
- [![Downloads](https://img.shields.io/npm/dt/@nexustechpro/baileys?color=blue&logo=npm)](https://www.npmjs.com/package/@nexustechpro/baileys)
11
- [![License](https://img.shields.io/github/license/nexustechpro/baileys?color=yellow)](./LICENSE)
12
- [![Node Version](https://img.shields.io/node/v/@nexustechpro/baileys)](https://nodejs.org)
13
-
14
- *Modern, feature-rich, and developer-friendly WhatsApp automation library*
15
-
16
- </div>
17
-
18
- ---
19
2
 
20
- ## 📋 Table of Contents
3
+ ![NexusTechPro Banner](https://files.catbox.moe/1rjzor.jpeg)
21
4
 
22
- - [✨ Features](#-features)
23
- - [📦 Installation](#-installation)
24
- - [🔌 Quick Start](#-quick-start)
25
- - [🔐 Authentication](#-authentication)
26
- - [💡 Socket Configuration](#-socket-configuration)
27
- - [💾 Session Management](#-session-management)
28
- - [📡 Event Handling](#-event-handling)
29
- - [🛠️ Data Store](#️-data-store)
30
- - [🔑 WhatsApp IDs](#-whatsapp-ids)
31
- - [💬 Sending Messages](#-sending-messages)
32
- - [Text & Special Messages](#text--special-messages)
33
- - [Media Messages](#media-messages)
34
- - [Buttons & Interactive Messages](#buttons--interactive-messages)
35
- - [✏️ Message Modifications](#️-message-modifications)
36
- - [📥 Media Operations](#-media-operations)
37
- - [👥 Group Management](#-group-management)
38
- - [📱 User Operations](#-user-operations)
39
- - [🔒 Privacy Controls](#-privacy-controls)
40
- - [💬 Chat Operations](#-chat-operations)
41
- - [📢 Broadcast & Stories](#-broadcast--stories)
42
- - [🧩 Advanced Features](#-advanced-features)
5
+ # @nexustechpro/baileys
43
6
 
44
- ---
7
+ **Advanced WhatsApp Web API — Built on WhiskeySockets/Baileys**
45
8
 
46
- ## ✨ Features
9
+ [![NPM Version](https://img.shields.io/npm/v/@nexustechpro/baileys?color=success&logo=npm&style=flat-square)](https://www.npmjs.com/package/@nexustechpro/baileys)
10
+ [![Downloads](https://img.shields.io/npm/dt/@nexustechpro/baileys?color=blue&logo=npm&style=flat-square)](https://www.npmjs.com/package/@nexustechpro/baileys)
11
+ [![License](https://img.shields.io/npm/l/@nexustechpro/baileys?color=yellow&style=flat-square)](https://github.com/nexustechpro2/baileys/blob/main/LICENSE)
12
+ [![Node Version](https://img.shields.io/node/v/@nexustechpro/baileys?style=flat-square)](https://nodejs.org)
13
+ [![Socket Badge](https://socket.dev/api/badge/npm/package/@nexustechpro/baileys)](https://socket.dev/npm/package/@nexustechpro/baileys)
47
14
 
48
- <table>
49
- <tr>
50
- <td>
15
+ *Modern, feature-rich, and developer-friendly WhatsApp automation library*
51
16
 
52
- ### Core Features
53
- - 🔥 **Multi-Device Support** - Connect without phone always online
54
- - ⚡ **WebSocket Based** - Fast and efficient communication
55
- - 💾 **Session Management** - Save and restore authentication
56
- - 🎯 **Event-Driven** - Reactive message handling
57
- - 📦 **TypeScript Ready** - Full type definitions included
58
- - 🚀 **Built on WhiskeySockets** - Latest Baileys implementation
17
+ </div>
59
18
 
60
- </td>
61
- <td>
19
+ ---
62
20
 
63
- ### Extended Features
64
- - 🎨 **Universal Button System** - Auto-converts any button format
65
- - 📸 **Media Handling** - Images, videos, audio, documents
66
- - 🤖 **Poll Support** - Create and manage polls
67
- - 📍 **Location Sharing** - Share locations with metadata
68
- - 🔔 **Newsletter Support** - Manage WhatsApp channels
69
- - 🎪 **Carousel Messages** - Multi-card interactive displays
21
+ ## 📋 Table of Contents
70
22
 
71
- </td>
72
- </tr>
73
- </table>
23
+ - [Installation](#-installation)
24
+ - [Quick Start](#-quick-start)
25
+ - [Authentication](#-authentication)
26
+ - [Browser Options](#-browser-options)
27
+ - [Socket Configuration](#-socket-configuration)
28
+ - [Session Management](#-session-management)
29
+ - [Sending Messages](#-sending-messages)
30
+ - [Text Messages](#text-messages)
31
+ - [Media Messages](#media-messages)
32
+ - [Buttons & Interactive](#buttons--interactive-messages)
33
+ - [Extended Types](#extended-message-types)
34
+ - [Status & Stories](#personal-status--story-statusbroadcast)
35
+ - [Sticker Pack](#sticker-pack)
36
+ - [Shorthand Wrappers](#shorthand-wrappers)
37
+ - [Message Modifications](#️-message-modifications)
38
+ - [Media Download](#-media-download)
39
+ - [Group Management](#-group-management)
40
+ - [User Operations](#-user-operations)
41
+ - [Privacy Controls](#-privacy-controls)
42
+ - [Chat Operations](#-chat-operations)
43
+ - [Newsletter / Channels](#-newsletter--channels)
44
+ - [Events Reference](#-events-reference)
45
+ - [Best Practices](#-best-practices)
46
+ - [Disclaimer](#️-disclaimer)
74
47
 
75
48
  ---
76
49
 
77
50
  ## 📦 Installation
78
51
 
79
- ### NPM
80
52
  ```bash
53
+ # npm
81
54
  npm install @nexustechpro/baileys
82
- ```
83
55
 
84
- ### Yarn
85
- ```bash
56
+ # yarn
86
57
  yarn add @nexustechpro/baileys
87
58
  ```
88
59
 
89
- ### Using Different Package Name
90
- Add to your `package.json`:
60
+ **Drop-in replacement for `@whiskeysockets/baileys`** — add this to `package.json`:
91
61
  ```json
92
62
  {
93
63
  "dependencies": {
94
64
  "@whiskeysockets/baileys": "npm:@nexustechpro/baileys"
95
65
  }
96
66
  }
67
+
68
+ // OR
69
+
70
+ {
71
+ "dependencies": {
72
+ "@nexustechpro/baileys": "latest"
73
+ }
74
+ }
97
75
  ```
98
76
 
99
- ### Import
77
+ **Import:**
100
78
  ```javascript
101
- // ESM
79
+ // ESM (recommended)
102
80
  import makeWASocket from '@nexustechpro/baileys'
103
81
 
104
82
  // CommonJS
@@ -107,42 +85,49 @@ const { default: makeWASocket } = require('@nexustechpro/baileys')
107
85
 
108
86
  ---
109
87
 
110
- ## 🔌 Quick Start
88
+ ## 🚀 Quick Start
89
+
111
90
  ```javascript
112
- import makeWASocket, { DisconnectReason, useMultiFileAuthState } from '@nexustechpro/baileys'
113
-
114
- async function connectToWhatsApp() {
115
- const { state, saveCreds } = await useMultiFileAuthState('auth_session')
116
-
117
- const sock = makeWASocket({
118
- auth: state,
119
- printQRInTerminal: true,
120
- browser: ['NexusTechPro', 'Chrome', '1.0.0']
121
- })
122
-
123
- sock.ev.on('connection.update', (update) => {
124
- const { connection, lastDisconnect } = update
125
- if(connection === 'close') {
126
- const shouldReconnect = lastDisconnect?.error?.output?.statusCode !== DisconnectReason.loggedOut
127
- if(shouldReconnect) {
128
- connectToWhatsApp()
129
- }
130
- } else if(connection === 'open') {
131
- console.log('✅ Connected to WhatsApp!')
132
- }
133
- })
134
-
135
- sock.ev.on('messages.upsert', async ({ messages }) => {
136
- for(const msg of messages) {
137
- if(!msg.key.fromMe && msg.message) {
138
- await sock.sendMessage(msg.key.remoteJid, {
139
- text: 'Hello from NexusTechPro Baileys!'
140
- })
141
- }
142
- }
143
- })
91
+ import makeWASocket, {
92
+ useMultiFileAuthState,
93
+ DisconnectReason,
94
+ makeCacheableSignalKeyStore,
95
+ Browsers
96
+ } from '@nexustechpro/baileys'
97
+ import pino from 'pino'
98
+
99
+ const connectToWhatsApp = async () => {
100
+ const { state, saveCreds } = await useMultiFileAuthState('auth_session')
101
+ const logger = pino({ level: 'silent' })
102
+
103
+ const sock = makeWASocket({
104
+ auth: {
105
+ creds: state.creds,
106
+ keys: makeCacheableSignalKeyStore(state.keys, logger)
107
+ },
108
+ browser: Browsers.ubuntu('Chrome'),
109
+ generateHighQualityLinkPreview: true,
110
+ logger
111
+ })
112
+
113
+ sock.ev.on('connection.update', ({ connection, lastDisconnect }) => {
114
+ if (connection === 'close') {
115
+ const shouldReconnect = lastDisconnect?.error?.output?.statusCode !== DisconnectReason.loggedOut
116
+ if (shouldReconnect) connectToWhatsApp()
117
+ } else if (connection === 'open') {
118
+ console.log(' Connected!')
119
+ }
120
+ })
144
121
 
145
- sock.ev.on('creds.update', saveCreds)
122
+ sock.ev.on('creds.update', saveCreds)
123
+
124
+ sock.ev.on('messages.upsert', async ({ messages }) => {
125
+ for (const msg of messages) {
126
+ if (!msg.key.fromMe && msg.message) {
127
+ await sock.sendMessage(msg.key.remoteJid, { text: 'Hello!' })
128
+ }
129
+ }
130
+ })
146
131
  }
147
132
 
148
133
  connectToWhatsApp()
@@ -152,1030 +137,943 @@ connectToWhatsApp()
152
137
 
153
138
  ## 🔐 Authentication
154
139
 
155
- ### QR Code Authentication
156
- ```javascript
157
- import makeWASocket from '@nexustechpro/baileys'
140
+ ### Pairing Code (Recommended)
158
141
 
159
- const sock = makeWASocket({
160
- auth: state,
161
- printQRInTerminal: true,
162
- browser: ['NexusTechPro Bot', 'Chrome', '1.0.0']
163
- })
164
- ```
142
+ No QR scanning — just a phone number. Call `requestPairingCode` directly after creating the socket. The socket internally waits for the WebSocket to be ready before sending the request, so **no manual polling or delays needed on your end**.
165
143
 
166
- ### Pairing Code Authentication
167
144
  ```javascript
145
+ import makeWASocket, {
146
+ useMultiFileAuthState,
147
+ makeCacheableSignalKeyStore,
148
+ Browsers
149
+ } from '@nexustechpro/baileys'
150
+ import pino from 'pino'
151
+
152
+ const { state, saveCreds } = await useMultiFileAuthState('auth_session')
153
+ const logger = pino({ level: 'silent' })
154
+
168
155
  const sock = makeWASocket({
169
- auth: state,
170
- printQRInTerminal: false
156
+ auth: {
157
+ creds: state.creds,
158
+ keys: makeCacheableSignalKeyStore(state.keys, logger)
159
+ },
160
+ browser: Browsers.ubuntu('Chrome'),
161
+ logger
171
162
  })
172
163
 
173
- if(!sock.authState.creds.registered) {
174
- const phoneNumber = '1234567890' // without + or spaces
175
- const code = await sock.requestPairingCode(phoneNumber)
176
- console.log(`Pairing code: ${code}`)
164
+ sock.ev.on('creds.update', saveCreds)
165
+
166
+ // Just call it — no need to wait or poll for WS state
167
+ if (!sock.authState.creds.registered) {
168
+ const code = await sock.requestPairingCode('1234567890') // digits only, no + or spaces
169
+ console.log('Pairing code:', code)
177
170
  }
178
171
  ```
179
172
 
180
173
  ### Custom Pairing Code
174
+
181
175
  ```javascript
182
- const phoneNumber = "628XXXXX"
183
- const code = await sock.requestPairingCode(phoneNumber.trim(), "NEXUS01")
184
- console.log("Your pairing code: " + code)
176
+ // Must be exactly 8 characters
177
+ const code = await sock.requestPairingCode('1234567890', 'NEXUS001')
178
+ console.log('Custom code:', code)
185
179
  ```
186
180
 
187
- ---
181
+ ### QR Code
188
182
 
189
- ## 💡 Socket Configuration
183
+ Scan the QR with your WhatsApp mobile app under **Linked Devices**.
190
184
 
191
- ### Cache Group Metadata (Recommended)
192
185
  ```javascript
193
- const groupCache = new NodeCache({ stdTTL: 5 * 60, useClones: false })
186
+ import makeWASocket, {
187
+ useMultiFileAuthState,
188
+ makeCacheableSignalKeyStore,
189
+ Browsers
190
+ } from '@nexustechpro/baileys'
191
+ import qrcode from 'qrcode-terminal'
192
+ import pino from 'pino'
193
+
194
+ const { state, saveCreds } = await useMultiFileAuthState('auth_session')
195
+ const logger = pino({ level: 'silent' })
194
196
 
195
197
  const sock = makeWASocket({
196
- cachedGroupMetadata: async (jid) => groupCache.get(jid)
198
+ auth: {
199
+ creds: state.creds,
200
+ keys: makeCacheableSignalKeyStore(state.keys, logger)
201
+ },
202
+ browser: Browsers.ubuntu('Chrome'),
203
+ logger
197
204
  })
198
205
 
199
- sock.ev.on('groups.update', async ([event]) => {
200
- const metadata = await sock.groupMetadata(event.id)
201
- groupCache.set(event.id, metadata)
206
+ sock.ev.on('connection.update', ({ connection, qr, lastDisconnect }) => {
207
+ if (qr) qrcode.generate(qr, { small: true })
208
+ if (connection === 'open') console.log('✅ Connected!')
209
+ if (connection === 'close') {
210
+ const shouldReconnect = lastDisconnect?.error?.output?.statusCode !== DisconnectReason.loggedOut
211
+ if (shouldReconnect) connectToWhatsApp()
212
+ }
202
213
  })
203
- ```
204
214
 
205
- ### Improve Retry & Poll Decryption
206
- ```javascript
207
- const sock = makeWASocket({
208
- getMessage: async (key) => await getMessageFromStore(key)
209
- })
215
+ sock.ev.on('creds.update', saveCreds)
210
216
  ```
211
217
 
212
- ### Receive Notifications in WhatsApp App
213
- ```javascript
214
- const sock = makeWASocket({
215
- markOnlineOnConnect: false
216
- })
217
- ```
218
+ Install the QR renderer: `npm install qrcode-terminal`
218
219
 
219
220
  ---
220
221
 
221
- ## 💾 Session Management
222
+ ## 🌐 Browser Options
222
223
 
223
- Avoid scanning QR every time:
224
- ```javascript
225
- import makeWASocket, { useMultiFileAuthState } from '@nexustechpro/baileys'
224
+ The `browser` config tells WhatsApp what client you appear to be. This affects how WhatsApp treats your session and which features it enables.
226
225
 
227
- const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
228
- const sock = makeWASocket({ auth: state })
226
+ | Option | Value | Notes |
227
+ |--------|-------|-------|
228
+ | `Browsers.ubuntu('Chrome')` | `['Ubuntu', 'Chrome', '22.04.4']` | ✅ Recommended — stable, widely used |
229
+ | `Browsers.macOS('Safari')` | `['Mac OS', 'Safari', '14.4.1']` | Good alternative |
230
+ | `Browsers.windows('Chrome')` | `['Windows', 'Chrome', '10.0.22631']` | Works well |
231
+ | `Browsers.baileys('Desktop')` | `['Baileys', 'Desktop', '6.5.0']` | Identifies as Baileys explicitly |
232
+ | `Browsers.appropriate('Chrome')` | Auto-detects your OS | Uses your actual platform |
229
233
 
230
- sock.ev.on('creds.update', saveCreds)
231
- ```
234
+ ```javascript
235
+ import { Browsers } from '@nexustechpro/baileys'
232
236
 
233
- > 💡 **Tip:** For production, store auth in a database instead of files.
237
+ // Pass any browser string as the second argument (Chrome, Safari, Firefox, etc.)
238
+ const sock = makeWASocket({
239
+ browser: Browsers.ubuntu('Chrome') // recommended
240
+ // browser: Browsers.macOS('Safari')
241
+ // browser: Browsers.windows('Chrome')
242
+ // browser: Browsers.appropriate('Chrome') // auto-detects your server OS
243
+ })
244
+ ```
234
245
 
235
246
  ---
236
247
 
237
- ## 📡 Event Handling
248
+ ## ⚙️ Socket Configuration
238
249
 
239
- ### Connection Updates
240
- ```javascript
241
- sock.ev.on('connection.update', (update) => {
242
- const { connection, lastDisconnect } = update
243
- if(connection === 'close') {
244
- const shouldReconnect = lastDisconnect?.error?.output?.statusCode !== DisconnectReason.loggedOut
245
- console.log('Connection closed, reconnecting:', shouldReconnect)
246
- if(shouldReconnect) connectToWhatsApp()
247
- } else if(connection === 'open') {
248
- console.log('Connection opened')
249
- }
250
- })
251
- ```
250
+ Key options from `DEFAULT_CONNECTION_CONFIG`:
252
251
 
253
- ### New Messages
254
252
  ```javascript
255
- sock.ev.on('messages.upsert', async ({ messages }) => {
256
- for(const msg of messages) {
257
- console.log('New message:', msg)
258
- }
259
- })
260
- ```
253
+ const sock = makeWASocket({
254
+ // Required
255
+ auth: { creds, keys },
261
256
 
262
- ### Message Updates
263
- ```javascript
264
- sock.ev.on('messages.update', async (updates) => {
265
- for(const update of updates) {
266
- console.log('Message updated:', update)
267
- }
268
- })
269
- ```
257
+ // Browser identity
258
+ browser: Browsers.ubuntu('Chrome'),
270
259
 
271
- ### Decrypt Poll Votes
272
- ```javascript
273
- sock.ev.on('messages.update', async (event) => {
274
- for(const { key, update } of event) {
275
- if(update.pollUpdates) {
276
- const pollCreation = await getMessage(key)
277
- if(pollCreation) {
278
- console.log('Poll update:', getAggregateVotesInPollMessage({
279
- message: pollCreation,
280
- pollUpdates: update.pollUpdates,
281
- }))
282
- }
283
- }
284
- }
285
- })
286
- ```
260
+ // Link preview quality (true = upload full image, false = compressed local thumb)
261
+ generateHighQualityLinkPreview: true,
287
262
 
288
- ---
263
+ // Cache group metadata to avoid repeated fetches
264
+ cachedGroupMetadata: async (jid) => groupCache.get(jid),
289
265
 
290
- ## 🛠️ Data Store
291
- ```javascript
292
- import makeWASocket, { makeInMemoryStore } from '@nexustechpro/baileys'
266
+ // Suppress your online status when connecting
267
+ markOnlineOnConnect: false,
293
268
 
294
- const store = makeInMemoryStore({})
295
- store.readFromFile('./baileys_store.json')
269
+ // Sync full message history on connect
270
+ syncFullHistory: false,
296
271
 
297
- setInterval(() => {
298
- store.writeToFile('./baileys_store.json')
299
- }, 10_000)
272
+ // Logger (use pino({ level: 'silent' }) to suppress logs)
273
+ logger: pino({ level: 'silent' }),
300
274
 
301
- const sock = makeWASocket({})
302
- store.bind(sock.ev)
275
+ // Connection timeout in ms
276
+ connectTimeoutMs: 60000,
303
277
 
304
- sock.ev.on('chats.upsert', () => {
305
- console.log('Got chats:', store.chats.all())
306
- })
278
+ // Max retries for failed message sends
279
+ maxMsgRetryCount: 5,
307
280
 
308
- sock.ev.on('contacts.upsert', () => {
309
- console.log('Got contacts:', Object.values(store.contacts))
281
+ // Custom message retrieval for retry/poll decryption
282
+ getMessage: async (key) => store.loadMessage(key.remoteJid, key.id),
310
283
  })
311
284
  ```
312
285
 
313
- > ⚠️ **Important:** Build your own data store for production. In-memory storage wastes RAM.
314
-
315
286
  ---
316
287
 
317
- ## 🔑 WhatsApp IDs
288
+ ## 💾 Session Management
289
+
290
+ ```javascript
291
+ import { useMultiFileAuthState } from '@nexustechpro/baileys'
292
+
293
+ const { state, saveCreds } = await useMultiFileAuthState('auth_session')
294
+ const sock = makeWASocket({ auth: state })
295
+
296
+ sock.ev.on('creds.update', saveCreds)
297
+ ```
318
298
 
319
- - **Personal Chats**: `[country code][phone number]@s.whatsapp.net`
320
- - Example: `1234567890@s.whatsapp.net`
321
- - **Groups**: `[group id]@g.us`
322
- - Example: `123456789-987654321@g.us`
323
- - **Broadcast Lists**: `[timestamp]@broadcast`
324
- - **Status**: `status@broadcast`
299
+ > 💡 For production, store credentials in a database (MongoDB, Redis, PostgreSQL) rather than the filesystem. The `useMultiFileAuthState` helper is for development only.
325
300
 
326
301
  ---
327
302
 
328
303
  ## 💬 Sending Messages
329
304
 
330
- ### Text & Special Messages
305
+ `sock.sendMessage(jid, content, options?)` handles **every message type**. The `jid` can be a user, group, status broadcast, or newsletter.
331
306
 
332
- #### Text Message
333
307
  ```javascript
334
- await sock.sendMessage(jid, { text: 'Hello World!' })
308
+ // JID formats
309
+ '1234567890@s.whatsapp.net' // personal chat
310
+ '123456789-987654321@g.us' // group
311
+ 'status@broadcast' // story/status
312
+ '120363...@newsletter' // newsletter channel
335
313
  ```
336
314
 
337
- #### Quote Message (works with all types)
315
+ ### Text Messages
316
+
338
317
  ```javascript
318
+ // Plain text
319
+ await sock.sendMessage(jid, { text: 'Hello World!' })
320
+
321
+ // With link preview (auto-detects URLs in text)
322
+ await sock.sendMessage(jid, { text: 'Check this out: https://github.com' })
323
+
324
+ // Quote/reply
339
325
  await sock.sendMessage(jid, { text: 'This is a reply' }, { quoted: message })
340
- ```
341
326
 
342
- #### Mention User (works with most types)
343
- ```javascript
327
+ // Mention users
344
328
  await sock.sendMessage(jid, {
345
- text: '@12345678901',
346
- mentions: ['12345678901@s.whatsapp.net']
329
+ text: '@1234567890 hey!',
330
+ mentions: ['1234567890@s.whatsapp.net']
347
331
  })
348
- ```
349
332
 
350
- #### Mention Status
351
- ```javascript
352
- await sock.sendStatusMentions(
353
- {
354
- text: "Hello", // or image / video / audio (url or buffer)
355
- },
356
- [
357
- "123456789123456789@g.us",
358
- "123456789@s.whatsapp.net",
359
- // Enter jid chat here
360
- ]
361
- )
333
+ // AI-generated label
334
+ await sock.sendMessage(jid, { text: 'AI response here', ai: true })
362
335
  ```
363
336
 
364
- #### Result Poll From Newsletter
365
- ```javascript
366
- await sock.sendMessage(jid, {
367
- pollResult: {
368
- name: "Text poll",
369
- votes: [["Options 1", 10], ["Options 2", 10]], // 10 for fake polling count results
370
- }
371
- }, { quoted: message })
372
- ```
337
+ ### Media Messages
373
338
 
374
- #### Send Album Message
375
- ```javascript
376
- await sock.sendAlbumMessage(
377
- jid,
378
- [
379
- {
380
- image: { url: "https://example.jpg" }, // or buffer
381
- caption: "Hello World",
382
- },
383
- {
384
- video: { url: "https://example.mp4" }, // or buffer
385
- caption: "Hello World",
386
- },
387
- ],
388
- {
389
- quoted: message,
390
- delay: 2000 // number in milliseconds
391
- }
392
- )
393
- ```
339
+ > You can pass `{ url: '...' }`, a `Buffer`, a file path string, or `{ stream: Stream }` for any media type.
394
340
 
395
- #### Request Payment
341
+ #### Image
396
342
  ```javascript
397
- // Example non media sticker
343
+ // From URL
398
344
  await sock.sendMessage(jid, {
399
- requestPayment: {
400
- currency: "IDR",
401
- amount: "10000000",
402
- from: "123456@s.whatsapp.net",
403
- note: "Payment Request",
404
- background: { /* background of the message */ }
405
- }
406
- }, { quoted: message })
345
+ image: { url: 'https://example.com/image.jpg' },
346
+ caption: 'Caption here'
347
+ })
407
348
 
408
- // With media sticker buffer
409
- await sock.sendMessage(jid, {
410
- requestPayment: {
411
- currency: "IDR",
412
- amount: "10000000",
413
- from: "123456@s.whatsapp.net",
414
- sticker: buffer,
415
- background: { /* background of the message */ }
416
- }
417
- }, { quoted: message })
349
+ // From Buffer
350
+ await sock.sendMessage(jid, { image: buffer, caption: 'From buffer' })
418
351
 
419
- // With media sticker url
420
- await sock.sendMessage(jid, {
421
- requestPayment: {
422
- currency: "IDR",
423
- amount: "10000000",
424
- from: "123456@s.whatsapp.net",
425
- sticker: { url: "https://example.com/sticker.webp" },
426
- background: { /* background of the message */ }
427
- }
428
- }, { quoted: message })
352
+ // From file
353
+ await sock.sendMessage(jid, { image: fs.readFileSync('./image.jpg') })
354
+
355
+ // View once
356
+ await sock.sendMessage(jid, { image: { url: './secret.jpg' }, viewOnce: true })
429
357
  ```
430
358
 
431
- #### Event Message
359
+ #### Video
432
360
  ```javascript
433
- await sock.sendMessage(jid, {
434
- event: {
435
- isCanceled: false, // or true for cancel event
436
- name: "Event Name",
437
- description: "Event Description",
438
- location: {
439
- degreesLatitude: -0,
440
- degreesLongitude: -0
441
- },
442
- link: "https://call-link.example.com",
443
- startTime: m.messageTimestamp.low,
444
- endTime: m.messageTimestamp.low + 86400, // 86400 is day in seconds
445
- extraGuestsAllowed: true // or false
446
- }
447
- }, { quoted: message })
361
+ await sock.sendMessage(jid, {
362
+ video: { url: './video.mp4' },
363
+ caption: 'Watch this!',
364
+ gifPlayback: false, // true for GIF
365
+ ptv: false // true for video note (circle)
366
+ })
448
367
  ```
449
368
 
450
- #### Product Message
369
+ #### Audio
451
370
  ```javascript
452
371
  await sock.sendMessage(jid, {
453
- productMessage: {
454
- title: "Product Title",
455
- description: "Product Description",
456
- thumbnail: "https://example.png",
457
- productId: "123456789",
458
- retailerId: "STORE",
459
- url: "https://example.png",
460
- body: "Product Body",
461
- footer: "Product Footer",
462
- buttons: [
463
- {
464
- name: "cta_url",
465
- buttonParamsJson: JSON.stringify({
466
- display_text: "Visit Site",
467
- url: "https://example.com"
468
- })
469
- }
470
- ]
471
- }
472
- }, { quoted: message })
372
+ audio: { url: './audio.mp3' },
373
+ mimetype: 'audio/mp4',
374
+ ptt: true // true = voice message, false = audio file
375
+ })
473
376
  ```
474
377
 
475
- #### Carousel Message
378
+ > Convert to voice-compatible format: `ffmpeg -i input.mp4 -avoid_negative_ts make_zero -ac 1 output.ogg`
379
+
380
+ #### Document
476
381
  ```javascript
477
382
  await sock.sendMessage(jid, {
478
- carouselMessage: {
479
- caption: "Click URL",
480
- footer: "Powered By NexusTechPro",
481
- cards: [
482
- // Card Mode Product
483
- {
484
- headerTitle: "`</> Owner Bot </>`",
485
- imageUrl: "https://example.com/image.jpg",
486
- productTitle: "Premium Bot",
487
- productDescription: "Get premium access",
488
- bodyText: "[NexusTechPro]\n- Important chat only\n- Don't call owner",
489
- buttons: [
490
- {
491
- name: "cta_call",
492
- params: {
493
- display_text: "Contact Owner",
494
- phone_number: "+1234567890"
495
- }
496
- }
497
- ]
498
- },
499
- // Card Mode Image
500
- {
501
- headerTitle: "`</> Bot Assistant </>`",
502
- imageUrl: "https://example.com/image2.jpg",
503
- bodyText: "[AI Assistant]\n- Don't spam bot\n- Don't call bot",
504
- buttons: [
505
- {
506
- name: "cta_url",
507
- params: {
508
- display_text: "Chat Bot",
509
- url: "https://wa.me/1234567890",
510
- merchant_url: "https://wa.me/1234567890"
511
- }
512
- }
513
- ]
514
- }
515
- ]
516
- }
517
- }, { quoted: message })
383
+ document: { url: './file.pdf' },
384
+ fileName: 'document.pdf',
385
+ mimetype: 'application/pdf',
386
+ caption: 'Here is the file'
387
+ })
518
388
  ```
519
389
 
520
- #### Forward Messages
390
+ #### Sticker
521
391
  ```javascript
522
- const msg = getMessageFromStore() // implement this on your end
523
- await sock.sendMessage(jid, { forward: msg })
392
+ await sock.sendMessage(jid, { sticker: { url: './sticker.webp' } })
524
393
  ```
525
394
 
526
- #### Location Message
395
+ #### Location
527
396
  ```javascript
528
397
  await sock.sendMessage(jid, {
529
- location: {
530
- degreesLatitude: 24.121231,
531
- degreesLongitude: 55.1121221,
532
- name: "Location Name",
533
- address: "Location Address"
534
- }
398
+ location: {
399
+ degreesLatitude: 24.121231,
400
+ degreesLongitude: 55.1121221,
401
+ name: 'Location Name',
402
+ address: 'Full Address Here'
403
+ }
535
404
  })
536
405
  ```
537
406
 
538
- #### Contact Message
407
+ #### Contact
539
408
  ```javascript
540
- const vcard = 'BEGIN:VCARD\n'
541
- + 'VERSION:3.0\n'
542
- + 'FN:John Doe\n'
543
- + 'ORG:NexusTechPro;\n'
544
- + 'TEL;type=CELL;type=VOICE;waid=1234567890:+1 234 567 890\n'
545
- + 'END:VCARD'
409
+ const vcard = 'BEGIN:VCARD\nVERSION:3.0\nFN:John Doe\nORG:NexusTechPro;\nTEL;type=CELL;waid=1234567890:+1 234 567 890\nEND:VCARD'
546
410
 
547
411
  await sock.sendMessage(jid, {
548
- contacts: {
549
- displayName: 'John Doe',
550
- contacts: [{ vcard }]
551
- }
412
+ contacts: {
413
+ displayName: 'John Doe',
414
+ contacts: [{ vcard }]
415
+ }
552
416
  })
553
417
  ```
554
418
 
555
- #### Reaction Message
419
+ #### Reaction
556
420
  ```javascript
557
421
  await sock.sendMessage(jid, {
558
- react: {
559
- text: '💖', // use empty string to remove reaction
560
- key: message.key
561
- }
422
+ react: {
423
+ text: '💖', // empty string removes reaction
424
+ key: message.key
425
+ }
562
426
  })
563
427
  ```
564
428
 
565
- #### Pin Message
429
+ #### Poll
566
430
  ```javascript
567
431
  await sock.sendMessage(jid, {
568
- pin: {
569
- type: 1, // 0 to remove
570
- time: 86400, // 24 hours in seconds
571
- key: message.key
572
- }
432
+ poll: {
433
+ name: 'Favorite Color?',
434
+ values: ['Red', 'Blue', 'Green'],
435
+ selectableOptionsCount: 1,
436
+ toAnnouncementGroup: false
437
+ }
573
438
  })
574
439
  ```
575
440
 
576
- **Pin Time Options:**
577
-
578
- | Time | Seconds |
579
- |------|-----------|
580
- | 24h | 86,400 |
581
- | 7d | 604,800 |
582
- | 30d | 2,592,000 |
441
+ #### Pin Message
442
+ ```javascript
443
+ await sock.sendMessage(jid, {
444
+ pin: {
445
+ type: 1, // 0 to unpin
446
+ time: 86400, // 24h = 86400 | 7d = 604800 | 30d = 2592000
447
+ key: message.key
448
+ }
449
+ })
450
+ ```
583
451
 
584
452
  #### Keep Message
585
453
  ```javascript
586
454
  await sock.sendMessage(jid, {
587
- keep: message.key,
588
- type: 1, // 2 to unpin
589
- time: 86400
455
+ keep: message.key,
456
+ type: 1, // 2 to unkeep
457
+ time: 86400
590
458
  })
591
459
  ```
592
460
 
593
- **Keep Time Options:**
461
+ #### Disappearing Messages
462
+ ```javascript
463
+ // Enable (seconds: 86400 = 24h, 604800 = 7d, 7776000 = 90d)
464
+ await sock.sendMessage(jid, { disappearingMessagesInChat: 86400 })
594
465
 
595
- | Time | Seconds |
596
- |------|-----------|
597
- | 24h | 86,400 |
598
- | 7d | 604,800 |
599
- | 30d | 2,592,000 |
466
+ // Disable
467
+ await sock.sendMessage(jid, { disappearingMessagesInChat: false })
468
+ ```
600
469
 
601
- #### Poll Message
470
+ #### Forward Message
602
471
  ```javascript
603
- await sock.sendMessage(jid, {
604
- poll: {
605
- name: 'Favorite Color?',
606
- values: ['Red', 'Blue', 'Green', 'Yellow'],
607
- selectableCount: 1,
608
- toAnnouncementGroup: false
609
- }
610
- })
472
+ await sock.sendMessage(jid, { forward: message, force: true })
611
473
  ```
612
474
 
613
- #### Link Preview
475
+ #### Edit Message
614
476
  ```javascript
615
477
  await sock.sendMessage(jid, {
616
- text: 'Check out https://github.com/nexustechpro1/baileys'
478
+ text: 'Updated text',
479
+ edit: originalMessage.key
617
480
  })
618
481
  ```
619
482
 
483
+ #### Delete Message
484
+ ```javascript
485
+ const sent = await sock.sendMessage(jid, { text: 'hello' })
486
+ await sock.sendMessage(jid, { delete: sent.key })
487
+ ```
488
+
620
489
  ---
621
490
 
622
- ### Media Messages
491
+ ### 🎭 Fake Quoted Messages
623
492
 
624
- > 📝 **Note:** You can pass `{ stream: Stream }`, `{ url: Url }`, or `Buffer` directly
493
+ Fake a reply without an actual original message useful for AI responses, status reposts, custom UIs and more. Only the bare minimum fields are needed — WhatsApp fills in the rest visually.
625
494
 
626
- #### Image Message
495
+ #### Text Quote
627
496
  ```javascript
628
- // From URL
629
- await sock.sendMessage(jid, {
630
- image: { url: 'https://example.com/image.jpg' },
631
- caption: 'Beautiful image!'
632
- })
633
-
634
- // From Buffer
635
- await sock.sendMessage(jid, {
636
- image: buffer,
637
- caption: 'Image from buffer'
497
+ await sock.sendMessage(jid, { text: 'Actual message' }, {
498
+ quoted: {
499
+ key: { remoteJid: jid, fromMe: false, id: 'FAKE_' + Date.now(), participant: '1234567890@s.whatsapp.net' },
500
+ message: { conversation: 'Fake quoted text' }
501
+ }
638
502
  })
503
+ ```
639
504
 
640
- // From File
641
- await sock.sendMessage(jid, {
642
- image: fs.readFileSync('./image.jpg'),
643
- caption: 'Local image'
505
+ #### Image Quote
506
+ ```javascript
507
+ await sock.sendMessage(jid, { text: 'Replying to image' }, {
508
+ quoted: {
509
+ key: { remoteJid: jid, fromMe: false, id: 'FAKE_' + Date.now(), participant: '1234567890@s.whatsapp.net' },
510
+ message: { imageMessage: { caption: 'Fake image caption' } }
511
+ }
644
512
  })
645
513
  ```
646
514
 
647
- #### Video Message
515
+ #### Sticker Quote
648
516
  ```javascript
649
- await sock.sendMessage(jid, {
650
- video: { url: './video.mp4' },
651
- caption: 'Check this out!',
652
- gifPlayback: false, // set true for GIF
653
- ptv: false // set true for video note
517
+ await sock.sendMessage(jid, { text: 'Replying to sticker' }, {
518
+ quoted: {
519
+ key: { remoteJid: jid, fromMe: false, id: 'FAKE_' + Date.now(), participant: '1234567890@s.whatsapp.net' },
520
+ message: { stickerMessage: {} }
521
+ }
654
522
  })
655
523
  ```
656
524
 
657
- #### GIF Message
525
+ #### AI / Bot Quote
658
526
  ```javascript
659
- await sock.sendMessage(jid, {
660
- video: fs.readFileSync('Media/gif.mp4'),
661
- caption: 'Funny GIF',
662
- gifPlayback: true
527
+ await sock.sendMessage(jid, { text: 'My response' }, {
528
+ quoted: {
529
+ key: { remoteJid: jid, fromMe: true, id: 'FAKE_' + Date.now() },
530
+ message: { extendedTextMessage: { text: 'AI generated this', title: 'NexusAI' } }
531
+ }
663
532
  })
664
533
  ```
665
534
 
666
- #### Audio Message
535
+ #### Status Quote
667
536
  ```javascript
668
- await sock.sendMessage(jid, {
669
- audio: { url: './audio.mp3' },
670
- mimetype: 'audio/mp4',
671
- ptt: true // voice message
537
+ await sock.sendMessage(jid, { text: 'Replying to your status!' }, {
538
+ quoted: {
539
+ key: { remoteJid: 'status@broadcast', fromMe: false, id: 'FAKE_' + Date.now(), participant: '1234567890@s.whatsapp.net' },
540
+ message: { conversation: 'Original status text' }
541
+ }
672
542
  })
673
543
  ```
674
544
 
675
- > 💡 **Audio Conversion Tip:**
676
- > ```bash
677
- > ffmpeg -i input.mp4 -avoid_negative_ts make_zero -ac 1 output.ogg
678
- > ```
545
+ #### Key Fields
679
546
 
680
- #### Document
547
+ | Field | Description |
548
+ |-------|-------------|
549
+ | `remoteJid` | Where the quoted message appears to be from (`jid`, `status@broadcast`, group etc.) |
550
+ | `fromMe` | `true` = appears sent by you/bot, `false` = appears sent by someone else |
551
+ | `id` | Any unique string — `'FAKE_' + Date.now()` avoids collisions |
552
+ | `participant` | Required in groups/status — the person who appears to have sent it |
553
+
554
+ ---
555
+
556
+ ### Buttons & Interactive Messages
557
+
558
+ #### Text with Buttons
681
559
  ```javascript
682
560
  await sock.sendMessage(jid, {
683
- document: { url: './document.pdf' },
684
- fileName: 'document.pdf',
685
- mimetype: 'application/pdf'
561
+ text: 'Choose an option',
562
+ footer: '© NexusTechPro',
563
+ buttons: [
564
+ {
565
+ name: 'quick_reply',
566
+ buttonParamsJson: JSON.stringify({ display_text: 'Option 1', id: 'opt1' })
567
+ },
568
+ {
569
+ name: 'cta_url',
570
+ buttonParamsJson: JSON.stringify({
571
+ display_text: 'Visit Website',
572
+ url: 'https://nexustechpro.com',
573
+ merchant_url: 'https://nexustechpro.com'
574
+ })
575
+ }
576
+ ]
686
577
  })
687
578
  ```
688
579
 
689
- #### Sticker
580
+ #### Image / Video / Document with Buttons
690
581
  ```javascript
691
582
  await sock.sendMessage(jid, {
692
- sticker: { url: './sticker.webp' }
583
+ image: { url: 'https://example.com/image.jpg' },
584
+ caption: 'Description',
585
+ footer: '© NexusTechPro',
586
+ buttons: [
587
+ {
588
+ name: 'quick_reply',
589
+ buttonParamsJson: JSON.stringify({ display_text: 'Reply', id: 'btn1' })
590
+ }
591
+ ]
693
592
  })
694
593
  ```
695
594
 
696
- #### Sticker Pack
595
+ #### All Button Types
697
596
 
698
- ### Method 1: Direct Socket Method (Recommended)
597
+ | Type | `name` value | Required params |
598
+ |------|-------------|-----------------|
599
+ | Quick Reply | `quick_reply` | `display_text`, `id` |
600
+ | URL | `cta_url` | `display_text`, `url`, `merchant_url` |
601
+ | Call | `cta_call` | `display_text`, `phone_number` |
602
+ | Copy | `cta_copy` | `display_text`, `copy_code` |
603
+ | List/Select | `single_select` | `title`, `sections[].rows[]` |
604
+ | Call Permission | `call_permission_request` | `has_multiple_buttons` |
605
+
606
+ #### List / Single Select
699
607
  ```javascript
700
- await sock.stickerPackMessage(jid, {
701
- name: 'My Stickers',
702
- publisher: 'Your Bot',
703
- description: 'Collection of stickers',
704
- stickers: [
705
- { data: buffer, emojis: ['😊'] },
706
- { data: './sticker.png', emojis: ['😂'] },
707
- { data: './sticker.webp', emojis: ['🎉'] },
708
- { data: 'https://example.com/sticker.jpg', emojis: ['❤️'] }
709
- ],
710
- cover: buffer
711
- }, { quoted: message });
608
+ {
609
+ name: 'single_select',
610
+ buttonParamsJson: JSON.stringify({
611
+ title: 'Select Option',
612
+ sections: [{
613
+ title: 'Section 1',
614
+ highlight_label: 'Popular',
615
+ rows: [
616
+ { title: 'Option 1', description: 'Desc 1', id: 'opt1' },
617
+ { title: 'Option 2', description: 'Desc 2', id: 'opt2' }
618
+ ]
619
+ }]
620
+ })
621
+ }
712
622
  ```
713
623
 
714
- ### Method 2: Via sendMessage
624
+ #### Full Interactive Message
715
625
  ```javascript
716
626
  await sock.sendMessage(jid, {
717
- stickerPack: {
718
- name: 'My Stickers',
719
- publisher: 'Your Bot',
720
- description: 'Collection of stickers',
721
- stickers: [
722
- { data: buffer, emojis: ['😊'] },
723
- { data: './sticker.png', emojis: ['😂'] },
724
- { data: './sticker.webp', emojis: ['🎉'] },
725
- { data: 'https://example.com/sticker.jpg', emojis: ['❤️'] }
726
- ],
727
- cover: buffer
627
+ interactiveMessage: {
628
+ title: 'Interactive',
629
+ footer: '© NexusTechPro',
630
+ image: { url: 'https://example.com/image.jpg' },
631
+ nativeFlowMessage: {
632
+ messageParamsJson: JSON.stringify({ /* optional advanced config */ }),
633
+ buttons: [
634
+ {
635
+ name: 'single_select',
636
+ buttonParamsJson: JSON.stringify({
637
+ title: 'Select',
638
+ sections: [{ title: 'Options', rows: [{ title: 'Option 1', id: 'opt1' }] }]
639
+ })
640
+ },
641
+ {
642
+ name: 'cta_copy',
643
+ buttonParamsJson: JSON.stringify({ display_text: 'Copy Code', copy_code: 'NEXUS2025' })
644
+ }
645
+ ]
728
646
  }
729
- }, { quoted: message });
647
+ }
648
+ })
730
649
  ```
731
650
 
732
- ### Supported Image Formats
651
+ #### interactiveButtons Shorthand
733
652
 
734
- | Format | Support | Notes |
735
- |--------|---------|-------|
736
- | **WebP** | ✅ Full | Used as-is, no conversion needed |
737
- | **PNG** | ✅ Full | Auto-converts to WebP |
738
- | **JPG/JPEG** | ✅ Full | Auto-converts to WebP |
739
- | **GIF** | ✅ Limited | Converts to static WebP |
740
- | **BMP** | ✅ Full | Auto-converts to WebP |
741
- | **Video** | ❌ Not supported | Only static images |
742
-
743
- ### Key Features
744
-
745
- ✅ **Automatic batching** - Splits packs >60 stickers
746
- ✅ **Compression** - Auto-compresses stickers >1MB
747
- ✅ **Auto-conversion** - Converts PNG, JPG, GIF, BMP to WebP
748
- ✅ **Multiple formats** - Supports buffers, file paths, URLs
749
- ✅ **Rate limiting** - 2-second delays between batches
750
- ✅ **Error handling** - Gracefully skips invalid stickers
751
-
752
- #### View Once Message
753
653
  ```javascript
654
+ // Without media header
754
655
  await sock.sendMessage(jid, {
755
- image: { url: './secret.jpg' },
756
- viewOnce: true,
757
- caption: 'View once only!'
758
- })
656
+ text: 'Description of Message',
657
+ title: 'Title of Message',
658
+ subtitle: 'Subtitle Message',
659
+ footer: 'Footer Message',
660
+ interactiveButtons: [
661
+ {
662
+ name: 'quick_reply',
663
+ buttonParamsJson: JSON.stringify({ display_text: 'Quick Reply', id: 'button_1' })
664
+ },
665
+ {
666
+ name: 'cta_url',
667
+ buttonParamsJson: JSON.stringify({ display_text: 'Visit Website', url: 'https://nexustechpro.com' })
668
+ }
669
+ ]
670
+ }, { quoted: message })
671
+
672
+ // With image header
673
+ await sock.sendMessage(jid, {
674
+ image: { url: 'https://example.jpg' }, // or buffer
675
+ caption: 'Description of Message',
676
+ title: 'Title of Message',
677
+ subtitle: 'Subtitle Message',
678
+ footer: 'Footer Message',
679
+ media: true,
680
+ interactiveButtons: [
681
+ {
682
+ name: 'quick_reply',
683
+ buttonParamsJson: JSON.stringify({ display_text: 'Quick Reply', id: 'button_1' })
684
+ },
685
+ {
686
+ name: 'cta_url',
687
+ buttonParamsJson: JSON.stringify({ display_text: 'Visit Website', url: 'https://nexustechpro.com' })
688
+ }
689
+ ]
690
+ }, { quoted: message })
691
+
692
+ // With product header
693
+ await sock.sendMessage(jid, {
694
+ product: {
695
+ productImage: { url: 'https://example.jpg' }, // or buffer
696
+ productImageCount: 1,
697
+ title: 'Product Title',
698
+ description: 'Product Description',
699
+ priceAmount1000: 20000 * 1000,
700
+ currencyCode: 'USD',
701
+ retailerId: 'Retail',
702
+ url: 'https://example.com'
703
+ },
704
+ businessOwnerJid: '1234@s.whatsapp.net',
705
+ caption: 'Description of Message',
706
+ title: 'Title of Message',
707
+ footer: 'Footer Message',
708
+ media: true,
709
+ interactiveButtons: [
710
+ {
711
+ name: 'quick_reply',
712
+ buttonParamsJson: JSON.stringify({ display_text: 'Quick Reply', id: 'button_1' })
713
+ },
714
+ {
715
+ name: 'cta_url',
716
+ buttonParamsJson: JSON.stringify({ display_text: 'Visit Website', url: 'https://nexustechpro.com' })
717
+ }
718
+ ]
719
+ }, { quoted: message })
759
720
  ```
760
721
 
761
- ---
722
+ #### Classic Buttons (Old Style)
762
723
 
763
- ### Buttons & Interactive Messages
724
+ For compatibility with older WhatsApp versions or specific use cases:
764
725
 
765
- #### Simple Text with Buttons
766
726
  ```javascript
727
+ // Text with classic buttons
767
728
  await sock.sendMessage(jid, {
768
- text: "Choose an option",
769
- footer: NexusTechPro",
770
- buttons: [
771
- {
772
- name: "quick_reply",
773
- buttonParamsJson: JSON.stringify({
774
- display_text: "Option 1",
775
- id: "opt1"
776
- })
777
- },
778
- {
779
- name: "cta_url",
780
- buttonParamsJson: JSON.stringify({
781
- display_text: "Visit Website",
782
- url: "https://nexustechpro.com",
783
- merchant_url: "https://nexustechpro.com"
784
- })
785
- }
786
- ]
729
+ text: 'Message with classic buttons',
730
+ footer: 'Footer text',
731
+ buttons: [
732
+ { buttonId: 'btn1', buttonText: { displayText: 'Button 1' }, type: 1 },
733
+ { buttonId: 'btn2', buttonText: { displayText: 'Button 2' }, type: 1 }
734
+ ],
735
+ headerType: 1
787
736
  })
788
- ```
789
737
 
790
- #### Image with Buttons
791
- ```javascript
738
+ // Image header with classic buttons
792
739
  await sock.sendMessage(jid, {
793
- image: { url: "https://example.com/image.jpg" },
794
- caption: "Description",
795
- footer: "© NexusTechPro",
796
- buttons: [
797
- {
798
- name: "quick_reply",
799
- buttonParamsJson: JSON.stringify({
800
- display_text: "Reply",
801
- id: "btn1"
802
- })
803
- }
804
- ]
740
+ image: { url: 'https://example.com/image.jpg' },
741
+ caption: 'Body text',
742
+ footer: 'Footer',
743
+ buttons: [
744
+ { buttonId: 'btn1', buttonText: { displayText: 'Button 1' }, type: 1 }
745
+ ],
746
+ headerType: 3
805
747
  })
806
748
  ```
807
749
 
808
- #### Video with Buttons
809
- ```javascript
810
- await sock.sendMessage(jid, {
811
- video: { url: "https://example.com/video.mp4" },
812
- caption: "Watch this",
813
- footer: "© NexusTechPro",
814
- buttons: [
815
- {
816
- name: "quick_reply",
817
- buttonParamsJson: JSON.stringify({
818
- display_text: "Like",
819
- id: "like"
820
- })
821
- }
822
- ]
823
- })
824
- ```
750
+ **Header Types:**
825
751
 
826
- #### Document with Buttons
827
- ```javascript
828
- await sock.sendMessage(jid, {
829
- document: { url: "./file.pdf" },
830
- fileName: "Document.pdf",
831
- mimetype: "application/pdf",
832
- caption: "Read this",
833
- footer: NexusTechPro",
834
- buttons: [
835
- {
836
- name: "quick_reply",
837
- buttonParamsJson: JSON.stringify({
838
- display_text: "Download",
839
- id: "download"
840
- })
841
- }
842
- ]
843
- })
844
- ```
752
+ | Value | Type | Description |
753
+ |-------|------|-------------|
754
+ | `0` | EMPTY | No header |
755
+ | `1` | TEXT | Text header |
756
+ | `2` | DOCUMENT | Document header |
757
+ | `3` | IMAGE | Image header |
758
+ | `4` | VIDEO | Video header |
759
+ | `5` | LOCATION | Location header |
760
+
761
+ **Button Types:**
762
+
763
+ | Value | Type | Description |
764
+ |-------|------|-------------|
765
+ | `1` | RESPONSE | Standard clickable button |
766
+ | `2` | NATIVE_FLOW | Native flow button |
845
767
 
846
768
  ---
847
769
 
848
- ### All Button Types
770
+ ### Extended Message Types
771
+
772
+ All of these go through `sock.sendMessage` — the library detects the type automatically.
849
773
 
850
- #### 1. Quick Reply
774
+ #### Album
851
775
  ```javascript
852
- {
853
- name: "quick_reply",
854
- buttonParamsJson: JSON.stringify({
855
- display_text: "Quick Reply",
856
- id: "button_id"
857
- })
858
- }
776
+ await sock.sendMessage(jid, {
777
+ albumMessage: [
778
+ { image: { url: 'https://example.com/1.jpg' }, caption: 'Photo 1' },
779
+ { video: { url: 'https://example.com/2.mp4' }, caption: 'Video 1' }
780
+ ]
781
+ }, { quoted: message })
782
+
783
+ // Shorthand
784
+ await sock.sendAlbumMessage(jid, [
785
+ { image: { url: 'https://example.com/1.jpg' }, caption: 'Photo 1' }
786
+ ], message)
859
787
  ```
860
788
 
861
- #### 2. URL Button
789
+ #### Carousel
862
790
  ```javascript
863
- {
864
- name: "cta_url",
865
- buttonParamsJson: JSON.stringify({
866
- display_text: "Visit Website",
867
- url: "https://nexustechpro.com",
868
- merchant_url: "https://nexustechpro.com"
869
- })
870
- }
791
+ await sock.sendMessage(jid, {
792
+ carouselMessage: {
793
+ caption: 'Our Products',
794
+ footer: 'Powered by NexusTechPro',
795
+ cards: [
796
+ {
797
+ headerTitle: 'Card 1',
798
+ imageUrl: 'https://example.com/1.jpg',
799
+ bodyText: 'Description',
800
+ buttons: [{ name: 'cta_url', params: { display_text: 'Visit', url: 'https://nexustechpro.com' } }]
801
+ },
802
+ {
803
+ headerTitle: 'Product Card',
804
+ imageUrl: 'https://example.com/2.jpg',
805
+ productTitle: 'Premium Bot',
806
+ productDescription: 'Get access',
807
+ bodyText: 'Details here',
808
+ buttons: [{ name: 'cta_call', params: { display_text: 'Call', phone_number: '+1234567890' } }]
809
+ }
810
+ ]
811
+ }
812
+ })
871
813
  ```
872
814
 
873
- #### 3. Call Button
815
+ #### Event
874
816
  ```javascript
875
- {
876
- name: "cta_call",
877
- buttonParamsJson: JSON.stringify({
878
- display_text: "Call Us",
879
- phone_number: "+1234567890"
880
- })
881
- }
817
+ await sock.sendMessage(jid, {
818
+ event: {
819
+ isCanceled: false,
820
+ name: 'Event Name',
821
+ description: 'Event Description',
822
+ location: { degreesLatitude: 0, degreesLongitude: 0, name: 'Venue' },
823
+ joinLink: 'https://meet.example.com/event',
824
+ startTime: Math.floor(Date.now() / 1000),
825
+ endTime: Math.floor(Date.now() / 1000) + 86400,
826
+ extraGuestsAllowed: true
827
+ }
828
+ }, { quoted: message })
882
829
  ```
883
830
 
884
- #### 4. Copy Button
831
+ #### Product Message
885
832
  ```javascript
886
- {
887
- name: "cta_copy",
888
- buttonParamsJson: JSON.stringify({
889
- display_text: "Copy Code",
890
- id: "copy_id",
891
- copy_code: "PROMO2025"
892
- })
893
- }
833
+ await sock.sendMessage(jid, {
834
+ productMessage: {
835
+ title: 'Product Title',
836
+ description: 'Product Description',
837
+ thumbnail: 'https://example.com/img.png',
838
+ productId: '123456789',
839
+ retailerId: 'STORE',
840
+ url: 'https://example.com',
841
+ body: 'Product Body',
842
+ footer: 'Product Footer',
843
+ buttons: [
844
+ {
845
+ name: 'cta_url',
846
+ buttonParamsJson: JSON.stringify({ display_text: 'Buy Now', url: 'https://example.com' })
847
+ }
848
+ ]
849
+ }
850
+ }, { quoted: message })
894
851
  ```
895
852
 
896
- #### 5. List/Single Select
853
+ #### Request Payment
897
854
  ```javascript
898
- {
899
- name: "single_select",
900
- buttonParamsJson: JSON.stringify({
901
- title: "Select Option",
902
- sections: [{
903
- title: "Section 1",
904
- highlight_label: "Popular",
905
- rows: [
906
- { title: "Option 1", description: "Desc 1", id: "opt1" },
907
- { title: "Option 2", description: "Desc 2", id: "opt2" }
908
- ]
909
- }]
910
- })
911
- }
855
+ // With note
856
+ await sock.sendMessage(jid, {
857
+ requestPayment: {
858
+ currency: 'IDR',
859
+ amount: '10000000',
860
+ from: '123456@s.whatsapp.net',
861
+ note: 'Payment for order #123'
862
+ }
863
+ }, { quoted: message })
864
+
865
+ // With sticker (URL or Buffer)
866
+ await sock.sendMessage(jid, {
867
+ requestPayment: {
868
+ currency: 'IDR',
869
+ amount: '10000000',
870
+ from: '123456@s.whatsapp.net',
871
+ sticker: { url: 'https://example.com/sticker.webp' }
872
+ }
873
+ })
912
874
  ```
913
875
 
914
- #### 6. Call Permission Request
876
+ #### Poll Result (Newsletter Style)
915
877
  ```javascript
916
- {
917
- name: "call_permission_request",
918
- buttonParamsJson: JSON.stringify({
919
- has_multiple_buttons: true
920
- })
921
- }
878
+ await sock.sendMessage(jid, {
879
+ pollResult: {
880
+ name: 'Poll Title',
881
+ votes: [['Option A', 42], ['Option B', 17]]
882
+ }
883
+ }, { quoted: message })
922
884
  ```
923
885
 
924
- ---
886
+ #### Group Story
887
+
888
+ Post a story/status visible only to a specific group.
925
889
 
926
- ### Classic Buttons (Old Style)
890
+ > All media types accept a URL, Buffer, file path, or WhatsApp CDN URL — no manual download needed.
927
891
 
928
- For compatibility with older WhatsApp versions:
929
892
  ```javascript
930
- await sock.sendMessage(jid, {
931
- text: "Message with classic buttons",
932
- footer: "Footer text",
933
- buttons: [
934
- {
935
- buttonId: "btn1",
936
- buttonText: { displayText: "Button 1" },
937
- type: 1
938
- },
939
- {
940
- buttonId: "btn2",
941
- buttonText: { displayText: "Button 2" },
942
- type: 1
943
- }
944
- ],
945
- headerType: 1
946
- })
947
- ```
893
+ // Text
894
+ await sock.sendMessage(jid, { groupStatus: { text: 'Hello group!' } })
948
895
 
949
- #### Header Types (Classic Buttons)
896
+ // Image
897
+ await sock.sendMessage(jid, { groupStatus: { image: { url: 'https://example.com/image.jpg' }, caption: 'Caption' } })
950
898
 
951
- | Value | Type | Description |
952
- |-------|------|-------------|
953
- | `0` | EMPTY | No header |
954
- | `1` | TEXT | Text header (use `title` field) |
955
- | `2` | DOCUMENT | Document header |
956
- | `3` | IMAGE | Image header |
957
- | `4` | VIDEO | Video header |
958
- | `5` | LOCATION | Location header |
899
+ // Video
900
+ await sock.sendMessage(jid, { groupStatus: { video: { url: 'https://example.com/video.mp4' }, caption: 'Caption' } })
959
901
 
960
- #### Button Types (Classic Buttons)
902
+ // Audio
903
+ await sock.sendMessage(jid, { groupStatus: { audio: { url: 'https://example.com/audio.mp3' }, ptt: false } })
961
904
 
962
- | Value | Type | Description |
963
- |-------|------|-------------|
964
- | `1` | RESPONSE | Standard clickable button |
965
- | `2` | NATIVE_FLOW | Native flow button |
905
+ // Via shorthand
906
+ await sock.sendGroupStatusMessage(groupJid, { text: 'Hello group!' })
907
+ await sock.sendGroupStatusMessage(groupJid, { image: { url: 'https://example.com/image.jpg' }, caption: 'Caption' })
908
+ await sock.sendGroupStatusMessage(groupJid, { video: { url: 'https://example.com/video.mp4' }, caption: 'Caption' })
909
+ await sock.sendGroupStatusMessage(groupJid, { audio: { url: 'https://example.com/audio.mp3' }, ptt: false })
966
910
 
967
- **Example with Image Header:**
968
- ```javascript
969
- await sock.sendMessage(jid, {
970
- image: { url: "https://example.com/image.jpg" },
971
- caption: "Body text",
972
- footer: "Footer",
973
- buttons: [
974
- { buttonId: "btn1", buttonText: { displayText: "Button 1" }, type: 1 }
975
- ],
976
- headerType: 3
977
- })
911
+ // Media also accepts Buffer or file path
912
+ await sock.sendGroupStatusMessage(groupJid, { image: buffer })
913
+ await sock.sendGroupStatusMessage(groupJid, { image: fs.readFileSync('./image.jpg') })
978
914
  ```
979
915
 
980
- ---
916
+ #### Personal Status / Story (status@broadcast)
981
917
 
982
- ### Advanced: Native Flow Messages
918
+ Post a story visible to all your contacts or a specific list.
983
919
 
984
- Complete example with all features:
985
920
  ```javascript
986
- await sock.sendMessage(jid, {
987
- interactiveMessage: {
988
- title: "Interactive Message",
989
- footer: "© NexusTechPro",
990
- image: { url: "https://example.com/image.jpg" },
991
- nativeFlowMessage: {
992
- messageParamsJson: JSON.stringify({
993
- limited_time_offer: {
994
- text: "Limited offer!",
995
- url: "https://nexustechpro.com",
996
- copy_code: "NEXUS2025",
997
- expiration_time: Date.now() + (24 * 60 * 60 * 1000)
998
- },
999
- bottom_sheet: {
1000
- in_thread_buttons_limit: 2,
1001
- divider_indices: [0, 1, 2],
1002
- list_title: "Select Option",
1003
- button_title: "Click Here"
1004
- },
1005
- tap_target_configuration: {
1006
- title: "Tap Target",
1007
- description: "Description",
1008
- canonical_url: "https://nexustechpro.com",
1009
- domain: "nexustechpro.com",
1010
- button_index: 0
1011
- }
1012
- }),
1013
- buttons: [
1014
- {
1015
- name: "single_select",
1016
- buttonParamsJson: JSON.stringify({
1017
- title: "Select",
1018
- sections: [{
1019
- title: "Options",
1020
- rows: [
1021
- { title: "Option 1", description: "Desc 1", id: "opt1" }
1022
- ]
1023
- }]
1024
- })
1025
- },
1026
- {
1027
- name: "cta_copy",
1028
- buttonParamsJson: JSON.stringify({
1029
- display_text: "Copy Code",
1030
- copy_code: "PROMO2025"
1031
- })
1032
- }
1033
- ]
1034
- }
1035
- }
921
+ // Text
922
+ await sock.sendMessage('status@broadcast', { text: 'My status update!' })
923
+
924
+ // Image
925
+ await sock.sendMessage('status@broadcast', { image: { url: 'https://example.com/image.jpg' }, caption: 'Caption' })
926
+
927
+ // Video
928
+ await sock.sendMessage('status@broadcast', { video: { url: 'https://example.com/video.mp4' }, caption: 'Caption' })
929
+
930
+ // Audio
931
+ await sock.sendMessage('status@broadcast', { audio: { url: 'https://example.com/audio.mp3' }, ptt: false })
932
+
933
+ // Send to specific contacts only
934
+ await sock.sendMessage('status@broadcast', {
935
+ text: 'Private status',
936
+ statusJidList: [
937
+ '1234567890@s.whatsapp.net',
938
+ '0987654321@s.whatsapp.net'
939
+ ]
1036
940
  })
1037
941
  ```
1038
942
 
1039
- ---
943
+ #### Status Mention (tag someone in your story)
944
+
945
+ Mention specific users or groups in a story. They get a private notification.
1040
946
 
1041
- ### Interactive Buttons (Alternative Format)
1042
947
  ```javascript
1043
- // Example non header media
1044
- await sock.sendMessage(jid, {
1045
- text: "Description of Message",
1046
- title: "Title of Message",
1047
- subtitle: "Subtitle Message",
1048
- footer: "Footer Message",
1049
- interactiveButtons: [
1050
- {
1051
- name: "quick_reply",
1052
- buttonParamsJson: JSON.stringify({
1053
- display_text: "Quick Reply",
1054
- id: "button_1"
1055
- })
1056
- },
1057
- {
1058
- name: "cta_url",
1059
- buttonParamsJson: JSON.stringify({
1060
- display_text: "Visit Website",
1061
- url: "https://nexustechpro.com"
1062
- })
1063
- }
1064
- ]
1065
- }, { quoted: message })
948
+ // Text
949
+ await sock.sendStatusMentions({ text: 'Hey @someone check this out!' }, ['1234567890@s.whatsapp.net'])
950
+
951
+ // Image
952
+ await sock.sendStatusMentions({ image: { url: 'https://example.com/image.jpg' }, caption: 'Caption' }, ['1234567890@s.whatsapp.net'])
953
+
954
+ // Video
955
+ await sock.sendStatusMentions({ video: { url: 'https://example.com/video.mp4' } }, ['1234567890@s.whatsapp.net'])
956
+
957
+ // Audio
958
+ await sock.sendStatusMentions({ audio: { url: 'https://example.com/audio.mp3' }, ptt: true }, ['1234567890@s.whatsapp.net'])
959
+
960
+ // Tag a group (all members get notified)
961
+ await sock.sendStatusMentions({ text: 'Hey group!' }, ['123456789@g.us'])
962
+ ```
963
+
964
+ #### Sticker Pack
1066
965
 
1067
- // Example with media
966
+ Send a full sticker pack. Supports buffers, file paths, and URLs. Packs over 60 stickers are automatically batched with a 2-second delay between batches.
967
+
968
+ ```javascript
969
+ // Method 1 — via sendMessage
1068
970
  await sock.sendMessage(jid, {
1069
- image: { url: "https://example.jpg" }, // or buffer
1070
- caption: "Description of Message",
1071
- title: "Title of Message",
1072
- subtitle: "Subtitle Message",
1073
- footer: "Footer Message",
1074
- media: true,
1075
- interactiveButtons: [
1076
- {
1077
- name: "quick_reply",
1078
- buttonParamsJson: JSON.stringify({
1079
- display_text: "Quick Reply",
1080
- id: "button_1"
1081
- })
1082
- },
1083
- {
1084
- name: "cta_url",
1085
- buttonParamsJson: JSON.stringify({
1086
- display_text: "Visit Website",
1087
- url: "https://nexustechpro.com"
1088
- })
1089
- }
1090
- ]
971
+ stickerPack: {
972
+ name: 'My Stickers',
973
+ publisher: 'NexusTechPro',
974
+ description: 'Custom sticker collection',
975
+ stickers: [
976
+ { data: buffer, emojis: ['😊'] },
977
+ { data: './sticker.png', emojis: ['😂'] },
978
+ { data: './sticker.webp', emojis: ['🎉'] },
979
+ { data: 'https://example.com/sticker.jpg', emojis: ['❤️'] }
980
+ ],
981
+ cover: coverBuffer // optional cover image
982
+ }
1091
983
  }, { quoted: message })
1092
984
 
1093
- // Example with header product
1094
- await sock.sendMessage(jid, {
1095
- product: {
1096
- productImage: { url: "https://example.jpg" }, // or buffer
1097
- productImageCount: 1,
1098
- title: "Product Title",
1099
- description: "Product Description",
1100
- priceAmount1000: 20000 * 1000,
1101
- currencyCode: "USD",
1102
- retailerId: "Retail",
1103
- url: "https://example.com",
1104
- },
1105
- businessOwnerJid: "1234@s.whatsapp.net",
1106
- caption: "Description of Message",
1107
- title: "Title of Message",
1108
- footer: "Footer Message",
1109
- media: true,
1110
- interactiveButtons: [
1111
- {
1112
- name: "quick_reply",
1113
- buttonParamsJson: JSON.stringify({
1114
- display_text: "Quick Reply",
1115
- id: "button_1"
1116
- })
1117
- },
1118
- {
1119
- name: "cta_url",
1120
- buttonParamsJson: JSON.stringify({
1121
- display_text: "Visit Website",
1122
- url: "https://nexustechpro.com"
1123
- })
1124
- }
1125
- ]
985
+ // Method 2 dedicated shorthand
986
+ await sock.stickerPackMessage(jid, {
987
+ name: 'My Stickers',
988
+ publisher: 'NexusTechPro',
989
+ description: 'A collection',
990
+ stickers: [
991
+ { data: buffer, emojis: ['😊'] },
992
+ { data: './sticker.png', emojis: ['😂'] }
993
+ ],
994
+ cover: coverBuffer
1126
995
  }, { quoted: message })
1127
996
  ```
1128
997
 
998
+ **Supported formats:**
999
+
1000
+ | Format | Support | Notes |
1001
+ |--------|---------|-------|
1002
+ | WebP | ✅ Full | Used as-is |
1003
+ | PNG | ✅ Full | Auto-converted to WebP |
1004
+ | JPG/JPEG | ✅ Full | Auto-converted to WebP |
1005
+ | GIF | ✅ Limited | Converts to static WebP |
1006
+ | BMP | ✅ Full | Auto-converted to WebP |
1007
+ | Video | ❌ | Not supported |
1008
+
1009
+ **Key behaviours:**
1010
+ - Packs >60 stickers are auto-batched
1011
+ - Stickers >1MB are auto-compressed
1012
+ - Invalid stickers are gracefully skipped
1013
+ - 2-second delay between batches to avoid rate limiting
1014
+
1129
1015
  ---
1130
1016
 
1131
- ## ✏️ Message Modifications
1017
+ ### Shorthand Wrappers
1132
1018
 
1133
- ### Delete Message (for everyone)
1134
1019
  ```javascript
1135
- const msg = await sock.sendMessage(jid, { text: 'hello' })
1136
- await sock.sendMessage(jid, { delete: msg.key })
1020
+ await sock.sendText(jid, 'Hello!', options)
1021
+ await sock.sendImage(jid, { url: './image.jpg' }, 'Caption', options)
1022
+ await sock.sendVideo(jid, buffer, 'Caption', options)
1023
+ await sock.sendDocument(jid, { url: './file.pdf' }, 'Caption', options)
1024
+ await sock.sendAudio(jid, { url: './audio.mp3' }, options)
1025
+ await sock.sendLocation(jid, { degreesLatitude: 24.12, degreesLongitude: 55.11, name: 'Place' }, options)
1026
+ await sock.sendPoll(jid, 'Question?', ['A', 'B', 'C'], false, options)
1027
+ await sock.sendReaction(jid, message.key, '💖', options)
1028
+ await sock.sendSticker(jid, { url: './sticker.webp' }, options)
1029
+ await sock.sendContact(jid, { vcard }, options)
1030
+ await sock.sendForward(jid, message, { force: true })
1137
1031
  ```
1138
1032
 
1139
- ### Edit Message
1033
+ ---
1034
+
1035
+ ## ✏️ Message Modifications
1036
+
1140
1037
  ```javascript
1141
- await sock.sendMessage(jid, {
1142
- text: 'Updated message text',
1143
- edit: originalMessage.key
1144
- })
1038
+ // Edit
1039
+ await sock.sendMessage(jid, { text: 'Updated text', edit: originalMessage.key })
1040
+
1041
+ // Delete for everyone
1042
+ const sent = await sock.sendMessage(jid, { text: 'hello' })
1043
+ await sock.sendMessage(jid, { delete: sent.key })
1044
+
1045
+ // Pin (time in seconds: 86400=24h, 604800=7d, 2592000=30d)
1046
+ await sock.sendMessage(jid, { pin: { type: 1, time: 86400, key: message.key } })
1047
+
1048
+ // Unpin
1049
+ await sock.sendMessage(jid, { pin: { type: 0, time: 0, key: message.key } })
1145
1050
  ```
1146
1051
 
1147
1052
  ---
1148
1053
 
1149
- ## 📥 Media Operations
1054
+ ## 📥 Media Download
1150
1055
 
1151
- ### Download Media
1152
1056
  ```javascript
1153
1057
  import { downloadMediaMessage, getContentType } from '@nexustechpro/baileys'
1154
1058
 
1155
1059
  sock.ev.on('messages.upsert', async ({ messages }) => {
1156
- const msg = messages[0]
1157
- if(!msg.message) return
1158
-
1159
- const messageType = getContentType(msg.message)
1160
-
1161
- if(messageType === 'imageMessage') {
1162
- const buffer = await downloadMediaMessage(
1163
- msg,
1164
- 'buffer',
1165
- {},
1166
- {
1167
- logger: console,
1168
- reuploadRequest: sock.updateMediaMessage
1169
- }
1170
- )
1171
- // Save buffer to file
1172
- fs.writeFileSync('./download.jpeg', buffer)
1173
- }
1060
+ const msg = messages[0]
1061
+ if (!msg.message) return
1062
+
1063
+ const type = getContentType(msg.message)
1064
+
1065
+ if (type === 'imageMessage') {
1066
+ const buffer = await downloadMediaMessage(
1067
+ msg,
1068
+ 'buffer',
1069
+ {},
1070
+ { logger, reuploadRequest: sock.updateMediaMessage }
1071
+ )
1072
+ fs.writeFileSync('./downloaded.jpg', buffer)
1073
+ }
1174
1074
  })
1175
- ```
1176
1075
 
1177
- ### Re-upload Media
1178
- ```javascript
1076
+ // Re-upload expired media
1179
1077
  await sock.updateMediaMessage(msg)
1180
1078
  ```
1181
1079
 
@@ -1183,564 +1081,291 @@ await sock.updateMediaMessage(msg)
1183
1081
 
1184
1082
  ## 👥 Group Management
1185
1083
 
1186
- ### Create Group
1187
1084
  ```javascript
1188
- const group = await sock.groupCreate('Group Name', [
1189
- '1234567890@s.whatsapp.net',
1190
- '0987654321@s.whatsapp.net'
1191
- ])
1192
- console.log('Group created:', group.id)
1193
- ```
1085
+ // Create group
1086
+ const group = await sock.groupCreate('Group Name', ['1234567890@s.whatsapp.net'])
1194
1087
 
1195
- ### Add/Remove Participants
1196
- ```javascript
1197
- // Add
1088
+ // Add / Remove / Promote / Demote
1198
1089
  await sock.groupParticipantsUpdate(groupJid, ['1234567890@s.whatsapp.net'], 'add')
1199
-
1200
- // Remove
1201
1090
  await sock.groupParticipantsUpdate(groupJid, ['1234567890@s.whatsapp.net'], 'remove')
1202
-
1203
- // Promote to admin
1204
1091
  await sock.groupParticipantsUpdate(groupJid, ['1234567890@s.whatsapp.net'], 'promote')
1205
-
1206
- // Demote from admin
1207
1092
  await sock.groupParticipantsUpdate(groupJid, ['1234567890@s.whatsapp.net'], 'demote')
1208
- ```
1209
1093
 
1210
- ### Update Group Subject
1211
- ```javascript
1094
+ // Update group info
1212
1095
  await sock.groupUpdateSubject(groupJid, 'New Group Name')
1213
- ```
1214
-
1215
- ### Update Group Description
1216
- ```javascript
1217
- await sock.groupUpdateDescription(groupJid, 'New group description')
1218
- ```
1219
-
1220
- ### Group Settings
1221
- ```javascript
1222
- // Only admins can send messages
1223
- await sock.groupSettingUpdate(groupJid, 'announcement')
1224
-
1225
- // Everyone can send messages
1226
- await sock.groupSettingUpdate(groupJid, 'not_announcement')
1096
+ await sock.groupUpdateDescription(groupJid, 'New description')
1227
1097
 
1228
- // Only admins can edit group info
1229
- await sock.groupSettingUpdate(groupJid, 'locked')
1098
+ // Settings
1099
+ await sock.groupSettingUpdate(groupJid, 'announcement') // only admins can send
1100
+ await sock.groupSettingUpdate(groupJid, 'not_announcement') // everyone can send
1101
+ await sock.groupSettingUpdate(groupJid, 'locked') // only admins edit info
1102
+ await sock.groupSettingUpdate(groupJid, 'unlocked') // everyone edits info
1230
1103
 
1231
- // Everyone can edit group info
1232
- await sock.groupSettingUpdate(groupJid, 'unlocked')
1233
- ```
1234
-
1235
- ### Get Group Metadata
1236
- ```javascript
1104
+ // Metadata
1237
1105
  const metadata = await sock.groupMetadata(groupJid)
1238
- console.log('Group:', metadata.subject)
1239
- console.log('Participants:', metadata.participants.length)
1240
- ```
1241
1106
 
1242
- ### Get Invite Code
1243
- ```javascript
1107
+ // Invite link
1244
1108
  const code = await sock.groupInviteCode(groupJid)
1245
- console.log('Invite link:', `https://chat.whatsapp.com/${code}`)
1246
- ```
1109
+ console.log(`https://chat.whatsapp.com/${code}`)
1247
1110
 
1248
- ### Revoke Invite Code
1249
- ```javascript
1250
- const newCode = await sock.groupRevokeInvite(groupJid)
1251
- console.log('New invite code:', newCode)
1252
- ```
1253
-
1254
- ### Join Group via Invite Code
1255
- ```javascript
1256
- await sock.groupAcceptInvite('INVITE_CODE_HERE')
1257
- ```
1258
-
1259
- ### Leave Group
1260
- ```javascript
1261
- await sock.groupLeave(groupJid)
1262
- ```
1263
-
1264
- ### Get Group Invite Info
1265
- ```javascript
1266
- const info = await sock.groupGetInviteInfo('INVITE_CODE')
1267
- console.log('Group info:', info)
1111
+ await sock.groupRevokeInvite(groupJid) // revoke invite
1112
+ await sock.groupAcceptInvite('INVITE_CODE') // join group
1113
+ await sock.groupLeave(groupJid) // leave group
1268
1114
  ```
1269
1115
 
1270
1116
  ---
1271
1117
 
1272
1118
  ## 📱 User Operations
1273
1119
 
1274
- ### Check if Number Exists
1275
1120
  ```javascript
1121
+ // Check if number exists on WhatsApp
1276
1122
  const [result] = await sock.onWhatsApp('1234567890')
1277
- if(result?.exists) {
1278
- console.log('Number exists:', result.jid)
1279
- }
1280
- ```
1281
-
1282
- ### Get Profile Picture
1283
- ```javascript
1284
- // Low resolution
1285
- const ppUrl = await sock.profilePictureUrl(jid)
1123
+ if (result?.exists) console.log(result.jid)
1286
1124
 
1287
- // High resolution
1288
- const ppUrlHD = await sock.profilePictureUrl(jid, 'image')
1289
- ```
1290
-
1291
- ### Update Profile Picture
1292
- ```javascript
1293
- await sock.updateProfilePicture(jid, {
1294
- url: './profile.jpg'
1295
- })
1296
- ```
1297
-
1298
- ### Remove Profile Picture
1299
- ```javascript
1125
+ // Profile picture
1126
+ const url = await sock.profilePictureUrl(jid, 'image') // 'image' = HD
1127
+ await sock.updateProfilePicture(jid, { url: './profile.jpg' })
1300
1128
  await sock.removeProfilePicture(jid)
1301
- ```
1302
1129
 
1303
- ### Get Status
1304
- ```javascript
1130
+ // Status & name
1305
1131
  const status = await sock.fetchStatus(jid)
1306
- console.log('Status:', status)
1307
- ```
1308
-
1309
- ### Update Profile Status
1310
- ```javascript
1311
1132
  await sock.updateProfileStatus('Available 24/7')
1312
- ```
1133
+ await sock.updateProfileName('My Bot')
1313
1134
 
1314
- ### Update Profile Name
1315
- ```javascript
1316
- await sock.updateProfileName('NexusTech Bot')
1317
- ```
1135
+ // Business profile
1136
+ const biz = await sock.getBusinessProfile(jid)
1318
1137
 
1319
- ### Get Business Profile
1320
- ```javascript
1321
- const profile = await sock.getBusinessProfile(jid)
1322
- console.log('Business:', profile.description)
1323
- ```
1324
-
1325
- ### Presence Updates
1326
- ```javascript
1327
- // Subscribe to presence updates
1138
+ // Presence
1328
1139
  await sock.presenceSubscribe(jid)
1140
+ await sock.sendPresenceUpdate('composing', jid) // available | unavailable | composing | recording | paused
1329
1141
 
1330
- // Send presence
1331
- await sock.sendPresenceUpdate('available', jid) // available, unavailable, composing, recording, paused
1332
- ```
1333
-
1334
- ### Read Messages
1335
- ```javascript
1142
+ // Read messages
1336
1143
  await sock.readMessages([message.key])
1144
+
1145
+ // Block / Unblock
1146
+ await sock.updateBlockStatus(jid, 'block')
1147
+ await sock.updateBlockStatus(jid, 'unblock')
1148
+
1149
+ // Blocklist
1150
+ const blocked = await sock.fetchBlocklist()
1337
1151
  ```
1338
1152
 
1339
1153
  ---
1340
1154
 
1341
1155
  ## 🔒 Privacy Controls
1342
1156
 
1343
- ### Block/Unblock User
1344
- ```javascript
1345
- // Block
1346
- await sock.updateBlockStatus(jid, 'block')
1347
-
1348
- // Unblock
1349
- await sock.updateBlockStatus(jid, 'unblock')
1350
- ```
1351
-
1352
- ### Get Privacy Settings
1353
1157
  ```javascript
1354
1158
  const settings = await sock.fetchPrivacySettings()
1355
- console.log(settings)
1356
- ```
1357
1159
 
1358
- ### Update Privacy Settings
1359
- ```javascript
1360
- // Last seen: 'all', 'contacts', 'contact_blacklist', 'none'
1160
+ // last seen: 'all' | 'contacts' | 'contact_blacklist' | 'none'
1361
1161
  await sock.updateLastSeenPrivacy('contacts')
1362
1162
 
1363
- // Online: 'all', 'match_last_seen'
1163
+ // online: 'all' | 'match_last_seen'
1364
1164
  await sock.updateOnlinePrivacy('all')
1365
1165
 
1366
- // Profile picture: 'all', 'contacts', 'contact_blacklist', 'none'
1166
+ // profile picture: 'all' | 'contacts' | 'contact_blacklist' | 'none'
1367
1167
  await sock.updateProfilePicturePrivacy('contacts')
1368
1168
 
1369
- // Status: 'all', 'contacts', 'contact_blacklist', 'none'
1169
+ // status: 'all' | 'contacts' | 'contact_blacklist' | 'none'
1370
1170
  await sock.updateStatusPrivacy('contacts')
1371
1171
 
1372
- // Read receipts: 'all', 'none'
1172
+ // read receipts: 'all' | 'none'
1373
1173
  await sock.updateReadReceiptsPrivacy('all')
1374
1174
 
1375
- // Groups add: 'all', 'contacts', 'contact_blacklist'
1175
+ // groups add: 'all' | 'contacts' | 'contact_blacklist'
1376
1176
  await sock.updateGroupsAddPrivacy('contacts')
1377
1177
  ```
1378
1178
 
1379
- ### Get Block List
1380
- ```javascript
1381
- const blocklist = await sock.fetchBlocklist()
1382
- console.log('Blocked users:', blocklist)
1383
- ```
1384
-
1385
1179
  ---
1386
1180
 
1387
1181
  ## 💬 Chat Operations
1388
1182
 
1389
- ### Archive/Unarchive Chat
1390
1183
  ```javascript
1391
- const lastMsg = await getLastMessageInChat(jid)
1184
+ const lastMsg = await getLastMessageInChat(jid) // implement with your store
1392
1185
 
1393
- await sock.chatModify({
1394
- archive: true,
1395
- lastMessages: [lastMsg]
1396
- }, jid)
1397
- ```
1186
+ // Archive / Unarchive
1187
+ await sock.chatModify({ archive: true, lastMessages: [lastMsg] }, jid)
1398
1188
 
1399
- ### Mute/Unmute Chat
1400
- ```javascript
1401
- // Mute for 8 hours
1402
- await sock.chatModify({
1403
- mute: 8 * 60 * 60 * 1000
1404
- }, jid)
1405
-
1406
- // Unmute
1407
- await sock.chatModify({
1408
- mute: null
1409
- }, jid)
1410
- ```
1189
+ // Mute (ms) / Unmute
1190
+ await sock.chatModify({ mute: 8 * 60 * 60 * 1000 }, jid)
1191
+ await sock.chatModify({ mute: null }, jid)
1411
1192
 
1412
- ### Pin/Unpin Chat
1413
- ```javascript
1414
- // Pin
1193
+ // Pin / Unpin
1415
1194
  await sock.chatModify({ pin: true }, jid)
1416
-
1417
- // Unpin
1418
1195
  await sock.chatModify({ pin: false }, jid)
1419
- ```
1420
-
1421
- ### Delete Chat
1422
- ```javascript
1423
- const lastMsg = await getLastMessageInChat(jid)
1424
1196
 
1425
- await sock.chatModify({
1426
- delete: true,
1427
- lastMessages: [{
1428
- key: lastMsg.key,
1429
- messageTimestamp: lastMsg.messageTimestamp
1430
- }]
1431
- }, jid)
1432
- ```
1197
+ // Delete chat
1198
+ await sock.chatModify({ delete: true, lastMessages: [{ key: lastMsg.key, messageTimestamp: lastMsg.messageTimestamp }] }, jid)
1433
1199
 
1434
- ### Mark Chat as Read/Unread
1435
- ```javascript
1436
- // Mark as read
1200
+ // Mark read / unread
1437
1201
  await sock.chatModify({ markRead: true }, jid)
1438
-
1439
- // Mark as unread
1440
1202
  await sock.chatModify({ markRead: false }, jid)
1441
1203
  ```
1442
1204
 
1443
1205
  ---
1444
1206
 
1445
- ## 📢 Broadcast & Stories
1446
-
1447
- ### Send Broadcast Message
1448
- ```javascript
1449
- await sock.sendMessage(jid, {
1450
- text: 'Broadcast message',
1451
- statusJidList: [
1452
- '1234567890@s.whatsapp.net',
1453
- '0987654321@s.whatsapp.net'
1454
- ],
1455
- broadcast: true
1456
- })
1457
- ```
1207
+ ## 📢 Newsletter / Channels
1458
1208
 
1459
- ### Send Story/Status
1460
1209
  ```javascript
1461
- await sock.sendMessage('status@broadcast', {
1462
- image: { url: './story.jpg' },
1463
- caption: 'My story update!'
1464
- })
1465
- ```
1466
-
1467
- ### Newsletter/Channel Management
1468
- ```javascript
1469
- // Create newsletter
1470
- await sock.newsletterCreate('Newsletter Name', {
1471
- description: 'Newsletter description',
1472
- picture: buffer // optional
1473
- })
1210
+ // Create
1211
+ await sock.newsletterCreate('Channel Name', { description: 'Description', picture: buffer })
1474
1212
 
1475
- // Update newsletter metadata
1476
- await sock.newsletterUpdateMetadata(newsletterJid, {
1477
- name: 'New Name',
1478
- description: 'New description'
1479
- })
1480
-
1481
- // Update newsletter picture
1213
+ // Update
1214
+ await sock.newsletterUpdateMetadata(newsletterJid, { name: 'New Name', description: 'New Desc' })
1482
1215
  await sock.newsletterUpdatePicture(newsletterJid, buffer)
1483
1216
 
1484
- // React to newsletter message
1217
+ // React to a message
1485
1218
  await sock.newsletterReactMessage(newsletterJid, messageId, '👍')
1486
1219
 
1487
- // Follow newsletter
1220
+ // Follow / Unfollow / Mute / Unmute
1488
1221
  await sock.newsletterFollow(newsletterJid)
1489
-
1490
- // Unfollow newsletter
1491
1222
  await sock.newsletterUnfollow(newsletterJid)
1492
-
1493
- // Mute newsletter
1494
1223
  await sock.newsletterMute(newsletterJid)
1495
-
1496
- // Unmute newsletter
1497
1224
  await sock.newsletterUnmute(newsletterJid)
1498
1225
  ```
1499
1226
 
1500
1227
  ---
1501
1228
 
1502
- ## 🧩 Advanced Features
1503
-
1504
- ### Disappearing Messages
1505
- ```javascript
1506
- // Enable (86400 = 24 hours, 604800 = 7 days, 7776000 = 90 days)
1507
- await sock.sendMessage(jid, {
1508
- disappearingMessagesInChat: 86400
1509
- })
1510
-
1511
- // Disable
1512
- await sock.sendMessage(jid, {
1513
- disappearingMessagesInChat: false
1514
- })
1515
- ```
1516
-
1517
- ### Query Message
1518
- ```javascript
1519
- const msg = await sock.loadMessage(jid, messageId)
1520
- console.log('Message:', msg)
1521
- ```
1522
-
1523
- ### Get Message Info
1524
- ```javascript
1525
- const info = await sock.messageInfo(jid, messageId)
1526
- console.log('Read by:', info.readBy.length)
1527
- console.log('Played by:', info.playedBy.length)
1528
- ```
1529
-
1530
- ### App State Sync
1531
- ```javascript
1532
- // Sync app state
1533
- await sock.appPatch(['regular', 'critical_block', 'critical_unblock_low'])
1534
- ```
1535
-
1536
- ### WABrowserId
1537
- ```javascript
1538
- const browserId = sock.generateBrowserId()
1539
- console.log('Browser ID:', browserId)
1540
- ```
1229
+ ## 📡 Events Reference
1230
+
1231
+ | Event | Trigger |
1232
+ |-------|---------|
1233
+ | `connection.update` | Connection state changed |
1234
+ | `creds.update` | Auth credentials updated |
1235
+ | `messages.upsert` | New message(s) received |
1236
+ | `messages.update` | Message status/content updated |
1237
+ | `messages.delete` | Message(s) deleted |
1238
+ | `message-receipt.update` | Read/delivered receipts |
1239
+ | `chats.set` | Initial chat list loaded |
1240
+ | `chats.upsert` | New chat(s) appeared |
1241
+ | `chats.update` | Chat metadata updated |
1242
+ | `chats.delete` | Chat(s) deleted |
1243
+ | `contacts.set` | Initial contacts loaded |
1244
+ | `contacts.upsert` | New contact(s) added |
1245
+ | `contacts.update` | Contact info updated |
1246
+ | `groups.upsert` | New group created/joined |
1247
+ | `groups.update` | Group metadata changed |
1248
+ | `group-participants.update` | Member added/removed/promoted |
1249
+ | `presence.update` | User presence changed |
1250
+ | `call` | Incoming call |
1251
+ | `blocklist.set` | Initial blocklist loaded |
1252
+ | `blocklist.update` | Block/unblock event |
1541
1253
 
1542
1254
  ---
1543
1255
 
1544
1256
  ## 🎯 Best Practices
1545
1257
 
1546
- ### 1. Session Management
1547
- ```javascript
1548
- import { useMultiFileAuthState } from '@nexustechpro/baileys'
1549
-
1550
- const { state, saveCreds } = await useMultiFileAuthState('auth_folder')
1551
- const sock = makeWASocket({ auth: state })
1552
-
1553
- sock.ev.on('creds.update', saveCreds)
1554
- ```
1258
+ ### Reconnection
1555
1259
 
1556
- ### 2. Store Implementation
1557
1260
  ```javascript
1558
- import { makeInMemoryStore } from '@nexustechpro/baileys'
1261
+ sock.ev.on('connection.update', ({ connection, lastDisconnect }) => {
1262
+ if (connection === 'close') {
1263
+ const code = lastDisconnect?.error?.output?.statusCode
1264
+ const shouldReconnect = code !== DisconnectReason.loggedOut
1265
+ if (shouldReconnect) connectToWhatsApp()
1266
+ else console.log('Logged out — clear session and re-authenticate')
1267
+ }
1268
+ })
1269
+ ```
1559
1270
 
1560
- const store = makeInMemoryStore({})
1561
- store.readFromFile('./store.json')
1271
+ ### Cache Group Metadata
1562
1272
 
1563
- setInterval(() => {
1564
- store.writeToFile('./store.json')
1565
- }, 10_000)
1273
+ ```javascript
1274
+ import NodeCache from '@cacheable/node-cache'
1566
1275
 
1567
- store.bind(sock.ev)
1568
- ```
1276
+ const groupCache = new NodeCache({ stdTTL: 5 * 60, useClones: false })
1569
1277
 
1570
- ### 3. Error Handling
1571
- ```javascript
1572
- try {
1573
- await sock.sendMessage(jid, { text: 'Hello' })
1574
- } catch(error) {
1575
- if(error.output?.statusCode === 401) {
1576
- console.log('Not authorized')
1577
- } else {
1578
- console.error('Send failed:', error)
1579
- }
1580
- }
1581
- ```
1278
+ const sock = makeWASocket({
1279
+ cachedGroupMetadata: async (jid) => groupCache.get(jid)
1280
+ })
1582
1281
 
1583
- ### 4. Reconnection Logic
1584
- ```javascript
1585
- sock.ev.on('connection.update', async (update) => {
1586
- const { connection, lastDisconnect } = update
1587
-
1588
- if(connection === 'close') {
1589
- const shouldReconnect = lastDisconnect?.error?.output?.statusCode !== DisconnectReason.loggedOut
1590
-
1591
- if(shouldReconnect) {
1592
- console.log('Reconnecting...')
1593
- await connectToWhatsApp()
1594
- } else {
1595
- console.log('Logged out')
1596
- }
1597
- }
1282
+ sock.ev.on('groups.update', async ([event]) => {
1283
+ const metadata = await sock.groupMetadata(event.id)
1284
+ groupCache.set(event.id, metadata)
1598
1285
  })
1599
1286
  ```
1600
1287
 
1601
- ### 5. Rate Limiting
1288
+ ### Rate Limiting
1289
+
1602
1290
  ```javascript
1603
1291
  const queue = []
1604
- const sending = false
1292
+ let sending = false
1605
1293
 
1606
- async function queueMessage(jid, message) {
1607
- queue.push({ jid, message })
1608
- if(!sending) processQueue()
1294
+ const queueMessage = (jid, content) => {
1295
+ queue.push({ jid, content })
1296
+ if (!sending) processQueue()
1609
1297
  }
1610
1298
 
1611
- async function processQueue() {
1612
- sending = true
1613
- while(queue.length > 0) {
1614
- const { jid, message } = queue.shift()
1615
- await sock.sendMessage(jid, message)
1616
- await delay(1000) // 1 second delay between messages
1617
- }
1618
- sending = false
1299
+ const processQueue = async () => {
1300
+ sending = true
1301
+ while (queue.length > 0) {
1302
+ const { jid, content } = queue.shift()
1303
+ await sock.sendMessage(jid, content)
1304
+ await new Promise(r => setTimeout(r, 1000))
1305
+ }
1306
+ sending = false
1619
1307
  }
1620
1308
  ```
1621
1309
 
1622
- ---
1310
+ ### Error Handling
1623
1311
 
1624
- ## 📝 Important Notes
1625
-
1626
- ### WhatsApp ID Formats
1627
- - **Personal**: `[country_code][phone_number]@s.whatsapp.net`
1628
- - **Group**: `[group_id]@g.us`
1629
- - **Broadcast**: `[timestamp]@broadcast`
1630
- - **Status**: `status@broadcast`
1631
- - **Newsletter**: `[newsletter_id]@newsletter`
1632
-
1633
- ### Message Types
1634
- All supported message types:
1635
- - `conversation` - Text
1636
- - `imageMessage` - Image
1637
- - `videoMessage` - Video
1638
- - `audioMessage` - Audio
1639
- - `documentMessage` - Document
1640
- - `stickerMessage` - Sticker
1641
- - `locationMessage` - Location
1642
- - `contactMessage` - Contact
1643
- - `pollCreationMessage` - Poll
1644
- - `reactionMessage` - Reaction
1645
- - `editedMessage` - Edited message
1646
- - `viewOnceMessage` - View once media
1647
- - `extendedTextMessage` - Text with link preview
1648
-
1649
- ### Events Reference
1650
1312
  ```javascript
1651
- // Connection events
1652
- 'connection.update'
1653
- 'creds.update'
1654
-
1655
- // Message events
1656
- 'messages.upsert'
1657
- 'messages.update'
1658
- 'messages.delete'
1659
- 'message-receipt.update'
1660
-
1661
- // Chat events
1662
- 'chats.set'
1663
- 'chats.upsert'
1664
- 'chats.update'
1665
- 'chats.delete'
1666
-
1667
- // Contact events
1668
- 'contacts.set'
1669
- 'contacts.upsert'
1670
- 'contacts.update'
1671
-
1672
- // Group events
1673
- 'groups.upsert'
1674
- 'groups.update'
1675
- 'group-participants.update'
1676
-
1677
- // Presence events
1678
- 'presence.update'
1679
-
1680
- // Call events
1681
- 'call'
1682
-
1683
- // Blocklist events
1684
- 'blocklist.set'
1685
- 'blocklist.update'
1313
+ try {
1314
+ await sock.sendMessage(jid, { text: 'Hello' })
1315
+ } catch (error) {
1316
+ if (error.output?.statusCode === 401) console.log('Unauthorized')
1317
+ else console.error('Send failed:', error)
1318
+ }
1686
1319
  ```
1687
1320
 
1688
- ---
1689
-
1690
- ## 🤝 Contributing
1691
-
1692
- Contributions are welcome! Please follow these guidelines:
1693
-
1694
- 1. Fork the repository
1695
- 2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
1696
- 3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
1697
- 4. Push to the branch (`git push origin feature/AmazingFeature`)
1698
- 5. Open a Pull Request
1699
-
1700
- ---
1321
+ ### Poll Decryption
1701
1322
 
1702
- ## 📄 License
1323
+ ```javascript
1324
+ import { getAggregateVotesInPollMessage } from '@nexustechpro/baileys'
1703
1325
 
1704
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
1326
+ sock.ev.on('messages.update', async (event) => {
1327
+ for (const { key, update } of event) {
1328
+ if (update.pollUpdates) {
1329
+ const pollCreation = await getMessage(key)
1330
+ if (pollCreation) {
1331
+ const result = getAggregateVotesInPollMessage({
1332
+ message: pollCreation,
1333
+ pollUpdates: update.pollUpdates
1334
+ })
1335
+ console.log('Poll votes:', result)
1336
+ }
1337
+ }
1338
+ }
1339
+ })
1340
+ ```
1705
1341
 
1706
1342
  ---
1707
1343
 
1708
1344
  ## ⚠️ Disclaimer
1709
1345
 
1710
- This project is **NOT** officially affiliated with WhatsApp or Meta. This is an independent project and should be used responsibly. The authors and maintainers are not responsible for any misuse of this library.
1346
+ This project is **not** affiliated with WhatsApp or Meta. Use responsibly:
1711
1347
 
1712
- **Important**:
1713
1348
  - Follow WhatsApp's Terms of Service
1714
- - Don't spam or send unsolicited messages
1349
+ - Do not spam or send unsolicited messages
1715
1350
  - Respect user privacy
1716
- - Use for legitimate purposes only
1717
1351
  - Be aware of WhatsApp's rate limits
1352
+ - This library is for legitimate automation purposes only
1718
1353
 
1719
1354
  ---
1720
1355
 
1721
1356
  ## 🙏 Acknowledgments
1722
1357
 
1723
- Special thanks to:
1724
1358
  - [WhiskeySockets](https://github.com/WhiskeySockets) for the original Baileys library
1725
- - All contributors who have helped improve this project
1726
- - The open-source community for their continuous support
1359
+ - All contributors and the open-source community
1727
1360
 
1728
1361
  ---
1729
1362
 
1730
- ## 📞 Support
1363
+ <div align="center">
1731
1364
 
1732
- - **Issues**: [Whatsapp Channel](https://whatsapp.com/channel/0029VbBK53XBvvslYeZlBe0V)
1733
- - **Discussions**: [Whatsapp Channel](https://whatsapp.com/channel/0029VbBK53XBvvslYeZlBe0V)
1734
- - **NPM**: [@nexustechpro/baileys](https://www.npmjs.com/package/@nexustechpro/baileys)
1365
+ **Made with ❤️ by [NexusTechPro](https://github.com/nexustechpro2)**
1735
1366
 
1736
- ---
1367
+ ⭐ **Star us on GitHub!** ⭐
1737
1368
 
1738
- <div align="center">
1739
-
1740
- **Made with ❤️ by [NexusTechPro](https://github.com/nexustechpro1)**
1741
-
1742
- ⭐ **Star us on GitHub!** ⭐
1743
-
1744
- [GitHub](https://github.com/nexustechpro1/baileys) • [NPM](https://www.npmjs.com/package/@nexustechpro/baileys) • [Documentation](https://github.com/nexustechpro1/baileys/wiki)
1369
+ [GitHub](https://github.com/nexustechpro2/baileys) • [NPM](https://www.npmjs.com/package/@nexustechpro/baileys)
1745
1370
 
1746
1371
  </div>