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) }