From 38f01ecac7e797538356056caad56e058e0d1f49 Mon Sep 17 00:00:00 2001 From: Kaxi <1042864399@qq.com> Date: Sun, 7 Jun 2026 01:07:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=92=89=E9=92=89=E6=B7=BB=E5=8A=A0=20?= =?UTF-8?q?admin=5Fusers=20=E9=85=8D=E7=BD=AE=EF=BC=8C=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=E7=94=A8=E6=88=B7=E5=90=8D=E5=AD=97=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=20[=E7=AE=A1=E7=90=86=E5=91=98]=20=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.7 --- platform/dingtalk/dingtalk.go | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/platform/dingtalk/dingtalk.go b/platform/dingtalk/dingtalk.go index 87388ac..563b4bc 100644 --- a/platform/dingtalk/dingtalk.go +++ b/platform/dingtalk/dingtalk.go @@ -82,6 +82,9 @@ type Platform struct { cardThrottleMs int degradeUntil time.Time degradeMu sync.Mutex + + // Admin tag configuration + adminUsers map[string]bool // user IDs that get "[管理员]" tag } func New(opts map[string]any) (core.Platform, error) { @@ -132,6 +135,18 @@ func New(opts map[string]any) (core.Platform, error) { cardThrottleMs = v } + // Parse admin user list + adminUsers := make(map[string]bool) + if raw, ok := opts["admin_users"]; ok { + if list, ok := raw.([]any); ok { + for _, id := range list { + if s, ok := id.(string); ok && s != "" { + adminUsers[s] = true + } + } + } + } + return &Platform{ clientID: clientID, clientSecret: clientSecret, @@ -144,6 +159,7 @@ func New(opts map[string]any) (core.Platform, error) { cardTemplateID: cardTemplateID, cardTemplateKey: cardTemplateKey, cardThrottleMs: cardThrottleMs, + adminUsers: adminUsers, }, nil } @@ -273,6 +289,12 @@ func (p *Platform) onMessage(data *chatbot.BotCallbackDataModel, richText *richT return } + // 告诉ai该用户是否是管理员 + userName := data.SenderNick + if p.adminUsers[data.SenderStaffId] { + userName += "[管理员]" + } + // Handle richText messages — extract plain text and images from rich content if data.Msgtype == "richText" { text, imageCodes := extractRichText(data.Content) @@ -299,7 +321,7 @@ func (p *Platform) onMessage(data *chatbot.BotCallbackDataModel, richText *richT SessionKey: sessionKey, Platform: "dingtalk", UserID: data.SenderStaffId, - UserName: data.SenderNick, + UserName: userName, ChatName: data.ConversationTitle, Content: text, MessageID: data.MsgId, @@ -335,7 +357,7 @@ func (p *Platform) onMessage(data *chatbot.BotCallbackDataModel, richText *richT SessionKey: sessionKey, Platform: "dingtalk", UserID: data.SenderStaffId, - UserName: data.SenderNick, + UserName: userName, ChatName: data.ConversationTitle, Content: messageContent, MessageID: data.MsgId, @@ -412,11 +434,15 @@ func (p *Platform) handleAudioMessage(data *chatbot.BotCallbackDataModel, sessio slog.Error("dingtalk: failed to download audio", "error", err) // Fallback to recognition text if available if recognition != "" { + userName := data.SenderNick + if p.adminUsers[data.SenderStaffId] { + userName += "[管理员]" + } msg := &core.Message{ SessionKey: sessionKey, Platform: "dingtalk", UserID: data.SenderStaffId, - UserName: data.SenderNick, + UserName: userName, Content: recognition, MessageID: data.MsgId, ChannelKey: data.ConversationId,