{
  "name": "Handoff Promise Ledger",
  "nodes": [
    {
      "id": "6cf3d5c3-d72c-46b8-ad72-0a50836a5062",
      "name": "Daily Handoff Check",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        100,
        300
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "10 8 * * 1-5"
            }
          ]
        }
      }
    },
    {
      "id": "c1b625bf-f939-4368-8561-f724dce27ba3",
      "name": "Get Closed Won Deals",
      "type": "n8n-nodes-base.salesforce",
      "typeVersion": 1.1,
      "position": [
        300,
        300
      ],
      "parameters": {
        "resource": "search",
        "operation": "query",
        "query": "SELECT Id, Name, CloseDate, Amount, Description, NextStep, Account.Name FROM Opportunity WHERE IsWon = true AND CloseDate = LAST_N_DAYS:120"
      },
      "credentials": {
        "salesforceOAuth2Api": {
          "id": "553Tae1kPe5Wpthq",
          "name": "Salesforce account"
        }
      },
      "executeOnce": true,
      "alwaysOutputData": true
    },
    {
      "id": "28553f81-caec-4056-bf8b-233cdede0341",
      "name": "Get Handoff Log",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        500,
        300
      ],
      "parameters": {
        "resource": "row",
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": "seqawgOX8XWCbgDu",
          "cachedResultName": "Handoff Log"
        },
        "returnAll": true
      },
      "executeOnce": true,
      "alwaysOutputData": true
    },
    {
      "id": "9bfa6c95-f198-4452-9ca5-8c442d98dbb4",
      "name": "Get Promise Ledger",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        700,
        300
      ],
      "parameters": {
        "resource": "row",
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": "YoJf0J9Hd2WLnA14",
          "cachedResultName": "Promise Ledger"
        },
        "returnAll": true
      },
      "executeOnce": true,
      "alwaysOutputData": true
    },
    {
      "id": "e82720e2-47b3-4359-80b9-2010225a1fb8",
      "name": "Find New Handoffs & Due Promises",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        900,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "// Decide in code what needs attention today: Closed Won deals since go-live with no handoff yet,\n// and promises in the ledger that are overdue or due within 7 days.\nconst runDate = $today.toFormat('yyyy-MM-dd');\nconst GO_LIVE = '2026-09-01';   // deals closed before the ledger went live need a separate backfill\nconst DAY = 86400000;\nconst days = (a, b) => Math.round((Date.parse(b + 'T00:00:00Z') - Date.parse(a + 'T00:00:00Z')) / DAY);\nconst won = $('Get Closed Won Deals').all().map(i => i.json).filter(o => o.Id && o.CloseDate >= GO_LIVE);\nconst handed = new Set($('Get Handoff Log').all().map(i => i.json.dealId).filter(Boolean));\nconst newDeals = won.filter(o => !handed.has(o.Id)).map(o => ({ runDate, dealId: o.Id, dealName: o.Name, accountName: (o.Account || {}).Name || '',\n  closeDate: o.CloseDate, amount: Number(o.Amount) || 0, notes: [o.Description, o.NextStep ? 'Next step: ' + o.NextStep : ''].filter(Boolean).join('\\n') }));\nconst ledger = $('Get Promise Ledger').all().map(i => i.json).filter(p => p.promiseId && p.status === 'open');\nconst overdue = ledger.filter(p => p.dueDate && p.dueDate < runDate).map(p => ({ ...p, daysOverdue: days(p.dueDate, runDate) })).sort((a, b) => b.daysOverdue - a.daysOverdue);\nconst dueSoon = ledger.filter(p => p.dueDate && p.dueDate >= runDate && days(runDate, p.dueDate) <= 7).map(p => ({ ...p, daysLeft: days(runDate, p.dueDate) }));\nconst undated = ledger.filter(p => !p.dueDate).length;\nreturn [{ json: { runDate, goLive: GO_LIVE, wonSinceGoLive: won.length, newDeals, overdue, dueSoon, openPromises: ledger.length, undated } }];\n"
      },
      "executeOnce": true
    },
    {
      "id": "e80fbce3-6cae-42a0-ac4d-13700555a2cf",
      "name": "Build Promise Alert",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1100,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "// Promise alert from the ledger, built in code: overdue first, then due in the next 7 days. Nothing to say, nothing posted.\nconst f = $('Find New Handoffs & Due Promises').first().json;\nif (!f.overdue.length && !f.dueSoon.length) return [];\nconst safe = t => String(t || '').replace(/~/g, '≈');\nconst line = (p, tail) => '• *' + p.accountName + '*: ' + safe(p.promise) + ' → ' + p.ownerTeam + ', due ' + p.dueDate + ' ' + tail + (p.roadmap ? ' :warning: roadmap' : '');\nlet text = ':rotating_light: *Promise Ledger* (' + f.runDate + '): ' + f.openPromises + ' open promises made during sales cycles.\\n' +\n  (f.overdue.length ? '\\n*Overdue* (' + f.overdue.length + ')\\n' + f.overdue.map(p => line(p, '(*' + p.daysOverdue + ' days overdue*)')).join('\\n') : '') +\n  (f.dueSoon.length ? '\\n\\n*Due in the next 7 days* (' + f.dueSoon.length + ')\\n' + f.dueSoon.map(p => line(p, '(' + p.daysLeft + ' days left)')).join('\\n') : '') +\n  (f.undated ? '\\n_' + f.undated + ' open promise(s) have no date in the notes; owners should set one._' : '') +\n  '\\n_Owners mark a promise delivered in the Promise Ledger; it then drops off this list._';\nreturn [{ json: { alertText: text.slice(0, 2900) } }];\n"
      }
    },
    {
      "id": "45d6d47e-e767-4c6c-b6d1-cc5794fc66d8",
      "name": "Post Promise Alert",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.7,
      "position": [
        1300,
        300
      ],
      "parameters": {
        "resource": "message",
        "operation": "post",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "C0BQ3G96HL6",
          "cachedResultName": "general"
        },
        "text": "={{ $json.alertText }}",
        "otherOptions": {
          "includeLinkToWorkflow": false
        }
      },
      "credentials": {
        "slackApi": {
          "id": "mv7TIi8kucFPqPg6",
          "name": "Slack account"
        }
      }
    },
    {
      "id": "ab2c39e5-e58d-48dc-bf98-ca568ae0a8fb",
      "name": "Split New Deals",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1100,
        450
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "return $('Find New Handoffs & Due Promises').first().json.newDeals.map(json => ({ json }));"
      }
    },
    {
      "id": "12659be7-4266-4959-9575-3ae53b7e63ae",
      "name": "Handoff Extractor",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        300,
        450
      ],
      "parameters": {
        "promptType": "define",
        "text": "={{ JSON.stringify({ closeDate: $json.closeDate, notes: $json.notes }, null, 1) }}",
        "hasOutputParser": true,
        "options": {
          "systemMessage": "You prepare a sales-to-customer-success handoff from an account executive's deal notes for Fortavault, Inc. (a fictional data protection company). Use only what the notes say.\n\nReturn:\n- whyBought: one plain sentence on why the customer bought.\n- stakeholders: every person named, with name, role and stance (economic buyer, champion, supporter, skeptic or unknown) as the notes describe them.\n- successMetrics: each success measure the customer stated, as metric (short) and quote.\n- promises: every specific commitment made to the customer during the sale that someone at Fortavault must now deliver. For each: promise (short), quote, ownerTeam (one of Customer Success, Professional Services, Product, Deal Desk, Training), dueDays (days after signing if the notes give a number of days, else null), dueDate (YYYY-MM-DD if the notes give a calendar date or month, using the close date's year, and the last day of the month for 'end of' a month; else null), roadmap (true if it commits to a feature that is not yet in the product). Standard onboarding is not a promise.\n- redFlags: concerns, skeptical stakeholders, constraints or risks a CSM should know, as flag (short) and quote.\n\nEvery quote must be copied word for word from the notes: a phrase or a sentence, never paraphrased or joined. Do not invent names, dates, numbers or commitments. Return empty lists when the notes contain nothing for a field."
        }
      },
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 2000
    },
    {
      "id": "065261f4-7fa1-4d7d-95fb-2f97c58030be",
      "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": "50ce800d-95bf-43d8-a1c4-5c4750b7f897",
      "name": "Handoff Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.3,
      "position": [
        100,
        600
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"whyBought\": {\n      \"type\": \"string\"\n    },\n    \"stakeholders\": {\n      \"type\": \"array\",\n      \"items\": {\n        \"type\": \"object\",\n        \"properties\": {\n          \"name\": {\n            \"type\": \"string\"\n          },\n          \"role\": {\n            \"type\": \"string\"\n          },\n          \"stance\": {\n            \"type\": \"string\"\n          }\n        },\n        \"required\": [\n          \"name\",\n          \"role\",\n          \"stance\"\n        ]\n      }\n    },\n    \"successMetrics\": {\n      \"type\": \"array\",\n      \"items\": {\n        \"type\": \"object\",\n        \"properties\": {\n          \"metric\": {\n            \"type\": \"string\"\n          },\n          \"quote\": {\n            \"type\": \"string\"\n          }\n        },\n        \"required\": [\n          \"metric\",\n          \"quote\"\n        ]\n      }\n    },\n    \"promises\": {\n      \"type\": \"array\",\n      \"items\": {\n        \"type\": \"object\",\n        \"properties\": {\n          \"promise\": {\n            \"type\": \"string\"\n          },\n          \"quote\": {\n            \"type\": \"string\"\n          },\n          \"ownerTeam\": {\n            \"type\": \"string\"\n          },\n          \"dueDays\": {\n            \"type\": [\n              \"number\",\n              \"null\"\n            ]\n          },\n          \"dueDate\": {\n            \"type\": [\n              \"string\",\n              \"null\"\n            ]\n          },\n          \"roadmap\": {\n            \"type\": \"boolean\"\n          }\n        },\n        \"required\": [\n          \"promise\",\n          \"quote\",\n          \"ownerTeam\",\n          \"dueDays\",\n          \"dueDate\",\n          \"roadmap\"\n        ]\n      }\n    },\n    \"redFlags\": {\n      \"type\": \"array\",\n      \"items\": {\n        \"type\": \"object\",\n        \"properties\": {\n          \"flag\": {\n            \"type\": \"string\"\n          },\n          \"quote\": {\n            \"type\": \"string\"\n          }\n        },\n        \"required\": [\n          \"flag\",\n          \"quote\"\n        ]\n      }\n    }\n  },\n  \"required\": [\n    \"whyBought\",\n    \"stakeholders\",\n    \"successMetrics\",\n    \"promises\",\n    \"redFlags\"\n  ]\n}"
      }
    },
    {
      "id": "f3cd9b39-98f7-49ef-960f-e5313ec84725",
      "name": "Verify Handoff",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        500,
        450
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Verify the handoff in code before CS sees it. Every quote must appear word for word in the AE's notes, every\n// stakeholder name must appear in the notes, and a due date only counts if its number (days) or month appears in the\n// promise's own quote. Due dates are computed here from the close date, never taken on trust.\nconst d = $('Split New Deals').item.json;\nconst out = $json.output || {};\nconst norm = s => String(s || '').replace(/[‘’]/g, \"'\").replace(/[“”]/g, '\"').replace(/\\s+/g, ' ').trim().toLowerCase();\nconst notes = norm(d.notes);\nconst inNotes = q => q && norm(q).length >= 6 && notes.includes(norm(q));\nconst safe = t => String(t || '').replace(/~/g, '≈');\nconst TEAMS = ['Customer Success', 'Professional Services', 'Product', 'Deal Desk', 'Training'];\nconst MONTHS = ['january','february','march','april','may','june','july','august','september','october','november','december'];\nconst addDays = (date, n) => new Date(Date.parse(date + 'T00:00:00Z') + n * 86400000).toISOString().slice(0, 10);\nconst days = (a, b) => Math.round((Date.parse(b + 'T00:00:00Z') - Date.parse(a + 'T00:00:00Z')) / 86400000);\nlet dropped = 0, dueDropped = 0;\n// A stakeholder must be a named person (first and last name, as written in the notes), not a role like 'internal audit lead'.\nconst stakeholders = (out.stakeholders || []).filter(s => s.name && /^[A-Z][\\w'-]+\\s+[A-Z]/.test(s.name)).filter(s => { const ok = notes.includes(norm(s.name)); if (!ok) dropped++; return ok; });\nconst metrics = (out.successMetrics || []).filter(m => { const ok = inNotes(m.quote); if (!ok) dropped++; return ok; });\nconst redFlags = (out.redFlags || []).filter(f => { const ok = inNotes(f.quote); if (!ok) dropped++; return ok; });\nconst promises = (out.promises || []).filter(p => { const ok = inNotes(p.quote); if (!ok) dropped++; return ok; }).map((p, i) => {\n  let dueDate = null, dueBasis = 'no date given';\n  const q = norm(p.quote);\n  if (Number.isFinite(p.dueDays) && p.dueDays > 0 && q.includes(String(p.dueDays))) { dueDate = addDays(d.closeDate, p.dueDays); dueBasis = p.dueDays + ' days after close'; }\n  else if (p.dueDate && /^\\d{4}-\\d{2}-\\d{2}$/.test(p.dueDate) && q.includes(MONTHS[Number(p.dueDate.slice(5, 7)) - 1])) { dueDate = p.dueDate; dueBasis = 'date in notes'; }\n  else if (p.dueDays || p.dueDate) dueDropped++;\n  return { promiseId: d.dealId + '-P' + (i + 1), dealId: d.dealId, accountName: d.accountName, promise: p.promise, quote: p.quote.trim(),\n    ownerTeam: TEAMS.includes(p.ownerTeam) ? p.ownerTeam : 'Customer Success', dueDate, dueBasis, roadmap: !!p.roadmap, status: 'open', loggedAt: $now.toISO() };\n});\nconst money = n => '$' + Math.round(n).toLocaleString('en-US');\nconst pLine = p => '• ' + safe(p.promise) + ' → *' + p.ownerTeam + '*, ' + (p.dueDate ? 'due ' + p.dueDate : 'no date') +\n  (p.dueDate && p.dueDate < d.runDate ? ' :rotating_light: *already ' + days(p.dueDate, d.runDate) + ' days overdue*' : '') +\n  (p.roadmap ? ' :warning: _roadmap commitment, needs product sign-off_' : '') + '\\n      _“' + safe(p.quote) + '”_';\nlet text = ':handshake: *Handoff: ' + d.accountName + '* (' + money(d.amount) + ', closed ' + d.closeDate + ', ' + days(d.closeDate, d.runDate) + ' days ago)\\n' +\n  '*Why they bought:* ' + safe(out.whyBought) + '\\n' +\n  '*Who\\'s who:* ' + (stakeholders.length ? stakeholders.map(s => s.name + ' (' + s.role + (s.stance && s.stance !== 'unknown' ? ', ' + s.stance : '') + ')').join(' · ') : 'none named') + '\\n' +\n  '*Success looks like:*\\n' + (metrics.length ? metrics.map(m => '• ' + safe(m.metric)).join('\\n') : '• not stated in the notes') + '\\n\\n' +\n  '*Promised during the sale* (' + promises.length + ')' + (promises.length ? ', each now logged with an owner:\\n' + promises.map(pLine).join('\\n') : ': nothing beyond standard onboarding.') + '\\n\\n' +\n  '*Watch out for:*\\n' + (redFlags.length ? redFlags.map(f => '• ' + safe(f.flag) + ' _(“' + safe(f.quote) + '”)_').join('\\n') : '• nothing raised in the notes') +\n  (dropped ? '\\n_' + dropped + ' item(s) dropped: not found word for word in the AE notes._' : '') + (dueDropped ? '\\n_' + dueDropped + ' due date(s) dropped: not supported by the quote._' : '');\nif (text.length > 2900) text = text.slice(0, 2850).slice(0, text.slice(0, 2850).lastIndexOf('\\n')) + '\\n_…cut to fit Slack; full handoff in the Handoff Log._';\nconst log = { dealId: d.dealId, dealName: d.dealName, accountName: d.accountName, closeDate: d.closeDate, amount: d.amount, whyBought: out.whyBought || '',\n  stakeholders: JSON.stringify(stakeholders), successMetrics: JSON.stringify(metrics.map(m => m.metric)), redFlags: JSON.stringify(redFlags.map(f => f.flag)),\n  promiseCount: promises.length, dropped: dropped + dueDropped, handedOffAt: $now.toISO() };\nreturn { json: { briefText: text, promiseRows: promises, log } };\n"
      }
    },
    {
      "id": "5173325e-ce58-4157-8a27-3ee6b9d7a5b5",
      "name": "Post Handoff Brief",
      "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.briefText }}",
        "otherOptions": {
          "includeLinkToWorkflow": false
        }
      },
      "credentials": {
        "slackApi": {
          "id": "mv7TIi8kucFPqPg6",
          "name": "Slack account"
        }
      }
    },
    {
      "id": "a6577d0d-9a0c-4c6a-8235-bbf33c56e4e5",
      "name": "Split Promise Rows",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        700,
        600
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "return $('Verify Handoff').all().flatMap(i => i.json.promiseRows).map(json => ({ json }));"
      }
    },
    {
      "id": "43553c10-9c6f-488e-8a30-c5acb15866a6",
      "name": "Add to Promise Ledger",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        900,
        600
      ],
      "parameters": {
        "resource": "row",
        "operation": "insert",
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": "YoJf0J9Hd2WLnA14",
          "cachedResultName": "Promise Ledger"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {}
        }
      }
    },
    {
      "id": "91bf9b52-3abd-402c-838c-ebe6bb57841c",
      "name": "Handoff Log Rows",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        700,
        750
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "return $('Verify Handoff').all().map(i => ({ json: i.json.log }));"
      }
    },
    {
      "id": "46938f7b-536d-44cd-9470-234ad6b5d266",
      "name": "Log Handoff",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        900,
        750
      ],
      "parameters": {
        "resource": "row",
        "operation": "insert",
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": "seqawgOX8XWCbgDu",
          "cachedResultName": "Handoff Log"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {}
        }
      }
    }
  ],
  "connections": {
    "Daily Handoff Check": {
      "main": [
        [
          {
            "node": "Get Closed Won Deals",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Closed Won Deals": {
      "main": [
        [
          {
            "node": "Get Handoff Log",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Handoff Log": {
      "main": [
        [
          {
            "node": "Get Promise Ledger",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Promise Ledger": {
      "main": [
        [
          {
            "node": "Find New Handoffs & Due Promises",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find New Handoffs & Due Promises": {
      "main": [
        [
          {
            "node": "Build Promise Alert",
            "type": "main",
            "index": 0
          },
          {
            "node": "Split New Deals",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Promise Alert": {
      "main": [
        [
          {
            "node": "Post Promise Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split New Deals": {
      "main": [
        [
          {
            "node": "Handoff Extractor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Handoff Extractor": {
      "main": [
        [
          {
            "node": "Verify Handoff",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Claude Sonnet": {
      "ai_languageModel": [
        [
          {
            "node": "Handoff Extractor",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Handoff Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Handoff Extractor",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Verify Handoff": {
      "main": [
        [
          {
            "node": "Post Handoff Brief",
            "type": "main",
            "index": 0
          },
          {
            "node": "Split Promise Rows",
            "type": "main",
            "index": 0
          },
          {
            "node": "Handoff Log Rows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Promise Rows": {
      "main": [
        [
          {
            "node": "Add to Promise Ledger",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Handoff Log Rows": {
      "main": [
        [
          {
            "node": "Log Handoff",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}