kyzz-baileys 1.0.0 → 1.0.2

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,119 +1,316 @@
1
1
  # Kyzz Baileys
2
2
 
3
- A lightweight, developer-friendly fork of [Baileys R14](https://github.com/WhiskeySockets/Baileys) (`v7.0.0-rc14`) featuring convenient built-in helpers while maintaining 100% core protocol and API compatibility.
3
+ <p align="center">
4
+ <b>A lightweight, high-performance, developer-friendly WhatsApp automation library.</b><br>
5
+ Built on top of <b>Baileys R14</b> (<code>v7.0.0-rc14</code>) with modern protobuf definitions and built-in convenience helpers.
6
+ </p>
4
7
 
5
8
  ---
6
9
 
7
- ## Features
10
+ ## 🌟 Highlights
8
11
 
9
- - **100% Baileys R14 Core Compatibility**: All original Baileys methods, binary stanzas, and events work out-of-the-box.
10
- - **Built-in `sendText`**: Simple shortcut to send plain text messages.
11
- - **Built-in `reply`**: Reply directly to messages using native Baileys quoted context.
12
- - **Built-in `lidToJid`**: Helper to resolve LID (`@lid`) to the real phone number JID (`@s.whatsapp.net`).
13
- - **Built-in `downloadMedia`**: Fast media downloading helper supporting images, videos, audio/PTT, documents, and stickers.
14
- - **Simple Logger Toggle**: Set `logger: false` directly in socket options to disable logging cleanly.
15
- - **Zero Extra Dependencies**: Built using Baileys native internals.
12
+ - **100% Baileys R14 Core Compatibility**: Complete retention of WhiskeySockets Baileys R14 architecture, binary nodes, Signal crypto, event buffering, and multi-device connection management.
13
+ - **Modern Extended Protobuf Definitions**: Enhanced protobuf definitions supporting modern WhatsApp stanzas, interactive native flows, newsletters, and rich messages.
14
+ - **Built-in Convenience Helpers**:
15
+ - `sock.sendText(jid, text, options?)`
16
+ - `sock.reply(jid, text, quotedMessage, options?)`
17
+ - `sock.lidToJid(lid)`
18
+ - `sock.downloadMedia(message, options?)`
19
+ - **Modular Message Builder** (Zero Globals):
20
+ - Socket methods: `sock.sendButton()`, `sock.sendButtonV2()`, `sock.sendCarousel()`, `sock.sendAIRich()`
21
+ - Exported classes: `Button`, `ButtonV2`, `Carousel`, `AIRich`, `Toolkit`
22
+ - **Clean Logger Configuration**: Supports `logger: false` directly in socket options.
23
+ - **Zero Heavy External Dependencies**: Pure, lean, and optimized for bot development.
16
24
 
17
25
  ---
18
26
 
19
- ## Installation
27
+ ## 📦 Installation
20
28
 
21
29
  ```bash
22
30
  npm install kyzz-baileys
23
31
  ```
24
32
 
33
+ ### Requirements
34
+ - **Node.js**: `v18.0.0` or higher
35
+ - **Module System**: ESM (`"type": "module"`) or TypeScript
36
+
25
37
  ---
26
38
 
27
- ## Usage
39
+ ## 🚀 Quick Start
28
40
 
29
- ### 1. Initializing Socket
41
+ ### Basic Connection Example (ESM)
30
42
 
31
43
  ```typescript
32
44
  import makeWASocket, { useMultiFileAuthState, DisconnectReason } from 'kyzz-baileys'
33
45
 
34
- const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
46
+ async function connectToWhatsApp() {
47
+ const { state, saveCreds } = await useMultiFileAuthState('auth_session')
35
48
 
36
- const sock = makeWASocket({
37
- auth: state,
38
- logger: false // or use a custom pino logger instance
39
- })
49
+ const sock = makeWASocket({
50
+ auth: state,
51
+ logger: false, // cleanly disable verbose pino logs, or supply your own pino logger
52
+ printQRInTerminal: true
53
+ })
40
54
 
41
- sock.ev.on('creds.update', saveCreds)
55
+ sock.ev.on('creds.update', saveCreds)
42
56
 
43
- sock.ev.on('connection.update', (update) => {
44
- const { connection, lastDisconnect } = update
45
- if (connection === 'close') {
46
- const shouldReconnect = (lastDisconnect?.error as any)?.output?.statusCode !== DisconnectReason.loggedOut
47
- console.log('Connection closed, reconnecting:', shouldReconnect)
48
- } else if (connection === 'open') {
49
- console.log('Connected successfully!')
50
- }
51
- })
57
+ sock.ev.on('connection.update', (update) => {
58
+ const { connection, lastDisconnect, qr } = update
59
+ if (connection === 'close') {
60
+ const shouldReconnect = (lastDisconnect?.error as any)?.output?.statusCode !== DisconnectReason.loggedOut
61
+ console.log('Connection closed. Reconnecting:', shouldReconnect)
62
+ if (shouldReconnect) connectToWhatsApp()
63
+ } else if (connection === 'open') {
64
+ console.log('✅ Connected to WhatsApp successfully!')
65
+ }
66
+ })
67
+
68
+ sock.ev.on('messages.upsert', async ({ messages, type }) => {
69
+ if (type !== 'notify') return
70
+ const msg = messages[0]
71
+ if (!msg.message || msg.key.fromMe) return
72
+
73
+ const jid = msg.key.remoteJid!
74
+ const text = msg.message.conversation || msg.message.extendedTextMessage?.text
75
+
76
+ if (text === '!ping') {
77
+ await sock.sendText(jid, 'Pong! 🏓')
78
+ }
79
+ })
80
+ }
81
+
82
+ connectToWhatsApp()
52
83
  ```
53
84
 
54
85
  ---
55
86
 
56
- ### 2. Built-in Helpers
87
+ ## 🛠️ Built-in Socket Helpers
88
+
89
+ ### 1. `sock.sendText(jid, text, options?)`
90
+ Sends a simple plain text message using Baileys' native pipeline.
57
91
 
58
- #### `sock.sendText(jid, text, options?)`
59
92
  ```typescript
60
- // Send simple text
61
- await sock.sendText('1234567890@s.whatsapp.net', 'Hello from Kyzz Baileys!')
93
+ // Simple text
94
+ await sock.sendText('628123456789@s.whatsapp.net', 'Hello from Kyzz Baileys!')
95
+
96
+ // With custom send options (e.g. ephemeral expiration)
97
+ await sock.sendText('628123456789@s.whatsapp.net', 'Hello with ephemeral expiration', {
98
+ ephemeralExpiration: 86400
99
+ })
62
100
  ```
63
101
 
64
- #### `sock.reply(jid, textOrContent, quotedMessage, options?)`
102
+ ---
103
+
104
+ ### 2. `sock.reply(jid, textOrContent, quotedMessage, options?)`
105
+ Replies directly to any received message with native quoted context.
106
+
65
107
  ```typescript
66
108
  sock.ev.on('messages.upsert', async ({ messages }) => {
67
109
  const msg = messages[0]
68
110
  if (!msg.message || msg.key.fromMe) return
69
111
 
70
- // Reply with text
71
- await sock.reply(msg.key.remoteJid!, 'Received your message!', msg)
112
+ const senderJid = msg.key.remoteJid!
113
+
114
+ // Reply with simple text
115
+ await sock.reply(senderJid, 'Got your message loud and clear!', msg)
116
+
117
+ // Or reply with AnyMessageContent object (e.g. media, formatted content)
118
+ await sock.reply(senderJid, {
119
+ text: 'Check this out with quoted context!'
120
+ }, msg)
72
121
  })
73
122
  ```
74
123
 
75
- #### `sock.lidToJid(lid)`
124
+ ---
125
+
126
+ ### 3. `sock.lidToJid(lid)`
127
+ Resolves a WhatsApp LID (e.g., `12345678901234@lid`) to the corresponding phone number JID (`...01234@s.whatsapp.net`) using Baileys' internal Signal/LID store.
128
+
76
129
  ```typescript
77
- // Resolve a LID to a phone number JID
78
- const phoneJid = await sock.lidToJid('123456789@lid')
79
- console.log('Resolved JID:', phoneJid) // e.g. 628123456789@s.whatsapp.net
130
+ const realJid = await sock.lidToJid('10293847561029@lid')
131
+ console.log('Resolved user JID:', realJid) // e.g. "628987654321@s.whatsapp.net"
80
132
  ```
81
133
 
82
- #### `sock.downloadMedia(message, options?)`
134
+ ---
135
+
136
+ ### 4. `sock.downloadMedia(message, options?)`
137
+ Extracts and downloads decrypted media buffer directly from any message type (images, videos, audio, voice notes, stickers, documents).
138
+
83
139
  ```typescript
84
140
  sock.ev.on('messages.upsert', async ({ messages }) => {
85
141
  const msg = messages[0]
86
142
  if (!msg.message || msg.key.fromMe) return
87
143
 
88
- // Download media buffer (images, stickers, audio, video, documents)
89
144
  try {
90
145
  const buffer = await sock.downloadMedia(msg)
91
- console.log('Downloaded media size:', buffer.length)
146
+ console.log('Downloaded media size:', buffer.length, 'bytes')
92
147
  } catch (err) {
93
- // Not a media message or download error
148
+ // Not a media message or decryption error
94
149
  }
95
150
  })
96
151
  ```
97
152
 
98
153
  ---
99
154
 
100
- ### 3. Standard Baileys API Compatibility
155
+ ## 🎨 Message Builder API
156
+
157
+ Kyzz Baileys provides built-in message builders for interactive buttons, modern native flows, carousels, and rich AI cards. All builder classes are **100% modular, importable, and contain NO global variables**.
158
+
159
+ ### 1. Interactive Buttons (`sock.sendButton`)
160
+
161
+ ```typescript
162
+ import { Button } from 'kyzz-baileys'
163
+
164
+ // Using socket helper
165
+ await sock.sendButton(jid, {
166
+ text: 'Select your preferred action:',
167
+ footer: 'Kyzz Baileys Bot',
168
+ buttons: [
169
+ Button.quickReply('btn_1', '🔘 Quick Reply'),
170
+ Button.url('🔗 Visit Website', 'https://github.com'),
171
+ Button.call('📞 Call Support', '+628123456789'),
172
+ Button.copy('📋 Copy Code', 'DISCOUNT2026')
173
+ ]
174
+ })
175
+ ```
176
+
177
+ ---
178
+
179
+ ### 2. Native Flow Buttons V2 (`sock.sendButtonV2`)
180
+
181
+ ```typescript
182
+ import { ButtonV2 } from 'kyzz-baileys'
183
+
184
+ await sock.sendButtonV2(jid, {
185
+ text: 'Modern Native Flow Interactive Buttons',
186
+ footer: 'Powered by Kyzz Baileys',
187
+ buttons: [
188
+ ButtonV2.quickReply('id_v2_ping', '🏓 Ping V2'),
189
+ ButtonV2.url('🌐 Open Portal', 'https://example.com'),
190
+ ButtonV2.copy('🔑 Copy Token', 'AUTH_TOKEN_XYZ')
191
+ ]
192
+ })
193
+ ```
194
+
195
+ ---
196
+
197
+ ### 3. Interactive Carousel (`sock.sendCarousel`)
198
+
199
+ ```typescript
200
+ import { Carousel, ButtonV2 } from 'kyzz-baileys'
201
+
202
+ await sock.sendCarousel(jid, {
203
+ text: 'Explore our features:',
204
+ footer: 'Swipe horizontally to view more',
205
+ cards: [
206
+ Carousel.createCard({
207
+ header: { title: 'Product A' },
208
+ body: 'High performance WhatsApp engine',
209
+ footer: 'Card 1 of 2',
210
+ buttons: [
211
+ ButtonV2.quickReply('card1_select', 'Select Product A')
212
+ ]
213
+ }),
214
+ Carousel.createCard({
215
+ header: { title: 'Product B' },
216
+ body: 'Extended Proto and zero globals',
217
+ footer: 'Card 2 of 2',
218
+ buttons: [
219
+ ButtonV2.quickReply('card2_select', 'Select Product B')
220
+ ]
221
+ })
222
+ ]
223
+ })
224
+ ```
225
+
226
+ ---
227
+
228
+ ### 4. AI Rich Persona Card (`sock.sendAIRich`)
229
+
230
+ ```typescript
231
+ import { AIRich } from 'kyzz-baileys'
232
+
233
+ await sock.sendAIRich(jid, {
234
+ text: 'Hello! I am your AI Assistant powered by Kyzz Baileys.',
235
+ persona: 'Kyzz AI',
236
+ botJid: '13135550002@s.whatsapp.net'
237
+ })
238
+ ```
239
+
240
+ ---
241
+
242
+ ### 5. Direct MessageBuilder Classes
101
243
 
102
- All standard Baileys functions remain fully functional:
244
+ You can also use the builder classes directly without the socket wrappers to generate standard `AnyMessageContent` objects:
245
+
246
+ ```typescript
247
+ import { Button, ButtonV2, Carousel, AIRich, Toolkit } from 'kyzz-baileys'
248
+
249
+ // Generate button payload
250
+ const buttonPayload = Button.build({
251
+ text: 'Hello World',
252
+ footer: 'Footer note',
253
+ buttons: [Button.quickReply('id1', 'Click Me')]
254
+ })
255
+
256
+ // Send using standard Baileys sendMessage
257
+ await sock.sendMessage(jid, buttonPayload)
258
+ ```
259
+
260
+ ---
261
+
262
+ ## ⚡ Original Baileys API Compatibility
263
+
264
+ All original Baileys methods are preserved and completely unchanged:
103
265
 
104
266
  ```typescript
105
267
  // Standard sendMessage
106
- await sock.sendMessage(jid, { text: 'Standard Baileys message' })
268
+ await sock.sendMessage(jid, { text: 'Regular message' })
269
+
270
+ // Sending media with caption
271
+ await sock.sendMessage(jid, {
272
+ image: { url: './assets/photo.jpg' },
273
+ caption: 'Here is a photo'
274
+ })
107
275
 
108
- // Standard media sending
276
+ // Reactions
109
277
  await sock.sendMessage(jid, {
110
- image: { url: './image.png' },
111
- caption: 'Hello World'
278
+ react: { text: '❤️', key: msg.key }
112
279
  })
280
+
281
+ // Group operations
282
+ const group = await sock.groupCreate('My Group', ['628123456789@s.whatsapp.net'])
283
+ await sock.groupParticipantsUpdate(group.id, ['628123456789@s.whatsapp.net'], 'promote')
113
284
  ```
114
285
 
115
286
  ---
116
287
 
117
- ## License
288
+ ## 📋 API Reference
289
+
290
+ | Method / Symbol | Description | Type |
291
+ |---|---|---|
292
+ | `sock.sendText(jid, text, options?)` | Convenience method to send plain text | Helper |
293
+ | `sock.reply(jid, textOrContent, quoted, options?)` | Convenience method to reply with quoted context | Helper |
294
+ | `sock.lidToJid(lid)` | Resolves WhatsApp LID to standard user JID | Helper |
295
+ | `sock.downloadMedia(message, options?)` | Downloads media buffer from any message | Helper |
296
+ | `sock.sendButton(jid, payload, options?)` | Sends interactive button message | UI Builder |
297
+ | `sock.sendButtonV2(jid, payload, options?)` | Sends native flow V2 button message | UI Builder |
298
+ | `sock.sendCarousel(jid, payload, options?)` | Sends interactive carousel message | UI Builder |
299
+ | `sock.sendAIRich(jid, payload, options?)` | Sends rich AI persona card | UI Builder |
300
+ | `Button`, `ButtonV2`, `Carousel`, `AIRich`, `Toolkit` | Modular message builder classes | Exports |
301
+ | `proto` | Protobuf definitions | Proto |
302
+ | `makeWASocket(config)` | Factory for creating WhatsApp socket instance | Core |
303
+
304
+ ---
305
+
306
+ ## 🤝 Special Thanks & Credits (TQTO)
307
+
308
+ - [WhiskeySockets/Baileys](https://github.com/WhiskeySockets/Baileys) — Original Baileys R14 multi-device library & protocol engine.
309
+ - **nixcode (nixel) / Valdaz** ([ValdazGT](https://gist.github.com/ValdazGT)) — For the Message Builder reference & interactive component designs.
310
+ - 📢 **Official WhatsApp Channel**: [Join Here](https://whatsapp.com/channel/0029VbCV1ck8fewpdNb2TY2k)
311
+
312
+ ---
313
+
314
+ ## 📄 License
118
315
 
119
316
  MIT License. WhiskeySockets/Baileys copyright belongs to its original authors.