{
  "name": "Closed-lost monitor",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "closed-lost-trigger",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "webhook",
      "name": "Trigger webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        240,
        320
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$json[\"trigger_type\"]}}",
              "operation": "equal",
              "value2": "champion_job_change"
            }
          ]
        }
      },
      "id": "is-champion-change",
      "name": "Champion job change?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        460,
        320
      ]
    },
    {
      "parameters": {
        "url": "https://api.apollo.io/v1/people/match",
        "method": "POST",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Cache-Control",
              "value": "no-cache"
            },
            {
              "name": "X-Api-Key",
              "value": "={{$env.APOLLO_API_KEY}}"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "email",
              "value": "={{$json[\"new_champion_email\"]}}"
            }
          ]
        }
      },
      "id": "apollo-enrich",
      "name": "Apollo enrich new champion",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        680,
        240
      ]
    },
    {
      "parameters": {
        "fileSelector": "/tmp/trigger_{{$json[\"deal_id\"]}}.json",
        "dataType": "json",
        "data": "={{ JSON.stringify([$json]) }}"
      },
      "id": "write-trigger",
      "name": "Write trigger file",
      "type": "n8n-nodes-base.writeBinaryFile",
      "typeVersion": 1,
      "position": [
        900,
        240
      ]
    },
    {
      "parameters": {
        "command": "=cd /opt/gtm-engineering && python automations/09-closed-lost-revival/monitor.py --triggers /tmp/trigger_{{$json[\"deal_id\"]}}.json --hubspot-update --slack --out /tmp/draft_{{$json[\"deal_id\"]}}.json"
      },
      "id": "run-monitor",
      "name": "Draft re-engagement",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        1120,
        240
      ]
    },
    {
      "parameters": {
        "channel": "#deal-alerts",
        "text": "=:rotating_light: Closed-lost trigger fired \u2014 *{{$json[\"account_name\"]}}* ({{$json[\"trigger_type\"]}}). Draft attached in HubSpot deal notes."
      },
      "id": "slack-notify",
      "name": "Alert AE",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2,
      "position": [
        1340,
        240
      ],
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={\"status\":\"received\"}"
      },
      "id": "respond",
      "name": "Respond to webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        1560,
        320
      ]
    },
    {
      "parameters": {
        "command": "=cd /opt/gtm-engineering && echo '[{{$json | json}}]' > /tmp/trigger_misc.json && python automations/09-closed-lost-revival/monitor.py --triggers /tmp/trigger_misc.json --hubspot-update --out /tmp/draft_misc.json"
      },
      "id": "run-monitor-generic",
      "name": "Draft (other triggers)",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        680,
        400
      ]
    }
  ],
  "connections": {
    "Trigger webhook": {
      "main": [
        [
          {
            "node": "Champion job change?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Champion job change?": {
      "main": [
        [
          {
            "node": "Apollo enrich new champion",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Draft (other triggers)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Apollo enrich new champion": {
      "main": [
        [
          {
            "node": "Write trigger file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write trigger file": {
      "main": [
        [
          {
            "node": "Draft re-engagement",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Draft re-engagement": {
      "main": [
        [
          {
            "node": "Alert AE",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Alert AE": {
      "main": [
        [
          {
            "node": "Respond to webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Draft (other triggers)": {
      "main": [
        [
          {
            "node": "Respond to webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "closed-lost-v1",
  "tags": [
    "closed-lost",
    "reengagement"
  ]
}