From 694b320d7603c186cc08b3e06d1c16fed1269df8 Mon Sep 17 00:00:00 2001 From: AI Bot Date: Mon, 24 Aug 2026 10:09:00 -0500 Subject: [PATCH] fix(webhook): add missing tipo_publicacion_id for Appwrite validation --- src/app/api/webhooks/whatsapp/route.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/app/api/webhooks/whatsapp/route.ts b/src/app/api/webhooks/whatsapp/route.ts index eba2db0..a5e3d67 100644 --- a/src/app/api/webhooks/whatsapp/route.ts +++ b/src/app/api/webhooks/whatsapp/route.ts @@ -129,6 +129,21 @@ export async function POST(req: Request) { fechaVencimiento = getLastDayOfMonth(); } + // Buscar un tipo de publicación por defecto (Requerido por Appwrite Schema) + let tipoPublicacionId = ''; + try { + const types = await databases.listDocuments( + APPWRITE_ALMEIRA_CONFIG.databaseId, + APPWRITE_ALMEIRA_CONFIG.collections.publicationTypes, + [] + ); + if (types.documents.length > 0) { + tipoPublicacionId = types.documents[0].$id; + } + } catch (e) { + console.warn('No se pudo obtener un tipo de publicación por defecto:', e); + } + // Crear Post en Appwrite const newPost = await databases.createDocument( APPWRITE_ALMEIRA_CONFIG.databaseId, @@ -144,6 +159,7 @@ export async function POST(req: Request) { contenido: parsed.contenido, estado: 'borrador', // Se requiere aprobación fecha_publicacion: new Date().toISOString(), + ...(tipoPublicacionId && { tipo_publicacion_id: tipoPublicacionId }), ...(fechaVencimiento && { fecha_finalizacion: new Date(fechaVencimiento).toISOString() }), ...(imageId && { imagen_destacada_id: imageId }) }