{
  "name": "RFP 00 - Production Error Handler",
  "nodes": [
    {
      "id": "a0fb821bdaf93ed9",
      "name": "Purpose",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -780,
        -300
      ],
      "parameters": {
        "content": "## Production error handler\nReceives failures from the five operational workflows, removes likely email/phone content, and alerts the owner without exposing proposal text or credentials.",
        "width": 620,
        "height": 260,
        "color": 5
      }
    },
    {
      "id": "5c43342f00d61928",
      "name": "Workflow Error Trigger",
      "type": "n8n-nodes-base.errorTrigger",
      "typeVersion": 1,
      "position": [
        -720,
        40
      ],
      "parameters": {}
    },
    {
      "id": "2a5e7a52a64f9094",
      "name": "Create Safe Error Event",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -440,
        40
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const p=$json; const e=p.execution??{}; const err=e.error??p.trigger?.error??{};\nconst safe=String(err.message??err.cause?.message??\"Unknown error\").replace(/[\\r\\n]+/g,\" \").replace(/[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,}/gi,\"[email removed]\").replace(/\\+?\\d[\\d\\s().-]{7,}\\d/g,\"[phone removed]\").slice(0,600);\nreturn [{json:{event_id:`ERR-${Date.now()}`,workflow:p.workflow?.name??\"Unknown\",execution_id:e.id??\"\",node:e.lastNodeExecuted??\"unknown\",severity:\"HIGH\",summary:safe,status:\"OPEN\",created_at:new Date().toISOString(),alert_text:`🚨 <b>RFP CONTROL ROOM ERROR</b>\\n\\nWorkflow: ${p.workflow?.name??\"Unknown\"}\\nNode: ${e.lastNodeExecuted??\"unknown\"}\\nError: ${safe}\\nTime: ${new Date().toISOString()}${e.url?`\\n${e.url}`:\"\"}`}}];"
      }
    },
    {
      "id": "d3a8ee2d488c9bc1",
      "name": "Alert Owner on Telegram",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        -140,
        -20
      ],
      "parameters": {
        "resource": "message",
        "operation": "sendMessage",
        "chatId": "SET_OWNER_TELEGRAM_CHAT_ID",
        "text": "={{ $json.alert_text }}",
        "additionalFields": {
          "parse_mode": "HTML",
          "appendAttribution": false
        }
      }
    },
    {
      "id": "5598a1360549fc2e",
      "name": "Alert Owner by Email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        -140,
        100
      ],
      "parameters": {
        "resource": "email",
        "operation": "send",
        "fromEmail": "Sales Evidence Control Room <SET_FROM_EMAIL>",
        "toEmail": "SET_OWNER_EMAIL",
        "subject": "RFP Control Room workflow error",
        "emailFormat": "text",
        "text": "={{ $json.alert_text.replace(/<[^>]+>/g, '') }}",
        "options": {
          "appendAttribution": false
        }
      }
    },
    {
      "id": "fd937ed1176347a5",
      "name": "Append Exception Queue",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        180,
        40
      ],
      "parameters": {
        "authentication": "oAuth2",
        "resource": "sheet",
        "operation": "append",
        "documentId": {
          "mode": "id",
          "value": "SET_OPERATIONS_WORKBOOK_ID"
        },
        "sheetName": {
          "mode": "name",
          "value": "Exception Queue"
        },
        "dataMode": "autoMapInputData",
        "options": {
          "handlingExtraData": "ignoreIt"
        }
      },
      "alwaysOutputData": false
    }
  ],
  "connections": {
    "Workflow Error Trigger": {
      "main": [
        [
          {
            "node": "Create Safe Error Event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Safe Error Event": {
      "main": [
        [
          {
            "node": "Alert Owner on Telegram",
            "type": "main",
            "index": 0
          },
          {
            "node": "Alert Owner by Email",
            "type": "main",
            "index": 0
          },
          {
            "node": "Append Exception Queue",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "timezone": "Africa/Lagos",
    "saveManualExecutions": true,
    "saveExecutionProgress": true,
    "saveDataErrorExecution": "all",
    "saveDataSuccessExecution": "all",
    "executionTimeout": 600
  }
}
