Files
Cruces-GLM/Cruces_GLM_Reporte_Usuario_n8n.json
2026-08-20 14:19:35 -04:00

120 lines
7.7 KiB
JSON

{
"name": "Cruces GLM - Reporte de Usuario",
"nodes": [
{
"parameters": {
"httpMethod": "POST",
"path": "cruces-glm-reportar",
"responseMode": "responseNode",
"options": {
"allowedOrigins": "*"
}
},
"type": "n8n-nodes-base.webhook",
"typeVersion": 2.1,
"position": [
-520,
0
],
"id": "afc06b7b-4fb3-4ea2-997d-4656ede7e206",
"name": "Webhook - Reportar",
"webhookId": "0baf1e89-c6ee-4c05-805f-0a42c5cd6045"
},
{
"parameters": {
"jsCode": "const body = $json.body ?? {};\n\nconst clean = (value, fallback = \"\") => {\n const text = typeof value === \"string\" ? value.trim() : \"\";\n return text || fallback;\n};\n\nconst escapeHtml = (value) =>\n String(value)\n .replace(/&/g, \"&amp;\")\n .replace(/</g, \"&lt;\")\n .replace(/>/g, \"&gt;\")\n .replace(/\"/g, \"&quot;\")\n .replace(/'/g, \"&#039;\");\n\nconst userEmail = clean(body.userEmail, \"Usuario no identificado\");\nconst userName = clean(body.userName, userEmail);\nconst rawMessage = clean(body.message);\n\nif (!rawMessage) {\n throw new Error(\"El reporte llegó sin mensaje. No se enviará el correo.\");\n}\n\nconst message = rawMessage.slice(0, 5000);\nconst submittedAt = clean(body.submittedAt, new Date().toISOString());\n\nlet dateLabel = submittedAt;\ntry {\n dateLabel = new Intl.DateTimeFormat(\"es-DO\", {\n dateStyle: \"long\",\n timeStyle: \"short\",\n timeZone: \"America/Santo_Domingo\",\n }).format(new Date(submittedAt));\n} catch {}\n\nconst htmlMessage = escapeHtml(message).replace(/\\n/g, \"<br>\");\nconst safeName = escapeHtml(userName);\nconst safeEmail = escapeHtml(userEmail);\nconst safeDate = escapeHtml(dateLabel);\n\nconst html = `<!doctype html>\n<html lang=\"es\">\n<head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n</head>\n<body style=\"margin:0;padding:0;background:#F5F5F5;font-family:Arial,Helvetica,sans-serif;color:#4A4A4A;\">\n <table role=\"presentation\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" style=\"background:#F5F5F5;padding:28px 12px;\">\n <tr>\n <td align=\"center\">\n <table role=\"presentation\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" style=\"max-width:660px;background:#FFFFFF;border:1px solid #D0D0D0;\">\n <tr>\n <td style=\"height:4px;background:#6CC24A;font-size:0;line-height:0;\">&nbsp;</td>\n </tr>\n <tr>\n <td style=\"padding:30px 34px 10px 34px;\">\n <img src=\"https://dbit.digitalcompass.agency/storage/v1/object/public/public-assets/GLM_completo.png\" alt=\"GomezLee Marketing\" width=\"190\" style=\"display:block;width:190px;max-width:100%;height:auto;border:0;\">\n </td>\n </tr>\n <tr>\n <td style=\"padding:18px 34px 0 34px;\">\n <div style=\"font-size:11px;line-height:16px;font-weight:700;letter-spacing:1.5px;color:#6CC24A;text-transform:uppercase;\">CRUCES GLM · REPORTE DE USUARIO</div>\n <h1 style=\"margin:8px 0 0 0;font-size:24px;line-height:30px;color:#4F758B;font-weight:700;\">Nuevo reporte recibido</h1>\n <p style=\"margin:10px 0 0 0;font-size:14px;line-height:22px;color:#4A4A4A;\">Un usuario envió un reporte desde la aplicación Cruces GLM.</p>\n </td>\n </tr>\n <tr>\n <td style=\"padding:24px 34px 0 34px;\">\n <table role=\"presentation\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" style=\"border-collapse:collapse;font-size:13px;line-height:20px;\">\n <tr>\n <td style=\"width:125px;padding:9px 12px;background:#EEF6E8;border:1px solid #D0D0D0;font-weight:700;color:#4F758B;\">Usuario</td>\n <td style=\"padding:9px 12px;border:1px solid #D0D0D0;color:#4A4A4A;\">${safeName}</td>\n </tr>\n <tr>\n <td style=\"padding:9px 12px;background:#EEF6E8;border:1px solid #D0D0D0;font-weight:700;color:#4F758B;\">Correo</td>\n <td style=\"padding:9px 12px;border:1px solid #D0D0D0;color:#4A4A4A;\">${safeEmail}</td>\n </tr>\n <tr>\n <td style=\"padding:9px 12px;background:#EEF6E8;border:1px solid #D0D0D0;font-weight:700;color:#4F758B;\">Fecha</td>\n <td style=\"padding:9px 12px;border:1px solid #D0D0D0;color:#4A4A4A;\">${safeDate}</td>\n </tr>\n </table>\n </td>\n </tr>\n <tr>\n <td style=\"padding:24px 34px 0 34px;\">\n <div style=\"font-size:11px;line-height:16px;font-weight:700;letter-spacing:1px;color:#4F758B;text-transform:uppercase;border-bottom:2px solid #6CC24A;padding-bottom:7px;\">MENSAJE DEL USUARIO</div>\n <div style=\"margin-top:14px;padding:16px 18px;background:#F5F5F5;border:1px solid #D0D0D0;font-size:14px;line-height:22px;color:#4A4A4A;\">${htmlMessage}</div>\n </td>\n </tr>\n <tr>\n <td style=\"padding:28px 34px 30px 34px;\">\n <div style=\"border-top:1px solid #D0D0D0;padding-top:12px;font-size:11px;line-height:17px;font-style:italic;color:#6B8FA3;\">CONFIDENCIAL — Uso interno GomezLee Marketing · Mensaje generado automáticamente desde Cruces GLM.</div>\n </td>\n </tr>\n </table>\n </td>\n </tr>\n </table>\n</body>\n</html>`;\n\nreturn [{\n json: {\n to: \"iaracena@gomezleemarketing.com\",\n subject: `[Cruces GLM] Reporte de usuario - ${userName}`,\n html,\n userEmail,\n userName,\n message,\n submittedAt,\n },\n}];"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-260,
0
],
"id": "d02ea9a9-8bab-4389-beb6-67b6cb430968",
"name": "Preparar correo GLM"
},
{
"parameters": {
"sendTo": "={{ $json.to }}",
"subject": "={{ $json.subject }}",
"emailType": "html",
"message": "={{ $json.html }}",
"options": {
"appendAttribution": false,
"senderName": "Cruces GLM"
}
},
"type": "n8n-nodes-base.gmail",
"typeVersion": 2.1,
"position": [
0,
0
],
"id": "aedf8c14-992d-4c68-a8ed-d3fb82633b57",
"name": "Enviar a Isaac - Seleccionar credencial Gmail"
},
{
"parameters": {
"respondWith": "json",
"responseBody": "={{ { ok: true, message: 'Reporte enviado correctamente.' } }}",
"options": {
"responseCode": 200
}
},
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1.4,
"position": [
280,
0
],
"id": "6c112a4a-74e7-440d-92db-c0cb5d442bf4",
"name": "Responder OK"
}
],
"connections": {
"Preparar correo GLM": {
"main": [
[
{
"node": "Enviar a Isaac - Seleccionar credencial Gmail",
"type": "main",
"index": 0
}
]
]
},
"Enviar a Isaac - Seleccionar credencial Gmail": {
"main": [
[
{
"node": "Responder OK",
"type": "main",
"index": 0
}
]
]
},
"Webhook - Reportar": {
"main": [
[
{
"node": "Preparar correo GLM",
"type": "main",
"index": 0
}
]
]
}
},
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"active": false,
"versionId": "1237b5ba-d249-4b3e-b361-664fdc821f60",
"meta": {
"templateCredsSetupCompleted": false
},
"tags": []
}