{
  "name": "CRM hygiene: flag deals that have gone quiet",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 8 * * 1-5"
            }
          ]
        }
      },
      "id": "3c940278-381f-5b46-9465-7bad20708444",
      "name": "Every weekday at 8:00",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "authentication": "appToken",
        "resource": "deal",
        "operation": "getAll",
        "returnAll": true,
        "filters": {
          "includeAssociations": true,
          "propertiesCollection": {
            "propertiesValues": {
              "properties": [
                "dealname",
                "amount",
                "dealstage",
                "hubspot_owner_id",
                "notes_last_contacted",
                "closedate"
              ]
            }
          }
        }
      },
      "id": "ca8b230f-3ffa-5ba3-9d72-a4fdf82e4279",
      "name": "Get open deals",
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 2,
      "position": [
        220,
        0
      ],
      "credentials": {
        "hubspotAppToken": {
          "id": "",
          "name": "HubSpot"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const cutoff = Date.now() - 14 * 24 * 3600 * 1000;\nconst stale = $input.all().map((i) => i.json.properties ?? i.json)\n  .filter((d) => !['closedwon', 'closedlost'].includes(d.dealstage))\n  .filter((d) => !d.notes_last_contacted || new Date(d.notes_last_contacted).getTime() < cutoff)\n  .sort((a, b) => Number(b.amount ?? 0) - Number(a.amount ?? 0));\nconst lines = stale.slice(0, 15).map((d) => `• ${d.dealname}: $${Number(d.amount ?? 0).toLocaleString('en-US')}, last contact ${d.notes_last_contacted ? new Date(d.notes_last_contacted).toDateString() : 'never'}`);\nreturn [{ json: { count: stale.length, digest: lines.join('\\n') } }];"
      },
      "id": "f339ac7c-c01a-52ab-880c-a9f376552eac",
      "name": "Find deals with no contact in 14 days",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        440,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "id": "e3ff0ca0-eef8-56a1-a240-78bd9c1f91a3",
              "leftValue": "={{ $json.count }}",
              "rightValue": 0,
              "operator": {
                "type": "number",
                "operation": "gt"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "6fe3e608-7a8e-5c70-8d72-19e10ff0c4a9",
      "name": "Any to chase?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        660,
        0
      ]
    },
    {
      "parameters": {
        "select": "channel",
        "channelId": {
          "__rl": true,
          "value": "#sales",
          "mode": "name"
        },
        "text": "=:hourglass: {{ $json.count }} open deals have had no contact for 14+ days. Biggest first:\n{{ $json.digest }}",
        "otherOptions": {}
      },
      "id": "ff0e50e6-87f3-544a-aadd-8109c3461e0c",
      "name": "Post the digest",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.2,
      "position": [
        880,
        -80
      ],
      "credentials": {
        "slackApi": {
          "id": "",
          "name": "Slack"
        }
      }
    },
    {
      "parameters": {},
      "id": "0f5b6d58-f888-530b-8526-944422968a8d",
      "name": "Nothing to chase",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        880,
        80
      ]
    }
  ],
  "connections": {
    "Every weekday at 8:00": {
      "main": [
        [
          {
            "node": "Get open deals",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get open deals": {
      "main": [
        [
          {
            "node": "Find deals with no contact in 14 days",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find deals with no contact in 14 days": {
      "main": [
        [
          {
            "node": "Any to chase?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Any to chase?": {
      "main": [
        [
          {
            "node": "Post the digest",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Nothing to chase",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false,
    "adev": {
      "slug": "crm-hygiene",
      "service": "ai-automation",
      "needs": [
        "n8n",
        "HubSpot",
        "Slack"
      ],
      "summary": "Every weekday morning, open deals with no contact in two weeks are posted to sales, biggest first, so nothing goes cold by accident."
    }
  },
  "tags": [
    {
      "name": "adev.build"
    }
  ]
}