1234 lines
51 KiB
JSON
1234 lines
51 KiB
JSON
{
|
|
"updatedAt": "2026-08-12T17:42:20.872Z",
|
|
"createdAt": "2026-07-24T19:13:05.914Z",
|
|
"id": "cFu3Xx23KQBKfr0M",
|
|
"name": "Seguimiento de Impuestos GLM - Recordatorios Gmail y Google Chat",
|
|
"description": null,
|
|
"active": true,
|
|
"isArchived": false,
|
|
"nodes": [
|
|
{
|
|
"parameters": {
|
|
"rule": {
|
|
"interval": [
|
|
{
|
|
"field": "cronExpression",
|
|
"expression": "0 8 * * *"
|
|
}
|
|
]
|
|
}
|
|
},
|
|
"type": "n8n-nodes-base.scheduleTrigger",
|
|
"typeVersion": 1.2,
|
|
"position": [
|
|
-352,
|
|
1920
|
|
],
|
|
"id": "0e8037b9-25e3-4fcb-9585-f11448a4b9bb",
|
|
"name": "Diario 8:00 AM"
|
|
},
|
|
{
|
|
"parameters": {},
|
|
"type": "n8n-nodes-base.manualTrigger",
|
|
"typeVersion": 1,
|
|
"position": [
|
|
-352,
|
|
2080
|
|
],
|
|
"id": "a63000b5-7dda-4c3a-98db-dd40064d4ed4",
|
|
"name": "Ejecutar manualmente"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"httpMethod": "POST",
|
|
"path": "seguimiento-impuestos",
|
|
"options": {}
|
|
},
|
|
"type": "n8n-nodes-base.webhook",
|
|
"typeVersion": 2.1,
|
|
"position": [
|
|
-352,
|
|
2272
|
|
],
|
|
"id": "ae941003-35ae-47a8-8e81-a9db92140e62",
|
|
"name": "Webhook seguimiento-impuestos",
|
|
"webhookId": "seguimiento-impuestos-glm"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"jsCode": "function dateInTimeZone(timeZone) {\n const parts = new Intl.DateTimeFormat('en-US', {\n timeZone,\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n }).formatToParts(new Date());\n const values = Object.fromEntries(parts.map((part) => [part.type, part.value]));\n return `${values.year}-${values.month}-${values.day}`;\n}\n\nconst input = $json ?? {};\nconst runDate = input.run_date || dateInTimeZone('America/Santo_Domingo');\n\nreturn [{\n json: {\n run_date: runDate,\n source: input.source || 'schedule',\n },\n}];"
|
|
},
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 2,
|
|
"position": [
|
|
-96,
|
|
2000
|
|
],
|
|
"id": "9dc0b144-b6e2-4238-8786-7bb418778bc1",
|
|
"name": "Preparar ejecución"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"jsCode": "const body = $json.body ?? $json;\nconst action = String(body.action ?? '').trim().toLowerCase();\n\nif (!['run_now', 'run_reminders', 'ejecutar_recordatorios'].includes(action)) {\n return [];\n}\n\nreturn [{\n json: {\n run_date: body.run_date || body.date || '',\n source: 'webhook',\n },\n}];"
|
|
},
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 2,
|
|
"position": [
|
|
-96,
|
|
2272
|
|
],
|
|
"id": "0b7ce2a9-6759-4eb7-9614-9ea588a27290",
|
|
"name": "Validar ejecución por Webhook"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"method": "POST",
|
|
"url": "https://dbit.digitalcompass.agency/rest/v1/rpc/tax_due_reminders",
|
|
"sendHeaders": true,
|
|
"headerParameters": {
|
|
"parameters": [
|
|
{
|
|
"name": "apikey",
|
|
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q"
|
|
},
|
|
{
|
|
"name": "Authorization",
|
|
"value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q"
|
|
},
|
|
{
|
|
"name": "Content-Type",
|
|
"value": "application/json"
|
|
}
|
|
]
|
|
},
|
|
"sendBody": true,
|
|
"specifyBody": "json",
|
|
"jsonBody": "={{ { p_run_date: $json.run_date } }}",
|
|
"options": {}
|
|
},
|
|
"type": "n8n-nodes-base.httpRequest",
|
|
"typeVersion": 4.4,
|
|
"position": [
|
|
160,
|
|
2080
|
|
],
|
|
"id": "9e198092-e114-491c-9672-048fa0ad5d2b",
|
|
"name": "Supabase - Recordatorios pendientes"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"jsCode": "const htmlEscape = (value) => String(value ?? '')\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"')\n .replace(/'/g, ''');\n\nconst rows = [];\nfor (const item of $input.all()) {\n const value = item.json;\n if (Array.isArray(value)) rows.push(...value);\n else if (Array.isArray(value?.data)) rows.push(...value.data);\n else if (Array.isArray(value?.body)) rows.push(...value.body);\n else if (value?.obligation_id) rows.push(value);\n}\n\nconst logoUrl = 'https://dbit.digitalcompass.agency/storage/v1/object/public/public-assets/GLM_completo.png';\nconst appUrl = 'https://digitalcompass.agency/calendario-impuestos/';\n\nconst formatDate = (iso) => {\n const [year, month, day] = String(iso).split('-').map(Number);\n return new Intl.DateTimeFormat('es-DO', {\n timeZone: 'UTC',\n day: '2-digit',\n month: 'long',\n year: 'numeric',\n }).format(new Date(Date.UTC(year, month - 1, day)));\n};\n\nreturn rows.map((row) => {\n const dueDate = formatDate(row.due_date);\n const isSameDay = row.alert_type === 'same_day';\n const reminderLabel = isSameDay ? 'Vence hoy' : 'Recordatorio previo';\n const categoryLabel = row.category === 'nomina' ? 'Nómina' : 'Administración';\n const firstName = String(row.contact_name ?? '').trim().split(/\\s+/)[0] || 'equipo';\n const subject = `${isSameDay ? 'Vence hoy' : 'Recordatorio'} · ${row.country_name} · ${row.description}`;\n\n const emailHtml = `\n<!doctype html>\n<html lang=\"es\">\n <body style=\"margin:0;padding:0;background:#F5F5F5;font-family:Arial,sans-serif;color:#4A4A4A;\">\n <table role=\"presentation\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" style=\"background:#F5F5F5;padding:28px 12px;\">\n <tr><td align=\"center\">\n <table role=\"presentation\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" style=\"max-width:640px;background:#FFFFFF;border:1px solid #D0D0D0;border-radius:14px;overflow:hidden;\">\n <tr><td style=\"padding:26px 30px 18px;\"><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;\"></td></tr>\n <tr><td style=\"height:5px;background:#6CC24A;font-size:0;line-height:0;\"> </td></tr>\n <tr><td style=\"padding:30px;\">\n <div style=\"font-size:12px;font-weight:700;letter-spacing:1.4px;text-transform:uppercase;color:#6CC24A;\">${htmlEscape(reminderLabel)}</div>\n <h1 style=\"margin:8px 0 10px;font-size:27px;line-height:1.18;color:#4F758B;\">Seguimiento de Impuestos GLM</h1>\n <p style=\"margin:0 0 24px;font-size:15px;line-height:1.6;\">Hola ${htmlEscape(firstName)}, este es el recordatorio correspondiente a la siguiente obligación tributaria:</p>\n <table role=\"presentation\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" style=\"border-collapse:collapse;border:1px solid #D0D0D0;\">\n <tr><td style=\"width:34%;padding:12px 14px;background:#EEF6E8;border-bottom:1px solid #D0D0D0;font-size:13px;font-weight:700;color:#4F758B;\">País</td><td style=\"padding:12px 14px;border-bottom:1px solid #D0D0D0;font-size:13px;\">${htmlEscape(row.country_name)}</td></tr>\n <tr><td style=\"padding:12px 14px;background:#EEF6E8;border-bottom:1px solid #D0D0D0;font-size:13px;font-weight:700;color:#4F758B;\">Categoría</td><td style=\"padding:12px 14px;border-bottom:1px solid #D0D0D0;font-size:13px;\">${htmlEscape(categoryLabel)}</td></tr>\n <tr><td style=\"padding:12px 14px;background:#EEF6E8;border-bottom:1px solid #D0D0D0;font-size:13px;font-weight:700;color:#4F758B;\">Fecha límite</td><td style=\"padding:12px 14px;border-bottom:1px solid #D0D0D0;font-size:13px;font-weight:700;color:#FF6A13;\">${htmlEscape(dueDate)}</td></tr>\n <tr><td style=\"padding:12px 14px;background:#EEF6E8;font-size:13px;font-weight:700;color:#4F758B;\">Obligación</td><td style=\"padding:12px 14px;font-size:13px;line-height:1.5;\">${htmlEscape(row.description)}</td></tr>\n </table>\n <p style=\"margin:22px 0 0;font-size:12px;line-height:1.55;color:#6B8FA3;\">Este aviso forma parte del seguimiento automático: miércoles anterior y fecha límite, incluidos sábados y domingos.</p>\n <div style=\"margin-top:24px;\"><a href=\"${htmlEscape(appUrl)}\" style=\"display:inline-block;background:#6CC24A;color:#FFFFFF;text-decoration:none;font-size:13px;font-weight:700;padding:11px 17px;border-radius:8px;\">Abrir calendario</a></div>\n </td></tr>\n <tr><td style=\"padding:16px 30px;border-top:1px solid #D0D0D0;font-size:11px;color:#6B8FA3;\">GOMEZLEE MARKETING | Seguimiento de Impuestos GLM | Uso interno</td></tr>\n </table>\n </td></tr>\n </table>\n </body>\n</html>`.trim();\n\n const googleChatText = [\n `*${reminderLabel.toUpperCase()} · SEGUIMIENTO DE IMPUESTOS GLM*`,\n '',\n `Hola ${firstName},`,\n '',\n `*País:* ${row.country_name}`,\n `*Categoría:* ${categoryLabel}`,\n `*Fecha límite:* ${dueDate}`,\n `*Obligación:* ${row.description}`,\n '',\n 'Seguimiento automático: miércoles anterior y fecha límite, incluidos sábados y domingos.',\n '',\n `Abrir calendario: ${appUrl}`,\n ].join('\\n');\n\n return {\n json: {\n ...row,\n email_subject: subject,\n email_html: emailHtml,\n google_chat_text: googleChatText,\n },\n };\n});"
|
|
},
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 2,
|
|
"position": [
|
|
416,
|
|
2080
|
|
],
|
|
"id": "c19543d0-6e85-4ed7-903a-1d254553cf49",
|
|
"name": "Construir mensajes GLM"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"jsCode": "return $input.all().filter((item) => item.json.email_enabled === true && String(item.json.contact_email ?? '').trim());"
|
|
},
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 2,
|
|
"position": [
|
|
688,
|
|
1936
|
|
],
|
|
"id": "e923e3bc-02d7-4402-8ca4-4138f2db3cd2",
|
|
"name": "Preparar correos"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"sendTo": "={{ $json.contact_email }}",
|
|
"subject": "={{ $json.email_subject }}",
|
|
"message": "={{ $json.email_html }}",
|
|
"options": {
|
|
"appendAttribution": false
|
|
}
|
|
},
|
|
"type": "n8n-nodes-base.gmail",
|
|
"typeVersion": 2.1,
|
|
"position": [
|
|
944,
|
|
1936
|
|
],
|
|
"id": "084ac77b-6f26-41c8-ab55-8d0989f81fb8",
|
|
"name": "Gmail - Enviar recordatorio",
|
|
"webhookId": "16bfebbd-f4e3-4b1e-aba2-028fecf98da1",
|
|
"credentials": {
|
|
"gmailOAuth2": {
|
|
"id": "UDcO1FLJqA453V2D",
|
|
"name": "Gmail account 3"
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"parameters": {
|
|
"method": "POST",
|
|
"url": "https://dbit.digitalcompass.agency/rest/v1/rpc/tax_record_notification",
|
|
"sendHeaders": true,
|
|
"headerParameters": {
|
|
"parameters": [
|
|
{
|
|
"name": "apikey",
|
|
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q"
|
|
},
|
|
{
|
|
"name": "Authorization",
|
|
"value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q"
|
|
},
|
|
{
|
|
"name": "Content-Type",
|
|
"value": "application/json"
|
|
}
|
|
]
|
|
},
|
|
"sendBody": true,
|
|
"specifyBody": "json",
|
|
"jsonBody": "={{ { p_obligation_id: $('Preparar correos').item.json.obligation_id, p_contact_id: $('Preparar correos').item.json.contact_id, p_alert_date: $('Preparar correos').item.json.alert_date, p_channel: 'email', p_status: 'sent', p_provider_response: $json } }}",
|
|
"options": {}
|
|
},
|
|
"type": "n8n-nodes-base.httpRequest",
|
|
"typeVersion": 4.4,
|
|
"position": [
|
|
1200,
|
|
1936
|
|
],
|
|
"id": "ce69dcd5-c9ae-4770-9797-a9fff667a7ba",
|
|
"name": "Supabase - Registrar correo"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"jsCode": "const CALLING_USER_EMAIL = 'iaracena@gomezleemarketing.com';\n\nreturn $input.all().filter((item) => {\n const enabled = item.json.google_chat_enabled === true;\n const email = String(item.json.contact_email ?? '').trim().toLowerCase();\n\n return enabled && email && email !== CALLING_USER_EMAIL;\n});"
|
|
},
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 2,
|
|
"position": [
|
|
688,
|
|
2208
|
|
],
|
|
"id": "a02e0bac-f208-491d-8257-83dc91fe5dd4",
|
|
"name": "Preparar Google Chat"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"method": "POST",
|
|
"url": "https://chat.googleapis.com/v1/spaces:setup",
|
|
"authentication": "predefinedCredentialType",
|
|
"nodeCredentialType": "googleChatOAuth2Api",
|
|
"sendHeaders": true,
|
|
"headerParameters": {
|
|
"parameters": [
|
|
{
|
|
"name": "Content-Type",
|
|
"value": "application/json"
|
|
}
|
|
]
|
|
},
|
|
"sendBody": true,
|
|
"specifyBody": "json",
|
|
"jsonBody": "={{ { space: { spaceType: 'DIRECT_MESSAGE', singleUserBotDm: false }, memberships: [ { member: { name: 'users/' + $json.contact_email, type: 'HUMAN' } } ] } }}",
|
|
"options": {
|
|
"timeout": 30000
|
|
}
|
|
},
|
|
"type": "n8n-nodes-base.httpRequest",
|
|
"typeVersion": 4.4,
|
|
"position": [
|
|
944,
|
|
2208
|
|
],
|
|
"id": "290d682a-55cf-411b-82f4-6e573fadaf9d",
|
|
"name": "Google Chat - Abrir DM",
|
|
"retryOnFail": true,
|
|
"maxTries": 3,
|
|
"waitBetweenTries": 1500,
|
|
"credentials": {
|
|
"googleChatOAuth2Api": {
|
|
"id": "8UR1kLTQ4SDHgfaZ",
|
|
"name": "Google Chat - Seguimiento de Impuestos GLM"
|
|
}
|
|
},
|
|
"onError": "continueRegularOutput"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"jsCode": "const responses = $input.all();\nconst sources = $('Preparar Google Chat').all();\n\nreturn responses.map((item, index) => {\n const source = sources[index]?.json ?? {};\n const response = item.json ?? {};\n const spaceName = String(response.name ?? '').trim();\n const ok = Boolean(spaceName) && !response.error;\n\n return {\n json: {\n ...source,\n chat_space_name: spaceName,\n chat_setup_ok: ok,\n google_chat_status: ok ? 'pending' : 'failed',\n google_chat_provider_response: response,\n },\n pairedItem: { item: index },\n };\n});"
|
|
},
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 2,
|
|
"position": [
|
|
1200,
|
|
2208
|
|
],
|
|
"id": "04d40a89-5b44-441f-ae5b-e681c480820e",
|
|
"name": "Evaluar DM Google Chat"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"jsCode": "return $input.all().filter((item) => item.json.chat_setup_ok === true);"
|
|
},
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 2,
|
|
"position": [
|
|
1456,
|
|
2096
|
|
],
|
|
"id": "1ab28b37-2d73-4471-ae52-c62163c4d9f0",
|
|
"name": "Preparar envío Google Chat"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"jsCode": "return $input.all().filter((item) => item.json.chat_setup_ok !== true);"
|
|
},
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 2,
|
|
"position": [
|
|
1456,
|
|
2352
|
|
],
|
|
"id": "fdd96034-cd48-427a-acda-3ac249eb3f31",
|
|
"name": "Preparar fallo DM Google Chat"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"method": "POST",
|
|
"url": "={{ 'https://chat.googleapis.com/v1/' + $json.chat_space_name + '/messages' }}",
|
|
"authentication": "predefinedCredentialType",
|
|
"nodeCredentialType": "googleChatOAuth2Api",
|
|
"sendHeaders": true,
|
|
"headerParameters": {
|
|
"parameters": [
|
|
{
|
|
"name": "Content-Type",
|
|
"value": "application/json"
|
|
}
|
|
]
|
|
},
|
|
"sendBody": true,
|
|
"specifyBody": "json",
|
|
"jsonBody": "={{ { text: $json.google_chat_text } }}",
|
|
"options": {
|
|
"timeout": 30000
|
|
}
|
|
},
|
|
"type": "n8n-nodes-base.httpRequest",
|
|
"typeVersion": 4.4,
|
|
"position": [
|
|
1712,
|
|
2096
|
|
],
|
|
"id": "2f510b09-4bb1-4dcb-863b-9d863868750b",
|
|
"name": "Google Chat - Enviar recordatorio",
|
|
"retryOnFail": true,
|
|
"maxTries": 3,
|
|
"waitBetweenTries": 1500,
|
|
"credentials": {
|
|
"googleChatOAuth2Api": {
|
|
"id": "8UR1kLTQ4SDHgfaZ",
|
|
"name": "Google Chat - Seguimiento de Impuestos GLM"
|
|
}
|
|
},
|
|
"onError": "continueRegularOutput"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"jsCode": "const responses = $input.all();\nconst sources = $('Preparar envío Google Chat').all();\n\nreturn responses.map((item, index) => {\n const source = sources[index]?.json ?? {};\n const response = item.json ?? {};\n const sent = Boolean(response.name) && !response.error;\n\n return {\n json: {\n ...source,\n google_chat_status: sent ? 'sent' : 'failed',\n google_chat_provider_response: response,\n },\n pairedItem: { item: index },\n };\n});"
|
|
},
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 2,
|
|
"position": [
|
|
1968,
|
|
2096
|
|
],
|
|
"id": "93094ae5-5e9b-4e42-9a9b-5ed9213943e3",
|
|
"name": "Evaluar envío Google Chat"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"method": "POST",
|
|
"url": "https://dbit.digitalcompass.agency/rest/v1/rpc/tax_record_notification",
|
|
"sendHeaders": true,
|
|
"headerParameters": {
|
|
"parameters": [
|
|
{
|
|
"name": "apikey",
|
|
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q"
|
|
},
|
|
{
|
|
"name": "Authorization",
|
|
"value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q"
|
|
},
|
|
{
|
|
"name": "Content-Type",
|
|
"value": "application/json"
|
|
}
|
|
]
|
|
},
|
|
"sendBody": true,
|
|
"specifyBody": "json",
|
|
"jsonBody": "={{ { p_obligation_id: $json.obligation_id, p_contact_id: $json.contact_id, p_alert_date: $json.alert_date, p_channel: 'google_chat', p_status: $json.google_chat_status, p_provider_response: $json.google_chat_provider_response } }}",
|
|
"options": {}
|
|
},
|
|
"type": "n8n-nodes-base.httpRequest",
|
|
"typeVersion": 4.4,
|
|
"position": [
|
|
2224,
|
|
2208
|
|
],
|
|
"id": "db27cf44-56e0-4544-90dd-d81bc0d4bd7d",
|
|
"name": "Supabase - Registrar Google Chat"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"content": "## RECORDATORIOS DE IMPUESTOS POR GMAIL Y GOOGLE CHAT\n\nEjecuta diariamente el proceso de recordatorios fiscales y notifica a los contactos correspondientes por correo electrónico y mensaje directo de Google Chat.\n\n- Puede iniciarse automáticamente a las 8:00 a. m., manualmente o desde el webhook de la aplicación.\n- Consulta en Supabase las obligaciones que requieren recordatorio y sus destinatarios.\n- Construye mensajes personalizados con el formato corporativo de GLM.\n- Envía los recordatorios por Gmail al correo de cada contacto y registra el resultado.\n- Abre o reutiliza el DM del destinatario en Google Chat mediante `spaces:setup`.\n- Conserva todos los items de Google Chat de principio a fin; no colapsa múltiples destinatarios en uno solo.\n- Envía texto con `spaces.messages.create` usando un body válido `{ text: ... }`.\n- Omite el correo del propio usuario autenticado de Google Chat, porque Google agrega automáticamente al calling user y no permite especificarlo como membership.\n- Evalúa cada intento individualmente y registra éxitos o errores en Supabase.",
|
|
"height": 1184,
|
|
"width": 2880,
|
|
"color": "#204750"
|
|
},
|
|
"type": "n8n-nodes-base.stickyNote",
|
|
"typeVersion": 1,
|
|
"position": [
|
|
-464,
|
|
1360
|
|
],
|
|
"id": "3ee2b7ce-eff0-4d62-b80d-f4df454e91df",
|
|
"name": "Sticky Note"
|
|
}
|
|
],
|
|
"connections": {
|
|
"Diario 8:00 AM": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Preparar ejecución",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Ejecutar manualmente": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Preparar ejecución",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Webhook seguimiento-impuestos": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Validar ejecución por Webhook",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Preparar ejecución": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Supabase - Recordatorios pendientes",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Validar ejecución por Webhook": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Preparar ejecución",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Supabase - Recordatorios pendientes": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Construir mensajes GLM",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Construir mensajes GLM": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Preparar correos",
|
|
"type": "main",
|
|
"index": 0
|
|
},
|
|
{
|
|
"node": "Preparar Google Chat",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Preparar correos": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Gmail - Enviar recordatorio",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Gmail - Enviar recordatorio": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Supabase - Registrar correo",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Preparar Google Chat": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Google Chat - Abrir DM",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Google Chat - Abrir DM": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Evaluar DM Google Chat",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Evaluar DM Google Chat": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Preparar envío Google Chat",
|
|
"type": "main",
|
|
"index": 0
|
|
},
|
|
{
|
|
"node": "Preparar fallo DM Google Chat",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Preparar envío Google Chat": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Google Chat - Enviar recordatorio",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Google Chat - Enviar recordatorio": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Evaluar envío Google Chat",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Evaluar envío Google Chat": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Supabase - Registrar Google Chat",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Preparar fallo DM Google Chat": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Supabase - Registrar Google Chat",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
}
|
|
},
|
|
"settings": {
|
|
"executionOrder": "v1",
|
|
"binaryMode": "separate",
|
|
"availableInMCP": true,
|
|
"timeSavedMode": "fixed",
|
|
"errorWorkflow": "puF4LUczoSz3hcek",
|
|
"timezone": "America/Santo_Domingo",
|
|
"callerPolicy": "workflowsFromSameOwner"
|
|
},
|
|
"staticData": {
|
|
"node:Diario 8:00 AM": {
|
|
"recurrenceRules": []
|
|
}
|
|
},
|
|
"meta": {
|
|
"templateCredsSetupCompleted": true
|
|
},
|
|
"versionId": "0ebbe45e-f485-4abc-8de3-5f5b05857edf",
|
|
"activeVersionId": "0ebbe45e-f485-4abc-8de3-5f5b05857edf",
|
|
"versionCounter": 121,
|
|
"triggerCount": 2,
|
|
"shared": [
|
|
{
|
|
"updatedAt": "2026-07-24T19:13:05.942Z",
|
|
"createdAt": "2026-07-24T19:13:05.942Z",
|
|
"role": "workflow:owner",
|
|
"workflowId": "cFu3Xx23KQBKfr0M",
|
|
"projectId": "PJpTANzTXIFibWsW",
|
|
"project": {
|
|
"updatedAt": "2026-04-22T14:25:09.686Z",
|
|
"createdAt": "2026-04-22T14:22:54.790Z",
|
|
"id": "PJpTANzTXIFibWsW",
|
|
"name": "Isaac Aracena <iaracena@gomezleemarketing.com>",
|
|
"type": "personal",
|
|
"icon": null,
|
|
"description": null,
|
|
"creatorId": "0a88c0b1-928e-4412-896e-c5d1c99b2029"
|
|
}
|
|
}
|
|
],
|
|
"tags": [],
|
|
"activeVersion": {
|
|
"updatedAt": "2026-08-12T17:42:42.000Z",
|
|
"createdAt": "2026-08-12T17:42:20.874Z",
|
|
"versionId": "0ebbe45e-f485-4abc-8de3-5f5b05857edf",
|
|
"workflowId": "cFu3Xx23KQBKfr0M",
|
|
"nodes": [
|
|
{
|
|
"parameters": {
|
|
"rule": {
|
|
"interval": [
|
|
{
|
|
"field": "cronExpression",
|
|
"expression": "0 8 * * *"
|
|
}
|
|
]
|
|
}
|
|
},
|
|
"type": "n8n-nodes-base.scheduleTrigger",
|
|
"typeVersion": 1.2,
|
|
"position": [
|
|
-352,
|
|
1920
|
|
],
|
|
"id": "0e8037b9-25e3-4fcb-9585-f11448a4b9bb",
|
|
"name": "Diario 8:00 AM"
|
|
},
|
|
{
|
|
"parameters": {},
|
|
"type": "n8n-nodes-base.manualTrigger",
|
|
"typeVersion": 1,
|
|
"position": [
|
|
-352,
|
|
2080
|
|
],
|
|
"id": "a63000b5-7dda-4c3a-98db-dd40064d4ed4",
|
|
"name": "Ejecutar manualmente"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"httpMethod": "POST",
|
|
"path": "seguimiento-impuestos",
|
|
"options": {}
|
|
},
|
|
"type": "n8n-nodes-base.webhook",
|
|
"typeVersion": 2.1,
|
|
"position": [
|
|
-352,
|
|
2272
|
|
],
|
|
"id": "ae941003-35ae-47a8-8e81-a9db92140e62",
|
|
"name": "Webhook seguimiento-impuestos",
|
|
"webhookId": "seguimiento-impuestos-glm"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"jsCode": "function dateInTimeZone(timeZone) {\n const parts = new Intl.DateTimeFormat('en-US', {\n timeZone,\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n }).formatToParts(new Date());\n const values = Object.fromEntries(parts.map((part) => [part.type, part.value]));\n return `${values.year}-${values.month}-${values.day}`;\n}\n\nconst input = $json ?? {};\nconst runDate = input.run_date || dateInTimeZone('America/Santo_Domingo');\n\nreturn [{\n json: {\n run_date: runDate,\n source: input.source || 'schedule',\n },\n}];"
|
|
},
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 2,
|
|
"position": [
|
|
-96,
|
|
2000
|
|
],
|
|
"id": "9dc0b144-b6e2-4238-8786-7bb418778bc1",
|
|
"name": "Preparar ejecución"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"jsCode": "const body = $json.body ?? $json;\nconst action = String(body.action ?? '').trim().toLowerCase();\n\nif (!['run_now', 'run_reminders', 'ejecutar_recordatorios'].includes(action)) {\n return [];\n}\n\nreturn [{\n json: {\n run_date: body.run_date || body.date || '',\n source: 'webhook',\n },\n}];"
|
|
},
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 2,
|
|
"position": [
|
|
-96,
|
|
2272
|
|
],
|
|
"id": "0b7ce2a9-6759-4eb7-9614-9ea588a27290",
|
|
"name": "Validar ejecución por Webhook"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"method": "POST",
|
|
"url": "https://dbit.digitalcompass.agency/rest/v1/rpc/tax_due_reminders",
|
|
"sendHeaders": true,
|
|
"headerParameters": {
|
|
"parameters": [
|
|
{
|
|
"name": "apikey",
|
|
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q"
|
|
},
|
|
{
|
|
"name": "Authorization",
|
|
"value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q"
|
|
},
|
|
{
|
|
"name": "Content-Type",
|
|
"value": "application/json"
|
|
}
|
|
]
|
|
},
|
|
"sendBody": true,
|
|
"specifyBody": "json",
|
|
"jsonBody": "={{ { p_run_date: $json.run_date } }}",
|
|
"options": {}
|
|
},
|
|
"type": "n8n-nodes-base.httpRequest",
|
|
"typeVersion": 4.4,
|
|
"position": [
|
|
160,
|
|
2080
|
|
],
|
|
"id": "9e198092-e114-491c-9672-048fa0ad5d2b",
|
|
"name": "Supabase - Recordatorios pendientes"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"jsCode": "const htmlEscape = (value) => String(value ?? '')\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"')\n .replace(/'/g, ''');\n\nconst rows = [];\nfor (const item of $input.all()) {\n const value = item.json;\n if (Array.isArray(value)) rows.push(...value);\n else if (Array.isArray(value?.data)) rows.push(...value.data);\n else if (Array.isArray(value?.body)) rows.push(...value.body);\n else if (value?.obligation_id) rows.push(value);\n}\n\nconst logoUrl = 'https://dbit.digitalcompass.agency/storage/v1/object/public/public-assets/GLM_completo.png';\nconst appUrl = 'https://digitalcompass.agency/calendario-impuestos/';\n\nconst formatDate = (iso) => {\n const [year, month, day] = String(iso).split('-').map(Number);\n return new Intl.DateTimeFormat('es-DO', {\n timeZone: 'UTC',\n day: '2-digit',\n month: 'long',\n year: 'numeric',\n }).format(new Date(Date.UTC(year, month - 1, day)));\n};\n\nreturn rows.map((row) => {\n const dueDate = formatDate(row.due_date);\n const isSameDay = row.alert_type === 'same_day';\n const reminderLabel = isSameDay ? 'Vence hoy' : 'Recordatorio previo';\n const categoryLabel = row.category === 'nomina' ? 'Nómina' : 'Administración';\n const firstName = String(row.contact_name ?? '').trim().split(/\\s+/)[0] || 'equipo';\n const subject = `${isSameDay ? 'Vence hoy' : 'Recordatorio'} · ${row.country_name} · ${row.description}`;\n\n const emailHtml = `\n<!doctype html>\n<html lang=\"es\">\n <body style=\"margin:0;padding:0;background:#F5F5F5;font-family:Arial,sans-serif;color:#4A4A4A;\">\n <table role=\"presentation\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" style=\"background:#F5F5F5;padding:28px 12px;\">\n <tr><td align=\"center\">\n <table role=\"presentation\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" style=\"max-width:640px;background:#FFFFFF;border:1px solid #D0D0D0;border-radius:14px;overflow:hidden;\">\n <tr><td style=\"padding:26px 30px 18px;\"><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;\"></td></tr>\n <tr><td style=\"height:5px;background:#6CC24A;font-size:0;line-height:0;\"> </td></tr>\n <tr><td style=\"padding:30px;\">\n <div style=\"font-size:12px;font-weight:700;letter-spacing:1.4px;text-transform:uppercase;color:#6CC24A;\">${htmlEscape(reminderLabel)}</div>\n <h1 style=\"margin:8px 0 10px;font-size:27px;line-height:1.18;color:#4F758B;\">Seguimiento de Impuestos GLM</h1>\n <p style=\"margin:0 0 24px;font-size:15px;line-height:1.6;\">Hola ${htmlEscape(firstName)}, este es el recordatorio correspondiente a la siguiente obligación tributaria:</p>\n <table role=\"presentation\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" style=\"border-collapse:collapse;border:1px solid #D0D0D0;\">\n <tr><td style=\"width:34%;padding:12px 14px;background:#EEF6E8;border-bottom:1px solid #D0D0D0;font-size:13px;font-weight:700;color:#4F758B;\">País</td><td style=\"padding:12px 14px;border-bottom:1px solid #D0D0D0;font-size:13px;\">${htmlEscape(row.country_name)}</td></tr>\n <tr><td style=\"padding:12px 14px;background:#EEF6E8;border-bottom:1px solid #D0D0D0;font-size:13px;font-weight:700;color:#4F758B;\">Categoría</td><td style=\"padding:12px 14px;border-bottom:1px solid #D0D0D0;font-size:13px;\">${htmlEscape(categoryLabel)}</td></tr>\n <tr><td style=\"padding:12px 14px;background:#EEF6E8;border-bottom:1px solid #D0D0D0;font-size:13px;font-weight:700;color:#4F758B;\">Fecha límite</td><td style=\"padding:12px 14px;border-bottom:1px solid #D0D0D0;font-size:13px;font-weight:700;color:#FF6A13;\">${htmlEscape(dueDate)}</td></tr>\n <tr><td style=\"padding:12px 14px;background:#EEF6E8;font-size:13px;font-weight:700;color:#4F758B;\">Obligación</td><td style=\"padding:12px 14px;font-size:13px;line-height:1.5;\">${htmlEscape(row.description)}</td></tr>\n </table>\n <p style=\"margin:22px 0 0;font-size:12px;line-height:1.55;color:#6B8FA3;\">Este aviso forma parte del seguimiento automático: miércoles anterior y fecha límite, incluidos sábados y domingos.</p>\n <div style=\"margin-top:24px;\"><a href=\"${htmlEscape(appUrl)}\" style=\"display:inline-block;background:#6CC24A;color:#FFFFFF;text-decoration:none;font-size:13px;font-weight:700;padding:11px 17px;border-radius:8px;\">Abrir calendario</a></div>\n </td></tr>\n <tr><td style=\"padding:16px 30px;border-top:1px solid #D0D0D0;font-size:11px;color:#6B8FA3;\">GOMEZLEE MARKETING | Seguimiento de Impuestos GLM | Uso interno</td></tr>\n </table>\n </td></tr>\n </table>\n </body>\n</html>`.trim();\n\n const googleChatText = [\n `*${reminderLabel.toUpperCase()} · SEGUIMIENTO DE IMPUESTOS GLM*`,\n '',\n `Hola ${firstName},`,\n '',\n `*País:* ${row.country_name}`,\n `*Categoría:* ${categoryLabel}`,\n `*Fecha límite:* ${dueDate}`,\n `*Obligación:* ${row.description}`,\n '',\n 'Seguimiento automático: miércoles anterior y fecha límite, incluidos sábados y domingos.',\n '',\n `Abrir calendario: ${appUrl}`,\n ].join('\\n');\n\n return {\n json: {\n ...row,\n email_subject: subject,\n email_html: emailHtml,\n google_chat_text: googleChatText,\n },\n };\n});"
|
|
},
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 2,
|
|
"position": [
|
|
416,
|
|
2080
|
|
],
|
|
"id": "c19543d0-6e85-4ed7-903a-1d254553cf49",
|
|
"name": "Construir mensajes GLM"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"jsCode": "return $input.all().filter((item) => item.json.email_enabled === true && String(item.json.contact_email ?? '').trim());"
|
|
},
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 2,
|
|
"position": [
|
|
688,
|
|
1936
|
|
],
|
|
"id": "e923e3bc-02d7-4402-8ca4-4138f2db3cd2",
|
|
"name": "Preparar correos"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"sendTo": "={{ $json.contact_email }}",
|
|
"subject": "={{ $json.email_subject }}",
|
|
"message": "={{ $json.email_html }}",
|
|
"options": {
|
|
"appendAttribution": false
|
|
}
|
|
},
|
|
"type": "n8n-nodes-base.gmail",
|
|
"typeVersion": 2.1,
|
|
"position": [
|
|
944,
|
|
1936
|
|
],
|
|
"id": "084ac77b-6f26-41c8-ab55-8d0989f81fb8",
|
|
"name": "Gmail - Enviar recordatorio",
|
|
"webhookId": "16bfebbd-f4e3-4b1e-aba2-028fecf98da1",
|
|
"credentials": {
|
|
"gmailOAuth2": {
|
|
"id": "UDcO1FLJqA453V2D",
|
|
"name": "Gmail account 3"
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"parameters": {
|
|
"method": "POST",
|
|
"url": "https://dbit.digitalcompass.agency/rest/v1/rpc/tax_record_notification",
|
|
"sendHeaders": true,
|
|
"headerParameters": {
|
|
"parameters": [
|
|
{
|
|
"name": "apikey",
|
|
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q"
|
|
},
|
|
{
|
|
"name": "Authorization",
|
|
"value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q"
|
|
},
|
|
{
|
|
"name": "Content-Type",
|
|
"value": "application/json"
|
|
}
|
|
]
|
|
},
|
|
"sendBody": true,
|
|
"specifyBody": "json",
|
|
"jsonBody": "={{ { p_obligation_id: $('Preparar correos').item.json.obligation_id, p_contact_id: $('Preparar correos').item.json.contact_id, p_alert_date: $('Preparar correos').item.json.alert_date, p_channel: 'email', p_status: 'sent', p_provider_response: $json } }}",
|
|
"options": {}
|
|
},
|
|
"type": "n8n-nodes-base.httpRequest",
|
|
"typeVersion": 4.4,
|
|
"position": [
|
|
1200,
|
|
1936
|
|
],
|
|
"id": "ce69dcd5-c9ae-4770-9797-a9fff667a7ba",
|
|
"name": "Supabase - Registrar correo"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"jsCode": "const CALLING_USER_EMAIL = 'iaracena@gomezleemarketing.com';\n\nreturn $input.all().filter((item) => {\n const enabled = item.json.google_chat_enabled === true;\n const email = String(item.json.contact_email ?? '').trim().toLowerCase();\n\n return enabled && email && email !== CALLING_USER_EMAIL;\n});"
|
|
},
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 2,
|
|
"position": [
|
|
688,
|
|
2208
|
|
],
|
|
"id": "a02e0bac-f208-491d-8257-83dc91fe5dd4",
|
|
"name": "Preparar Google Chat"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"method": "POST",
|
|
"url": "https://chat.googleapis.com/v1/spaces:setup",
|
|
"authentication": "predefinedCredentialType",
|
|
"nodeCredentialType": "googleChatOAuth2Api",
|
|
"sendHeaders": true,
|
|
"headerParameters": {
|
|
"parameters": [
|
|
{
|
|
"name": "Content-Type",
|
|
"value": "application/json"
|
|
}
|
|
]
|
|
},
|
|
"sendBody": true,
|
|
"specifyBody": "json",
|
|
"jsonBody": "={{ { space: { spaceType: 'DIRECT_MESSAGE', singleUserBotDm: false }, memberships: [ { member: { name: 'users/' + $json.contact_email, type: 'HUMAN' } } ] } }}",
|
|
"options": {
|
|
"timeout": 30000
|
|
}
|
|
},
|
|
"type": "n8n-nodes-base.httpRequest",
|
|
"typeVersion": 4.4,
|
|
"position": [
|
|
944,
|
|
2208
|
|
],
|
|
"id": "290d682a-55cf-411b-82f4-6e573fadaf9d",
|
|
"name": "Google Chat - Abrir DM",
|
|
"retryOnFail": true,
|
|
"maxTries": 3,
|
|
"waitBetweenTries": 1500,
|
|
"credentials": {
|
|
"googleChatOAuth2Api": {
|
|
"id": "8UR1kLTQ4SDHgfaZ",
|
|
"name": "Google Chat - Seguimiento de Impuestos GLM"
|
|
}
|
|
},
|
|
"onError": "continueRegularOutput"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"jsCode": "const responses = $input.all();\nconst sources = $('Preparar Google Chat').all();\n\nreturn responses.map((item, index) => {\n const source = sources[index]?.json ?? {};\n const response = item.json ?? {};\n const spaceName = String(response.name ?? '').trim();\n const ok = Boolean(spaceName) && !response.error;\n\n return {\n json: {\n ...source,\n chat_space_name: spaceName,\n chat_setup_ok: ok,\n google_chat_status: ok ? 'pending' : 'failed',\n google_chat_provider_response: response,\n },\n pairedItem: { item: index },\n };\n});"
|
|
},
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 2,
|
|
"position": [
|
|
1200,
|
|
2208
|
|
],
|
|
"id": "04d40a89-5b44-441f-ae5b-e681c480820e",
|
|
"name": "Evaluar DM Google Chat"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"jsCode": "return $input.all().filter((item) => item.json.chat_setup_ok === true);"
|
|
},
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 2,
|
|
"position": [
|
|
1456,
|
|
2096
|
|
],
|
|
"id": "1ab28b37-2d73-4471-ae52-c62163c4d9f0",
|
|
"name": "Preparar envío Google Chat"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"jsCode": "return $input.all().filter((item) => item.json.chat_setup_ok !== true);"
|
|
},
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 2,
|
|
"position": [
|
|
1456,
|
|
2352
|
|
],
|
|
"id": "fdd96034-cd48-427a-acda-3ac249eb3f31",
|
|
"name": "Preparar fallo DM Google Chat"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"method": "POST",
|
|
"url": "={{ 'https://chat.googleapis.com/v1/' + $json.chat_space_name + '/messages' }}",
|
|
"authentication": "predefinedCredentialType",
|
|
"nodeCredentialType": "googleChatOAuth2Api",
|
|
"sendHeaders": true,
|
|
"headerParameters": {
|
|
"parameters": [
|
|
{
|
|
"name": "Content-Type",
|
|
"value": "application/json"
|
|
}
|
|
]
|
|
},
|
|
"sendBody": true,
|
|
"specifyBody": "json",
|
|
"jsonBody": "={{ { text: $json.google_chat_text } }}",
|
|
"options": {
|
|
"timeout": 30000
|
|
}
|
|
},
|
|
"type": "n8n-nodes-base.httpRequest",
|
|
"typeVersion": 4.4,
|
|
"position": [
|
|
1712,
|
|
2096
|
|
],
|
|
"id": "2f510b09-4bb1-4dcb-863b-9d863868750b",
|
|
"name": "Google Chat - Enviar recordatorio",
|
|
"retryOnFail": true,
|
|
"maxTries": 3,
|
|
"waitBetweenTries": 1500,
|
|
"credentials": {
|
|
"googleChatOAuth2Api": {
|
|
"id": "8UR1kLTQ4SDHgfaZ",
|
|
"name": "Google Chat - Seguimiento de Impuestos GLM"
|
|
}
|
|
},
|
|
"onError": "continueRegularOutput"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"jsCode": "const responses = $input.all();\nconst sources = $('Preparar envío Google Chat').all();\n\nreturn responses.map((item, index) => {\n const source = sources[index]?.json ?? {};\n const response = item.json ?? {};\n const sent = Boolean(response.name) && !response.error;\n\n return {\n json: {\n ...source,\n google_chat_status: sent ? 'sent' : 'failed',\n google_chat_provider_response: response,\n },\n pairedItem: { item: index },\n };\n});"
|
|
},
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 2,
|
|
"position": [
|
|
1968,
|
|
2096
|
|
],
|
|
"id": "93094ae5-5e9b-4e42-9a9b-5ed9213943e3",
|
|
"name": "Evaluar envío Google Chat"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"method": "POST",
|
|
"url": "https://dbit.digitalcompass.agency/rest/v1/rpc/tax_record_notification",
|
|
"sendHeaders": true,
|
|
"headerParameters": {
|
|
"parameters": [
|
|
{
|
|
"name": "apikey",
|
|
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q"
|
|
},
|
|
{
|
|
"name": "Authorization",
|
|
"value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q"
|
|
},
|
|
{
|
|
"name": "Content-Type",
|
|
"value": "application/json"
|
|
}
|
|
]
|
|
},
|
|
"sendBody": true,
|
|
"specifyBody": "json",
|
|
"jsonBody": "={{ { p_obligation_id: $json.obligation_id, p_contact_id: $json.contact_id, p_alert_date: $json.alert_date, p_channel: 'google_chat', p_status: $json.google_chat_status, p_provider_response: $json.google_chat_provider_response } }}",
|
|
"options": {}
|
|
},
|
|
"type": "n8n-nodes-base.httpRequest",
|
|
"typeVersion": 4.4,
|
|
"position": [
|
|
2224,
|
|
2208
|
|
],
|
|
"id": "db27cf44-56e0-4544-90dd-d81bc0d4bd7d",
|
|
"name": "Supabase - Registrar Google Chat"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"content": "## RECORDATORIOS DE IMPUESTOS POR GMAIL Y GOOGLE CHAT\n\nEjecuta diariamente el proceso de recordatorios fiscales y notifica a los contactos correspondientes por correo electrónico y mensaje directo de Google Chat.\n\n- Puede iniciarse automáticamente a las 8:00 a. m., manualmente o desde el webhook de la aplicación.\n- Consulta en Supabase las obligaciones que requieren recordatorio y sus destinatarios.\n- Construye mensajes personalizados con el formato corporativo de GLM.\n- Envía los recordatorios por Gmail al correo de cada contacto y registra el resultado.\n- Abre o reutiliza el DM del destinatario en Google Chat mediante `spaces:setup`.\n- Conserva todos los items de Google Chat de principio a fin; no colapsa múltiples destinatarios en uno solo.\n- Envía texto con `spaces.messages.create` usando un body válido `{ text: ... }`.\n- Omite el correo del propio usuario autenticado de Google Chat, porque Google agrega automáticamente al calling user y no permite especificarlo como membership.\n- Evalúa cada intento individualmente y registra éxitos o errores en Supabase.",
|
|
"height": 1184,
|
|
"width": 2880,
|
|
"color": "#204750"
|
|
},
|
|
"type": "n8n-nodes-base.stickyNote",
|
|
"typeVersion": 1,
|
|
"position": [
|
|
-464,
|
|
1360
|
|
],
|
|
"id": "3ee2b7ce-eff0-4d62-b80d-f4df454e91df",
|
|
"name": "Sticky Note"
|
|
}
|
|
],
|
|
"connections": {
|
|
"Diario 8:00 AM": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Preparar ejecución",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Ejecutar manualmente": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Preparar ejecución",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Webhook seguimiento-impuestos": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Validar ejecución por Webhook",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Preparar ejecución": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Supabase - Recordatorios pendientes",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Validar ejecución por Webhook": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Preparar ejecución",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Supabase - Recordatorios pendientes": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Construir mensajes GLM",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Construir mensajes GLM": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Preparar correos",
|
|
"type": "main",
|
|
"index": 0
|
|
},
|
|
{
|
|
"node": "Preparar Google Chat",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Preparar correos": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Gmail - Enviar recordatorio",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Gmail - Enviar recordatorio": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Supabase - Registrar correo",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Preparar Google Chat": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Google Chat - Abrir DM",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Google Chat - Abrir DM": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Evaluar DM Google Chat",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Evaluar DM Google Chat": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Preparar envío Google Chat",
|
|
"type": "main",
|
|
"index": 0
|
|
},
|
|
{
|
|
"node": "Preparar fallo DM Google Chat",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Preparar envío Google Chat": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Google Chat - Enviar recordatorio",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Google Chat - Enviar recordatorio": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Evaluar envío Google Chat",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Evaluar envío Google Chat": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Supabase - Registrar Google Chat",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Preparar fallo DM Google Chat": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Supabase - Registrar Google Chat",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
}
|
|
},
|
|
"authors": "Isaac Aracena",
|
|
"name": "Version 0ebbe45e",
|
|
"description": "",
|
|
"autosaved": true,
|
|
"workflowPublishHistory": [
|
|
{
|
|
"createdAt": "2026-08-12T17:42:42.706Z",
|
|
"id": 4607,
|
|
"workflowId": "cFu3Xx23KQBKfr0M",
|
|
"versionId": "0ebbe45e-f485-4abc-8de3-5f5b05857edf",
|
|
"event": "activated",
|
|
"userId": "0a88c0b1-928e-4412-896e-c5d1c99b2029"
|
|
}
|
|
]
|
|
}
|
|
} |