feat: 添加排除提到的人和消息ID的功能以优化聊天记录获取逻辑
This commit is contained in:
parent
0a3d46e0b4
commit
553f212cc8
@ -9,7 +9,15 @@ const agent = async (ctx: Context.Data) => {
|
||||
larkCard,
|
||||
larkService,
|
||||
appInfo,
|
||||
larkBody: { messageId, msgText, chatId, mentions, rawMsgText, openId },
|
||||
larkBody: {
|
||||
messageId,
|
||||
msgText,
|
||||
chatId,
|
||||
mentions,
|
||||
rawMsgText,
|
||||
openId,
|
||||
mentionedRobot,
|
||||
},
|
||||
} = ctx
|
||||
const cardGender = larkCard.child("groupAgent")
|
||||
// 回复一个loading的卡片
|
||||
@ -36,6 +44,7 @@ const agent = async (ctx: Context.Data) => {
|
||||
mentions,
|
||||
senderOpenId: openId,
|
||||
excludedMessageIds: [message_id, messageId],
|
||||
excludeMentions: [mentionedRobot?.id?.open_id || ""],
|
||||
})
|
||||
// 如果没有聊天记录,返回错误信息
|
||||
if (chatHistory.length === 0) {
|
||||
|
@ -50,14 +50,16 @@ const getChatHistory = async (
|
||||
endTime,
|
||||
senderOpenId,
|
||||
mentions: targetUsers,
|
||||
excludedMessageIds = [], // 新增参数
|
||||
excludedMessageIds = [],
|
||||
excludeMentions = [],
|
||||
}: {
|
||||
chatId: string
|
||||
startTime: string
|
||||
endTime: string
|
||||
senderOpenId?: string
|
||||
mentions?: LarkEvent.Mention[]
|
||||
excludedMessageIds?: string[] // 新增参数类型
|
||||
excludedMessageIds?: string[] // 不需要的消息 ID
|
||||
excludeMentions?: string[] // 不需要的提到的人
|
||||
}
|
||||
): Promise<{
|
||||
messages: Message[]
|
||||
@ -108,15 +110,27 @@ const getChatHistory = async (
|
||||
|
||||
// 遍历历史消息
|
||||
for (const chat of chatHistory) {
|
||||
// 过滤掉不需要的消息 ID
|
||||
if (excludedMessageIds.includes(chat.message_id)) {
|
||||
continue
|
||||
}
|
||||
let hasExcludeMention = false
|
||||
|
||||
if (chat.mentions) {
|
||||
for (const mention of chat.mentions) {
|
||||
mentions.set(mention.id, mention.name)
|
||||
// 过滤掉不需要的提到的人
|
||||
if (excludeMentions.includes(mention.id)) {
|
||||
hasExcludeMention = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 如果提到了不要包含的人,则跳过该消息
|
||||
if (hasExcludeMention) {
|
||||
continue
|
||||
}
|
||||
|
||||
// 过滤掉不需要的消息 ID
|
||||
if (excludedMessageIds.includes(chat.message_id)) {
|
||||
continue
|
||||
}
|
||||
// 过滤掉不是文本和post消息的消息
|
||||
if (!allowedMsgTypes.includes(chat.msg_type)) {
|
||||
continue
|
||||
|
@ -29,20 +29,20 @@
|
||||
"husky": "^9.1.7",
|
||||
"lint-staged": "^15.2.10",
|
||||
"oxlint": "^0.13.2",
|
||||
"prettier": "^3.4.1",
|
||||
"prettier": "^3.4.2",
|
||||
"prisma": "5.22.0",
|
||||
"typescript-eslint": "^8.16.0"
|
||||
"typescript-eslint": "^8.17.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5.5.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@egg/hooks": "^1.2.0",
|
||||
"@egg/lark-msg-tool": "^1.18.0",
|
||||
"@egg/lark-msg-tool": "^1.19.0",
|
||||
"@egg/logger": "^1.6.0",
|
||||
"@egg/net-tool": "^1.19.0",
|
||||
"@egg/path-tool": "^1.4.1",
|
||||
"@langchain/core": "^0.3.19",
|
||||
"@langchain/core": "^0.3.20",
|
||||
"@langchain/openai": "^0.3.14",
|
||||
"@prisma/client": "5.22.0",
|
||||
"joi": "^17.13.3",
|
||||
|
Loading…
x
Reference in New Issue
Block a user