{
  "name": "One error inbox for all your workflows, secrets removed",
  "nodes": [
    {
      "id": "398bec45-16eb-4f1e-8f16-d3ce2eab43c8",
      "name": "Read me first",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -640,
        -160
      ],
      "parameters": {
        "content": "## One error inbox for all your workflows, secrets removed\nPoint your other workflows here. Each error is logged with keys, tokens, emails and phone numbers removed. Login and rate-limit errors reach you at once, and each morning you get a count.\n\n### You need\n- A Google Sheets login and an Errors tab with: Time, Workflow, Step, Message, Severity, Run Link\n- A Telegram bot and your chat ID\n\n### Set it up\n1. Pick your sheet in **Log the error** and **Read the error log**. Add your chat ID in **Settings** and your bot in both Telegram steps.\n2. Turn this workflow on.\n3. In each workflow you want to watch, open Workflow settings and set Error workflow to this one. Do not set it on this workflow.\n\n### Test it\n- Make a test workflow on a schedule with a Code step that says: throw new Error('test'). Point its Error workflow here and turn it on.\n- After it runs, the Errors tab gets a row. Errors from a manual test run are not sent: n8n only does that for runs that start on their own.",
        "height": 780,
        "width": 560,
        "color": 4
      }
    },
    {
      "id": "c9f9d4ff-2d4c-4ae1-93a1-b9e06d31b136",
      "name": "Note: clean",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        672,
        -160
      ],
      "parameters": {
        "content": "## Clean and log\nKeys, tokens, passwords, emails and phone numbers are removed before anything is saved or sent.",
        "height": 440,
        "width": 1000,
        "color": 7
      }
    },
    {
      "id": "d84c582b-b82f-4056-92aa-5e5b03464a6a",
      "name": "Note: digest",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        672,
        320
      ],
      "parameters": {
        "content": "## Morning count\nEvery morning: how many errors came in over the last 24 hours, by workflow. A quiet day says so.",
        "height": 460,
        "width": 1000,
        "color": 7
      }
    },
    {
      "id": "206b664f-13a8-4639-b77a-4f30aac80557",
      "name": "When another workflow fails",
      "type": "n8n-nodes-base.errorTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ],
      "parameters": {}
    },
    {
      "id": "3767cee0-e858-437c-8603-6f6175e8ad78",
      "name": "Every morning",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.3,
      "position": [
        0,
        240
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "days",
              "triggerAtHour": 8
            }
          ]
        }
      }
    },
    {
      "id": "f23ce437-c8b2-43ce-b5a3-c92060ab61f5",
      "name": "Settings",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        240,
        120
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "f1",
              "name": "sendEveryError",
              "type": "boolean",
              "value": false
            },
            {
              "id": "f2",
              "name": "telegramChatId",
              "type": "string",
              "value": "YOUR_CHAT_ID"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      }
    },
    {
      "id": "12cba77b-2680-4739-b941-bdd795e79383",
      "name": "Morning run?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        480,
        120
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ $('Every morning').isExecuted }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "looseTypeValidation": true,
        "options": {}
      }
    },
    {
      "id": "05c78266-7db7-47d0-a470-70a622f025fe",
      "name": "Remove secrets",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        720,
        0
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const e = $('When another workflow fails').first().json;\nconst exec = e.execution || {};\nconst err = exec.error || {};\nconst clean = v => String(v ?? '')\n  .replace(/Bearer\\s+[A-Za-z0-9._~+\\/=-]+/gi, 'Bearer [removed]')\n  .replace(/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}/g, '[email]')\n  .replace(/\\b\\d{6,12}:[A-Za-z0-9_-]{30,}/g, '[bot token]')\n  .replace(/\\b(sk|pk|rk|shpat|ghp|xoxb)[-_][A-Za-z0-9_-]{12,}/g, '[key]')\n  .replace(/((?:api[_-]?key|token|secret|password|authorization)[\"']?\\s*[:=]\\s*[\"']?)[^\"',}\\s]+/gi, '$1[removed]')\n  .replace(/([?&](?:key|token|access_token|api_key|sig)=)[^&\\s\"]+/gi, '$1[removed]')\n  .replace(/\\+?\\d[\\d\\s().-]{7,}\\d/g, '[number]');\nconst message = clean(err.message || 'n8n did not give a reason.').slice(0, 400);\nconst severity = /401|403|unauthori[sz]ed|forbidden|credential|expired|invalid (token|key)/i.test(message) ? 'Login problem'\n  : /429|rate limit|too many requests|quota/i.test(message) ? 'Rate limit' : 'Normal';\nreturn [{ json: {\n  time: $now.toISO(), workflow: String((e.workflow || {}).name || 'unknown'), step: String(exec.lastNodeExecuted || (err.node || {}).name || 'unknown'),\n  message, severity, runLink: String(exec.url || ''),\n} }];"
      }
    },
    {
      "id": "5b984c9f-d2b0-4207-9ff9-807b87dadc78",
      "name": "Log the error",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        960,
        0
      ],
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "",
          "mode": "url"
        },
        "sheetName": {
          "__rl": true,
          "value": "Errors",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Time": "={{ $json.time }}",
            "Workflow": "={{ $json.workflow }}",
            "Step": "={{ $json.step }}",
            "Message": "={{ $json.message }}",
            "Severity": "={{ $json.severity }}",
            "Run Link": "={{ $json.runLink }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Time",
              "displayName": "Time",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Workflow",
              "displayName": "Workflow",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Step",
              "displayName": "Step",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Message",
              "displayName": "Message",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Severity",
              "displayName": "Severity",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Run Link",
              "displayName": "Run Link",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "aece4a1e-396b-497f-b473-fb69154a9acf",
      "name": "Send it now?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1200,
        0
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ $('Remove secrets').item.json.severity !== 'Normal' || $('Settings').first().json.sendEveryError === true }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "looseTypeValidation": true,
        "options": {}
      }
    },
    {
      "id": "47f9f83e-64b0-4f52-b670-e6b5a967b9cc",
      "name": "Send the alert",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1440,
        0
      ],
      "parameters": {
        "chatId": "={{ $('Settings').first().json.telegramChatId }}",
        "text": "={{ $('Remove secrets').item.json.severity + ' in ' + $('Remove secrets').item.json.workflow + '\\nStep: ' + $('Remove secrets').item.json.step + '\\nWhy: ' + $('Remove secrets').item.json.message + ($('Remove secrets').item.json.runLink ? '\\nOpen the run: ' + $('Remove secrets').item.json.runLink : '') }}",
        "additionalFields": {
          "appendAttribution": false
        }
      }
    },
    {
      "id": "86bab088-74c3-428b-ae03-2943e0e0618b",
      "name": "Read the error log",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        720,
        400
      ],
      "parameters": {
        "operation": "read",
        "documentId": {
          "__rl": true,
          "value": "",
          "mode": "url"
        },
        "sheetName": {
          "__rl": true,
          "value": "Errors",
          "mode": "name"
        },
        "options": {}
      },
      "executeOnce": true,
      "alwaysOutputData": true
    },
    {
      "id": "9635a92a-0453-49ab-9fdb-7d3b6ed636b9",
      "name": "Write the morning count",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        960,
        400
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const since = $now.minus({ hours: 24 });\nconst rows = $input.all().map(i => i.json).filter(r => r.Time && DateTime.fromISO(String(r.Time)) >= since);\nconst by = {};\nfor (const r of rows) by[r.Workflow || 'unknown'] = (by[r.Workflow || 'unknown'] || 0) + 1;\nconst lines = Object.entries(by).sort((a, b) => b[1] - a[1]).slice(0, 15).map(([w, n]) => '- ' + w + ': ' + n);\nreturn [{ json: { message: rows.length === 0 ? 'No workflow errors in the last 24 hours.' : 'Workflow errors in the last 24 hours: ' + rows.length + '\\n\\n' + lines.join('\\n') } }];"
      }
    },
    {
      "id": "6d7cb90c-89fe-4b19-b81b-c00f7f626438",
      "name": "Send the morning count",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1200,
        400
      ],
      "parameters": {
        "chatId": "={{ $('Settings').first().json.telegramChatId }}",
        "text": "={{ $json.message }}",
        "additionalFields": {
          "appendAttribution": false
        }
      }
    }
  ],
  "connections": {
    "When another workflow fails": {
      "main": [
        [
          {
            "node": "Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Every morning": {
      "main": [
        [
          {
            "node": "Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Settings": {
      "main": [
        [
          {
            "node": "Morning run?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Morning run?": {
      "main": [
        [
          {
            "node": "Read the error log",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Remove secrets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read the error log": {
      "main": [
        [
          {
            "node": "Write the morning count",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write the morning count": {
      "main": [
        [
          {
            "node": "Send the morning count",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Remove secrets": {
      "main": [
        [
          {
            "node": "Log the error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log the error": {
      "main": [
        [
          {
            "node": "Send it now?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send it now?": {
      "main": [
        [
          {
            "node": "Send the alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "tags": []
}
