{
  "name": "Employee referral into the candidate sheet",
  "nodes": [
    {
      "parameters": {
        "content": "## Employee referral into the candidate sheet\n\nPortfolio demo only. This workflow is an original example for demonstration. It is not client work and it does not represent a deployment for any customer.\n\nRun **Run demo** to execute the offline rules engine. The live branch is used only when the incoming item sets `demo` to false and the placeholder credentials have been replaced.",
        "height": 220,
        "width": 520,
        "color": 4
      },
      "id": "50ce985d-3cae-4f6d-a845-b7d52a556d2d",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        -40
      ]
    },
    {
      "parameters": {},
      "id": "1ea97905-8454-475f-b995-244cd6eba5db",
      "name": "Run demo",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        40,
        280
      ],
      "notes": "CLI and the n8n editor start here. An empty manual run loads the bundled sample.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "referral-intake",
        "authentication": "none",
        "responseMode": "lastNode",
        "responseData": "firstEntryJson",
        "options": {}
      },
      "id": "d262d30f-f433-4df6-95fb-6a624ee1daf4",
      "name": "Inbound webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        40,
        460
      ],
      "notes": "POST JSON to this path. Include demo:false only after credentials are connected.",
      "notesInFlow": true,
      "webhookId": "7626d78a-d58f-424a-b48a-9f30ee812d76"
    },
    {
      "parameters": {
        "formTitle": "Refer someone",
        "formDescription": "Portfolio demo form. Submissions land in the same rules engine as the webhook.",
        "responseMode": "lastNode",
        "formFields": {
          "values": [
            {
              "fieldLabel": "name",
              "fieldType": "text",
              "requiredField": false
            },
            {
              "fieldLabel": "email",
              "fieldType": "text",
              "requiredField": false
            },
            {
              "fieldLabel": "role",
              "fieldType": "text",
              "requiredField": false
            },
            {
              "fieldLabel": "years",
              "fieldType": "number",
              "requiredField": false
            },
            {
              "fieldLabel": "workAuth",
              "fieldType": "text",
              "requiredField": false
            },
            {
              "fieldLabel": "resumeText",
              "fieldType": "text",
              "requiredField": false
            }
          ]
        }
      },
      "id": "9c13f25e-501e-4e47-b597-a0b1bc94ef6b",
      "name": "Web form",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.2,
      "position": [
        40,
        640
      ],
      "notes": "n8n Form trigger. Field names match the sample payload.",
      "notesInFlow": true,
      "webhookId": "7ff8fb69-459b-4b3d-b285-4344856b7318"
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const sample = {\n  \"demo\": true,\n  \"name\": \"Leila Haddad\",\n  \"email\": \"leila@example.com\",\n  \"role\": \"Automation engineer\",\n  \"years\": 5,\n  \"workAuth\": true,\n  \"resumeText\": \"Five years building JavaScript services, SQL reporting, and n8n workflows for HubSpot teams.\",\n  \"source\": \"referral\",\n  \"referrer\": \"Amina\"\n};\nconst incoming = $input.first()?.json ?? {};\nconst provided = Object.keys(incoming).filter((key) => incoming[key] !== undefined && incoming[key] !== null && incoming[key] !== '');\nconst base = provided.length ? { ...sample, ...incoming } : { ...sample };\nconst flag = incoming.demo;\nbase.demo = !(flag === false || flag === 'false' || flag === 0 || flag === '0');\nreturn [{ json: base }];\n"
      },
      "id": "40ced0cb-77d6-4f06-9bd8-f4403a7426dd",
      "name": "Normalize input",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        340,
        360
      ],
      "notes": "Merges the request over the bundled sample. demo stays true unless the caller explicitly turns it off.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const item = $input.first().json;\nconst produced = (() => {\n\nconst text = String(item.resumeText || item.cv || '').toLowerCase();\nconst must = ['javascript', 'sql'];\nconst nice = ['n8n'];\nconst haveMust = must.filter((skill) => text.includes(skill));\nconst haveNice = nice.filter((skill) => text.includes(skill));\nconst experience = Number(item.years || (text.match(/(\\d+)\\s+\\+?\\s*years/) || [])[1] || 0);\nlet score = haveMust.length * 20 + haveNice.length * 8;\nif (experience >= 3) score += 15;\nif (item.workAuth === false) score -= 25;\nscore = Math.max(0, Math.min(100, score));\nconst route = haveMust.length < Math.ceil(must.length / 2) ? 'reject' : score >= 70 ? 'screen' : 'hold';\nconst record = {\n  name: item.name || 'Candidate',\n  email: item.email || '',\n  role: item.role || 'Open role',\n  score,\n  route,\n  haveMust: haveMust.join(', '),\n  haveNice: haveNice.join(', '),\n  experience,\n  title: (item.name || 'Candidate') + ' \u2014 ' + (item.role || 'role'),\n};\nreturn {\n  summary: record.name + ' scored ' + score + ' for ' + record.role + ' (' + route + ').',\n  route,\n  record,\n  slackText: route.toUpperCase() + ' ' + record.name + ' (' + score + ') for ' + record.role,\n  actions: [{ app: 'ATS', operation: route, payload: record }],\n};\n\n})();\nif (!produced || typeof produced.summary !== 'string' || !produced.summary.trim()) {\n  throw new Error('Apply rules must return a summary string');\n}\nreturn [{\n  json: {\n    ...item,\n    ...produced,\n    demo: item.demo !== false,\n  },\n}];\n"
      },
      "id": "d655c498-7967-4592-90bf-8dc6a41e10a8",
      "name": "Apply rules",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        620,
        360
      ],
      "notes": "Deterministic stand-in for the model or enrichment API. Replace or precede this with a live model node when you turn demo mode off.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "3c308f24-4349-45db-9806-2c6e8223bdb9",
              "leftValue": "={{ $json.demo }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "cfa98e19-2634-43e5-8d20-571ba84bb937",
      "name": "Demo mode?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        900,
        360
      ],
      "notes": "True: package the offline result. False: run the credentialed apps.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const item = $input.first().json;\nreturn [{\n  json: {\n    demo: true,\n    status: 'demo_ready',\n    workflow: 'referral-intake',\n    summary: item.summary,\n    route: item.route ?? null,\n    record: item.record ?? {},\n    actions: item.actions ?? [],\n    slackText: item.slackText ?? item.summary,\n    notes: 'Demo mode did not call external apps. Send {\"demo\": false} after placeholder credentials are replaced.',\n  },\n}];\n"
      },
      "id": "e97cd5e8-f747-4021-a0a1-88808bfb3521",
      "name": "Package demo result",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1180,
        180
      ]
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "sheet",
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_SPREADSHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Referrals"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {},
          "matchingColumns": [],
          "schema": []
        },
        "options": {}
      },
      "id": "96a72584-f8a3-40fb-ae48-af52ac8b8635",
      "name": "Append Referrals",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        1180,
        760
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "PLACEHOLDER_GOOGLESHEETSOAUTH2API",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "message",
        "operation": "post",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "name",
          "value": "#hiring"
        },
        "text": "={{ $json.slackText || $json.summary }}",
        "otherOptions": {}
      },
      "id": "0e1d2a88-dae8-4d46-9ea8-a0fe4075865d",
      "name": "Post #hiring",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [
        1460,
        760
      ],
      "credentials": {
        "slackOAuth2Api": {
          "id": "PLACEHOLDER_SLACKOAUTH2API",
          "name": "Slack account"
        }
      }
    },
    {
      "parameters": {
        "content": "## Live path\n\nReplace every `PLACEHOLDER_*` credential, then POST the sample with `\"demo\": false`.\n\nThe nodes on this branch use the `record` and `actions` fields produced by Apply rules.",
        "height": 180,
        "width": 420,
        "color": 6
      },
      "id": "0bcb1f93-70d1-44ee-b309-32ec9d829205",
      "name": "Live path",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1120,
        520
      ]
    }
  ],
  "connections": {
    "Run demo": {
      "main": [
        [
          {
            "node": "Normalize input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Inbound webhook": {
      "main": [
        [
          {
            "node": "Normalize input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Web form": {
      "main": [
        [
          {
            "node": "Normalize input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize input": {
      "main": [
        [
          {
            "node": "Apply rules",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Apply rules": {
      "main": [
        [
          {
            "node": "Demo mode?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Demo mode?": {
      "main": [
        [
          {
            "node": "Package demo result",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Append Referrals",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append Referrals": {
      "main": [
        [
          {
            "node": "Post #hiring",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "meta": {
    "templateCredsSetupCompleted": false,
    "description": "A referral form is scored with the same rubric as a direct applicant and logged with the referrer's name."
  },
  "active": false
}
