This commit is contained in:
张成
2026-03-17 15:10:27 +08:00
parent f071215ad5
commit 39a5b49213
5 changed files with 70 additions and 52 deletions

View File

@@ -135,12 +135,16 @@ class ChatManager {
*/
async get_chat_detail(sn_code, mqttClient, params = {}) {
const { platform = 'boss', ...rest } = params;
console.log(`[聊天管理] 开始获取设备 ${sn_code} 的沟通详情`);
const friendId = rest.friendId != null ? Number(rest.friendId) : NaN;
if (!Number.isFinite(friendId) || friendId <= 0) {
throw new Error('缺少必要参数friendId需为有效正数');
}
console.log(`[聊天管理] 开始获取设备 ${sn_code} 的沟通详情`, { friendId });
const response = await mqttClient.publishAndWait(sn_code, {
platform,
action: 'get_chat_detail',
data: rest
data: { ...rest, friendId }
});
const ok = response && (response.code === 200 || response.code === 0);
@@ -285,6 +289,16 @@ class ChatManager {
const jobInfo = detail.job || {};
// 用 messages 判定整条对话最后一条是否来自 HR只有最后一条是 HR 才需要回复
const last_in_messages = messages[messages.length - 1];
const last_from_uid = last_in_messages && last_in_messages.from ? this._normalizeUid(last_in_messages.from.uid) : null;
const hr_uid_str = this._normalizeUid(hr_uid);
const is_last_from_hr = hr_uid_str && last_from_uid === hr_uid_str && !this._isSystemMessage(last_in_messages);
if (!is_last_from_hr) {
this._saveReplyIntentLog(options, '', jobInfo, '', '', false, '最后一条消息不是HR发的', null);
return { replied: false, reason: '最后一条消息不是HR发的' };
}
const hrList = this._filterHrReplyableMessages(messages, geek_uid);
if (hrList.length === 0) {
this._saveReplyIntentLog(options, '', jobInfo, '', '', false, '无HR可回复消息已过滤系统与己方', null);
@@ -292,11 +306,6 @@ class ChatManager {
}
const last = hrList[hrList.length - 1];
if (!last.from || last.from.uid !== hr_uid) {
this._saveReplyIntentLog(options, '', jobInfo, '', '', false, '最后一条可回复消息不是HR', null);
return { replied: false, reason: '最后一条可回复消息不是HR' };
}
const body = last.body || {};
const hr_message_text =
(typeof body.text === 'string' && body.text) ||