fix(webhook): garantizar tipo_publicacion_id y timeouts de Evolution API
This commit is contained in:
parent
3c44471597
commit
67dc0d5d16
@ -274,8 +274,14 @@ export async function POST(req: Request) {
|
||||
fechaVencimiento = getLastDayOfMonth();
|
||||
}
|
||||
|
||||
// Buscar tipo de publicación correspondiente (NOTICIA, EVENTO, CLASIFICADO)
|
||||
let tipoPublicacionId = '';
|
||||
// Mapeo seguro de tipo_publicacion_id requerido por el esquema de Appwrite
|
||||
const DEFAULT_PUBLICATION_TYPES: Record<string, string> = {
|
||||
noticia: '69c2b91400362d5d52b6',
|
||||
evento: '69c2b9150030f3d1288c',
|
||||
aviso: '69c2b916002aeec66684'
|
||||
};
|
||||
|
||||
let tipoPublicacionId = DEFAULT_PUBLICATION_TYPES[parsed.tipo] || '69c2b91400362d5d52b6';
|
||||
try {
|
||||
const types = await databases.listDocuments(
|
||||
APPWRITE_ALMEIRA_CONFIG.databaseId,
|
||||
@ -290,7 +296,7 @@ export async function POST(req: Request) {
|
||||
tipoPublicacionId = matched.$id;
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('No se pudo obtener el tipo de publicación en Appwrite:', e);
|
||||
console.warn('No se pudo obtener el tipo de publicación en Appwrite, usando fallback:', e);
|
||||
}
|
||||
|
||||
// Crear Post en Appwrite (Vinculando la imagen destacada de la biblioteca de medios)
|
||||
@ -302,13 +308,13 @@ export async function POST(req: Request) {
|
||||
titulo: truncateString(parsed.titulo, 70),
|
||||
slug: generateSlug(parsed.titulo) + '-' + Date.now().toString().slice(-4),
|
||||
tipo: parsed.tipo,
|
||||
tipo_publicacion_id: tipoPublicacionId,
|
||||
resumen_redes: truncateString(parsed.seo_descripcion, 155),
|
||||
seo_titulo: truncateString(parsed.titulo, 60),
|
||||
seo_descripcion: truncateString(parsed.seo_descripcion, 155),
|
||||
contenido: parsed.contenido,
|
||||
estado: 'borrador', // Requiere aprobación
|
||||
fecha_publicacion: new Date().toISOString(),
|
||||
...(tipoPublicacionId && { tipo_publicacion_id: tipoPublicacionId }),
|
||||
...(fechaVencimiento && { fecha_finalizacion: new Date(fechaVencimiento).toISOString() }),
|
||||
...(featuredMediaDocId && { imagen_destacada_id: featuredMediaDocId }),
|
||||
...(ogImageUrl && { og_image_url: ogImageUrl })
|
||||
|
||||
@ -15,7 +15,7 @@ export async function sendWhatsAppMessage(numberId: string, text: string) {
|
||||
const response = await axios.post(url, {
|
||||
number: numberId,
|
||||
text: text
|
||||
}, { headers });
|
||||
}, { headers, timeout: 25000 });
|
||||
|
||||
return response.data;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user