feat: 钉钉添加 admin_users 配置,管理员用户名字显示 [管理员] 标识

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-06-07 01:07:21 +08:00
parent 9731bff268
commit 38f01ecac7
+29 -3
View File
@@ -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,