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();
|
fechaVencimiento = getLastDayOfMonth();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Buscar tipo de publicación correspondiente (NOTICIA, EVENTO, CLASIFICADO)
|
// Mapeo seguro de tipo_publicacion_id requerido por el esquema de Appwrite
|
||||||
let tipoPublicacionId = '';
|
const DEFAULT_PUBLICATION_TYPES: Record<string, string> = {
|
||||||
|
noticia: '69c2b91400362d5d52b6',
|
||||||
|
evento: '69c2b9150030f3d1288c',
|
||||||
|
aviso: '69c2b916002aeec66684'
|
||||||
|
};
|
||||||
|
|
||||||
|
let tipoPublicacionId = DEFAULT_PUBLICATION_TYPES[parsed.tipo] || '69c2b91400362d5d52b6';
|
||||||
try {
|
try {
|
||||||
const types = await databases.listDocuments(
|
const types = await databases.listDocuments(
|
||||||
APPWRITE_ALMEIRA_CONFIG.databaseId,
|
APPWRITE_ALMEIRA_CONFIG.databaseId,
|
||||||
@ -290,7 +296,7 @@ export async function POST(req: Request) {
|
|||||||
tipoPublicacionId = matched.$id;
|
tipoPublicacionId = matched.$id;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} 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)
|
// 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),
|
titulo: truncateString(parsed.titulo, 70),
|
||||||
slug: generateSlug(parsed.titulo) + '-' + Date.now().toString().slice(-4),
|
slug: generateSlug(parsed.titulo) + '-' + Date.now().toString().slice(-4),
|
||||||
tipo: parsed.tipo,
|
tipo: parsed.tipo,
|
||||||
|
tipo_publicacion_id: tipoPublicacionId,
|
||||||
resumen_redes: truncateString(parsed.seo_descripcion, 155),
|
resumen_redes: truncateString(parsed.seo_descripcion, 155),
|
||||||
seo_titulo: truncateString(parsed.titulo, 60),
|
seo_titulo: truncateString(parsed.titulo, 60),
|
||||||
seo_descripcion: truncateString(parsed.seo_descripcion, 155),
|
seo_descripcion: truncateString(parsed.seo_descripcion, 155),
|
||||||
contenido: parsed.contenido,
|
contenido: parsed.contenido,
|
||||||
estado: 'borrador', // Requiere aprobación
|
estado: 'borrador', // Requiere aprobación
|
||||||
fecha_publicacion: new Date().toISOString(),
|
fecha_publicacion: new Date().toISOString(),
|
||||||
...(tipoPublicacionId && { tipo_publicacion_id: tipoPublicacionId }),
|
|
||||||
...(fechaVencimiento && { fecha_finalizacion: new Date(fechaVencimiento).toISOString() }),
|
...(fechaVencimiento && { fecha_finalizacion: new Date(fechaVencimiento).toISOString() }),
|
||||||
...(featuredMediaDocId && { imagen_destacada_id: featuredMediaDocId }),
|
...(featuredMediaDocId && { imagen_destacada_id: featuredMediaDocId }),
|
||||||
...(ogImageUrl && { og_image_url: ogImageUrl })
|
...(ogImageUrl && { og_image_url: ogImageUrl })
|
||||||
|
|||||||
@ -15,7 +15,7 @@ export async function sendWhatsAppMessage(numberId: string, text: string) {
|
|||||||
const response = await axios.post(url, {
|
const response = await axios.post(url, {
|
||||||
number: numberId,
|
number: numberId,
|
||||||
text: text
|
text: text
|
||||||
}, { headers });
|
}, { headers, timeout: 25000 });
|
||||||
|
|
||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user