simplifica un poco los logs para que no sean tan pesados de parsear

main
borja 3 months ago
parent 4bc78f476c
commit 3d87aead2c

@ -39,22 +39,23 @@ export class WebhookServer {
} }
if (process.env.NODE_ENV !== 'test') { if (process.env.NODE_ENV !== 'test') {
console.log(' Incoming webhook request:', { console.log(' Incoming webhook request:')
method: request.method, // console.log(' Incoming webhook request:', {
path: url.pathname, // method: request.method,
time: new Date().toISOString() // path: url.pathname,
}); // time: new Date().toISOString()
// });
} }
// 1. Method validation // 1. Method validation
if (request.method !== 'POST') { if (request.method !== 'POST') {
return new Response('Method not allowed', { status: 405 }); return new Response('🚫 Method not allowed', { status: 405 });
} }
// 2. Content-Type validation // 2. Content-Type validation
const contentType = request.headers.get('content-type'); const contentType = request.headers.get('content-type');
if (!contentType?.includes('application/json')) { if (!contentType?.includes('application/json')) {
return new Response('Invalid content type', { status: 400 }); return new Response('🚫 Invalid content type', { status: 400 });
} }
try { try {
@ -62,13 +63,13 @@ export class WebhookServer {
const payload = await request.json() as WebhookPayload; const payload = await request.json() as WebhookPayload;
if (!payload.event || !payload.instance) { if (!payload.event || !payload.instance) {
return new Response('Invalid payload', { status: 400 }); return new Response('🚫 Invalid payload', { status: 400 });
} }
// 4. Verify instance matches (skip in test environment unless TEST_VERIFY_INSTANCE is set) // 4. Verify instance matches (skip in test environment unless TEST_VERIFY_INSTANCE is set)
if ((process.env.NODE_ENV !== 'test' || process.env.TEST_VERIFY_INSTANCE) && if ((process.env.NODE_ENV !== 'test' || process.env.TEST_VERIFY_INSTANCE) &&
payload.instance !== process.env.EVOLUTION_API_INSTANCE) { payload.instance !== process.env.EVOLUTION_API_INSTANCE) {
return new Response('Invalid instance', { status: 403 }); return new Response('🚫 Invalid instance', { status: 403 });
} }
// 5. Route events // 5. Route events
@ -114,7 +115,7 @@ export class WebhookServer {
// Parse command components // Parse command components
const commandParts = messageText.trim().split(/\s+/); const commandParts = messageText.trim().split(/\s+/);
const command = commandParts[0].toLowerCase(); const command = commandParts[0].toLowerCase();
if (commandParts.length < 2) { if (commandParts.length < 2) {
console.log('⚠️ Invalid /tarea command - missing action'); console.log('⚠️ Invalid /tarea command - missing action');
return; return;
@ -123,7 +124,7 @@ export class WebhookServer {
const action = commandParts[1].toLowerCase(); const action = commandParts[1].toLowerCase();
let descriptionParts = []; let descriptionParts = [];
let dueDate = ''; let dueDate = '';
// Process remaining parts // Process remaining parts
for (let i = 2; i < commandParts.length; i++) { for (let i = 2; i < commandParts.length; i++) {
const part = commandParts[i]; const part = commandParts[i];
@ -132,7 +133,7 @@ export class WebhookServer {
const date = new Date(part); const date = new Date(part);
const today = new Date(); const today = new Date();
today.setHours(0, 0, 0, 0); today.setHours(0, 0, 0, 0);
if (date >= today) { if (date >= today) {
dueDate = part; dueDate = part;
} else { } else {

Loading…
Cancel
Save