davexbaileys 2.5.8 → 2.5.10

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,53 +1,254 @@
1
1
  <div align="center">
2
- <h1>Davebaileys</h1>
3
- <p>A WebSocket-based JavaScript library for interacting with the WhatsApp Web API</p>
4
-
5
- [![npm version](https://img.shields.io/npm/v/davebaileys.svg)](https://www.npmjs.com/package/davebaileys)
6
- [![npm downloads](https://img.shields.io/npm/dm/davebaileys.svg)](https://www.npmjs.com/package/davebaileys)
7
- [![License](https://img.shields.io/npm/l/davebaileys.svg)](https://github.com/Davex-254/davebaileys/blob/main/LICENSE)
2
+
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.
11
16
 
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.
17
+ ---
18
+
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
 
16
30
  ```bash
17
- npm install davebaileys
31
+ npm install davexbaileys
18
32
  ```
19
33
 
20
- Or using yarn:
21
- ```bash
22
- yarn add davebaileys
34
+ ---
35
+
36
+ ## Requirements
37
+
38
+ - **Node.js v20 or higher**
39
+ - This package is **ESM only** — use `import`, not `require`
40
+
41
+ ---
42
+
43
+ ## Getting Started
44
+
45
+ ### Save & Restore Session
46
+
47
+ ```js
48
+ import makeWASocket, { useMultiFileAuthState, DisconnectReason } from 'davexbaileys'
49
+ import { Boom } from '@hapi/boom'
50
+
51
+ async function start() {
52
+ const { state, saveCreds } = await useMultiFileAuthState('session')
53
+
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'
111
+ })
112
+
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
139
+
140
+ | Type | Format |
141
+ |------|--------|
142
+ | Personal chat | `254700000000@s.whatsapp.net` |
143
+ | Group | `123456789-123456@g.us` |
144
+ | Broadcast | `status@broadcast` |
145
+
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
23
205
  ```
24
206
 
25
- ## Quick Start
207
+ ---
26
208
 
27
- ### CommonJS (Recommended)
28
- ```javascript
29
- const { default: makeWASocket, useMultiFileAuthState, Browsers } = require('davebaileys')
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
+ }
220
+ }
221
+ })
30
222
  ```
31
223
 
32
- ### ES Modules / TypeScript
33
- ```javascript
34
- import pkg from 'davebaileys'
35
- const { default: makeWASocket, useMultiFileAuthState, Browsers } = pkg
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
+ })
36
241
  ```
37
242
 
38
- ## Features
243
+ ---
244
+
245
+ ## Links
246
+
247
+ - **npm:** https://www.npmjs.com/package/davexbaileys
248
+ - **GitHub:** https://github.com/Davex-254/davebaileys
39
249
 
40
- - Full WhatsApp Web API support
41
- - Multi-device support with QR code and pairing code authentication
42
- - LID (Link ID) addressing support for both personal chats and groups
43
- - Group status/story sending functionality
44
- - Session management and restoration
45
- - Message sending, receiving, and manipulation
46
- - Group management
47
- - Privacy settings
48
- - Profile management
49
- - And much more!
250
+ ---
50
251
 
51
- ## Documentation
252
+ ## License
52
253
 
53
- Full documentation is available at [github.com/Davex-254/davebaileys](https://github.com/Davex-254/davebaileys)
254
+ MIT © Davex-254
@@ -36,7 +36,7 @@ export const PROCESSABLE_HISTORY_TYPES = [
36
36
  ];
37
37
  export const DEFAULT_CONNECTION_CONFIG = {
38
38
  version: version,
39
- browser: Browsers.macOS('Chrome'),
39
+ browser: Browsers.ubuntu('Chrome'),
40
40
  waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
41
41
  connectTimeoutMs: 20000,
42
42
  keepAliveIntervalMs: 30000,
@@ -49,7 +49,7 @@ export const DEFAULT_CONNECTION_CONFIG = {
49
49
  fireInitQueries: true,
50
50
  auth: undefined,
51
51
  markOnlineOnConnect: true,
52
- syncFullHistory: true,
52
+ syncFullHistory: false,
53
53
  patchMessageBeforeSending: msg => msg,
54
54
  shouldSyncHistoryMessage: () => true,
55
55
  shouldIgnoreJid: () => false,
@@ -174,7 +174,7 @@ export const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connect
174
174
  * Use to ensure your WA connection is always on the latest version
175
175
  */
176
176
  export const fetchLatestBaileysVersion = async (options = {}) => {
177
- const URL = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/index.ts';
177
+ const URL = 'https://raw.githubusercontent.com/mauricegift/gifted-aileys/main/lib/Defaults/baileys-version.json';
178
178
  try {
179
179
  const response = await fetch(URL, {
180
180
  dispatcher: options.dispatcher,
@@ -184,21 +184,11 @@ export const fetchLatestBaileysVersion = async (options = {}) => {
184
184
  if (!response.ok) {
185
185
  throw new Boom(`Failed to fetch latest Baileys version: ${response.statusText}`, { statusCode: response.status });
186
186
  }
187
- const text = await response.text();
188
- // Extract version from line 7 (const version = [...])
189
- const lines = text.split('\n');
190
- const versionLine = lines[6]; // Line 7 (0-indexed)
191
- const versionMatch = versionLine.match(/const version = \[(\d+),\s*(\d+),\s*(\d+)\]/);
192
- if (versionMatch) {
193
- const version = [parseInt(versionMatch[1]), parseInt(versionMatch[2]), parseInt(versionMatch[3])];
194
- return {
195
- version,
196
- isLatest: true
197
- };
198
- }
199
- else {
200
- throw new Error('Could not parse version from Defaults/index.ts');
201
- }
187
+ const result = await response.json();
188
+ return {
189
+ version: result.version,
190
+ isLatest: true
191
+ };
202
192
  }
203
193
  catch (error) {
204
194
  return {
@@ -50,12 +50,10 @@ export const generateLoginNode = (userJid, config) => {
50
50
  const { user, device } = jidDecode(userJid);
51
51
  const payload = {
52
52
  ...getClientPayload(config),
53
- passive: true,
53
+ passive: false,
54
54
  pull: true,
55
55
  username: +user,
56
- device: device,
57
- // TODO: investigate (hard set as false atm)
58
- lidDbMigrated: false
56
+ device: device
59
57
  };
60
58
  return proto.ClientPayload.fromObject(payload);
61
59
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "davexbaileys",
3
- "version": "2.5.8",
3
+ "version": "2.5.10",
4
4
  "type": "module",
5
5
  "description": "A lightweight, full-featured WhatsApp Web API library for Node.js",
6
6
  "main": "lib/index.js",