{
  "name": "Stalled deal sweep (HubSpot)",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 7 * * 1-5"
            }
          ]
        }
      },
      "id": "030799f7-e1fc-468f-a9a3-4042a23878bf",
      "name": "Weekdays 07:00",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        300
      ]
    },
    {
      "parameters": {
        "authentication": "appToken",
        "resource": "deal",
        "operation": "getAll",
        "returnAll": true,
        "filters": {
          "propertiesCollection": {
            "propertiesValues": {
              "properties": [
                "dealname",
                "dealstage",
                "amount",
                "hs_lastmodifieddate",
                "notes_last_contacted",
                "hubspot_owner_id"
              ]
            }
          }
        }
      },
      "id": "cb661a5b-c313-449e-8186-e762c2396a81",
      "name": "Get open deals",
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 2.1,
      "position": [
        220,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const cutoff = Date.now() - 14 * 24 * 3600 * 1000;\nreturn $input.all().filter(i => new Date(i.json.properties?.notes_last_contacted?.value || 0).getTime() < cutoff);"
      },
      "id": "3c39ad9e-9869-4198-98d8-5bc3ffe252ee",
      "name": "Keep stalled deals",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        440,
        300
      ]
    },
    {
      "parameters": {
        "maxItems": 20
      },
      "id": "7f845d66-4993-430f-b490-84b0e3d874bd",
      "name": "Limit to 20 a day",
      "type": "n8n-nodes-base.limit",
      "typeVersion": 1,
      "position": [
        660,
        300
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Deal: {{ JSON.stringify($json) }}",
        "hasOutputParser": true,
        "options": {
          "systemMessage": "You review one stalled deal. Propose a next step and the CRM fields to update. Never invent facts that are not in the deal record."
        }
      },
      "id": "16fe869c-fee0-4948-bbec-62d61d4d5ada",
      "name": "Deal review agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.7,
      "position": [
        880,
        300
      ]
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "claude-sonnet-4-5",
          "mode": "list",
          "cachedResultName": "Claude Sonnet"
        },
        "options": {
          "temperature": 0.2
        }
      },
      "id": "7e252d66-6065-455f-9a8e-63ffd4aa9141",
      "name": "Claude model",
      "type": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
      "typeVersion": 1.3,
      "position": [
        800,
        540
      ]
    },
    {
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"next_step\": { \"type\": \"string\" },\n    \"risk\": { \"type\": \"string\", \"enum\": [\"low\", \"medium\", \"high\"] },\n    \"field_updates\": { \"type\": \"object\" },\n    \"evidence\": { \"type\": \"string\" }\n  },\n  \"required\": [\"next_step\", \"risk\", \"field_updates\", \"evidence\"]\n}"
      },
      "id": "f508aadc-bdeb-4d64-b586-17d73853f00e",
      "name": "Deal update schema",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.2,
      "position": [
        980,
        540
      ]
    },
    {
      "parameters": {
        "operation": "sendAndWait",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "value": "#deal-desk",
          "mode": "name"
        },
        "message": "=Stalled deal: {{ $('Keep stalled deals').item.json.properties.dealname.value }}\nProposed next step: {{ $json.output.next_step }}",
        "approvalOptions": {
          "values": {
            "approvalType": "double"
          }
        },
        "options": {}
      },
      "id": "7dd9129d-5a4c-4969-a5d0-52bc09c8843d",
      "name": "Ask owner in Slack",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [
        1140,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "09844ff2-d2dd-4223-809f-00a149f78c51",
              "leftValue": "={{ $json.data.approved }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "e50d0a61-6a8b-463c-b53a-a370ccb6475d",
      "name": "Approved?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1380,
        300
      ]
    },
    {
      "parameters": {
        "authentication": "appToken",
        "resource": "deal",
        "operation": "update",
        "dealId": "={{ $('Keep stalled deals').item.json.dealId }}",
        "updateFields": {
          "description": "={{ $('Deal review agent').item.json.output.next_step }}"
        }
      },
      "id": "ae1560a8-297b-46a2-a181-68d6a17f80f9",
      "name": "Update deal",
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 2.1,
      "position": [
        1620,
        200
      ]
    },
    {
      "parameters": {
        "schema": {
          "__rl": true,
          "value": "public",
          "mode": "list"
        },
        "table": {
          "__rl": true,
          "value": "agent_actions",
          "mode": "list"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {}
        },
        "options": {}
      },
      "id": "e2e47729-07af-4a7c-9a35-12e26cb0ef59",
      "name": "Log decision",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        1860,
        300
      ]
    }
  ],
  "connections": {
    "Weekdays 07:00": {
      "main": [
        [
          {
            "node": "Get open deals",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get open deals": {
      "main": [
        [
          {
            "node": "Keep stalled deals",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Keep stalled deals": {
      "main": [
        [
          {
            "node": "Limit to 20 a day",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Limit to 20 a day": {
      "main": [
        [
          {
            "node": "Deal review agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Claude model": {
      "ai_languageModel": [
        [
          {
            "node": "Deal review agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Deal update schema": {
      "ai_outputParser": [
        [
          {
            "node": "Deal review agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Deal review agent": {
      "main": [
        [
          {
            "node": "Ask owner in Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ask owner in Slack": {
      "main": [
        [
          {
            "node": "Approved?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Approved?": {
      "main": [
        [
          {
            "node": "Update deal",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Log decision",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update deal": {
      "main": [
        [
          {
            "node": "Log decision",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}