package atproto import ( "encoding/json" "fmt" "net/http" ) // Profile holds resolved ATProto profile information fetched at runtime type Profile struct { DID string `json:"did"` Handle string `json:"handle"` DisplayName string `json:"displayName"` Avatar string `json:"avatar"` PDSURL string `json:"pdsUrl"` } const bskyAppViewURL = "https://public.api.bsky.app" // ResolveProfile fetches a user's profile from the Bluesky public AppView. func ResolveProfile(did string) (*Profile, error) { url := fmt.Sprintf("%s/xrpc/app.bsky.actor.getProfile?actor=%s", bskyAppViewURL, did) resp, err := httpClient.Get(url) if err != nil { return nil, err } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("profile fetch failed: %d", resp.StatusCode) } var result struct { DID string `json:"did"` Handle string `json:"handle"` DisplayName string `json:"displayName"` Avatar string `json:"avatar"` } if err := json.NewDecoder(resp.Body).Decode(&result); err != nil { return nil, err } return &Profile{ DID: result.DID, Handle: result.Handle, DisplayName: result.DisplayName, Avatar: result.Avatar, }, nil } // GetDisplayName returns the best available name for a user func (p *Profile) GetDisplayName() string { if p.DisplayName != "" { return p.DisplayName } if p.Handle != "" && p.Handle != p.DID { return p.Handle } return p.DID }