{
  "name": "Lunexo – Daily Stats Reporter",
  "nodes": [
    {
      "parameters": {
        "content": "## Daily Stats Reporter\n\n**What it does:** Fetches stats from your API every morning, formats an HTML email report and sends a short Telegram summary.\n\n**Setup (~10 min):**\n1. Add your SMTP credentials\n2. Add your Telegram Bot API credentials\n3. Replace `YOUR_STATS_API_URL` with your stats endpoint\n4. Replace `YOUR_ADMIN_EMAIL` with your inbox\n5. Replace `YOUR_TELEGRAM_CHAT_ID` with your chat ID\n6. Activate the workflow\n\n**Variables to change:**\n- `YOUR_STATS_API_URL` — stats API endpoint\n- `YOUR_ADMIN_EMAIL` — your email inbox\n- `YOUR_TELEGRAM_CHAT_ID` — Telegram chat ID",
        "height": 350,
        "width": 350,
        "color": 5
      },
      "id": "c5a10001-b2c3-4d5e-a6f7-500000000001",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [40, 80]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 8,
              "triggerAtMinute": 0
            }
          ]
        },
        "options": {
          "timezone": "Europe/Berlin"
        }
      },
      "id": "c5a10001-b2c3-4d5e-a6f7-500000000002",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [240, 300]
    },
    {
      "parameters": {
        "url": "YOUR_STATS_API_URL",
        "options": {
          "timeout": 10000
        }
      },
      "id": "c5a10001-b2c3-4d5e-a6f7-500000000003",
      "name": "Fetch Stats",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [460, 300]
    },
    {
      "parameters": {
        "jsCode": "try {\n  const data = $input.first().json;\n  const users = data.users ?? 'N/A';\n  const pageViews = data.pageViews ?? 'N/A';\n  const revenue = data.revenue ?? 'N/A';\n  const openTickets = data.openTickets ?? 'N/A';\n  const date = new Date().toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });\n\n  const htmlReport = `<div style=\"font-family:Arial,sans-serif;max-width:600px;margin:0 auto;padding:20px;\">`\n    + `<h2 style=\"color:#6C2BD9;\">Daily Stats Report</h2>`\n    + `<p style=\"color:#555;\">${date}</p>`\n    + `<table style=\"width:100%;border-collapse:collapse;margin:16px 0;\">`\n    + `<tr style=\"background:#f4f0ff;\"><td style=\"padding:12px;border:1px solid #e0d4f5;font-weight:bold;\">Users</td><td style=\"padding:12px;border:1px solid #e0d4f5;text-align:right;font-size:18px;\">${users}</td></tr>`\n    + `<tr><td style=\"padding:12px;border:1px solid #e0d4f5;font-weight:bold;\">Page Views</td><td style=\"padding:12px;border:1px solid #e0d4f5;text-align:right;font-size:18px;\">${pageViews}</td></tr>`\n    + `<tr style=\"background:#f4f0ff;\"><td style=\"padding:12px;border:1px solid #e0d4f5;font-weight:bold;\">Revenue</td><td style=\"padding:12px;border:1px solid #e0d4f5;text-align:right;font-size:18px;\">${revenue}</td></tr>`\n    + `<tr><td style=\"padding:12px;border:1px solid #e0d4f5;font-weight:bold;\">Open Tickets</td><td style=\"padding:12px;border:1px solid #e0d4f5;text-align:right;font-size:18px;\">${openTickets}</td></tr>`\n    + `</table>`\n    + `<p style=\"color:#888;font-size:12px;\">— Lunexo Daily Stats Reporter</p>`\n    + `</div>`;\n\n  const telegramSummary = `📊 Daily Stats (${date})\\n\\n👥 Users: ${users}\\n📈 Page Views: ${pageViews}\\n💰 Revenue: ${revenue}\\n🎫 Open Tickets: ${openTickets}`;\n\n  return [{ json: { htmlReport, telegramSummary } }];\n} catch (err) {\n  const fallback = 'Stats unavailable — the API did not return expected data.';\n  const htmlReport = `<div style=\"font-family:Arial,sans-serif;padding:20px;\"><h2 style=\"color:#6C2BD9;\">Daily Stats Report</h2><p style=\"color:red;\">${fallback}</p><p>Error: ${err.message}</p></div>`;\n  const telegramSummary = `⚠️ Daily Stats Report\\n\\n${fallback}\\nError: ${err.message}`;\n  return [{ json: { htmlReport, telegramSummary } }];\n}"
      },
      "id": "c5a10001-b2c3-4d5e-a6f7-500000000004",
      "name": "Format Report",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [680, 300]
    },
    {
      "parameters": {
        "fromEmail": "noreply@yourdomain.com",
        "toEmail": "YOUR_ADMIN_EMAIL",
        "subject": "=Daily Stats Report — {{ new Date().toLocaleDateString('en-US') }}",
        "emailType": "html",
        "html": "={{ $json.htmlReport }}",
        "options": {}
      },
      "id": "c5a10001-b2c3-4d5e-a6f7-500000000005",
      "name": "Send Email Report",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [900, 300],
      "credentials": {
        "smtp": {
          "id": "CHANGE_ME",
          "name": "Your SMTP Account"
        }
      }
    },
    {
      "parameters": {
        "chatId": "YOUR_TELEGRAM_CHAT_ID",
        "text": "={{ $json.telegramSummary }}",
        "additionalFields": {
          "parse_mode": "Markdown"
        }
      },
      "id": "c5a10001-b2c3-4d5e-a6f7-500000000006",
      "name": "Send Telegram Summary",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [1120, 300],
      "credentials": {
        "telegramApi": {
          "id": "CHANGE_ME",
          "name": "Your Telegram Bot"
        }
      }
    }
  ],
  "connections": {
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Fetch Stats",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Stats": {
      "main": [
        [
          {
            "node": "Format Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Report": {
      "main": [
        [
          {
            "node": "Send Email Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Email Report": {
      "main": [
        [
          {
            "node": "Send Telegram Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "c5a10001-b2c3-4d5e-a6f7-500000000099",
  "meta": {
    "templateCredsSetupCompleted": false,
    "instanceId": "lunexo"
  },
  "pinData": {},
  "staticData": null,
  "tags": [
    { "name": "Lunexo" },
    { "name": "Report" },
    { "name": "Scheduled" }
  ]
}