{
  "id": "peskids-followup-24h",
  "name": "Peskids - Auto Follow-up 24h",
  "active": true,
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 1
            }
          ]
        }
      },
      "id": "schedule-trigger",
      "name": "Every 1 Hour",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $env.PESKIDS_APP_URL || 'https://peskids.op-sly.com' }}/api/admin/followups/execute",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $env.PESKIDS_FOLLOWUP_CRON_SECRET || $env.PESKIDS_DIGEST_CRON_SECRET }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "options": {}
      },
      "id": "execute-followups",
      "name": "Execute Follow-ups",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        260,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ Boolean($json.ok) }}",
              "value2": true
            }
          ]
        }
      },
      "id": "check-result",
      "name": "Check Result",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1.2,
      "position": [
        520,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{ Array.isArray($json.executed) ? $json.executed.length : 0 }}",
              "operation": "larger",
              "value2": 0
            }
          ]
        }
      },
      "id": "has-followups",
      "name": "Has Follow-ups?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1.2,
      "position": [
        780,
        200
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $env.OPSLY_CRM_NOTIFY_WEBHOOK_URL }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ content: `\ud83d\udea8 **Peskids \u2014 Follow-ups ejecutados**\\n\\n**Procesados:** ${(Array.isArray($json.executed) ? $json.executed.length : 0)}\\n**Saltados:** ${(Array.isArray($json.skipped) ? $json.skipped.length : 0)}\\n**Fallidos:** ${(Array.isArray($json.failed) ? $json.failed.length : 0)}\\n\\n_CRM: https://crm-peskids.op-sly.com_` }) }}",
        "options": {}
      },
      "id": "discord-notify",
      "name": "Discord Notification",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1040,
        150
      ],
      "continueOnFail": true
    },
    {
      "parameters": {
        "jsCode": "return [{ json: { skipped: true, reason: 'No follow-ups executed', checked_at: new Date().toISOString() } }];"
      },
      "id": "no-followups",
      "name": "No Follow-ups",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1040,
        350
      ]
    }
  ],
  "connections": {
    "Every 1 Hour": {
      "main": [
        [
          {
            "node": "Execute Follow-ups",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute Follow-ups": {
      "main": [
        [
          {
            "node": "Check Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Result": {
      "main": [
        [
          {
            "node": "Has Follow-ups?",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Follow-ups",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has Follow-ups?": {
      "main": [
        [
          {
            "node": "Discord Notification",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Follow-ups",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}