From ea7f9326499d451a68164c75fef9b53aa3ef62ec Mon Sep 17 00:00:00 2001 From: viettranx Date: Tue, 3 Mar 2026 14:10:01 +0700 Subject: [PATCH] feat: Resolve Feishu message mentions by stripping bot mentions and replacing user mentions with names. --- internal/channels/feishu/bot_parse.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/internal/channels/feishu/bot_parse.go b/internal/channels/feishu/bot_parse.go index 0c208b46..d0230d33 100644 --- a/internal/channels/feishu/bot_parse.go +++ b/internal/channels/feishu/bot_parse.go @@ -44,10 +44,9 @@ func (c *Channel) parseMessageEvent(event *MessageEvent) *messageContext { } } - // Strip bot mention from content - if mentionedBot && c.botOpenID != "" { - content = stripBotMention(content, mentions, c.botOpenID) - } + // Replace mention placeholders with readable names. + // Bot mention is stripped entirely; other user mentions become @Name. + content = resolveMentions(content, mentions, c.botOpenID) return &messageContext{ ChatID: chatID, @@ -180,10 +179,19 @@ func parsePostContent(rawContent string) string { return strings.Join(textParts, "\n") } -func stripBotMention(text string, mentions []mentionInfo, botOpenID string) string { +// resolveMentions replaces mention placeholders (@_user_1, @_user_2, etc.) in content. +// Bot mention is stripped entirely; other user mentions become @Name. +func resolveMentions(text string, mentions []mentionInfo, botOpenID string) string { for _, m := range mentions { - if m.OpenID == botOpenID && m.Key != "" { + if m.Key == "" { + continue + } + if botOpenID != "" && m.OpenID == botOpenID { + // Strip bot mention text = strings.ReplaceAll(text, m.Key, "") + } else if m.Name != "" { + // Replace with @Name + text = strings.ReplaceAll(text, m.Key, "@"+m.Name) } } return strings.TrimSpace(text)