zaileys 1.1.25 β†’ 1.1.26

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 (4) hide show
  1. package/README.md +137 -220
  2. package/dist/index.js +1 -5276
  3. package/dist/index.mjs +1 -5246
  4. package/package.json +3 -3
package/README.md CHANGED
@@ -1,59 +1,64 @@
1
- <div align='center'>
2
- <img alt="Zaileys - Simplify Typescript/Javascript WhatsApp NodeJS API" src="https://socialify.git.ci/zeative/zaileys/image?description=1&amp;descriptionEditable=Zaileys%20is%20a%20simplified%20version%20of%20the%20Baileys%20package%20%0Awhich%20is%20easier%20and%20faster.&amp;font=KoHo&amp;forks=1&amp;issues=1&amp;language=1&amp;name=1&amp;owner=1&amp;pattern=Circuit%20Board&amp;pulls=1&amp;stargazers=1&amp;theme=Auto">
1
+ <div align="center">
2
+ <img alt="Zaileys - Simplified WhatsApp Node.js API" src="https://socialify.git.ci/zeative/zaileys/image?description=1&descriptionEditable=Zaileys%20is%20a%20simplified%20version%20of%20the%20Baileys%20package%20%0Awhich%20is%20easier%20and%20faster.&font=KoHo&forks=1&issues=1&language=1&name=1&owner=1&pattern=Circuit%20Board&pulls=1&stargazers=1&theme=Auto">
3
3
  </div>
4
4
 
