natureco-cli 2.7.1 → 2.8.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.
package/bin/natureco.js CHANGED
@@ -193,6 +193,24 @@ program
193
193
  telegramCmd(action);
194
194
  });
195
195
 
196
+ program
197
+ .command('message <action>')
198
+ .description('Send messages directly (send)')
199
+ .option('--target <target>', 'Target phone number or chat ID')
200
+ .option('--message <message>', 'Message to send')
201
+ .option('--channel <channel>', 'Channel: whatsapp or telegram (default: whatsapp)')
202
+ .action((action, options) => {
203
+ if (action === 'send') {
204
+ const messageCmd = require('../src/commands/message');
205
+ const args = process.argv.slice(3); // Get all args after 'message send'
206
+ messageCmd(args);
207
+ } else {
208
+ console.log(chalk.red('\n❌ Unknown action\n'));
209
+ console.log(chalk.gray('Available actions: send\n'));
210
+ process.exit(1);
211
+ }
212
+ });
213
+
196
214
  program
197
215
  .command('dashboard [action]')
198
216
  .description('Web Control UI (start|stop|status)')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "natureco-cli",
3
- "version": "2.7.1",
3
+ "version": "2.8.0",
4
4
  "description": "NatureCo AI Bot Terminal Interface",
5
5
  "main": "bin/natureco.js",
