natureco-cli 1.0.34 → 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 +1 -1
- package/src/commands/gateway-server.js +32 -22
package/package.json
CHANGED
|
@@ -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)
|
|
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
|
-
|
|
244
|
-
|
|
245
|
-
|
|
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
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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
|
});
|