natureco-cli 1.0.39 → 1.0.40

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "natureco-cli",
3
- "version": "1.0.39",
3
+ "version": "1.0.40",
4
4
  "description": "NatureCo AI Bot Terminal Interface",
5
5
  "main": "bin/natureco.js",
6
6
  "bin": {
@@ -45,6 +45,12 @@ function log(module, message, color = 'white') {
45
45
  }
46
46
  }
47
47
 
48
+ // Number matching helper - compare last 10 digits only
49
+ function numberMatches(incoming, allowed) {
50
+ const clean = (n) => n.replace(/\D/g, '').slice(-10);
51
+ return clean(incoming) === clean(allowed);
52
+ }
53
+
48
54
  async function gatewayServer(action) {
49
55
  // Check if running as background worker
50
56
  if (process.argv.includes('--gateway-worker')) {
@@ -239,8 +245,8 @@ async function startWhatsAppProvider(sessionDir, config) {
239
245
  // Log incoming number before access control
240
246
  log('whatsapp', `Incoming from: +${sender}, allowed: ${JSON.stringify(allowedNumbers)}`, 'gray');
241
247
 
242
- // Access control
243
- if (allowedNumbers.length > 0 && !allowedNumbers.includes(sender)) {
248
+ // Access control - compare last 10 digits
249
+ if (allowedNumbers.length > 0 && !allowedNumbers.some(n => numberMatches(n, sender))) {
244
250
  log('whatsapp', `blocked message from +${sender} (not in allowed list)`, 'yellow');
245
251
  continue;
246
252
  }
@@ -95,6 +95,22 @@ async function connectWhatsApp() {
95
95
 
96
96
  const selectedBot = botList.bots.find(b => b.id === botId);
97
97
 
98
+ // Ask for allowed numbers
99
+ process.stdin.resume();
100
+ const { allowedNumbers } = await inquirer.prompt([
101
+ {
102
+ type: 'input',
103
+ name: 'allowedNumbers',
104
+ message: 'Hangi numaralar mesaj gönderebilir? (virgülle ayırın, zorunlu)',
105
+ validate: (input) => {
106
+ if (!input || input.trim().length === 0) {
107
+ return 'En az bir numara girmelisiniz';
108
+ }
109
+ return true;
110
+ },
111
+ },
112
+ ]);
113
+
98
114
  console.log(chalk.cyan('\n📱 WhatsApp bağlantısı başlatılıyor...'));
99
115
  console.log(chalk.gray('Telefonunuzda WhatsApp\'ı açın ve QR kodu taratın.\n'));
100
116
 
@@ -107,8 +123,14 @@ async function connectWhatsApp() {
107
123
  fs.mkdirSync(sessionDir, { recursive: true });
108
124
  }
109
125
 
126
+ // Parse allowed numbers
127
+ const allowedNumbersList = allowedNumbers
128
+ .split(',')
129
+ .map(n => n.trim().replace(/[\s\+\-\(\)]/g, ''))
130
+ .filter(n => n.length > 0);
131
+
110
132
  // Start connection (only for QR code)
111
- await startWhatsAppConnection(sessionDir, botId, selectedBot, config, []);
133
+ await startWhatsAppConnection(sessionDir, botId, selectedBot, config, allowedNumbersList);
112
134
  }
113
135
 
114
136
  async function startWhatsAppConnection(sessionDir, botId, selectedBot, config, allowedNumbersList = []) {
@@ -185,15 +207,17 @@ async function startWhatsAppConnection(sessionDir, botId, selectedBot, config, a
185
207
  console.log(chalk.cyan('Telefon:'), chalk.white(sock.user?.id || 'Unknown'));
186
208
  console.log(chalk.gray('\nSession kaydedildi: ~/.natureco/whatsapp-sessions/'));
187
209
 
188
- // Save to config with empty allowed numbers (allow all)
210
+ // Save to config with allowed numbers
189
211
  config.whatsappConnected = true;
190
212
  config.whatsappBotId = botId;
191
213
  config.whatsappPhone = sock.user?.id;
192
- config.whatsappAllowedNumbers = [];
214
+ config.whatsappAllowedNumbers = allowedNumbersList;
193
215
  saveConfig(config);
194
216
 
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>'));
217
+ if (allowedNumbersList.length > 0) {
218
+ console.log(chalk.cyan('\nİzin verilen numaralar:'));
219
+ allowedNumbersList.forEach(num => console.log(chalk.gray(` - +${num}`)));
220
+ }
197
221
 
198
222
  console.log(chalk.green('\n✅ Kurulum tamamlandı!\n'));
199
223
  console.log(chalk.yellow('Gateway ile başlatmak için:'), chalk.cyan('natureco gateway start'));