natureco-cli 5.4.21 → 5.5.1
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 +10 -2
- package/src/commands/channel-helper.js +51 -0
- package/src/commands/discord.js +116 -114
- package/src/commands/gateway-server.js +2107 -1977
- package/src/commands/imessage.js +2 -0
- package/src/commands/setup.js +22 -0
- package/src/commands/signal.js +2 -0
- package/src/commands/slack.js +121 -119
- package/src/commands/whatsapp.js +318 -316
- package/src/utils/api.js +1158 -1054
package/src/commands/whatsapp.js
CHANGED
|
@@ -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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
console.log(
|
|
113
|
-
console.log(chalk.gray('
|
|
114
|
-
console.log(chalk.
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
console.log(chalk.
|
|
146
|
-
console.log(chalk.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
config
|
|
155
|
-
config.
|
|
156
|
-
config.
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
console.log(chalk.
|
|
163
|
-
|
|
164
|
-
console.log(chalk.
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
//
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
console.log(chalk.
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
delete config.
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
console.log(chalk.
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
console.log(chalk.cyan('İzin listesi:'));
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
if
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
console.log(chalk.
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
console.log(chalk.
|
|
313
|
-
console.log(chalk.
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
|
|
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;
|