feat: 添加排除消息ID参数以优化聊天记录获取逻辑

This commit is contained in:
zhaoyingbo 2024-12-02 08:30:17 +00:00
parent 36c1dc2136
commit f8f0186665
2 changed files with 7 additions and 0 deletions

View File

@ -35,6 +35,7 @@ const agent = async (ctx: Context.Data) => {
endTime,
mentions,
senderOpenId: openId,
excludedMessageIds: [message_id, messageId],
})
// 如果没有聊天记录,返回错误信息
if (chatHistory.length === 0) {

View File

@ -50,12 +50,14 @@ const getChatHistory = async (
endTime,
senderOpenId,
mentions: targetUsers,
excludedMessageIds = [], // 新增参数
}: {
chatId: string
startTime: string
endTime: string
senderOpenId?: string
mentions?: LarkEvent.Mention[]
excludedMessageIds?: string[] // 新增参数类型
}
): Promise<{
messages: Message[]
@ -106,6 +108,10 @@ const getChatHistory = async (
// 遍历历史消息
for (const chat of chatHistory) {
// 过滤掉不需要的消息 ID
if (excludedMessageIds.includes(chat.message_id)) {
continue
}
if (chat.mentions) {
for (const mention of chat.mentions) {
mentions.set(mention.id, mention.name)