zaileys 3.3.0 โ†’ 4.0.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/README.MD DELETED
@@ -1,1280 +0,0 @@
1
- <div align="center">
2
-
3
- <img alt="Zaileys - Simplified WhatsApp Node.js TypeScript/JavaScript API" src="https://github.com/zeative/zeative/blob/main/libraries/zaileys/zaileys-clean.png?raw=true" width="140">
4
-
5
- <h1 align="center">Zaileys - Simplified WhatsApp Node.js <br /> TypeScript/JavaScript API</h1>
6
-
7
- <br>
8
-
9
- <div align="center">
10
- <a href="https://www.npmjs.com/package/zaileys"><img src="https://img.shields.io/npm/v/zaileys.svg" alt="NPM Version"></a>
11
- <a href="https://www.npmjs.com/package/zaileys"><img src="https://img.shields.io/npm/dw/zaileys?label=npm&color=%23CB3837" alt="NPM Downloads"></a>
12
- <a href="https://github.com/zeative/zaileys/releases"><img src="https://img.shields.io/npm/dt/zaileys" alt="NPM Downloads"></a>
13
- <a href="https://github.com/zeative/zaileys"><img src="https://img.shields.io/github/languages/code-size/zeative/zaileys" alt="GitHub Code Size"></a>
14
- <a href="https://github.com/zeative/zaileys"><img src="https://img.shields.io/badge/TypeScript-5.0%2B-blue?style=flat-square&logo=typescript" alt="TypeScript"></a>
15
- </div>
16
-
17
- <div align="center">
18
- <a href="https://github.com/zeative/zaileys"><img src="https://img.shields.io/github/license/zeative/zaileys" alt="GitHub License"></a>
19
- <a href="https://discord.gg/KBHhTTVUc5"><img alt="Discord" src="https://img.shields.io/discord/1105833273415962654?logo=discord&label=discord&link=https%3A%2F%2Fgithub.com%2Fzeative%2Fzaileys"></a>
20
- <a href="https://chat.whatsapp.com/GlQfvc83mSH3F6ov06vuCt"><img alt="WhatsApp" src="https://img.shields.io/badge/WhatsApp-Group-25D366?logo=whatsapp&logoColor=white"></a>
21
- <a href="https://github.com/zeative/zaileys"><img src="https://img.shields.io/github/stars/zeative/zaileys" alt="GitHub Stars"></a>
22
- <a href="https://github.com/zeative/zaileys"><img src="https://img.shields.io/github/forks/zeative/zaileys" alt="GitHub Forks"></a>
23
- <a href="https://github.com/zeative/zaileys"><img src="https://img.shields.io/github/watchers/zeative/zaileys" alt="GitHub Watchers"></a>
24
- <a href="https://deepwiki.com/zeative/zaileys"><img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki"></a>
25
- </div>
26
-
27
- <br>
28
-
29
- <div align="center">
30
- <p>
31
- <b>Zaileys</b> is a powerful, type-safe wrapper around <a href="https://github.com/WhiskeySockets/Baileys">Baileys</a>, designed to simplify the development of WhatsApp bots. It provides a robust architecture with built-in state management, middleware support, and easy-to-use event handlers, making it perfect for building scalable and maintainable WhatsApp applications.
32
- </p>
33
- </div>
34
-
35
- <div align="center">
36
-
37
- [๐Ÿš€ Overview](#-overview) &nbsp;&nbsp;โ€ข&nbsp;&nbsp;
38
- [๐Ÿชถ Features](#-features) &nbsp;&nbsp;โ€ข&nbsp;&nbsp;
39
- [๐Ÿ“ฆ Installation](#-installation) &nbsp;&nbsp;โ€ข&nbsp;&nbsp;
40
- [๐Ÿ Starter Kit](#-starter-kit) &nbsp;&nbsp;โ€ข&nbsp;&nbsp;
41
- [โšก Quick Start](#-quick-start) &nbsp;&nbsp;โ€ข&nbsp;&nbsp;
42
- [๐Ÿงฉ Plugins](#-plugins) &nbsp;&nbsp;โ€ข&nbsp;&nbsp;
43
- [๐Ÿ“จ Sending Messages](#-sending-messages) &nbsp;&nbsp;โ€ข&nbsp;&nbsp;
44
- [๐Ÿ‘ฅ Group Management](#-group-management) &nbsp;&nbsp;โ€ข&nbsp;&nbsp;
45
- [๐Ÿ“ฐ Newsletter Management](#-newsletter-channel) &nbsp;&nbsp;โ€ข&nbsp;&nbsp;
46
- [๐ŸŒ Community Management](#-community-management) &nbsp;&nbsp;โ€ข&nbsp;&nbsp;
47
- [๐Ÿ”’ Privacy](#-privacy-settings) &nbsp;&nbsp;โ€ข&nbsp;&nbsp;
48
- [๐Ÿค Contributing](#-contributing)
49
-
50
- <br>
51
-
52
- <a href="https://discord.gg/KBHhTTVUc5"><img alt="Discord" src="https://discord.com/api/guilds/1105833273415962654/widget.png?style=banner2"></a>
53
-
54
- </div>
55
-
56
- </div>
57
-
58
- <br>
59
-
60
- ---
61
-
62
- ## ๐Ÿš€ Overview
63
-
64
- > Zaileys solves the complexity of managing raw WhatsApp socket connections by providing a high-level, opinionated API. It is built for developers who need to create bots, customer support agents, or automated notification systems without getting bogged down in protocol details.
65
-
66
- Targeting **Node.js** and **TypeScript** developers, Zaileys integrates essential features like rate limiting, session management, and input validation out of the box.
67
-
68
- ### ๐ŸŒŸ What's New in v3 (Performance & Stability Core)
69
-
70
- - ๐Ÿš€ **Unified Store Architecture**: Say goodbye to messy caches! We've elegantly grouped all scattered memory into a single, highly-optimized **Registry Pattern**. Enjoy zero memory leaks and strict namespaces for absolute peace of mind.
71
- - โšก **FireAndForget v3 Engine**: Background tasks just got superpowers! Now fully event-based with smart priority channels (`CRITICAL` to `LOW`). It automatically prevents queue clogs, handles smart retries, and shuts down gracefully.
72
- - ๐Ÿ›ก๏ธ **Auto-Healing Connections**: Maximum uptime, zero headaches! Zaileys now brilliantly catches nasty connection drops (like those sneaky `405` stale sessions) and seamlessly auto-reconnects behind the scenes instead of crashing.
73
- - ๐ŸŽฌ **Decoupled Media Processing**: We've trimmed the fat! All FFmpeg and image magic are now safely housed in an ultra-robust standalone package (`@zaadevofc/media-process`), making the core platform incredibly lightweight.
74
- - ๐ŸŽ๏ธ **Lightning Database & Slim Dependencies**: Speed is everything. We crushed bloat by upgrading to blazing-fast `lmdb` and swapping heavy libraries (`zod`, `lodash`) for modern speed demons like `valibot` and `radashi`.
75
-
76
- ## ๐Ÿชถ Features
77
-
78
- - โœ… **Type-Safe** - Full TypeScript + `Valibot` validation with autocomplete
79
- - โœ… **Middleware** - Intercept and process events globally
80
- - โœ… **Plugin System** - Drop-in file-based plugins with on/off controls
81
- - โœ… **State Management** - Built-in [LMDB](https://github.com/kriszyp/lmdb-js) for blazing-fast database persistence with **auto chunking** for heap safety
82
- - โœ… **Rate Limiting** - Anti-spam protection powered by lightning-fast native LRU bounds
83
- - โœ… **Multi-Device** - QR code or Pairing Code authentication
84
- - โœ… **Built-in FFmpeg** - No external dependencies for media processing
85
- - โœ… **Interactive Buttons** - Simple buttons, URL, copy code, call buttons, multi-card carousel and lists
86
- - โœ… **Auto Clean Up** - Periodic database maintenance to save space
87
-
88
- ## ๐ŸŽจ Concepts & Architecture
89
-
90
- **Client** - Your bot's brain. Manages connections, events, and the entire lifecycle.
91
-
92
- **Context** - Rich event objects with all the data and helpers you need.
93
-
94
- **Middleware** - Pre-process events for logging, auth, spam filtering, or custom logic.
95
-
96
- **Plugins** - Drop files in `plugins/` directory. Auto-loaded, zero config.
97
-
98
- **Store** - Lightning-fast database (`LMDB`) that auto-syncs chats, contacts, messages, and cryptographic keys.
99
-
100
- ## ๐Ÿ“ฆ Installation
101
-
102
- Install `zaileys` using your preferred package manager:
103
-
104
- ```bash
105
- npm install zaileys
106
- # or
107
- pnpm add zaileys
108
- # or
109
- yarn add zaileys
110
- ```
111
-
112
- > **Note**: Requires Node.js v20+ and TypeScript for best experience.
113
-
114
- > **FFmpeg**: No need to install FFmpeg separately! It's already bundled with Zaileys for seamless media processing (audio, video, stickers). You can disabled it if you want at `Client Configuration`.
115
-
116
- ## ๐Ÿ Starter Kit
117
-
118
- Prefer a ready-to-run setup? We provide a complete example that covers messages, media, buttons, carousel, polls, and more โ€” ready to copy and go.
119
-
120
- ๐Ÿ‘‰ [**examples/basic.ts**](./examples/basic.ts) โ€” Clean, comprehensive starter with all features demonstrated
121
-
122
- ## โšก Quick Start
123
-
124
- Here is a minimal example to get your bot running with QR code authentication:
125
-
126
- ```typescript
127
- import { Client } from 'zaileys';
128
- // or
129
- const { Client } = require('zaileys');
130
-
131
- const wa = new Client({
132
- // dynamic session you can change
133
- session: 'zaileys', // default
134
-
135
- // qr code
136
- authType: 'qr',
137
-
138
- // pairing code
139
- authType: 'pairing',
140
- phoneNumber: 6280000000,
141
-
142
- // for detailed logs
143
- // fancyLogs: true,
144
-
145
- // if you want to disable built-in ffmpeg
146
- // disableFFmpeg: true,
147
-
148
- // plugin configuration
149
- pluginsDir: 'plugins', // default
150
- pluginsHmr: true, // default: true (auto reload plugins on change)
151
-
152
- sticker: {
153
- authorName: 'your name',
154
- packageName: 'package name',
155
- quality: 80,
156
- shape: 'circle', // output sticker must be circle
157
- },
158
- });
159
-
160
- wa.on('messages', async (ctx) => {
161
- if (ctx.text == 'ping') {
162
- await wa.send(ctx.roomId, 'Pong! ๐Ÿ“');
163
- }
164
- });
165
- ```
166
-
167
- <details>
168
- <summary>โœจ Structure of <b>ctx</b> on event listener <code>messages</code></summary>
169
-
170
- ```jsonc
171
- {
172
- "uniqueId": "Z4D3FCXXXXXXXXXXXXX",
173
- "channelId": "Z4D3FCXXXXXXXXXXXXX",
174
-
175
- "chatId": "ACAE07XXXXXXXXXXXXX",
176
- "chatType": "text",
177
-
178
- "receiverId": "628xxxxxxxx@s.whatsapp.net",
179
- "receiverName": "Zaileys",
180
-
181
- "roomId": "120xxxxxxxx@g.us",
182
- "roomName": "Group Test",
183
- "senderLid": "272xxxxxxxx@lid",
184
-
185
- "senderId": "628xxxxxxxx@s.whatsapp.net",
186
- "senderName": "kejaa",
187
- "senderDevice": "android",
188
-
189
- "timestamp": 1766045633000,
190
- "text": "World Hello! https://github.com/zeative/zaileys",
191
-
192
- "mentions": ["@628xxxxxxxx", "@123xxxxxxxx"],
193
- "links": ["https://github.com/zeative/zaileys"],
194
-
195
- "isBot": false,
196
- "isFromMe": false,
197
- "isPrefix": false,
198
- "isTagMe": false,
199
-
200
- "isStatusMention": false,
201
- "isGroupStatusMention": false,
202
- "isHideTags": true,
203
-
204
- "isSpam": false,
205
- "isGroup": true,
206
- "isNewsletter": false,
207
- "isQuestion": false,
208
- "isStory": false,
209
-
210
- "isViewOnce": false,
211
- "isEdited": false,
212
- "isDeleted": false,
213
- "isPinned": false,
214
- "isUnPinned": false,
215
-
216
- "isBroadcast": false,
217
- "isEphemeral": false,
218
- "isForwarded": false,
219
-
220
- "citation": {
221
- "authors": [AsyncFunction (anonymous)],
222
- "banned": [AsyncFunction (anonymous)]
223
- },
224
-
225
- "media": {
226
- // ...
227
- // buffer promise
228
- // stream promise
229
- },
230
-
231
- "message": [Function (anonymous)],
232
- "replied": {} // MessagesContext
233
- }
234
-
235
- ````
236
- </details>
237
-
238
- ## ๐Ÿ› ๏ธ Configuration
239
-
240
- The `Client` constructor accepts a configuration object. Below are the valid options based on the library's type definitions.
241
-
242
- ### General Options
243
-
244
- These options apply to both authentication methods:
245
-
246
- | Option | Type | Default | Description |
247
- | :---------------- | :-------- | :---------- | :-------------------------------------- |
248
- | `session` | `string` | `'zaileys'` | Name of the session folder. |
249
- | `prefix` | `string` | `undefined` | Command prefix (e.g., `'/'`). |
250
- | `showLogs` | `boolean` | `true` | Enable internal logging. |
251
- | `fancyLogs` | `boolean` | `false` | Enable detailed, fancy log output. |
252
- | `ignoreMe` | `boolean` | `true` | Ignore messages sent by the bot itself. |
253
- | `syncFullHistory` | `boolean` | `true` | Sync full chat history on startup. |
254
- | `pluginsDir` | `string` | `'plugins'` | Directory where plugins are located. |
255
- | `pluginsHmr` | `boolean` | `true` | Enable Hot Module Replacement for plugins. |
256
- | `showSpinner` | `boolean` | `true` | Shows a loading console spinner for internal system events. |
257
- | `maxReplies` | `number` | `3` | Restricts recursive payload parsing for nested replied chains. |
258
- | `cleanupDays` | `number` | `7` | Days to keep messages before auto-deletion. |
259
- | `autoCleanUp` | `object` | `undefined` | Configuration for periodic database cleanup. |
260
- | `disableFFmpeg` | `boolean` | `false` | Disable built-in FFmpeg installers. |
261
- | `deleteSessionOnLogout`| `boolean`| `false` | Automatically deletes invalid `.session` state and forces a fresh QR scan if connection expires (loggedOut code 401). |
262
-
263
- ### Automation Options
264
-
265
- | Option | Type | Default | Description |
266
- | :--------------- | :-------- | :------ | :--------------------------------------------------------- |
267
- | `autoRead` | `boolean` | `true` | Automatically mark messages as read. |
268
- | `autoOnline` | `boolean` | `true` | Automatically set presence to online. |
269
- | `autoPresence` | `boolean` | `true` | Automatically send presence updates (composing/recording). |
270
- | `autoMentions` | `boolean` | `true` | Automatically handle mentions. |
271
- | `autoRejectCall` | `boolean` | `true` | Automatically reject incoming calls. |
272
-
273
- ### Advanced Configuration
274
-
275
- | Option | Type | Description |
276
- | :---------- | :------- | :------------------------------------------------------------------------------ |
277
- | `limiter` | `object` | Rate limiting configuration. Default: `maxMessages: 20, durationMs: 10_000`. |
278
- | `fakeReply` | `object` | Configuration for fake reply provider. |
279
- | `sticker` | `object` | Default metadata for sticker creation (`packageName`, `authorName`, `quality`, `shape`). |
280
- | `citation` | `object` | Custom citation sources. |
281
-
282
- ## ๐Ÿ’ก Advanced Usage
283
-
284
- ### Middleware & Spam Protection
285
-
286
- You can use middleware to filter messages or add custom logic before your handlers run.
287
-
288
- ```typescript
289
- wa.use(async (ctx, next) => {
290
- if (ctx.messages.isSpam) {
291
- console.warn(`Spam detected from ${ctx.messages.senderName}`);
292
- return;
293
- }
294
-
295
- await next();
296
- });
297
- ````
298
-
299
- ### ๐Ÿงฉ Plugins
300
-
301
- Zaileys features a built-in file-based plugin system with **Hot Module Replacement (HMR)** support. By default, it looks for plugins in the `plugins` directory of your project root and automatically reloads them when you make changes.
302
-
303
- **0. Configuration:**
304
- You can customize the plugin directory and HMR behavior in the `Client` constructor:
305
-
306
- ```typescript
307
- const wa = new Client({
308
- pluginsDir: 'my-plugins', // Custom plugins directory
309
- pluginsHmr: true, // Enable/disable HMR (default: true)
310
- });
311
- ```
312
-
313
- **1. Create a plugin file** (e.g., `plugins/hello.ts`):
314
-
315
- also nested file `plugins/nested1/nested2/hello.ts`
316
-
317
- ```typescript
318
- import { definePlugins } from 'zaileys';
319
-
320
- export default definePlugins(
321
- async (wa, ctx) => {
322
- await wa.send(ctx.messages.roomId, 'Hello from plugin!');
323
- },
324
- {
325
- matcher: ['/hello', '!hello'], // Trigger commands
326
- metadata: {
327
- description: 'A simple hello world plugin',
328
- },
329
- },
330
- );
331
- ```
332
-
333
- **2. Extract plugin information** (optional):
334
-
335
- ```typescript
336
- const pluginsInfo = wa.plugins.getPluginsInfo();
337
-
338
- /* Example output
339
- [
340
- {
341
- matcher: ['/hello', '!hello'],
342
- metadata: {
343
- description: 'A simple hello world plugin',
344
- },
345
- }
346
- ]
347
- */
348
- ```
349
-
350
- This returns an array of all loaded plugins with their `matcher` and `metadata`, useful for generating help menus or listing available commands.
351
-
352
- **3. Plugin Controls:**
353
-
354
- ```typescript
355
- // Disable all plugins
356
- wa.plugins.disableAll();
357
-
358
- // Enable all plugins
359
- wa.plugins.enableAll();
360
-
361
- // Disable specific plugin by matcher
362
- wa.plugins.disable('/hello');
363
-
364
- // Enable specific plugin
365
- wa.plugins.enable('/hello');
366
-
367
- // Disable all plugins in a folder (e.g., plugins/admin/)
368
- wa.plugins.disableByParent('admin');
369
-
370
- // Enable all plugins in a folder
371
- wa.plugins.enableByParent('admin');
372
-
373
- // Check if plugins are globally enabled
374
- wa.plugins.isEnabled(); // true/false
375
- ```
376
-
377
- ### ๐Ÿ” Citation (Custom Authorization)
378
-
379
- Citation allows you to define custom authorization logic by creating named checkers that verify if a user is in a specific list (e.g., premium users, banned users).
380
-
381
- **1. Configure citation sources** in the client options:
382
-
383
- ```typescript
384
- const wa = new Client({
385
- authType: 'qr',
386
- citation: {
387
- premium: async () => {
388
- // const numbers = await fetch...
389
- return [6280000000, 12388888888];
390
- },
391
- banned: async () => {
392
- return [6285555555555];
393
- },
394
- },
395
- });
396
- ```
397
-
398
- **2. Use citation in your message handlers**:
399
-
400
- ```typescript
401
- wa.on('messages', async (ctx) => {
402
- const isBanned = await ctx.citation.banned();
403
- const isPremium = await ctx.citation.premium();
404
-
405
- if (isBanned) return;
406
-
407
- if (isPremium) {
408
- await wa.send(ctx.roomId, 'Premium feature unlocked!');
409
- }
410
- });
411
- ```
412
-
413
- Each citation function returns `true` if the sender matches any ID in the returned list, `false` otherwise.
414
-
415
- **How it works:**
416
-
417
- Citation functions return an array of phone numbers, group id and lid Internally, Zaileys compares the sender's ID against this list by checking:
418
-
419
- - `roomId` - The chat/group ID
420
- - `senderId` - The sender's WhatsApp ID
421
- - `senderLid` - The sender's LID
422
-
423
- If any of these match a number in your returned array, the citation check returns `true`. This makes it flexible for both individual chats and group scenarios.
424
-
425
- ### ๐Ÿ”Œ Context Injection
426
-
427
- Context Injection allows you to inject custom data that is accessible in every message context.
428
-
429
- **1. Inject data:**
430
-
431
- ```typescript
432
- // Inject data anywhere in your app
433
- wa.inject('user', { name: 'Kejaa', role: 'admin' });
434
- wa.inject('config', { debug: true, version: '1.0.0' });
435
- ```
436
-
437
- **2. Access injected data in handlers:**
438
-
439
- ```typescript
440
- wa.on('messages', async (ctx) => {
441
- console.log(ctx.injection.user); // { name: 'John', role: 'admin' }
442
- console.log(ctx.injection.config); // { debug: true, version: '1.0.0' }
443
- });
444
- ```
445
-
446
- **3. Manage injections:**
447
-
448
- ```typescript
449
- // Get injection value
450
- const user = wa.getInjection('user');
451
-
452
- // Remove specific injection
453
- wa.removeInjection('user');
454
-
455
- // Clear all injections
456
- wa.clearInjections();
457
- ```
458
-
459
- This is perfect for sharing database connections, user sessions, or configuration across all handlers.
460
-
461
- ### ๐Ÿ›ก๏ธ Auto-Healing
462
-
463
- Zaileys includes an intelligent `HealthManager` that monitors your connection and automatically repairs corrupted sessions.
464
-
465
- - **Bad MAC Repair**: Automatically detects "Bad MAC" errors and repairs the affected session keys without requiring a full logout.
466
- - **Log Suppression**: Silences noisy stack traces and internal error messages from `libsignal-node` to keep your terminal clean.
467
- - **Zero Config**: Enabled by default and works silently in the background.
468
-
469
- ### ๐Ÿงน Auto Clean Up
470
-
471
- Keep your database lean and performant by enabling automatic cleanup of old messages.
472
-
473
- ```typescript
474
- const wa = new Client({
475
- autoCleanUp: {
476
- enabled: true,
477
- intervalMs: 60 * 60 * 1000, // Run every 1 hour
478
- maxAgeMs: 24 * 60 * 60 * 1000, // Delete messages older than 24 hours
479
- scopes: ['messages'], // Database scopes to clean
480
- },
481
- });
482
- ```
483
-
484
- The `CleanUpManager` runs in the background and ensures your storage usage stays within limits.
485
-
486
- ## ๐Ÿ“ซ Sending Messages
487
-
488
- > **Quick Jump:** [Text](#send-text) ยท [Reply](#reply-to-message) ยท [Forward](#forward-message) ยท [Media](#send-media) ยท [Banner](#send-with-banner) ยท [Location](#send-location) ยท [Contact](#send-contact) ยท [Poll](#send-poll) ยท [Reaction](#send-reaction) ยท [Presence](#update-presence) ยท [Mentions](#mentions) ยท [Edit & Delete](#edit--delete-messages) ยท [Buttons](#interactive-buttons) ยท [Member Label](#member-label)
489
-
490
- ### Send Text
491
-
492
- Send a simple text message to any chat.
493
-
494
- ```typescript
495
- await wa.send(ctx.roomId, 'Hello World!');
496
-
497
- await wa.send(ctx.roomId, {
498
- text: 'Hello with options!',
499
- });
500
- ```
501
-
502
- ### Reply to Message
503
-
504
- Reply to a specific message using the `replied` option.
505
-
506
- ```typescript
507
- await wa.send(ctx.roomId, {
508
- text: 'This is a reply!',
509
- replied: ctx.message(),
510
- });
511
- ```
512
-
513
- ### Forward Message
514
-
515
- Forward message to any chat.
516
-
517
- ```typescript
518
- await wa.forward(ctx.roomId, {
519
- text: 'Forwarded message',
520
- isForwardedMany: true,
521
- });
522
- ```
523
-
524
- ### Send Media
525
-
526
- Send images, videos, audio, stickers, or documents. Media can be a URL, Buffer, or base64 string.
527
-
528
- **Image:**
529
-
530
- ```typescript
531
- await wa.send(ctx.roomId, {
532
- image: 'https://example.com/image.jpg',
533
- caption: 'Check this out!',
534
- });
535
-
536
- await wa.send(ctx.roomId, {
537
- image: fs.readFileSync('./image.jpg'),
538
- caption: 'Image from buffer',
539
- isViewOnce: true,
540
- });
541
- ```
542
-
543
- **Video:**
544
-
545
- ```typescript
546
- await wa.send(ctx.roomId, {
547
- video: 'https://example.com/video.mp4',
548
- caption: 'Cool video!',
549
- ptv: true,
550
- });
551
- ```
552
-
553
- **Audio:**
554
-
555
- ```typescript
556
- await wa.send(ctx.roomId, {
557
- audio: 'https://example.com/audio.mp3',
558
- ptt: true,
559
- });
560
- ```
561
-
562
- **Sticker:**
563
-
564
- ```typescript
565
- // support gif and video
566
- await wa.send(ctx.roomId, {
567
- sticker: 'https://example.com/sticker.mp4',
568
- shape: 'circle', // default: 'default' | 'circle' | 'rounded' | 'oval'
569
- });
570
- ```
571
-
572
- **Document:**
573
-
574
- ```typescript
575
- await wa.send(ctx.roomId, {
576
- document: 'https://example.com/file.pdf',
577
- fileName: 'document.pdf',
578
- caption: 'Here is the file',
579
- });
580
- ```
581
-
582
- ### Send with Banner
583
-
584
- Send messages with an external ad reply banner (link preview).
585
-
586
- ```typescript
587
- await wa.send(ctx.roomId, {
588
- text: 'Banner message!',
589
- banner: {
590
- thumbnailUrl: 'https://github.com/zeative.png',
591
- sourceUrl: 'https://jaa.web.id',
592
- title: 'Test Banner',
593
- body: 'Hello World!',
594
- },
595
- });
596
- ```
597
-
598
- ### Send Location
599
-
600
- Send location with coordinates.
601
-
602
- ```typescript
603
- await wa.send(ctx.roomId, {
604
- location: {
605
- latitude: -6.2,
606
- longitude: 106.816666,
607
- title: 'Jakarta',
608
- footer: 'Capital of Indonesia',
609
- url: 'https://maps.google.com/?q=-6.200000,106.816666',
610
- },
611
- });
612
- ```
613
-
614
- ### Send Contact
615
-
616
- Send one or multiple contacts.
617
-
618
- ```typescript
619
- await wa.send(ctx.roomId, {
620
- contacts: {
621
- title: 'My Contacts',
622
- contacts: [
623
- {
624
- fullname: 'John Doe',
625
- phoneNumber: 6281234567890,
626
- organization: 'Company Inc.',
627
- },
628
- {
629
- fullname: 'Jane Smith',
630
- phoneNumber: 6289876543210,
631
- },
632
- ],
633
- },
634
- });
635
- ```
636
-
637
- ### Send Poll
638
-
639
- Create a poll with multiple options.
640
-
641
- ```typescript
642
- await wa.send(ctx.roomId, {
643
- poll: {
644
- name: 'What is your favorite color?',
645
- answers: ['Red', 'Blue', 'Green', 'Yellow'],
646
- isMultiple: false,
647
- },
648
- });
649
- ```
650
-
651
- ### Send Reaction
652
-
653
- React to a message with an emoji.
654
-
655
- ```typescript
656
- await wa.reaction(ctx.message(), '๐Ÿ‘');
657
-
658
- await wa.reaction(ctx.message(), 'โค๏ธ');
659
- ```
660
-
661
- ### Update Presence
662
-
663
- Update your presence status in a chat.
664
-
665
- ```typescript
666
- await wa.presence(ctx.roomId, 'typing');
667
-
668
- await wa.presence(ctx.roomId, 'recording');
669
- ```
670
-
671
- ### Mentions
672
-
673
- Mentions are automatically detected when `autoMentions` is enabled (default: `true`).
674
-
675
- ```typescript
676
- // support lid
677
- await wa.send(ctx.roomId, 'Hello @6281234567890!');
678
- ```
679
-
680
- ### Edit & Delete Messages
681
-
682
- **Edit message:**
683
-
684
- ```typescript
685
- const sent = await wa.send(ctx.roomId, 'Original text');
686
-
687
- setTimeout(async () => {
688
- await wa.edit(sent, 'Edited text');
689
- }, 2000);
690
- ```
691
-
692
- **Delete message:**
693
-
694
- ```typescript
695
- const sent = await wa.send(ctx.roomId, 'This will be deleted');
696
-
697
- setTimeout(async () => {
698
- await wa.delete(sent);
699
- }, 2000);
700
-
701
- // or multiple messages
702
- await wa.delete([sent1, sent2]);
703
- ```
704
-
705
- ### Interactive Buttons
706
-
707
- Send messages with interactive buttons.
708
-
709
- **Simple Buttons:**
710
-
711
- > โœ… Simple button type is **fully supported on all devices** โ€” Android, iOS, and **WhatsApp Desktop/Web**.
712
-
713
- ```typescript
714
- await wa.button(ctx.roomId, {
715
- text: 'Choose an option:',
716
- buttons: {
717
- type: 'simple',
718
- footer: 'Footer text',
719
- data: [
720
- { id: 'btn1', text: 'Option 1' },
721
- { id: 'btn2', text: 'Option 2' },
722
- { id: 'btn3', text: 'Option 3' },
723
- ],
724
- },
725
- });
726
- ```
727
-
728
- **Interactive Buttons:**
729
-
730
- > โš ๏ธ Experimental, only support Android/iPhone
731
-
732
- ```typescript
733
- await wa.button(ctx.roomId, {
734
- text: 'Interactive menu:',
735
- buttons: {
736
- type: 'interactive',
737
- footer: 'Footer text',
738
- data: [
739
- { type: 'quick_reply', id: 'reply1', text: 'Quick Reply' },
740
- { type: 'cta_url', text: 'Visit Website', url: 'https://example.com' },
741
- { type: 'cta_copy', id: 'copy1', text: 'Copy Code', copy: 'PROMO123' },
742
- { type: 'cta_call', text: 'Call Us', phoneNumber: '+6281234567890' },
743
- ],
744
- },
745
- });
746
- ```
747
-
748
- **Lists Buttons:**
749
-
750
- > โš ๏ธ Experimental, not supported on some devices. Don't use in production!
751
-
752
- ```typescript
753
- await wa.button(ctx.roomId, {
754
- text: 'Choose an option:',
755
- buttons: {
756
- type: 'interactive',
757
- footer: 'Footer text',
758
- data: [
759
- {
760
- type: 'single_select',
761
- text: 'Choose an option:',
762
- section: [
763
- {
764
- title: 'Section 1',
765
- rows: [
766
- { id: 'btn1', title: 'Option 1' },
767
- { id: 'btn2', title: 'Option 2' },
768
- { id: 'btn3', title: 'Option 3' },
769
- ],
770
- },
771
- ],
772
- },
773
- ],
774
- },
775
- });
776
- ```
777
-
778
- **Carousel Buttons:**
779
-
780
- > โš ๏ธ Carousel button is supported on **Android** and **WhatsApp Desktop/Web** only. iOS is currently not supported. Each card can include an image or video header with native flow buttons.
781
-
782
- ```typescript
783
- await wa.button(ctx.roomId, {
784
- text: 'Check out our products!',
785
- buttons: {
786
- type: 'carousel',
787
- data: [
788
- {
789
- body: 'Product A - Premium quality',
790
- footer: 'Starting from $9.99',
791
- header: {
792
- title: 'Product A',
793
- image: 'https://example.com/product-a.jpg',
794
- hasMediaAttachment: true,
795
- },
796
- nativeFlow: [
797
- { type: 'cta_url', text: 'Buy Now', url: 'https://example.com/product-a' },
798
- { type: 'quick_reply', id: 'fav_a', text: 'โค๏ธ Favorite' },
799
- ],
800
- },
801
- {
802
- body: 'Product B - Best value',
803
- footer: 'Starting from $4.99',
804
- header: {
805
- title: 'Product B',
806
- image: 'https://example.com/product-b.jpg',
807
- hasMediaAttachment: true,
808
- },
809
- nativeFlow: [
810
- { type: 'cta_url', text: 'Buy Now', url: 'https://example.com/product-b' },
811
- { type: 'cta_copy', id: 'code_b', text: 'Copy Promo Code', copy: 'SAVE20' },
812
- ],
813
- },
814
- ],
815
- },
816
- });
817
- ```
818
-
819
- ### Member Label
820
-
821
- Labeling user member on group chat.
822
-
823
- ```typescript
824
- await wa.memberLabel(ctx.roomId, 'Fullstack Developer');
825
- ```
826
-
827
- ## ๐Ÿ‘ฅ Group Management
828
-
829
- > **Quick Jump:** [Create](#create-group) ยท [Participants](#manage-participants) ยท [Profile](#group-profile) ยท [Settings](#group-settings) ยท [Invite Code](#invite-code) ยท [Metadata](#group-metadata) ยท [Join Requests](#join-requests) ยท [Fetch All](#fetch-all-groups) ยท [Ephemeral](#ephemeral-messages) ยท [Leave](#leave-group)
830
-
831
- Manage groups, participants, and settings easily.
832
-
833
- ### Create Group
834
-
835
- Create a new group with initial participants.
836
-
837
- ```typescript
838
- // Create group with name and participants
839
- const group = await wa.group.create('My Group', ['senderId']);
840
- console.log('Group created:', group);
841
- ```
842
-
843
- ### Manage Participants
844
-
845
- Add, remove, promote, or demote participants.
846
-
847
- ```typescript
848
- const groupId = '1234567890@g.us';
849
-
850
- // Add participants
851
- await wa.group.participant(groupId, ['senderId'], 'add');
852
-
853
- // Remove participants
854
- await wa.group.participant(groupId, [...], 'remove');
855
-
856
- // Promote to admin
857
- await wa.group.participant(groupId, [...], 'promote');
858
-
859
- // Demote to member
860
- await wa.group.participant(groupId, [...], 'demote');
861
- ```
862
-
863
- ### Group Profile
864
-
865
- Update group subject, description, or icon.
866
-
867
- ```typescript
868
- // Update subject
869
- await wa.group.profile(groupId, 'New Group Name', 'subject');
870
-
871
- // Update description
872
- await wa.group.profile(groupId, 'This is the new description', 'description');
873
-
874
- // Update group avatar (from URL or Buffer)
875
- await wa.group.profile(groupId, 'https://example.com/icon.jpg', 'avatar');
876
- ```
877
-
878
- ### Group Settings
879
-
880
- Configure group permissions.
881
-
882
- ```typescript
883
- // All members can send messages
884
- await wa.group.setting(groupId, 'open');
885
-
886
- // Only admins can send messages
887
- await wa.group.setting(groupId, 'close');
888
-
889
- // Only admins can edit group info
890
- await wa.group.setting(groupId, 'locked');
891
-
892
- // All members can edit group info
893
- await wa.group.setting(groupId, 'unlocked');
894
-
895
- // Only admins can add members
896
- await wa.group.setting(groupId, 'admin_add');
897
-
898
- // All members can add members
899
- await wa.group.setting(groupId, 'all_member_add');
900
- ```
901
-
902
- ### Invite Code
903
-
904
- Manage group invite links.
905
-
906
- ```typescript
907
- // Get current invite code
908
- const code = await wa.group.inviteCode(groupId, 'code');
909
- console.log('Invite link:', `https://chat.whatsapp.com/${code}`);
910
-
911
- // Revoke invite code
912
- await wa.group.inviteCode(groupId, 'revoke');
913
-
914
- // Get invite info
915
- const info = await wa.group.inviteCode('INVITE_CODE', 'info');
916
-
917
- // Join group via invite code
918
- await wa.group.inviteCode('INVITE_CODE', 'accept');
919
- ```
920
-
921
- ### Group Metadata
922
-
923
- Get full group metadata.
924
-
925
- ```typescript
926
- const metadata = await wa.group.metadata(groupId);
927
- console.log(metadata);
928
- ```
929
-
930
- ### Join Requests
931
-
932
- Manage pending join requests.
933
-
934
- ```typescript
935
- // Get list of pending requests
936
- const requests = await wa.group.requestJoinList(groupId);
937
-
938
- // Approve requests
939
- await wa.group.requestJoin(groupId, ['senderId'], 'approve');
940
-
941
- // Reject requests
942
- await wa.group.requestJoin(groupId, [...], 'reject');
943
- ```
944
-
945
- ### Fetch All Groups
946
-
947
- Get all groups the bot is part of.
948
-
949
- ```typescript
950
- const groups = await wa.group.fetchAllGroups();
951
- console.log('Joined groups:', Object.keys(groups).length);
952
- ```
953
-
954
- ### Ephemeral Messages
955
-
956
- Set disappearing messages in groups.
957
-
958
- ```typescript
959
- // Turn off disappearing messages
960
- await wa.group.ephemeral(groupId, 'off');
961
-
962
- // Set to 24 hours
963
- await wa.group.ephemeral(groupId, '24h');
964
-
965
- // Set to 7 days
966
- await wa.group.ephemeral(groupId, '7d');
967
-
968
- // Set to 90 days
969
- await wa.group.ephemeral(groupId, '90d');
970
- ```
971
-
972
- ### Leave Group
973
-
974
- Leave group.
975
-
976
- ```typescript
977
- await wa.group.leave(groupId);
978
- ```
979
-
980
- ## ๐Ÿ“ฐ Newsletter (Channel)
981
-
982
- Create and manage WhatsApp Channels (Newsletters).
983
-
984
- > **Quick Jump:** [Create](#create-channel) ยท [Actions](#channel-actions) ยท [Update](#update-channel) ยท [Info](#channel-info) ยท [Messages](#manage-messages) ยท [Admin](#admin-actions)
985
-
986
- ### Create Channel
987
-
988
- ```typescript
989
- const channel = await wa.newsletter.create('My Channel', 'Description here');
990
- console.log('Channel created:', channel);
991
- ```
992
-
993
- ### Channel Actions
994
-
995
- Follow, unfollow, mute, or unmute a channel.
996
-
997
- ```typescript
998
- const channelId = '1234567890@newsletter';
999
-
1000
- // Follow
1001
- await wa.newsletter.action(channelId, 'follow');
1002
-
1003
- // Unfollow
1004
- await wa.newsletter.action(channelId, 'unfollow');
1005
-
1006
- // Mute
1007
- await wa.newsletter.action(channelId, 'mute');
1008
-
1009
- // Unmute
1010
- await wa.newsletter.action(channelId, 'unmute');
1011
- ```
1012
-
1013
- ### Update Channel
1014
-
1015
- Update channel info.
1016
-
1017
- ```typescript
1018
- // Update name
1019
- await wa.newsletter.update(channelId, 'New Name', 'name');
1020
-
1021
- // Update description
1022
- await wa.newsletter.update(channelId, 'New Description', 'description');
1023
-
1024
- // Update picture (URL/Buffer)
1025
- await wa.newsletter.update(channelId, 'https://example.com/image.jpg', 'picture');
1026
-
1027
- // Remove picture
1028
- await wa.newsletter.removePicture(channelId);
1029
- ```
1030
-
1031
- ### Channel Info
1032
-
1033
- Get channel details.
1034
-
1035
- ```typescript
1036
- // Get metadata by ChannelId
1037
- const meta = await wa.newsletter.metadata(channelId, 'jid');
1038
-
1039
- // Get metadata by Invite Code
1040
- const metaInvite = await wa.newsletter.metadata('INVITE_CODE', 'invite');
1041
-
1042
- // Get subscribers
1043
- const subs = await wa.newsletter.subscribers(channelId);
1044
-
1045
- // Get admin count
1046
- const adminCount = await wa.newsletter.adminCount(channelId);
1047
- ```
1048
-
1049
- ### Manage Messages
1050
-
1051
- Fetch messages or react to them.
1052
-
1053
- ```typescript
1054
- // Fetch messages
1055
- const since = new Date() - 1000 * 60 * 60 * 24; // 1 day
1056
- const after = new Date();
1057
-
1058
- const count = 10;
1059
-
1060
- const messages = await wa.newsletter.fetchMessages(channelId, count, since, after);
1061
-
1062
- // React to message
1063
- await wa.newsletter.reaction(channelId, 'chatId', '๐Ÿ‘');
1064
- ```
1065
-
1066
- ### Admin Actions
1067
-
1068
- Manage channel ownership and admins.
1069
-
1070
- ```typescript
1071
- // Change owner
1072
- await wa.newsletter.changeOwner(channelId, 'senderId');
1073
-
1074
- // Demote admin
1075
- await wa.newsletter.demote(channelId, 'senderId');
1076
-
1077
- // Delete channel
1078
- await wa.newsletter.delete(channelId);
1079
- ```
1080
-
1081
- ## ๐ŸŒ Community Management
1082
-
1083
- Create and manage WhatsApp Communities.
1084
-
1085
- > **Quick Jump:** [Create](#create-community) ยท [Create Group](#create-group-in-community) ยท [Groups](#manage-groups) ยท [Info](#community-info) ยท [Participants](#manage-participants-1) ยท [Invite](#invite-code-1) ยท [Settings](#community-settings) ยท [Leave](#leave-community)
1086
-
1087
- ### Create Community
1088
-
1089
- ```typescript
1090
- const community = await wa.community.create('My Community', 'Description here');
1091
- console.log('Community created:', community);
1092
- ```
1093
-
1094
- ### Create Group in Community
1095
-
1096
- Create a new group linked to a community.
1097
-
1098
- ```typescript
1099
- const communityId = '1234567890@g.us';
1100
- const group = await wa.community.createGroup('New Group', ['senderId'], communityId);
1101
- ```
1102
-
1103
- ### Manage Groups
1104
-
1105
- Link or unlink groups from a community.
1106
-
1107
- ```typescript
1108
- const groupId = '0987654321@g.us';
1109
-
1110
- // Link group
1111
- await wa.community.group(communityId, 'link', groupId);
1112
-
1113
- // Unlink group
1114
- await wa.community.group(communityId, 'unlink', groupId);
1115
-
1116
- // Get linked groups
1117
- const linkedGroups = await wa.community.group(communityId, 'linked');
1118
- ```
1119
-
1120
- ### Community Info
1121
-
1122
- Get metadata or update info.
1123
-
1124
- ```typescript
1125
- // Get metadata
1126
- const meta = await wa.community.metadata(communityId);
1127
-
1128
- // Update subject
1129
- await wa.community.update(communityId, 'subject', 'New Name');
1130
-
1131
- // Update description
1132
- await wa.community.update(communityId, 'description', 'New Description');
1133
- ```
1134
-
1135
- ### Manage Participants
1136
-
1137
- Manage community participants.
1138
-
1139
- ```typescript
1140
- // List participants
1141
- const participants = await wa.community.participants(communityId, 'list');
1142
-
1143
- // Add participant
1144
- await wa.community.participants(communityId, 'update', 'add', ['senderId']);
1145
-
1146
- // Remove participant
1147
- await wa.community.participants(communityId, 'update', 'remove', ['senderId']);
1148
-
1149
- // Promote to admin
1150
- await wa.community.participants(communityId, 'update', 'promote', ['senderId']);
1151
-
1152
- // Demote to member
1153
- await wa.community.participants(communityId, 'update', 'demote', ['senderId']);
1154
- ```
1155
-
1156
- ### Invite Code
1157
-
1158
- Manage community invite links.
1159
-
1160
- ```typescript
1161
- // Get invite code
1162
- const code = await wa.community.invite(communityId, 'code');
1163
-
1164
- // Revoke invite code
1165
- await wa.community.invite(communityId, 'revoke');
1166
-
1167
- // Get invite info
1168
- const info = await wa.community.invite('INVITE_CODE', 'info');
1169
-
1170
- // Join via invite code
1171
- await wa.community.invite('INVITE_CODE', 'accept');
1172
- ```
1173
-
1174
- ### Community Settings
1175
-
1176
- Configure community settings.
1177
-
1178
- ```typescript
1179
- // Toggle ephemeral messages
1180
- await wa.community.settings(communityId, 'ephemeral', 86400); // 24 hours
1181
-
1182
- // Who can add members? 'all_member_add' or 'admin_add'
1183
- await wa.community.settings(communityId, 'memberAdd', 'admin_add');
1184
-
1185
- // Join approval mode? 'on' or 'off'
1186
- await wa.community.settings(communityId, 'approval', 'on');
1187
- ```
1188
-
1189
- ### Leave Community
1190
-
1191
- Leave a community.
1192
-
1193
- ```typescript
1194
- await wa.community.leave(communityId);
1195
- ```
1196
-
1197
- ## ๐Ÿ”’ Privacy Settings
1198
-
1199
- Manage your privacy settings and block list.
1200
-
1201
- > **Quick Jump:** [Block/Unblock](#blockunblock) ยท [Configuration](#privacy-configuration) ยท [Get Settings](#get-settings)
1202
-
1203
- ### Block/Unblock
1204
-
1205
- ```typescript
1206
- // Block user
1207
- await wa.privacy.block('senderId');
1208
-
1209
- // Unblock user
1210
- await wa.privacy.unblock('senderId');
1211
-
1212
- // Get blocklist
1213
- const blocklist = await wa.privacy.blocklist();
1214
- ```
1215
-
1216
- ### Privacy Configuration
1217
-
1218
- Update privacy settings.
1219
-
1220
- ```typescript
1221
- // Last Seen: 'all', 'contacts', 'contact_blacklist', 'none'
1222
- await wa.privacy.lastSeen('contacts');
1223
-
1224
- // Online: 'all', 'match_last_seen'
1225
- await wa.privacy.online('match_last_seen');
1226
-
1227
- // Profile Picture: 'all', 'contacts', 'contact_blacklist', 'none'
1228
- await wa.privacy.picture('all');
1229
-
1230
- // Status: 'all', 'contacts', 'contact_blacklist', 'none'
1231
- await wa.privacy.status('contacts');
1232
-
1233
- // Read Receipts: 'all', 'none'
1234
- await wa.privacy.readReceipt('all');
1235
-
1236
- // Group Add: 'all', 'contacts', 'contact_blacklist', 'none'
1237
- await wa.privacy.groupsAdd('contacts');
1238
-
1239
- // Default Disappearing Mode: 'off', '24h', '7d', '90d'
1240
- await wa.privacy.ephemeral('90d');
1241
- ```
1242
-
1243
- ### Get Settings
1244
-
1245
- Fetch current privacy settings.
1246
-
1247
- ```typescript
1248
- const settings = await wa.privacy.getSettings();
1249
- console.log(settings);
1250
- ```
1251
-
1252
- ## ๐Ÿค Contributing
1253
-
1254
- Contributions are welcome! Please follow these steps:
1255
-
1256
- 1. Fork the repository.
1257
- 2. Create new branch: `git checkout -b feature/my-feature`.
1258
- 3. Commit your changes: `git commit -m 'Add some feature'`.
1259
- 4. Push to the branch: `git push origin feature/my-feature`.
1260
- 5. Open Pull Request.
1261
-
1262
- ## ๐ŸŽฏ Issues & Feedback
1263
-
1264
- **If you encounter any problems or have feature requests, please open an [issue](https://github.com/zeative/zaileys/issues)**
1265
-
1266
- - [Buy me coffee โ˜•](https://saweria.co/zaadevofc)
1267
- - [Ko-Fi](https://ko-fi.com/zaadevofc)
1268
- - [Trakteer](https://trakteer.id/zaadevofc)
1269
- - โญ Star the repo on GitHub
1270
-
1271
- ## ๐Ÿ“œ License
1272
-
1273
- Distributed under the **MIT License**. See [`LICENSE`](https://github.com/zeative/zaileys/blob/main/LICENSE) for details.
1274
-
1275
- <div align="left">
1276
- <p>
1277
- <img alt="Zaileys - Simplified WhatsApp Node.js TypeScript/JavaScript API" src="https://github.com/zeative/zeative/blob/main/libraries/zaileys/zaileys-clean.png?raw=true" width="28" align="center">
1278
- Copyright ยฉ 2025 zaadevofc. All rights reserved.
1279
- </p>
1280
- </div>