{
 "name": "TWWP: meeting notes into tickets with owners (UC-0741)",
 "nodes": [
  {
   "parameters": {
    "httpMethod": "POST",
    "path": "twwp-meeting-notes",
    "responseMode": "responseNode",
    "options": {}
   },
   "id": "webhook",
   "name": "Webhook (synthetic input)",
   "type": "n8n-nodes-base.webhook",
   "typeVersion": 2,
   "position": [
    0,
    0
   ],
   "webhookId": "6dd31185-73e6-5788-9d0c-31470e355c31"
  },
  {
   "parameters": {
    "jsCode": "const b = $input.first().json.body || {};\nconst hint = (b.approved !== undefined && typeof b.approved !== 'boolean') ? 'approved must be true or false, written without quotes (not yes, and not \"true\")' : undefined;\nconst lines = String(b.transcript || '').split(/\\r?\\n/).map(s => s.trim()).filter(Boolean);\nconst actions = [];\nfor (const line of lines) {\n  const m = line.match(/^(?:[A-Za-z]+:\\s*)?(?:ACTION|TODO)\\s*[:\\-]\\s*(.+)$/i);\n  if (!m) continue;\n  const text = m[1].trim();\n  const owner = (text.match(/@([A-Za-z][\\w-]*)/) || [])[1] || null;\n  const due = (text.match(/\\bby\\s+(Monday|Tuesday|Wednesday|Thursday|Friday|\\d{4}-\\d{2}-\\d{2})\\b/i) || [])[1] || null;\n  actions.push({ title: text.replace(/@[A-Za-z][\\w-]*/g, '').replace(/\\s+/g, ' ').replace(/\\s*\\bby\\s+\\S+\\s*$/i, '').trim(), owner, due, needs_owner: owner === null });\n}\nconst message = actions.length ? undefined : 'No lines starting with ACTION: were found. Write each task on its own line, like this: ACTION: Update the pricing page @dana by Thursday';\nreturn [{ json: { hint, meeting: b.meeting || 'untitled', actions, message, hold_reasons: actions.length ? [] : ['no action lines found'] } }];"
   },
   "id": "extract-and-decide",
   "name": "Extract and decide",
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "position": [
    240,
    0
   ]
  },
  {
   "parameters": {
    "jsCode": "// DEMO ONLY. A person's approval is stood in for by the request field approved === true, so the tests run without a screen.\n// In real use replace this node with a SEPARATE approval step (a person's click or a signed event: authenticated, bound to this exact draft, asked again if the draft changes).\n// FIXED LOGIC, not a model field: anything that would send, pay or change data ALWAYS waits for approval. The extract / AI step can only ADD reasons to hold (hold_reasons);\n// it can never remove the hold, skip the approval, or open the gate. A missing or malformed hold_reasons is treated as a hold.\nconst j = $input.first().json;\nconst body = ($('Webhook (synthetic input)').first().json.body) || {};\nconst approved = body.approved === true;\nconst modelHolds = !Array.isArray(j.hold_reasons) || j.hold_reasons.length > 0;\nreturn [{ json: { ...j, gate_open: approved && !modelHolds } }];"
   },
   "id": "approval-check-(demo-toggle)",
   "name": "Approval check (demo toggle)",
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "position": [
    360,
    0
   ]
  },
  {
   "parameters": {
    "conditions": {
     "options": {
      "caseSensitive": true,
      "leftValue": "",
      "typeValidation": "strict"
     },
     "conditions": [
      {
       "id": "approved",
       "leftValue": "={{ $json.gate_open }}",
       "rightValue": true,
       "operator": {
        "type": "boolean",
        "operation": "true",
        "singleValue": true
       }
      }
     ],
     "combinator": "and"
    },
    "options": {}
   },
   "id": "gate",
   "name": "Approval gate",
   "type": "n8n-nodes-base.if",
   "typeVersion": 2.2,
   "position": [
    600,
    0
   ]
  },
  {
   "parameters": {
    "jsCode": "const j = $input.first().json;\nconst tickets = j.actions.map((a, i) => ({ id: 'LOCAL-' + String(i + 1).padStart(3, '0'), title: a.title, owner: a.owner || 'UNASSIGNED', due: a.due }));\nreturn [{ json: { status: 'tickets_ready', meeting: j.meeting, count: tickets.length, tickets } }];"
   },
   "id": "local-stub-(drafts-only)",
   "name": "Local stub (drafts only)",
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "position": [
    840,
    -100
   ]
  },
  {
   "parameters": {
    "jsCode": "const j = $input.first().json;\nreturn [{ json: { ...(j.hint ? { approval_hint: j.hint } : {}), status: 'held_for_approval', meeting: j.meeting, proposed: j.actions, unassigned: j.actions.filter(a => a.needs_owner).length, ...(j.message ? { message: j.message } : {}) } }];"
   },
   "id": "hold-for-approval",
   "name": "Hold for approval",
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "position": [
    840,
    100
   ]
  },
  {
   "parameters": {
    "respondWith": "json",
    "responseBody": "={{ $json }}",
    "options": {}
   },
   "id": "respond:-released",
   "name": "Respond: released",
   "type": "n8n-nodes-base.respondToWebhook",
   "typeVersion": 1.1,
   "position": [
    1080,
    -100
   ]
  },
  {
   "parameters": {
    "respondWith": "json",
    "responseBody": "={{ $json }}",
    "options": {}
   },
   "id": "respond:-held",
   "name": "Respond: held",
   "type": "n8n-nodes-base.respondToWebhook",
   "typeVersion": 1.1,
   "position": [
    1080,
    100
   ]
  },
  {
   "parameters": {
    "content": "APPROVAL GATE (demo): the PM approves the list (approved=true). Nothing becomes a ticket until then, and an empty list is never approved. The request field approved stands in for a person: in real use replace the Approval check node with a separate, authenticated approval bound to the draft, never model output. Synthetic data only. No node here sends anything outside this machine; the 'AI step' is a deterministic stand-in to swap for an AI node.",
    "height": 230,
    "width": 440
   },
   "id": "note",
   "name": "Note",
   "type": "n8n-nodes-base.stickyNote",
   "typeVersion": 1,
   "position": [
    560,
    -220
   ]
  }
 ],
 "connections": {
  "Webhook (synthetic input)": {
   "main": [
    [
     {
      "node": "Extract and decide",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Extract and decide": {
   "main": [
    [
     {
      "node": "Approval check (demo toggle)",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Approval check (demo toggle)": {
   "main": [
    [
     {
      "node": "Approval gate",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Approval gate": {
   "main": [
    [
     {
      "node": "Local stub (drafts only)",
      "type": "main",
      "index": 0
     }
    ],
    [
     {
      "node": "Hold for approval",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Local stub (drafts only)": {
   "main": [
    [
     {
      "node": "Respond: released",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Hold for approval": {
   "main": [
    [
     {
      "node": "Respond: held",
      "type": "main",
      "index": 0
     }
    ]
   ]
  }
 },
 "settings": {
  "executionOrder": "v1",
  "saveDataSuccessExecution": "none",
  "saveDataErrorExecution": "none"
 },
 "id": "twwp0741meetingnotes",
 "active": false,
 "pinData": {},
 "tags": []
}