feat: 钉钉添加 admin_users 配置,管理员用户名字显示 [管理员] 标识
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -82,6 +82,9 @@ type Platform struct {
|
|||||||
cardThrottleMs int
|
cardThrottleMs int
|
||||||
degradeUntil time.Time
|
degradeUntil time.Time
|
||||||
degradeMu sync.Mutex
|
degradeMu sync.Mutex
|
||||||
|
|
||||||
|
// Admin tag configuration
|
||||||
|
adminUsers map[string]bool // user IDs that get "[管理员]" tag
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(opts map[string]any) (core.Platform, error) {
|
func New(opts map[string]any) (core.Platform, error) {
|
||||||
@@ -132,6 +135,18 @@ func New(opts map[string]any) (core.Platform, error) {
|
|||||||
cardThrottleMs = v
|
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{
|
return &Platform{
|
||||||
clientID: clientID,
|
clientID: clientID,
|
||||||
clientSecret: clientSecret,
|
clientSecret: clientSecret,
|
||||||
@@ -144,6 +159,7 @@ func New(opts map[string]any) (core.Platform, error) {
|
|||||||
cardTemplateID: cardTemplateID,
|
cardTemplateID: cardTemplateID,
|
||||||
cardTemplateKey: cardTemplateKey,
|
cardTemplateKey: cardTemplateKey,
|
||||||
cardThrottleMs: cardThrottleMs,
|
cardThrottleMs: cardThrottleMs,
|
||||||
|
adminUsers: adminUsers,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,6 +289,12 @@ func (p *Platform) onMessage(data *chatbot.BotCallbackDataModel, richText *richT
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 告诉ai该用户是否是管理员
|
||||||
|
userName := data.SenderNick
|
||||||
|
if p.adminUsers[data.SenderStaffId] {
|
||||||
|
userName += "[管理员]"
|
||||||
|
}
|
||||||
|
|
||||||
// Handle richText messages — extract plain text and images from rich content
|
// Handle richText messages — extract plain text and images from rich content
|
||||||
if data.Msgtype == "richText" {
|
if data.Msgtype == "richText" {
|
||||||
text, imageCodes := extractRichText(data.Content)
|
text, imageCodes := extractRichText(data.Content)
|
||||||
@@ -299,7 +321,7 @@ func (p *Platform) onMessage(data *chatbot.BotCallbackDataModel, richText *richT
|
|||||||
SessionKey: sessionKey,
|
SessionKey: sessionKey,
|
||||||
Platform: "dingtalk",
|
Platform: "dingtalk",
|
||||||
UserID: data.SenderStaffId,
|
UserID: data.SenderStaffId,
|
||||||
UserName: data.SenderNick,
|
UserName: userName,
|
||||||
ChatName: data.ConversationTitle,
|
ChatName: data.ConversationTitle,
|
||||||
Content: text,
|
Content: text,
|
||||||
MessageID: data.MsgId,
|
MessageID: data.MsgId,
|
||||||
@@ -335,7 +357,7 @@ func (p *Platform) onMessage(data *chatbot.BotCallbackDataModel, richText *richT
|
|||||||
SessionKey: sessionKey,
|
SessionKey: sessionKey,
|
||||||
Platform: "dingtalk",
|
Platform: "dingtalk",
|
||||||
UserID: data.SenderStaffId,
|
UserID: data.SenderStaffId,
|
||||||
UserName: data.SenderNick,
|
UserName: userName,
|
||||||
ChatName: data.ConversationTitle,
|
ChatName: data.ConversationTitle,
|
||||||
Content: messageContent,
|
Content: messageContent,
|
||||||
MessageID: data.MsgId,
|
MessageID: data.MsgId,
|
||||||
@@ -412,11 +434,15 @@ func (p *Platform) handleAudioMessage(data *chatbot.BotCallbackDataModel, sessio
|
|||||||
slog.Error("dingtalk: failed to download audio", "error", err)
|
slog.Error("dingtalk: failed to download audio", "error", err)
|
||||||
// Fallback to recognition text if available
|
// Fallback to recognition text if available
|
||||||
if recognition != "" {
|
if recognition != "" {
|
||||||
|
userName := data.SenderNick
|
||||||
|
if p.adminUsers[data.SenderStaffId] {
|
||||||
|
userName += "[管理员]"
|
||||||
|
}
|
||||||
msg := &core.Message{
|
msg := &core.Message{
|
||||||
SessionKey: sessionKey,
|
SessionKey: sessionKey,
|
||||||
Platform: "dingtalk",
|
Platform: "dingtalk",
|
||||||
UserID: data.SenderStaffId,
|
UserID: data.SenderStaffId,
|
||||||
UserName: data.SenderNick,
|
UserName: userName,
|
||||||
Content: recognition,
|
Content: recognition,
|
||||||
MessageID: data.MsgId,
|
MessageID: data.MsgId,
|
||||||
ChannelKey: data.ConversationId,
|
ChannelKey: data.ConversationId,
|
||||||
|
|||||||
Reference in New Issue
Block a user