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

@@ -337,12 +337,20 @@ class MqttDispatcher {
? firstMsg.body.text
: null;
// 兼容 uid 为数字或 { low, high } 两种格式
const toUidStr = (uid) => {
if (uid == null) return null;
if (typeof uid === 'number' && !Number.isNaN(uid)) return String(uid);
if (typeof uid === 'object' && typeof uid.low === 'number') return String(uid.low);
return null;
};
const normalized = {
sn_code,
type: payload.type || null,
version: payload.version || null,
from_uid: fromUidObj && typeof fromUidObj.low === 'number' ? String(fromUidObj.low) : null,
to_uid: toUidObj && typeof toUidObj.low === 'number' ? String(toUidObj.low) : null,
from_uid: toUidStr(fromUidObj),
to_uid: toUidStr(toUidObj),
text,
raw: payload
};
@@ -406,12 +414,16 @@ class MqttDispatcher {
// 调用现有 AI 自动回复流程(基于 get_chat_detail + getReplyContentFromDetail
try {
if (normalized.from_uid && this.mqttClient) {
const friendIdNum = normalized.from_uid != null ? Number(normalized.from_uid) : 0;
const hasValidFriendId = friendIdNum > 0 && Number.isFinite(friendIdNum);
if (hasValidFriendId && this.mqttClient) {
const result = await chatManager.auto_reply_with_ai(sn_code, this.mqttClient, {
friendId: Number(normalized.from_uid),
friendId: friendIdNum,
platform: 'boss'
});
console.log('[MQTT Boss 消息] AI 自动回复结果:', result);
} else if (!hasValidFriendId && normalized.from_uid != null) {
console.warn('[MQTT Boss 消息] 跳过 AI 回复friendId 无效或为 0', { from_uid: normalized.from_uid, friendIdNum });
}
} catch (e) {
console.warn('[MQTT Boss 消息] AI 自动回复失败:', e.message);