natureco-cli 1.0.33 → 1.0.35

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.33",
3
+ "version": "1.0.35",
4
4
  "description": "NatureCo AI Bot Terminal Interface",
5
5
  "main": "bin/natureco.js",
6
6
  "bin": {
@@ -218,13 +218,20 @@ async function startWhatsAppProvider(sessionDir, config) {
218
218
  }
219
219
  } else if (connection === 'open') {
220
220
  const phone = sock.user?.id?.split(':')[0].replace('@s.whatsapp.net', '') || 'unknown';
221
+ log('whatsapp', `Connected successfully`, 'green');
221
222
  log('whatsapp', `Listening for inbound messages.`, 'cyan');
223
+ log('whatsapp', `Phone: +${phone}`, 'gray');
222
224
  }
223
225
  });
224
226
 
225
227
  sock.ev.on('messages.upsert', async ({ messages }) => {
228
+ log('whatsapp', `messages.upsert event triggered, ${messages.length} message(s)`, 'gray');
229
+
226
230
  for (const msg of messages) {
227
- if (msg.key.fromMe) continue;
231
+ if (msg.key.fromMe) {
232
+ log('whatsapp', 'skipping own message', 'gray');
233
+ continue;
234
+ }
228
235
 
229
236
  const sender = msg.key.remoteJid?.split('@')[0].split(':')[0];
230
237
  const allowedNumbers = config.whatsappAllowedNumbers || [];
@@ -239,30 +246,33 @@ async function startWhatsAppProvider(sessionDir, config) {
239
246
  msg.message?.extendedTextMessage?.text ||
240
247
  '';
241
248
 
242
- if (messageText) {
243
- const ownNumber = sock.user?.id?.split(':')[0].replace('@s.whatsapp.net', '') || 'unknown';
244
- log('whatsapp', `Inbound message +${sender} -> +${ownNumber}`, 'cyan');
245
- log('whatsapp', `Message: "${messageText.substring(0, 100)}${messageText.length > 100 ? '...' : ''}"`, 'gray');
249
+ if (!messageText) {
250
+ log('whatsapp', 'skipping message without text content', 'gray');
251
+ continue;
252
+ }
253
+
254
+ const ownNumber = sock.user?.id?.split(':')[0].replace('@s.whatsapp.net', '') || 'unknown';
255
+ log('whatsapp', `Inbound message +${sender} -> +${ownNumber} (${messageText.length} chars)`, 'cyan');
256
+ log('whatsapp', `Message: "${messageText.substring(0, 100)}${messageText.length > 100 ? '...' : ''}"`, 'gray');
257
+
258
+ try {
259
+ const { sendMessage } = require('../utils/api');
260
+ log('whatsapp', 'Sending to NatureCo API...', 'cyan');
246
261
 
247
- try {
248
- const { sendMessage } = require('../utils/api');
249
- log('whatsapp', 'Sending to NatureCo API...', 'cyan');
250
-
251
- const response = await sendMessage(config.apiKey, config.whatsappBotId, messageText, null, '');
252
- const reply = response?.reply || response?.message || '';
262
+ const response = await sendMessage(config.apiKey, config.whatsappBotId, messageText, null, '');
263
+ const reply = response?.reply || response?.message || '';
264
+
265
+ if (reply) {
266
+ log('whatsapp', `API response: "${reply.substring(0, 100)}${reply.length > 100 ? '...' : ''}"`, 'gray');
267
+ log('whatsapp', 'Sending reply...', 'cyan');
253
268
 
254
- if (reply) {
255
- log('whatsapp', `API response: "${reply.substring(0, 100)}${reply.length > 100 ? '...' : ''}"`, 'gray');
256
- log('whatsapp', 'Sending reply...', 'cyan');
257
-
258
- await sock.sendMessage(msg.key.remoteJid, { text: reply });
259
- log('whatsapp', `Reply sent (${reply.length} chars)`, 'green');
260
- } else {
261
- log('whatsapp', 'No reply from API', 'yellow');
262
- }
263
- } catch (err) {
264
- log('whatsapp', `API error: ${err.message}`, 'red');
269
+ await sock.sendMessage(msg.key.remoteJid, { text: reply });
270
+ log('whatsapp', `Reply sent (${reply.length} chars)`, 'green');
271
+ } else {
272
+ log('whatsapp', 'No reply from API', 'yellow');
265
273
  }
274
+ } catch (err) {
275
+ log('whatsapp', `API error: ${err.message}`, 'red');
266
276
  }
267
277
  }
268
278
  });
@@ -372,4 +382,9 @@ function showLogs() {
372
382
  console.log(logs);
373
383
  }
374
384
 
385
+ // Direkt çalıştırılınca worker olarak başlat
386
+ if (require.main === module || process.argv.includes('--gateway-worker')) {
387
+ gatewayServer('--gateway-worker');
388
+ }
389
+
375
390
  module.exports = gatewayServer;