feat(whatsapp): notificacion con Titular, Imagen destacada, Resumen y Contenido sin etiquetas
This commit is contained in:
parent
7ff2dd41fb
commit
f356cfbadd
@ -23,6 +23,27 @@ function truncateString(str: string, length: number): string {
|
|||||||
return str.length > length ? str.substring(0, length - 3) + '...' : str;
|
return str.length > length ? str.substring(0, length - 3) + '...' : str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function htmlToWhatsAppText(html: string): string {
|
||||||
|
if (!html) return '';
|
||||||
|
return html
|
||||||
|
.replace(/<strong[^>]*>(.*?)<\/strong>/gi, '*$1*')
|
||||||
|
.replace(/<b[^>]*>(.*?)<\/b>/gi, '*$1*')
|
||||||
|
.replace(/<em[^>]*>(.*?)<\/em>/gi, '_$1_')
|
||||||
|
.replace(/<i[^>]*>(.*?)<\/i>/gi, '_$1_')
|
||||||
|
.replace(/<li[^>]*>(.*?)<\/li>/gi, '• $1\n')
|
||||||
|
.replace(/<\/?(?:p|div|h[1-6]|ul|ol|table|tr|td)[^>]*>/gi, '\n')
|
||||||
|
.replace(/<br\s*\/?>/gi, '\n')
|
||||||
|
.replace(/<[^>]+>/g, '') // Eliminar cualquier etiqueta HTML remanente
|
||||||
|
.replace(/ /g, ' ')
|
||||||
|
.replace(/&/g, '&')
|
||||||
|
.replace(/"/g, '"')
|
||||||
|
.replace(/'/g, "'")
|
||||||
|
.replace(/</g, '<')
|
||||||
|
.replace(/>/g, '>')
|
||||||
|
.replace(/\n{3,}/g, '\n\n')
|
||||||
|
.trim();
|
||||||
|
}
|
||||||
|
|
||||||
export async function POST(req: Request) {
|
export async function POST(req: Request) {
|
||||||
try {
|
try {
|
||||||
const payload = await req.json();
|
const payload = await req.json();
|
||||||
@ -294,22 +315,24 @@ export async function POST(req: Request) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// Notificar al grupo de WhatsApp pidiendo aprobación explícita
|
// Formatear contenido limpio para WhatsApp (sin etiquetas HTML)
|
||||||
let imageNotice = '';
|
const cleanContent = htmlToWhatsAppText(parsed.contenido);
|
||||||
|
|
||||||
|
// Estado de la imagen destacada
|
||||||
|
let imageNotice = 'No se adjuntó imagen';
|
||||||
if (candidateMediaList.length > 1) {
|
if (candidateMediaList.length > 1) {
|
||||||
const chosenNum = (parsed.selected_image_index ?? 0) + 1;
|
const chosenNum = (parsed.selected_image_index ?? 0) + 1;
|
||||||
imageNotice = `🖼️ *Imagen Destacada:* Foto #${chosenNum} de ${candidateMediaList.length} analizadas`
|
imageNotice = `Foto #${chosenNum} de ${candidateMediaList.length} analizadas`
|
||||||
+ (parsed.image_selection_reason ? ` (${parsed.image_selection_reason})\n` : '\n');
|
+ (parsed.image_selection_reason ? ` (${parsed.image_selection_reason})` : '');
|
||||||
} else if (candidateMediaList.length === 1) {
|
} else if (candidateMediaList.length === 1) {
|
||||||
imageNotice = `🖼️ *Imagen Destacada:* 1 foto procesada (${isSquare ? 'Formato 640x640' : 'Formato 640x360'})\n`;
|
imageNotice = `1 foto procesada (${isSquare ? '640x640' : '640x360'})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestText = `🔔 *SOLICITUD DE APROBACIÓN DE PUBLICACIÓN* 🔔\n`
|
const requestText = `🔔 *SOLICITUD DE APROBACIÓN DE PUBLICACIÓN*\n\n`
|
||||||
+ `_Almeira Web • Asistente Editorial con IA_\n\n`
|
+ `📌 *Titular:*\n${parsed.titulo}\n\n`
|
||||||
+ `📌 *Título:* ${parsed.titulo}\n`
|
+ `🖼️ *Imagen Destacada:*\n${imageNotice}\n\n`
|
||||||
+ `📂 *Categoría:* ${parsed.tipo.toUpperCase()} (${isSquare ? 'Cuadrado 640x640' : 'Panorámico 640x360'})\n`
|
+ `📝 *Resumen:*\n${parsed.seo_descripcion}\n\n`
|
||||||
+ (imageNotice ? `${imageNotice}` : '')
|
+ `📄 *Contenido:*\n${cleanContent}\n\n`
|
||||||
+ `📝 *Resumen:* ${parsed.seo_descripcion}\n\n`
|
|
||||||
+ `━━━━━━━━━━━━━━━━━━━━━━\n`
|
+ `━━━━━━━━━━━━━━━━━━━━━━\n`
|
||||||
+ `¿Autorizas la publicación en el portal?\n\n`
|
+ `¿Autorizas la publicación en el portal?\n\n`
|
||||||
+ `👉 Responde a este mensaje con:\n`
|
+ `👉 Responde a este mensaje con:\n`
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user