{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "ec2e79fe-ba71-4527-868d-b02b2d37bb6b",
      "name": "Fetch Job Description",
      "type": "n8n-nodes-base.notion",
      "position": [
        -2192,
        3040
      ],
      "parameters": {
        "simple": false,
        "filters": {
          "conditions": [
            {
              "key": "Task name|title",
              "condition": "contains",
              "titleValue": "={{ $('Get Pending Candidate').item.json.property_position }}"
            }
          ]
        },
        "options": {},
        "resource": "databasePage",
        "operation": "getAll",
        "returnAll": true,
        "databaseId": {
          "__rl": true,
          "mode": "list",
          "value": "19a21223-e79e-80a3-8049-c04ca8c01f9c",
          "cachedResultUrl": "https://www.notion.so/19a21223e79e80a38049c04ca8c01f9c",
          "cachedResultName": "Open Jobs"
        },
        "filterType": "manual"
      },
      "typeVersion": 2.2,
      "alwaysOutputData": true
    },
    {
      "id": "657437dd-9166-4439-bfd4-aa71e9041b02",
      "name": "Get Pending Candidate",
      "type": "n8n-nodes-base.notion",
      "position": [
        -3104,
        3040
      ],
      "parameters": {
        "limit": 1,
        "filters": {
          "conditions": [
            {
              "key": "AI Comments|rich_text",
              "condition": "is_empty"
            }
          ]
        },
        "options": {},
        "resource": "databasePage",
        "operation": "getAll",
        "databaseId": {
          "__rl": true,
          "mode": "list",
          "value": "1d921223-e79e-8164-8cd4-fa013f4dd093",
          "cachedResultUrl": "https://www.notion.so/1d921223e79e81648cd4fa013f4dd093",
          "cachedResultName": "TD Career"
        },
        "filterType": "manual"
      },
      "typeVersion": 2.2
    },
    {
      "id": "da1129f4-d252-4c3b-a2e7-d958b3b66156",
      "name": "Stop",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -2656,
        3232
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "fe8dcd59-4ef8-42fd-a46b-71d0c05c7bc4",
      "name": "On New Candidate",
      "type": "n8n-nodes-base.notionTrigger",
      "position": [
        -3328,
        3040
      ],
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "databaseId": {
          "__rl": true,
          "mode": "list",
          "value": "1d921223-e79e-8164-8cd4-fa013f4dd093",
          "cachedResultUrl": "https://www.notion.so/1d921223e79e81648cd4fa013f4dd093",
          "cachedResultName": "TD Careers"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "e59001d4-2464-45f1-b0d8-1baed1068fab",
      "name": "Extract PDF Content",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        -1104,
        3072
      ],
      "parameters": {
        "options": {},
        "operation": "pdf"
      },
      "typeVersion": 1
    },
    {
      "id": "18d738b1-d7ae-4afb-9c14-509da07d0a2c",
      "name": "OpenAI PDF Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -576,
        3232
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4-turbo",
          "cachedResultName": "gpt-4-turbo"
        },
        "options": {
          "temperature": 0.1
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "fff487e1-4695-4abf-8ed9-8e24bf5e4bd9",
      "name": "Analyze Candidate (PDF)",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -592,
        3072
      ],
      "parameters": {
        "text": "=You are a senior technical recruiter... (truncated for brevity, logic maintained)",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 1.8
    },
    {
      "id": "d8992980-7a8c-4ad9-8df2-73a4a4a94ab9",
      "name": "OpenAI DOCX Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -576,
        2832
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4-turbo",
          "cachedResultName": "gpt-4-turbo"
        },
        "options": {
          "temperature": 0.1
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "a2ae1018-34fa-4ba7-a7ae-c1544dd06c53",
      "name": "Analyze Candidate (DOCX)",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -592,
        2672
      ],
      "parameters": {
        "text": "=You are a senior technical recruiter... (truncated for brevity, logic maintained)",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 1.8
    },
    {
      "id": "19e03b19-82fe-4fc8-bcf2-1a4b0c5e59fe",
      "name": "Format DOCX Data",
      "type": "n8n-nodes-base.code",
      "position": [
        -832,
        2672
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Resume Content Analysis and Preprocessing..."
      },
      "typeVersion": 2
    },
    {
      "id": "661cd80f-a9f7-4420-bd33-c1269678126b",
      "name": "Check Processing Status",
      "type": "n8n-nodes-base.if",
      "position": [
        -2880,
        3040
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "628809e8-f7c5-491d-af46-418a70fc1c57",
              "operator": {
                "type": "string",
                "operation": "empty",
                "singleValue": true
              },
              "leftValue": "={{ $json.property_ai_comments }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "511b0ee0-631d-4dd2-8fb9-96ea8551e233",
      "name": "Get Full Record",
      "type": "n8n-nodes-base.notion",
      "position": [
        -2656,
        3040
      ],
      "parameters": {
        "pageId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Get Pending Candidate').item.json.id }}"
        },
        "resource": "databasePage",
        "operation": "get"
      },
      "typeVersion": 2.2
    },
    {
      "id": "e5c5e096-cd23-44eb-9a0c-9be66f103df5",
      "name": "Prepare Resume URL",
      "type": "n8n-nodes-base.set",
      "position": [
        -2384,
        3040
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "3eb0e8e6-67de-4961-9022-61ef5253d1ae",
              "name": "property_resume_file",
              "type": "string",
              "value": "={{ $json.property_resume_file }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "fe3d34f2-20d3-43fe-84cd-af25e38b69fe",
      "name": "Download Resume",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1984,
        3040
      ],
      "parameters": {
        "url": "={{ $('Prepare Resume URL').item.json.property_resume_file }}",
        "options": {
          "response": {
            "response": {
              "fullResponse": true,
              "responseFormat": "file"
            }
          }
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "4f5b079d-c346-4083-a6a4-9115c1d296dd",
      "name": "Identify File Type",
      "type": "n8n-nodes-base.code",
      "position": [
        -1760,
        3040
      ],
      "parameters": {
        "jsCode": "const results = [];\nfor (const item of $input.all()) {\n  const json = item.json;\n  let result = { ...item };\n\n  if (!json.file_name) {\n    result.json.error = \"File name is missing in the input data.\";\n    result.json.fileType = null;\n  } else {\n    const fileExtension = json.file_name.split('.').pop().toLowerCase();\n    result.json.fileType = fileExtension === 'pdf'\n      ? 'pdf'\n      : fileExtension === 'docx'\n      ? 'docx'\n      : null;\n  }\n  results.push(result);\n}\nreturn results;"
      },
      "typeVersion": 2
    },
    {
      "id": "fc76e4a8-742d-423e-9bff-700b78a3a7ae",
      "name": "Route by Extension",
      "type": "n8n-nodes-base.switch",
      "position": [
        -1536,
        3040
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "c1169099-a261-4aba-ad20-0522cb33520c",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    },
                    "leftValue": "={{ $('Prepare Resume URL').item.json.property_resume_file }}",
                    "rightValue": ".docx"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "238481cf-809b-4186-81ec-528033c1c079",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    },
                    "leftValue": "={{ $('Prepare Resume URL').item.json.property_resume_file }}",
                    "rightValue": "pdf"
                  }
                ]
              }
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "e80ecc43-c4c8-4cac-8b6b-1702a00728d5",
      "name": "Convert DOCX to Text",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        -1312,
        2672
      ],
      "parameters": {
        "options": {},
        "operation": "rtf"
      },
      "typeVersion": 1.1
    },
    {
      "id": "6032f72c-58c7-4e95-8d0f-e58e53256c47",
      "name": "Extract DOCX Content",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        -1072,
        2672
      ],
      "parameters": {
        "options": {},
        "operation": "html"
      },
      "typeVersion": 1
    },
    {
      "id": "1d93f999-0ff9-4225-ae08-7cd7cf30c52e",
      "name": "Format PDF Data",
      "type": "n8n-nodes-base.code",
      "position": [
        -832,
        3072
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Resume Content Analysis and Preprocessing..."
      },
      "typeVersion": 2
    },
    {
      "id": "3f908df7-2927-4b33-af16-0738809f8efe",
      "name": "Format AI Output (DOCX)",
      "type": "n8n-nodes-base.code",
      "position": [
        -208,
        2672
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Final JSON Processing..."
      },
      "typeVersion": 2
    },
    {
      "id": "788996eb-3b98-4f00-84c0-d3b689908917",
      "name": "Format AI Output (PDF)",
      "type": "n8n-nodes-base.code",
      "position": [
        -208,
        3072
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Final JSON Processing..."
      },
      "typeVersion": 2
    },
    {
      "id": "f313d8f5-72a2-4a11-97ac-7f116106dcd7",
      "name": "Update Notion (DOCX)",
      "type": "n8n-nodes-base.notion",
      "position": [
        80,
        2672
      ],
      "parameters": {
        "pageId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Get Pending Candidate').item.json.id }}"
        },
        "simple": false,
        "options": {},
        "resource": "databasePage",
        "operation": "update",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Feedback|select",
              "selectValue": "={{ $json.status }}"
            },
            {
              "key": "AI Comments|rich_text",
              "textContent": "={{ $json.comments }}"
            },
            {
              "key": "={{ $json.verdictComment[0] }}"
            },
            {
              "key": "Resume Score|rich_text",
              "textContent": "={{ $json.overallScore.toString() }}"
            },
            {
              "key": "Top Skills Detected|rich_text",
              "textContent": "={{ $json.skillsExtractedText }}"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "6ab4b958-d5ef-4c93-9db8-8872056c2c85",
      "name": "Update Notion (PDF)",
      "type": "n8n-nodes-base.notion",
      "position": [
        80,
        3072
      ],
      "parameters": {
        "pageId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Get Pending Candidate').item.json.id }}"
        },
        "simple": false,
        "options": {},
        "resource": "databasePage",
        "operation": "update",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Feedback|select",
              "selectValue": "={{ $json.status }}"
            },
            {
              "key": "AI Comments|rich_text",
              "textContent": "={{ $json.comments }}"
            },
            {
              "key": "One Line Summary|rich_text",
              "textContent": "={{ $json.rawAnalysis.verdictComment }}"
            },
            {
              "key": "Resume Score|rich_text",
              "textContent": "={{ $json.overallScore.toString() }}"
            },
            {
              "key": "Top Skills Detected|rich_text",
              "textContent": "={{ $json.skillsExtractedText }}"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "198ad01f-ca8d-4919-a871-f37edc0eba38",
      "name": "Sticky Note18",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3776,
        2848
      ],
      "parameters": {
        "width": 379,
        "height": 570,
        "content": "## How it works\n1. **Watches Notion** for new job applications in the \"TD Careers\" database.\n2. **Checks Status** to ensure the candidate hasn't already been processed (looks for empty AI comments).\n3. **Downloads Resume** and detects if it is a PDF or DOCX file.\n4. **Analyzes Candidate** using OpenAI to score them against the specific job requirements found in the \"Open Jobs\" database.\n5. **Updates Notion** with a fit score, summary, and disqualification factors.\n\n## Setup steps\n1. Configure your **Notion Credentials** in the trigger and Notion nodes.\n2. Update the `databaseId` in the 'On New Candidate' and 'Fetch Job Description' nodes to match your Notion setup.\n3. Ensure your Notion database has these fields: `AI Comments` (Text), `Resume Score` (Text), `Top Skills Detected` (Text), and `Feedback` (Select)."
      },
      "typeVersion": 1
    },
    {
      "id": "bd3950c1-6f5a-4661-a728-e0971ca7fcf8",
      "name": "Sticky Note19",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3376,
        2960
      ],
      "parameters": {
        "color": 7,
        "width": 900,
        "height": 260,
        "content": "### 1. Trigger & Validation\nDetects new items and ensures we don't process the same candidate twice."
      },
      "typeVersion": 1
    },
    {
      "id": "2fbccbea-5621-4b11-9978-7d5d4fb0e08d",
      "name": "Sticky Note20",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2416,
        2960
      ],
      "parameters": {
        "color": 7,
        "width": 1100,
        "height": 260,
        "content": "### 2. Data Preparation\nFetches the full job description and downloads the resume file."
      },
      "typeVersion": 1
    },
    {
      "id": "5ebf07ff-cb7a-46ad-8a93-0246314626be",
      "name": "Sticky Note21",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1168,
        2592
      ],
      "parameters": {
        "color": 7,
        "width": 1400,
        "height": 300,
        "content": "### 3. DOCX Processing Branch\nConverts DOCX to text, analyzes via AI, and updates Notion."
      },
      "typeVersion": 1
    },
    {
      "id": "8ac30c6d-42a5-48a6-8c10-42e9f5efa138",
      "name": "Sticky Note22",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1168,
        2992
      ],
      "parameters": {
        "color": 7,
        "width": 1400,
        "height": 300,
        "content": "### 4. PDF Processing Branch\nExtracts PDF text, analyzes via AI, and updates Notion."
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Download Resume": {
      "main": [
        [
          {
            "node": "Identify File Type",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format PDF Data": {
      "main": [
        [
          {
            "node": "Analyze Candidate (PDF)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Full Record": {
      "main": [
        [
          {
            "node": "Prepare Resume URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format DOCX Data": {
      "main": [
        [
          {
            "node": "Analyze Candidate (DOCX)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On New Candidate": {
      "main": [
        [
          {
            "node": "Get Pending Candidate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI PDF Model": {
      "ai_languageModel": [
        [
          {
            "node": "Analyze Candidate (PDF)",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI DOCX Model": {
      "ai_languageModel": [
        [
          {
            "node": "Analyze Candidate (DOCX)",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Identify File Type": {
      "main": [
        [
          {
            "node": "Route by Extension",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Resume URL": {
      "main": [
        [
          {
            "node": "Fetch Job Description",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route by Extension": {
      "main": [
        [
          {
            "node": "Convert DOCX to Text",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract PDF Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract PDF Content": {
      "main": [
        [
          {
            "node": "Format PDF Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert DOCX to Text": {
      "main": [
        [
          {
            "node": "Extract DOCX Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract DOCX Content": {
      "main": [
        [
          {
            "node": "Format DOCX Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Job Description": {
      "main": [
        [
          {
            "node": "Download Resume",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Pending Candidate": {
      "main": [
        [
          {
            "node": "Check Processing Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format AI Output (PDF)": {
      "main": [
        [
          {
            "node": "Update Notion (PDF)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analyze Candidate (PDF)": {
      "main": [
        [
          {
            "node": "Format AI Output (PDF)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Processing Status": {
      "main": [
        [
          {
            "node": "Get Full Record",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Stop",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format AI Output (DOCX)": {
      "main": [
        [
          {
            "node": "Update Notion (DOCX)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analyze Candidate (DOCX)": {
      "main": [
        [
          {
            "node": "Format AI Output (DOCX)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}