baileys-wa-master
v1.7.34
Published
Node.js master implementation for WhatsApp using Baileys
Maintainers
Readme
WA Master - WhatsApp Multi-Client Manager
WA Master is a scalable, efficient, and fault-tolerant multi-client management solution for WhatsApp built on Node.js using the Baileys library. This system leverages Redis for data storage and caching, providing robust features like event handling, worker threads, and LRU caching.
Features
- Multi-client Management: Manage multiple WhatsApp clients simultaneously.
- Worker Thread Architecture: Each client runs in its dedicated worker thread.
- Redis Integration: Store and retrieve chats, messages, and other data efficiently using Redis.
- Scalable and Resilient: Supports reconnections, error handling, and maximum restart attempts.
- Event-driven System: Process and respond to various WhatsApp events like messages, presence updates, and connections.
- TypeScript Support: Strong type safety for all components and handlers.
Table of Contents
Installation
Prerequisites
- Node.js (>= 16.x)
- Redis server (>= 6.x)
Steps
- Clone this repository:
git clone https://github.com/your-username/wa-master.git
cd wa-master- Install dependencies:
npm install- Start Redis server:
redis-serverUsage
Starting the Application
To start managing WhatsApp clients:
npm startSample Code
Below is an example to demonstrate adding and managing a WhatsApp client:
import { WAMaster } from './src/index';
import { WAClientConfig } from './src/client/types';
const master = new WAMaster();
const clientConfig: WAClientConfig = {
clientId: 'unique-client-id',
redisStoreUrl: 'redis://localhost:6379',
browser: ['Chrome', '91', 'MacOS'],
};
master.startClient(clientConfig);
master.on('messages.upsert', (data) => {
console.log('New messages:', data);
});Configuration Options
RedisStorage
The RedisStorage class handles data operations using Redis. It provides methods to register, fetch, and clean up data.
Key Options:
| Option | Type | Default | Description |
|------------------|---------------|------------|------------------------------------------------|
| sessionId | string | Required | Unique identifier for the client session. |
| redis | RedisClient | Required | Instance of Redis client for storage. |
| logger | Logger | null | Optional logger for debugging. |
WAClientConfig
| Option | Type | Default | Description |
|-------------------------|---------------|------------|--------------------------------------------|
| clientId | string | Required | Unique client identifier. |
| redisStoreUrl | string | Required | URL of the Redis instance. |
| browser | string[] | Required | Browser information for WhatsApp Web. |
| shouldSyncHistoryMessage | boolean | false | Whether to sync history messages. |
API Reference
WAMaster Class
startClient(clientConfig: WAClientConfig): void
Starts a new WhatsApp client with the given configuration.
stopClient(clientId: string): void
Stops a running WhatsApp client.
on<T>(event: T, callback: Function): void
Registers a callback for a specific event.
off<T>(event: T, callback: Function): void
Removes a callback for a specific event.
Contributing
Contributions are welcome! To contribute:
- Fork the repository.
- Create a feature branch:
git checkout -b feature/your-feature. - Commit your changes:
git commit -m 'Add new feature'. - Push the branch:
git push origin feature/your-feature. - Submit a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
For more information, visit the GitHub Repository.
