{
  "id": "3oKFFAHQRqFtLdXveoxF5",
  "name": "Send severity-based error alerts for n8n workflows using Telegram and email",
  "tags": [],
  "nodes": [
    {
      "id": "72861743-6801-4c0a-8d3b-057391782d3e",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        224,
        -96
      ],
      "parameters": {
        "width": 576,
        "height": 560,
        "content": "## Workflow overview\n\nThis workflow provides a production-ready way to monitor n8n workflow failures.\n\nIt acts as a global error handler that listens for execution failures,\nclassifies them by severity, and sends alerts using different channels\nbased on how critical the error is.\n\n### How it works\n\u2022 Captures errors from linked workflows using the Error Trigger\n\u2022 Classifies errors into Critical, High, or Normal\n\u2022 Routes alerts based on severity\n\u2022 Sends notifications via Telegram and Email\n\u2022 Logs critical errors for later review\n\n### Setup steps\n1. Configure Telegram and Email credentials\n2. Replace placeholder values (Chat ID, Email, Sheet ID)\n3. Activate this workflow\n4. Assign it as the Error Workflow in other workflows\n5. Trigger a test error to verify alerts\n\nThis design helps reduce alert fatigue while ensuring critical issues\nare escalated immediately.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "c625da1a-a8c7-455e-bd6e-a2fdcce812c6",
      "name": "Send Alert",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1792,
        704
      ],
      "parameters": {
        "text": "={{ $('Severity-Based Routing').item.json.message }}",
        "chatId": "YOUR_CHAT_ID",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "21537f3e-e58f-436f-800e-245d28e48b6e",
      "name": "Format Message",
      "type": "n8n-nodes-base.set",
      "position": [
        608,
        688
      ],
      "parameters": {
        "values": {
          "string": [
            {
              "name": "message",
              "value": "=\ud83d\udea8 *n8n Workflow Error Alert*\n\n\u26a0\ufe0f *Severity:* {{ $json.severity }}\n\n\ud83d\udcdb *Workflow:* {{ $json.workflowName }}\n\n\ud83e\udde9 *Failed Node:* {{ $json.failedNode }}\n\n\u23f1 *Time:* {{ $json.time }}\n\n\ud83c\udd94 *Execution ID:* {{ $json.executionId }}\n\n\ud83d\udd17 *Execution URL:*\n{{ $json.executionUrl }}\n\n\u274c *Error Message:*\n{{ $json.errorMessage }}\n"
            }
          ]
        },
        "options": {
          "dotNotation": false
        },
        "keepOnlySet": true
      },
      "typeVersion": 1
    },
    {
      "id": "1a9e71db-04be-4429-81a1-8ff0a8a750bf",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        816,
        64
      ],
      "parameters": {
        "color": 7,
        "width": 464,
        "height": 176,
        "content": "## \ud83d\udc4b Need help with n8n automations?\n\n## \ud83c\udf10 https://abdallahhussein.com\n## Automation & Workflow Consulting"
      },
      "typeVersion": 1
    },
    {
      "id": "f3f6ec2e-3bb3-4002-a224-4b570d0d79f6",
      "name": "Error Trigger",
      "type": "n8n-nodes-base.errorTrigger",
      "position": [
        0,
        688
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "f4624aca-db6a-4996-99a6-17f907f39071",
      "name": "Classify Error & Context",
      "type": "n8n-nodes-base.code",
      "position": [
        288,
        688
      ],
      "parameters": {
        "jsCode": "const error = $json.execution?.error || {};\nconst message = (error.message || \"\").toLowerCase();\nconst httpCode = error.httpCode ? error.httpCode.toString() : \"\";\n\nlet severity = \"\ud83d\udfe1 Normal\";\n\n// \ud83d\udd34 Critical \u2013 Authentication & Permission errors\nif (\n  httpCode === \"401\" ||\n  httpCode === \"403\" ||\n  message.includes(\"unauthorized\") ||\n  message.includes(\"forbidden\") ||\n  message.includes(\"authentication\")\n) {\n  severity = \"\ud83d\udd34 Critical (Auth)\";\n}\n\n// \ud83d\udfe0 High \u2013 Timeouts & Server errors\nelse if (\n  message.includes(\"timeout\") ||\n  message.includes(\"timed out\") ||\n  httpCode.startsWith(\"5\")\n) {\n  severity = \"\ud83d\udfe0 High (Timeout / Server)\";\n}\n// \ud83d\udfe1 Normal \u2013 Everything else\nreturn [\n  {\n    severity,\n    workflowName: $json.workflow.name,\n    workflowId: $json.workflow.id,\n    failedNode: $json.execution.lastNodeExecuted,\n    executionId: $json.execution.id,\n    executionUrl: $json.execution.url,\n    errorMessage: error.message || \"Unknown error\",\n    time: $now.toFormat(\"yyyy-LL-dd HH:mm\"),\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "cddf5ddb-d2f2-4333-8479-ad3c8e939f08",
      "name": "Send an Email",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1264,
        528
      ],
      "parameters": {
        "sendTo": "YOUR_ALERT_EMAIL",
        "message": "={{ $('Format Message').item.json.message }}",
        "options": {
          "appendAttribution": false
        },
        "subject": "=Critical Error in Workflow : {{ $('Classify Error & Context').item.json.workflowName }} ",
        "emailType": "text"
      },
      "typeVersion": 2.2
    },
    {
      "id": "8057ea85-b3b8-44ba-bf65-ff8603090102",
      "name": "Add Logs to Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1520,
        528
      ],
      "parameters": {
        "columns": {
          "value": {
            "Severity": "={{ $('Classify Error & Context').item.json.severity }}",
            "Failed Node": "={{ $('Classify Error & Context').item.json.failedNode }}",
            "Execution ID": "={{ $('Classify Error & Context').item.json.executionId }}",
            "Error Message": "={{ $('Classify Error & Context').item.json.errorMessage }}",
            "Execution URL": "={{ $('Classify Error & Context').item.json.executionUrl }}",
            "Workflow Name": "={{ $('Classify Error & Context').item.json.workflowName }}"
          },
          "schema": [
            {
              "id": "Workflow Name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Workflow Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Severity",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Severity",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Execution ID",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Execution ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Execution URL",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Execution URL",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Failed Node",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Failed Node",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Error Message",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Error Message",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "id",
          "value": "=YOUR_SHEET_ID"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "=YOUR_Document_ID"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "2f238c72-7b24-4574-aa10-fae12bfdd9e9",
      "name": "Severity-Based Routing",
      "type": "n8n-nodes-base.switch",
      "position": [
        944,
        688
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "\ud83d\udd34 Critical ",
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "3e69dcfa-1fa7-4d12-9afc-1c114ce2e396",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('Classify Error & Context').item.json.severity }}",
                    "rightValue": "\ud83d\udd34 Critical (Auth)"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "\ud83d\udfe1 Normal",
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "db78bb0c-09c4-4da1-acac-66436e27ae95",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('Classify Error & Context').item.json.severity }}",
                    "rightValue": "\ud83d\udfe1 Normal"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "\ud83d\udfe0 High",
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "87c91c9b-1bd2-4d8d-9b86-65c3334b198e",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('Classify Error & Context').item.json.severity }}",
                    "rightValue": "\ud83d\udfe0 High (Timeout / Server)"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.4
    },
    {
      "id": "e6086824-960b-4591-a7d8-741d9929ac43",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        192,
        480
      ],
      "parameters": {
        "color": 7,
        "width": 288,
        "height": 352,
        "content": "## Error classification\n\nErrors are analyzed and classified into:\n\u2022 Critical (auth & permission issues)\n\u2022 High (timeouts & server errors)\n\u2022 Normal (all other errors)\n\nThis enables smarter alert routing.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "a773399f-2ebd-42d5-a6c3-c48fd4bbe363",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        848,
        464
      ],
      "parameters": {
        "color": 7,
        "width": 336,
        "height": 400,
        "content": "## Severity-based routing\n\nErrors are routed depending on severity:\n\u2022 Critical \u2192 Email + Telegram + Logging\n\u2022 High \u2192 Telegram\n\u2022 Normal \u2192 Telegram\n\nThis ensures proper escalation without noise.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "b468c730-fa6b-4a33-8840-d86dce477e21",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        512,
        480
      ],
      "parameters": {
        "color": 7,
        "width": 288,
        "height": 352,
        "content": "## Alert formatting\n\nBuilds a readable alert message with\nworkflow name, failed node, execution time,\nerror message, and execution link.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "87b21e3c-5f80-48b1-b82e-3d04278a3e87",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1440,
        368
      ],
      "parameters": {
        "color": 7,
        "width": 272,
        "height": 336,
        "content": "## Error logging\n\nCritical errors are logged for auditing\nand historical review using Google Sheets.\n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "db72c481-2f08-4dcf-b516-d8d1512203fb",
  "connections": {
    "Error Trigger": {
      "main": [
        [
          {
            "node": "Classify Error & Context",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send an Email": {
      "main": [
        [
          {
            "node": "Add Logs to Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Message": {
      "main": [
        [
          {
            "node": "Severity-Based Routing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Logs to Sheet": {
      "main": [
        [
          {
            "node": "Send Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Severity-Based Routing": {
      "main": [
        [
          {
            "node": "Send an Email",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Alert",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Classify Error & Context": {
      "main": [
        [
          {
            "node": "Format Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}