{
  "name": "Feedback Loop Closer",
  "nodes": [
    {
      "id": "afb7b48d-570e-469b-a84d-1d5b50f6b3e6",
      "name": "Weekly Feedback Review",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        100,
        300
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "50 8 * * 3"
            }
          ]
        }
      }
    },
    {
      "id": "317e4e04-b840-4db8-bf81-4faaa9581793",
      "name": "Get Customer Value",
      "type": "n8n-nodes-base.salesforce",
      "typeVersion": 1.1,
      "position": [
        300,
        300
      ],
      "parameters": {
        "resource": "search",
        "operation": "query",
        "query": "SELECT Amount, Account.Name FROM Opportunity WHERE IsWon = true"
      },
      "credentials": {
        "salesforceOAuth2Api": {
          "id": "553Tae1kPe5Wpthq",
          "name": "Salesforce account"
        }
      },
      "executeOnce": true,
      "alwaysOutputData": true
    },
    {
      "id": "6a77418d-d0e4-480f-8649-60663511b126",
      "name": "Get Support Tickets",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        500,
        300
      ],
      "parameters": {
        "resource": "row",
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": "B822UKLgJVgEHj8q",
          "cachedResultName": "Support Triage Log"
        },
        "returnAll": true
      },
      "executeOnce": true,
      "alwaysOutputData": true
    },
    {
      "id": "ddd7ccc2-4ed3-42f9-8bbc-078418f9b7b0",
      "name": "Get Touchpoints",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        700,
        300
      ],
      "parameters": {
        "resource": "row",
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": "4VwFmA1iJIEW3N3N",
          "cachedResultName": "Customer Touchpoints"
        },
        "returnAll": true
      },
      "executeOnce": true,
      "alwaysOutputData": true
    },
    {
      "id": "a5dfbf2b-6953-4177-a4f9-e2456219e7a7",
      "name": "Get Request Ledger",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        900,
        300
      ],
      "parameters": {
        "resource": "row",
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": "y8J38NAg5AFIl58Q",
          "cachedResultName": "Feature Request Ledger"
        },
        "returnAll": true
      },
      "executeOnce": true,
      "alwaysOutputData": true
    },
    {
      "id": "3947515c-6b30-45a5-9e32-28040ca6e1c0",
      "name": "Get Release Notes",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        1100,
        300
      ],
      "parameters": {
        "resource": "row",
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": "i7z9EWP9UQPUXbPo",
          "cachedResultName": "Release Notes"
        },
        "returnAll": true
      },
      "executeOnce": true,
      "alwaysOutputData": true
    },
    {
      "id": "5397581a-7458-4316-94c2-d0ceea336c48",
      "name": "Get Account Team",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        1300,
        300
      ],
      "parameters": {
        "resource": "row",
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": "2kpKzQwXkV4jVof7",
          "cachedResultName": "Account Team"
        },
        "returnAll": true
      },
      "executeOnce": true,
      "alwaysOutputData": true
    },
    {
      "id": "f1fc3bd7-2b24-4af4-8a8d-c9ac5d2428d4",
      "name": "Collect Requests & Releases",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1500,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "// Collect, in code, everything Claude needs and nothing it doesn't: feature-request tickets from the Support Triage log\n// (duplicates of the same email removed), customer notes from the last 90 days that are not yet in the ledger, the themes\n// already in the ledger, and releases shipped in the last 30 days that have not closed any request yet.\nconst runDate = $today.toFormat('yyyy-MM-dd');\nconst since = $today.minus({ days: 90 }).toFormat('yyyy-MM-dd'), relSince = $today.minus({ days: 30 }).toFormat('yyyy-MM-dd');\nconst ledger = $('Get Request Ledger').all().map(i => i.json).filter(r => r.requestId);\nconst seenSources = new Set(ledger.map(r => r.requestId.split('#')[0]));\nconst tickets = $('Get Support Tickets').all().map(i => i.json).filter(t => t.caseId && /feature request/i.test(t.category || ''))\n  .sort((a, b) => String(a.loggedAt).localeCompare(String(b.loggedAt)));\nconst firstOf = {}; let duplicateTickets = 0;\nfor (const t of tickets) { const k = (t.customerEmail + '|' + t.emailSubject).toLowerCase(); if (firstOf[k]) duplicateTickets++; else firstOf[k] = t; }\nconst sources = [\n  ...Object.values(firstOf).map(t => ({ sourceId: 'case:' + t.caseId, accountName: t.accountName, date: String(t.loggedAt).slice(0, 10), kind: 'support ticket', text: t.emailSubject.replace(/^\\[[^\\]]*\\]\\s*/, '') + '. ' + t.summary })),\n  ...$('Get Touchpoints').all().map(i => i.json).filter(n => n.accountName && n.date >= since)\n    .map(n => ({ sourceId: 'note:' + n.accountName + '|' + n.date + '|' + String(n.notes).slice(0, 24), accountName: n.accountName, date: n.date, kind: 'CSM note', text: n.notes }))\n].filter(s => !seenSources.has(s.sourceId));\nconst linked = new Set(ledger.map(r => r.releaseId).filter(Boolean));\nconst releases = $('Get Release Notes').all().map(i => i.json).filter(r => r.releaseId && r.shippedOn >= relSince && r.shippedOn <= runDate && !linked.has(r.releaseId))\n  .map(r => ({ releaseId: r.releaseId, title: r.title, notes: r.notes, shippedOn: r.shippedOn }));\nconst existingThemes = [...new Set(ledger.filter(r => r.status === 'open').map(r => r.theme))];\nreturn [{ json: { runDate, sources, releases, existingThemes, duplicateTickets, ticketCount: tickets.length } }];\n"
      },
      "executeOnce": true
    },
    {
      "id": "5de62fa1-4913-4903-bc1c-691c06c02e6c",
      "name": "Request Reader",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        300,
        450
      ],
      "parameters": {
        "promptType": "define",
        "text": "={{ JSON.stringify({ existingThemes: $json.existingThemes, sources: $json.sources.map(s => ({ sourceId: s.sourceId, kind: s.kind, text: s.text })), releases: $json.releases }, null, 1) }}",
        "hasOutputParser": true,
        "options": {
          "systemMessage": "You help product and customer success at Fortavault, Inc. (a fictional data protection company) close the loop on customer feedback. You get new support tickets and customer notes, the request themes already open, and recently shipped releases.\n\n1. requests: for each source that asks for something the product does not do today (a new capability, export, setting, report or workflow), return sourceId, request (one short plain sentence), quote (the exact words from that source that show the ask, copied word for word) and theme (a short name for the underlying need, 2 to 5 words). Reuse an existing theme name whenever the need is the same, and give the same theme to different customers asking for the same thing in different words. Skip bug reports, outages, things that were fixed, questions about pricing or buying more, and general updates.\n\n2. releaseMatches: for each release, list every theme (existing or from step 1) that it actually delivers, with releaseId, theme (exactly as named) and quote (the exact words from the release notes that deliver it). A release that only touches the same product area without delivering the ask does not match. Return empty lists when nothing applies."
        }
      },
      "executeOnce": true,
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 2000
    },
    {
      "id": "757be4b5-28e5-4954-a932-98f83e35359d",
      "name": "Claude Sonnet",
      "type": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
      "typeVersion": 1.3,
      "position": [
        100,
        450
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "claude-sonnet-4-6",
          "cachedResultName": "Claude Sonnet 4.6"
        },
        "options": {
          "temperature": 0
        }
      },
      "credentials": {
        "anthropicApi": {
          "id": "3d3ZiTi7BwnkFwqU",
          "name": "Anthropic account"
        }
      }
    },
    {
      "id": "735661a0-6cc1-4966-880d-b17f6795a8b1",
      "name": "Request Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.3,
      "position": [
        100,
        600
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n \"type\": \"object\",\n \"properties\": {\n  \"requests\": {\n   \"type\": \"array\",\n   \"items\": {\n    \"type\": \"object\",\n    \"properties\": {\n     \"sourceId\": {\n      \"type\": \"string\"\n     },\n     \"request\": {\n      \"type\": \"string\"\n     },\n     \"quote\": {\n      \"type\": \"string\"\n     },\n     \"theme\": {\n      \"type\": \"string\"\n     }\n    },\n    \"required\": [\n     \"sourceId\",\n     \"request\",\n     \"quote\",\n     \"theme\"\n    ]\n   }\n  },\n  \"releaseMatches\": {\n   \"type\": \"array\",\n   \"items\": {\n    \"type\": \"object\",\n    \"properties\": {\n     \"releaseId\": {\n      \"type\": \"string\"\n     },\n     \"theme\": {\n      \"type\": \"string\"\n     },\n     \"quote\": {\n      \"type\": \"string\"\n     }\n    },\n    \"required\": [\n     \"releaseId\",\n     \"theme\",\n     \"quote\"\n    ]\n   }\n  }\n },\n \"required\": [\n  \"requests\",\n  \"releaseMatches\"\n ]\n}"
      }
    },
    {
      "id": "6c6290ea-8126-45dc-b05b-1c5fbd88b2b8",
      "name": "Group, Rank & Close Loop",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        500,
        450
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "// Verify, group and route in code. A request counts only if its quote is word for word in its ticket or note; one account\n// asking twice for the same theme counts once. A release closes a theme only if Claude quotes the release notes word for\n// word. Themes are ranked by the Closed Won value of the accounts asking, and shipped themes list exactly who asked.\nconst c = $('Collect Requests & Releases').first().json;\nconst out = $('Request Reader').first().json.output || {};\nconst norm = s => String(s || '').replace(/[‘’]/g, \"'\").replace(/[“”]/g, '\"').replace(/\\s+/g, ' ').trim().toLowerCase();\nconst safe = t => String(t || '').replace(/~/g, '≈');\nconst value = {}; for (const o of $('Get Customer Value').all().map(i => i.json).filter(o => o.Account && o.Account.Name)) value[o.Account.Name] = (value[o.Account.Name] || 0) + (Number(o.Amount) || 0);\nconst team = {}; for (const t of $('Get Account Team').all().map(i => i.json).filter(r => r.accountName)) team[t.accountName] = t;\nconst src = {}; for (const s of c.sources) src[s.sourceId] = s;\nconst ledger = $('Get Request Ledger').all().map(i => i.json).filter(r => r.requestId);\nlet dropped = 0;\nconst fresh = [];\nconst keyOf = r => r.accountName + '|' + r.theme.toLowerCase();\nconst openKeys = new Set(ledger.filter(r => r.status === 'open').map(keyOf));\nfor (const r of (out.requests || [])) {\n  const s = src[r.sourceId];\n  if (!s || !r.theme || !r.quote || norm(r.quote).length < 12 || !norm(s.text).includes(norm(r.quote))) { dropped++; continue; }\n  const row = { requestId: s.sourceId + '#' + r.theme, theme: r.theme.trim(), accountName: s.accountName, request: r.request, quote: r.quote.trim(), source: s.kind,\n    requestedOn: s.date, status: 'open', releaseId: '', updatedOn: c.runDate };\n  if (openKeys.has(keyOf(row))) continue;   // same account, same theme already open\n  openKeys.add(keyOf(row)); fresh.push(row);\n}\nconst open = [...ledger.filter(r => r.status === 'open'), ...fresh];\nconst relById = {}; for (const r of c.releases) relById[r.releaseId] = r;\nconst shippedRows = [], shipped = [];\nfor (const m of (out.releaseMatches || [])) {\n  const rel = relById[m.releaseId];\n  const rows = open.filter(r => r.theme.toLowerCase() === String(m.theme).toLowerCase() && r.status === 'open');\n  if (!rel || !rows.length || !m.quote || !norm(rel.notes).includes(norm(m.quote))) continue;\n  for (const r of rows) { r.status = 'shipped'; r.releaseId = rel.releaseId; r.updatedOn = c.runDate; shippedRows.push(r); }\n  shipped.push({ rel, theme: m.theme, quote: m.quote, rows });\n}\nconst themes = {};\nfor (const r of open.filter(r => r.status === 'open')) {\n  const t = themes[r.theme] = themes[r.theme] || { theme: r.theme, accounts: new Set(), value: 0 };\n  if (!t.accounts.has(r.accountName)) { t.accounts.add(r.accountName); t.value += value[r.accountName] || 0; }\n}\nconst ranked = Object.values(themes).sort((a, b) => b.value - a.value || b.accounts.size - a.accounts.size);\nconst money = n => '$' + Math.round((n || 0) / 1000) + 'K';\nconst who = a => a + (value[a] ? ' (' + money(value[a]) + ')' : ' (no Closed Won in Salesforce)');\nconst owner = a => team[a] ? 'CSM ' + team[a].csm : 'no CSM: reply on the support ticket';\nlet text = ':speech_balloon: *Feedback Loop Closer* (' + c.runDate + ')\\n' +\n  (shipped.length ? '\\n:white_check_mark: *Shipped: tell the customers who asked*\\n' + shipped.map(s => '*' + s.rel.title + '* (' + s.rel.releaseId + ', ' + s.rel.shippedOn + ') delivers _' + s.theme + '_: “' + safe(s.quote) + '”\\n' +\n    s.rows.map(r => '      • *' + r.accountName + '* → ' + owner(r.accountName) + '. They asked (' + r.requestedOn + ', ' + r.source + '): _“' + safe(r.quote) + '”_').join('\\n')).join('\\n\\n') + '\\n' : '') +\n  '\\n*Open requests for product, by revenue asking* (' + ranked.length + ' themes)\\n' +\n  ranked.slice(0, 6).map((t, i) => (i + 1) + '. *' + t.theme + '* · ' + money(t.value) + ' Closed Won · ' + t.accounts.size + ' account' + (t.accounts.size === 1 ? '' : 's') + ': ' + [...t.accounts].join(', ')).join('\\n') +\n  '\\n_' + c.sources.length + ' new tickets and notes read; ' + fresh.length + ' new requests' + (c.duplicateTickets ? '; ' + c.duplicateTickets + ' duplicate ticket(s) of the same email ignored' : '') + (dropped ? '; ' + dropped + ' dropped: quote not found in the source' : '') + '._';\nif (text.length > 2900) text = text.slice(0, 2850).slice(0, text.slice(0, 2850).lastIndexOf('\\n')) + '\\n_…cut to fit Slack; every request is in the Feature Request Ledger._';\nconst byId = {}; for (const r of [...fresh, ...shippedRows]) byId[r.requestId] = r;\nconst rows = Object.values(byId).map(({ id, createdAt, updatedAt, ...r }) => r);\nreturn [{ json: { digestText: text, rows, counts: { fresh: fresh.length, shipped: shippedRows.length, themes: ranked.length, dropped } } }];\n"
      },
      "executeOnce": true
    },
    {
      "id": "a565ea32-d5e9-4a16-8b13-82ef39b5ae55",
      "name": "Post Feedback Digest",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.7,
      "position": [
        700,
        450
      ],
      "parameters": {
        "resource": "message",
        "operation": "post",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "C0BQ3G96HL6",
          "cachedResultName": "general"
        },
        "text": "={{ $json.digestText }}",
        "otherOptions": {
          "includeLinkToWorkflow": false
        }
      },
      "credentials": {
        "slackApi": {
          "id": "mv7TIi8kucFPqPg6",
          "name": "Slack account"
        }
      }
    },
    {
      "id": "4490f376-5571-4697-99e8-ab2e52236168",
      "name": "Split Ledger Rows",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        700,
        600
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "return $('Group, Rank & Close Loop').first().json.rows.map(json => ({ json }));"
      }
    },
    {
      "id": "f0276c89-082d-44d4-a19b-97f595eeb903",
      "name": "Update Request Ledger",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        900,
        600
      ],
      "parameters": {
        "resource": "row",
        "operation": "upsert",
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": "y8J38NAg5AFIl58Q",
          "cachedResultName": "Feature Request Ledger"
        },
        "matchType": "allConditions",
        "filters": {
          "conditions": [
            {
              "keyName": "requestId",
              "condition": "eq",
              "keyValue": "={{ $json.requestId }}"
            }
          ]
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {}
        }
      }
    }
  ],
  "connections": {
    "Weekly Feedback Review": {
      "main": [
        [
          {
            "node": "Get Customer Value",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Customer Value": {
      "main": [
        [
          {
            "node": "Get Support Tickets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Support Tickets": {
      "main": [
        [
          {
            "node": "Get Touchpoints",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Touchpoints": {
      "main": [
        [
          {
            "node": "Get Request Ledger",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Request Ledger": {
      "main": [
        [
          {
            "node": "Get Release Notes",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Release Notes": {
      "main": [
        [
          {
            "node": "Get Account Team",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Account Team": {
      "main": [
        [
          {
            "node": "Collect Requests & Releases",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Collect Requests & Releases": {
      "main": [
        [
          {
            "node": "Request Reader",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Request Reader": {
      "main": [
        [
          {
            "node": "Group, Rank & Close Loop",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Claude Sonnet": {
      "ai_languageModel": [
        [
          {
            "node": "Request Reader",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Request Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Request Reader",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Group, Rank & Close Loop": {
      "main": [
        [
          {
            "node": "Post Feedback Digest",
            "type": "main",
            "index": 0
          },
          {
            "node": "Split Ledger Rows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Ledger Rows": {
      "main": [
        [
          {
            "node": "Update Request Ledger",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}