6
6
  "bin": {
@@ -211,7 +211,7 @@ body::before{
211
211
  <div class="header-bot-name" id="header-bot-name">Nature Bot</div>
212
212
  <div class="header-bot-model" id="header-bot-model">NatureCo</div>
213
213
  </div>
214
- <div class="version-badge" id="version-badge">v2.7.1</div>
214
+ <div class="version-badge" id="version-badge">v2.8.0</div>
215
215
  </div>
216
216
  <div class="messages" id="messages"></div>
217
217
  <div class="input-area">
@@ -341,7 +341,7 @@ function dashboard(action) {
341
341
  apiKey: cfg.apiKey,
342
342
  defaultBot: cfg.defaultBot,
343
343
  defaultBotId: cfg.defaultBotId,
344
- version: 'v2.7.1',
344
+ version: 'v2.8.0',
345
345
  bots: cfg.bots || [],
346
346
  telegramToken: cfg.telegramToken || null,
347
347
  whatsappConnected: cfg.whatsappConnected || false,
@@ -128,7 +128,7 @@ async function startGateway() {
128
128
 
129
129
  async function runGatewayWorker() {
130
130
  // This runs in the background
131
- log('gateway', 'Starting NatureCo Gateway v2.7.1...', 'green');
131
+ log('gateway', 'Starting NatureCo Gateway v2.8.0...', 'green');
132
132
 
133
133
  // Load config
134
134
  const { getConfig } = require('../utils/config');
@@ -0,0 +1,195 @@
1
+ const chalk = require('chalk');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const os = require('os');
5
+ const { getConfig } = require('../utils/config');
6
+
7
+ const PID_FILE = path.join(os.homedir(), '.natureco', 'gateway.pid');
8
+
9
+ async function message(args) {
10
+ // Parse arguments
11
+ const targetIndex = args.indexOf('--target');
12
+ const messageIndex = args.indexOf('--message');
13
+ const channelIndex = args.indexOf('--channel');
14
+
15
+ if (targetIndex === -1 || messageIndex === -1) {
16
+ console.log(chalk.red('\n❌ Eksik parametre\n'));
17
+ console.log(chalk.gray('Kullanım:'));
18
+ console.log(chalk.cyan(' natureco message send --target <target> --message <msg> --channel [whatsapp|telegram]'));
19
+ console.log(chalk.gray('\nÖrnekler:'));
20
+ console.log(chalk.cyan(' natureco message send --target +905422842631 --message "Test" --channel whatsapp'));
21
+ console.log(chalk.cyan(' natureco message send --target 6139455189 --message "Test" --channel telegram\n'));
22
+ process.exit(1);
23
+ }
24
+
25
+ const target = args[targetIndex + 1];
26
+ const messageText = args[messageIndex + 1];
27
+ const channel = channelIndex !== -1 ? args[channelIndex + 1] : 'whatsapp';
28
+
29
+ if (!target || !messageText) {
30
+ console.log(chalk.red('\n❌ Target veya message boş olamaz\n'));
31
+ process.exit(1);
32
+ }
33
+
34
+ if (!['whatsapp', 'telegram'].includes(channel)) {
35
+ console.log(chalk.red('\n❌ Geçersiz kanal. Sadece "whatsapp" veya "telegram" kullanılabilir\n'));
36
+ process.exit(1);
37
+ }
38
+
39
+ // Check if gateway is running
40
+ if (!fs.existsSync(PID_FILE)) {
41
+ console.log(chalk.red('\n❌ Gateway çalışmıyor\n'));
42
+ console.log(chalk.yellow('Önce gateway\'i başlatın:'), chalk.cyan('natureco gateway start\n'));
43
+ process.exit(1);
44
+ }
45
+
46
+ try {
47
+ const pid = parseInt(fs.readFileSync(PID_FILE, 'utf-8').trim());
48
+ process.kill(pid, 0); // Check if process exists
49
+ } catch {
50
+ console.log(chalk.red('\n❌ Gateway çalışmıyor (stale PID)\n'));
51
+ console.log(chalk.yellow('Önce gateway\'i başlatın:'), chalk.cyan('natureco gateway start\n'));
52
+ process.exit(1);
53
+ }
54
+
55
+ const config = getConfig();
56
+
57
+ if (channel === 'whatsapp') {
58
+ await sendWhatsAppMessage(target, messageText, config);
59
+ } else if (channel === 'telegram') {
60
+ await sendTelegramMessage(target, messageText, config);
61
+ }
62
+ }
63
+
64
+ async function sendWhatsAppMessage(target, messageText, config) {
65
+ if (!config.whatsappConnected || !config.whatsappBotId) {
66
+ console.log(chalk.red('\n❌ WhatsApp bağlı değil\n'));
67
+ console.log(chalk.yellow('Önce WhatsApp\'ı bağlayın:'), chalk.cyan('natureco whatsapp connect\n'));
68
+ process.exit(1);
69
+ }
70
+
71
+ console.log(chalk.yellow('\n⏳ WhatsApp mesajı gönderiliyor...\n'));
72
+
73
+ try {
74
+ // Lazy load Baileys
75
+ const baileys = require('@whiskeysockets/baileys');
76
+ const makeWASocket = baileys.default;
77
+ const useMultiFileAuthState = baileys.useMultiFileAuthState;
78
+ const fetchLatestBaileysVersion = baileys.fetchLatestBaileysVersion;
79
+ const Browsers = baileys.Browsers;
80
+ const pino = require('pino');
81
+ const logger = pino({ level: 'silent' });
82
+
83
+ const sessionDir = path.join(os.homedir(), '.natureco', 'whatsapp-sessions', config.whatsappBotId);
84
+
85
+ if (!fs.existsSync(sessionDir)) {
86
+ console.log(chalk.red('❌ WhatsApp session bulunamadı\n'));
87
+ console.log(chalk.yellow('Önce WhatsApp\'ı bağlayın:'), chalk.cyan('natureco whatsapp connect\n'));
88
+ process.exit(1);
89
+ }
90
+
91
+ const { state } = await useMultiFileAuthState(sessionDir);
92
+ const { version } = await fetchLatestBaileysVersion();
93
+
94
+ const sock = makeWASocket({
95
+ version,
96
+ auth: state,
97
+ printQRInTerminal: false,
98
+ logger: logger,
99
+ browser: Browsers.ubuntu('Chrome'),
100
+ connectTimeoutMs: 30000,
101
+ });
102
+
103
+ // Wait for connection
104
+ await new Promise((resolve, reject) => {
105
+ const timeout = setTimeout(() => {
106
+ reject(new Error('Connection timeout'));
107
+ }, 30000);
108
+
109
+ sock.ev.on('connection.update', (update) => {
110
+ if (update.connection === 'open') {
111
+ clearTimeout(timeout);
112
+ resolve();
113
+ } else if (update.connection === 'close') {
114
+ clearTimeout(timeout);
115
+ reject(new Error('Connection failed'));
116
+ }
117
+ });
118
+ });
119
+
120
+ // Normalize phone number
121
+ const normalizedTarget = target.replace(/[^\d]/g, '');
122
+ const jid = `${normalizedTarget}@s.whatsapp.net`;
123
+
124
+ // Send message
125
+ await sock.sendMessage(jid, { text: messageText });
126
+
127
+ console.log(chalk.green('✅ Mesaj gönderildi!\n'));
128
+ console.log(chalk.cyan('Hedef:'), chalk.white(target));
129
+ console.log(chalk.cyan('Mesaj:'), chalk.white(messageText));
130
+ console.log('');
131
+
132
+ // Close connection
133
+ setTimeout(() => {
134
+ sock.end();
135
+ process.exit(0);
136
+ }, 2000);
137
+
138
+ } catch (err) {
139
+ console.log(chalk.red(`\n❌ Hata: ${err.message}\n`));
140
+ process.exit(1);
141
+ }
142
+ }
143
+
144
+ async function sendTelegramMessage(target, messageText, config) {
145
+ if (!config.telegramToken || !config.telegramBotId) {
146
+ console.log(chalk.red('\n❌ Telegram bağlı değil\n'));
147
+ console.log(chalk.yellow('Önce Telegram\'ı bağlayın:'), chalk.cyan('natureco telegram connect\n'));
148
+ process.exit(1);
149
+ }
150
+
151
+ console.log(chalk.yellow('\n⏳ Telegram mesajı gönderiliyor...\n'));
152
+
153
+ try {
154
+ // Lazy load node-telegram-bot-api
155
+ let TelegramBot;
156
+ try {
157
+ TelegramBot = require('node-telegram-bot-api');
158
+ } catch (err) {
159
+ console.log(chalk.red('❌ node-telegram-bot-api yüklü değil\n'));
160
+ console.log(chalk.yellow('Yüklemek için:'), chalk.cyan('npm install -g node-telegram-bot-api\n'));
161
+ process.exit(1);
162
+ }
163
+
164
+ const bot = new TelegramBot(config.telegramToken, { polling: false });
165
+
166
+ // Validate chat ID (should be numeric)
167
+ const chatId = target.trim();
168
+ if (!/^-?\d+$/.test(chatId)) {
169
+ console.log(chalk.red('❌ Geçersiz Telegram Chat ID\n'));
170
+ console.log(chalk.gray('Chat ID sadece rakamlardan oluşmalı (örnek: 123456789)\n'));
171
+ process.exit(1);
172
+ }
173
+
174
+ // Send message
175
+ await bot.sendMessage(chatId, messageText);
176
+
177
+ console.log(chalk.green('✅ Mesaj gönderildi!\n'));
178
+ console.log(chalk.cyan('Chat ID:'), chalk.white(chatId));
179
+ console.log(chalk.cyan('Mesaj:'), chalk.white(messageText));
180
+ console.log('');
181
+
182
+ process.exit(0);
183
+
184
+ } catch (err) {
185
+ console.log(chalk.red(`\n❌ Hata: ${err.message}\n`));
186
+
187
+ if (err.message.includes('chat not found')) {
188
+ console.log(chalk.yellow('⚠️ Chat ID bulunamadı. Önce bot\'a mesaj gönderin.\n'));
189
+ }
190
+
191
+ process.exit(1);
192
+ }
193
+ }
194
+
195
+ module.exports = message;
package/src/utils/api.js CHANGED
@@ -1,4 +1,4 @@
1
- // NatureCo CLI v2.7.1 - Universal LLM Provider Support
1
+ // NatureCo CLI v2.8.0 - Universal LLM Provider Support
2
2
  // Supports: OpenAI, Groq, Together, Fireworks, Perplexity, Mistral, DeepSeek, OpenRouter, Ollama, LM Studio, Anthropic
3
3
 
4
4
  const fs = require('fs');