{
  "name": "Escalate an outage ticket to on-call",
  "nodes": [
    {
      "parameters": {
        "content": "## Escalate an outage ticket to on-call\n\nPortfolio demo only. This workflow is an original example for demonstration. It is not client work and it does not represent a deployment for any customer.\n\nRun **Run demo** to execute the offline rules engine. The live branch is used only when the incoming item sets `demo` to false and the placeholder credentials have been replaced.",
        "height": 220,
        "width": 520,
        "color": 4
      },
      "id": "30c89932-b919-4b8a-835b-e7b31987e7e3",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        -40
      ]
    },
    {
      "parameters": {},
      "id": "47f322ed-937b-451b-a01c-ef116fd308f6",
      "name": "Run demo",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        40,
        280
      ],
      "notes": "CLI and the n8n editor start here. An empty manual run loads the bundled sample.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "oncall-escalation",
        "authentication": "none",
        "responseMode": "lastNode",
        "responseData": "firstEntryJson",
        "options": {}
      },
      "id": "cd5875cb-6bbe-4e3a-8013-ccfdc02bce4c",
      "name": "Inbound webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        40,
        460
      ],
      "notes": "POST JSON to this path. Include demo:false only after credentials are connected.",
      "notesInFlow": true,
      "webhookId": "c8f202c7-9196-469d-9c5a-9c1482e02956"
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const sample = {\n  \"demo\": true,\n  \"from\": \"ada@northwind.example\",\n  \"subject\": \"Checkout returns 500\",\n  \"body\": \"The checkout is broken and returns a 500 after submit.\",\n  \"email\": \"ada@northwind.example\"\n};\nconst incoming = $input.first()?.json ?? {};\nconst provided = Object.keys(incoming).filter((key) => incoming[key] !== undefined && incoming[key] !== null && incoming[key] !== '');\nconst base = provided.length ? { ...sample, ...incoming } : { ...sample };\nconst flag = incoming.demo;\nbase.demo = !(flag === false || flag === 'false' || flag === 0 || flag === '0');\nreturn [{ json: base }];\n"
      },
      "id": "3878e2cc-b1a5-446f-b4fd-4851e3b0a680",
      "name": "Normalize input",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        340,
        360
      ],
      "notes": "Merges the request over the bundled sample. demo stays true unless the caller explicitly turns it off.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const item = $input.first().json;\nconst produced = (() => {\n\nconst haystack = String(item.body || item.body || item.subject || item.summary || '').toLowerCase();\nconst hits = [];\nif (['refund', 'invoice', 'charge', 'payment'].some((word) => haystack.includes(word))) {\n  hits.push({ id: 'billing', label: 'Billing', weight: 3 });\n}\nif (['error', 'bug', 'broken', 'down', '500'].some((word) => haystack.includes(word))) {\n  hits.push({ id: 'technical', label: 'Technical', weight: 3 });\n}\nif (['login', 'password', 'access', 'invite'].some((word) => haystack.includes(word))) {\n  hits.push({ id: 'account', label: 'Account', weight: 2 });\n}\nif (['hello', 'question'].some((word) => haystack.includes(word))) {\n  hits.push({ id: 'general', label: 'General', weight: 1 });\n}\nhits.sort((a, b) => b.weight - a.weight);\nconst winner = hits[0] || { id: 'general', label: 'general', weight: 0 };\nconst draft = item.draft || ('Thanks for the note. We logged this as ' + winner.label + ' and will follow up shortly.');\nconst record = {\n  label: winner.id,\n  labelName: winner.label,\n  confidence: hits.length ? Math.min(0.95, 0.45 + hits.length * 0.15) : 0.3,\n  subject: item.subject || winner.label,\n  body: draft,\n  email: item.from || item.email || '',\n  priority: winner.id,\n  title: (item.subject || winner.label),\n};\nreturn {\n  summary: 'Ticket classified as ' + winner.label + ' (' + record.confidence.toFixed(2) + ').',\n  route: winner.id,\n  record,\n  slackText: winner.label + ': ' + (item.subject || haystack.slice(0, 80)),\n  actions: [{ app: 'mailbox', operation: 'label-and-draft', payload: record }],\n};\n\n})();\nif (!produced || typeof produced.summary !== 'string' || !produced.summary.trim()) {\n  throw new Error('Apply rules must return a summary string');\n}\nreturn [{\n  json: {\n    ...item,\n    ...produced,\n    demo: item.demo !== false,\n  },\n}];\n"
      },
      "id": "6f21a8c7-be21-4ee9-a7af-172999a1f312",
      "name": "Apply rules",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        620,
        360
      ],
      "notes": "Deterministic stand-in for the model or enrichment API. Replace or precede this with a live model node when you turn demo mode off.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "c2c45b41-cc35-4731-bdbb-3864daba7f12",
              "leftValue": "={{ $json.demo }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "1c45b19f-f1b0-4e3a-a68d-7d18e9f119b2",
      "name": "Demo mode?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        900,
        360
      ],
      "notes": "True: package the offline result. False: run the credentialed apps.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const item = $input.first().json;\nreturn [{\n  json: {\n    demo: true,\n    status: 'demo_ready',\n    workflow: 'oncall-escalation',\n    summary: item.summary,\n    route: item.route ?? null,\n    record: item.record ?? {},\n    actions: item.actions ?? [],\n    slackText: item.slackText ?? item.summary,\n    notes: 'Demo mode did not call external apps. Send {\"demo\": false} after placeholder credentials are replaced.',\n  },\n}];\n"
      },
      "id": "0a053b2b-1733-4825-905e-b280246f89c2",
      "name": "Package demo result",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1180,
        180
      ]
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "message",
        "operation": "post",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "name",
          "value": "#incidents"
        },
        "text": "={{ $json.slackText || $json.summary }}",
        "otherOptions": {}
      },
      "id": "bc4a8d37-7cf0-4f7d-9b24-a4ba0586b612",
      "name": "Post #incidents",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [
        1180,
        760
      ],
      "credentials": {
        "slackOAuth2Api": {
          "id": "PLACEHOLDER_SLACKOAUTH2API",
          "name": "Slack account"
        }
      }
    },
    {
      "parameters": {
        "resource": "sms",
        "operation": "send",
        "from": "={{ $json.record.from || '+15555550100' }}",
        "to": "={{ $json.record.to || $json.record.phone || $json.phone }}",
        "message": "={{ $json.record.message || $json.slackText || $json.summary }}",
        "twiml": "={{ $json.record.twiml || '<Response><Say>We will call you back shortly.</Say></Response>' }}"
      },
      "id": "90cefb05-f854-4446-8e05-f86d50047a12",
      "name": "Send SMS",
      "type": "n8n-nodes-base.twilio",
      "typeVersion": 1,
      "position": [
        1460,
        760
      ],
      "credentials": {
        "twilioApi": {
          "id": "PLACEHOLDER_TWILIOAPI",
          "name": "Twilio account"
        }
      }
    },
    {
      "parameters": {
        "authentication": "apiToken",
        "resource": "ticket",
        "operation": "create",
        "description": "={{ $json.record.body || $json.summary }}",
        "jsonParameters": false,
        "additionalFields": {
          "subject": "={{ $json.record.subject || $json.summary }}"
        }
      },
      "id": "cbf362dc-e809-4bc6-8046-26656e26a7b4",
      "name": "Create Zendesk ticket",
      "type": "n8n-nodes-base.zendesk",
      "typeVersion": 1,
      "position": [
        1740,
        760
      ],
      "credentials": {
        "zendeskApi": {
          "id": "PLACEHOLDER_ZENDESKAPI",
          "name": "Zendesk account"
        }
      }
    },
    {
      "parameters": {
        "content": "## Live path\n\nReplace every `PLACEHOLDER_*` credential, then POST the sample with `\"demo\": false`.\n\nThe nodes on this branch use the `record` and `actions` fields produced by Apply rules.",
        "height": 180,
        "width": 420,
        "color": 6
      },
      "id": "d7145ad6-f003-4d78-86df-5bf037933573",
      "name": "Live path",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1120,
        520
      ]
    }
  ],
  "connections": {
    "Run demo": {
      "main": [
        [
          {
            "node": "Normalize input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Inbound webhook": {
      "main": [
        [
          {
            "node": "Normalize input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize input": {
      "main": [
        [
          {
            "node": "Apply rules",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Apply rules": {
      "main": [
        [
          {
            "node": "Demo mode?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Demo mode?": {
      "main": [
        [
          {
            "node": "Package demo result",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Post #incidents",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Post #incidents": {
      "main": [
        [
          {
            "node": "Send SMS",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send SMS": {
      "main": [
        [
          {
            "node": "Create Zendesk ticket",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "meta": {
    "templateCredsSetupCompleted": false,
    "description": "Technical tickets that mention an outage or a 500 page Slack and text the on-call number. Other classes stay in Zendesk."
  },
  "active": false
}
