davexbaileys 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +222 -44
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,15 +1,29 @@
1
1
  <div align="center">
2
- <h1>davexbaileys</h1>
3
- <p>A WebSocket-based JavaScript library for interacting with the WhatsApp Web API</p>
4
2
 
5
- [![npm version](https://img.shields.io/npm/v/davexbaileys.svg)](https://www.npmjs.com/package/davexbaileys)
6
- [![npm downloads](https://img.shields.io/npm/dm/davexbaileys.svg)](https://www.npmjs.com/package/davexbaileys)
7
- [![License](https://img.shields.io/npm/l/davexbaileys.svg)](https://github.com/Davex-254/davebaileys/blob/main/LICENSE)
3
+ # davexbaileys
4
+
5
+ **A fast, lightweight WhatsApp Web API library for Node.js**
6
+
7
+ [![npm](https://img.shields.io/npm/v/davexbaileys?color=crimson)](https://www.npmjs.com/package/davexbaileys)
8
+ [![npm downloads](https://img.shields.io/npm/dm/davexbaileys)](https://www.npmjs.com/package/davexbaileys)
9
+ [![license](https://img.shields.io/npm/l/davexbaileys)](https://github.com/Davex-254/davebaileys/blob/main/LICENSE)
10
+
8
11
  </div>
9
12
 
10
- ## Disclaimer
13
+ ---
14
+
15
+ > **Disclaimer:** This project is not affiliated with or endorsed by WhatsApp. Use responsibly. Do not use for spam, bulk messaging, or stalkerware.
16
+
17
+ ---
11
18
 
12
- This project is not affiliated, associated, authorized, endorsed by, or in any way officially connected with WhatsApp or any of its subsidiaries or affiliates. Use at your own discretion. Do not spam people with this. We discourage any stalkerware, bulk or automated messaging usage.
19
+ ## Why davexbaileys?
20
+
21
+ - No browser, no Selenium — connects directly via **WebSocket**
22
+ - Based on the latest official WhatsApp multi-device protocol
23
+ - Built-in fix for the **428 reconnection loop** that kills deployed bots
24
+ - Pure ESM — works cleanly with modern Node.js (v20+)
25
+
26
+ ---
13
27
 
14
28
  ## Installation
15
29
 
@@ -17,60 +31,224 @@ This project is not affiliated, associated, authorized, endorsed by, or in any w
17
31
  npm install davexbaileys
18
32
  ```
19
33
 
20
- Or using yarn:
21
- ```bash
22
- yarn add davexbaileys
23
- ```
34
+ ---
24
35
 
25
- ## Quick Start
36
+ ## Requirements
26
37
 
27
- This package is pure ESM. Use `import` syntax:
38
+ - **Node.js v20 or higher**
39
+ - This package is **ESM only** — use `import`, not `require`
28
40
 
29
- ```javascript
30
- import makeWASocket, { useMultiFileAuthState, Browsers } from 'davexbaileys'
31
- ```
41
+ ---
32
42
 
33
- ### Basic Connection Example
43
+ ## Getting Started
34
44
 
35
- ```javascript
45
+ ### Save & Restore Session
46
+
47
+ ```js
36
48
  import makeWASocket, { useMultiFileAuthState, DisconnectReason } from 'davexbaileys'
37
49
  import { Boom } from '@hapi/boom'
38
50
 
39
- const { state, saveCreds } = await useMultiFileAuthState('auth_info')
51
+ async function start() {
52
+ const { state, saveCreds } = await useMultiFileAuthState('session')
40
53
 
41
- const sock = makeWASocket({
42
- auth: state,
43
- printQRInTerminal: false
54
+ const sock = makeWASocket({ auth: state })
55
+
56
+ sock.ev.on('creds.update', saveCreds)
57
+
58
+ sock.ev.on('connection.update', ({ connection, lastDisconnect, qr }) => {
59
+ if (qr) console.log('QR code:', qr)
60
+
61
+ if (connection === 'close') {
62
+ const code = lastDisconnect?.error?.output?.statusCode
63
+ if (code !== DisconnectReason.loggedOut) start()
64
+ } else if (connection === 'open') {
65
+ console.log('Connected!')
66
+ }
67
+ })
68
+
69
+ sock.ev.on('messages.upsert', async ({ messages }) => {
70
+ for (const msg of messages) {
71
+ console.log(msg)
72
+ }
73
+ })
74
+ }
75
+
76
+ start()
77
+ ```
78
+
79
+ ### Connect with Pairing Code (no QR)
80
+
81
+ ```js
82
+ const sock = makeWASocket({ auth: state })
83
+
84
+ if (!sock.authState.creds.registered) {
85
+ const code = await sock.requestPairingCode('2547XXXXXXXX') // full number, no +
86
+ console.log('Pairing code:', code)
87
+ }
88
+ ```
89
+
90
+ ---
91
+
92
+ ## Sending Messages
93
+
94
+ ```js
95
+ // Text
96
+ await sock.sendMessage(jid, { text: 'Hello!' })
97
+
98
+ // Reply / quote
99
+ await sock.sendMessage(jid, { text: 'Got it' }, { quoted: msg })
100
+
101
+ // Mention someone
102
+ await sock.sendMessage(jid, {
103
+ text: '@254700000000 hey!',
104
+ mentions: ['254700000000@s.whatsapp.net']
105
+ })
106
+
107
+ // Image
108
+ await sock.sendMessage(jid, {
109
+ image: { url: './image.jpg' },
110
+ caption: 'Check this out'
44
111
  })
45
112
 
46
- sock.ev.on('creds.update', saveCreds)
113
+ // Video
114
+ await sock.sendMessage(jid, {
115
+ video: { url: './video.mp4' },
116
+ caption: 'Watch this'
117
+ })
118
+
119
+ // Audio
120
+ await sock.sendMessage(jid, {
121
+ audio: { url: './audio.mp3' },
122
+ mimetype: 'audio/mp4'
123
+ })
124
+
125
+ // React to a message
126
+ await sock.sendMessage(jid, {
127
+ react: { text: '🔥', key: msg.key }
128
+ })
129
+
130
+ // Delete for everyone
131
+ await sock.sendMessage(jid, {
132
+ delete: msg.key
133
+ })
134
+ ```
135
+
136
+ ---
137
+
138
+ ## WhatsApp JID Format
47
139
 
48
- sock.ev.on('connection.update', ({ connection, lastDisconnect, qr }) => {
49
- if (qr) console.log('Scan QR:', qr)
140
+ | Type | Format |
141
+ |------|--------|
142
+ | Personal chat | `254700000000@s.whatsapp.net` |
143
+ | Group | `123456789-123456@g.us` |
144
+ | Broadcast | `status@broadcast` |
50
145
 
51
- if (connection === 'close') {
52
- const shouldReconnect = (lastDisconnect?.error instanceof Boom)
53
- && lastDisconnect.error.output.statusCode !== DisconnectReason.loggedOut
54
- if (shouldReconnect) connectToWA()
55
- } else if (connection === 'open') {
56
- console.log('Connected!')
146
+ ---
147
+
148
+ ## Groups
149
+
150
+ ```js
151
+ // Create
152
+ const group = await sock.groupCreate('My Group', ['254700000000@s.whatsapp.net'])
153
+
154
+ // Add / remove participants
155
+ await sock.groupParticipantsUpdate(jid, ['254700000000@s.whatsapp.net'], 'add') // or 'remove'
156
+
157
+ // Promote / demote
158
+ await sock.groupParticipantsUpdate(jid, ['254700000000@s.whatsapp.net'], 'promote') // or 'demote'
159
+
160
+ // Get invite link
161
+ const code = await sock.groupInviteCode(jid)
162
+
163
+ // Join by invite code
164
+ await sock.groupAcceptInvite('abc123')
165
+
166
+ // Group info
167
+ const meta = await sock.groupMetadata(jid)
168
+
169
+ // Leave
170
+ await sock.groupLeave(jid)
171
+ ```
172
+
173
+ ---
174
+
175
+ ## Privacy & Profile
176
+
177
+ ```js
178
+ // Block / unblock
179
+ await sock.updateBlockStatus(jid, 'block') // or 'unblock'
180
+
181
+ // Change display name
182
+ await sock.updateProfileName('My Name')
183
+
184
+ // Change status
185
+ await sock.updateProfileStatus('Available')
186
+
187
+ // Update profile picture
188
+ await sock.updateProfilePicture(jid, { url: './photo.jpg' })
189
+
190
+ // Fetch someone's profile picture
191
+ const url = await sock.profilePictureUrl(jid, 'image')
192
+ ```
193
+
194
+ ---
195
+
196
+ ## Reading Messages & Presence
197
+
198
+ ```js
199
+ // Mark messages as read
200
+ await sock.readMessages([msg.key])
201
+
202
+ // Update presence (in a chat)
203
+ await sock.sendPresenceUpdate('composing', jid) // typing
204
+ await sock.sendPresenceUpdate('paused', jid) // stopped typing
205
+ ```
206
+
207
+ ---
208
+
209
+ ## Downloading Media
210
+
211
+ ```js
212
+ import { downloadMediaMessage } from 'davexbaileys'
213
+
214
+ sock.ev.on('messages.upsert', async ({ messages }) => {
215
+ for (const msg of messages) {
216
+ if (msg.message?.imageMessage) {
217
+ const buffer = await downloadMediaMessage(msg, 'buffer', {})
218
+ // save or process buffer
219
+ }
57
220
  }
58
221
  })
59
222
  ```
60
223
 
61
- ## Features
224
+ ---
225
+
226
+ ## Caching Group Metadata (Recommended for group bots)
227
+
228
+ ```js
229
+ import { NodeCache } from '@cacheable/node-cache'
230
+
231
+ const groupCache = new NodeCache({ stdTTL: 300 })
232
+
233
+ const sock = makeWASocket({
234
+ auth: state,
235
+ cachedGroupMetadata: async (jid) => groupCache.get(jid)
236
+ })
237
+
238
+ sock.ev.on('groups.update', async ([event]) => {
239
+ groupCache.set(event.id, await sock.groupMetadata(event.id))
240
+ })
241
+ ```
242
+
243
+ ---
244
+
245
+ ## Links
246
+
247
+ - **npm:** https://www.npmjs.com/package/davexbaileys
248
+ - **GitHub:** https://github.com/Davex-254/davebaileys
62
249
 
63
- - Full WhatsApp Web API support — based on official [@WhiskeySockets/Baileys](https://github.com/WhiskeySockets/Baileys) v7.0.0-rc.9
64
- - Multi-device support with QR code and pairing code authentication
65
- - LID (Link ID) addressing support for personal chats and groups
66
- - Session stability fix for deployed servers (no more 428 reconnection loops)
67
- - Message sending, receiving, and manipulation
68
- - Group management
69
- - Newsletter / channel support
70
- - Privacy settings
71
- - Profile management
72
- - And much more!
250
+ ---
73
251
 
74
- ## Documentation
252
+ ## License
75
253
 
76
- Full documentation is available at [github.com/Davex-254/davebaileys](https://github.com/Davex-254/davebaileys)
254
+ MIT © Davex-254
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "davexbaileys",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "type": "module",
5
5
  "description": "A lightweight, full-featured WhatsApp Web API library for Node.js",
6
6
  "main": "lib/index.js",