jackwener/OpenCLI · error · CommandExecutionError
该聊天缺少 securityId,无法获取历史消息
Error message
该聊天缺少 securityId,无法获取历史消息
What it means
bossChatMsg throws CommandExecutionError('该聊天缺少 securityId,无法获取历史消息') when the matched chat entry exists but its securityId field is missing or empty. BOSS's historyMsg endpoint requires both gid and securityId as path parameters, so the library refuses to issue a request it knows will fail. This is a data-shape defect in the scraped friend record, not a user input problem.
Source
Thrown at clis/boss/chatmsg.js:42
};
}
function mapGeekMsg(m, friend) {
const fromUid = m.from && m.from.uid;
const isFromBoss = fromUid != null && String(fromUid) === String(friend.uid);
return {
from: isFromBoss ? '对方' : '我',
type: TYPE_MAP[m.type] || `其他(${m.type})`,
text: m.text || m.body?.text || m.body?.content || m.body?.showText ||
JSON.stringify(m.body || {}).slice(0, 120),
time: m.time ? new Date(m.time).toLocaleString('zh-CN') : '',
};
}
async function bossChatMsg(page, kwargs, existingFriend) {
const friend = existingFriend ?? await findFriendByUid(page, kwargs.uid);
if (!friend) throw new EmptyResultError('boss chatmsg', '未找到该候选人');
if (!friend.securityId) throw new CommandExecutionError('该聊天缺少 securityId,无法获取历史消息');
const gid = friend.uid;
const securityId = encodeURIComponent(friend.securityId);
const msgUrl = `https://www.zhipin.com/wapi/zpchat/boss/historyMsg?gid=${gid}&securityId=${securityId}&page=${kwargs.page}&c=20&src=0`;
const msgData = await bossFetch(page, msgUrl);
const messages = msgData.zpData?.messages ?? msgData.zpData?.historyMsgList;
if (!Array.isArray(messages)) {
throw new CommandExecutionError('Boss recruiter history response did not include a message list');
}
if (messages.length === 0) {
throw new EmptyResultError('boss chatmsg', 'Boss returned no messages for this chat.');
}
return messages.map((m) => mapBossMsg(m, friend));
}
async function geekChatMsg(page, kwargs, encryptSystemId) {
const friend = await findGeekFriendByUid(page, kwargs.uid, { encryptSystemId });
if (!friend) throw new EmptyResultError('boss chatmsg', '未找到该聊天(geek 侧)');
if (!friend.securityId) throw new CommandExecutionError('该聊天缺少 securityId,无法获取历史消息');View on GitHub (pinned to 49907e53dc)
Solutions
- Re-run the command; if the chat list was read mid-render, a fresh pass often populates securityId.
- Refresh the chat list page and retry: `opencli boss chatmsg <uid> --side boss` after re-login/reload.
- If it persists, the friend-list scraper in clis/boss/utils.js likely needs updating for a BOSS DOM/API change — check for a newer version of the CLI package.
- Try the same uid with side=geek (auto mode) in case the geek-side record carries a securityId.
- Report/inspect the raw friend entry (enable verbose output) to confirm securityId is truly absent before filing a bug.
Example fix
// before
const friend = await findFriendByUid(page, kwargs.uid);
// after — retry after forcing a fresh chat-list read
await navigateToChat(page);
const friend = await findFriendByUid(page, kwargs.uid);
if (friend && !friend.securityId) throw new Error('stale chat list — reload and retry'); Defensive patterns
Strategy: retry
Validate before calling
// nothing the caller can check pre-call (server-side field); validate result shape after chatlist
const friends = await chatlist({});
if (friends.length && friends.every(f => !f.securityId)) console.warn('chatlist missing securityId for all entries — scraper/DOM issue'); Type guard
function hasSecurityId(f) { return !!f && typeof f.securityId === 'string' && f.securityId.length > 0; } Try / catch
try {
const msgs = await chatmsg(uid, { side: 'boss' });
} catch (e) {
if (isCommandExecutionError(e) && /securityId/.test(e.message)) {
// reload session / retry once, then try the other side
return chatmsg(uid, { side: 'geek' });
}
throw e;
} Prevention
- Retry once after a short delay — mid-render chat lists often lack securityId.
- Fall back to the opposite side (boss/geek) which may carry the field.
- Keep the CLI package updated for BOSS DOM changes.
- Report persistent cases with verbose dumps of the friend object.
When it happens
Trigger: The chat list DOM/API response used by findFriendByUid returned a friend object without a securityId for this conversation — e.g. BOSS changed the field name/attribute in the friend list payload, or a system/placeholder chat entry has no securityId.
Common situations: BOSS front-end update renaming the securityId attribute so scraping yields undefined; very new or system-generated conversations lacking the field; partially rendered chat list read too early.
Related errors
- Boss recruiter history response did not include a message li
- BOSS detail page did not expose a complete job posting
- Boss recommend response did not include zpData.friendList
- Boss geek chat list response did not include zpData.friendLi
- Boss geek friend enrichment response did not include zpData.
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/8551966d453dc510.
Report an issue: GitHub.