mark.js
1 /** 2 * BOSS直聘 mark — label/mark a candidate. 3 * 4 * Available labels: 5 * 1=新招呼, 2=沟通中, 3=已约面, 4=已获取简历, 5=已交换电话, 6 * 6=已交换微信, 7=不合适, 8=牛人发起, 11=收藏 7 */ 8 import { cli, Strategy } from '@jackwener/opencli/registry'; 9 import { requirePage, navigateToChat, bossFetch, findFriendByUid, verbose } from './utils.js'; 10 import { ArgumentError, EmptyResultError } from '@jackwener/opencli/errors'; 11 const LABEL_MAP = { 12 '新招呼': 1, '沟通中': 2, '已约面': 3, '已获取简历': 4, 13 '已交换电话': 5, '已交换微信': 6, '不合适': 7, '牛人发起': 8, '收藏': 11, 14 }; 15 cli({ 16 site: 'boss', 17 name: 'mark', 18 description: 'BOSS直聘给候选人添加标签', 19 domain: 'www.zhipin.com', 20 strategy: Strategy.COOKIE, 21 navigateBefore: false, 22 browser: true, 23 args: [ 24 { name: 'uid', positional: true, required: true, help: 'Encrypted UID of the candidate' }, 25 { name: 'label', required: true, help: 'Label name (新招呼/沟通中/已约面/已获取简历/已交换电话/已交换微信/不合适/收藏) or label ID' }, 26 { name: 'remove', type: 'boolean', default: false, help: 'Remove the label instead of adding' }, 27 ], 28 columns: ['status', 'detail'], 29 func: async (page, kwargs) => { 30 requirePage(page); 31 const labelInput = kwargs.label; 32 const remove = kwargs.remove || false; 33 // Resolve label to ID 34 let labelId; 35 if (LABEL_MAP[labelInput]) { 36 labelId = LABEL_MAP[labelInput]; 37 } 38 else if (!isNaN(Number(labelInput))) { 39 labelId = Number(labelInput); 40 } 41 else { 42 const entry = Object.entries(LABEL_MAP).find(([k]) => k.includes(labelInput)); 43 if (entry) { 44 labelId = entry[1]; 45 } 46 else { 47 throw new ArgumentError(`未知标签: ${labelInput}。可用标签: ${Object.keys(LABEL_MAP).join(', ')}`); 48 } 49 } 50 verbose(`${remove ? 'Removing' : 'Adding'} label ${labelId} for ${kwargs.uid}...`); 51 await navigateToChat(page); 52 const friend = await findFriendByUid(page, kwargs.uid, { checkGreetList: true }); 53 if (!friend) 54 throw new EmptyResultError('boss candidate search'); 55 const friendName = friend.name || '候选人'; 56 const action = remove ? 'deleteMark' : 'addMark'; 57 const params = new URLSearchParams({ 58 friendId: String(friend.uid), 59 friendSource: String(friend.friendSource ?? 0), 60 labelId: String(labelId), 61 }); 62 await bossFetch(page, `https://www.zhipin.com/wapi/zprelation/friend/label/${action}?${params.toString()}`); 63 const labelName = Object.entries(LABEL_MAP).find(([, v]) => v === labelId)?.[0] || String(labelId); 64 return [{ 65 status: remove ? '✅ 标签已移除' : '✅ 标签已添加', 66 detail: `${friendName}: ${remove ? '移除' : '添加'}标签「${labelName}」`, 67 }]; 68 }, 69 });