{
  "id": "wnbJahytoQE4GFZ3",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Automate CV Screening & Candidate Validation with AI & Email Parsing",
  "tags": [],
  "nodes": [
    {
      "id": "2c5dae24-563c-4e86-958f-b267b80c7b97",
      "name": "Trigger on New CV Email\t",
      "type": "n8n-nodes-base.emailReadImap",
      "position": [
        -880,
        60
      ],
      "parameters": {
        "format": "resolved",
        "options": {
          "customEmailConfig": "[\"UNSEEN\", [\"SUBJECT\", \"CV\"]]"
        }
      },
      "credentials": {
        "imap": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "3fb527d0-5485-4a0d-bbe0-0ae995b8e5ec",
      "name": "Extract Text from PDF CV\t",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        -660,
        60
      ],
      "parameters": {
        "options": {},
        "operation": "pdf",
        "binaryPropertyName": "attachment_0"
      },
      "typeVersion": 1
    },
    {
      "id": "fd00eedc-3366-4c3c-b9b1-df26c85155cc",
      "name": "Ensure All CV Data Loaded\t",
      "type": "n8n-nodes-base.wait",
      "position": [
        -440,
        60
      ],
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "059b48de-32c9-41a7-a200-6112457df2e7",
      "name": "Parse & Structure CV Information\t",
      "type": "n8n-nodes-base.code",
      "position": [
        -220,
        60
      ],
      "parameters": {
        "jsCode": "// Access the extracted PDF text\nconst fileContent = ($input.first().json.text || '').toLowerCase();\nconst keywordsToDepartments = {\n  hr: 'HR',\n  bde: 'BDE',\n  'business development': 'BDE',\n  seo: 'SEO',\n  devops: 'DevOps',\n  developer: 'Development',\n  engineer: 'Engineering',\n  marketing: 'Marketing',\n  sales: 'Sales',\n  support: 'Support',\n  tester: 'QA',\n  qa: 'QA',\n};\n\n// Define a priority order (higher number = higher priority)\nconst priority = {\n  devops: 3,\n  developer: 3,\n  engineer: 3,\n  seo: 2,\n  bde: 2,\n  'business development': 2,\n  marketing: 2,\n  sales: 2,\n  support: 2,\n  tester: 2,\n  qa: 2,\n  hr: 1,\n};\n\n// Find all matching departments with their priorities\nlet matches = [];\nfor (const [keyword, department] of Object.entries(keywordsToDepartments)) {\n  if (fileContent.includes(keyword)) {\n    matches.push({ department, priority: priority[keyword] || 0 });\n  }\n}\n\n// Extract the username (first line of the CV text)\nconst originalText = $input.first().json.text || '';\nconst username = originalText.split('\\n')[0].trim(); // First line, e.g., \"Komal Shah\"\n\n// If matches are found, return the department with the highest priority along with the username\nif (matches.length > 0) {\n  const bestMatch = matches.reduce((best, current) =>\n    current.priority > best.priority ? current : best\n  );\n  return [{ department: bestMatch.department, username }];\n}\n\nreturn [{ department: 'Unknown', username }];"
      },
      "typeVersion": 2
    },
    {
      "id": "709ca3a3-04b6-44d7-bdc4-190c6b5f979f",
      "name": "Check CV for Required Fields\t",
      "type": "n8n-nodes-base.if",
      "position": [
        0,
        60
      ],
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.department }}",
              "value2": true,
              "operation": "notEqual"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "3093ed8e-cc84-4ca2-9e24-b4ffe2fc0e6f",
      "name": "Save Valid CV to Folder\t",
      "type": "n8n-nodes-base.executeCommand",
      "position": [
        240,
        -140
      ],
      "parameters": {
        "command": "=mkdir -p /home/node/.n8n/resume/{{ $json.department }}/ && echo \"{{ $('Extract Text from PDF CV\t').item.json.text }}\" > /home/node/.n8n/resume/{{ $json.department }}/{{ $json.username.replace(/ /g, '-') }}.pdf"
      },
      "typeVersion": 1
    },
    {
      "id": "bae56e7d-8232-404b-856e-7cc2bb86fffe",
      "name": "Notify HR of Invalid CV\t",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        260,
        260
      ],
      "parameters": {
        "text": "CV Not Found",
        "options": {},
        "subject": "CV Processing Error",
        "toEmail": "user@example.com",
        "fromEmail": "user@example.com"
      },
      "credentials": {
        "smtp": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "68fa371e-f91e-415e-ad4c-a83a18fe4ecb",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -900,
        -80
      ],
      "parameters": {
        "width": 150,
        "height": 280,
        "content": "Listens for new emails containing CV attachments."
      },
      "typeVersion": 1
    },
    {
      "id": "5a2368ad-226a-45c3-bf2f-be91208d357d",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -240,
        -80
      ],
      "parameters": {
        "color": 4,
        "width": 150,
        "height": 280,
        "content": "Extracts structured details like name, skills, education, experience using AI or custom logic.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "e2ba359c-c363-4805-b80a-291ff7c12185",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -20,
        -80
      ],
      "parameters": {
        "color": 6,
        "width": 150,
        "height": 280,
        "content": "Verifies presence of essential fields (e.g. name, email, skills) before proceeding.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "a0d2f49b-0a2b-4faf-9c26-a8de59095b36",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        240,
        100
      ],
      "parameters": {
        "color": 3,
        "width": 150,
        "height": 280,
        "content": "Sends email alert for incomplete or invalid CVs.\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "b788d954-5d93-4db0-a58f-5fa7f8173aed",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        220,
        -280
      ],
      "parameters": {
        "color": 2,
        "width": 150,
        "height": 280,
        "content": "Stores successfully validated CVs into a target directory.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "a2f60daf-2ae0-4643-ad18-e9fd5fff132b",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -680,
        -80
      ],
      "parameters": {
        "color": 3,
        "width": 150,
        "height": 280,
        "content": "Parses CV content from attached PDF files.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "1efb64dc-b917-47d9-9339-85dbae2d2385",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -460,
        -80
      ],
      "parameters": {
        "color": 5,
        "width": 150,
        "height": 280,
        "content": "Pauses until full data is ready for processing.\n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "128c5a19-ad2a-4426-851f-a9dbf2a9ff17",
  "connections": {
    "Trigger on New CV Email\t": {
      "main": [
        [
          {
            "node": "Extract Text from PDF CV\t",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Text from PDF CV\t": {
      "main": [
        [
          {
            "node": "Ensure All CV Data Loaded\t",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ensure All CV Data Loaded\t": {
      "main": [
        [
          {
            "node": "Parse & Structure CV Information\t",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check CV for Required Fields\t": {
      "main": [
        [
          {
            "node": "Save Valid CV to Folder\t",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Notify HR of Invalid CV\t",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse & Structure CV Information\t": {
      "main": [
        [
          {
            "node": "Check CV for Required Fields\t",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}