{
  "name": "Dead Deal Necromancer",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 8 * * *"
            }
          ]
        }
      },
      "id": "3b1128bb-29c0-40cc-ac11-12d09c400a1d",
      "name": "Daily Scan",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.3,
      "position": [
        0,
        432
      ]
    },
    {
      "parameters": {
        "resource": "search",
        "query": "SELECT Id, Name, Amount, CloseDate, Account.Name, Description FROM Opportunity WHERE StageName = 'Closed Lost'"
      },
      "id": "1f6e5ba8-07c4-400e-aa3c-79388a901148",
      "name": "Find Closed Lost Opportunities",
      "type": "n8n-nodes-base.salesforce",
      "typeVersion": 1.1,
      "position": [
        224,
        432
      ],
      "credentials": {
        "salesforceOAuth2Api": {
          "name": "Salesforce account"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=A Closed Lost opportunity:\n\nDeal: {{ $json.Name }}\nAccount: {{ $json.Account?.Name }}\nAmount: {{ $json.Amount }}\nClose Date: {{ $json.CloseDate }}\nLoss reason / notes: {{ $json.Description }}\n\nAssess whether this deal is worth resurrecting.",
        "hasOutputParser": true,
        "options": {
          "systemMessage": "You are a deal-resurrection assessor for Fortavault, Inc., a fictional data protection and security platform (cloud backup, ransomware recovery, zero-trust access, and compliance reporting). Products: Fortavault Backup Cloud, Fortavault Shield (ransomware detection + one-click rollback), Fortavault Access (zero-trust), Fortavault Insights (compliance reporting). Key competitors: Veyron Data, Ashcombe Systems, Cyphertide, Northgate Cloud Security, Ridgeline Compliance.\n\nYou review Closed Lost opportunities and decide whether it is worth re-engaging the account now. Be selective - most closed-lost deals should NOT be resurrected. Only flag ones where the stated loss reason plausibly could have changed given how much time has passed (e.g. a budget freeze may have thawed, a point-in-time staffing gap may be resolved), or where the deal size clearly justifies a second look.\n\nIf worth resurrecting, draft a short reengagementAngle: 2-3 sentences a rep could paste into an email or LinkedIn message, referencing the original context and a specific reason to revisit now, grounded in real Fortavault products and competitive positioning where relevant.\n\nRespond with a JSON object with exactly three fields: worthResurrecting (boolean), rationale (a 1-2 sentence explanation for the rep, private - not sent externally), and reengagementAngle (the drafted opener text, or an empty string if worthResurrecting is false)."
        }
      },
      "id": "aac6e428-c949-45be-9b18-c4888429fa3c",
      "name": "Necromancy Assessor",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        448,
        432
      ]
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "claude-sonnet-4-6",
          "cachedResultName": "Claude Sonnet 4.6"
        },
        "options": {
          "temperature": 0.4
        }
      },
      "id": "78b8ff17-0c0a-47cd-8891-794cd80c0622",
      "name": "Anthropic Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
      "typeVersion": 1.5,
      "position": [
        400,
        672
      ],
      "credentials": {
        "anthropicApi": {
          "name": "Anthropic account"
        }
      }
    },
    {
      "parameters": {
        "jsonSchemaExample": "{ \"worthResurrecting\": true, \"rationale\": \"brief reasoning for the rep\", \"reengagementAngle\": \"drafted re-engagement opener, empty string if not worth resurrecting\" }",
        "autoFix": true
      },
      "id": "9193cadb-3d6b-4b00-9762-6f8be16ac8e8",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.3,
      "position": [
        592,
        624
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 1
          },
          "conditions": [
            {
              "leftValue": "={{ $json.output.worthResurrecting }}",
              "operator": {
                "type": "boolean",
                "operation": "equals"
              },
              "rightValue": true
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "d3701c30-7a12-4d3b-a82b-7adf6da66ef2",
      "name": "Worth Resurrecting?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        896,
        432
      ]
    },
    {
      "parameters": {
        "operation": "sendAndWait",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "C0BQ3G96HL6"
        },
        "message": "=Dead deal worth resurrecting\n\n{{ $('Find Closed Lost Opportunities').item.json.Name }} - {{ $('Find Closed Lost Opportunities').item.json.Account?.Name }}\nAmount: ${{ $('Find Closed Lost Opportunities').item.json.Amount }}\nOriginally lost: {{ $('Find Closed Lost Opportunities').item.json.CloseDate }}\n\nWhy now: {{ $json.output.rationale }}\n\nSuggested re-engagement:\n{{ $json.output.reengagementAngle }}",
        "approvalOptions": {
          "values": {
            "approvalType": "double",
            "approveLabel": "Reopen & Follow Up",
            "disapproveLabel": "Skip"
          }
        },
        "options": {}
      },
      "id": "53a26fdb-bb9c-4ade-a3f9-7c2b9764fbea",
      "name": "Send for Approval",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.7,
      "position": [
        1344,
        48
      ],
      "credentials": {
        "slackApi": {
          "name": "Slack account"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 1
          },
          "conditions": [
            {
              "leftValue": "={{ $json.data.approved }}",
              "operator": {
                "type": "boolean",
                "operation": "equals"
              },
              "rightValue": true
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "92dc72bb-8ce8-47f3-a073-90157ae418cf",
      "name": "Approved?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1568,
        48
      ]
    },
    {
      "parameters": {
        "resource": "opportunity",
        "operation": "update",
        "opportunityId": "={{ $('Find Closed Lost Opportunities').item.json.Id }}",
        "updateFields": {
          "closeDate": "={{ $now.plus(90, \"days\").toFormat(\"yyyy-MM-dd\") }}",
          "stageName": "Qualification"
        }
      },
      "id": "a8c1e5bc-93ae-4c12-8435-949d4c8d4dbc",
      "name": "Reopen Opportunity",
      "type": "n8n-nodes-base.salesforce",
      "typeVersion": 1.1,
      "position": [
        1792,
        0
      ],
      "credentials": {
        "salesforceOAuth2Api": {
          "name": "Salesforce account"
        }
      }
    },
    {
      "parameters": {
        "resource": "task",
        "status": "Not Started",
        "additionalFields": {
          "activityDate": "={{ $now.plus(7, \"days\").toFormat(\"yyyy-MM-dd\") }}",
          "description": "={{ $('Necromancy Assessor').item.json.output.reengagementAngle }}",
          "priority": "High",
          "subject": "={{ 'Re-engage: ' + $('Find Closed Lost Opportunities').item.json.Name }}",
          "whatId": "={{ $('Find Closed Lost Opportunities').item.json.Id }}"
        }
      },
      "id": "af2b9084-55d6-4a18-a47b-a6b0f019abfb",
      "name": "Create Follow-Up Task",
      "type": "n8n-nodes-base.salesforce",
      "typeVersion": 1.1,
      "position": [
        2016,
        0
      ],
      "credentials": {
        "salesforceOAuth2Api": {
          "name": "Salesforce account"
        }
      }
    },
    {
      "parameters": {
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": "gpAdVkCwQUmZJSqv",
          "cachedResultName": "Dead Deal Log"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "opportunityId": "={{ $('Find Closed Lost Opportunities').item.json.Id }}",
            "opportunityName": "={{ $('Find Closed Lost Opportunities').item.json.Name }}",
            "accountName": "={{ $('Find Closed Lost Opportunities').item.json.Account?.Name }}",
            "amount": "={{ $('Find Closed Lost Opportunities').item.json.Amount }}",
            "closeDate": "={{ $('Find Closed Lost Opportunities').item.json.CloseDate }}",
            "lossReason": "={{ $('Find Closed Lost Opportunities').item.json.Description }}",
            "worthResurrecting": "={{ $('Necromancy Assessor').item.json.output.worthResurrecting }}",
            "rationale": "={{ $('Necromancy Assessor').item.json.output.rationale }}",
            "reengagementAngle": "={{ $('Necromancy Assessor').item.json.output.reengagementAngle }}",
            "channel": "C0BQ3G96HL6",
            "status": "approved",
            "flaggedAt": "={{ $now.toISO() }}",
            "approvedAt": "={{ $now.toISO() }}"
          }
        },
        "options": {}
      },
      "id": "584b5128-1065-4445-ae3e-1a6ae8aa7952",
      "name": "Log Approved",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        2240,
        128
      ]
    },
    {
      "parameters": {
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": "gpAdVkCwQUmZJSqv",
          "cachedResultName": "Dead Deal Log"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "opportunityId": "={{ $('Find Closed Lost Opportunities').item.json.Id }}",
            "opportunityName": "={{ $('Find Closed Lost Opportunities').item.json.Name }}",
            "accountName": "={{ $('Find Closed Lost Opportunities').item.json.Account?.Name }}",
            "amount": "={{ $('Find Closed Lost Opportunities').item.json.Amount }}",
            "closeDate": "={{ $('Find Closed Lost Opportunities').item.json.CloseDate }}",
            "lossReason": "={{ $('Find Closed Lost Opportunities').item.json.Description }}",
            "worthResurrecting": "={{ $('Necromancy Assessor').item.json.output.worthResurrecting }}",
            "rationale": "={{ $('Necromancy Assessor').item.json.output.rationale }}",
            "reengagementAngle": "={{ $('Necromancy Assessor').item.json.output.reengagementAngle }}",
            "channel": "C0BQ3G96HL6",
            "status": "declined",
            "flaggedAt": "={{ $now.toISO() }}"
          }
        },
        "options": {}
      },
      "id": "38031a16-e021-40e8-920b-5b7c4418acd8",
      "name": "Log Declined",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        1792,
        192
      ]
    },
    {
      "parameters": {
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": "gpAdVkCwQUmZJSqv",
          "cachedResultName": "Dead Deal Log"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "opportunityId": "={{ $('Find Closed Lost Opportunities').item.json.Id }}",
            "opportunityName": "={{ $('Find Closed Lost Opportunities').item.json.Name }}",
            "accountName": "={{ $('Find Closed Lost Opportunities').item.json.Account?.Name }}",
            "amount": "={{ $('Find Closed Lost Opportunities').item.json.Amount }}",
            "closeDate": "={{ $('Find Closed Lost Opportunities').item.json.CloseDate }}",
            "lossReason": "={{ $('Find Closed Lost Opportunities').item.json.Description }}",
            "worthResurrecting": false,
            "status": "skipped",
            "flaggedAt": "={{ $now.toISO() }}"
          }
        },
        "options": {}
      },
      "id": "6b02e022-c45b-4c0e-b49b-2ac20f5874ae",
      "name": "Log Skipped",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        1120,
        528
      ]
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "483d1a76-e8c4-4370-86d5-48581b98bf4c",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        1120,
        336
      ]
    }
  ],
  "connections": {
    "Daily Scan": {
      "main": [
        [
          {
            "node": "Find Closed Lost Opportunities",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find Closed Lost Opportunities": {
      "main": [
        [
          {
            "node": "Necromancy Assessor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Necromancy Assessor": {
      "main": [
        [
          {
            "node": "Worth Resurrecting?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Anthropic Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Necromancy Assessor",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "Structured Output Parser",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Necromancy Assessor",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Worth Resurrecting?": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Log Skipped",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send for Approval": {
      "main": [
        [
          {
            "node": "Approved?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Approved?": {
      "main": [
        [
          {
            "node": "Reopen Opportunity",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Log Declined",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reopen Opportunity": {
      "main": [
        [
          {
            "node": "Create Follow-Up Task",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Follow-Up Task": {
      "main": [
        [
          {
            "node": "Log Approved",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        null,
        [
          {
            "node": "Send for Approval",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Approved": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Declined": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}