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,