{
  "name": "CRM hygiene sweep (Agent Routines)",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 15 * * 5"
            }
          ]
        }
      },
      "id": "e9f051d7-5929-54b2-9ab4-4bedf1c58c5f",
      "name": "Fridays 3 PM",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "https://YOUR_CRM_API/deals?status=open",
        "options": {
          "response": {
            "response": {
              "fullResponse": true,
              "neverError": true
            }
          },
          "timeout": 10000
        }
      },
      "id": "c5207ffb-df87-5e62-bf33-7340840d9b4f",
      "name": "Fetch open deals",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        490,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const deals=$json.body.deals||[];const cut=Date.now()-14*864e5;\nconst stale=deals.filter(d=>new Date(d.last_activity)<cut);const missing=deals.filter(d=>!d.amount||!d.close_date);\nreturn [{json:{stale,missing,text:`Stale deals: ${stale.length}\\nMissing amount or close date: ${missing.length}\\n`+stale.map(d=>`- ${d.name} (${d.owner})`).join('\\n')}}];"
      },
      "id": "cad57371-f8d3-5078-8fba-6834da739bf9",
      "name": "Flag stale and incomplete",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        730,
        300
      ]
    },
    {
      "parameters": {
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "name",
          "value": "#sales"
        },
        "text": "={{ $json.text }}",
        "otherOptions": {}
      },
      "id": "139c877b-b019-590a-82c1-c145817767e7",
      "name": "Post summary",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.2,
      "position": [
        970,
        300
      ],
      "credentials": {
        "slackApi": {
          "id": "REPLACE_ME",
          "name": "Slack account"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://YOUR_CRM_API/tasks",
        "options": {
          "response": {
            "response": {
              "fullResponse": true,
              "neverError": true
            }
          },
          "timeout": 10000
        }
      },
      "id": "e383edb7-1daf-56f3-a28a-309703b4671a",
      "name": "Create follow-up tasks",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        970,
        460
      ]
    }
  ],
  "connections": {
    "Fridays 3 PM": {
      "main": [
        [
          {
            "node": "Fetch open deals",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch open deals": {
      "main": [
        [
          {
            "node": "Flag stale and incomplete",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Flag stale and incomplete": {
      "main": [
        [
          {
            "node": "Post summary",
            "type": "main",
            "index": 0
          },
          {
            "node": "Create follow-up tasks",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false,
    "source": "https://agentroutines.si/r/crm-hygiene-sweep/"
  },
  "tags": []
}