{
  "name": "NewsWave - Daily Newsletter Sender",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 8 * * *"
            }
          ]
        }
      },
      "id": "daily-schedule",
      "name": "Daily at 8 AM",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "url": "http://localhost:3001/api/stats",
        "options": {}
      },
      "id": "check-subscribers",
      "name": "Check Subscribers",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        480,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "conditions": [
            {
              "leftValue": "={{$json.newsletterSubscribers}}",
              "rightValue": 0,
              "operator": {
                "type": "number",
                "operation": "gt"
              }
            }
          ]
        }
      },
      "id": "has-subscribers",
      "name": "Has Subscribers?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        720,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://localhost:3001/api/newsletter/send-all",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "x-api-key",
              "value": "={{$env.N8N_WEBHOOK_KEY}}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": []
        },
        "options": {}
      },
      "id": "send-newsletters",
      "name": "Send All Newsletters",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        960,
        200
      ]
    },
    {
      "parameters": {
        "message": "=\ud83d\udce7 NewsWave Newsletter: Sent to {{$node['Check Subscribers'].json.newsletterSubscribers}} subscribers at {{new Date().toLocaleTimeString()}}",
        "options": {}
      },
      "id": "log-newsletter-sent",
      "name": "Log Newsletter Sent",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1200,
        200
      ]
    },
    {
      "parameters": {
        "message": "\u2139\ufe0f NewsWave Newsletter: Skipped - 0 subscribers",
        "options": {}
      },
      "id": "log-no-subscribers",
      "name": "Log No Subscribers",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        960,
        400
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "{\"message\": \"Newsletter send triggered manually\"}"
      },
      "id": "manual-webhook",
      "name": "Manual Trigger Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        240,
        500
      ]
    },
    {
      "parameters": {
        "url": "http://localhost:3001/api/news?limit=1",
        "options": {}
      },
      "id": "check-has-news",
      "name": "Check News Available",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        480,
        120
      ]
    }
  ],
  "connections": {
    "Daily at 8 AM": {
      "main": [
        [
          {
            "node": "Check News Available",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check News Available": {
      "main": [
        [
          {
            "node": "Check Subscribers",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Subscribers": {
      "main": [
        [
          {
            "node": "Has Subscribers?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has Subscribers?": {
      "main": [
        [
          {
            "node": "Send All Newsletters",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Log No Subscribers",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send All Newsletters": {
      "main": [
        [
          {
            "node": "Log Newsletter Sent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Manual Trigger Webhook": {
      "main": [
        [
          {
            "node": "Check Subscribers",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "1",
  "tags": [
    "newswave",
    "newsletter"
  ],
  "notes": "Sends personalized AI-generated newsletters daily at 8 AM to all subscribed users. Each user gets articles tailored to their preferences, with AI-written summaries and direct links back to NewsWave."
}