{
  "name": "Digest an incident channel",
  "nodes": [
    {
      "parameters": {
        "content": "## Digest an incident channel\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": "97ae30bc-37bf-4293-a79f-a0d79770c176",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        -40
      ]
    },
    {
      "parameters": {},
      "id": "b59a208d-705c-4589-bd9e-3efd9ad39f27",
      "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": "incident-channel-digest",
        "authentication": "none",
        "responseMode": "lastNode",
        "responseData": "firstEntryJson",
        "options": {}
      },
      "id": "1ce6fadc-4188-4c19-bc3d-fb8ce250e204",
      "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": "34d17ffb-6b6b-410e-9fd3-b1f6f4c3376a"
    },
    {
      "parameters": {
        "trigger": [
          "message"
        ],
        "watchWorkspace": false,
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_SLACK_CHANNEL_ID"
        }
      },
      "id": "3d1a6540-786e-4c33-9f37-84821f3388a6",
      "name": "Slack trigger",
      "type": "n8n-nodes-base.slackTrigger",
      "typeVersion": 1,
      "position": [
        40,
        640
      ],
      "credentials": {
        "slackApi": {
          "id": "PLACEHOLDER_SLACKAPI",
          "name": "Slack bot"
        }
      },
      "notes": "Watches a channel for messages that should become tasks. Demo uses the sample message.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const sample = {\n  \"demo\": true,\n  \"text\": \"@leo Checkout 500 started 08:10. Payments paused.\\nDue 2026-11-25.\",\n  \"channel\": \"#incidents\",\n  \"source\": \"slack\"\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": "13378034-bf11-4ac0-987d-ec08d610bf58",
      "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 text = String(item.text || item.message || '').trim();\nconst owner = (text.match(/@([a-z0-9._-]+)/i) || [])[1] || item.owner || 'unassigned';\nconst due = (text.match(/due\\s+(\\d{4}-\\d{2}-\\d{2})/i) || [])[1] || item.due || '';\nconst urgent = /urgent|asap|today|blocker|sev-?1/i.test(text);\nconst title = text.split('\\n')[0].slice(0, 100) || 'Untitled task';\nconst record = {\n  title,\n  body: text,\n  owner,\n  due,\n  priority: urgent ? 'high' : 'normal',\n  source: item.source || 'slack',\n  channel: item.channel || '',\n};\nreturn {\n  summary: 'Task for ' + owner + (due ? ' due ' + due : '') + ': ' + title,\n  route: urgent ? 'urgent' : 'normal',\n  record,\n  slackText: 'Created a Notion task for ' + owner + ': ' + title,\n  actions: [{ app: 'Notion', operation: 'create task', 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": "f51fcbda-5c33-480b-99f0-0c9690fcf312",
      "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": "40f00fed-c9c8-45d3-b7ff-cdb80865e3bd",
              "leftValue": "={{ $json.demo }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "d809cfb5-d6a2-4547-9eb6-1c5e4d958f70",
      "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: 'incident-channel-digest',\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": "e8ddc8ed-1015-4997-aa34-1f8cd8324731",
      "name": "Package demo result",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1180,
        180
      ]
    },
    {
      "parameters": {
        "authentication": "apiKey",
        "resource": "page",
        "operation": "create",
        "pageId": {
          "__rl": true,
          "mode": "url",
          "value": "https://www.notion.so/0123456789abcdef0123456789abcdef"
        },
        "title": "={{ $json.record.title || $json.summary }}",
        "blockUi": {
          "blockValues": []
        }
      },
      "id": "280a1755-6fbd-4a9a-a635-186073d4c4f3",
      "name": "Create Notion page",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.2,
      "position": [
        1180,
        760
      ],
      "credentials": {
        "notionApi": {
          "id": "PLACEHOLDER_NOTIONAPI",
          "name": "Notion account"
        }
      }
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "sheet",
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_SPREADSHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Incidents"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {},
          "matchingColumns": [],
          "schema": []
        },
        "options": {}
      },
      "id": "650f6001-4fc7-47aa-8f3f-32ab21acee24",
      "name": "Append Incidents",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        1460,
        760
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "PLACEHOLDER_GOOGLESHEETSOAUTH2API",
          "name": "Google Sheets 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": "9b1cc232-726c-4382-999b-ce4087844a2d",
      "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
          }
        ]
      ]
    },
    "Slack trigger": {
      "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": "Create Notion page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Notion page": {
      "main": [
        [
          {
            "node": "Append Incidents",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "meta": {
    "templateCredsSetupCompleted": false,
    "description": "Incident channel messages are reduced to a timeline note with an owner, then stored in Notion and a sheet."
  },
  "active": false
}
