natureco-cli 1.0.37 → 1.0.39
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
CHANGED
|
@@ -236,6 +236,9 @@ async function startWhatsAppProvider(sessionDir, config) {
|
|
|
236
236
|
const sender = msg.key.remoteJid?.split('@')[0].split(':')[0];
|
|
237
237
|
const allowedNumbers = config.whatsappAllowedNumbers || [];
|
|
238
238
|
|
|
239
|
+
// Log incoming number before access control
|
|
240
|
+
log('whatsapp', `Incoming from: +${sender}, allowed: ${JSON.stringify(allowedNumbers)}`, 'gray');
|
|
241
|
+
|
|
239
242
|
// Access control
|
|
240
243
|
if (allowedNumbers.length > 0 && !allowedNumbers.includes(sender)) {
|
|
241
244
|
log('whatsapp', `blocked message from +${sender} (not in allowed list)`, 'yellow');
|
package/src/commands/whatsapp.js
CHANGED
|
@@ -42,8 +42,18 @@ async function whatsapp(action) {
|
|
|
42
42
|
return statusWhatsApp();
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
if (action === 'allow') {
|
|
46
|
+
const number = process.argv[4];
|
|
47
|
+
if (!number) {
|
|
48
|
+
console.log(chalk.red('\n❌ Numara belirtmelisiniz\n'));
|
|
49
|
+
console.log(chalk.gray('Kullanım: natureco whatsapp allow <numara>\n'));
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
return allowNumber(number);
|
|
53
|
+
}
|
|
54
|
+
|
|
45
55
|
console.log(chalk.red('\n❌ Unknown action\n'));
|
|
46
|
-
console.log(chalk.gray('Available actions: connect, disconnect, status\n'));
|
|
56
|
+
console.log(chalk.gray('Available actions: connect, disconnect, status, allow\n'));
|
|
47
57
|
process.exit(1);
|
|
48
58
|
}
|
|
49
59
|
|
|
@@ -85,17 +95,6 @@ async function connectWhatsApp() {
|
|
|
85
95
|
|
|
86
96
|
const selectedBot = botList.bots.find(b => b.id === botId);
|
|
87
97
|
|
|
88
|
-
// Ask for allowed numbers
|
|
89
|
-
process.stdin.resume();
|
|
90
|
-
const { allowedNumbers } = await inquirer.prompt([
|
|
91
|
-
{
|
|
92
|
-
type: 'input',
|
|
93
|
-
name: 'allowedNumbers',
|
|
94
|
-
message: 'Hangi numaralar mesaj gönderebilir? (virgülle ayırın, boş bırakırsan sadece kendi numaran)',
|
|
95
|
-
default: '',
|
|
96
|
-
},
|
|
97
|
-
]);
|
|
98
|
-
|
|
99
98
|
console.log(chalk.cyan('\n📱 WhatsApp bağlantısı başlatılıyor...'));
|
|
100
99
|
console.log(chalk.gray('Telefonunuzda WhatsApp\'ı açın ve QR kodu taratın.\n'));
|
|
101
100
|
|
|
@@ -108,14 +107,8 @@ async function connectWhatsApp() {
|
|
|
108
107
|
fs.mkdirSync(sessionDir, { recursive: true });
|
|
109
108
|
}
|
|
110
109
|
|
|
111
|
-
// Parse allowed numbers
|
|
112
|
-
const allowedNumbersList = allowedNumbers
|
|
113
|
-
.split(',')
|
|
114
|
-
.map(n => n.trim())
|
|
115
|
-
.filter(n => n.length > 0);
|
|
116
|
-
|
|
117
110
|
// Start connection (only for QR code)
|
|
118
|
-
await startWhatsAppConnection(sessionDir, botId, selectedBot, config,
|
|
111
|
+
await startWhatsAppConnection(sessionDir, botId, selectedBot, config, []);
|
|
119
112
|
}
|
|
120
113
|
|
|
121
114
|
async function startWhatsAppConnection(sessionDir, botId, selectedBot, config, allowedNumbersList = []) {
|
|
@@ -192,21 +185,15 @@ async function startWhatsAppConnection(sessionDir, botId, selectedBot, config, a
|
|
|
192
185
|
console.log(chalk.cyan('Telefon:'), chalk.white(sock.user?.id || 'Unknown'));
|
|
193
186
|
console.log(chalk.gray('\nSession kaydedildi: ~/.natureco/whatsapp-sessions/'));
|
|
194
187
|
|
|
195
|
-
//
|
|
196
|
-
const ownNumber = sock.user?.id?.split(':')[0].replace('@s.whatsapp.net', '');
|
|
197
|
-
const finalAllowedNumbers = ownNumber ? [ownNumber, ...allowedNumbersList] : allowedNumbersList;
|
|
198
|
-
|
|
199
|
-
// Save to config
|
|
188
|
+
// Save to config with empty allowed numbers (allow all)
|
|
200
189
|
config.whatsappConnected = true;
|
|
201
190
|
config.whatsappBotId = botId;
|
|
202
191
|
config.whatsappPhone = sock.user?.id;
|
|
203
|
-
config.whatsappAllowedNumbers =
|
|
192
|
+
config.whatsappAllowedNumbers = [];
|
|
204
193
|
saveConfig(config);
|
|
205
194
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
finalAllowedNumbers.forEach(num => console.log(chalk.gray(` - ${num}`)));
|
|
209
|
-
}
|
|
195
|
+
console.log(chalk.cyan('\nİzin listesi:'), chalk.gray('Boş (herkesten mesaj kabul edilir)'));
|
|
196
|
+
console.log(chalk.gray('Numara eklemek için: natureco whatsapp allow <numara>'));
|
|
210
197
|
|
|
211
198
|
console.log(chalk.green('\n✅ Kurulum tamamlandı!\n'));
|
|
212
199
|
console.log(chalk.yellow('Gateway ile başlatmak için:'), chalk.cyan('natureco gateway start'));
|
|
@@ -305,6 +292,15 @@ function statusWhatsApp() {
|
|
|
305
292
|
console.log(chalk.cyan('Phone:'), chalk.white(config.whatsappPhone));
|
|
306
293
|
}
|
|
307
294
|
|
|
295
|
+
// Show allowed numbers
|
|
296
|
+
const allowedNumbers = config.whatsappAllowedNumbers || [];
|
|
297
|
+
if (allowedNumbers.length === 0) {
|
|
298
|
+
console.log(chalk.cyan('İzin listesi:'), chalk.gray('Boş (herkesten mesaj kabul edilir)'));
|
|
299
|
+
} else {
|
|
300
|
+
console.log(chalk.cyan('İzin listesi:'));
|
|
301
|
+
allowedNumbers.forEach(num => console.log(chalk.white(` - +${num}`)));
|
|
302
|
+
}
|
|
303
|
+
|
|
308
304
|
// Check if session files exist
|
|
309
305
|
const sessionDir = path.join(WHATSAPP_SESSION_DIR, config.whatsappBotId);
|
|
310
306
|
if (fs.existsSync(sessionDir)) {
|
|
@@ -317,4 +313,39 @@ function statusWhatsApp() {
|
|
|
317
313
|
console.log(chalk.gray('\nDisconnect with: natureco whatsapp disconnect\n'));
|
|
318
314
|
}
|
|
319
315
|
|
|
316
|
+
function allowNumber(number) {
|
|
317
|
+
const config = getConfig();
|
|
318
|
+
|
|
319
|
+
if (!config.whatsappConnected) {
|
|
320
|
+
console.log(chalk.red('\n❌ WhatsApp not connected\n'));
|
|
321
|
+
console.log(chalk.gray('Connect first with: natureco whatsapp connect\n'));
|
|
322
|
+
process.exit(1);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// Normalize number (remove +, spaces, etc.)
|
|
326
|
+
const normalized = number.replace(/[\s\+\-\(\)]/g, '');
|
|
327
|
+
|
|
328
|
+
if (!/^\d+$/.test(normalized)) {
|
|
329
|
+
console.log(chalk.red('\n❌ Geçersiz numara formatı\n'));
|
|
330
|
+
console.log(chalk.gray('Örnek: natureco whatsapp allow 905551234567\n'));
|
|
331
|
+
process.exit(1);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
const allowedNumbers = config.whatsappAllowedNumbers || [];
|
|
335
|
+
|
|
336
|
+
if (allowedNumbers.includes(normalized)) {
|
|
337
|
+
console.log(chalk.yellow('\n⚠️ Bu numara zaten izin listesinde\n'));
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
allowedNumbers.push(normalized);
|
|
342
|
+
config.whatsappAllowedNumbers = allowedNumbers;
|
|
343
|
+
saveConfig(config);
|
|
344
|
+
|
|
345
|
+
console.log(chalk.green('\n✅ Numara izin listesine eklendi\n'));
|
|
346
|
+
console.log(chalk.cyan('Numara:'), chalk.white(`+${normalized}`));
|
|
347
|
+
console.log(chalk.cyan('Toplam:'), chalk.white(`${allowedNumbers.length} numara`));
|
|
348
|
+
console.log(chalk.gray('\nGateway\'i yeniden başlatın: natureco gateway stop && natureco gateway start\n'));
|
|
349
|
+
}
|
|
350
|
+
|
|
320
351
|
module.exports = whatsapp;
|