{
  "name": "Eventos - Lembrete autom\u00e1tico (v\u00e9spera e dia do evento)",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 18 * * *"
            }
          ]
        }
      },
      "id": "c3d4e5f6-0001-4000-9000-000000000001",
      "name": "Cron 18h (v\u00e9spera)",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        240,
        200
      ]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 8 * * *"
            }
          ]
        }
      },
      "id": "c3d4e5f6-0002-4000-9000-000000000002",
      "name": "Cron 08h (dia do evento)",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        240,
        420
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "={{$env.REDE_GUTI_API_URL}}/automation/event-reminders?window=tomorrow",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/json"
            }
          ]
        },
        "options": {
          "timeout": 30000,
          "response": {
            "response": {
              "neverError": false,
              "fullResponse": false
            }
          }
        }
      },
      "id": "c3d4e5f6-0003-4000-9000-000000000003",
      "name": "GET lembretes de amanh\u00e3",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        480,
        200
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "GET",
        "url": "={{$env.REDE_GUTI_API_URL}}/automation/event-reminders?window=today",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/json"
            }
          ]
        },
        "options": {
          "timeout": 30000,
          "response": {
            "response": {
              "neverError": false,
              "fullResponse": false
            }
          }
        }
      },
      "id": "c3d4e5f6-0004-4000-9000-000000000004",
      "name": "GET lembretes de hoje",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        480,
        420
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Achata eventos \u2192 uma mensagem por convidado.\n// CONFIRMADO recebe lembrete simples; APROVADO recebe pedido de confirma\u00e7\u00e3o\n// com o link p\u00fablico de confirma\u00e7\u00e3o.\nconst data = $input.item.json;\nconst when = data.window === 'today' ? 'HOJE' : 'AMANH\u00c3';\nconst out = [];\n\nfor (const ev of data.eventos || []) {\n  const dataBr = new Date(ev.data).toLocaleDateString('pt-BR', { timeZone: 'America/Sao_Paulo' });\n  for (const ind of ev.indicados || []) {\n    let message;\n    if (ind.status === 'CONFIRMADO') {\n      message =\n        `Ol\u00e1 ${ind.nome}! \ud83d\ude4f Passando para lembrar: \u00e9 ${when}!\\n\\n` +\n        `\ud83d\udcc5 *${ev.nome}*\\n` +\n        `\ud83d\uddd3 ${dataBr}\\n` +\n        `\u23f0 ${ev.hora}\\n` +\n        `\ud83d\udccd ${ev.local}\\n\\n` +\n        `Te esperamos l\u00e1! \ud83d\udc99`;\n    } else {\n      message =\n        `Ol\u00e1 ${ind.nome}! \ud83d\ude4f O evento *${ev.nome}* \u00e9 ${when} (${dataBr} \u00e0s ${ev.hora}, ${ev.local}) ` +\n        `e ainda n\u00e3o recebemos sua confirma\u00e7\u00e3o.\\n\\n` +\n        `Confirme sua presen\u00e7a aqui:\\n${ind.confirmacaoLink}`;\n    }\n    out.push({ json: { phone: ind.telefone, message, eventoId: ev.id, indicadoId: ind.id, status: ind.status } });\n  }\n}\n\nreturn out;"
      },
      "id": "c3d4e5f6-0005-4000-9000-000000000005",
      "name": "Montar mensagens",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        720,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{$env.WHATSAPP_API_URL}}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"number\": \"{{$json.phone}}\",\n  \"text\": {{JSON.stringify($json.message)}}\n}",
        "options": {
          "timeout": 10000,
          "batching": {
            "batch": {
              "batchSize": 1,
              "batchInterval": 2000
            }
          },
          "response": {
            "response": {
              "neverError": true,
              "fullResponse": true
            }
          }
        }
      },
      "id": "c3d4e5f6-0006-4000-9000-000000000006",
      "name": "Enviar WhatsApp",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        960,
        300
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "onError": "continueRegularOutput"
    }
  ],
  "connections": {
    "Cron 18h (v\u00e9spera)": {
      "main": [
        [
          {
            "node": "GET lembretes de amanh\u00e3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Cron 08h (dia do evento)": {
      "main": [
        [
          {
            "node": "GET lembretes de hoje",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GET lembretes de amanh\u00e3": {
      "main": [
        [
          {
            "node": "Montar mensagens",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GET lembretes de hoje": {
      "main": [
        [
          {
            "node": "Montar mensagens",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Montar mensagens": {
      "main": [
        [
          {
            "node": "Enviar WhatsApp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false,
    "description": "Lembrete autom\u00e1tico de eventos: na v\u00e9spera \u00e0s 18h e no dia \u00e0s 08h busca GET /automation/event-reminders e envia WhatsApp para cada convidado APROVADO (pede confirma\u00e7\u00e3o com link) ou CONFIRMADO (lembrete). Vari\u00e1veis: REDE_GUTI_API_URL, WHATSAPP_API_URL. Credentials: 'Rede Guti Automation Token' e 'WhatsApp API Header Auth'. Configure APP_PUBLIC_URL no backend para o link de confirma\u00e7\u00e3o sair absoluto."
  },
  "tags": []
}