@nexustechpro/baileys 1.1.7 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,1746 +1,1746 @@
1
- # 🚀 NexusTechPro Baileys
2
-
3
- <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
-
20
- ## 📋 Table of Contents
21
-
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)
43
-
44
- ---
45
-
46
- ## ✨ Features
47
-
48
- <table>
49
- <tr>
50
- <td>
51
-
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
59
-
60
- </td>
61
- <td>
62
-
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
70
-
71
- </td>
72
- </tr>
73
- </table>
74
-
75
- ---
76
-
77
- ## 📦 Installation
78
-
79
- ### NPM
80
- ```bash
81
- npm install @nexustechpro/baileys
82
- ```
83
-
84
- ### Yarn
85
- ```bash
86
- yarn add @nexustechpro/baileys
87
- ```
88
-
89
- ### Using Different Package Name
90
- Add to your `package.json`:
91
- ```json
92
- {
93
- "dependencies": {
94
- "@whiskeysockets/baileys": "npm:@nexustechpro/baileys"
95
- }
96
- }
97
- ```
98
-
99
- ### Import
100
- ```javascript
101
- // ESM
102
- import makeWASocket from '@nexustechpro/baileys'
103
-
104
- // CommonJS
105
- const { default: makeWASocket } = require('@nexustechpro/baileys')
106
- ```
107
-
108
- ---
109
-
110
- ## 🔌 Quick Start
111
- ```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
- })
144
-
145
- sock.ev.on('creds.update', saveCreds)
146
- }
147
-
148
- connectToWhatsApp()
149
- ```
150
-
151
- ---
152
-
153
- ## 🔐 Authentication
154
-
155
- ### QR Code Authentication
156
- ```javascript
157
- import makeWASocket from '@nexustechpro/baileys'
158
-
159
- const sock = makeWASocket({
160
- auth: state,
161
- printQRInTerminal: true,
162
- browser: ['NexusTechPro Bot', 'Chrome', '1.0.0']
163
- })
164
- ```
165
-
166
- ### Pairing Code Authentication
167
- ```javascript
168
- const sock = makeWASocket({
169
- auth: state,
170
- printQRInTerminal: false
171
- })
172
-
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}`)
177
- }
178
- ```
179
-
180
- ### Custom Pairing Code
181
- ```javascript
182
- const phoneNumber = "628XXXXX"
183
- const code = await sock.requestPairingCode(phoneNumber.trim(), "NEXUS01")
184
- console.log("Your pairing code: " + code)
185
- ```
186
-
187
- ---
188
-
189
- ## 💡 Socket Configuration
190
-
191
- ### Cache Group Metadata (Recommended)
192
- ```javascript
193
- const groupCache = new NodeCache({ stdTTL: 5 * 60, useClones: false })
194
-
195
- const sock = makeWASocket({
196
- cachedGroupMetadata: async (jid) => groupCache.get(jid)
197
- })
198
-
199
- sock.ev.on('groups.update', async ([event]) => {
200
- const metadata = await sock.groupMetadata(event.id)
201
- groupCache.set(event.id, metadata)
202
- })
203
- ```
204
-
205
- ### Improve Retry & Poll Decryption
206
- ```javascript
207
- const sock = makeWASocket({
208
- getMessage: async (key) => await getMessageFromStore(key)
209
- })
210
- ```
211
-
212
- ### Receive Notifications in WhatsApp App
213
- ```javascript
214
- const sock = makeWASocket({
215
- markOnlineOnConnect: false
216
- })
217
- ```
218
-
219
- ---
220
-
221
- ## 💾 Session Management
222
-
223
- Avoid scanning QR every time:
224
- ```javascript
225
- import makeWASocket, { useMultiFileAuthState } from '@nexustechpro/baileys'
226
-
227
- const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
228
- const sock = makeWASocket({ auth: state })
229
-
230
- sock.ev.on('creds.update', saveCreds)
231
- ```
232
-
233
- > 💡 **Tip:** For production, store auth in a database instead of files.
234
-
235
- ---
236
-
237
- ## 📡 Event Handling
238
-
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
- ```
252
-
253
- ### New Messages
254
- ```javascript
255
- sock.ev.on('messages.upsert', async ({ messages }) => {
256
- for(const msg of messages) {
257
- console.log('New message:', msg)
258
- }
259
- })
260
- ```
261
-
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
- ```
270
-
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
- ```
287
-
288
- ---
289
-
290
- ## 🛠️ Data Store
291
- ```javascript
292
- import makeWASocket, { makeInMemoryStore } from '@nexustechpro/baileys'
293
-
294
- const store = makeInMemoryStore({})
295
- store.readFromFile('./baileys_store.json')
296
-
297
- setInterval(() => {
298
- store.writeToFile('./baileys_store.json')
299
- }, 10_000)
300
-
301
- const sock = makeWASocket({})
302
- store.bind(sock.ev)
303
-
304
- sock.ev.on('chats.upsert', () => {
305
- console.log('Got chats:', store.chats.all())
306
- })
307
-
308
- sock.ev.on('contacts.upsert', () => {
309
- console.log('Got contacts:', Object.values(store.contacts))
310
- })
311
- ```
312
-
313
- > ⚠️ **Important:** Build your own data store for production. In-memory storage wastes RAM.
314
-
315
- ---
316
-
317
- ## 🔑 WhatsApp IDs
318
-
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`
325
-
326
- ---
327
-
328
- ## 💬 Sending Messages
329
-
330
- ### Text & Special Messages
331
-
332
- #### Text Message
333
- ```javascript
334
- await sock.sendMessage(jid, { text: 'Hello World!' })
335
- ```
336
-
337
- #### Quote Message (works with all types)
338
- ```javascript
339
- await sock.sendMessage(jid, { text: 'This is a reply' }, { quoted: message })
340
- ```
341
-
342
- #### Mention User (works with most types)
343
- ```javascript
344
- await sock.sendMessage(jid, {
345
- text: '@12345678901',
346
- mentions: ['12345678901@s.whatsapp.net']
347
- })
348
- ```
349
-
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
- )
362
- ```
363
-
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
- ```
373
-
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
- ```
394
-
395
- #### Request Payment
396
- ```javascript
397
- // Example non media sticker
398
- 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 })
407
-
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 })
418
-
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 })
429
- ```
430
-
431
- #### Event Message
432
- ```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 })
448
- ```
449
-
450
- #### Product Message
451
- ```javascript
452
- 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 })
473
- ```
474
-
475
- #### Carousel Message
476
- ```javascript
477
- 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 })
518
- ```
519
-
520
- #### Forward Messages
521
- ```javascript
522
- const msg = getMessageFromStore() // implement this on your end
523
- await sock.sendMessage(jid, { forward: msg })
524
- ```
525
-
526
- #### Location Message
527
- ```javascript
528
- await sock.sendMessage(jid, {
529
- location: {
530
- degreesLatitude: 24.121231,
531
- degreesLongitude: 55.1121221,
532
- name: "Location Name",
533
- address: "Location Address"
534
- }
535
- })
536
- ```
537
-
538
- #### Contact Message
539
- ```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'
546
-
547
- await sock.sendMessage(jid, {
548
- contacts: {
549
- displayName: 'John Doe',
550
- contacts: [{ vcard }]
551
- }
552
- })
553
- ```
554
-
555
- #### Reaction Message
556
- ```javascript
557
- await sock.sendMessage(jid, {
558
- react: {
559
- text: '💖', // use empty string to remove reaction
560
- key: message.key
561
- }
562
- })
563
- ```
564
-
565
- #### Pin Message
566
- ```javascript
567
- await sock.sendMessage(jid, {
568
- pin: {
569
- type: 1, // 0 to remove
570
- time: 86400, // 24 hours in seconds
571
- key: message.key
572
- }
573
- })
574
- ```
575
-
576
- **Pin Time Options:**
577
-
578
- | Time | Seconds |
579
- |------|-----------|
580
- | 24h | 86,400 |
581
- | 7d | 604,800 |
582
- | 30d | 2,592,000 |
583
-
584
- #### Keep Message
585
- ```javascript
586
- await sock.sendMessage(jid, {
587
- keep: message.key,
588
- type: 1, // 2 to unpin
589
- time: 86400
590
- })
591
- ```
592
-
593
- **Keep Time Options:**
594
-
595
- | Time | Seconds |
596
- |------|-----------|
597
- | 24h | 86,400 |
598
- | 7d | 604,800 |
599
- | 30d | 2,592,000 |
600
-
601
- #### Poll Message
602
- ```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
- })
611
- ```
612
-
613
- #### Link Preview
614
- ```javascript
615
- await sock.sendMessage(jid, {
616
- text: 'Check out https://github.com/nexustechpro/baileys'
617
- })
618
- ```
619
-
620
- ---
621
-
622
- ### Media Messages
623
-
624
- > 📝 **Note:** You can pass `{ stream: Stream }`, `{ url: Url }`, or `Buffer` directly
625
-
626
- #### Image Message
627
- ```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'
638
- })
639
-
640
- // From File
641
- await sock.sendMessage(jid, {
642
- image: fs.readFileSync('./image.jpg'),
643
- caption: 'Local image'
644
- })
645
- ```
646
-
647
- #### Video Message
648
- ```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
654
- })
655
- ```
656
-
657
- #### GIF Message
658
- ```javascript
659
- await sock.sendMessage(jid, {
660
- video: fs.readFileSync('Media/gif.mp4'),
661
- caption: 'Funny GIF',
662
- gifPlayback: true
663
- })
664
- ```
665
-
666
- #### Audio Message
667
- ```javascript
668
- await sock.sendMessage(jid, {
669
- audio: { url: './audio.mp3' },
670
- mimetype: 'audio/mp4',
671
- ptt: true // voice message
672
- })
673
- ```
674
-
675
- > 💡 **Audio Conversion Tip:**
676
- > ```bash
677
- > ffmpeg -i input.mp4 -avoid_negative_ts make_zero -ac 1 output.ogg
678
- > ```
679
-
680
- #### Document
681
- ```javascript
682
- await sock.sendMessage(jid, {
683
- document: { url: './document.pdf' },
684
- fileName: 'document.pdf',
685
- mimetype: 'application/pdf'
686
- })
687
- ```
688
-
689
- #### Sticker
690
- ```javascript
691
- await sock.sendMessage(jid, {
692
- sticker: { url: './sticker.webp' }
693
- })
694
- ```
695
-
696
- #### Sticker Pack
697
-
698
- ### Method 1: Direct Socket Method (Recommended)
699
- ```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 });
712
- ```
713
-
714
- ### Method 2: Via sendMessage
715
- ```javascript
716
- 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
728
- }
729
- }, { quoted: message });
730
- ```
731
-
732
- ### Supported Image Formats
733
-
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
- ```javascript
754
- await sock.sendMessage(jid, {
755
- image: { url: './secret.jpg' },
756
- viewOnce: true,
757
- caption: 'View once only!'
758
- })
759
- ```
760
-
761
- ---
762
-
763
- ### Buttons & Interactive Messages
764
-
765
- #### Simple Text with Buttons
766
- ```javascript
767
- 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
- ]
787
- })
788
- ```
789
-
790
- #### Image with Buttons
791
- ```javascript
792
- 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
- ]
805
- })
806
- ```
807
-
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
- ```
825
-
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
- ```
845
-
846
- ---
847
-
848
- ### All Button Types
849
-
850
- #### 1. Quick Reply
851
- ```javascript
852
- {
853
- name: "quick_reply",
854
- buttonParamsJson: JSON.stringify({
855
- display_text: "Quick Reply",
856
- id: "button_id"
857
- })
858
- }
859
- ```
860
-
861
- #### 2. URL Button
862
- ```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
- }
871
- ```
872
-
873
- #### 3. Call Button
874
- ```javascript
875
- {
876
- name: "cta_call",
877
- buttonParamsJson: JSON.stringify({
878
- display_text: "Call Us",
879
- phone_number: "+1234567890"
880
- })
881
- }
882
- ```
883
-
884
- #### 4. Copy Button
885
- ```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
- }
894
- ```
895
-
896
- #### 5. List/Single Select
897
- ```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
- }
912
- ```
913
-
914
- #### 6. Call Permission Request
915
- ```javascript
916
- {
917
- name: "call_permission_request",
918
- buttonParamsJson: JSON.stringify({
919
- has_multiple_buttons: true
920
- })
921
- }
922
- ```
923
-
924
- ---
925
-
926
- ### Classic Buttons (Old Style)
927
-
928
- For compatibility with older WhatsApp versions:
929
- ```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
- ```
948
-
949
- #### Header Types (Classic Buttons)
950
-
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 |
959
-
960
- #### Button Types (Classic Buttons)
961
-
962
- | Value | Type | Description |
963
- |-------|------|-------------|
964
- | `1` | RESPONSE | Standard clickable button |
965
- | `2` | NATIVE_FLOW | Native flow button |
966
-
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
- })
978
- ```
979
-
980
- ---
981
-
982
- ### Advanced: Native Flow Messages
983
-
984
- Complete example with all features:
985
- ```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
- }
1036
- })
1037
- ```
1038
-
1039
- ---
1040
-
1041
- ### Interactive Buttons (Alternative Format)
1042
- ```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 })
1066
-
1067
- // Example with media
1068
- 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
- ]
1091
- }, { quoted: message })
1092
-
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
- ]
1126
- }, { quoted: message })
1127
- ```
1128
-
1129
- ---
1130
-
1131
- ## ✏️ Message Modifications
1132
-
1133
- ### Delete Message (for everyone)
1134
- ```javascript
1135
- const msg = await sock.sendMessage(jid, { text: 'hello' })
1136
- await sock.sendMessage(jid, { delete: msg.key })
1137
- ```
1138
-
1139
- ### Edit Message
1140
- ```javascript
1141
- await sock.sendMessage(jid, {
1142
- text: 'Updated message text',
1143
- edit: originalMessage.key
1144
- })
1145
- ```
1146
-
1147
- ---
1148
-
1149
- ## 📥 Media Operations
1150
-
1151
- ### Download Media
1152
- ```javascript
1153
- import { downloadMediaMessage, getContentType } from '@nexustechpro/baileys'
1154
-
1155
- 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
- }
1174
- })
1175
- ```
1176
-
1177
- ### Re-upload Media
1178
- ```javascript
1179
- await sock.updateMediaMessage(msg)
1180
- ```
1181
-
1182
- ---
1183
-
1184
- ## 👥 Group Management
1185
-
1186
- ### Create Group
1187
- ```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
- ```
1194
-
1195
- ### Add/Remove Participants
1196
- ```javascript
1197
- // Add
1198
- await sock.groupParticipantsUpdate(groupJid, ['1234567890@s.whatsapp.net'], 'add')
1199
-
1200
- // Remove
1201
- await sock.groupParticipantsUpdate(groupJid, ['1234567890@s.whatsapp.net'], 'remove')
1202
-
1203
- // Promote to admin
1204
- await sock.groupParticipantsUpdate(groupJid, ['1234567890@s.whatsapp.net'], 'promote')
1205
-
1206
- // Demote from admin
1207
- await sock.groupParticipantsUpdate(groupJid, ['1234567890@s.whatsapp.net'], 'demote')
1208
- ```
1209
-
1210
- ### Update Group Subject
1211
- ```javascript
1212
- 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')
1227
-
1228
- // Only admins can edit group info
1229
- await sock.groupSettingUpdate(groupJid, 'locked')
1230
-
1231
- // Everyone can edit group info
1232
- await sock.groupSettingUpdate(groupJid, 'unlocked')
1233
- ```
1234
-
1235
- ### Get Group Metadata
1236
- ```javascript
1237
- const metadata = await sock.groupMetadata(groupJid)
1238
- console.log('Group:', metadata.subject)
1239
- console.log('Participants:', metadata.participants.length)
1240
- ```
1241
-
1242
- ### Get Invite Code
1243
- ```javascript
1244
- const code = await sock.groupInviteCode(groupJid)
1245
- console.log('Invite link:', `https://chat.whatsapp.com/${code}`)
1246
- ```
1247
-
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)
1268
- ```
1269
-
1270
- ---
1271
-
1272
- ## 📱 User Operations
1273
-
1274
- ### Check if Number Exists
1275
- ```javascript
1276
- 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)
1286
-
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
1300
- await sock.removeProfilePicture(jid)
1301
- ```
1302
-
1303
- ### Get Status
1304
- ```javascript
1305
- const status = await sock.fetchStatus(jid)
1306
- console.log('Status:', status)
1307
- ```
1308
-
1309
- ### Update Profile Status
1310
- ```javascript
1311
- await sock.updateProfileStatus('Available 24/7')
1312
- ```
1313
-
1314
- ### Update Profile Name
1315
- ```javascript
1316
- await sock.updateProfileName('NexusTech Bot')
1317
- ```
1318
-
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
1328
- await sock.presenceSubscribe(jid)
1329
-
1330
- // Send presence
1331
- await sock.sendPresenceUpdate('available', jid) // available, unavailable, composing, recording, paused
1332
- ```
1333
-
1334
- ### Read Messages
1335
- ```javascript
1336
- await sock.readMessages([message.key])
1337
- ```
1338
-
1339
- ---
1340
-
1341
- ## 🔒 Privacy Controls
1342
-
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
- ```javascript
1354
- const settings = await sock.fetchPrivacySettings()
1355
- console.log(settings)
1356
- ```
1357
-
1358
- ### Update Privacy Settings
1359
- ```javascript
1360
- // Last seen: 'all', 'contacts', 'contact_blacklist', 'none'
1361
- await sock.updateLastSeenPrivacy('contacts')
1362
-
1363
- // Online: 'all', 'match_last_seen'
1364
- await sock.updateOnlinePrivacy('all')
1365
-
1366
- // Profile picture: 'all', 'contacts', 'contact_blacklist', 'none'
1367
- await sock.updateProfilePicturePrivacy('contacts')
1368
-
1369
- // Status: 'all', 'contacts', 'contact_blacklist', 'none'
1370
- await sock.updateStatusPrivacy('contacts')
1371
-
1372
- // Read receipts: 'all', 'none'
1373
- await sock.updateReadReceiptsPrivacy('all')
1374
-
1375
- // Groups add: 'all', 'contacts', 'contact_blacklist'
1376
- await sock.updateGroupsAddPrivacy('contacts')
1377
- ```
1378
-
1379
- ### Get Block List
1380
- ```javascript
1381
- const blocklist = await sock.fetchBlocklist()
1382
- console.log('Blocked users:', blocklist)
1383
- ```
1384
-
1385
- ---
1386
-
1387
- ## 💬 Chat Operations
1388
-
1389
- ### Archive/Unarchive Chat
1390
- ```javascript
1391
- const lastMsg = await getLastMessageInChat(jid)
1392
-
1393
- await sock.chatModify({
1394
- archive: true,
1395
- lastMessages: [lastMsg]
1396
- }, jid)
1397
- ```
1398
-
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
- ```
1411
-
1412
- ### Pin/Unpin Chat
1413
- ```javascript
1414
- // Pin
1415
- await sock.chatModify({ pin: true }, jid)
1416
-
1417
- // Unpin
1418
- await sock.chatModify({ pin: false }, jid)
1419
- ```
1420
-
1421
- ### Delete Chat
1422
- ```javascript
1423
- const lastMsg = await getLastMessageInChat(jid)
1424
-
1425
- await sock.chatModify({
1426
- delete: true,
1427
- lastMessages: [{
1428
- key: lastMsg.key,
1429
- messageTimestamp: lastMsg.messageTimestamp
1430
- }]
1431
- }, jid)
1432
- ```
1433
-
1434
- ### Mark Chat as Read/Unread
1435
- ```javascript
1436
- // Mark as read
1437
- await sock.chatModify({ markRead: true }, jid)
1438
-
1439
- // Mark as unread
1440
- await sock.chatModify({ markRead: false }, jid)
1441
- ```
1442
-
1443
- ---
1444
-
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
- ```
1458
-
1459
- ### Send Story/Status
1460
- ```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
- })
1474
-
1475
- // Update newsletter metadata
1476
- await sock.newsletterUpdateMetadata(newsletterJid, {
1477
- name: 'New Name',
1478
- description: 'New description'
1479
- })
1480
-
1481
- // Update newsletter picture
1482
- await sock.newsletterUpdatePicture(newsletterJid, buffer)
1483
-
1484
- // React to newsletter message
1485
- await sock.newsletterReactMessage(newsletterJid, messageId, '👍')
1486
-
1487
- // Follow newsletter
1488
- await sock.newsletterFollow(newsletterJid)
1489
-
1490
- // Unfollow newsletter
1491
- await sock.newsletterUnfollow(newsletterJid)
1492
-
1493
- // Mute newsletter
1494
- await sock.newsletterMute(newsletterJid)
1495
-
1496
- // Unmute newsletter
1497
- await sock.newsletterUnmute(newsletterJid)
1498
- ```
1499
-
1500
- ---
1501
-
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
- ```
1541
-
1542
- ---
1543
-
1544
- ## 🎯 Best Practices
1545
-
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
- ```
1555
-
1556
- ### 2. Store Implementation
1557
- ```javascript
1558
- import { makeInMemoryStore } from '@nexustechpro/baileys'
1559
-
1560
- const store = makeInMemoryStore({})
1561
- store.readFromFile('./store.json')
1562
-
1563
- setInterval(() => {
1564
- store.writeToFile('./store.json')
1565
- }, 10_000)
1566
-
1567
- store.bind(sock.ev)
1568
- ```
1569
-
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
- ```
1582
-
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
- }
1598
- })
1599
- ```
1600
-
1601
- ### 5. Rate Limiting
1602
- ```javascript
1603
- const queue = []
1604
- const sending = false
1605
-
1606
- async function queueMessage(jid, message) {
1607
- queue.push({ jid, message })
1608
- if(!sending) processQueue()
1609
- }
1610
-
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
1619
- }
1620
- ```
1621
-
1622
- ---
1623
-
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
- ```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'
1686
- ```
1687
-
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
- ---
1701
-
1702
- ## 📄 License
1703
-
1704
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
1705
-
1706
- ---
1707
-
1708
- ## ⚠️ Disclaimer
1709
-
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.
1711
-
1712
- **Important**:
1713
- - Follow WhatsApp's Terms of Service
1714
- - Don't spam or send unsolicited messages
1715
- - Respect user privacy
1716
- - Use for legitimate purposes only
1717
- - Be aware of WhatsApp's rate limits
1718
-
1719
- ---
1720
-
1721
- ## 🙏 Acknowledgments
1722
-
1723
- Special thanks to:
1724
- - [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
1727
-
1728
- ---
1729
-
1730
- ## 📞 Support
1731
-
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)
1735
-
1736
- ---
1737
-
1738
- <div align="center">
1739
-
1740
- **Made with ❤️ by [NexusTechPro](https://github.com/nexustechpro)**
1741
-
1742
- ⭐ **Star us on GitHub!** ⭐
1743
-
1744
- [GitHub](https://github.com/nexustechpro/baileys) • [NPM](https://www.npmjs.com/package/@nexustechpro/baileys) • [Documentation](https://github.com/nexustechpro/baileys/wiki)
1745
-
1
+ # 🚀 NexusTechPro Baileys
2
+
3
+ <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
+
20
+ ## 📋 Table of Contents
21
+
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)
43
+
44
+ ---
45
+
46
+ ## ✨ Features
47
+
48
+ <table>
49
+ <tr>
50
+ <td>
51
+
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
59
+
60
+ </td>
61
+ <td>
62
+
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
70
+
71
+ </td>
72
+ </tr>
73
+ </table>
74
+
75
+ ---
76
+
77
+ ## 📦 Installation
78
+
79
+ ### NPM
80
+ ```bash
81
+ npm install @nexustechpro/baileys
82
+ ```
83
+
84
+ ### Yarn
85
+ ```bash
86
+ yarn add @nexustechpro/baileys
87
+ ```
88
+
89
+ ### Using Different Package Name
90
+ Add to your `package.json`:
91
+ ```json
92
+ {
93
+ "dependencies": {
94
+ "@whiskeysockets/baileys": "npm:@nexustechpro/baileys"
95
+ }
96
+ }
97
+ ```
98
+
99
+ ### Import
100
+ ```javascript
101
+ // ESM
102
+ import makeWASocket from '@nexustechpro/baileys'
103
+
104
+ // CommonJS
105
+ const { default: makeWASocket } = require('@nexustechpro/baileys')
106
+ ```
107
+
108
+ ---
109
+
110
+ ## 🔌 Quick Start
111
+ ```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
+ })
144
+
145
+ sock.ev.on('creds.update', saveCreds)
146
+ }
147
+
148
+ connectToWhatsApp()
149
+ ```
150
+
151
+ ---
152
+
153
+ ## 🔐 Authentication
154
+
155
+ ### QR Code Authentication
156
+ ```javascript
157
+ import makeWASocket from '@nexustechpro/baileys'
158
+
159
+ const sock = makeWASocket({
160
+ auth: state,
161
+ printQRInTerminal: true,
162
+ browser: ['NexusTechPro Bot', 'Chrome', '1.0.0']
163
+ })
164
+ ```
165
+
166
+ ### Pairing Code Authentication
167
+ ```javascript
168
+ const sock = makeWASocket({
169
+ auth: state,
170
+ printQRInTerminal: false
171
+ })
172
+
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}`)
177
+ }
178
+ ```
179
+
180
+ ### Custom Pairing Code
181
+ ```javascript
182
+ const phoneNumber = "628XXXXX"
183
+ const code = await sock.requestPairingCode(phoneNumber.trim(), "NEXUS01")
184
+ console.log("Your pairing code: " + code)
185
+ ```
186
+
187
+ ---
188
+
189
+ ## 💡 Socket Configuration
190
+
191
+ ### Cache Group Metadata (Recommended)
192
+ ```javascript
193
+ const groupCache = new NodeCache({ stdTTL: 5 * 60, useClones: false })
194
+
195
+ const sock = makeWASocket({
196
+ cachedGroupMetadata: async (jid) => groupCache.get(jid)
197
+ })
198
+
199
+ sock.ev.on('groups.update', async ([event]) => {
200
+ const metadata = await sock.groupMetadata(event.id)
201
+ groupCache.set(event.id, metadata)
202
+ })
203
+ ```
204
+
205
+ ### Improve Retry & Poll Decryption
206
+ ```javascript
207
+ const sock = makeWASocket({
208
+ getMessage: async (key) => await getMessageFromStore(key)
209
+ })
210
+ ```
211
+
212
+ ### Receive Notifications in WhatsApp App
213
+ ```javascript
214
+ const sock = makeWASocket({
215
+ markOnlineOnConnect: false
216
+ })
217
+ ```
218
+
219
+ ---
220
+
221
+ ## 💾 Session Management
222
+
223
+ Avoid scanning QR every time:
224
+ ```javascript
225
+ import makeWASocket, { useMultiFileAuthState } from '@nexustechpro/baileys'
226
+
227
+ const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
228
+ const sock = makeWASocket({ auth: state })
229
+
230
+ sock.ev.on('creds.update', saveCreds)
231
+ ```
232
+
233
+ > 💡 **Tip:** For production, store auth in a database instead of files.
234
+
235
+ ---
236
+
237
+ ## 📡 Event Handling
238
+
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
+ ```
252
+
253
+ ### New Messages
254
+ ```javascript
255
+ sock.ev.on('messages.upsert', async ({ messages }) => {
256
+ for(const msg of messages) {
257
+ console.log('New message:', msg)
258
+ }
259
+ })
260
+ ```
261
+
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
+ ```
270
+
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
+ ```
287
+
288
+ ---
289
+
290
+ ## 🛠️ Data Store
291
+ ```javascript
292
+ import makeWASocket, { makeInMemoryStore } from '@nexustechpro/baileys'
293
+
294
+ const store = makeInMemoryStore({})
295
+ store.readFromFile('./baileys_store.json')
296
+
297
+ setInterval(() => {
298
+ store.writeToFile('./baileys_store.json')
299
+ }, 10_000)
300
+
301
+ const sock = makeWASocket({})
302
+ store.bind(sock.ev)
303
+
304
+ sock.ev.on('chats.upsert', () => {
305
+ console.log('Got chats:', store.chats.all())
306
+ })
307
+
308
+ sock.ev.on('contacts.upsert', () => {
309
+ console.log('Got contacts:', Object.values(store.contacts))
310
+ })
311
+ ```
312
+
313
+ > ⚠️ **Important:** Build your own data store for production. In-memory storage wastes RAM.
314
+
315
+ ---
316
+
317
+ ## 🔑 WhatsApp IDs
318
+
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`
325
+
326
+ ---
327
+
328
+ ## 💬 Sending Messages
329
+
330
+ ### Text & Special Messages
331
+
332
+ #### Text Message
333
+ ```javascript
334
+ await sock.sendMessage(jid, { text: 'Hello World!' })
335
+ ```
336
+
337
+ #### Quote Message (works with all types)
338
+ ```javascript
339
+ await sock.sendMessage(jid, { text: 'This is a reply' }, { quoted: message })
340
+ ```
341
+
342
+ #### Mention User (works with most types)
343
+ ```javascript
344
+ await sock.sendMessage(jid, {
345
+ text: '@12345678901',
346
+ mentions: ['12345678901@s.whatsapp.net']
347
+ })
348
+ ```
349
+
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
+ )
362
+ ```
363
+
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
+ ```
373
+
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
+ ```
394
+
395
+ #### Request Payment
396
+ ```javascript
397
+ // Example non media sticker
398
+ 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 })
407
+
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 })
418
+
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 })
429
+ ```
430
+
431
+ #### Event Message
432
+ ```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 })
448
+ ```
449
+
450
+ #### Product Message
451
+ ```javascript
452
+ 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 })
473
+ ```
474
+
475
+ #### Carousel Message
476
+ ```javascript
477
+ 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 })
518
+ ```
519
+
520
+ #### Forward Messages
521
+ ```javascript
522
+ const msg = getMessageFromStore() // implement this on your end
523
+ await sock.sendMessage(jid, { forward: msg })
524
+ ```
525
+
526
+ #### Location Message
527
+ ```javascript
528
+ await sock.sendMessage(jid, {
529
+ location: {
530
+ degreesLatitude: 24.121231,
531
+ degreesLongitude: 55.1121221,
532
+ name: "Location Name",
533
+ address: "Location Address"
534
+ }
535
+ })
536
+ ```
537
+
538
+ #### Contact Message
539
+ ```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'
546
+
547
+ await sock.sendMessage(jid, {
548
+ contacts: {
549
+ displayName: 'John Doe',
550
+ contacts: [{ vcard }]
551
+ }
552
+ })
553
+ ```
554
+
555
+ #### Reaction Message
556
+ ```javascript
557
+ await sock.sendMessage(jid, {
558
+ react: {
559
+ text: '💖', // use empty string to remove reaction
560
+ key: message.key
561
+ }
562
+ })
563
+ ```
564
+
565
+ #### Pin Message
566
+ ```javascript
567
+ await sock.sendMessage(jid, {
568
+ pin: {
569
+ type: 1, // 0 to remove
570
+ time: 86400, // 24 hours in seconds
571
+ key: message.key
572
+ }
573
+ })
574
+ ```
575
+
576
+ **Pin Time Options:**
577
+
578
+ | Time | Seconds |
579
+ |------|-----------|
580
+ | 24h | 86,400 |
581
+ | 7d | 604,800 |
582
+ | 30d | 2,592,000 |
583
+
584
+ #### Keep Message
585
+ ```javascript
586
+ await sock.sendMessage(jid, {
587
+ keep: message.key,
588
+ type: 1, // 2 to unpin
589
+ time: 86400
590
+ })
591
+ ```
592
+
593
+ **Keep Time Options:**
594
+
595
+ | Time | Seconds |
596
+ |------|-----------|
597
+ | 24h | 86,400 |
598
+ | 7d | 604,800 |
599
+ | 30d | 2,592,000 |
600
+
601
+ #### Poll Message
602
+ ```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
+ })
611
+ ```
612
+
613
+ #### Link Preview
614
+ ```javascript
615
+ await sock.sendMessage(jid, {
616
+ text: 'Check out https://github.com/nexustechpro1/baileys'
617
+ })
618
+ ```
619
+
620
+ ---
621
+
622
+ ### Media Messages
623
+
624
+ > 📝 **Note:** You can pass `{ stream: Stream }`, `{ url: Url }`, or `Buffer` directly
625
+
626
+ #### Image Message
627
+ ```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'
638
+ })
639
+
640
+ // From File
641
+ await sock.sendMessage(jid, {
642
+ image: fs.readFileSync('./image.jpg'),
643
+ caption: 'Local image'
644
+ })
645
+ ```
646
+
647
+ #### Video Message
648
+ ```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
654
+ })
655
+ ```
656
+
657
+ #### GIF Message
658
+ ```javascript
659
+ await sock.sendMessage(jid, {
660
+ video: fs.readFileSync('Media/gif.mp4'),
661
+ caption: 'Funny GIF',
662
+ gifPlayback: true
663
+ })
664
+ ```
665
+
666
+ #### Audio Message
667
+ ```javascript
668
+ await sock.sendMessage(jid, {
669
+ audio: { url: './audio.mp3' },
670
+ mimetype: 'audio/mp4',
671
+ ptt: true // voice message
672
+ })
673
+ ```
674
+
675
+ > 💡 **Audio Conversion Tip:**
676
+ > ```bash
677
+ > ffmpeg -i input.mp4 -avoid_negative_ts make_zero -ac 1 output.ogg
678
+ > ```
679
+
680
+ #### Document
681
+ ```javascript
682
+ await sock.sendMessage(jid, {
683
+ document: { url: './document.pdf' },
684
+ fileName: 'document.pdf',
685
+ mimetype: 'application/pdf'
686
+ })
687
+ ```
688
+
689
+ #### Sticker
690
+ ```javascript
691
+ await sock.sendMessage(jid, {
692
+ sticker: { url: './sticker.webp' }
693
+ })
694
+ ```
695
+
696
+ #### Sticker Pack
697
+
698
+ ### Method 1: Direct Socket Method (Recommended)
699
+ ```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 });
712
+ ```
713
+
714
+ ### Method 2: Via sendMessage
715
+ ```javascript
716
+ 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
728
+ }
729
+ }, { quoted: message });
730
+ ```
731
+
732
+ ### Supported Image Formats
733
+
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
+ ```javascript
754
+ await sock.sendMessage(jid, {
755
+ image: { url: './secret.jpg' },
756
+ viewOnce: true,
757
+ caption: 'View once only!'
758
+ })
759
+ ```
760
+
761
+ ---
762
+
763
+ ### Buttons & Interactive Messages
764
+
765
+ #### Simple Text with Buttons
766
+ ```javascript
767
+ 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
+ ]
787
+ })
788
+ ```
789
+
790
+ #### Image with Buttons
791
+ ```javascript
792
+ 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
+ ]
805
+ })
806
+ ```
807
+
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
+ ```
825
+
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
+ ```
845
+
846
+ ---
847
+
848
+ ### All Button Types
849
+
850
+ #### 1. Quick Reply
851
+ ```javascript
852
+ {
853
+ name: "quick_reply",
854
+ buttonParamsJson: JSON.stringify({
855
+ display_text: "Quick Reply",
856
+ id: "button_id"
857
+ })
858
+ }
859
+ ```
860
+
861
+ #### 2. URL Button
862
+ ```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
+ }
871
+ ```
872
+
873
+ #### 3. Call Button
874
+ ```javascript
875
+ {
876
+ name: "cta_call",
877
+ buttonParamsJson: JSON.stringify({
878
+ display_text: "Call Us",
879
+ phone_number: "+1234567890"
880
+ })
881
+ }
882
+ ```
883
+
884
+ #### 4. Copy Button
885
+ ```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
+ }
894
+ ```
895
+
896
+ #### 5. List/Single Select
897
+ ```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
+ }
912
+ ```
913
+
914
+ #### 6. Call Permission Request
915
+ ```javascript
916
+ {
917
+ name: "call_permission_request",
918
+ buttonParamsJson: JSON.stringify({
919
+ has_multiple_buttons: true
920
+ })
921
+ }
922
+ ```
923
+
924
+ ---
925
+
926
+ ### Classic Buttons (Old Style)
927
+
928
+ For compatibility with older WhatsApp versions:
929
+ ```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
+ ```
948
+
949
+ #### Header Types (Classic Buttons)
950
+
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 |
959
+
960
+ #### Button Types (Classic Buttons)
961
+
962
+ | Value | Type | Description |
963
+ |-------|------|-------------|
964
+ | `1` | RESPONSE | Standard clickable button |
965
+ | `2` | NATIVE_FLOW | Native flow button |
966
+
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
+ })
978
+ ```
979
+
980
+ ---
981
+
982
+ ### Advanced: Native Flow Messages
983
+
984
+ Complete example with all features:
985
+ ```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
+ }
1036
+ })
1037
+ ```
1038
+
1039
+ ---
1040
+
1041
+ ### Interactive Buttons (Alternative Format)
1042
+ ```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 })
1066
+
1067
+ // Example with media
1068
+ 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
+ ]
1091
+ }, { quoted: message })
1092
+
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
+ ]
1126
+ }, { quoted: message })
1127
+ ```
1128
+
1129
+ ---
1130
+
1131
+ ## ✏️ Message Modifications
1132
+
1133
+ ### Delete Message (for everyone)
1134
+ ```javascript
1135
+ const msg = await sock.sendMessage(jid, { text: 'hello' })
1136
+ await sock.sendMessage(jid, { delete: msg.key })
1137
+ ```
1138
+
1139
+ ### Edit Message
1140
+ ```javascript
1141
+ await sock.sendMessage(jid, {
1142
+ text: 'Updated message text',
1143
+ edit: originalMessage.key
1144
+ })
1145
+ ```
1146
+
1147
+ ---
1148
+
1149
+ ## 📥 Media Operations
1150
+
1151
+ ### Download Media
1152
+ ```javascript
1153
+ import { downloadMediaMessage, getContentType } from '@nexustechpro/baileys'
1154
+
1155
+ 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
+ }
1174
+ })
1175
+ ```
1176
+
1177
+ ### Re-upload Media
1178
+ ```javascript
1179
+ await sock.updateMediaMessage(msg)
1180
+ ```
1181
+
1182
+ ---
1183
+
1184
+ ## 👥 Group Management
1185
+
1186
+ ### Create Group
1187
+ ```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
+ ```
1194
+
1195
+ ### Add/Remove Participants
1196
+ ```javascript
1197
+ // Add
1198
+ await sock.groupParticipantsUpdate(groupJid, ['1234567890@s.whatsapp.net'], 'add')
1199
+
1200
+ // Remove
1201
+ await sock.groupParticipantsUpdate(groupJid, ['1234567890@s.whatsapp.net'], 'remove')
1202
+
1203
+ // Promote to admin
1204
+ await sock.groupParticipantsUpdate(groupJid, ['1234567890@s.whatsapp.net'], 'promote')
1205
+
1206
+ // Demote from admin
1207
+ await sock.groupParticipantsUpdate(groupJid, ['1234567890@s.whatsapp.net'], 'demote')
1208
+ ```
1209
+
1210
+ ### Update Group Subject
1211
+ ```javascript
1212
+ 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')
1227
+
1228
+ // Only admins can edit group info
1229
+ await sock.groupSettingUpdate(groupJid, 'locked')
1230
+
1231
+ // Everyone can edit group info
1232
+ await sock.groupSettingUpdate(groupJid, 'unlocked')
1233
+ ```
1234
+
1235
+ ### Get Group Metadata
1236
+ ```javascript
1237
+ const metadata = await sock.groupMetadata(groupJid)
1238
+ console.log('Group:', metadata.subject)
1239
+ console.log('Participants:', metadata.participants.length)
1240
+ ```
1241
+
1242
+ ### Get Invite Code
1243
+ ```javascript
1244
+ const code = await sock.groupInviteCode(groupJid)
1245
+ console.log('Invite link:', `https://chat.whatsapp.com/${code}`)
1246
+ ```
1247
+
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)
1268
+ ```
1269
+
1270
+ ---
1271
+
1272
+ ## 📱 User Operations
1273
+
1274
+ ### Check if Number Exists
1275
+ ```javascript
1276
+ 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)
1286
+
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
1300
+ await sock.removeProfilePicture(jid)
1301
+ ```
1302
+
1303
+ ### Get Status
1304
+ ```javascript
1305
+ const status = await sock.fetchStatus(jid)
1306
+ console.log('Status:', status)
1307
+ ```
1308
+
1309
+ ### Update Profile Status
1310
+ ```javascript
1311
+ await sock.updateProfileStatus('Available 24/7')
1312
+ ```
1313
+
1314
+ ### Update Profile Name
1315
+ ```javascript
1316
+ await sock.updateProfileName('NexusTech Bot')
1317
+ ```
1318
+
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
1328
+ await sock.presenceSubscribe(jid)
1329
+
1330
+ // Send presence
1331
+ await sock.sendPresenceUpdate('available', jid) // available, unavailable, composing, recording, paused
1332
+ ```
1333
+
1334
+ ### Read Messages
1335
+ ```javascript
1336
+ await sock.readMessages([message.key])
1337
+ ```
1338
+
1339
+ ---
1340
+
1341
+ ## 🔒 Privacy Controls
1342
+
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
+ ```javascript
1354
+ const settings = await sock.fetchPrivacySettings()
1355
+ console.log(settings)
1356
+ ```
1357
+
1358
+ ### Update Privacy Settings
1359
+ ```javascript
1360
+ // Last seen: 'all', 'contacts', 'contact_blacklist', 'none'
1361
+ await sock.updateLastSeenPrivacy('contacts')
1362
+
1363
+ // Online: 'all', 'match_last_seen'
1364
+ await sock.updateOnlinePrivacy('all')
1365
+
1366
+ // Profile picture: 'all', 'contacts', 'contact_blacklist', 'none'
1367
+ await sock.updateProfilePicturePrivacy('contacts')
1368
+
1369
+ // Status: 'all', 'contacts', 'contact_blacklist', 'none'
1370
+ await sock.updateStatusPrivacy('contacts')
1371
+
1372
+ // Read receipts: 'all', 'none'
1373
+ await sock.updateReadReceiptsPrivacy('all')
1374
+
1375
+ // Groups add: 'all', 'contacts', 'contact_blacklist'
1376
+ await sock.updateGroupsAddPrivacy('contacts')
1377
+ ```
1378
+
1379
+ ### Get Block List
1380
+ ```javascript
1381
+ const blocklist = await sock.fetchBlocklist()
1382
+ console.log('Blocked users:', blocklist)
1383
+ ```
1384
+
1385
+ ---
1386
+
1387
+ ## 💬 Chat Operations
1388
+
1389
+ ### Archive/Unarchive Chat
1390
+ ```javascript
1391
+ const lastMsg = await getLastMessageInChat(jid)
1392
+
1393
+ await sock.chatModify({
1394
+ archive: true,
1395
+ lastMessages: [lastMsg]
1396
+ }, jid)
1397
+ ```
1398
+
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
+ ```
1411
+
1412
+ ### Pin/Unpin Chat
1413
+ ```javascript
1414
+ // Pin
1415
+ await sock.chatModify({ pin: true }, jid)
1416
+
1417
+ // Unpin
1418
+ await sock.chatModify({ pin: false }, jid)
1419
+ ```
1420
+
1421
+ ### Delete Chat
1422
+ ```javascript
1423
+ const lastMsg = await getLastMessageInChat(jid)
1424
+
1425
+ await sock.chatModify({
1426
+ delete: true,
1427
+ lastMessages: [{
1428
+ key: lastMsg.key,
1429
+ messageTimestamp: lastMsg.messageTimestamp
1430
+ }]
1431
+ }, jid)
1432
+ ```
1433
+
1434
+ ### Mark Chat as Read/Unread
1435
+ ```javascript
1436
+ // Mark as read
1437
+ await sock.chatModify({ markRead: true }, jid)
1438
+
1439
+ // Mark as unread
1440
+ await sock.chatModify({ markRead: false }, jid)
1441
+ ```
1442
+
1443
+ ---
1444
+
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
+ ```
1458
+
1459
+ ### Send Story/Status
1460
+ ```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
+ })
1474
+
1475
+ // Update newsletter metadata
1476
+ await sock.newsletterUpdateMetadata(newsletterJid, {
1477
+ name: 'New Name',
1478
+ description: 'New description'
1479
+ })
1480
+
1481
+ // Update newsletter picture
1482
+ await sock.newsletterUpdatePicture(newsletterJid, buffer)
1483
+
1484
+ // React to newsletter message
1485
+ await sock.newsletterReactMessage(newsletterJid, messageId, '👍')
1486
+
1487
+ // Follow newsletter
1488
+ await sock.newsletterFollow(newsletterJid)
1489
+
1490
+ // Unfollow newsletter
1491
+ await sock.newsletterUnfollow(newsletterJid)
1492
+
1493
+ // Mute newsletter
1494
+ await sock.newsletterMute(newsletterJid)
1495
+
1496
+ // Unmute newsletter
1497
+ await sock.newsletterUnmute(newsletterJid)
1498
+ ```
1499
+
1500
+ ---
1501
+
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
+ ```
1541
+
1542
+ ---
1543
+
1544
+ ## 🎯 Best Practices
1545
+
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
+ ```
1555
+
1556
+ ### 2. Store Implementation
1557
+ ```javascript
1558
+ import { makeInMemoryStore } from '@nexustechpro/baileys'
1559
+
1560
+ const store = makeInMemoryStore({})
1561
+ store.readFromFile('./store.json')
1562
+
1563
+ setInterval(() => {
1564
+ store.writeToFile('./store.json')
1565
+ }, 10_000)
1566
+
1567
+ store.bind(sock.ev)
1568
+ ```
1569
+
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
+ ```
1582
+
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
+ }
1598
+ })
1599
+ ```
1600
+
1601
+ ### 5. Rate Limiting
1602
+ ```javascript
1603
+ const queue = []
1604
+ const sending = false
1605
+
1606
+ async function queueMessage(jid, message) {
1607
+ queue.push({ jid, message })
1608
+ if(!sending) processQueue()
1609
+ }
1610
+
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
1619
+ }
1620
+ ```
1621
+
1622
+ ---
1623
+
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
+ ```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'
1686
+ ```
1687
+
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
+ ---
1701
+
1702
+ ## 📄 License
1703
+
1704
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
1705
+
1706
+ ---
1707
+
1708
+ ## ⚠️ Disclaimer
1709
+
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.
1711
+
1712
+ **Important**:
1713
+ - Follow WhatsApp's Terms of Service
1714
+ - Don't spam or send unsolicited messages
1715
+ - Respect user privacy
1716
+ - Use for legitimate purposes only
1717
+ - Be aware of WhatsApp's rate limits
1718
+
1719
+ ---
1720
+
1721
+ ## 🙏 Acknowledgments
1722
+
1723
+ Special thanks to:
1724
+ - [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
1727
+
1728
+ ---
1729
+
1730
+ ## 📞 Support
1731
+
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)
1735
+
1736
+ ---
1737
+
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)
1745
+
1746
1746
  </div>