{
  "name": "INV 00 - Finance Error Handler",
  "nodes": [
    {
      "name": "Purpose",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -720,
        -260
      ],
      "parameters": {
        "content": "## Finance workflow error handler\nSanitises failures and alerts the owner in Telegram. Do not include invoice email bodies or credentials in alerts.",
        "height": 250,
        "width": 560,
        "color": 5
      }
    },
    {
      "name": "Workflow Error Trigger",
      "type": "n8n-nodes-base.errorTrigger",
      "typeVersion": 1,
      "position": [
        -660,
        60
      ],
      "parameters": {}
    },
    {
      "name": "Format Safe Finance Error",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -380,
        60
      ],
      "parameters": {
        "jsCode": "const p=$json; const e=p.execution??{}; const t=p.trigger??{}; const w=p.workflow??{}; const err=e.error??t.error??{};\nconst safe=String(err.message??err.cause?.message??'Unknown error').replace(/[\\r\\n]+/g,' ').slice(0,700);\nconst at=new Date().toISOString();\nreturn [{json:{alert_text:`🚨 <b>SMART INVOICE ERROR</b>\\n\\nWorkflow: ${w.name??'Unknown'}\\nExecution: ${e.id??'not saved'}\\nNode: ${e.lastNodeExecuted??err.node?.name??'unknown'}\\nError: ${safe}\\nTime: ${at}${e.url?`\\n${e.url}`:''}`}}];"
      }
    },
    {
      "name": "Alert Owner on Telegram",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        -80,
        60
      ],
      "parameters": {
        "resource": "message",
        "operation": "sendMessage",
        "chatId": "OWNER_CHAT_ID",
        "text": "={{ $json.alert_text }}",
        "additionalFields": {
          "parse_mode": "HTML",
          "appendAttribution": false
        }
      }
    }
  ],
  "connections": {
    "Workflow Error Trigger": {
      "main": [
        [
          {
            "node": "Format Safe Finance Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Safe Finance Error": {
      "main": [
        [
          {
            "node": "Alert Owner on Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "timezone": "TIMEZONE",
    "saveManualExecutions": true,
    "saveExecutionProgress": true,
    "saveDataErrorExecution": "all",
    "saveDataSuccessExecution": "all",
    "executionTimeout": 300
  },
  "pinData": {},
  "tags": []
}
