User methods
Methods that read user state or your own session state. Most of the heavy account-management surface lives at the raw TL layer; gogram exposes the everyday subset as helpers.
Who am I
me, err := client.GetMe() fmt.Println(me.ID, me.Username, me.Bot)
me, err := client.GetMe()
fmt.Println(me.ID, me.Username, me.Bot)GetMe returns the *UserObj for the current session. Bots have Bot: true. Cache it on startup; you do not need a round-trip later when you want your own id.
User info
For a known id, GetUser reads from the in-memory cache and falls back to a server lookup:
u, err := client.GetUser(123456789) fmt.Println(u.FirstName, u.LastName, u.Username)
u, err := client.GetUser(123456789)
fmt.Println(u.FirstName, u.LastName, u.Username)For richer profile data — bio, common chats, settings flags — drop down to the raw UsersGetFullUser call.
Profile photos
photos, err := client.GetProfilePhotos("@durov", &telegram.PhotosOptions{
Limit: 20,
})
for _, p := range photos {
fmt.Println(p)
}photos, err := client.GetProfilePhotos("@durov", &telegram.PhotosOptions{
Limit: 20,
})
for _, p := range photos {
fmt.Println(p)
}GetProfilePhotos takes any peer-id form and returns every photo the account has posted to its profile, newest first.
Listing dialogs
dialogs, err := client.GetDialogs(&telegram.DialogOptions{Limit: 100})
for _, d := range dialogs {
fmt.Println(d.Peer, d.Pinned, d.UnreadCount)
}
// or stream every dialog through a callback:
err = client.IterDialogs(func(d *telegram.TLDialog) error {
fmt.Println(d.Peer)
return nil
})dialogs, err := client.GetDialogs(&telegram.DialogOptions{Limit: 100})
for _, d := range dialogs {
fmt.Println(d.Peer, d.Pinned, d.UnreadCount)
}
// or stream every dialog through a callback:
err = client.IterDialogs(func(d *telegram.TLDialog) error {
fmt.Println(d.Peer)
return nil
})Dialogs are the entries shown in the chat list. GetDialogs returns a batch; IterDialogs streams every one through a callback.
Common chats
common, err := client.GetCommonChats(userID)
for _, c := range common {
fmt.Println(c)
}common, err := client.GetCommonChats(userID)
for _, c := range common {
fmt.Println(c)
}Returns the groups and channels both you and the target user are members of.
Emoji status
_, _ = client.SetEmojiStatus(&telegram.EmojiStatusObj{
DocumentID: docID,
})
// clear:
_, _ = client.SetEmojiStatus()_, _ = client.SetEmojiStatus(&telegram.EmojiStatusObj{
DocumentID: docID,
})
// clear:
_, _ = client.SetEmojiStatus()Premium accounts can set a small custom-emoji badge next to their name. Pass an EmojiStatus with the document id of a custom emoji from a sticker set; omit the argument to clear.
Business helpers
Telegram Business accounts get a few extra knobs — away message, greeting message, intro card, business hours, chat links. gogram has typed helpers for each:
_ = client.SetAwayMessage(telegram.SetAwayMessageOptions{
Shortcut: "away",
OfflineOnly: true,
})
_ = client.SetGreetingMessage(telegram.SetGreetingOptions{
Shortcut: "hello",
Inactivity: 7, // days
})_ = client.SetAwayMessage(telegram.SetAwayMessageOptions{
Shortcut: "away",
OfflineOnly: true,
})
_ = client.SetGreetingMessage(telegram.SetGreetingOptions{
Shortcut: "hello",
Inactivity: 7, // days
})Other helpers in the same family: SetBusinessIntro, SetBusinessLocation, SetBusinessHours, CreateBusinessChatLink, ListBusinessChatLinks.
