waengine 1.0.1 → 1.0.4
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/package.json +4 -3
- package/src/client.js +175 -45
- package/src/qr.js +132 -23
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "waengine",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "🚀 WAEngine - The most powerful WhatsApp Bot Library with Multi-Device Support & EasyBot API",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -47,9 +47,10 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@whiskeysockets/baileys": "^7.0.0-rc.9",
|
|
50
|
+
"pino": "^8.0.0",
|
|
50
51
|
"playwright": "^1.58.1",
|
|
51
|
-
"qrcode
|
|
52
|
-
"
|
|
52
|
+
"qrcode": "^1.5.4",
|
|
53
|
+
"qrcode-terminal": "^0.12.0"
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
56
|
"@types/node": "^20.0.0"
|
package/src/client.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import makeWASocket,
|
|
1
|
+
import { makeWASocket, useMultiFileAuthState, DisconnectReason, fetchLatestBaileysVersion, isJidBroadcast } from "@whiskeysockets/baileys";
|
|
2
2
|
import pino from "pino";
|
|
3
3
|
import { generateQRCode, closeBrowser } from "./qr.js";
|
|
4
4
|
import { Message } from "./message.js";
|
|
@@ -8,11 +8,13 @@ export class WhatsAppClient {
|
|
|
8
8
|
this.options = {
|
|
9
9
|
authDir: "./auth",
|
|
10
10
|
printQR: false,
|
|
11
|
-
browser: options.browser || ["
|
|
11
|
+
browser: options.browser || ["Chrome", "121.0.0", ""], // Aktueller Chrome
|
|
12
12
|
logLevel: options.logLevel || "silent", // Sauber ohne Debug
|
|
13
13
|
...options
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
+
// Clean initialization
|
|
17
|
+
|
|
16
18
|
this.socket = null;
|
|
17
19
|
this.isConnected = false;
|
|
18
20
|
this.eventHandlers = new Map();
|
|
@@ -32,44 +34,87 @@ export class WhatsAppClient {
|
|
|
32
34
|
// ===== CONNECTION METHODS =====
|
|
33
35
|
|
|
34
36
|
async connect() {
|
|
35
|
-
console.log("🔄 Starte Verbindung...");
|
|
36
|
-
|
|
37
37
|
if (this.socket && this.isConnected) {
|
|
38
|
-
console.log("✅ Bereits verbunden");
|
|
39
38
|
return this.socket;
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
const { state, saveCreds } = await useMultiFileAuthState(this.options.authDir);
|
|
43
|
-
console.log("📁 Auth-Daten geladen");
|
|
44
|
-
|
|
45
|
-
// Prüfen ob bereits eingeloggt
|
|
46
42
|
const isLoggedIn = !!state.creds?.me?.id;
|
|
47
|
-
console.log(`🔐 Login-Status: ${isLoggedIn ? 'Eingeloggt' : 'Nicht eingeloggt'}`);
|
|
48
43
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
44
|
+
// Fetch latest Baileys version for compatibility
|
|
45
|
+
try {
|
|
46
|
+
const { version, isLatest } = await fetchLatestBaileysVersion();
|
|
47
|
+
|
|
48
|
+
this.socket = makeWASocket({
|
|
49
|
+
version,
|
|
50
|
+
auth: state,
|
|
51
|
+
logger: pino({ level: this.options.logLevel }),
|
|
52
|
+
browser: this.options.browser,
|
|
53
|
+
generateHighQualityLinkPreview: true,
|
|
54
|
+
syncFullHistory: true, // Wichtig für Message-Empfang
|
|
55
|
+
markOnlineOnConnect: true,
|
|
56
|
+
getMessage: async (key) => {
|
|
57
|
+
// Wichtig für Message-Handling
|
|
58
|
+
return { conversation: "Message not found" };
|
|
59
|
+
},
|
|
60
|
+
shouldIgnoreJid: jid => isJidBroadcast(jid),
|
|
61
|
+
// Bessere Message-Synchronisation
|
|
62
|
+
emitOwnEvents: true,
|
|
63
|
+
fireInitQueries: true,
|
|
64
|
+
shouldSyncHistoryMessage: msg => {
|
|
65
|
+
return !!msg.message && !msg.key.fromMe;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
} catch (versionError) {
|
|
69
|
+
this.socket = makeWASocket({
|
|
70
|
+
auth: state,
|
|
71
|
+
logger: pino({ level: this.options.logLevel }),
|
|
72
|
+
browser: this.options.browser,
|
|
73
|
+
generateHighQualityLinkPreview: true,
|
|
74
|
+
syncFullHistory: true, // Wichtig für Message-Empfang
|
|
75
|
+
markOnlineOnConnect: true,
|
|
76
|
+
getMessage: async (key) => {
|
|
77
|
+
// Wichtig für Message-Handling
|
|
78
|
+
return { conversation: "Message not found" };
|
|
79
|
+
},
|
|
80
|
+
shouldIgnoreJid: jid => isJidBroadcast(jid),
|
|
81
|
+
// Bessere Message-Synchronisation
|
|
82
|
+
emitOwnEvents: true,
|
|
83
|
+
fireInitQueries: true,
|
|
84
|
+
shouldSyncHistoryMessage: msg => {
|
|
85
|
+
return !!msg.message && !msg.key.fromMe;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
55
89
|
|
|
56
90
|
console.log("🔌 Socket erstellt");
|
|
57
91
|
|
|
58
92
|
// QR-Code Browser nur öffnen wenn nicht eingeloggt
|
|
59
93
|
if (!this.options.printQR && !isLoggedIn) {
|
|
60
|
-
console.log("🌐 Öffne Browser für QR-Code...");
|
|
61
94
|
await generateQRCode();
|
|
62
|
-
} else if (isLoggedIn) {
|
|
63
|
-
console.log("✅ Bereits authentifiziert, verbinde direkt...");
|
|
64
95
|
}
|
|
65
96
|
|
|
66
97
|
return new Promise((resolve, reject) => {
|
|
98
|
+
// Event-Handler SOFORT registrieren, nicht erst bei "open"
|
|
99
|
+
this.setupEventHandlers();
|
|
100
|
+
|
|
67
101
|
this.socket.ev.on("connection.update", async ({ connection, lastDisconnect, qr }) => {
|
|
68
|
-
console.log(`🔄 Connection
|
|
102
|
+
console.log(`🔄 Connection Update: ${connection}`);
|
|
69
103
|
|
|
70
|
-
if (qr
|
|
71
|
-
console.log("📱 QR
|
|
72
|
-
|
|
104
|
+
if (qr) {
|
|
105
|
+
console.log("📱 QR-Code empfangen");
|
|
106
|
+
if (this.options.printQR) {
|
|
107
|
+
// Terminal QR
|
|
108
|
+
console.log("\n📱 QR-CODE IM TERMINAL:");
|
|
109
|
+
console.log("─".repeat(50));
|
|
110
|
+
const qrcode = await import("qrcode-terminal");
|
|
111
|
+
qrcode.default.generate(qr, { small: true });
|
|
112
|
+
console.log("─".repeat(50));
|
|
113
|
+
console.log("📲 Scanne den QR-Code mit WhatsApp!");
|
|
114
|
+
} else {
|
|
115
|
+
// Browser QR
|
|
116
|
+
await generateQRCode(qr);
|
|
117
|
+
}
|
|
73
118
|
}
|
|
74
119
|
|
|
75
120
|
if (connection === "connecting") {
|
|
@@ -78,22 +123,24 @@ export class WhatsAppClient {
|
|
|
78
123
|
|
|
79
124
|
if (connection === "close") {
|
|
80
125
|
console.log("🔴 Verbindung geschlossen");
|
|
81
|
-
const
|
|
126
|
+
const statusCode = lastDisconnect?.error?.output?.statusCode;
|
|
127
|
+
const shouldReconnect = statusCode !== DisconnectReason.loggedOut;
|
|
82
128
|
|
|
83
129
|
if (shouldReconnect) {
|
|
84
|
-
console.log("🔄 Wiederverbindung...");
|
|
130
|
+
console.log("🔄 Wiederverbindung in 3 Sekunden...");
|
|
85
131
|
this.isConnected = false;
|
|
86
132
|
this.socket = null;
|
|
87
133
|
setTimeout(() => this.connect().then(resolve).catch(reject), 3000);
|
|
88
134
|
} else {
|
|
89
|
-
console.log("👋 Ausgeloggt
|
|
135
|
+
console.log("👋 Ausgeloggt");
|
|
90
136
|
await closeBrowser();
|
|
91
137
|
this.emit('disconnected', { reason: 'logged_out' });
|
|
138
|
+
reject(new Error('Logged out'));
|
|
92
139
|
}
|
|
93
140
|
} else if (connection === "open") {
|
|
94
|
-
console.log("✅ WhatsApp
|
|
141
|
+
console.log("✅ WhatsApp verbunden!");
|
|
95
142
|
this.isConnected = true;
|
|
96
|
-
|
|
143
|
+
await closeBrowser(); // QR Browser schließen
|
|
97
144
|
this.emit('connected');
|
|
98
145
|
resolve(this);
|
|
99
146
|
}
|
|
@@ -154,14 +201,51 @@ export class WhatsAppClient {
|
|
|
154
201
|
}
|
|
155
202
|
|
|
156
203
|
setupEventHandlers() {
|
|
157
|
-
|
|
204
|
+
console.log("🔧 Registriere Event-Handler...");
|
|
205
|
+
|
|
206
|
+
// Messages - Verbesserte Message-Erkennung
|
|
158
207
|
this.socket.ev.on("messages.upsert", ({ messages, type }) => {
|
|
159
|
-
|
|
208
|
+
console.log(`📨 Messages.upsert - Type: ${type}, Count: ${messages.length}`);
|
|
209
|
+
|
|
210
|
+
// Alle Message-Types verarbeiten, nicht nur "notify"
|
|
211
|
+
if (type !== "notify" && type !== "append") {
|
|
212
|
+
console.log(`⚠️ Ignoriere Message-Type: ${type}`);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
160
215
|
|
|
161
|
-
messages.forEach(msg => {
|
|
162
|
-
|
|
216
|
+
messages.forEach((msg, index) => {
|
|
217
|
+
console.log(`🔍 Processing message ${index + 1}/${messages.length}`);
|
|
218
|
+
console.log(` - From: ${msg.key.remoteJid}`);
|
|
219
|
+
console.log(` - FromMe: ${msg.key.fromMe}`);
|
|
220
|
+
console.log(` - Message Keys: ${Object.keys(msg.message || {}).join(', ')}`);
|
|
221
|
+
|
|
222
|
+
// Bessere Message-Validierung
|
|
223
|
+
if (!msg.message) {
|
|
224
|
+
console.log(" ❌ Keine Message-Daten");
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (msg.key.fromMe) {
|
|
229
|
+
console.log(" ❌ Eigene Nachricht - ignoriert");
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Ignoriere Broadcast-Messages
|
|
234
|
+
if (msg.key.remoteJid && isJidBroadcast(msg.key.remoteJid)) {
|
|
235
|
+
console.log(" ❌ Broadcast-Message - ignoriert");
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
163
238
|
|
|
164
239
|
const messageData = this.parseMessage(msg);
|
|
240
|
+
console.log(` ✅ Text extrahiert: "${messageData.text}"`);
|
|
241
|
+
console.log(` ✅ Type: ${messageData.type}`);
|
|
242
|
+
|
|
243
|
+
// Nur verarbeiten wenn Text vorhanden oder andere unterstützte Typen
|
|
244
|
+
if (!messageData.text && messageData.type === 'unknown') {
|
|
245
|
+
console.log(" ❌ Kein Text und unbekannter Typ");
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
|
|
165
249
|
const messageObj = new Message(this, messageData);
|
|
166
250
|
|
|
167
251
|
// Prefix System - Command Check
|
|
@@ -169,6 +253,8 @@ export class WhatsAppClient {
|
|
|
169
253
|
const commandText = messageData.text.slice(this.prefix.length).trim();
|
|
170
254
|
const [command, ...args] = commandText.split(' ');
|
|
171
255
|
|
|
256
|
+
console.log(` ⚡ Command erkannt: ${command}`);
|
|
257
|
+
|
|
172
258
|
messageObj.isCommand = true;
|
|
173
259
|
messageObj.command = command.toLowerCase();
|
|
174
260
|
messageObj.args = args;
|
|
@@ -180,40 +266,82 @@ export class WhatsAppClient {
|
|
|
180
266
|
// Spezifischen Command Handler aufrufen falls vorhanden
|
|
181
267
|
if (this.commands.has(command.toLowerCase())) {
|
|
182
268
|
const handler = this.commands.get(command.toLowerCase());
|
|
269
|
+
console.log(` 🎯 Führe Command-Handler aus: ${command}`);
|
|
183
270
|
try {
|
|
184
271
|
handler(messageObj, args);
|
|
185
272
|
} catch (error) {
|
|
186
273
|
console.error(`❌ Fehler in Command '${command}':`, error);
|
|
187
274
|
}
|
|
275
|
+
} else {
|
|
276
|
+
console.log(` ❓ Kein Handler für Command: ${command}`);
|
|
188
277
|
}
|
|
189
278
|
} else {
|
|
190
279
|
messageObj.isCommand = false;
|
|
191
280
|
messageObj.command = null;
|
|
192
281
|
messageObj.args = [];
|
|
282
|
+
console.log(" 📝 Normale Nachricht");
|
|
193
283
|
}
|
|
194
284
|
|
|
285
|
+
console.log(" 📤 Emittiere Message-Event");
|
|
195
286
|
this.emit('message', messageObj);
|
|
287
|
+
console.log(" ✅ Message verarbeitet");
|
|
196
288
|
});
|
|
197
289
|
});
|
|
198
290
|
|
|
291
|
+
// Zusätzliche Events für bessere Kompatibilität
|
|
292
|
+
this.socket.ev.on("messages.update", (updates) => {
|
|
293
|
+
console.log(`📝 Messages.update - Count: ${updates.length}`);
|
|
294
|
+
this.emit('messages.update', updates);
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
// Bessere Presence-Handling
|
|
298
|
+
this.socket.ev.on("presence.update", (update) => {
|
|
299
|
+
console.log(`👤 Presence.update - ID: ${update.id}`);
|
|
300
|
+
this.emit('presence.update', update);
|
|
301
|
+
});
|
|
302
|
+
|
|
199
303
|
// Group updates
|
|
200
304
|
this.socket.ev.on("group-participants.update", (update) => {
|
|
305
|
+
console.log(`👥 Group-participants.update - Group: ${update.id}`);
|
|
201
306
|
this.emit('group.participants.update', update);
|
|
202
307
|
});
|
|
203
308
|
|
|
204
|
-
//
|
|
205
|
-
this.socket.ev.on("
|
|
206
|
-
|
|
309
|
+
// Chats updates für bessere Synchronisation
|
|
310
|
+
this.socket.ev.on("chats.upsert", (chats) => {
|
|
311
|
+
console.log(`💬 Chats.upsert - Count: ${chats.length}`);
|
|
312
|
+
this.emit('chats.upsert', chats);
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
// Contacts updates
|
|
316
|
+
this.socket.ev.on("contacts.upsert", (contacts) => {
|
|
317
|
+
console.log(`📞 Contacts.upsert - Count: ${contacts.length}`);
|
|
318
|
+
this.emit('contacts.upsert', contacts);
|
|
207
319
|
});
|
|
320
|
+
|
|
321
|
+
console.log("✅ Event-Handler registriert!");
|
|
208
322
|
}
|
|
209
323
|
|
|
210
324
|
parseMessage(msg) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
msg.message.
|
|
216
|
-
|
|
325
|
+
// Erweiterte Text-Extraktion für verschiedene Message-Typen
|
|
326
|
+
let text = null;
|
|
327
|
+
|
|
328
|
+
if (msg.message.conversation) {
|
|
329
|
+
text = msg.message.conversation;
|
|
330
|
+
} else if (msg.message.extendedTextMessage?.text) {
|
|
331
|
+
text = msg.message.extendedTextMessage.text;
|
|
332
|
+
} else if (msg.message.imageMessage?.caption) {
|
|
333
|
+
text = msg.message.imageMessage.caption;
|
|
334
|
+
} else if (msg.message.videoMessage?.caption) {
|
|
335
|
+
text = msg.message.videoMessage.caption;
|
|
336
|
+
} else if (msg.message.documentMessage?.caption) {
|
|
337
|
+
text = msg.message.documentMessage.caption;
|
|
338
|
+
} else if (msg.message.buttonsResponseMessage?.selectedButtonId) {
|
|
339
|
+
text = msg.message.buttonsResponseMessage.selectedButtonId;
|
|
340
|
+
} else if (msg.message.listResponseMessage?.singleSelectReply?.selectedRowId) {
|
|
341
|
+
text = msg.message.listResponseMessage.singleSelectReply.selectedRowId;
|
|
342
|
+
} else if (msg.message.templateButtonReplyMessage?.selectedId) {
|
|
343
|
+
text = msg.message.templateButtonReplyMessage.selectedId;
|
|
344
|
+
}
|
|
217
345
|
|
|
218
346
|
return {
|
|
219
347
|
id: msg.key.id,
|
|
@@ -223,12 +351,14 @@ export class WhatsAppClient {
|
|
|
223
351
|
timestamp: msg.messageTimestamp,
|
|
224
352
|
type: this.getMessageType(msg.message),
|
|
225
353
|
isGroup: msg.key.remoteJid?.includes("@g.us"),
|
|
354
|
+
participant: msg.key.participant, // Wichtig für Gruppen
|
|
226
355
|
raw: msg
|
|
227
356
|
};
|
|
228
357
|
}
|
|
229
358
|
|
|
230
359
|
getMessageType(message) {
|
|
231
360
|
if (message.conversation) return 'text';
|
|
361
|
+
if (message.extendedTextMessage) return 'text';
|
|
232
362
|
if (message.imageMessage) return 'image';
|
|
233
363
|
if (message.videoMessage) return 'video';
|
|
234
364
|
if (message.audioMessage) return 'audio';
|
|
@@ -236,6 +366,11 @@ export class WhatsAppClient {
|
|
|
236
366
|
if (message.stickerMessage) return 'sticker';
|
|
237
367
|
if (message.locationMessage) return 'location';
|
|
238
368
|
if (message.contactMessage) return 'contact';
|
|
369
|
+
if (message.buttonsResponseMessage) return 'button_response';
|
|
370
|
+
if (message.listResponseMessage) return 'list_response';
|
|
371
|
+
if (message.templateButtonReplyMessage) return 'template_button_reply';
|
|
372
|
+
if (message.pollCreationMessage) return 'poll';
|
|
373
|
+
if (message.pollUpdateMessage) return 'poll_update';
|
|
239
374
|
return 'unknown';
|
|
240
375
|
}
|
|
241
376
|
|
|
@@ -250,7 +385,6 @@ export class WhatsAppClient {
|
|
|
250
385
|
|
|
251
386
|
setPrefix(prefix) {
|
|
252
387
|
this.prefix = prefix;
|
|
253
|
-
console.log(`🎯 Prefix gesetzt auf: "${prefix}"`);
|
|
254
388
|
return this;
|
|
255
389
|
}
|
|
256
390
|
|
|
@@ -260,15 +394,11 @@ export class WhatsAppClient {
|
|
|
260
394
|
|
|
261
395
|
addCommand(command, handler) {
|
|
262
396
|
this.commands.set(command.toLowerCase(), handler);
|
|
263
|
-
console.log(`⚡ Command registriert: ${this.prefix || ''}${command}`);
|
|
264
397
|
return this;
|
|
265
398
|
}
|
|
266
399
|
|
|
267
400
|
removeCommand(command) {
|
|
268
401
|
const removed = this.commands.delete(command.toLowerCase());
|
|
269
|
-
if (removed) {
|
|
270
|
-
console.log(`🗑️ Command entfernt: ${command}`);
|
|
271
|
-
}
|
|
272
402
|
return this;
|
|
273
403
|
}
|
|
274
404
|
|
package/src/qr.js
CHANGED
|
@@ -6,26 +6,10 @@ let page = null;
|
|
|
6
6
|
|
|
7
7
|
export async function generateQRCode(qrData = null) {
|
|
8
8
|
try {
|
|
9
|
-
//
|
|
10
|
-
if (!browser) {
|
|
11
|
-
console.log("🌐 Öffne Microsoft Edge...");
|
|
12
|
-
browser = await chromium.launch({
|
|
13
|
-
channel: "msedge",
|
|
14
|
-
headless: false
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// Neue Seite öffnen falls noch nicht vorhanden
|
|
19
|
-
if (!page) {
|
|
20
|
-
page = await browser.newPage();
|
|
21
|
-
await page.goto("https://web.whatsapp.com");
|
|
22
|
-
console.log("🌐 Microsoft Edge mit WhatsApp Web geöffnet");
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// QR-Code anzeigen falls vorhanden
|
|
9
|
+
// QR-Code im Terminal anzeigen falls vorhanden
|
|
26
10
|
if (qrData) {
|
|
27
11
|
console.log("\n📱 QR-CODE GENERIERT!");
|
|
28
|
-
console.log("👆 Scanne den QR-Code
|
|
12
|
+
console.log("👆 Scanne den QR-Code hier im Terminal:");
|
|
29
13
|
console.log("─".repeat(50));
|
|
30
14
|
|
|
31
15
|
// QR-Code im Terminal anzeigen
|
|
@@ -36,22 +20,147 @@ export async function generateQRCode(qrData = null) {
|
|
|
36
20
|
console.log(" 1. Gehe zu Einstellungen");
|
|
37
21
|
console.log(" 2. Tippe auf 'Verknüpfte Geräte'");
|
|
38
22
|
console.log(" 3. Tippe auf 'Gerät verknüpfen'");
|
|
39
|
-
console.log(" 4. Scanne den QR-Code");
|
|
23
|
+
console.log(" 4. Scanne den QR-Code OBEN im Terminal");
|
|
40
24
|
console.log("⏳ Warte auf QR-Scan...");
|
|
41
25
|
}
|
|
42
26
|
|
|
27
|
+
// Browser öffnen und den richtigen QR-Code anzeigen
|
|
28
|
+
if (!browser && qrData) {
|
|
29
|
+
console.log("🌐 Öffne Browser mit korrektem QR-Code...");
|
|
30
|
+
browser = await chromium.launch({
|
|
31
|
+
channel: "msedge",
|
|
32
|
+
headless: false
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
page = await browser.newPage();
|
|
36
|
+
|
|
37
|
+
// Custom HTML-Seite mit dem richtigen QR-Code erstellen
|
|
38
|
+
const qrCodeDataURL = await generateQRCodeDataURL(qrData);
|
|
39
|
+
const html = `
|
|
40
|
+
<!DOCTYPE html>
|
|
41
|
+
<html>
|
|
42
|
+
<head>
|
|
43
|
+
<title>WAEngine - QR Code Scanner</title>
|
|
44
|
+
<style>
|
|
45
|
+
body {
|
|
46
|
+
font-family: Arial, sans-serif;
|
|
47
|
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
48
|
+
margin: 0;
|
|
49
|
+
padding: 20px;
|
|
50
|
+
display: flex;
|
|
51
|
+
flex-direction: column;
|
|
52
|
+
align-items: center;
|
|
53
|
+
justify-content: center;
|
|
54
|
+
min-height: 100vh;
|
|
55
|
+
color: white;
|
|
56
|
+
}
|
|
57
|
+
.container {
|
|
58
|
+
background: rgba(255, 255, 255, 0.1);
|
|
59
|
+
backdrop-filter: blur(10px);
|
|
60
|
+
border-radius: 20px;
|
|
61
|
+
padding: 40px;
|
|
62
|
+
text-align: center;
|
|
63
|
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
|
|
64
|
+
border: 1px solid rgba(255, 255, 255, 0.2);
|
|
65
|
+
}
|
|
66
|
+
h1 {
|
|
67
|
+
margin-bottom: 20px;
|
|
68
|
+
font-size: 2.5em;
|
|
69
|
+
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
|
|
70
|
+
}
|
|
71
|
+
.qr-container {
|
|
72
|
+
background: white;
|
|
73
|
+
padding: 20px;
|
|
74
|
+
border-radius: 15px;
|
|
75
|
+
margin: 20px 0;
|
|
76
|
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
|
|
77
|
+
}
|
|
78
|
+
.qr-code {
|
|
79
|
+
max-width: 300px;
|
|
80
|
+
height: auto;
|
|
81
|
+
}
|
|
82
|
+
.instructions {
|
|
83
|
+
font-size: 1.2em;
|
|
84
|
+
line-height: 1.6;
|
|
85
|
+
margin-top: 20px;
|
|
86
|
+
}
|
|
87
|
+
.step {
|
|
88
|
+
margin: 10px 0;
|
|
89
|
+
padding: 10px;
|
|
90
|
+
background: rgba(255, 255, 255, 0.1);
|
|
91
|
+
border-radius: 10px;
|
|
92
|
+
}
|
|
93
|
+
.warning {
|
|
94
|
+
background: rgba(255, 193, 7, 0.2);
|
|
95
|
+
border: 2px solid #ffc107;
|
|
96
|
+
border-radius: 10px;
|
|
97
|
+
padding: 15px;
|
|
98
|
+
margin: 20px 0;
|
|
99
|
+
font-weight: bold;
|
|
100
|
+
}
|
|
101
|
+
</style>
|
|
102
|
+
</head>
|
|
103
|
+
<body>
|
|
104
|
+
<div class="container">
|
|
105
|
+
<h1>🚀 WAEngine QR Scanner</h1>
|
|
106
|
+
<div class="qr-container">
|
|
107
|
+
<img src="${qrCodeDataURL}" alt="QR Code" class="qr-code" />
|
|
108
|
+
</div>
|
|
109
|
+
<div class="warning">
|
|
110
|
+
⚠️ Scanne NUR diesen QR-Code!<br>
|
|
111
|
+
Nicht den Standard WhatsApp Web QR-Code!
|
|
112
|
+
</div>
|
|
113
|
+
<div class="instructions">
|
|
114
|
+
<div class="step">📱 1. Öffne WhatsApp auf deinem Handy</div>
|
|
115
|
+
<div class="step">⚙️ 2. Gehe zu Einstellungen</div>
|
|
116
|
+
<div class="step">🔗 3. Tippe auf "Verknüpfte Geräte"</div>
|
|
117
|
+
<div class="step">📷 4. Tippe auf "Gerät verknüpfen"</div>
|
|
118
|
+
<div class="step">🎯 5. Scanne den QR-Code oben</div>
|
|
119
|
+
</div>
|
|
120
|
+
</div>
|
|
121
|
+
<script>
|
|
122
|
+
// Auto-refresh QR code every 30 seconds
|
|
123
|
+
setTimeout(() => {
|
|
124
|
+
location.reload();
|
|
125
|
+
}, 30000);
|
|
126
|
+
</script>
|
|
127
|
+
</body>
|
|
128
|
+
</html>`;
|
|
129
|
+
|
|
130
|
+
await page.setContent(html);
|
|
131
|
+
console.log("✅ Browser mit korrektem QR-Code geöffnet!");
|
|
132
|
+
}
|
|
133
|
+
|
|
43
134
|
return { browser, page };
|
|
44
135
|
|
|
45
136
|
} catch (error) {
|
|
46
|
-
console.error("❌ Fehler beim
|
|
137
|
+
console.error("❌ Fehler beim QR-Code Browser:", error);
|
|
47
138
|
|
|
48
139
|
// Fallback: QR nur im Terminal
|
|
49
140
|
if (qrData) {
|
|
50
|
-
console.log("📱 Fallback - QR-Code im Terminal:");
|
|
141
|
+
console.log("📱 Fallback - QR-Code nur im Terminal:");
|
|
51
142
|
qrcode.generate(qrData, { small: true });
|
|
52
143
|
}
|
|
53
144
|
|
|
54
|
-
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Hilfsfunktion um QR-Code als Data URL zu generieren
|
|
150
|
+
async function generateQRCodeDataURL(qrData) {
|
|
151
|
+
try {
|
|
152
|
+
const QRCode = await import('qrcode');
|
|
153
|
+
return await QRCode.toDataURL(qrData, {
|
|
154
|
+
width: 300,
|
|
155
|
+
margin: 2,
|
|
156
|
+
color: {
|
|
157
|
+
dark: '#000000',
|
|
158
|
+
light: '#FFFFFF'
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
} catch (error) {
|
|
162
|
+
console.error("❌ Fehler beim QR-Code DataURL:", error);
|
|
163
|
+
return 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzAwIiBoZWlnaHQ9IjMwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMzAwIiBoZWlnaHQ9IjMwMCIgZmlsbD0iI2Y4ZjlmYSIvPjx0ZXh0IHg9IjE1MCIgeT0iMTUwIiBmb250LWZhbWlseT0iQXJpYWwiIGZvbnQtc2l6ZT0iMTYiIGZpbGw9IiM2NjY2NjYiIHRleHQtYW5jaG9yPSJtaWRkbGUiPkVycm9yPC90ZXh0Pjwvc3ZnPg==';
|
|
55
164
|
}
|
|
56
165
|
}
|
|
57
166
|
|
|
@@ -62,4 +171,4 @@ export async function closeBrowser() {
|
|
|
62
171
|
page = null;
|
|
63
172
|
console.log("🔴 Browser geschlossen");
|
|
64
173
|
}
|
|
65
|
-
}
|
|
174
|
+
}
|