From 35e013c8e7ace93b1b881f970120b41ae6f00a70 Mon Sep 17 00:00:00 2001 From: sean2077 <37324769+sean2077@users.noreply.github.com> Date: Fri, 13 Mar 2026 11:52:15 +0800 Subject: [PATCH] fix(feishu): preserve non-bot @mentions in messages sent to agent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, stripMentions() removed all @mention placeholders from message text, including mentions of other users. This meant messages like "@Bot create a task, assign to @张三" arrived at the agent as "create a task, assign to" — losing the referenced user entirely. Now only the bot's own mention is stripped. Other user mentions are replaced with their display name (e.g. @_user_2 → @张三), so the agent can see who was referenced in the original message. Closes #51 --- platform/feishu/feishu.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/platform/feishu/feishu.go b/platform/feishu/feishu.go index 653f6d1..3b5ecbb 100644 --- a/platform/feishu/feishu.go +++ b/platform/feishu/feishu.go @@ -434,7 +434,7 @@ func (p *Platform) onMessage(event *larkim.P2MessageReceiveV1) error { slog.Error(p.tag()+": failed to parse text content", "error", err) return nil } - text := stripMentions(textBody.Text, msg.Mentions) + text := stripMentions(textBody.Text, msg.Mentions, p.botOpenID) if text == "" { return nil } @@ -496,7 +496,7 @@ func (p *Platform) onMessage(event *larkim.P2MessageReceiveV1) error { case "post": textParts, images := p.parsePostContent(messageID, *msg.Content) - text := stripMentions(strings.Join(textParts, "\n"), msg.Mentions) + text := stripMentions(strings.Join(textParts, "\n"), msg.Mentions, p.botOpenID) if text == "" && len(images) == 0 { return nil } @@ -970,14 +970,22 @@ func isBotMentioned(mentions []*larkim.MentionEvent, botOpenID string) bool { return false } -// stripMentions removes @mention placeholders (e.g. @_user_1) from text -// so that group-chat messages like "@Bot /help" become "/help". -func stripMentions(text string, mentions []*larkim.MentionEvent) string { +// stripMentions processes @mention placeholders (e.g. @_user_1) in text. +// The bot's own mention is removed; other user mentions are replaced with +// their display name so the agent can see who was referenced. +func stripMentions(text string, mentions []*larkim.MentionEvent, botOpenID string) string { if len(mentions) == 0 { return text } for _, m := range mentions { - if m.Key != nil { + if m.Key == nil { + continue + } + if botOpenID != "" && m.Id != nil && m.Id.OpenId != nil && *m.Id.OpenId == botOpenID { + text = strings.ReplaceAll(text, *m.Key, "") + } else if m.Name != nil && *m.Name != "" { + text = strings.ReplaceAll(text, *m.Key, "@"+*m.Name) + } else { text = strings.ReplaceAll(text, *m.Key, "") } }