{
  "name": "招聘简历自动筛选工作流",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "resume-screening",
        "responseMode": "onReceived",
        "options": {}
      },
      "name": "Webhook收简历",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [0, 0],
      "webhookId": "resume-screening-automation"
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const raw = $input.first().json;\nconst body = raw.body || raw;\n// 简历来源：招聘官网表单 / 邮箱附件 / IM bot 转发\nconst candidateName = raw.candidate_name || raw.name || raw.subject || '未署名候选人';\nconst contact = raw.contact || raw.email || raw.phone || raw.user_id || '';\nconst source = raw.source || 'webhook';\nconst jd = raw.jd || raw.job_description || raw.position || '';\n// 简历文本：表单已含纯文本；附件需前置 Extract from File 节点解析\nlet resumeText = raw.resume_text || raw.resume || raw.content || raw.text || '';\nif (raw.attachment_b64) {\n  // 二进制附件由上游 Extract from File 节点转为 text；此处兜底标记\n  resumeText = resumeText || '[附件未解析，需前置 Extract from File 节点]';\n}\n// 清洗：去页眉页脚分隔线、多余空行、邮箱签名噪音\nresumeText = resumeText.replace(/-{3,}[\\s\\S]*?-{3,}/g, ' ').replace(/\\n{3,}/g, '\\n\\n').trim();\n// 去重键：联系方式优先，否则姓名加来源\nconst dedupKey = contact || (candidateName + '|' + source);\nreturn { json: { ...body, candidateName, contact, source, jd, resumeText, dedupKey } };"
      },
      "name": "提取文本",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [220, 0]
    },
    {
      "parameters": {
        "url": "https://api.moonshot.cn/v1/chat/completions",
        "method": "POST",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            { "name": "Authorization", "value": "Bearer YOUR_LLM_API_KEY" },
            { "name": "Content-Type", "value": "application/json" }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"model\":\"moonshot-v1-8k\",\"messages\":[{\"role\":\"system\",\"content\":\"你是招聘助理，按JD给候选人简历打分，输出JSON：skill_match(0-100,技能与JD关键词匹配度)、experience(0-100,工作年限与项目经验契合度)、stability(0-100,跳槽频率与履历连贯性,频繁跳槽扣分)、risk(low/medium/high,风险信号如空窗期过长/经历与JD严重不符/简历矛盾)、score(综合0-100)、tier(interview:score>=80进面试 / pool:60-79备选 / reject:<60婉拒,三选一)、reason(百字内,引用简历事实)、interview_questions(建议追问2-3条)。规则：仅依据技能、经验、项目、履历判断；禁止使用性别、年龄、婚育、种族、户籍、残疾、宗教、政治面貌等受保护属性评分,简历中出现一律忽略；不编造简历中没有的事实；信息严重不足时score默认50、tier默认pool并在reason前加[信息不足]。\"},{\"role\":\"user\",\"content\":\"={{JSON.stringify({jd:$json.jd,resume_text:$json.resumeText})}}\"}]}",
        "options": {}
      },
      "name": "LLM按JD打分",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [440, 0]
    },
    {
      "parameters": {
        "conditions": {
          "combinator": "or",
          "boolean": [
            { "value1": "={{JSON.parse($json.choices[0].message.content).tier}}", "value2": "interview" },
            { "value1": "={{JSON.parse($json.choices[0].message.content).tier}}", "value2": "pool" }
          ]
        }
      },
      "name": "IF达标",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [660, 0]
    },
    {
      "parameters": {
        "dataType": "string",
        "value1": "={{JSON.parse($json.choices[0].message.content).tier}}",
        "rules": {
          "rules": [
            { "value2": "interview" }
          ]
        },
        "fallbackOutput": 1
      },
      "name": "Switch路由",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 1,
      "position": [880, -160]
    },
    {
      "parameters": {
        "url": "YOUR_FEISHU_BITABLE_INTERVIEW_API_URL",
        "method": "POST",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            { "name": "Authorization", "value": "Bearer YOUR_FEISHU_TOKEN" },
            { "name": "Content-Type", "value": "application/json" }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"fields\":{\"候选人\":\"{{$node[\\\"提取文本\\\"].json.candidateName}}\",\"联系方式\":\"{{$node[\\\"提取文本\\\"].json.contact}}\",\"岗位JD\":\"{{$node[\\\"提取文本\\\"].json.jd}}\",\"score\":{{JSON.parse($json.choices[0].message.content).score}},\"risk\":\"{{JSON.parse($json.choices[0].message.content).risk}}\",\"reason\":\"{{JSON.parse($json.choices[0].message.content).reason}}\",\"interview_questions\":\"{{JSON.parse($json.choices[0].message.content).interview_questions.join(' | ')}}\",\"来源\":\"{{$node[\\\"提取文本\\\"].json.source}}\",\"投递时间\":\"{{$now.toISO()}}\",\"路由\":\"interview\"}}",
        "options": {}
      },
      "name": "写入飞书-面试队列",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [1100, -260]
    },
    {
      "parameters": {
        "url": "YOUR_FEISHU_BITABLE_POOL_API_URL",
        "method": "POST",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            { "name": "Authorization", "value": "Bearer YOUR_FEISHU_TOKEN" },
            { "name": "Content-Type", "value": "application/json" }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"fields\":{\"候选人\":\"{{$node[\\\"提取文本\\\"].json.candidateName}}\",\"联系方式\":\"{{$node[\\\"提取文本\\\"].json.contact}}\",\"岗位JD\":\"{{$node[\\\"提取文本\\\"].json.jd}}\",\"score\":{{JSON.parse($json.choices[0].message.content).score}},\"risk\":\"{{JSON.parse($json.choices[0].message.content).risk}}\",\"reason\":\"{{JSON.parse($json.choices[0].message.content).reason}}\",\"来源\":\"{{$node[\\\"提取文本\\\"].json.source}}\",\"投递时间\":\"{{$now.toISO()}}\",\"路由\":\"pool\"}}",
        "options": {}
      },
      "name": "写入飞书-备选库",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [1100, -60]
    },
    {
      "parameters": {
        "url": "YOUR_EMAIL_API_URL",
        "method": "POST",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"to\":\"{{$node[\\\"提取文本\\\"].json.contact}}\",\"subject\":\"关于您应聘的岗位\",\"body\":\"{{$node[\\\"提取文本\\\"].json.candidateName}}您好，\\n感谢您投递我司岗位。经综合评估，您的情况与本岗位当前需求匹配度较低，暂不进入下一轮。\\n您的简历已按相关法规纳入人才库（如未授权留存可回复此邮件要求删除）。祝求职顺利。\"}",
        "options": {}
      },
      "name": "发婉拒邮件",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [880, 200]
    },
    {
      "parameters": {
        "url": "YOUR_RECRUITER_WEBHOOK_URL",
        "method": "POST",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"msgtype\":\"text\",\"text\":{\"content\":\"[简历过筛-面试队列]\\n候选人: {{$node[\\\"提取文本\\\"].json.candidateName}}\\n岗位: {{$node[\\\"提取文本\\\"].json.jd}}\\n综合分: {{JSON.parse($json.choices[0].message.content).score}}\\n风险: {{JSON.parse($json.choices[0].message.content).risk}}\\n理由: {{JSON.parse($json.choices[0].message.content).reason}}\\n建议追问: {{JSON.parse($json.choices[0].message.content).interview_questions.join(' / ')}}\\n来源: {{$node[\\\"提取文本\\\"].json.source}}\"}}",
        "options": {}
      },
      "name": "通知招聘者",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [1320, -260]
    },
    {
      "parameters": {
        "url": "YOUR_ATS_WRITEBACK_URL",
        "method": "PATCH",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"dedupKey\":\"{{$node[\\\"提取文本\\\"].json.dedupKey}}\",\"status\":\"screened\",\"score\":{{JSON.parse($json.choices[0].message.content).score}},\"tier\":\"{{JSON.parse($json.choices[0].message.content).tier}}\",\"risk\":\"{{JSON.parse($json.choices[0].message.content).risk}}\",\"screened_at\":\"{{$now.toISO()}}\"}",
        "options": {}
      },
      "name": "状态回写ATS",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [1540, 0]
    }
  ],
  "connections": {
    "Webhook收简历": { "main": [ [{ "node": "提取文本", "type": "main", "index": 0 }] ] },
    "提取文本": { "main": [ [{ "node": "LLM按JD打分", "type": "main", "index": 0 }] ] },
    "LLM按JD打分": { "main": [ [{ "node": "IF达标", "type": "main", "index": 0 }] ] },
    "IF达标": { "main": [ [{ "node": "Switch路由", "type": "main", "index": 0 }], [{ "node": "发婉拒邮件", "type": "main", "index": 0 }] ] },
    "Switch路由": { "main": [ [{ "node": "写入飞书-面试队列", "type": "main", "index": 0 }], [{ "node": "写入飞书-备选库", "type": "main", "index": 0 }] ] },
    "写入飞书-面试队列": { "main": [ [{ "node": "通知招聘者", "type": "main", "index": 0 }] ] },
    "通知招聘者": { "main": [ [{ "node": "状态回写ATS", "type": "main", "index": 0 }] ] },
    "写入飞书-备选库": { "main": [ [{ "node": "状态回写ATS", "type": "main", "index": 0 }] ] },
    "发婉拒邮件": { "main": [ [{ "node": "状态回写ATS", "type": "main", "index": 0 }] ] }
  }
}
