natureco-cli 1.0.25 → 1.0.26
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/commands/whatsapp.js +27 -14
package/package.json
CHANGED
package/src/commands/whatsapp.js
CHANGED
|
@@ -88,16 +88,21 @@ async function connectWhatsApp() {
|
|
|
88
88
|
console.log(chalk.cyan('\n📱 WhatsApp bağlantısı başlatılıyor...'));
|
|
89
89
|
console.log(chalk.gray('Telefonunuzda WhatsApp\'ı açın ve QR kodu taratın.\n'));
|
|
90
90
|
|
|
91
|
+
// Load Baileys
|
|
92
|
+
loadBaileys();
|
|
93
|
+
|
|
94
|
+
// Create session directory
|
|
95
|
+
const sessionDir = path.join(WHATSAPP_SESSION_DIR, botId);
|
|
96
|
+
if (!fs.existsSync(sessionDir)) {
|
|
97
|
+
fs.mkdirSync(sessionDir, { recursive: true });
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Start connection
|
|
101
|
+
await startWhatsAppConnection(sessionDir, botId, selectedBot, config);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function startWhatsAppConnection(sessionDir, botId, selectedBot, config) {
|
|
91
105
|
try {
|
|
92
|
-
// Load Baileys
|
|
93
|
-
loadBaileys();
|
|
94
|
-
|
|
95
|
-
// Create session directory
|
|
96
|
-
const sessionDir = path.join(WHATSAPP_SESSION_DIR, botId);
|
|
97
|
-
if (!fs.existsSync(sessionDir)) {
|
|
98
|
-
fs.mkdirSync(sessionDir, { recursive: true });
|
|
99
|
-
}
|
|
100
|
-
|
|
101
106
|
// Create auth state
|
|
102
107
|
const { state, saveCreds } = await useMultiFileAuthState(sessionDir);
|
|
103
108
|
|
|
@@ -138,19 +143,27 @@ async function connectWhatsApp() {
|
|
|
138
143
|
}
|
|
139
144
|
|
|
140
145
|
if (connection === 'close') {
|
|
141
|
-
const shouldReconnect = lastDisconnect?.error?.output?.statusCode !== DisconnectReason.loggedOut;
|
|
142
146
|
const statusCode = lastDisconnect?.error?.output?.statusCode;
|
|
143
147
|
|
|
144
|
-
if (statusCode ===
|
|
148
|
+
if (statusCode === 515) {
|
|
149
|
+
// Normal — yeniden bağlan, logout değil
|
|
150
|
+
console.log(chalk.yellow('🔄 Yeniden bağlanıyor...'));
|
|
151
|
+
setTimeout(() => startWhatsAppConnection(sessionDir, botId, selectedBot, config), 1000);
|
|
152
|
+
return;
|
|
153
|
+
} else if (statusCode === 401) {
|
|
154
|
+
console.log(chalk.red('❌ Oturum sonlandı, tekrar bağlanın.'));
|
|
155
|
+
process.exit(1);
|
|
156
|
+
} else if (statusCode === DisconnectReason.loggedOut) {
|
|
145
157
|
console.log(chalk.red('\n❌ WhatsApp oturumu kapatıldı\n'));
|
|
158
|
+
process.exit(0);
|
|
146
159
|
} else if (!isConnected) {
|
|
147
160
|
console.log(chalk.red('\n❌ Bağlantı başarısız\n'));
|
|
148
161
|
console.log(chalk.gray(`Hata kodu: ${statusCode}\n`));
|
|
162
|
+
process.exit(1);
|
|
149
163
|
} else {
|
|
150
|
-
console.log(chalk.
|
|
164
|
+
console.log(chalk.red(`❌ Bağlantı kesildi: ${statusCode}\n`));
|
|
165
|
+
process.exit(1);
|
|
151
166
|
}
|
|
152
|
-
|
|
153
|
-
process.exit(statusCode === DisconnectReason.loggedOut ? 0 : 1);
|
|
154
167
|
} else if (connection === 'open') {
|
|
155
168
|
isConnected = true;
|
|
156
169
|
console.log(chalk.green('✅ WhatsApp bağlandı!\n'));
|