5
- <h1 align="center">Zaileys - Simplify Typescript/Javascript WhatsApp NodeJS API</h1>
6
-
7
- <div align='center'>
8
-
9
- [![NPM Version](https://img.shields.io/npm/v/zaileys.svg)](https://www.npmjs.com/package/zaileys)
10
- [![NPM Downloads](https://img.shields.io/npm/dw/zaileys?label=npm&color=%23CB3837)](https://www.npmjs.com/package/zaileys)
11
- [![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/zeative/zaileys)](https://www.npmjs.com/package/zaileys)
12
- [![GitHub License](https://img.shields.io/github/license/zeative/zaileys)](https://github.com/zeative/zaileys)
13
- [![GitHub Repo stars](https://img.shields.io/github/stars/zeative/zaileys)](https://github.com/zeative/zaileys)
14
- [![GitHub forks](https://img.shields.io/github/forks/zeative/zaileys)](https://github.com/zeative/zaileys)
15
-
5
+ <h1 align="center">Zaileys - Simplified WhatsApp Node.js API</h1>
6
+
7
+ <div align="center">
8
+ <a href="https://www.npmjs.com/package/zaileys">
9
+ <img src="https://img.shields.io/npm/v/zaileys.svg" alt="NPM Version">
10
+ </a>
11
+ <a href="https://www.npmjs.com/package/zaileys">
12
+ <img src="https://img.shields.io/npm/dw/zaileys?label=npm&color=%23CB3837" alt="NPM Downloads">
13
+ </a>
14
+ <a href="https://github.com/zeative/zaileys">
15
+ <img src="https://img.shields.io/github/languages/code-size/zeative/zaileys" alt="GitHub Code Size">
16
+ </a>
17
+ <a href="https://github.com/zeative/zaileys">
18
+ <img src="https://img.shields.io/github/license/zeative/zaileys" alt="GitHub License">
19
+ </a>
20
+ <a href="https://github.com/zeative/zaileys">
21
+ <img src="https://img.shields.io/github/stars/zeative/zaileys" alt="GitHub Stars">
22
+ </a>
23
+ <a href="https://github.com/zeative/zaileys">
24
+ <img src="https://img.shields.io/github/forks/zeative/zaileys" alt="GitHub Forks">
25
+ </a>
16
26
  </div>
17
27
 
18
28
  > [!NOTE]
19
- > Join whatsapp community for latest info [WhatsApp Channel](https://whatsapp.com/channel/0029VazENbmInlqHIWzgn33h)
29
+ > Join our [WhatsApp Channel](https://whatsapp.com/channel/0029VazENbmInlqHIWzgn33h) for updates and support.
20
30
 
21
- > **Zaileys** is a simplified, high-performance wrapper around the Baileys library for building WhatsApp bots and integrations with TypeScript/JavaScript. Designed for simplicity, speed, and scalabilityβ€”perfect for beginners and pros alike.
31
+ **Zaileys** is a lightweight, high-performance wrapper around the Baileys library for building WhatsApp bots and integrations using TypeScript or ESM JavaScript. Designed for simplicity, speed, and scalability.
32
+
33
+ > [!WARNING]
34
+ > Pairing code authentication is currently experiencing issues and is not supported. Use QR code authentication instead.
22
35
 
23
36
  ## πŸ“‹ Table of Contents
24
37
 
25
- 1. [πŸš€ Features](#πŸš€-features)
26
- 2. [πŸ’» Installation](#πŸ’»-installation)
27
- 3. [⚑ Quick Start](#⚑-quick-start)
38
+ 1. [πŸš€ Features](#features)
39
+ 2. [πŸ’» Installation](#installation)
40
+ 3. [⚑ Quick Start](#quick-start)
28
41
  - [Simplify Version](#simplify-version)
29
- 4. [πŸ” Core Concepts](#πŸ”-core-concepts)
30
- - [Sessions & Authentication](#sessions--authentication)
31
- - [Citation Concept](#citation-concept)
32
- 5. [πŸ“ Examples](#πŸ“-examples)
33
- 6. [πŸ“’ Event Handling](#πŸ“’-event-handling)
34
- 7. [πŸ‘Ύ Worker Actions](#πŸ‘Ύ-worker-actions)
35
- - [Sending Messages](#sending-messages)
36
- - [Sending Media](#sending-media)
37
- - [Presence Update](#presence-update)
38
- - [Get Profile](#get-profile)
39
- - [Reject Call](#reject-call)
40
- 8. [🐞 Issues & Feedback](#🐞-issues--feedback)
41
- 9. [❀️ Funding & Support](#❀️-funding--support)
42
- 10. [πŸ“„ License](#πŸ“„-license)
43
- 11. [πŸ™ Acknowledgements](#πŸ™-acknowledgements)
42
+ 4. [πŸ” Core Concepts](#core-concepts)
43
+ 5. [πŸ“’ Event Handling](#event-handling)
44
+ 6. [πŸ‘Ύ Worker Actions](#worker-actions)
45
+ 7. [🐞 Issues & Feedback](#issues--feedback)
46
+ 8. [❀️ Support](#support)
47
+ 9. [πŸ“„ License](#license)
48
+ 10. [πŸ™ Acknowledgements](#acknowledgements)
44
49
 
45
50
  ## πŸš€ Features
46
51
 
47
- - 🎯 **Simplified API**: Minimal boilerplateβ€”get up and running in minutes.
52
+ - 🎯 **Simplified API**: Minimal setup for rapid development.
48
53
  - πŸ”’ **Secure Multi-Device**: Full multi-device support via Baileys.
49
- - βš™οΈ **Modular & Extensible**: Plug-and-play middleware, transports, and storage layers.
50
- - ~~πŸ“ˆ **Built-in Logging**: Integrated with Pino for structured logs.~~
51
- - πŸ“Ÿ **Live QRs**: Automatically generate and display WhatsApp QR codes in terminal.
52
- - πŸ› οΈ **TypeScript First**: Full type definitions (`.d.ts`) and zero-config TS support.
54
+ - βš™οΈ **Modular Design**: Extensible with middleware and storage layers.
55
+ - πŸ“Ÿ **QR Code Authentication**: Seamless QR-based login in terminal.
56
+ - πŸ› οΈ **TypeScript/ESM Only**: Full type definitions and ESM support.
57
+ - πŸ’Ύ **Database-Driven**: SQLite, PostgreSQL, or MySQL for session storage.
53
58
 
54
59
  ## πŸ’» Installation
55
60
 
56
- Install with your preferred package manager:
61
+ Install via your preferred package manager:
57
62
 
58
63
  ```bash
59
64
  npm install zaileys
@@ -61,293 +66,205 @@ npm install zaileys
61
66
  yarn add zaileys
62
67
  # or
63
68
  pnpm add zaileys
64
-
65
- # just install, don't run with these runtime
66
- bun add zaileys
67
- deno add npm:zaileys
68
69
  ```
69
70
 
70
- > ❗ **Compatibility Notice**
71
+ > [!IMPORTANT]
71
72
  >
72
- > - Zaileys does **not** support **Deno** and **Bun** runtimes at runtime due to `better-sqlite3` incompatibility. You may install dependencies with these runtimes, but execution requires **Node.js**.
73
- > - Supports both **CommonJS (CJS)** and **ECMAScript Modules (ESM)**.
74
-
75
- Ensure you are running Node.js **>= 18** as specified in `package.json`.
73
+ > - Requires **Node.js >= 18**.
74
+ > - Only supports **ESM** and **TypeScript** (no CommonJS).
75
+ > - QR code authentication only (pairing code not supported).
76
+ > - Deno and Bun are not supported at runtime due to `better-sqlite3` incompatibility.
76
77
 
77
78
  ## ⚑ Quick Start
78
79
 
79
- Basic usage of Zaileys based on [`test/example.ts`](https://github.com/zeative/zaileys/blob/main/test/example.ts):
80
-
81
80
  ```ts
82
- // cjs
83
- // const { Client } = require("zaileys");
84
-
85
- // esm
86
81
  import { Client } from "zaileys";
87
82
 
88
- // the configuration below is the default
89
83
  const wa = new Client({
90
- prefix: "/", // command prefix
91
- phoneNumber: 628123456789, // bot phone number for pairing
92
- authType: "pairing", // authentication method: 'pairing' | 'qr'
93
- ignoreMe: true, // ignore messages sent by the bot
94
- showLogs: true, // enable message logs
95
- autoMentions: true, // automatically user mentions
96
- autoOnline: true, // automatically set status to online
97
- autoRead: true, // automatically mark messages as read
98
- autoPresence: true, // manage presence updates 'typing' or 'recording'
99
- autoRejectCall: true, // automatically reject incoming calls
84
+ prefix: "/", // Command prefix
85
+ ignoreMe: true, // Ignore bot's own messages
86
+ autoRead: true, // Auto-mark messages as read
87
+ autoOnline: true, // Auto-set status to online
88
+ autoPresence: true, // Auto-manage presence (typing/recording)
89
+ autoRejectCall: true, // Auto-reject incoming calls
100
90
  database: {
101
- type: "sqlite", // database type: 'sqlite' | 'postgresql' | 'mysql'
91
+ type: "sqlite",
102
92
  connection: { url: "./session/zaileys.db" },
103
93
  },
104
- citation: {
105
- // your own keys; will generate ctx.citation.is<Key> booleans
106
- author: async () => {
107
- // const res = await fetch(...)
108
- return [628123456789];
109
- },
110
- myGroup: () => [120099],
111
- vipUsers: () => [628123456789],
112
- },
113
- });
114
-
115
- // Connection updates
116
- wa.on("connection", (ctx) => {
117
- //
118
94
  });
119
95
 
120
- // Message events
121
96
  wa.on("messages", async (ctx) => {
122
- // Example: checking generated flags
123
- if (!ctx.citation?.isAuthor) return;
124
- if (ctx.citation.isVipUsers) {
125
- // VIP handling
126
- }
127
-
128
97
  if (ctx.text === "test") {
129
- wa.text("Helloo", { roomId: ctx.roomId });
98
+ await wa.text("Hello!", { roomId: ctx.roomId });
130
99
  }
131
100
  });
132
101
 
133
- // Call events
134
- wa.on("calls", (ctx) => {
135
- //
102
+ wa.on("connection", (ctx) => {
103
+ console.log("Connection status:", ctx.status);
136
104
  });
137
105
  ```
138
106
 
139
107
  ### Simplify Version
140
108
 
141
- ```js
142
- // auth with pairing code
143
- const wa = new Client({
144
- phoneNumber: 628123456789,
145
- authType: "pairing",
146
- });
109
+ ```ts
110
+ import { Client } from "zaileys";
147
111
 
148
- // auth with qr
149
112
  const wa = new Client({
150
113
  authType: "qr",
151
114
  });
152
115
 
153
116
  wa.on("messages", (ctx) => {
154
- wa.reply("hello");
117
+ wa.reply("Hello!");
155
118
  });
156
119
  ```
157
120
 
158
- ## πŸ“ Examples
159
-
160
- Refer to [`test/example.ts`](https://github.com/zeative/zaileys/blob/main/test/example.ts) for complete example usage.
161
-
162
121
  ## πŸ” Core Concepts
163
122
 
164
123
  ### Sessions & Authentication
165
124
 
166
- Zaileys persists authentication credentials and session data in a configurable database (`sqlite`, `postgresql`, or `mysql`), ensuring seamless reconnection without repeated QR scans or pairing codes. This database-driven approach enhances flexibility by:
125
+ Zaileys uses QR code authentication and stores session data in a database (SQLite, PostgreSQL, or MySQL) for seamless reconnections without repeated QR scans.
167
126
 
168
- - **Unified Storage**: Store session data and authentication credentials in a single, structured database, enabling easy backup, migration, and scalability.
169
- - **Flexible Data Management**: Query and manage session data directly via SQL, allowing custom integrations and advanced use cases.
170
-
171
- Configure the database in the `Client` options:
127
+ ```ts
128
+ import { Client } from "zaileys";
172
129
 
173
- ```js
174
130
  const wa = new Client({
175
131
  database: {
176
- type: "sqlite", // or 'postgresql' | 'mysql'
177
- connection: { url: "./session/zaileys.db" }, // sqlite file path
132
+ type: "sqlite",
133
+ connection: { url: "./session/zaileys.db" },
178
134
  },
179
135
  });
180
136
  ```
181
137
 
182
- #### Citation Concept
138
+ ### Citation Mechanism
183
139
 
184
- Zaileys provides a flexible **citation** mechanism. Define any metadata provider functions under the `citation` option. Each key will automatically generate a boolean on `ctx.citation`, prefixed with `is` and formatted in camelCase.
185
-
186
- Providers can be **async** or **sync**, and Zaileys will await Promises:
140
+ Define custom metadata providers in the `citation` option. Each key generates a boolean on `ctx.citation` (e.g., `isKeyName`).
187
141
 
188
142
  ```ts
189
- citation: {
190
- // async provider
191
- authorAsync: async () => await fetchAuthorizedAuthors(),
192
- // sync provider
193
- vipList: () => [1234567890]
194
- }
195
- ```
196
-
197
- Results in:
198
-
199
- - `ctx.citation.isAuthorAsync`
200
- - `ctx.citation.isVipList`
201
-
202
- Use them in handlers:
143
+ const wa = new Client({
144
+ citation: {
145
+ admins: async () => [628123456789],
146
+ vips: () => [628123456789],
147
+ },
148
+ });
203
149
 
204
- ```ts
205
150
  wa.on("messages", (ctx) => {
206
- if (!ctx.citation?.isAuthorAsync) return;
207
- if (ctx.citation.isVipList) {
208
- // VIP logic
151
+ if (ctx.citation?.isAdmins) {
152
+ wa.text("Admin access granted", { roomId: ctx.roomId });
209
153
  }
210
154
  });
211
155
  ```
212
156
 
213
157
  ## πŸ“’ Event Handling
214
158
 
215
- ```js
216
- // Connection updates
217
- wa.on("connection", (ctx) => {});
159
+ ```ts
160
+ wa.on("connection", (ctx) => {
161
+ console.log("Connection:", ctx.status);
162
+ });
218
163
 
219
- // Message events
220
- wa.on("messages", (ctx) => {});
164
+ wa.on("messages", (ctx) => {
165
+ console.log("Message:", ctx.text);
166
+ });
221
167
 
222
- // Call events
223
- wa.on("calls", (ctx) => {});
168
+ wa.on("calls", (ctx) => {
169
+ wa.rejectCall(ctx);
170
+ });
224
171
  ```
225
172
 
226
173
  ## πŸ‘Ύ Worker Actions
227
174
 
228
175
  ### Sending Messages
229
176
 
230
- ```js
177
+ ```ts
231
178
  const roomId = ctx.roomId;
232
179
  const message = ctx.message;
233
180
 
234
- // sending text message
235
- wa.text("Hallo test", { roomId });
236
-
237
- // sending reply message
238
- wa.text("Test reply", { roomId, quoted: message });
239
-
240
- // sending text message as forwarded
241
- wa.text("Test forwarded", { roomId, asForwarded: true });
242
-
243
- // sending reply message as verified number
244
- wa.text("Test verified reply", { roomId, quoted: message, verifiedReply: "whatsapp" });
245
-
246
- // also combine verified number and forwarded
247
- wa.text("Test verified reply", { roomId, quoted: message, verifiedReply: "meta", asForwarded: true });
248
-
249
- // sending view once message
250
- // support: image, video, audio
251
- wa.text({ image: "https://github.com/zaadevofc.png", text: "Test view once" }, { roomId, asViewOnce: true });
252
-
253
- // sending reaction message
254
- // empty string for removing reaction
255
- wa.reaction("🐞", { message });
256
-
257
- // editing message
258
- const msg1 = await wa.text("Test edit", { roomId });
259
- wa.edit("Editing success", { message: msg1?.message });
260
-
261
- // deleting message
262
- const msg2 = await wa.text("Test delete", { roomId });
263
- wa.delete("Deleting success", { message: msg2?.message });
264
-
265
- // sending location message
266
- wa.location({ latitude: 24.121231, longitude: 55.1121221, ...other }, { roomId });
267
-
268
- // sending contact message
269
- wa.contact({ fullname: "Kejaa", whatsAppNumber: 628123456789, ...other }, { roomId });
270
-
271
- // sending polling message
272
- wa.poll({ name: "Are you love me?", answers: ["yes", "maybe", "no"] }, { roomId });
181
+ wa.text("Hello", { roomId });
182
+ wa.text("Reply", { roomId, quoted: message });
183
+ wa.text("Forwarded", { roomId, asForwarded: true });
184
+ wa.text("Verified reply", { roomId, quoted: message, verifiedReply: "whatsapp" });
185
+ wa.text({ image: "https://example.com/image.png", text: "View once" }, { roomId, asViewOnce: true });
186
+ wa.reaction("πŸ‘", { message });
187
+ wa.edit("Edited", { message: await wa.text("Original", { roomId })?.message });
188
+ wa.delete("Deleted", { message: await wa.text("To delete", { roomId })?.message });
189
+ wa.location({ latitude: 24.121231, longitude: 55.1121221 }, { roomId });
190
+ wa.contact({ fullname: "Kejaa", whatsAppNumber: 628123456789 }, { roomId });
191
+ wa.poll({ name: "Do you love me?", answers: ["Yes", "Maybe", "No"] }, { roomId });
273
192
  ```
274
193
 
275
194
  ### Sending Media
276
195
 
277
- ```js
278
- // sending image message
279
- wa.text({ image: "https://github.com/zaadevofc.png", text: "Test image message" }, { roomId });
280
- // buffer
281
- wa.text({ image: fs.readFileSync("example/file.png"), text: "Test image message" }, { roomId });
196
+ Supports URLs and local files (via Buffer).
197
+
198
+ ```ts
199
+ import fs from "fs";
200
+
201
+ // Image (URL or file)
202
+ wa.text({ image: "https://example.com/image.png", text: "Image" }, { roomId });
203
+ wa.text({ image: fs.readFileSync("example/image.png"), text: "Image" }, { roomId });
282
204
 
283
- // sending sticker message
284
- wa.text({ sticker: "https://github.com/zaadevofc.png" }, { roomId });
205
+ // Sticker
206
+ wa.text({ sticker: "https://example.com/sticker.png" }, { roomId });
207
+ wa.text({ sticker: fs.readFileSync("example/sticker.png") }, { roomId });
285
208
 
286
- // sending gif message
287
- wa.text({ gif: "https://qu.ax/nTFwh.mp4" }, { roomId });
209
+ // GIF
210
+ wa.text({ gif: "https://example.com/video.mp4" }, { roomId });
211
+ wa.text({ gif: fs.readFileSync("example/video.mp4") }, { roomId });
288
212
 
289
- // sending video message
290
- wa.text({ video: "https://qu.ax/nTFwh.mp4", text: "Test video message" }, { roomId });
213
+ // Video
214
+ wa.text({ video: "https://example.com/video.mp4", text: "Video" }, { roomId });
215
+ wa.text({ video: fs.readFileSync("example/video.mp4"), text: "Video" }, { roomId });
291
216
 
292
- // sending video note message
293
- wa.text({ videoNote: "https://qu.ax/nTFwh.mp4" }, { roomId });
217
+ // Video Note
218
+ wa.text({ videoNote: "https://example.com/video.mp4" }, { roomId });
219
+ wa.text({ videoNote: fs.readFileSync("example/video.mp4") }, { roomId });
294
220
 
295
- // sending audio message
296
- // use .ogg format for better device support
297
- wa.text({ audio: "https://qu.ax/oeSCG.ogg" }, { roomId });
221
+ // Audio (use .ogg for better compatibility)
222
+ wa.text({ audio: "https://example.com/audio.ogg" }, { roomId });
223
+ wa.text({ audio: fs.readFileSync("example/audio.ogg") }, { roomId });
298
224
 
299
- // sending voice note message
300
- // use .ogg format for better device support
301
- wa.text({ audioNote: "https://qu.ax/oeSCG.ogg" }, { roomId });
225
+ // Voice Note (use .ogg for better compatibility)
226
+ wa.text({ audioNote: "https://example.com/audio.ogg" }, { roomId });
227
+ wa.text({ audioNote: fs.readFileSync("example/audio.ogg") }, { roomId });
302
228
  ```
303
229
 
304
230
  ### Presence Update
305
231
 
306
- ```js
307
- // available presence types:
308
- // typing | recording | online | offline | paused
309
- wa.presence("typing", { roomId });
232
+ ```ts
233
+ wa.presence("typing", { roomId }); // Options: typing, recording, online, offline, paused
310
234
  ```
311
235
 
312
236
  ### Get Profile
313
237
 
314
- ```js
315
- // get user profile
316
- wa.profile("6281223456789@s.whatsapp.net");
317
-
318
- // get group profile
319
- wa.profile("1209999@g.us");
238
+ ```ts
239
+ wa.profile("628123456789@s.whatsapp.net"); // User profile
240
+ wa.profile("1209999@g.us"); // Group profile
320
241
  ```
321
242
 
322
243
  ### Reject Call
323
244
 
324
- ```js
245
+ ```ts
325
246
  wa.on("calls", (ctx) => {
326
247
  wa.rejectCall({ callId: ctx.callId, callerId: ctx.callerId });
327
-
328
- // for simplify
329
- wa.rejectCall(ctx);
330
248
  });
331
249
  ```
332
250
 
333
251
  ## 🐞 Issues & Feedback
334
252
 
335
- If you encounter any problems or have feature requests, please open an issue:
336
- [https://github.com/zeative/zaileys/issues](https://github.com/zeative/zaileys/issues)
253
+ Report issues or request features at [GitHub Issues](https://github.com/zeative/zaileys/issues).
337
254
 
338
- ## ❀️ Funding & Support
255
+ ## ❀️ Support
339
256
 
340
- If you find Zaileys useful, consider supporting development:
257
+ Support the project:
341
258
 
342
259
  - [Buy me a coffee β˜•](https://saweria.co/zaadevofc)
343
- - ⭐ Star the repo on GitHub
260
+ - ⭐ Star the repo on [GitHub](https://github.com/zeative/zaileys).
344
261
 
345
262
  ## πŸ“„ License
346
263
 
347
- Distributed under the **MIT License**. See [`LICENSE`](https://github.com/zeative/zaileys/blob/main/LICENSE) for details.
264
+ [MIT License](https://github.com/zeative/zaileys/blob/main/LICENSE).
348
265
 
349
266
  ## πŸ™ Acknowledgements
350
267
 
351
- This project stands on the shoulders of the original [Baileys](https://github.com/WhiskeySockets/Baileys) library by Whiskey Sockets. Thank you for your incredible work and inspiration!"
268
+ Built on [Baileys](https://github.com/WhiskeySockets/Baileys) by Whiskey Sockets.
352
269
 
353
270
  > Happy coding! πŸš€