natureco-cli 5.4.20 → 5.5.0

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.
@@ -1,316 +1,318 @@
1
- const chalk = require('chalk');
2
- const inquirer = require('../utils/inquirer-wrapper');
3
- const qrcode = require('qrcode-terminal');
4
- const fs = require('fs');
5
- const path = require('path');
6
- const os = require('os');
7
- const pino = require('pino');
8
- const { getApiKey, getConfig, saveConfig } = require('../utils/config');
9
- const { getBots, sendMessage } = require('../utils/api');
10
- const { loadBaileys } = require('../utils/baileys');
11
- const { NatureCoError, ChannelError, handleError } = require('../utils/errors');
12
-
13
- const logger = pino({ level: 'silent' });
14
-
15
- // WhatsApp session directory
16
- const WHATSAPP_SESSION_DIR = path.join(os.homedir(), '.natureco', 'whatsapp-sessions');
17
-
18
- async function whatsapp(action, number) {
19
- if (!action || action === 'connect') {
20
- return connectWhatsApp();
21
- }
22
-
23
- if (action === 'disconnect') {
24
- return disconnectWhatsApp();
25
- }
26
-
27
- if (action === 'status') {
28
- return statusWhatsApp();
29
- }
30
-
31
- if (action === 'allow') {
32
- if (!number) {
33
- console.log(chalk.red('\n❌ Numara belirtmelisiniz\n'));
34
- console.log(chalk.gray('Kullanım: natureco whatsapp allow <numara>\n'));
35
- process.exit(1);
36
- }
37
- return allowNumber(number);
38
- }
39
-
40
- console.log(chalk.red('\n❌ Unknown action\n'));
41
- console.log(chalk.gray('Available actions: connect, disconnect, status, allow\n'));
42
- process.exit(1);
43
- }
44
-
45
- async function connectWhatsApp() {
46
- const config = getConfig();
47
-
48
- if (!config.providerUrl) {
49
- console.log(chalk.red('\n❌ Setup yapılmamış. Önce "natureco setup" çalıştırın.\n'));
50
- process.exit(1);
51
- }
52
-
53
- console.log(chalk.yellow('\n⏳ WhatsApp bağlantısı hazırlanıyor...\n'));
54
-
55
- // WhatsApp için bot ID oluştur (timestamp-based)
56
- const botId = `whatsapp_${Date.now()}`;
57
- const selectedBot = { name: 'WhatsApp Bot', id: botId };
58
-
59
- console.log(chalk.cyan('\n📱 WhatsApp bağlantısı başlatılıyor...'));
60
- console.log(chalk.gray('Telefonunuzda WhatsApp\'ı açın ve QR kodu taratın.\n'));
61
-
62
- // Create session directory
63
- const sessionDir = path.join(WHATSAPP_SESSION_DIR, botId);
64
- if (!fs.existsSync(sessionDir)) {
65
- fs.mkdirSync(sessionDir, { recursive: true });
66
- }
67
-
68
- // Start connection (only for QR code)
69
- await startWhatsAppConnection(sessionDir, botId, selectedBot, config);
70
- }
71
-
72
- async function startWhatsAppConnection(sessionDir, botId, selectedBot, config) {
73
- try {
74
- const { makeWASocket, useMultiFileAuthState, DisconnectReason, fetchLatestBaileysVersion, Browsers } = loadBaileys();
75
-
76
- // Create auth state
77
- const { state, saveCreds } = await useMultiFileAuthState(sessionDir);
78
-
79
- // Get latest Baileys version
80
- const { version } = await fetchLatestBaileysVersion();
81
-
82
- console.log(chalk.yellow('⏳ WhatsApp client başlatılıyor...\n'));
83
-
84
- // Create socket
85
- const sock = makeWASocket({
86
- version,
87
- auth: state,
88
- printQRInTerminal: false,
89
- logger: logger,
90
- browser: Browsers.ubuntu('Chrome'),
91
- connectTimeoutMs: 60000,
92
- defaultQueryTimeoutMs: 60000,
93
- keepAliveIntervalMs: 10000,
94
- retryRequestDelayMs: 2000,
95
- });
96
-
97
- let qrDisplayed = false;
98
- let isConnected = false;
99
-
100
- // Connection update handler
101
- sock.ev.on('connection.update', async (update) => {
102
- const { connection, lastDisconnect, qr } = update;
103
-
104
- if (qr && !qrDisplayed) {
105
- console.log(chalk.green('✅ QR kod hazır!\n'));
106
-
107
- // Display QR code in terminal
108
- qrcode.generate(qr, { small: true });
109
-
110
- console.log('');
111
- console.log(chalk.gray('1. WhatsApp\'ı açın'));
112
- console.log(chalk.gray('2. Ayarlar > Bağlı Cihazlar > Cihaz Bağla'));
113
- console.log(chalk.gray('3. Bu QR kodu taratın\n'));
114
- console.log(chalk.yellow(' QR kod taranması bekleniyor...\n'));
115
-
116
- qrDisplayed = true;
117
- }
118
-
119
- if (connection === 'close') {
120
- const statusCode = lastDisconnect?.error?.output?.statusCode;
121
-
122
- if (statusCode === 515 || statusCode === 408) {
123
- // Normal — yeniden bağlan, logout değil
124
- console.log(chalk.yellow('🔄 Yeniden bağlanıyor...'));
125
- setTimeout(() => startWhatsAppConnection(sessionDir, botId, selectedBot, config), 2000);
126
- return;
127
- } else if (statusCode === 401) {
128
- console.log(chalk.red('❌ Oturum sonlandı, tekrar bağlanın.'));
129
- process.exit(1);
130
- } else if (statusCode === DisconnectReason.loggedOut) {
131
- console.log(chalk.red('\n❌ WhatsApp oturumu kapatıldı\n'));
132
- process.exit(0);
133
- } else if (!isConnected) {
134
- console.log(chalk.red('\n❌ Bağlantı başarısız\n'));
135
- console.log(chalk.gray(`Hata kodu: ${statusCode}\n`));
136
- process.exit(1);
137
- } else {
138
- console.log(chalk.red(`❌ Bağlantı kesildi: ${statusCode}\n`));
139
- process.exit(1);
140
- }
141
- } else if (connection === 'open') {
142
- isConnected = true;
143
- console.log(chalk.green('✅ WhatsApp bağlandı!\n'));
144
- console.log(chalk.cyan('Bot:'), chalk.white(selectedBot.name));
145
- console.log(chalk.cyan('Telefon:'), chalk.white(sock.user?.id || 'Unknown'));
146
- console.log(chalk.gray('\nSession kaydedildi: ~/.natureco/whatsapp-sessions/'));
147
-
148
- // Extract own number and add to allowed list
149
- const ownNumber = sock.user?.id?.split(':')[0].replace('@s.whatsapp.net', '') || '';
150
- const allowedNumbers = ownNumber ? [ownNumber] : [];
151
-
152
- // Save to config with own number in allowed list
153
- config.whatsappConnected = true;
154
- config.whatsappBotId = botId;
155
- config.whatsappPhone = sock.user?.id;
156
- config.whatsappAllowedNumbers = allowedNumbers;
157
- saveConfig(config);
158
-
159
- console.log(chalk.cyan('\nİzin verilen numara:'), chalk.white(`+${ownNumber} (kendi numaranız)`));
160
- console.log(chalk.gray('Başka numara eklemek için: natureco whatsapp allow <numara>'));
161
-
162
- console.log(chalk.green('\n✅ Kurulum tamamlandı!\n'));
163
- console.log(chalk.yellow('Gateway ile başlatmak için:'), chalk.cyan('natureco gateway start'));
164
- console.log(chalk.gray('Gateway, WhatsApp\ otomatik olarak başlatacak.\n'));
165
-
166
- // Exit after setup
167
- setTimeout(() => {
168
- process.exit(0);
169
- }, 2000);
170
- }
171
- });
172
-
173
- // Message handler removed - gateway handles this now
174
-
175
- // Save credentials on update
176
- sock.ev.on('creds.update', saveCreds);
177
-
178
- // Handle Ctrl+C
179
- process.on('SIGINT', () => {
180
- console.log(chalk.yellow('\n\n⚠️ Bağlantı iptal edildi\n'));
181
- process.exit(0);
182
- });
183
-
184
- } catch (err) {
185
- const msg = err instanceof NatureCoError ? err.message : err?.message ?? 'Unknown error';
186
- console.log(chalk.red(`\n❌ Connection failed: ${msg}\n`));
187
- if (err?.message?.includes('Cannot find module')) {
188
- console.log(chalk.yellow('⚠️ Baileys paketi yüklü değil. Yükleniyor...\n'));
189
- console.log(chalk.gray('Lütfen şu komutu çalıştırın:\n'));
190
- console.log(chalk.cyan('npm install -g @whiskeysockets/baileys pino\n'));
191
- }
192
- process.exit(1);
193
- }
194
- }
195
-
196
- async function disconnectWhatsApp() {
197
- const config = getConfig();
198
-
199
- if (!config.whatsappConnected) {
200
- console.log(chalk.gray('\n⚠️ No WhatsApp connection found\n'));
201
- return;
202
- }
203
-
204
- process.stdin.resume();
205
-
206
- const { confirm } = await inquirer.prompt([
207
- {
208
- type: 'confirm',
209
- name: 'confirm',
210
- message: 'Are you sure you want to disconnect WhatsApp?',
211
- default: false,
212
- },
213
- ]);
214
-
215
- if (!confirm) {
216
- console.log(chalk.gray('\nCancelled\n'));
217
- return;
218
- }
219
-
220
- try {
221
- // Remove session directory
222
- const sessionDir = path.join(WHATSAPP_SESSION_DIR, config.whatsappBotId);
223
- if (fs.existsSync(sessionDir)) {
224
- fs.rmSync(sessionDir, { recursive: true, force: true });
225
- console.log(chalk.green('\n✅ Session dosyaları silindi\n'));
226
- }
227
-
228
- // Remove from config
229
- delete config.whatsappConnected;
230
- delete config.whatsappBotId;
231
- delete config.whatsappPhone;
232
- saveConfig(config);
233
-
234
- console.log(chalk.green('✅ WhatsApp disconnected\n'));
235
- console.log(chalk.gray('Note: You may need to manually remove the device from WhatsApp settings.\n'));
236
- } catch (err) {
237
- console.log(chalk.red(`\n❌ Error: ${err.message}\n`));
238
- }
239
- }
240
-
241
- function statusWhatsApp() {
242
- const config = getConfig();
243
-
244
- if (!config.whatsappConnected) {
245
- console.log(chalk.gray('\n⚠️ WhatsApp not connected\n'));
246
- console.log(chalk.gray('Connect with: natureco whatsapp connect\n'));
247
- return;
248
- }
249
-
250
- console.log(chalk.green('\n✅ WhatsApp connected\n'));
251
-
252
- if (config.whatsappBotId) {
253
- console.log(chalk.cyan('Bot ID:'), chalk.white(config.whatsappBotId));
254
- }
255
-
256
- if (config.whatsappPhone) {
257
- console.log(chalk.cyan('Phone:'), chalk.white(config.whatsappPhone));
258
- }
259
-
260
- // Show allowed numbers
261
- const allowedNumbers = config.whatsappAllowedNumbers || [];
262
- if (allowedNumbers.length === 0) {
263
- console.log(chalk.cyan('İzin listesi:'), chalk.gray('Boş (herkesten mesaj kabul edilir)'));
264
- } else {
265
- console.log(chalk.cyan('İzin listesi:'));
266
- allowedNumbers.forEach(num => console.log(chalk.white(` - +${num}`)));
267
- }
268
-
269
- // Check if session files exist
270
- const sessionDir = path.join(WHATSAPP_SESSION_DIR, config.whatsappBotId);
271
- if (fs.existsSync(sessionDir)) {
272
- console.log(chalk.cyan('Session:'), chalk.white('Active'));
273
- console.log(chalk.gray(`Location: ${sessionDir}`));
274
- } else {
275
- console.log(chalk.yellow('Session:'), chalk.gray('Not found (may need to reconnect)'));
276
- }
277
-
278
- console.log(chalk.gray('\nDisconnect with: natureco whatsapp disconnect\n'));
279
- }
280
-
281
- function allowNumber(number) {
282
- const config = getConfig();
283
-
284
- if (!config.whatsappConnected) {
285
- console.log(chalk.red('\n❌ WhatsApp not connected\n'));
286
- console.log(chalk.gray('Connect first with: natureco whatsapp connect\n'));
287
- process.exit(1);
288
- }
289
-
290
- // Normalize number (remove +, spaces, etc.)
291
- const normalized = number.replace(/[\s\+\-\(\)]/g, '');
292
-
293
- if (!/^\d+$/.test(normalized)) {
294
- console.log(chalk.red('\n❌ Geçersiz numara formatı\n'));
295
- console.log(chalk.gray('Örnek: natureco whatsapp allow 905551234567\n'));
296
- process.exit(1);
297
- }
298
-
299
- const allowedNumbers = config.whatsappAllowedNumbers || [];
300
-
301
- if (allowedNumbers.includes(normalized)) {
302
- console.log(chalk.yellow('\n⚠️ Bu numara zaten izin listesinde\n'));
303
- return;
304
- }
305
-
306
- allowedNumbers.push(normalized);
307
- config.whatsappAllowedNumbers = allowedNumbers;
308
- saveConfig(config);
309
-
310
- console.log(chalk.green('\n✅ Numara izin listesine eklendi\n'));
311
- console.log(chalk.cyan('Numara:'), chalk.white(`+${normalized}`));
312
- console.log(chalk.cyan('Toplam:'), chalk.white(`${allowedNumbers.length} numara`));
313
- console.log(chalk.gray('\nGateway\'i yeniden başlatın: natureco gateway stop && natureco gateway start\n'));
314
- }
315
-
316
- module.exports = whatsapp;
1
+ const chalk = require('chalk');
2
+ const inquirer = require('../utils/inquirer-wrapper');
3
+ const qrcode = require('qrcode-terminal');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+ const os = require('os');
7
+ const pino = require('pino');
8
+ const { getApiKey, getConfig, saveConfig } = require('../utils/config');
9
+ const { getBots, sendMessage } = require('../utils/api');
10
+ const { loadBaileys } = require('../utils/baileys');
11
+ const { NatureCoError, ChannelError, handleError } = require('../utils/errors');
12
+
13
+ const logger = pino({ level: 'silent' });
14
+
15
+ // WhatsApp session directory
16
+ const WHATSAPP_SESSION_DIR = path.join(os.homedir(), '.natureco', 'whatsapp-sessions');
17
+
18
+ const { checkExistingToken } = require('./channel-helper');
19
+
20
+ async function whatsapp(action, number) {
21
+ if (!action || action === 'connect') {
22
+ return connectWhatsApp();
23
+ }
24
+
25
+ if (action === 'disconnect') {
26
+ return disconnectWhatsApp();
27
+ }
28
+
29
+ if (action === 'status') {
30
+ return statusWhatsApp();
31
+ }
32
+
33
+ if (action === 'allow') {
34
+ if (!number) {
35
+ console.log(chalk.red('\n❌ Numara belirtmelisiniz\n'));
36
+ console.log(chalk.gray('Kullanım: natureco whatsapp allow <numara>\n'));
37
+ process.exit(1);
38
+ }
39
+ return allowNumber(number);
40
+ }
41
+
42
+ console.log(chalk.red('\n❌ Unknown action\n'));
43
+ console.log(chalk.gray('Available actions: connect, disconnect, status, allow\n'));
44
+ process.exit(1);
45
+ }
46
+
47
+ async function connectWhatsApp() {
48
+ const config = getConfig();
49
+
50
+ if (!config.providerUrl) {
51
+ console.log(chalk.red('\n❌ Setup yapılmamış. Önce "natureco setup" çalıştırın.\n'));
52
+ process.exit(1);
53
+ }
54
+
55
+ console.log(chalk.yellow('\n⏳ WhatsApp bağlantısı hazırlanıyor...\n'));
56
+
57
+ // WhatsApp için bot ID oluştur (timestamp-based)
58
+ const botId = `whatsapp_${Date.now()}`;
59
+ const selectedBot = { name: 'WhatsApp Bot', id: botId };
60
+
61
+ console.log(chalk.cyan('\n📱 WhatsApp bağlantısı başlatılıyor...'));
62
+ console.log(chalk.gray('Telefonunuzda WhatsApp\'ı açın ve QR kodu taratın.\n'));
63
+
64
+ // Create session directory
65
+ const sessionDir = path.join(WHATSAPP_SESSION_DIR, botId);
66
+ if (!fs.existsSync(sessionDir)) {
67
+ fs.mkdirSync(sessionDir, { recursive: true });
68
+ }
69
+
70
+ // Start connection (only for QR code)
71
+ await startWhatsAppConnection(sessionDir, botId, selectedBot, config);
72
+ }
73
+
74
+ async function startWhatsAppConnection(sessionDir, botId, selectedBot, config) {
75
+ try {
76
+ const { makeWASocket, useMultiFileAuthState, DisconnectReason, fetchLatestBaileysVersion, Browsers } = loadBaileys();
77
+
78
+ // Create auth state
79
+ const { state, saveCreds } = await useMultiFileAuthState(sessionDir);
80
+
81
+ // Get latest Baileys version
82
+ const { version } = await fetchLatestBaileysVersion();
83
+
84
+ console.log(chalk.yellow('⏳ WhatsApp client başlatılıyor...\n'));
85
+
86
+ // Create socket
87
+ const sock = makeWASocket({
88
+ version,
89
+ auth: state,
90
+ printQRInTerminal: false,
91
+ logger: logger,
92
+ browser: Browsers.ubuntu('Chrome'),
93
+ connectTimeoutMs: 60000,
94
+ defaultQueryTimeoutMs: 60000,
95
+ keepAliveIntervalMs: 10000,
96
+ retryRequestDelayMs: 2000,
97
+ });
98
+
99
+ let qrDisplayed = false;
100
+ let isConnected = false;
101
+
102
+ // Connection update handler
103
+ sock.ev.on('connection.update', async (update) => {
104
+ const { connection, lastDisconnect, qr } = update;
105
+
106
+ if (qr && !qrDisplayed) {
107
+ console.log(chalk.green('✅ QR kod hazır!\n'));
108
+
109
+ // Display QR code in terminal
110
+ qrcode.generate(qr, { small: true });
111
+
112
+ console.log('');
113
+ console.log(chalk.gray('1. WhatsApp\'ı açın'));
114
+ console.log(chalk.gray('2. Ayarlar > Bağlı Cihazlar > Cihaz Bağla'));
115
+ console.log(chalk.gray('3. Bu QR kodu taratın\n'));
116
+ console.log(chalk.yellow('⏳ QR kod taranması bekleniyor...\n'));
117
+
118
+ qrDisplayed = true;
119
+ }
120
+
121
+ if (connection === 'close') {
122
+ const statusCode = lastDisconnect?.error?.output?.statusCode;
123
+
124
+ if (statusCode === 515 || statusCode === 408) {
125
+ // Normal yeniden bağlan, logout değil
126
+ console.log(chalk.yellow('🔄 Yeniden bağlanıyor...'));
127
+ setTimeout(() => startWhatsAppConnection(sessionDir, botId, selectedBot, config), 2000);
128
+ return;
129
+ } else if (statusCode === 401) {
130
+ console.log(chalk.red('❌ Oturum sonlandı, tekrar bağlanın.'));
131
+ process.exit(1);
132
+ } else if (statusCode === DisconnectReason.loggedOut) {
133
+ console.log(chalk.red('\n❌ WhatsApp oturumu kapatıldı\n'));
134
+ process.exit(0);
135
+ } else if (!isConnected) {
136
+ console.log(chalk.red('\n❌ Bağlantı başarısız\n'));
137
+ console.log(chalk.gray(`Hata kodu: ${statusCode}\n`));
138
+ process.exit(1);
139
+ } else {
140
+ console.log(chalk.red(`❌ Bağlantı kesildi: ${statusCode}\n`));
141
+ process.exit(1);
142
+ }
143
+ } else if (connection === 'open') {
144
+ isConnected = true;
145
+ console.log(chalk.green(' WhatsApp bağlandı!\n'));
146
+ console.log(chalk.cyan('Bot:'), chalk.white(selectedBot.name));
147
+ console.log(chalk.cyan('Telefon:'), chalk.white(sock.user?.id || 'Unknown'));
148
+ console.log(chalk.gray('\nSession kaydedildi: ~/.natureco/whatsapp-sessions/'));
149
+
150
+ // Extract own number and add to allowed list
151
+ const ownNumber = sock.user?.id?.split(':')[0].replace('@s.whatsapp.net', '') || '';
152
+ const allowedNumbers = ownNumber ? [ownNumber] : [];
153
+
154
+ // Save to config with own number in allowed list
155
+ config.whatsappConnected = true;
156
+ config.whatsappBotId = botId;
157
+ config.whatsappPhone = sock.user?.id;
158
+ config.whatsappAllowedNumbers = allowedNumbers;
159
+ saveConfig(config);
160
+
161
+ console.log(chalk.cyan('\nİzin verilen numara:'), chalk.white(`+${ownNumber} (kendi numaranız)`));
162
+ console.log(chalk.gray('Başka numara eklemek için: natureco whatsapp allow <numara>'));
163
+
164
+ console.log(chalk.green('\n✅ Kurulum tamamlandı!\n'));
165
+ console.log(chalk.yellow('Gateway ile başlatmak için:'), chalk.cyan('natureco gateway start'));
166
+ console.log(chalk.gray('Gateway, WhatsApp\'ı otomatik olarak başlatacak.\n'));
167
+
168
+ // Exit after setup
169
+ setTimeout(() => {
170
+ process.exit(0);
171
+ }, 2000);
172
+ }
173
+ });
174
+
175
+ // Message handler removed - gateway handles this now
176
+
177
+ // Save credentials on update
178
+ sock.ev.on('creds.update', saveCreds);
179
+
180
+ // Handle Ctrl+C
181
+ process.on('SIGINT', () => {
182
+ console.log(chalk.yellow('\n\n⚠️ Bağlantı iptal edildi\n'));
183
+ process.exit(0);
184
+ });
185
+
186
+ } catch (err) {
187
+ const msg = err instanceof NatureCoError ? err.message : err?.message ?? 'Unknown error';
188
+ console.log(chalk.red(`\n❌ Connection failed: ${msg}\n`));
189
+ if (err?.message?.includes('Cannot find module')) {
190
+ console.log(chalk.yellow('⚠️ Baileys paketi yüklü değil. Yükleniyor...\n'));
191
+ console.log(chalk.gray('Lütfen şu komutu çalıştırın:\n'));
192
+ console.log(chalk.cyan('npm install -g @whiskeysockets/baileys pino\n'));
193
+ }
194
+ process.exit(1);
195
+ }
196
+ }
197
+
198
+ async function disconnectWhatsApp() {
199
+ const config = getConfig();
200
+
201
+ if (!config.whatsappConnected) {
202
+ console.log(chalk.gray('\n⚠️ No WhatsApp connection found\n'));
203
+ return;
204
+ }
205
+
206
+ process.stdin.resume();
207
+
208
+ const { confirm } = await inquirer.prompt([
209
+ {
210
+ type: 'confirm',
211
+ name: 'confirm',
212
+ message: 'Are you sure you want to disconnect WhatsApp?',
213
+ default: false,
214
+ },
215
+ ]);
216
+
217
+ if (!confirm) {
218
+ console.log(chalk.gray('\nCancelled\n'));
219
+ return;
220
+ }
221
+
222
+ try {
223
+ // Remove session directory
224
+ const sessionDir = path.join(WHATSAPP_SESSION_DIR, config.whatsappBotId);
225
+ if (fs.existsSync(sessionDir)) {
226
+ fs.rmSync(sessionDir, { recursive: true, force: true });
227
+ console.log(chalk.green('\n✅ Session dosyaları silindi\n'));
228
+ }
229
+
230
+ // Remove from config
231
+ delete config.whatsappConnected;
232
+ delete config.whatsappBotId;
233
+ delete config.whatsappPhone;
234
+ saveConfig(config);
235
+
236
+ console.log(chalk.green('✅ WhatsApp disconnected\n'));
237
+ console.log(chalk.gray('Note: You may need to manually remove the device from WhatsApp settings.\n'));
238
+ } catch (err) {
239
+ console.log(chalk.red(`\n❌ Error: ${err.message}\n`));
240
+ }
241
+ }
242
+
243
+ function statusWhatsApp() {
244
+ const config = getConfig();
245
+
246
+ if (!config.whatsappConnected) {
247
+ console.log(chalk.gray('\n⚠️ WhatsApp not connected\n'));
248
+ console.log(chalk.gray('Connect with: natureco whatsapp connect\n'));
249
+ return;
250
+ }
251
+
252
+ console.log(chalk.green('\n✅ WhatsApp connected\n'));
253
+
254
+ if (config.whatsappBotId) {
255
+ console.log(chalk.cyan('Bot ID:'), chalk.white(config.whatsappBotId));
256
+ }
257
+
258
+ if (config.whatsappPhone) {
259
+ console.log(chalk.cyan('Phone:'), chalk.white(config.whatsappPhone));
260
+ }
261
+
262
+ // Show allowed numbers
263
+ const allowedNumbers = config.whatsappAllowedNumbers || [];
264
+ if (allowedNumbers.length === 0) {
265
+ console.log(chalk.cyan('İzin listesi:'), chalk.gray('Boş (herkesten mesaj kabul edilir)'));
266
+ } else {
267
+ console.log(chalk.cyan('İzin listesi:'));
268
+ allowedNumbers.forEach(num => console.log(chalk.white(` - +${num}`)));
269
+ }
270
+
271
+ // Check if session files exist
272
+ const sessionDir = path.join(WHATSAPP_SESSION_DIR, config.whatsappBotId);
273
+ if (fs.existsSync(sessionDir)) {
274
+ console.log(chalk.cyan('Session:'), chalk.white('Active'));
275
+ console.log(chalk.gray(`Location: ${sessionDir}`));
276
+ } else {
277
+ console.log(chalk.yellow('Session:'), chalk.gray('Not found (may need to reconnect)'));
278
+ }
279
+
280
+ console.log(chalk.gray('\nDisconnect with: natureco whatsapp disconnect\n'));
281
+ }
282
+
283
+ function allowNumber(number) {
284
+ const config = getConfig();
285
+
286
+ if (!config.whatsappConnected) {
287
+ console.log(chalk.red('\n❌ WhatsApp not connected\n'));
288
+ console.log(chalk.gray('Connect first with: natureco whatsapp connect\n'));
289
+ process.exit(1);
290
+ }
291
+
292
+ // Normalize number (remove +, spaces, etc.)
293
+ const normalized = number.replace(/[\s\+\-\(\)]/g, '');
294
+
295
+ if (!/^\d+$/.test(normalized)) {
296
+ console.log(chalk.red('\n❌ Geçersiz numara formatı\n'));
297
+ console.log(chalk.gray('Örnek: natureco whatsapp allow 905551234567\n'));
298
+ process.exit(1);
299
+ }
300
+
301
+ const allowedNumbers = config.whatsappAllowedNumbers || [];
302
+
303
+ if (allowedNumbers.includes(normalized)) {
304
+ console.log(chalk.yellow('\n⚠️ Bu numara zaten izin listesinde\n'));
305
+ return;
306
+ }
307
+
308
+ allowedNumbers.push(normalized);
309
+ config.whatsappAllowedNumbers = allowedNumbers;
310
+ saveConfig(config);
311
+
312
+ console.log(chalk.green('\n✅ Numara izin listesine eklendi\n'));
313
+ console.log(chalk.cyan('Numara:'), chalk.white(`+${normalized}`));
314
+ console.log(chalk.cyan('Toplam:'), chalk.white(`${allowedNumbers.length} numara`));
315
+ console.log(chalk.gray('\nGateway\'i yeniden başlatın: natureco gateway stop && natureco gateway start\n'));
316
+ }
317
+
318
+ module.exports = whatsapp;