waengine 1.9.4 → 1.9.6
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 +65 -0
- package/src/connection-recovery.js +43 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "waengine",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.6",
|
|
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
|
@@ -1192,6 +1192,71 @@ export class WhatsAppClient {
|
|
|
1192
1192
|
return await this.setPresence('paused', chatId);
|
|
1193
1193
|
}
|
|
1194
1194
|
|
|
1195
|
+
// ===== BOT PROFILE UPDATE METHODS =====
|
|
1196
|
+
|
|
1197
|
+
/**
|
|
1198
|
+
* Aktualisiert das Profilbild des Bots
|
|
1199
|
+
* @param {string|Buffer} imagePath - Pfad zum Bild oder Buffer
|
|
1200
|
+
* @returns {Promise<boolean>} - Erfolg oder Fehler
|
|
1201
|
+
*/
|
|
1202
|
+
async updateProfilePicture(imagePath) {
|
|
1203
|
+
try {
|
|
1204
|
+
const fs = await import('fs');
|
|
1205
|
+
let imageBuffer;
|
|
1206
|
+
|
|
1207
|
+
// Prüfe ob es ein Buffer oder Pfad ist
|
|
1208
|
+
if (Buffer.isBuffer(imagePath)) {
|
|
1209
|
+
imageBuffer = imagePath;
|
|
1210
|
+
} else {
|
|
1211
|
+
// Lade Bild von Pfad
|
|
1212
|
+
imageBuffer = fs.readFileSync(imagePath);
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
// Hole eigene JID
|
|
1216
|
+
const myJid = this.socket.user.id;
|
|
1217
|
+
|
|
1218
|
+
// Update Profilbild
|
|
1219
|
+
await this.socket.updateProfilePicture(myJid, imageBuffer);
|
|
1220
|
+
|
|
1221
|
+
console.log('✅ Profilbild erfolgreich aktualisiert!');
|
|
1222
|
+
return true;
|
|
1223
|
+
} catch (error) {
|
|
1224
|
+
this.errorHandler.handleError(error, {
|
|
1225
|
+
action: 'update_profile_picture',
|
|
1226
|
+
details: 'Profilbild-Update fehlgeschlagen'
|
|
1227
|
+
});
|
|
1228
|
+
console.error('❌ Fehler beim Aktualisieren des Profilbilds:', error);
|
|
1229
|
+
return false;
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
/**
|
|
1234
|
+
* Aktualisiert den Namen/Nickname des Bots
|
|
1235
|
+
* @param {string} name - Neuer Name
|
|
1236
|
+
* @returns {Promise<boolean>} - Erfolg oder Fehler
|
|
1237
|
+
*/
|
|
1238
|
+
async updateProfileName(name) {
|
|
1239
|
+
try {
|
|
1240
|
+
if (!name || typeof name !== 'string') {
|
|
1241
|
+
throw new Error('Name muss ein String sein');
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
// Update Profilname
|
|
1245
|
+
await this.socket.updateProfileName(name);
|
|
1246
|
+
|
|
1247
|
+
console.log(`✅ Profilname erfolgreich aktualisiert: "${name}"`);
|
|
1248
|
+
return true;
|
|
1249
|
+
} catch (error) {
|
|
1250
|
+
this.errorHandler.handleError(error, {
|
|
1251
|
+
action: 'update_profile_name',
|
|
1252
|
+
name: name,
|
|
1253
|
+
details: 'Profilname-Update fehlgeschlagen'
|
|
1254
|
+
});
|
|
1255
|
+
console.error('❌ Fehler beim Aktualisieren des Profilnamens:', error);
|
|
1256
|
+
return false;
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1195
1260
|
// ===== SENDCHAT API - Nachrichten an beliebige Chats senden! =====
|
|
1196
1261
|
|
|
1197
1262
|
/**
|
|
@@ -54,21 +54,58 @@ export class ConnectionRecovery {
|
|
|
54
54
|
// Perform connection health check
|
|
55
55
|
async performHealthCheck() {
|
|
56
56
|
try {
|
|
57
|
+
// Basis-Check: Socket und Connection-Status
|
|
57
58
|
if (!this.client.isConnected || !this.client.socket) {
|
|
58
59
|
throw new Error('Not connected');
|
|
59
60
|
}
|
|
60
61
|
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
// Prüfe ob Socket wirklich tot ist oder nur inaktiv
|
|
63
|
+
const socketState = this.client.socket.ws?.readyState;
|
|
64
|
+
|
|
65
|
+
// WebSocket States: 0=CONNECTING, 1=OPEN, 2=CLOSING, 3=CLOSED
|
|
66
|
+
if (socketState === 1) {
|
|
67
|
+
// Socket ist offen - alles gut, auch wenn inaktiv
|
|
68
|
+
this.state.lastSuccessTime = Date.now();
|
|
69
|
+
this.state.retryCount = 0;
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (socketState === 0) {
|
|
74
|
+
// Socket verbindet noch - warten
|
|
75
|
+
console.log('🔄 Socket is connecting...');
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Nur bei CLOSED oder CLOSING einen Ping-Test machen
|
|
80
|
+
if (socketState === 2 || socketState === 3) {
|
|
81
|
+
// Versuche Ping mit Timeout
|
|
82
|
+
const pingPromise = this.client.socket.query({
|
|
83
|
+
tag: 'iq',
|
|
84
|
+
attrs: { type: 'get', xmlns: 'w:p', id: 'health_' + Date.now() },
|
|
85
|
+
content: [{ tag: 'ping' }]
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const timeoutPromise = new Promise((_, reject) =>
|
|
89
|
+
setTimeout(() => reject(new Error('Ping timeout')), 5000)
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
await Promise.race([pingPromise, timeoutPromise]);
|
|
93
|
+
}
|
|
67
94
|
|
|
68
95
|
this.state.lastSuccessTime = Date.now();
|
|
69
96
|
this.state.retryCount = 0;
|
|
70
97
|
|
|
71
98
|
} catch (error) {
|
|
99
|
+
// Nur bei echten Verbindungsproblemen Recovery starten
|
|
100
|
+
const socketState = this.client.socket?.ws?.readyState;
|
|
101
|
+
|
|
102
|
+
if (socketState === 1) {
|
|
103
|
+
// Socket ist eigentlich offen - ignoriere Ping-Fehler
|
|
104
|
+
console.log('ℹ️ Ping failed but socket is open (device might be idle)');
|
|
105
|
+
this.state.lastSuccessTime = Date.now();
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
72
109
|
console.log('⚠️ Health check failed:', error.message);
|
|
73
110
|
await this.initiateRecovery(error);
|
|
74
111
|
}
|