feat: add DingTalk directory-backed session titles

This commit is contained in:
姚章浩
2026-07-23 10:55:25 +08:00
parent 39c5fbbaef
commit 5e0694835a
33 changed files with 1648 additions and 62 deletions
+48
View File
@@ -0,0 +1,48 @@
package session
import (
"strings"
"unicode/utf8"
"gitea.zheromiku.top/Weknora/dobotai-platform/internal/core"
)
// TitleIdentity contains only the display inputs required to name a WeKnora
// session. Stable IDs remain the session identity; titles are display-only.
type TitleIdentity struct {
ConversationType core.ConversationType
ExternalUserID string
ExternalChatID string
SenderName string
ConversationTitle string
}
// BuildDisplayTitle returns a readable DingTalk session title without exposing
// the full stable ID. Direct titles contain only the employee name; department
// and region are deliberately not part of this contract.
func BuildDisplayTitle(identity TitleIdentity) string {
switch identity.ConversationType {
case core.ConversationGroup:
if title := strings.TrimSpace(identity.ConversationTitle); title != "" {
return title
}
return fallbackTitle("钉钉群聊", identity.ExternalChatID)
default:
if name := strings.TrimSpace(identity.SenderName); name != "" {
return name
}
return fallbackTitle("钉钉用户", identity.ExternalUserID)
}
}
func fallbackTitle(prefix, stableID string) string {
stableID = strings.TrimSpace(stableID)
if stableID == "" {
return prefix
}
runes := []rune(stableID)
if utf8.RuneCountInString(stableID) > 4 {
runes = runes[len(runes)-4:]
}
return prefix + "-" + string(runes)
}