waengine 1.0.1
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 +911 -0
- package/examples/easy-bot-examples.js +186 -0
- package/examples/multi-device-example.js +253 -0
- package/examples/quick-start.js +10 -0
- package/examples/simple-multi-device.js +42 -0
- package/package.json +67 -0
- package/src/client.js +412 -0
- package/src/core.js +79 -0
- package/src/device-manager.js +404 -0
- package/src/easy-bot.js +744 -0
- package/src/groups.js +156 -0
- package/src/index.js +6 -0
- package/src/message.js +628 -0
- package/src/messages.js +80 -0
- package/src/multi-client.js +374 -0
- package/src/qr.js +65 -0
- package/src/utils.js +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,911 @@
|
|
|
1
|
+
# 🚀 WhatsApp Multi Client
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/whatsapp-multi-client)
|
|
4
|
+
[](https://www.npmjs.com/package/whatsapp-multi-client)
|
|
5
|
+
[](https://github.com/yourusername/whatsapp-multi-client/blob/main/LICENSE)
|
|
6
|
+
[](https://nodejs.org/)
|
|
7
|
+
|
|
8
|
+
**The most powerful WhatsApp Bot Library with Multi-Device Support & EasyBot API**
|
|
9
|
+
|
|
10
|
+
🎯 **Perfect for beginners AND professionals**
|
|
11
|
+
🔧 **Multi-Device Load Balancing**
|
|
12
|
+
⚡ **3-Line Bot Creation**
|
|
13
|
+
🚀 **120+ Features Built-in**
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## ⚡ Quick Start (3 Lines!)
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
import { quickBot } from "whatsapp-multi-client";
|
|
21
|
+
|
|
22
|
+
quickBot()
|
|
23
|
+
.when("hello").reply("Hi! 👋")
|
|
24
|
+
.start();
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
**That's it!** Your WhatsApp bot is running! 🎉
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## 📦 Installation
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install whatsapp-multi-client
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**Requirements:**
|
|
38
|
+
- Node.js 16+
|
|
39
|
+
- A WhatsApp account for the bot
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## 🎯 Choose Your API
|
|
44
|
+
|
|
45
|
+
### 🟢 **EasyBot** - For Beginners
|
|
46
|
+
Perfect for quick bots and learning:
|
|
47
|
+
|
|
48
|
+
```javascript
|
|
49
|
+
import { createBot } from "whatsapp-multi-client";
|
|
50
|
+
|
|
51
|
+
createBot()
|
|
52
|
+
.when("ping").reply("Pong! 🏓")
|
|
53
|
+
.when("hello").reply("Hi there! 👋")
|
|
54
|
+
.command("time", () => new Date().toLocaleString())
|
|
55
|
+
.start();
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 🔵 **Advanced API** - For Professionals
|
|
59
|
+
Full control and customization:
|
|
60
|
+
|
|
61
|
+
```javascript
|
|
62
|
+
import { WhatsAppClient } from "whatsapp-multi-client";
|
|
63
|
+
|
|
64
|
+
const client = new WhatsAppClient();
|
|
65
|
+
client.setPrefix('!');
|
|
66
|
+
|
|
67
|
+
client.on('message', async (msg) => {
|
|
68
|
+
if (msg.text === 'hello') {
|
|
69
|
+
await msg.simulateTyping('Hello! How can I help?');
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
await client.connect();
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 🟡 **Multi-Device** - For Scale
|
|
77
|
+
Run multiple WhatsApp accounts simultaneously:
|
|
78
|
+
|
|
79
|
+
```javascript
|
|
80
|
+
import { MultiWhatsAppClient } from "whatsapp-multi-client";
|
|
81
|
+
|
|
82
|
+
const multiClient = new MultiWhatsAppClient({
|
|
83
|
+
maxDevices: 3,
|
|
84
|
+
loadBalancing: 'round-robin'
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
await multiClient.addDevice('bot1');
|
|
88
|
+
await multiClient.addDevice('bot2');
|
|
89
|
+
await multiClient.connect();
|
|
90
|
+
|
|
91
|
+
// Messages automatically load-balanced across devices!
|
|
92
|
+
await multiClient.sendMessage(chatId, { text: 'Hello from multi-device!' });
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## ⚡ EasyBot - For Beginners
|
|
98
|
+
|
|
99
|
+
### **Super Simple API**
|
|
100
|
+
Create WhatsApp bots in minutes, not hours!
|
|
101
|
+
|
|
102
|
+
```javascript
|
|
103
|
+
import { quickBot } from "whatsapp-multi-client";
|
|
104
|
+
|
|
105
|
+
quickBot()
|
|
106
|
+
.when("hello").reply("Hi! 👋")
|
|
107
|
+
.start();
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### **Action Chaining**
|
|
111
|
+
Chain multiple actions elegantly:
|
|
112
|
+
|
|
113
|
+
```javascript
|
|
114
|
+
import { createBot } from "whatsapp-multi-client";
|
|
115
|
+
|
|
116
|
+
createBot()
|
|
117
|
+
.when("important")
|
|
118
|
+
.react("⚠️")
|
|
119
|
+
.type(2)
|
|
120
|
+
.reply("This is important!")
|
|
121
|
+
.react("✅")
|
|
122
|
+
.done()
|
|
123
|
+
.start();
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### **EasyBot Features**
|
|
127
|
+
```javascript
|
|
128
|
+
const bot = createBot()
|
|
129
|
+
// Simple responses
|
|
130
|
+
.when("hello").reply("Hi! 👋")
|
|
131
|
+
.when("ping").reply("Pong! 🏓")
|
|
132
|
+
|
|
133
|
+
// Auto-responses
|
|
134
|
+
.autoReply("hi", "Hello!")
|
|
135
|
+
.autoReply("bye", "Goodbye!")
|
|
136
|
+
|
|
137
|
+
// Commands
|
|
138
|
+
.command("help", "I can help you!")
|
|
139
|
+
.command("time", () => new Date().toLocaleString())
|
|
140
|
+
|
|
141
|
+
// Templates with variables
|
|
142
|
+
.template("greeting", "Hello {name}! Today is {day}")
|
|
143
|
+
.when("welcome").useTemplate("greeting")
|
|
144
|
+
|
|
145
|
+
// Conditional logic
|
|
146
|
+
.if("is group").then("reply Hello group!")
|
|
147
|
+
.if("contains bot").then("react 🤖")
|
|
148
|
+
|
|
149
|
+
// Multi-device (optional)
|
|
150
|
+
.enableMultiDevice(2)
|
|
151
|
+
|
|
152
|
+
.start();
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### **EasyBot Multi-Device**
|
|
156
|
+
```javascript
|
|
157
|
+
import { multiBot } from "whatsapp-multi-client";
|
|
158
|
+
|
|
159
|
+
multiBot(3) // 3 devices
|
|
160
|
+
.when("test").reply("Multi-device test!")
|
|
161
|
+
.command("status", "📊 Multi-device running!")
|
|
162
|
+
.start();
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### **Template System**
|
|
166
|
+
```javascript
|
|
167
|
+
bot
|
|
168
|
+
.template("info", "Hello {name}! Time: {time}, Date: {date}")
|
|
169
|
+
.template("status", "Chat: {chat} | Day: {day}")
|
|
170
|
+
.when("info").useTemplate("info")
|
|
171
|
+
.when("status").useTemplate("status");
|
|
172
|
+
|
|
173
|
+
// Available variables:
|
|
174
|
+
// {name} - Sender name
|
|
175
|
+
// {sender} - Sender JID
|
|
176
|
+
// {time} - Current time
|
|
177
|
+
// {date} - Current date
|
|
178
|
+
// {datetime} - Date + time
|
|
179
|
+
// {day} - Weekday
|
|
180
|
+
// {chat} - "Group" or "Private"
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## 🔥 Multi-Device Support
|
|
186
|
+
|
|
187
|
+
### **Multi-Device System**
|
|
188
|
+
Run 2-3 WhatsApp accounts simultaneously for higher availability and load balancing!
|
|
189
|
+
|
|
190
|
+
```javascript
|
|
191
|
+
import { MultiWhatsAppClient } from "whatsapp-multi-client";
|
|
192
|
+
|
|
193
|
+
const multiClient = new MultiWhatsAppClient({
|
|
194
|
+
maxDevices: 3,
|
|
195
|
+
loadBalancing: 'round-robin' // round-robin, random, least-used, failover
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
// Add devices
|
|
199
|
+
await multiClient.addDevice('bot1');
|
|
200
|
+
await multiClient.addDevice('bot2');
|
|
201
|
+
await multiClient.addDevice('bot3');
|
|
202
|
+
|
|
203
|
+
// Connect all
|
|
204
|
+
await multiClient.connect();
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### **Load Balancing Strategies**
|
|
208
|
+
```javascript
|
|
209
|
+
// Round-robin (default)
|
|
210
|
+
multiClient.setLoadBalancingStrategy('round-robin');
|
|
211
|
+
|
|
212
|
+
// Random selection
|
|
213
|
+
multiClient.setLoadBalancingStrategy('random');
|
|
214
|
+
|
|
215
|
+
// Least used device
|
|
216
|
+
multiClient.setLoadBalancingStrategy('least-used');
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### **Smart Messaging**
|
|
220
|
+
```javascript
|
|
221
|
+
// Load-balanced sending
|
|
222
|
+
await multiClient.sendMessage(chatId, { text: 'Hello!' });
|
|
223
|
+
|
|
224
|
+
// Broadcast to all devices
|
|
225
|
+
await multiClient.broadcast(chatId, { text: 'Broadcast!' });
|
|
226
|
+
|
|
227
|
+
// With failover (if one device fails)
|
|
228
|
+
await multiClient.sendWithFailover(chatId, { text: 'Failover!' });
|
|
229
|
+
|
|
230
|
+
// Specific device
|
|
231
|
+
await multiClient.sendFromDevice('bot1', chatId, { text: 'From Bot1!' });
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### **Multi-Device Events**
|
|
235
|
+
```javascript
|
|
236
|
+
multiClient.on('message', async (msg) => {
|
|
237
|
+
console.log(`Message from device: ${msg.deviceId}`);
|
|
238
|
+
|
|
239
|
+
// Reply from same device
|
|
240
|
+
await msg.replyFromSameDevice('Same device reply');
|
|
241
|
+
|
|
242
|
+
// Reply via load balancing
|
|
243
|
+
await msg.replyFromAnyDevice('Load balanced reply');
|
|
244
|
+
|
|
245
|
+
// Broadcast reply
|
|
246
|
+
await msg.broadcastReply('Broadcast reply');
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
// Device status events
|
|
250
|
+
multiClient.on('device.connected', (data) => {
|
|
251
|
+
console.log(`✅ Device ${data.deviceId} connected`);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
multiClient.on('device.disconnected', (data) => {
|
|
255
|
+
console.log(`🔴 Device ${data.deviceId} disconnected`);
|
|
256
|
+
});
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### **Health Monitoring**
|
|
260
|
+
```javascript
|
|
261
|
+
// Get status
|
|
262
|
+
const status = multiClient.getStatus();
|
|
263
|
+
console.log(`${status.activeDevices}/${status.totalDevices} devices active`);
|
|
264
|
+
|
|
265
|
+
// Health check
|
|
266
|
+
const health = multiClient.getHealthCheck();
|
|
267
|
+
console.log(`Health: ${health.healthPercentage}% - ${health.recommendation}`);
|
|
268
|
+
|
|
269
|
+
// Device stats
|
|
270
|
+
const stats = multiClient.getDeviceStats();
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### **Multi-Device Benefits:**
|
|
274
|
+
✅ **Higher availability** - If one account gets banned, others continue
|
|
275
|
+
✅ **Load distribution** - Spread messages across multiple accounts
|
|
276
|
+
✅ **Rate limit bypass** - WhatsApp limits per account
|
|
277
|
+
✅ **Automatic failover** - Seamless switching on failures
|
|
278
|
+
✅ **Separate auth** - Each device has its own authentication
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
## 🔐 Authentication
|
|
283
|
+
|
|
284
|
+
### **Persistent Authentication**
|
|
285
|
+
- ✅ **One-time QR scan** → Always auto-connect
|
|
286
|
+
- ✅ **Microsoft Edge integration** - QR code in browser
|
|
287
|
+
- ✅ **Terminal fallback** - QR code in terminal
|
|
288
|
+
- ✅ **Auto-reconnect** - Automatic reconnection
|
|
289
|
+
|
|
290
|
+
```javascript
|
|
291
|
+
const client = new WhatsAppClient({
|
|
292
|
+
authDir: "./auth", // Auth data storage
|
|
293
|
+
printQR: false, // QR in browser (true = terminal)
|
|
294
|
+
logLevel: "silent" // Log level
|
|
295
|
+
});
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
---
|
|
299
|
+
|
|
300
|
+
## 💬 Message System
|
|
301
|
+
|
|
302
|
+
### **Basic Messaging**
|
|
303
|
+
```javascript
|
|
304
|
+
// Simple reply
|
|
305
|
+
await msg.reply("Hello!")
|
|
306
|
+
|
|
307
|
+
// With mentions
|
|
308
|
+
await msg.reply("Hello @user!", [userJid])
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### **Media Messages**
|
|
312
|
+
```javascript
|
|
313
|
+
// Images
|
|
314
|
+
await msg.sendImage("path/image.jpg", "Caption", [mentions])
|
|
315
|
+
|
|
316
|
+
// Videos
|
|
317
|
+
await msg.sendVideo("path/video.mp4", "Caption", [mentions])
|
|
318
|
+
|
|
319
|
+
// Audio
|
|
320
|
+
await msg.sendAudio("path/audio.mp3")
|
|
321
|
+
|
|
322
|
+
// Stickers
|
|
323
|
+
await msg.sendSticker("path/sticker.webp")
|
|
324
|
+
|
|
325
|
+
// Documents
|
|
326
|
+
await msg.sendDocument("path/file.pdf", "filename.pdf", [mentions])
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
### **Special Messages**
|
|
330
|
+
```javascript
|
|
331
|
+
// Location
|
|
332
|
+
await msg.sendLocation(latitude, longitude)
|
|
333
|
+
|
|
334
|
+
// Contact
|
|
335
|
+
await msg.sendContact(vcard, "Display Name")
|
|
336
|
+
|
|
337
|
+
// Emoji reaction
|
|
338
|
+
await msg.react("😂")
|
|
339
|
+
|
|
340
|
+
// Delete message
|
|
341
|
+
await msg.delete()
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
### **Message Properties**
|
|
345
|
+
```javascript
|
|
346
|
+
msg.id // Message ID
|
|
347
|
+
msg.from // Sender JID
|
|
348
|
+
msg.text // Message text
|
|
349
|
+
msg.type // text, image, video, audio, etc.
|
|
350
|
+
msg.isGroup // true/false
|
|
351
|
+
msg.timestamp // Unix timestamp
|
|
352
|
+
msg.raw // Raw Baileys object
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
---
|
|
356
|
+
|
|
357
|
+
## 🎭 Typing Indicator
|
|
358
|
+
|
|
359
|
+
### **Manual Control**
|
|
360
|
+
```javascript
|
|
361
|
+
// Start/stop typing
|
|
362
|
+
await msg.visualWrite(true) // Typing ON
|
|
363
|
+
await msg.visualWrite(false) // Typing OFF
|
|
364
|
+
|
|
365
|
+
// Typing for specific time
|
|
366
|
+
await msg.typeFor(3000) // 3 seconds typing
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
### **Typing + Reply Combined**
|
|
370
|
+
```javascript
|
|
371
|
+
// Fixed time
|
|
372
|
+
await msg.typeAndReply("Message", 2000) // 2 seconds typing
|
|
373
|
+
|
|
374
|
+
// Realistic typing
|
|
375
|
+
await msg.simulateTyping("Long text...", {
|
|
376
|
+
typingSpeed: 50, // ms per character
|
|
377
|
+
minTypingTime: 1000, // Minimum time
|
|
378
|
+
maxTypingTime: 5000, // Maximum time
|
|
379
|
+
mentions: [userJid] // With mentions
|
|
380
|
+
})
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
---
|
|
384
|
+
|
|
385
|
+
## 👥 Group Management
|
|
386
|
+
|
|
387
|
+
### **Group Information**
|
|
388
|
+
```javascript
|
|
389
|
+
// Group metadata
|
|
390
|
+
const metadata = await client.get.GroupMetadata(groupId)
|
|
391
|
+
|
|
392
|
+
// All participants
|
|
393
|
+
const participants = await client.get.GroupParticipants(groupId)
|
|
394
|
+
|
|
395
|
+
// Only admins
|
|
396
|
+
const admins = await client.get.GroupAdmins(groupId)
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
### **User Management**
|
|
400
|
+
```javascript
|
|
401
|
+
// Add user
|
|
402
|
+
await client.add.user(groupId, [userJid], [mentions])
|
|
403
|
+
|
|
404
|
+
// Remove user
|
|
405
|
+
await client.kick.user(groupId, [userJid], [mentions])
|
|
406
|
+
|
|
407
|
+
// Promote to admin
|
|
408
|
+
await client.promote.user(groupId, [userJid], [mentions])
|
|
409
|
+
|
|
410
|
+
// Remove admin
|
|
411
|
+
await client.demote.user(groupId, [userJid], [mentions])
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
### **Mention System**
|
|
415
|
+
```javascript
|
|
416
|
+
// Mention single person
|
|
417
|
+
await msg.replyWithMention("Hello @user!", userJid)
|
|
418
|
+
|
|
419
|
+
// Mention all in group
|
|
420
|
+
await msg.mentionAll("Hello everyone!")
|
|
421
|
+
|
|
422
|
+
// Get mentions from message
|
|
423
|
+
const mentions = msg.getMentions()
|
|
424
|
+
|
|
425
|
+
// Check if mentioned
|
|
426
|
+
const isMentioned = msg.isMentioned(userJid)
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
---
|
|
430
|
+
|
|
431
|
+
## 🛡️ Permission System
|
|
432
|
+
|
|
433
|
+
### **Permission Checks**
|
|
434
|
+
```javascript
|
|
435
|
+
// Admin checks
|
|
436
|
+
const isAdmin = await msg.isAdmin() // Is sender admin?
|
|
437
|
+
const isBotAdmin = await msg.isBotAdmin() // Is bot admin?
|
|
438
|
+
const isOwner = await msg.isOwner() // Is sender owner?
|
|
439
|
+
|
|
440
|
+
// Chat type checks
|
|
441
|
+
const isGroup = msg.isGroup // Is group?
|
|
442
|
+
const isPrivate = msg.isPrivate() // Is private chat?
|
|
443
|
+
|
|
444
|
+
// Sender info
|
|
445
|
+
const senderJid = msg.getSender() // Sender JID
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
### **Usage in Commands**
|
|
449
|
+
```javascript
|
|
450
|
+
client.addCommand('kick', async (msg, args) => {
|
|
451
|
+
if (!msg.isGroup) {
|
|
452
|
+
return msg.reply('❌ Groups only!')
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
if (!(await msg.isAdmin())) {
|
|
456
|
+
return msg.reply('❌ Admins only!')
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
if (!(await msg.isBotAdmin())) {
|
|
460
|
+
return msg.reply('❌ Bot needs admin rights!')
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// Kick logic...
|
|
464
|
+
})
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
---
|
|
468
|
+
|
|
469
|
+
## 📊 Statistics System
|
|
470
|
+
|
|
471
|
+
### **Message Statistics**
|
|
472
|
+
```javascript
|
|
473
|
+
// Message counts
|
|
474
|
+
const stats = await msg.stats.getMessageCount()
|
|
475
|
+
// Returns: { total: 1234, today: 56, thisWeek: 234 }
|
|
476
|
+
|
|
477
|
+
// User activity
|
|
478
|
+
const activity = await msg.stats.getUserActivity(userId)
|
|
479
|
+
// Returns: { messagesCount: 123, lastSeen: Date, isActive: true }
|
|
480
|
+
|
|
481
|
+
// Group stats (groups only)
|
|
482
|
+
const groupStats = await msg.stats.getGroupStats()
|
|
483
|
+
// Returns: { groupName, totalMembers, admins, created, description }
|
|
484
|
+
|
|
485
|
+
// Top active users
|
|
486
|
+
const topUsers = await msg.stats.getMostActiveUsers(5)
|
|
487
|
+
|
|
488
|
+
// Messages by type
|
|
489
|
+
const messageTypes = await msg.stats.getMessagesByType()
|
|
490
|
+
// Returns: { text: 500, image: 100, video: 50, ... }
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
---
|
|
494
|
+
|
|
495
|
+
## 🎯 Command System
|
|
496
|
+
|
|
497
|
+
### **Prefix Setup**
|
|
498
|
+
```javascript
|
|
499
|
+
// Set prefix
|
|
500
|
+
const prefix = "!"
|
|
501
|
+
client.setPrefix(prefix)
|
|
502
|
+
|
|
503
|
+
// Register commands
|
|
504
|
+
client.addCommand('help', async (msg, args) => {
|
|
505
|
+
await msg.reply('Help text')
|
|
506
|
+
})
|
|
507
|
+
|
|
508
|
+
client.addCommand('ping', async (msg, args) => {
|
|
509
|
+
await msg.reply('Pong! 🏓')
|
|
510
|
+
})
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
### **Command Properties**
|
|
514
|
+
```javascript
|
|
515
|
+
// In message events
|
|
516
|
+
if (msg.isCommand) {
|
|
517
|
+
console.log(msg.command) // "help"
|
|
518
|
+
console.log(msg.args) // ["arg1", "arg2"]
|
|
519
|
+
console.log(msg.commandText) // "help arg1 arg2"
|
|
520
|
+
}
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
### **Command Management**
|
|
524
|
+
```javascript
|
|
525
|
+
// List commands
|
|
526
|
+
const commands = client.getCommands()
|
|
527
|
+
|
|
528
|
+
// Remove command
|
|
529
|
+
client.removeCommand('help')
|
|
530
|
+
|
|
531
|
+
// Get prefix
|
|
532
|
+
const currentPrefix = client.getPrefix()
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
---
|
|
536
|
+
|
|
537
|
+
## 📊 Poll Integration
|
|
538
|
+
|
|
539
|
+
### **Create Polls**
|
|
540
|
+
```javascript
|
|
541
|
+
// Simple poll
|
|
542
|
+
await msg.sendPoll('Favorite pizza?', ['Margherita', 'Pepperoni', 'Hawaiian'])
|
|
543
|
+
|
|
544
|
+
// Multi-selection poll
|
|
545
|
+
await msg.sendMultiPoll('Which colors?', ['Red', 'Blue', 'Green'], 2)
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
### **Fallback System**
|
|
549
|
+
If native polls don't work, the library automatically uses emoji fallback:
|
|
550
|
+
```
|
|
551
|
+
📊 **Favorite pizza?**
|
|
552
|
+
|
|
553
|
+
1️⃣ Margherita
|
|
554
|
+
2️⃣ Pepperoni
|
|
555
|
+
3️⃣ Hawaiian
|
|
556
|
+
|
|
557
|
+
_React with the corresponding emoji!_
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
---
|
|
561
|
+
|
|
562
|
+
## 🎧 Event System
|
|
563
|
+
|
|
564
|
+
### **Event Registration**
|
|
565
|
+
```javascript
|
|
566
|
+
// Message events
|
|
567
|
+
client.on('message', (msg) => {
|
|
568
|
+
console.log(`Message from ${msg.from}: ${msg.text}`)
|
|
569
|
+
})
|
|
570
|
+
|
|
571
|
+
// Command events
|
|
572
|
+
client.on('command', (msg) => {
|
|
573
|
+
console.log(`Command: ${msg.command}`)
|
|
574
|
+
})
|
|
575
|
+
|
|
576
|
+
// Connection events
|
|
577
|
+
client.on('connected', () => {
|
|
578
|
+
console.log('Connected!')
|
|
579
|
+
})
|
|
580
|
+
|
|
581
|
+
client.on('disconnected', (data) => {
|
|
582
|
+
console.log('Disconnected:', data.reason)
|
|
583
|
+
})
|
|
584
|
+
|
|
585
|
+
// Group events
|
|
586
|
+
client.on('group.participants.update', (update) => {
|
|
587
|
+
console.log('Group changed:', update)
|
|
588
|
+
})
|
|
589
|
+
|
|
590
|
+
// Presence events
|
|
591
|
+
client.on('presence.update', (update) => {
|
|
592
|
+
console.log('Status changed:', update)
|
|
593
|
+
})
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
### **Event Management**
|
|
597
|
+
```javascript
|
|
598
|
+
// Remove event handler
|
|
599
|
+
client.off('message', handler)
|
|
600
|
+
|
|
601
|
+
// Emit custom event
|
|
602
|
+
client.emit('custom-event', data)
|
|
603
|
+
```
|
|
604
|
+
|
|
605
|
+
---
|
|
606
|
+
|
|
607
|
+
## 📱 QR Code System
|
|
608
|
+
|
|
609
|
+
### **QR Code Generation**
|
|
610
|
+
```javascript
|
|
611
|
+
import { generateQRCode } from "whatsapp-multi-client"
|
|
612
|
+
|
|
613
|
+
// Generate QR code
|
|
614
|
+
await generateQRCode()
|
|
615
|
+
|
|
616
|
+
// QR code with data
|
|
617
|
+
await generateQRCode(qrData)
|
|
618
|
+
|
|
619
|
+
// Close browser
|
|
620
|
+
await closeBrowser()
|
|
621
|
+
```
|
|
622
|
+
|
|
623
|
+
### **Features**
|
|
624
|
+
- ✅ **Microsoft Edge integration** - Automatic opening
|
|
625
|
+
- ✅ **Terminal fallback** - QR in terminal if browser fails
|
|
626
|
+
- ✅ **Auto-close** - Browser closes automatically after login
|
|
627
|
+
|
|
628
|
+
---
|
|
629
|
+
|
|
630
|
+
## 🔧 Utility Functions
|
|
631
|
+
|
|
632
|
+
### **Connection Management**
|
|
633
|
+
```javascript
|
|
634
|
+
// Connect
|
|
635
|
+
await client.connect()
|
|
636
|
+
|
|
637
|
+
// Disconnect
|
|
638
|
+
await client.disconnect()
|
|
639
|
+
|
|
640
|
+
// Get status
|
|
641
|
+
const state = client.getConnectionState()
|
|
642
|
+
// Returns: { isConnected: true, socket: true }
|
|
643
|
+
```
|
|
644
|
+
|
|
645
|
+
### **Presence Management**
|
|
646
|
+
```javascript
|
|
647
|
+
// Global presence
|
|
648
|
+
await client.setOnline()
|
|
649
|
+
await client.setOffline()
|
|
650
|
+
await client.setTyping(chatId)
|
|
651
|
+
await client.setRecording(chatId)
|
|
652
|
+
await client.setPaused(chatId)
|
|
653
|
+
```
|
|
654
|
+
|
|
655
|
+
### **Message Type Detection**
|
|
656
|
+
```javascript
|
|
657
|
+
const type = client.getMessageType(message)
|
|
658
|
+
// Returns: text, image, video, audio, document, sticker, location, contact, unknown
|
|
659
|
+
```
|
|
660
|
+
|
|
661
|
+
---
|
|
662
|
+
|
|
663
|
+
## 📚 Examples
|
|
664
|
+
|
|
665
|
+
### **EasyBot (Beginners)**
|
|
666
|
+
```javascript
|
|
667
|
+
import { quickBot } from "whatsapp-multi-client";
|
|
668
|
+
|
|
669
|
+
// 3 lines = complete bot!
|
|
670
|
+
quickBot()
|
|
671
|
+
.when("hello").reply("Hi! 👋")
|
|
672
|
+
.start();
|
|
673
|
+
```
|
|
674
|
+
|
|
675
|
+
### **EasyBot with Action Chaining**
|
|
676
|
+
```javascript
|
|
677
|
+
import { createBot } from "whatsapp-multi-client";
|
|
678
|
+
|
|
679
|
+
createBot()
|
|
680
|
+
.when("important")
|
|
681
|
+
.react("⚠️") // Reaction
|
|
682
|
+
.type(2) // 2 seconds typing
|
|
683
|
+
.reply("Important!") // Reply
|
|
684
|
+
.react("✅") // Another reaction
|
|
685
|
+
.done() // Back to bot
|
|
686
|
+
|
|
687
|
+
.when("party")
|
|
688
|
+
.react("🎉")
|
|
689
|
+
.type(1)
|
|
690
|
+
.reply("Party! 🥳")
|
|
691
|
+
.done()
|
|
692
|
+
|
|
693
|
+
.command("help", "I can help you!")
|
|
694
|
+
.autoReply("hi", "Hello!")
|
|
695
|
+
.start();
|
|
696
|
+
```
|
|
697
|
+
|
|
698
|
+
### **EasyBot Multi-Device**
|
|
699
|
+
```javascript
|
|
700
|
+
import { multiBot } from "whatsapp-multi-client";
|
|
701
|
+
|
|
702
|
+
multiBot(2) // 2 devices
|
|
703
|
+
.when("test").reply("Multi-device test!")
|
|
704
|
+
.command("status", "📊 2 devices active!")
|
|
705
|
+
.start();
|
|
706
|
+
```
|
|
707
|
+
|
|
708
|
+
### **Multi-Device Bot**
|
|
709
|
+
```javascript
|
|
710
|
+
import { MultiWhatsAppClient } from "whatsapp-multi-client";
|
|
711
|
+
|
|
712
|
+
const multiClient = new MultiWhatsAppClient({
|
|
713
|
+
maxDevices: 3,
|
|
714
|
+
loadBalancing: 'round-robin'
|
|
715
|
+
});
|
|
716
|
+
|
|
717
|
+
// Add devices
|
|
718
|
+
await multiClient.addDevice('main-bot');
|
|
719
|
+
await multiClient.addDevice('backup-bot');
|
|
720
|
+
await multiClient.addDevice('support-bot');
|
|
721
|
+
|
|
722
|
+
// Commands for all devices
|
|
723
|
+
multiClient.setPrefix('!');
|
|
724
|
+
|
|
725
|
+
multiClient.addCommand('ping', async (msg) => {
|
|
726
|
+
await msg.replyFromSameDevice(`Pong from ${msg.deviceId}! 🏓`);
|
|
727
|
+
});
|
|
728
|
+
|
|
729
|
+
multiClient.addCommand('status', async (msg) => {
|
|
730
|
+
const status = multiClient.getStatus();
|
|
731
|
+
await msg.replyFromSameDevice(`📊 ${status.activeDevices}/${status.totalDevices} devices active`);
|
|
732
|
+
});
|
|
733
|
+
|
|
734
|
+
multiClient.addCommand('broadcast', async (msg, args) => {
|
|
735
|
+
const message = args.join(' ');
|
|
736
|
+
await multiClient.broadcast(msg.from, { text: `📢 ${message}` });
|
|
737
|
+
});
|
|
738
|
+
|
|
739
|
+
// Events
|
|
740
|
+
multiClient.on('message', async (msg) => {
|
|
741
|
+
if (msg.text === 'hello') {
|
|
742
|
+
// Load-balanced response
|
|
743
|
+
await multiClient.sendMessage(msg.from, {
|
|
744
|
+
text: `Hello from ${msg.deviceId}! 👋`
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
});
|
|
748
|
+
|
|
749
|
+
// Connect all devices
|
|
750
|
+
await multiClient.connect();
|
|
751
|
+
console.log("🎉 Multi-device bot running!");
|
|
752
|
+
```
|
|
753
|
+
|
|
754
|
+
### **Advanced Bot**
|
|
755
|
+
```javascript
|
|
756
|
+
import { WhatsAppClient } from "whatsapp-multi-client";
|
|
757
|
+
|
|
758
|
+
const client = new WhatsAppClient();
|
|
759
|
+
const prefix = "!";
|
|
760
|
+
client.setPrefix(prefix);
|
|
761
|
+
|
|
762
|
+
// Commands
|
|
763
|
+
client.addCommand('ping', async (msg) => {
|
|
764
|
+
await msg.typeAndReply('Pong! 🏓', 1000);
|
|
765
|
+
});
|
|
766
|
+
|
|
767
|
+
client.addCommand('info', async (msg) => {
|
|
768
|
+
await msg.visualWrite(true);
|
|
769
|
+
await new Promise(r => setTimeout(r, 2000));
|
|
770
|
+
await msg.visualWrite(false);
|
|
771
|
+
await msg.reply('Bot info: Running perfectly! ✅');
|
|
772
|
+
});
|
|
773
|
+
|
|
774
|
+
// Events
|
|
775
|
+
client.on('message', async (msg) => {
|
|
776
|
+
if (msg.text === 'hello') {
|
|
777
|
+
await msg.simulateTyping('Hello! How are you?');
|
|
778
|
+
}
|
|
779
|
+
});
|
|
780
|
+
|
|
781
|
+
await client.connect();
|
|
782
|
+
```
|
|
783
|
+
|
|
784
|
+
### **Interactive Bot**
|
|
785
|
+
```javascript
|
|
786
|
+
client.on('message', async (msg) => {
|
|
787
|
+
if (msg.text.includes('how are you')) {
|
|
788
|
+
await msg.visualWrite(true);
|
|
789
|
+
await new Promise(r => setTimeout(r, 3000));
|
|
790
|
+
await msg.visualWrite(false);
|
|
791
|
+
await msg.reply('I\'m doing great, thanks! 😊 How about you?');
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
if (msg.text.includes('poll')) {
|
|
795
|
+
await msg.quickType('Creating poll...');
|
|
796
|
+
await msg.sendPoll('How do you like the bot?', ['Great!', 'Good', 'Okay', 'Bad']);
|
|
797
|
+
}
|
|
798
|
+
});
|
|
799
|
+
```
|
|
800
|
+
|
|
801
|
+
---
|
|
802
|
+
|
|
803
|
+
## 🎮 Available Commands (Test Bot)
|
|
804
|
+
|
|
805
|
+
- **`!help`** - Show all commands
|
|
806
|
+
- **`!ping`** - Pong response
|
|
807
|
+
- **`!stats`** - Show statistics
|
|
808
|
+
- **`!kick @user`** - Kick user (admin only)
|
|
809
|
+
- **`!debug`** - Debug information
|
|
810
|
+
- **`!poll "Question" "Opt1" "Opt2"`** - Create poll
|
|
811
|
+
- **`!demo`** - Typing demo
|
|
812
|
+
- **`!customtype 3000 "Text"`** - Custom typing
|
|
813
|
+
- **`!slowtype "Text"`** - Slow typing
|
|
814
|
+
|
|
815
|
+
## 🔥 Feature Count
|
|
816
|
+
|
|
817
|
+
**Total: 120+ Functions and Features!**
|
|
818
|
+
|
|
819
|
+
- **Message Functions:** 15+
|
|
820
|
+
- **Group Functions:** 8+
|
|
821
|
+
- **Permission Functions:** 6+
|
|
822
|
+
- **Statistics Functions:** 5+
|
|
823
|
+
- **Typing Functions:** 8+
|
|
824
|
+
- **Command System:** 10+
|
|
825
|
+
- **Event System:** 8+
|
|
826
|
+
- **QR Functions:** 3+
|
|
827
|
+
- **Utility Functions:** 15+
|
|
828
|
+
- **Multi-Device System:** 20+
|
|
829
|
+
- **🆕 EasyBot System:** 25+
|
|
830
|
+
|
|
831
|
+
---
|
|
832
|
+
|
|
833
|
+
## 🚀 Why Choose This Library?
|
|
834
|
+
|
|
835
|
+
### **🎯 Three APIs in One**
|
|
836
|
+
- **EasyBot** - 3-line bot creation for beginners
|
|
837
|
+
- **Advanced** - Full control for professionals
|
|
838
|
+
- **Multi-Device** - Scale with multiple accounts
|
|
839
|
+
|
|
840
|
+
### **🔥 Unique Features**
|
|
841
|
+
- **Multi-Device Load Balancing** - Industry first!
|
|
842
|
+
- **Action Chaining** - jQuery-style bot building
|
|
843
|
+
- **Realistic Typing** - Human-like interactions
|
|
844
|
+
- **Edge QR Integration** - Seamless authentication
|
|
845
|
+
- **Template System** - Dynamic content with variables
|
|
846
|
+
|
|
847
|
+
### **💪 Production Ready**
|
|
848
|
+
- **Persistent Auth** - One-time setup
|
|
849
|
+
- **Auto Reconnection** - Handles disconnections
|
|
850
|
+
- **Health Monitoring** - Track device status
|
|
851
|
+
- **Error Handling** - Graceful failure recovery
|
|
852
|
+
- **TypeScript Support** - Full type definitions
|
|
853
|
+
|
|
854
|
+
### **📈 Scalable Architecture**
|
|
855
|
+
- **Load Balancing** - Distribute message load
|
|
856
|
+
- **Failover System** - Automatic device switching
|
|
857
|
+
- **Rate Limit Bypass** - Multiple account limits
|
|
858
|
+
- **Plugin Ready** - Extensible for v2.0
|
|
859
|
+
|
|
860
|
+
---
|
|
861
|
+
|
|
862
|
+
## 🤝 Contributing
|
|
863
|
+
|
|
864
|
+
We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
865
|
+
|
|
866
|
+
### **Quick Contribute**
|
|
867
|
+
1. Fork the repository
|
|
868
|
+
2. Create your feature branch: `git checkout -b feature/amazing-feature`
|
|
869
|
+
3. Commit your changes: `git commit -m 'Add amazing feature'`
|
|
870
|
+
4. Push to the branch: `git push origin feature/amazing-feature`
|
|
871
|
+
5. Open a Pull Request
|
|
872
|
+
|
|
873
|
+
---
|
|
874
|
+
|
|
875
|
+
## 📄 License
|
|
876
|
+
|
|
877
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
878
|
+
|
|
879
|
+
---
|
|
880
|
+
|
|
881
|
+
## 🔮 Roadmap (v2.0)
|
|
882
|
+
|
|
883
|
+
- **🔌 Plugin System** - Extensible architecture
|
|
884
|
+
- **💾 Database Integration** - Persistent storage
|
|
885
|
+
- **🌐 Web Dashboard** - Browser-based management
|
|
886
|
+
- **📅 Scheduled Messages** - Cron-like scheduling
|
|
887
|
+
- **🛡️ Advanced Moderation** - Auto-spam detection
|
|
888
|
+
- **🤖 AI Integration** - ChatGPT/Claude support
|
|
889
|
+
- **📊 Analytics Dashboard** - Detailed insights
|
|
890
|
+
- **🎮 Game Framework** - Interactive bot games
|
|
891
|
+
|
|
892
|
+
---
|
|
893
|
+
|
|
894
|
+
## 💖 Support
|
|
895
|
+
|
|
896
|
+
- **⭐ Star** this repository if you find it helpful
|
|
897
|
+
- **🐛 Report bugs** via GitHub Issues
|
|
898
|
+
- **💡 Request features** via GitHub Discussions
|
|
899
|
+
- **📧 Contact** for commercial support
|
|
900
|
+
|
|
901
|
+
---
|
|
902
|
+
|
|
903
|
+
## 🏆 Contributors
|
|
904
|
+
|
|
905
|
+
Thanks to all contributors who make this project possible! 🎉
|
|
906
|
+
|
|
907
|
+
---
|
|
908
|
+
|
|
909
|
+
**Made with ❤️ for WhatsApp Automation**
|
|
910
|
+
|
|
911
|
+
*The most powerful WhatsApp bot library - from 3-line bots to enterprise multi-device systems!*
|