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.
@@ -0,0 +1,186 @@
1
+ import { EasyBot, createBot, quickBot, multiBot } from "../src/index.js";
2
+
3
+ // ===== BEISPIEL 1: SUPER EINFACH =====
4
+
5
+ async function superEinfach() {
6
+ console.log("🚀 Super einfacher Bot");
7
+
8
+ const bot = quickBot()
9
+ .when("hallo").reply("Hi! 👋")
10
+ .when("ping").reply("Pong! 🏓")
11
+ .command("zeit", () => new Date().toLocaleString())
12
+ .start();
13
+ }
14
+
15
+ // ===== BEISPIEL 2: MIT CHAINING =====
16
+
17
+ async function mitChaining() {
18
+ console.log("🔗 Bot mit Action Chaining");
19
+
20
+ const bot = createBot()
21
+ .when("wichtig").react("⚠️").type(2).reply("Das ist wichtig!")
22
+ .when("lustig").react("😂").reply("Haha, das ist witzig!")
23
+ .start();
24
+ }
25
+
26
+ // ===== BEISPIEL 3: MULTI-DEVICE =====
27
+
28
+ async function multiDevice() {
29
+ console.log("🔧 Multi-Device Bot");
30
+
31
+ const bot = multiBot(2)
32
+ .when("test").reply("Multi-Device Test!")
33
+ .command("status", "📊 Multi-Device läuft!")
34
+ .start();
35
+ }
36
+
37
+ // ===== BEISPIEL 4: ERWEITERTE TEMPLATES =====
38
+
39
+ async function erweiterteTempates() {
40
+ console.log("📝 Bot mit erweiterten Templates");
41
+
42
+ const bot = createBot()
43
+ .template("begrüßung", "Hallo {name}! Heute ist {day}, {time}")
44
+ .template("info", "Chat: {chat} | Sender: {sender} | Datum: {date}")
45
+ .when("info").useTemplate("info")
46
+ .when("hallo").useTemplate("begrüßung")
47
+ .start();
48
+ }
49
+
50
+ // ===== BEISPIEL 5: ACTION CHAINING =====
51
+
52
+ async function actionChaining() {
53
+ console.log("🔗 Perfektes Action Chaining");
54
+
55
+ const bot = createBot()
56
+ .when("wichtig")
57
+ .react("⚠️")
58
+ .type(2)
59
+ .reply("Das ist eine wichtige Nachricht!")
60
+ .react("✅")
61
+ .done() // Zurück zum Bot
62
+ .when("party")
63
+ .react("🎉")
64
+ .type(1)
65
+ .reply("Party Zeit!")
66
+ .react("🥳")
67
+ .done()
68
+ .start();
69
+ }
70
+
71
+ // ===== BEISPIEL 6: CONDITIONAL LOGIC =====
72
+
73
+ async function conditionalLogic() {
74
+ console.log("🤔 Bot mit Conditional Logic");
75
+
76
+ const bot = createBot()
77
+ .if("contains hallo").then("reply Hallo zurück!")
78
+ .if("starts with !").then("reply Das ist ein Command!")
79
+ .if("is group").then("reply Hallo Gruppe!")
80
+ .if("is private").then("reply Hallo im Privat-Chat!")
81
+ .if("has media").then("react 📷")
82
+ .start();
83
+ }
84
+
85
+ // ===== BEISPIEL 7: VOLLSTÄNDIGER BOT =====
86
+
87
+ async function vollständigerBot() {
88
+ console.log("🤖 Vollständiger EasyBot");
89
+
90
+ const bot = createBot()
91
+ // Templates
92
+ .template("willkommen", "Willkommen {name}! Heute ist {day}")
93
+ .template("status", "Bot läuft seit {time} | Chat: {chat}")
94
+
95
+ // Auto Responses
96
+ .autoReply("hallo", "Hi! 👋")
97
+ .autoReply("tschüss", "Bye! 👋")
98
+
99
+ // Rules mit Chaining
100
+ .when("wichtig")
101
+ .react("⚠️")
102
+ .type(2)
103
+ .reply("Wichtige Nachricht erkannt!")
104
+ .done()
105
+
106
+ .when("willkommen")
107
+ .useTemplate("willkommen")
108
+ .react("🎉")
109
+ .done()
110
+
111
+ // Commands
112
+ .command("hilfe", "🤖 Verfügbare Commands:\n!hilfe, !ping, !status, !zeit")
113
+ .command("ping", "Pong! 🏓")
114
+ .command("status", () => {
115
+ const status = bot.status();
116
+ return `📊 Bot Status: ${status.running ? 'Läuft' : 'Gestoppt'}`;
117
+ })
118
+
119
+ // Conditional Logic
120
+ .if("is group").then("react 👥")
121
+ .if("contains bot").then("reply Ja, ich bin ein Bot! 🤖")
122
+
123
+ // Settings
124
+ .enableTyping(true)
125
+ .enableReactions(true)
126
+ .addQuickCommands()
127
+
128
+ .start();
129
+ }
130
+
131
+ // ===== BEISPIEL 8: MULTI-DEVICE ADVANCED =====
132
+
133
+ async function multiDeviceAdvanced() {
134
+ console.log("🔧 Advanced Multi-Device Bot");
135
+
136
+ const bot = multiBot(3)
137
+ .when("test")
138
+ .react("🧪")
139
+ .type(1)
140
+ .reply("Multi-Device Test erfolgreich!")
141
+ .done()
142
+
143
+ .command("devices", () => {
144
+ const status = bot.status();
145
+ return `🔧 ${status.activeDevices}/${status.totalDevices} Devices aktiv`;
146
+ })
147
+
148
+ .template("multi", "Nachricht von Device via Load Balancing! Zeit: {time}")
149
+ .when("multi").useTemplate("multi")
150
+
151
+ .start();
152
+ }
153
+
154
+ // Beispiele ausführen
155
+ if (import.meta.url === `file://${process.argv[1]}`) {
156
+ const example = process.argv[2] || 'vollständig';
157
+
158
+ switch (example) {
159
+ case 'einfach':
160
+ superEinfach();
161
+ break;
162
+ case 'chaining':
163
+ mitChaining();
164
+ break;
165
+ case 'multi':
166
+ multiDevice();
167
+ break;
168
+ case 'templates':
169
+ erweiterteTempates();
170
+ break;
171
+ case 'actions':
172
+ actionChaining();
173
+ break;
174
+ case 'conditional':
175
+ conditionalLogic();
176
+ break;
177
+ case 'vollständig':
178
+ vollständigerBot();
179
+ break;
180
+ case 'multi-advanced':
181
+ multiDeviceAdvanced();
182
+ break;
183
+ default:
184
+ console.log("Verfügbare Beispiele: einfach, chaining, multi, templates, actions, conditional, vollständig, multi-advanced");
185
+ }
186
+ }
@@ -0,0 +1,253 @@
1
+ import { MultiWhatsAppClient } from "../src/index.js";
2
+
3
+ // ===== MULTI-DEVICE BOT EXAMPLE =====
4
+
5
+ async function startMultiDeviceBot() {
6
+ console.log("🚀 Starte Multi-Device WhatsApp Bot...");
7
+
8
+ // Multi-Client mit 3 Devices initialisieren
9
+ const multiClient = new MultiWhatsAppClient({
10
+ maxDevices: 3,
11
+ loadBalancing: 'round-robin', // round-robin, random, least-used, failover
12
+ syncEvents: true
13
+ });
14
+
15
+ // ===== DEVICES HINZUFÜGEN =====
16
+
17
+ try {
18
+ // Device 1: Haupt-Bot
19
+ await multiClient.addDevice('main-bot', {
20
+ browser: ['MainBot', '1.0.0', ''],
21
+ logLevel: 'silent'
22
+ });
23
+
24
+ // Device 2: Backup-Bot
25
+ await multiClient.addDevice('backup-bot', {
26
+ browser: ['BackupBot', '1.0.0', ''],
27
+ logLevel: 'silent'
28
+ });
29
+
30
+ // Device 3: Support-Bot
31
+ await multiClient.addDevice('support-bot', {
32
+ browser: ['SupportBot', '1.0.0', ''],
33
+ logLevel: 'silent'
34
+ });
35
+
36
+ console.log("✅ Alle 3 Devices hinzugefügt");
37
+
38
+ } catch (error) {
39
+ console.error("❌ Fehler beim Hinzufügen der Devices:", error.message);
40
+ return;
41
+ }
42
+
43
+ // ===== COMMAND SYSTEM =====
44
+
45
+ const prefix = "!";
46
+ multiClient.setPrefix(prefix);
47
+
48
+ // Commands für alle Devices
49
+ multiClient.addCommand('ping', async (msg) => {
50
+ const deviceInfo = msg.deviceId ? ` (Device: ${msg.deviceId})` : '';
51
+ await msg.replyFromSameDevice(`🏓 Pong!${deviceInfo}`);
52
+ });
53
+
54
+ multiClient.addCommand('status', async (msg) => {
55
+ const status = multiClient.getStatus();
56
+ const health = multiClient.getHealthCheck();
57
+
58
+ let response = `📊 **Multi-Device Status**\n\n`;
59
+ response += `🔧 Devices: ${status.activeDevices}/${status.totalDevices} aktiv\n`;
60
+ response += `💚 Health: ${health.healthPercentage}% (${health.recommendation})\n`;
61
+ response += `⚖️ Load Balancing: ${status.loadBalancing}\n\n`;
62
+
63
+ response += `**Device Details:**\n`;
64
+ status.devices.forEach(device => {
65
+ const statusIcon = device.status === 'connected' ? '✅' :
66
+ device.status === 'connecting' ? '🔄' : '❌';
67
+ response += `${statusIcon} ${device.id}: ${device.messageCount} msgs, ${device.errors} errors\n`;
68
+ });
69
+
70
+ await msg.replyFromSameDevice(response);
71
+ });
72
+
73
+ multiClient.addCommand('broadcast', async (msg, args) => {
74
+ if (args.length === 0) {
75
+ return msg.replyFromSameDevice('❌ Verwendung: !broadcast <nachricht>');
76
+ }
77
+
78
+ const message = args.join(' ');
79
+ const results = await multiClient.broadcast(msg.from, { text: `📢 Broadcast: ${message}` });
80
+
81
+ const successful = results.filter(r => r.success).length;
82
+ await msg.replyFromSameDevice(`✅ Broadcast an ${successful}/${results.length} Devices gesendet`);
83
+ });
84
+
85
+ multiClient.addCommand('device', async (msg, args) => {
86
+ if (args.length < 2) {
87
+ return msg.replyFromSameDevice('❌ Verwendung: !device <deviceId> <nachricht>');
88
+ }
89
+
90
+ const [deviceId, ...messageParts] = args;
91
+ const message = messageParts.join(' ');
92
+
93
+ try {
94
+ await multiClient.sendFromDevice(deviceId, msg.from, { text: `📱 Von ${deviceId}: ${message}` });
95
+ await msg.replyFromSameDevice(`✅ Nachricht von Device '${deviceId}' gesendet`);
96
+ } catch (error) {
97
+ await msg.replyFromSameDevice(`❌ Fehler: ${error.message}`);
98
+ }
99
+ });
100
+
101
+ multiClient.addCommand('failover', async (msg, args) => {
102
+ if (args.length === 0) {
103
+ return msg.replyFromSameDevice('❌ Verwendung: !failover <nachricht>');
104
+ }
105
+
106
+ const message = args.join(' ');
107
+
108
+ try {
109
+ await multiClient.sendWithFailover(msg.from, { text: `🔄 Failover: ${message}` });
110
+ await msg.replyFromSameDevice('✅ Failover-Nachricht gesendet');
111
+ } catch (error) {
112
+ await msg.replyFromSameDevice(`❌ Alle Devices fehlgeschlagen: ${error.message}`);
113
+ }
114
+ });
115
+
116
+ // ===== EVENT HANDLERS =====
117
+
118
+ // Message Events von allen Devices
119
+ multiClient.on('message', async (msg) => {
120
+ // Ignore Commands (werden separat behandelt)
121
+ if (msg.isCommand) return;
122
+
123
+ // Einfache Auto-Responses
124
+ if (msg.text?.toLowerCase().includes('hallo')) {
125
+ // Load-balanced Response
126
+ await multiClient.sendMessage(msg.from, {
127
+ text: `Hallo! 👋 (Beantwortet von Device: ${msg.deviceId})`
128
+ });
129
+ }
130
+
131
+ if (msg.text?.toLowerCase().includes('hilfe')) {
132
+ const helpText = `🤖 **Multi-Device Bot Hilfe**\n\n` +
133
+ `${prefix}ping - Ping Test\n` +
134
+ `${prefix}status - Device Status\n` +
135
+ `${prefix}broadcast <msg> - An alle Devices\n` +
136
+ `${prefix}device <id> <msg> - Spezifisches Device\n` +
137
+ `${prefix}failover <msg> - Mit Failover\n\n` +
138
+ `Aktive Devices: ${multiClient.getActiveDevices().join(', ')}`;
139
+
140
+ await msg.replyFromSameDevice(helpText);
141
+ }
142
+ });
143
+
144
+ // Device Connection Events
145
+ multiClient.on('device.connected', (data) => {
146
+ console.log(`✅ Device '${data.deviceId}' verbunden`);
147
+ });
148
+
149
+ multiClient.on('device.disconnected', (data) => {
150
+ console.log(`🔴 Device '${data.deviceId}' getrennt:`, data.reason || 'Unbekannt');
151
+ });
152
+
153
+ multiClient.on('device.error', (data) => {
154
+ console.error(`❌ Device '${data.deviceId}' Fehler:`, data.error.message);
155
+ });
156
+
157
+ // ===== VERBINDUNG STARTEN =====
158
+
159
+ try {
160
+ console.log("🔄 Verbinde alle Devices...");
161
+ const connectedCount = await multiClient.connect();
162
+
163
+ console.log(`🎉 Multi-Device Bot gestartet!`);
164
+ console.log(`✅ ${connectedCount} Devices erfolgreich verbunden`);
165
+ console.log(`🎯 Prefix: "${prefix}"`);
166
+ console.log(`⚖️ Load Balancing: ${multiClient.deviceManager.config.loadBalancing}`);
167
+
168
+ // Status alle 5 Minuten loggen
169
+ setInterval(() => {
170
+ const health = multiClient.getHealthCheck();
171
+ console.log(`💚 Health Check: ${health.healthPercentage}% - ${health.recommendation}`);
172
+ }, 5 * 60 * 1000);
173
+
174
+ // Device Rotation alle 10 Minuten (optional)
175
+ setInterval(() => {
176
+ multiClient.rotateDevices();
177
+ }, 10 * 60 * 1000);
178
+
179
+ } catch (error) {
180
+ console.error("❌ Fehler beim Starten des Multi-Device Bots:", error.message);
181
+ process.exit(1);
182
+ }
183
+
184
+ // ===== GRACEFUL SHUTDOWN =====
185
+
186
+ process.on('SIGINT', async () => {
187
+ console.log("\n🛑 Shutdown Signal empfangen...");
188
+ await multiClient.cleanup();
189
+ console.log("✅ Multi-Device Bot sauber beendet");
190
+ process.exit(0);
191
+ });
192
+ }
193
+
194
+ // ===== ADVANCED USAGE EXAMPLES =====
195
+
196
+ async function advancedExamples() {
197
+ const multiClient = new MultiWhatsAppClient();
198
+
199
+ // Beispiel 1: Device-spezifische Konfiguration
200
+ await multiClient.addDevice('premium-bot', {
201
+ browser: ['PremiumBot', '2.0.0', ''],
202
+ logLevel: 'info'
203
+ });
204
+
205
+ await multiClient.configureDevice('premium-bot', {
206
+ maxRetries: 5,
207
+ timeout: 30000
208
+ });
209
+
210
+ // Beispiel 2: Load Balancing Strategy wechseln
211
+ multiClient.setLoadBalancingStrategy('least-used');
212
+
213
+ // Beispiel 3: Conditional Messaging
214
+ multiClient.on('message', async (msg) => {
215
+ if (msg.isGroup && msg.text?.includes('wichtig')) {
216
+ // Wichtige Nachrichten über alle Devices broadcasten
217
+ await multiClient.broadcast(msg.from, {
218
+ text: '🚨 Wichtige Nachricht erkannt - alle Devices alarmiert!'
219
+ });
220
+ } else {
221
+ // Normale Nachrichten load-balanced
222
+ await multiClient.sendMessage(msg.from, {
223
+ text: 'Normale Antwort via Load Balancing'
224
+ });
225
+ }
226
+ });
227
+
228
+ // Beispiel 4: Device Health Monitoring
229
+ setInterval(async () => {
230
+ const health = multiClient.getHealthCheck();
231
+
232
+ if (health.healthPercentage < 50) {
233
+ console.warn('🚨 Kritische Device-Health! Versuche Reconnect...');
234
+
235
+ // Versuche fehlerhafte Devices zu reconnecten
236
+ const status = multiClient.getStatus();
237
+ for (const device of status.devices) {
238
+ if (device.status !== 'connected') {
239
+ try {
240
+ await multiClient.deviceManager.connectDevice(device.id);
241
+ } catch (error) {
242
+ console.error(`❌ Reconnect fehlgeschlagen für ${device.id}:`, error.message);
243
+ }
244
+ }
245
+ }
246
+ }
247
+ }, 2 * 60 * 1000); // Alle 2 Minuten prüfen
248
+ }
249
+
250
+ // Bot starten
251
+ if (import.meta.url === `file://${process.argv[1]}`) {
252
+ startMultiDeviceBot().catch(console.error);
253
+ }
@@ -0,0 +1,10 @@
1
+ import { quickBot } from "../src/index.js";
2
+
3
+ // 🚀 QUICKEST WAY TO START - 3 LINES!
4
+
5
+ quickBot()
6
+ .when("hello").reply("Hi there! 👋")
7
+ .when("ping").reply("Pong! 🏓")
8
+ .start();
9
+
10
+ console.log("✅ QuickBot started! Send 'hello' or 'ping' to test!");
@@ -0,0 +1,42 @@
1
+ import { MultiWhatsAppClient } from "../src/index.js";
2
+
3
+ // ===== EINFACHES MULTI-DEVICE BEISPIEL =====
4
+
5
+ async function simpleMultiDevice() {
6
+ console.log("🚀 Einfacher Multi-Device Bot");
7
+
8
+ // Multi-Client erstellen
9
+ const client = new MultiWhatsAppClient({
10
+ maxDevices: 2,
11
+ loadBalancing: 'round-robin'
12
+ });
13
+
14
+ // 2 Devices hinzufügen
15
+ await client.addDevice('bot1');
16
+ await client.addDevice('bot2');
17
+
18
+ // Commands
19
+ client.setPrefix('!');
20
+
21
+ client.addCommand('ping', async (msg) => {
22
+ await msg.replyFromSameDevice(`Pong von ${msg.deviceId}! 🏓`);
23
+ });
24
+
25
+ client.addCommand('test', async (msg) => {
26
+ // Nachricht über Load Balancing senden
27
+ await client.sendMessage(msg.from, { text: 'Test via Load Balancing!' });
28
+ });
29
+
30
+ // Events
31
+ client.on('message', async (msg) => {
32
+ if (msg.text === 'hallo') {
33
+ await client.sendMessage(msg.from, { text: `Hallo von ${msg.deviceId}! 👋` });
34
+ }
35
+ });
36
+
37
+ // Verbinden
38
+ await client.connect();
39
+ console.log("✅ Multi-Device Bot läuft!");
40
+ }
41
+
42
+ simpleMultiDevice().catch(console.error);
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "waengine",
3
+ "version": "1.0.1",
4
+ "description": "🚀 WAEngine - The most powerful WhatsApp Bot Library with Multi-Device Support & EasyBot API",
5
+ "main": "src/index.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "start": "node examples/simple-multi-device.js",
9
+ "test": "node test.js",
10
+ "example:basic": "node examples/easy-bot-examples.js einfach",
11
+ "example:multi": "node examples/multi-device-example.js",
12
+ "example:easy": "node examples/easy-bot-examples.js vollständig"
13
+ },
14
+ "keywords": [
15
+ "whatsapp",
16
+ "bot",
17
+ "baileys",
18
+ "multi-device",
19
+ "automation",
20
+ "whatsapp-bot",
21
+ "whatsapp-api",
22
+ "easy-bot",
23
+ "chatbot",
24
+ "messaging",
25
+ "multi-account",
26
+ "load-balancing",
27
+ "typescript",
28
+ "javascript",
29
+ "nodejs"
30
+ ],
31
+ "author": {
32
+ "name": "Lia",
33
+ "email": "Liaia@outlook.de",
34
+ "url": "https://github.com/neotreydel-lab"
35
+ },
36
+ "license": "MIT",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/neotreydel-lab/whatsapp-multi-client.git"
40
+ },
41
+ "bugs": {
42
+ "url": "https://github.com/neotreydel-lab/whatsapp-multi-client/issues"
43
+ },
44
+ "homepage": "https://github.com/neotreydel-lab/whatsapp-multi-client#readme",
45
+ "engines": {
46
+ "node": ">=16.0.0"
47
+ },
48
+ "dependencies": {
49
+ "@whiskeysockets/baileys": "^7.0.0-rc.9",
50
+ "playwright": "^1.58.1",
51
+ "qrcode-terminal": "^0.12.0",
52
+ "pino": "^8.0.0"
53
+ },
54
+ "devDependencies": {
55
+ "@types/node": "^20.0.0"
56
+ },
57
+ "files": [
58
+ "src/",
59
+ "examples/",
60
+ "README.md",
61
+ "LICENSE"
62
+ ],
63
+ "funding": {
64
+ "type": "github",
65
+ "url": "https://github.com/sponsors/neotreydel-lab"
66
+ }
67
+ }