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.
- package/README.md +222 -44
- 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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
# davexbaileys
|
|
4
|
+
|
|
5
|
+
**A fast, lightweight WhatsApp Web API library for Node.js**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/davexbaileys)
|
|
8
|
+
[](https://www.npmjs.com/package/davexbaileys)
|
|
9
|
+
[](https://github.com/Davex-254/davebaileys/blob/main/LICENSE)
|
|
10
|
+
|
|
8
11
|
</div>
|
|
9
12
|
|
|
10
|
-
|
|
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
|
-
|
|
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
|
-
|
|
21
|
-
```bash
|
|
22
|
-
yarn add davexbaileys
|
|
23
|
-
```
|
|
34
|
+
---
|
|
24
35
|
|
|
25
|
-
##
|
|
36
|
+
## Requirements
|
|
26
37
|
|
|
27
|
-
|
|
38
|
+
- **Node.js v20 or higher**
|
|
39
|
+
- This package is **ESM only** — use `import`, not `require`
|
|
28
40
|
|
|
29
|
-
|
|
30
|
-
import makeWASocket, { useMultiFileAuthState, Browsers } from 'davexbaileys'
|
|
31
|
-
```
|
|
41
|
+
---
|
|
32
42
|
|
|
33
|
-
|
|
43
|
+
## Getting Started
|
|
34
44
|
|
|
35
|
-
|
|
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
|
-
|
|
51
|
+
async function start() {
|
|
52
|
+
const { state, saveCreds } = await useMultiFileAuthState('session')
|
|
40
53
|
|
|
41
|
-
const sock = makeWASocket({
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
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
|
-
|
|
49
|
-
|
|
140
|
+
| Type | Format |
|
|
141
|
+
|------|--------|
|
|
142
|
+
| Personal chat | `254700000000@s.whatsapp.net` |
|
|
143
|
+
| Group | `123456789-123456@g.us` |
|
|
144
|
+
| Broadcast | `status@broadcast` |
|
|
50
145
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
##
|
|
252
|
+
## License
|
|
75
253
|
|
|
76
|
-
|
|
254
|
+
MIT — © Davex-254
|