{
  "name": "Silent-failure watchdog — Telegram alert when a workflow stops running",
  "nodes": [
    {
      "parameters": {
        "content": "## 🕵️ Silent-failure watchdog\n\nThe Error Trigger only fires when a workflow **throws**. If a trigger silently stops (webhook deregistered, polling died, upstream app quietly revoked access) — nothing throws, and nobody hears about it. This workflow checks every hour that your critical workflows actually ran recently, and pings you on Telegram when one goes quiet.\n\n### Setup (~5 minutes)\n1. **n8n API credential:** n8n → Settings → *n8n API* → create an API key → attach it to **Get recent executions** (base URL = your instance URL).\n2. **Config node:** paste the workflow IDs to watch (comma-separated — the ID is in each workflow's URL), the max hours a workflow may stay silent, and your Telegram chat ID.\n3. **Telegram:** attach your bot credential to **Send Telegram alert** (create a bot with @BotFather; get your chat ID from @userinfobot).\n4. Save & **activate**.\n\n### Good to know\n- **Avoid false alarms:** a workflow that only runs on weekdays will look \"silent\" every weekend. Set `skipWeekends` to true and/or `quietHours` (e.g. `22-07`) in the Config node — checks are skipped during those windows (server timezone). Pick each threshold from the workflow's real cadence, not a single global number.\n- Scans the **last 100 executions** on the instance. Very busy instance? Raise the limit in *Get recent executions*.\n- Don't add THIS workflow to its own watch list 🙂\n- Swap Telegram for Slack/Discord/email — each alert item carries `workflowId` and `problem` fields.\n\n---\n🩺 This template answers \"did it run at all?\". **WentQuiet** → https://wentquiet.com?ref=n8n-template also catches volume anomalies (\"usually 40 runs/day, today 0\"), captures error content, alerts on Slack/Telegram/WhatsApp/webhook, and gives agencies a client-facing status page — for n8n **and** Make. Founding pricing is open.",
        "width": 460,
        "height": 760
      },
      "id": "sticky-setup-2",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [-320, -120]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "7 * * * *"
            }
          ]
        }
      },
      "id": "schedule-2",
      "name": "Every hour",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [220, 160]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "cfg-ids",
              "name": "watchedWorkflowIds",
              "value": "PASTE_WORKFLOW_ID_1, PASTE_WORKFLOW_ID_2",
              "type": "string"
            },
            {
              "id": "cfg-hours",
              "name": "maxHoursWithoutRun",
              "value": 6,
              "type": "number"
            },
            {
              "id": "cfg-chat",
              "name": "telegramChatId",
              "value": "PASTE_YOUR_CHAT_ID",
              "type": "string"
            },
            {
              "id": "cfg-quiet",
              "name": "quietHours",
              "value": "",
              "type": "string"
            },
            {
              "id": "cfg-weekends",
              "name": "skipWeekends",
              "value": false,
              "type": "boolean"
            }
          ]
        },
        "options": {}
      },
      "id": "config-2",
      "name": "Config",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [420, 160]
    },
    {
      "parameters": {
        "resource": "execution",
        "operation": "getAll",
        "returnAll": false,
        "limit": 100,
        "filters": {}
      },
      "id": "get-execs-2",
      "name": "Get recent executions",
      "type": "n8n-nodes-base.n8n",
      "typeVersion": 1,
      "position": [620, 160],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "jsCode": "const cfg = $('Config').first().json;\n// Quiet windows: don't alert during hours when your workflows legitimately don't run\n// (times use this n8n server's timezone)\nconst nowD = new Date();\nif (cfg.skipWeekends && [0, 6].includes(nowD.getDay())) return [];\nif (cfg.quietHours) {\n  const m = String(cfg.quietHours).match(/^(\\d{1,2})-(\\d{1,2})$/);\n  if (m) {\n    const h = nowD.getHours(), start = +m[1], end = +m[2];\n    const inQuiet = start <= end ? (h >= start && h < end) : (h >= start || h < end);\n    if (inQuiet) return [];\n  }\n}\nconst watched = String(cfg.watchedWorkflowIds).split(',').map(s => s.trim()).filter(Boolean);\nconst maxMs = Number(cfg.maxHoursWithoutRun) * 3600 * 1000;\nconst now = Date.now();\nconst execs = $input.all().map(i => i.json).filter(e => e && e.workflowId);\nconst alerts = [];\nfor (const id of watched) {\n  const mine = execs.filter(e => String(e.workflowId) === id);\n  const latest = mine.map(e => new Date(e.startedAt).getTime()).sort((a, b) => b - a)[0];\n  if (!latest) {\n    alerts.push({ json: { workflowId: id, problem: `No run found among the last ${execs.length} executions on this instance. It may have stopped completely (or raise the limit in 'Get recent executions').` } });\n  } else if (now - latest > maxMs) {\n    const hours = Math.round((now - latest) / 36e5);\n    alerts.push({ json: { workflowId: id, problem: `Last run was ${hours}h ago (threshold: ${cfg.maxHoursWithoutRun}h).` } });\n  }\n}\n// Empty array = all quiet = nothing downstream runs. No IF node needed.\nreturn alerts;"
      },
      "id": "find-silent-2",
      "name": "Find silent workflows",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [820, 160]
    },
    {
      "parameters": {
        "chatId": "={{ $('Config').first().json.telegramChatId }}",
        "text": "=🚨 Silent-failure watchdog\n\nWorkflow {{ $json.workflowId }} went quiet:\n{{ $json.problem }}\n\nChecked at {{ $now.toISO() }}",
        "additionalFields": {}
      },
      "id": "telegram-2",
      "name": "Send Telegram alert",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [1020, 160]
    }
  ],
  "connections": {
    "Every hour": {
      "main": [
        [
          {
            "node": "Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config": {
      "main": [
        [
          {
            "node": "Get recent executions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get recent executions": {
      "main": [
        [
          {
            "node": "Find silent workflows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find silent workflows": {
      "main": [
        [
          {
            "node": "Send Telegram alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}
