zaileys 0.29.20 β 1.1.0
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/LICENSE +21 -0
- package/README.md +351 -3
- package/dist/index.cjs +1 -1
- package/dist/index.d.mts +188 -220
- package/dist/index.d.ts +188 -220
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Zeative Media
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -15,7 +15,355 @@
|
|
|
15
15
|
|
|
16
16
|
</div>
|
|
17
17
|
|
|
18
|
-
> [!
|
|
19
|
-
>
|
|
18
|
+
> [!NOTE]
|
|
19
|
+
> Join whatsapp community for latest info [WhatsApp Channel](https://whatsapp.com/channel/0029VazENbmInlqHIWzgn33h)
|
|
20
20
|
|
|
21
|
-
Zaileys is a
|
|
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.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## π Table of Contents
|
|
26
|
+
|
|
27
|
+
1. [π Features](#π-features)
|
|
28
|
+
2. [π» Installation](#π»-installation)
|
|
29
|
+
3. [β‘ Quick Start](#β‘-quick-start)
|
|
30
|
+
4. [π Core Concepts](#π-core-concepts)
|
|
31
|
+
- [Client](#client)
|
|
32
|
+
- [Sessions & Authentication](#sessions--authentication)
|
|
33
|
+
- [Messages & Events](#messages--events)
|
|
34
|
+
- [Citation Concept](#citation-concept)
|
|
35
|
+
5. [βοΈ Configuration & Options](#βοΈ-configuration--options)
|
|
36
|
+
6. [π Examples](#π-examples)
|
|
37
|
+
7. [π’ Event Handling](#π’-event-handling)
|
|
38
|
+
8. [πΎ Worker Actions](#πΎ-worker-actions)
|
|
39
|
+
- [Sending Messages](#sending-messages)
|
|
40
|
+
- [Sending Media](#sending-media)
|
|
41
|
+
- [Presence Update](#presence-update)
|
|
42
|
+
- [Get Profile](#get-profile)
|
|
43
|
+
- [Reject Call](#reject-call)
|
|
44
|
+
9. [π Issues & Feedback](#π-issues--feedback)
|
|
45
|
+
10. [β€οΈ Funding & Support](#β€οΈ-funding--support)
|
|
46
|
+
11. [π License](#π-license)
|
|
47
|
+
12. [π Acknowledgements](#π-acknowledgements)
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## π Features
|
|
52
|
+
|
|
53
|
+
- π― **Simplified API**: Minimal boilerplateβget up and running in minutes.
|
|
54
|
+
- π **Secure Multi-Device**: Full multi-device support via Baileys.
|
|
55
|
+
- βοΈ **Modular & Extensible**: Plug-and-play middleware, transports, and storage layers.
|
|
56
|
+
- ~~π **Built-in Logging**: Integrated with Pino for structured logs.~~
|
|
57
|
+
- π **Live QRs**: Automatically generate and display WhatsApp QR codes in terminal.
|
|
58
|
+
- π οΈ **TypeScript First**: Full type definitions (`.d.ts`) and zero-config TS support.
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## π» Installation
|
|
63
|
+
|
|
64
|
+
Install with your preferred package manager:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
npm install zaileys
|
|
68
|
+
# or
|
|
69
|
+
yarn add zaileys
|
|
70
|
+
# or
|
|
71
|
+
pnpm add zaileys
|
|
72
|
+
|
|
73
|
+
# just install, don't run with these runtime
|
|
74
|
+
bun add zaileys
|
|
75
|
+
deno add npm:zaileys
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
> β **Compatibility Notice**
|
|
79
|
+
>
|
|
80
|
+
> - 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**.
|
|
81
|
+
> - Supports both **CommonJS (CJS)** and **ECMAScript Modules (ESM)**.
|
|
82
|
+
|
|
83
|
+
Ensure you are running Node.js **>= 18** as specified in `package.json`.
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## β‘ Quick Start
|
|
88
|
+
|
|
89
|
+
Basic usage of Zaileys based on [`test/example.ts`](https://github.com/zeative/zaileys/blob/main/test/example.ts):
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
// cjs
|
|
93
|
+
// const Client = require("zaileys");
|
|
94
|
+
|
|
95
|
+
// esm
|
|
96
|
+
import Client from "zaileys";
|
|
97
|
+
|
|
98
|
+
// the configuration below is the default
|
|
99
|
+
const wa = new Client({
|
|
100
|
+
prefix: "/", // command prefix
|
|
101
|
+
phoneNumber: 628123456789, // bot phone number for pairing
|
|
102
|
+
authType: "pairing", // authentication method: 'pairing' | 'qr'
|
|
103
|
+
ignoreMe: true, // ignore messages sent by the bot
|
|
104
|
+
showLogs: true, // enable message logs
|
|
105
|
+
autoMentions: true, // automatically user mentions
|
|
106
|
+
autoOnline: true, // automatically set status to online
|
|
107
|
+
autoRead: true, // automatically mark messages as read
|
|
108
|
+
autoPresence: true, // manage presence updates 'typing' or 'recording'
|
|
109
|
+
autoRejectCall: true, // automatically reject incoming calls
|
|
110
|
+
database: {
|
|
111
|
+
type: "sqlite", // database type: 'sqlite' | 'postgresql' | 'mysql'
|
|
112
|
+
connection: { url: "./session/zaileys.db" },
|
|
113
|
+
},
|
|
114
|
+
citation: {
|
|
115
|
+
// your own keys; will generate ctx.citation.is<Key> booleans
|
|
116
|
+
author: async () => {
|
|
117
|
+
// const res = await fetch(...)
|
|
118
|
+
return [628123456789];
|
|
119
|
+
},
|
|
120
|
+
myGroup: () => [120099],
|
|
121
|
+
vipUsers: () => [628123456789],
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// Connection updates
|
|
126
|
+
wa.on("connection", (ctx) => {
|
|
127
|
+
//
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// Message events
|
|
131
|
+
wa.on("messages", async (ctx) => {
|
|
132
|
+
// Example: checking generated flags
|
|
133
|
+
if (!ctx.citation?.isAuthor) return;
|
|
134
|
+
if (ctx.citation.isVipUsers) {
|
|
135
|
+
// VIP handling
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (ctx.text === "test") {
|
|
139
|
+
wa.text("Helloo", { roomId: ctx.roomId });
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// Call events
|
|
144
|
+
wa.on("calls", (ctx) => {
|
|
145
|
+
//
|
|
146
|
+
});
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## π Core Concepts
|
|
152
|
+
|
|
153
|
+
### Client
|
|
154
|
+
|
|
155
|
+
The heart of Zaileys. Use `new Client(options)` to instantiate. It emits events (`messages`, `calls`, `connection`, etc.) and exposes methods (`text`, `reply`, `location`, and more).
|
|
156
|
+
|
|
157
|
+
### Sessions & Authentication
|
|
158
|
+
|
|
159
|
+
Zaileys persists authentication credentials in your specified `session`. Re-running your bot will reuse credentialsβno QR scan or pairing code required each time.
|
|
160
|
+
|
|
161
|
+
### Messages & Events
|
|
162
|
+
|
|
163
|
+
All WhatsApp activity is exposed via events. Listen on `messages`, `calls`, `connection`, and more to build reactive bots.
|
|
164
|
+
|
|
165
|
+
#### Citation Concept
|
|
166
|
+
|
|
167
|
+
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.
|
|
168
|
+
|
|
169
|
+
Providers can be **async** or **sync**, and Zaileys will await Promises:
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
citation: {
|
|
173
|
+
// async provider
|
|
174
|
+
authorAsync: async () => await fetchAuthorizedAuthors(),
|
|
175
|
+
// sync provider
|
|
176
|
+
vipList: () => [1234567890]
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Results in:
|
|
181
|
+
|
|
182
|
+
- `ctx.citation.isAuthorAsync`
|
|
183
|
+
- `ctx.citation.isVipList`
|
|
184
|
+
|
|
185
|
+
Use them in handlers:
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
wa.on("messages", (ctx) => {
|
|
189
|
+
if (!ctx.citation?.isAuthorAsync) return;
|
|
190
|
+
if (ctx.citation.isVipList) {
|
|
191
|
+
// VIP logic
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
## βοΈ Configuration & Options
|
|
199
|
+
|
|
200
|
+
Pass low-level Baileys options via `baileysConfig` in your client options for advanced scenarios.
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## π Examples
|
|
205
|
+
|
|
206
|
+
Refer to [`test/example.ts`](https://github.com/zeative/zaileys/blob/main/test/example.ts) for complete example usage.
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## π’ Event Handling
|
|
211
|
+
|
|
212
|
+
```js
|
|
213
|
+
// Connection updates
|
|
214
|
+
wa.on("connection", (ctx) => {});
|
|
215
|
+
|
|
216
|
+
// Message events
|
|
217
|
+
wa.on("messages", (ctx) => {});
|
|
218
|
+
|
|
219
|
+
// Call events
|
|
220
|
+
wa.on("calls", (ctx) => {});
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## πΎ Worker Actions
|
|
226
|
+
|
|
227
|
+
### Sending Messages
|
|
228
|
+
|
|
229
|
+
```js
|
|
230
|
+
const roomId = ctx.roomId;
|
|
231
|
+
const message = ctx.message;
|
|
232
|
+
|
|
233
|
+
// sending text message
|
|
234
|
+
wa.text("Hallo test", { roomId });
|
|
235
|
+
|
|
236
|
+
// sending reply message
|
|
237
|
+
wa.text("Test reply", { roomId, quoted: message });
|
|
238
|
+
|
|
239
|
+
// sending text message as forwarded
|
|
240
|
+
wa.text("Test forwarded", { roomId, asForwarded: true });
|
|
241
|
+
|
|
242
|
+
// sending reply message as verified number
|
|
243
|
+
wa.text("Test verified reply", { roomId, quoted: message, verifiedReply: "whatsapp" });
|
|
244
|
+
|
|
245
|
+
// also combine verified number and forwarded
|
|
246
|
+
wa.text("Test verified reply", { roomId, quoted: message, verifiedReply: "meta", asForwarded: true });
|
|
247
|
+
|
|
248
|
+
// sending view once message
|
|
249
|
+
// support: image, video, audio
|
|
250
|
+
wa.text({ image: "https://github.com/zaadevofc.png", text: "Test view once" }, { roomId, asViewOnce: true });
|
|
251
|
+
|
|
252
|
+
// sending reaction message
|
|
253
|
+
// empty string for removing reaction
|
|
254
|
+
wa.reaction("π", { message });
|
|
255
|
+
|
|
256
|
+
// editing message
|
|
257
|
+
const msg1 = await wa.text("Test edit", { roomId });
|
|
258
|
+
await wa.edit("Editing success", { message: msg1?.message });
|
|
259
|
+
|
|
260
|
+
// deleting message
|
|
261
|
+
const msg2 = await wa.text("Test delete", { roomId });
|
|
262
|
+
await wa.delete("Deleting success", { message: msg2?.message });
|
|
263
|
+
|
|
264
|
+
// sending location message
|
|
265
|
+
wa.location({ latitude: 24.121231, longitude: 55.1121221, ...other }, { roomId });
|
|
266
|
+
|
|
267
|
+
// sending contact message
|
|
268
|
+
wa.contact({ fullname: "Kejaa", whatsAppNumber: 628123456789, ...other }, { roomId });
|
|
269
|
+
|
|
270
|
+
// sending polling message
|
|
271
|
+
wa.poll({ name: "Are you love me?", answers: ["yes", "maybe", "no"] }, { roomId });
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
### Sending Media
|
|
277
|
+
|
|
278
|
+
```js
|
|
279
|
+
// sending image message
|
|
280
|
+
wa.text({ image: "https://github.com/zaadevofc.png", text: "Test image message" }, { roomId });
|
|
281
|
+
// buffer
|
|
282
|
+
wa.text({ image: fs.readFileSync("example/file.png"), text: "Test image message" }, { roomId });
|
|
283
|
+
|
|
284
|
+
// sending sticker message
|
|
285
|
+
wa.text({ sticker: "https://github.com/zaadevofc.png" }, { roomId });
|
|
286
|
+
|
|
287
|
+
// sending gif message
|
|
288
|
+
wa.text({ gif: "https://qu.ax/nTFwh.mp4" }, { roomId });
|
|
289
|
+
|
|
290
|
+
// sending video message
|
|
291
|
+
wa.text({ video: "https://qu.ax/nTFwh.mp4", text: "Test video message" }, { roomId });
|
|
292
|
+
|
|
293
|
+
// sending video note message
|
|
294
|
+
wa.text({ videoNote: "https://qu.ax/nTFwh.mp4" }, { roomId });
|
|
295
|
+
|
|
296
|
+
// sending audio message
|
|
297
|
+
// use .ogg format for better device support
|
|
298
|
+
wa.text({ audio: "https://qu.ax/oeSCG.ogg" }, { roomId });
|
|
299
|
+
|
|
300
|
+
// sending voice note message
|
|
301
|
+
// use .ogg format for better device support
|
|
302
|
+
wa.text({ audioNote: "https://qu.ax/oeSCG.ogg" }, { roomId });
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
|
|
307
|
+
### Presence Update
|
|
308
|
+
|
|
309
|
+
```js
|
|
310
|
+
// available presence types:
|
|
311
|
+
// typing | recording | online | offline | paused
|
|
312
|
+
wa.presence("typing", { roomId });
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
### Get Profile
|
|
318
|
+
|
|
319
|
+
```js
|
|
320
|
+
// get user profile
|
|
321
|
+
wa.profile("6281223456789@s.whatsapp.net");
|
|
322
|
+
|
|
323
|
+
// get group profile
|
|
324
|
+
wa.profile("1209999@g.us");
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
---
|
|
328
|
+
|
|
329
|
+
### Reject Call
|
|
330
|
+
|
|
331
|
+
```js
|
|
332
|
+
wa.on("calls", (ctx) => {
|
|
333
|
+
wa.rejectCall({ callId: ctx.callId, callerId: ctx.callerId });
|
|
334
|
+
|
|
335
|
+
// for simplify
|
|
336
|
+
wa.rejectCall(ctx);
|
|
337
|
+
});
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
---
|
|
341
|
+
|
|
342
|
+
## π Issues & Feedback
|
|
343
|
+
|
|
344
|
+
If you encounter any problems or have feature requests, please open an issue:
|
|
345
|
+
[https://github.com/zeative/zaileys/issues](https://github.com/zeative/zaileys/issues)
|
|
346
|
+
|
|
347
|
+
---
|
|
348
|
+
|
|
349
|
+
## β€οΈ Funding & Support
|
|
350
|
+
|
|
351
|
+
If you find Zaileys useful, consider supporting development:
|
|
352
|
+
|
|
353
|
+
- [Buy me a coffee β](https://trakteer.id/zaadevofc)
|
|
354
|
+
- β Star the repo on GitHub
|
|
355
|
+
- Spread the word
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
|
|
359
|
+
## π License
|
|
360
|
+
|
|
361
|
+
Distributed under the **MIT License**. See [`LICENSE`](https://github.com/zeative/zaileys/blob/main/LICENSE) for details.
|
|
362
|
+
|
|
363
|
+
---
|
|
364
|
+
|
|
365
|
+
## π Acknowledgements
|
|
366
|
+
|
|
367
|
+
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!"
|
|
368
|
+
|
|
369
|
+
> Happy coding! π
|