Skip to content

User Methods ​

User methods provide access to user information, profile management, contacts, and blocking. These methods operate on the *Client instance and require a context.Context.

go
client, _ := telegram.NewClient(cfg)
user, err := client.GetMe(ctx)

GetMe ​

Retrieves the currently authenticated user's full information. The result is cached on the client.

go
func (c *Client) GetMe(ctx context.Context) (*types.User, error)

Returns: The authenticated *types.User, or an error if not connected.

go
me, err := client.GetMe(ctx)
if err != nil {
    log.Fatal(err)
}
fmt.Printf("Logged in as: %s (ID: %d)\n", me.FirstName, me.ID)

GetUser ​

Retrieves full profile information for a single user by ID.

go
func (c *Client) GetUser(ctx context.Context, userID int64) (*types.User, error)

Parameters:

NameTypeDescription
ctxcontext.ContextCancellation context
userIDint64Identifier of the user

Returns: *types.User with full profile information, or an error.

GetUsers ​

Retrieves full user information for each of the provided user IDs. Users that cannot be resolved are silently skipped.

go
func (c *Client) GetUsers(ctx context.Context, userIDs []int64) ([]*types.User, error)

Parameters:

NameTypeDescription
ctxcontext.ContextCancellation context
userIDs[]int64Slice of user identifiers
go
users, err := client.GetUsers(ctx, []int64{123456, 789012})
if err != nil {
    log.Fatal(err)
}
for _, u := range users {
    fmt.Printf("%s %s (ID: %d)\n", u.FirstName, u.LastName, u.ID)
}

GetCommonChats ​

Retrieves the list of chats (groups, channels, supergroups) shared with a specific user.

go
func (c *Client) GetCommonChats(ctx context.Context, userID int64, limit int) ([]*types.Chat, error)

Parameters:

NameTypeDescription
ctxcontext.ContextCancellation context
userIDint64Identifier of the target user
limitintMaximum chats to return (defaults to 100 if <= 0)

UpdateProfile ​

Updates the current user's first name, last name, and bio. Only non-empty fields are included in the update; pass an empty string for fields that should remain unchanged.

go
func (c *Client) UpdateProfile(ctx context.Context, firstName, lastName, bio string) (*types.User, error)

Parameters:

NameTypeDescription
ctxcontext.ContextCancellation context
firstNamestringNew first name (empty to skip)
lastNamestringNew last name (empty to skip)
biostringNew bio/about text (empty to skip)

Returns: The updated *types.User.

go
updated, err := client.UpdateProfile(ctx, "Alice", "", "Full-stack developer")
if err != nil {
    log.Fatal(err)
}
fmt.Printf("Updated: %s\n", updated.FirstName)

SetProfilePhoto ​

Uploads and sets a new profile photo for the current user.

go
func (c *Client) SetProfilePhoto(ctx context.Context, photo tg.InputFileClass) error

Parameters:

NameTypeDescription
ctxcontext.ContextCancellation context
phototg.InputFileClassUploaded file to use as profile photo

DeleteProfilePhoto ​

Deletes a profile photo by its ID.

go
func (c *Client) DeleteProfilePhoto(ctx context.Context, photoID int64) error

GetProfilePhotos ​

Retrieves a paginated list of profile photos for a user.

go
func (c *Client) GetProfilePhotos(ctx context.Context, userID int64, opts ...*GetProfilePhotosOption) ([]*types.ChatPhoto, error)

Parameters:

NameTypeDescription
ctxcontext.ContextCancellation context
userIDint64Target user identifier
opts...*GetProfilePhotosOptionPagination options (limit defaults to 100)

GetProfilePhotosOption:

FieldTypeDescription
Offsetint32Number of photos to skip
Limitint32Maximum photos to return (default: 100)
MaxIDint64Maximum photo ID (0 to disable filter)
go
photos, err := client.GetProfilePhotos(ctx, userID, &telegram.GetProfilePhotosOption{
    Limit: 10,
})
if err != nil {
    log.Fatal(err)
}
fmt.Printf("User has %d profile photos\n", len(photos))

SetUsername ​

Updates the current user's username. Must comply with Telegram's naming rules.

go
func (c *Client) SetUsername(ctx context.Context, username string) error

SetBio ​

Updates the current user's bio/about text. Must not exceed Telegram's length limit.

go
func (c *Client) SetBio(ctx context.Context, bio string) error

BlockUser ​

Blocks a user from interacting with the current account.

go
func (c *Client) BlockUser(ctx context.Context, userID int64) error
go
err := client.BlockUser(ctx, spammerID)
if err != nil {
    log.Fatal(err)
}
fmt.Println("User blocked")

UnblockUser ​

Removes a user from the blocked list.

go
func (c *Client) UnblockUser(ctx context.Context, userID int64) error

GetBlocked ​

Retrieves a paginated list of blocked users.

go
func (c *Client) GetBlocked(ctx context.Context, limit, offset int) (tg.BlockedClass, error)

Parameters:

NameTypeDescription
ctxcontext.ContextCancellation context
limitintMaximum entries to return
offsetintStarting position for pagination

AddContact ​

Adds a user to the contact list. If share is true, the phone number is shared with the contact.

go
func (c *Client) AddContact(ctx context.Context, userID int64, firstName, lastName, phone string, share bool) error

Parameters:

NameTypeDescription
ctxcontext.ContextCancellation context
userIDint64User to add as contact
firstNamestringContact first name
lastNamestringContact last name
phonestringContact phone number
shareboolWhether to share phone with contact
go
err := client.AddContact(ctx, userID, "Alice", "Smith", "+1234567890", true)
if err != nil {
    log.Fatal(err)
}
fmt.Println("Contact added")

DeleteContacts ​

Removes users from the contact list.

go
func (c *Client) DeleteContacts(ctx context.Context, userIDs []int64) error

GetContacts ​

Retrieves the current user's contact list. The hash parameter is a checksum of the previously known contact list; if it matches the server-side hash, an empty response may be returned.

go
func (c *Client) GetContacts(ctx context.Context, hash int64) (tg.ContactsClass, error)
go
contacts, err := client.GetContacts(ctx, 0)
if err != nil {
    log.Fatal(err)
}

Released under the Apache-2.0 License.