waengine 1.8.1 → 1.8.2
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 +1 -1
- package/src/client.js +119 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "waengine",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.2",
|
|
4
4
|
"description": "🚀 WAEngine - The most powerful WhatsApp Bot Library with 860+ Working Features, Complete Baileys Integration & Production-Ready Stability",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
package/src/client.js
CHANGED
|
@@ -1413,6 +1413,125 @@ class DemoteAPI {
|
|
|
1413
1413
|
});
|
|
1414
1414
|
}
|
|
1415
1415
|
|
|
1416
|
+
// ===== SENDCHAT API - Nachrichten an beliebige Chats senden! =====
|
|
1417
|
+
|
|
1418
|
+
/**
|
|
1419
|
+
* Sendet eine Nachricht an einen beliebigen Chat (außerhalb von Message-Context)
|
|
1420
|
+
* @param {string} targetJid - Die JID des Ziel-Chats
|
|
1421
|
+
* @param {string|object} content - Text oder Message-Objekt
|
|
1422
|
+
* @param {object} options - Optionale Einstellungen
|
|
1423
|
+
* @returns {Promise} Gesendete Nachricht
|
|
1424
|
+
*/
|
|
1425
|
+
async sendChat(targetJid, content, options = {}) {
|
|
1426
|
+
try {
|
|
1427
|
+
if (!this.socket || !this.isConnected) {
|
|
1428
|
+
throw new Error('❌ Bot ist nicht verbunden!');
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
// Validiere JID Format
|
|
1432
|
+
if (!targetJid || typeof targetJid !== 'string') {
|
|
1433
|
+
throw new Error('❌ Ungültige JID! Format: "nummer@s.whatsapp.net" oder "gruppenid@g.us"');
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
// Normalisiere JID falls nötig
|
|
1437
|
+
let normalizedJid = targetJid;
|
|
1438
|
+
if (!targetJid.includes('@')) {
|
|
1439
|
+
normalizedJid = `${targetJid}@s.whatsapp.net`;
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
// Erstelle Message-Objekt
|
|
1443
|
+
let messageObj;
|
|
1444
|
+
|
|
1445
|
+
if (typeof content === 'string') {
|
|
1446
|
+
messageObj = { text: content };
|
|
1447
|
+
|
|
1448
|
+
// Füge optionale Features hinzu
|
|
1449
|
+
if (options.mentions && Array.isArray(options.mentions)) {
|
|
1450
|
+
messageObj.mentions = options.mentions;
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
if (options.image) {
|
|
1454
|
+
messageObj.image = { url: options.image };
|
|
1455
|
+
messageObj.caption = content;
|
|
1456
|
+
delete messageObj.text;
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
if (options.video) {
|
|
1460
|
+
messageObj.video = { url: options.video };
|
|
1461
|
+
messageObj.caption = content;
|
|
1462
|
+
delete messageObj.text;
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
if (options.audio) {
|
|
1466
|
+
messageObj.audio = { url: options.audio };
|
|
1467
|
+
messageObj.mimetype = 'audio/mp4';
|
|
1468
|
+
delete messageObj.text;
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
if (options.sticker) {
|
|
1472
|
+
messageObj.sticker = { url: options.sticker };
|
|
1473
|
+
delete messageObj.text;
|
|
1474
|
+
delete messageObj.caption;
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
if (options.document) {
|
|
1478
|
+
messageObj.document = { url: options.document };
|
|
1479
|
+
messageObj.fileName = options.fileName || 'document';
|
|
1480
|
+
messageObj.mimetype = options.mimetype || 'application/octet-stream';
|
|
1481
|
+
if (content) messageObj.caption = content;
|
|
1482
|
+
delete messageObj.text;
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
} else if (typeof content === 'object') {
|
|
1486
|
+
messageObj = content;
|
|
1487
|
+
} else {
|
|
1488
|
+
throw new Error('❌ Content muss String oder Objekt sein');
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1491
|
+
// Sende Nachricht
|
|
1492
|
+
console.log(`📤 Sende Nachricht an ${normalizedJid}`);
|
|
1493
|
+
const result = await this.socket.sendMessage(normalizedJid, messageObj);
|
|
1494
|
+
console.log('✅ Nachricht erfolgreich gesendet:', result?.key?.id);
|
|
1495
|
+
|
|
1496
|
+
return result;
|
|
1497
|
+
|
|
1498
|
+
} catch (error) {
|
|
1499
|
+
console.error('❌ Fehler beim Senden an anderen Chat:', error);
|
|
1500
|
+
throw error;
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1504
|
+
/**
|
|
1505
|
+
* Sendet eine Nachricht an mehrere Chats gleichzeitig (Broadcast)
|
|
1506
|
+
* @param {Array<string>} targetJids - Array von JIDs
|
|
1507
|
+
* @param {string|object} content - Nachricht
|
|
1508
|
+
* @param {object} options - Optionale Einstellungen
|
|
1509
|
+
* @returns {Promise<Array>} Array mit Ergebnissen
|
|
1510
|
+
*/
|
|
1511
|
+
async sendToMultipleChats(targetJids, content, options = {}) {
|
|
1512
|
+
if (!Array.isArray(targetJids) || targetJids.length === 0) {
|
|
1513
|
+
throw new Error('❌ targetJids muss ein nicht-leeres Array sein');
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
const results = [];
|
|
1517
|
+
const delay = options.delay || 1000;
|
|
1518
|
+
|
|
1519
|
+
for (const jid of targetJids) {
|
|
1520
|
+
try {
|
|
1521
|
+
const result = await this.sendChat(jid, content, options);
|
|
1522
|
+
results.push({ jid, success: true, result });
|
|
1523
|
+
|
|
1524
|
+
if (delay > 0 && jid !== targetJids[targetJids.length - 1]) {
|
|
1525
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
1526
|
+
}
|
|
1527
|
+
} catch (error) {
|
|
1528
|
+
results.push({ jid, success: false, error: error.message });
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
return results;
|
|
1533
|
+
}
|
|
1534
|
+
|
|
1416
1535
|
// ===== ERROR RECOVERY =====
|
|
1417
1536
|
|
|
1418
1537
|
async recoverFromError(error) {
|