natureco-cli 1.0.25 → 1.0.27
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 +32 -15
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
|
|
|
@@ -111,8 +116,12 @@ async function connectWhatsApp() {
|
|
|
111
116
|
version,
|
|
112
117
|
auth: state,
|
|
113
118
|
printQRInTerminal: false,
|
|
114
|
-
browser: Browsers.ubuntu('Chrome'),
|
|
115
119
|
logger: logger,
|
|
120
|
+
browser: Browsers.ubuntu('Chrome'),
|
|
121
|
+
connectTimeoutMs: 60000,
|
|
122
|
+
defaultQueryTimeoutMs: 60000,
|
|
123
|
+
keepAliveIntervalMs: 10000,
|
|
124
|
+
retryRequestDelayMs: 2000,
|
|
116
125
|
});
|
|
117
126
|
|
|
118
127
|
let qrDisplayed = false;
|
|
@@ -138,19 +147,27 @@ async function connectWhatsApp() {
|
|
|
138
147
|
}
|
|
139
148
|
|
|
140
149
|
if (connection === 'close') {
|
|
141
|
-
const shouldReconnect = lastDisconnect?.error?.output?.statusCode !== DisconnectReason.loggedOut;
|
|
142
150
|
const statusCode = lastDisconnect?.error?.output?.statusCode;
|
|
143
151
|
|
|
144
|
-
if (statusCode ===
|
|
152
|
+
if (statusCode === 515 || statusCode === 408) {
|
|
153
|
+
// Normal — yeniden bağlan, logout değil
|
|
154
|
+
console.log(chalk.yellow('🔄 Yeniden bağlanıyor...'));
|
|
155
|
+
setTimeout(() => startWhatsAppConnection(sessionDir, botId, selectedBot, config), 2000);
|
|
156
|
+
return;
|
|
157
|
+
} else if (statusCode === 401) {
|
|
158
|
+
console.log(chalk.red('❌ Oturum sonlandı, tekrar bağlanın.'));
|
|
159
|
+
process.exit(1);
|
|
160
|
+
} else if (statusCode === DisconnectReason.loggedOut) {
|
|
145
161
|
console.log(chalk.red('\n❌ WhatsApp oturumu kapatıldı\n'));
|
|
162
|
+
process.exit(0);
|
|
146
163
|
} else if (!isConnected) {
|
|
147
164
|
console.log(chalk.red('\n❌ Bağlantı başarısız\n'));
|
|
148
165
|
console.log(chalk.gray(`Hata kodu: ${statusCode}\n`));
|
|
166
|
+
process.exit(1);
|
|
149
167
|
} else {
|
|
150
|
-
console.log(chalk.
|
|
168
|
+
console.log(chalk.red(`❌ Bağlantı kesildi: ${statusCode}\n`));
|
|
169
|
+
process.exit(1);
|
|
151
170
|
}
|
|
152
|
-
|
|
153
|
-
process.exit(statusCode === DisconnectReason.loggedOut ? 0 : 1);
|
|
154
171
|
} else if (connection === 'open') {
|
|
155
172
|
isConnected = true;
|
|
156
173
|
console.log(chalk.green('✅ WhatsApp bağlandı!\n'));
|