Documentation ¶
Overview ¶
Package peers contains helpers to work with Telegram peers.
NB: this package is completely experimental and still WIP. API and behavior may be changed dramatically, so use it with caution.
Index ¶
- type Bot
- type Broadcast
- type Cache
- type Channel
- func (c Channel) AdminRights() (tg.ChatAdminRights, bool)
- func (c Channel) BannedRights() (tg.ChatBannedRights, bool)
- func (c Channel) CallActive() bool
- func (c Channel) CallNotEmpty() bool
- func (c Channel) Creator() bool
- func (c Channel) DefaultBannedRights() (tg.ChatBannedRights, bool)
- func (c Channel) Delete(ctx context.Context) error
- func (c Channel) DisableReactions(ctx context.Context) error
- func (c Channel) Fake() bool
- func (c Channel) FullRaw(ctx context.Context) (*tg.ChannelFull, error)
- func (c Channel) HasGeo() bool
- func (c Channel) HasLink() bool
- func (c Channel) ID() int64
- func (c Channel) InputChannel() tg.InputChannelClass
- func (c Channel) InputPeer() tg.InputPeerClass
- func (c Channel) InviteLinks() InviteLinks
- func (c Channel) IsBroadcast() bool
- func (c Channel) IsSupergroup() bool
- func (c Channel) Join(ctx context.Context) error
- func (c Channel) Leave(ctx context.Context) error
- func (c Channel) Left() bool
- func (c Channel) Manager() *Manager
- func (c Channel) NoForwards() bool
- func (c Channel) ParticipantsCount() int
- func (c Channel) Photo(ctx context.Context) (*tg.Photo, bool, error)
- func (c Channel) Raw() *tg.Channel
- func (c Channel) Report(ctx context.Context, reason tg.ReportReasonClass, message string) error
- func (c Channel) Restricted() ([]tg.RestrictionReason, bool)
- func (c Channel) Scam() bool
- func (c Channel) SetDescription(ctx context.Context, about string) error
- func (c Channel) SetReactions(ctx context.Context, reactions ...tg.ReactionClass) error
- func (c Channel) SetTitle(ctx context.Context, title string) error
- func (c Channel) Sync(ctx context.Context) error
- func (c Channel) TDLibPeerID() constant.TDLibPeerID
- func (c Channel) ToBroadcast() (Broadcast, bool)
- func (c Channel) ToSupergroup() (Supergroup, bool)
- func (c Channel) Username() (string, bool)
- func (c Channel) Verified() bool
- func (c Channel) VisibleName() string
- type Chat
- func (c Chat) ActualChat(ctx context.Context) (Channel, bool, error)
- func (c Chat) AdminRights() (tg.ChatAdminRights, bool)
- func (c Chat) CallActive() bool
- func (c Chat) CallNotEmpty() bool
- func (c Chat) Creator() bool
- func (c Chat) Deactivated() bool
- func (c Chat) DefaultBannedRights() (tg.ChatBannedRights, bool)
- func (c Chat) DisableReactions(ctx context.Context) error
- func (c Chat) Fake() bool
- func (c Chat) FullRaw(ctx context.Context) (*tg.ChatFull, error)
- func (c Chat) ID() int64
- func (c Chat) InputPeer() tg.InputPeerClass
- func (c Chat) InviteLinks() InviteLinks
- func (c Chat) IsBroadcast() bool
- func (c Chat) IsSupergroup() bool
- func (c Chat) Leave(ctx context.Context) error
- func (c Chat) LeaveAndDelete(ctx context.Context) error
- func (c Chat) Left() bool
- func (c Chat) Manager() *Manager
- func (c Chat) MigratedTo() (tg.InputChannelClass, bool)
- func (c Chat) NoForwards() bool
- func (c Chat) ParticipantsCount() int
- func (c Chat) Photo(ctx context.Context) (*tg.Photo, bool, error)
- func (c Chat) Raw() *tg.Chat
- func (c Chat) Report(ctx context.Context, reason tg.ReportReasonClass, message string) error
- func (c Chat) Restricted() ([]tg.RestrictionReason, bool)
- func (c Chat) Scam() bool
- func (c Chat) SetDescription(ctx context.Context, about string) error
- func (c Chat) SetReactions(ctx context.Context, reactions ...tg.ReactionClass) error
- func (c Chat) SetTitle(ctx context.Context, title string) error
- func (c Chat) Sync(ctx context.Context) error
- func (c Chat) TDLibPeerID() constant.TDLibPeerID
- func (c Chat) ToBroadcast() (Broadcast, bool)
- func (c Chat) ToSupergroup() (Supergroup, bool)
- func (c Chat) Username() (string, bool)
- func (c Chat) Verified() bool
- func (c Chat) VisibleName() string
- type ExportLinkOptions
- type GetAllChatsResult
- type InmemoryCache
- func (f *InmemoryCache) FindChannel(ctx context.Context, id int64) (*tg.Channel, bool, error)
- func (f *InmemoryCache) FindChannelFull(ctx context.Context, id int64) (*tg.ChannelFull, bool, error)
- func (f *InmemoryCache) FindChat(ctx context.Context, id int64) (*tg.Chat, bool, error)
- func (f *InmemoryCache) FindChatFull(ctx context.Context, id int64) (*tg.ChatFull, bool, error)
- func (f *InmemoryCache) FindUser(ctx context.Context, id int64) (*tg.User, bool, error)
- func (f *InmemoryCache) FindUserFull(ctx context.Context, id int64) (*tg.UserFull, bool, error)
- func (f *InmemoryCache) SaveChannelFulls(ctx context.Context, channels ...*tg.ChannelFull) error
- func (f *InmemoryCache) SaveChannels(ctx context.Context, channels ...*tg.Channel) error
- func (f *InmemoryCache) SaveChatFulls(ctx context.Context, chats ...*tg.ChatFull) error
- func (f *InmemoryCache) SaveChats(ctx context.Context, chats ...*tg.Chat) error
- func (f *InmemoryCache) SaveUserFulls(ctx context.Context, users ...*tg.UserFull) error
- func (f *InmemoryCache) SaveUsers(ctx context.Context, users ...*tg.User) error
- type InmemoryStorage
- func (f *InmemoryStorage) Find(ctx context.Context, key Key) (value Value, found bool, _ error)
- func (f *InmemoryStorage) FindPhone(ctx context.Context, phone string) (key Key, value Value, found bool, err error)
- func (f *InmemoryStorage) GetContactsHash(ctx context.Context) (int64, error)
- func (f *InmemoryStorage) Save(ctx context.Context, key Key, value Value) error
- func (f *InmemoryStorage) SaveContactsHash(ctx context.Context, hash int64) error
- func (f *InmemoryStorage) SavePhone(ctx context.Context, phone string, key Key) error
- type InviteLink
- func (l InviteLink) CreatedAt() time.Time
- func (l InviteLink) Creator(ctx context.Context) (User, error)
- func (l InviteLink) ExpireDate() (time.Time, bool)
- func (l InviteLink) Link() string
- func (l InviteLink) Permanent() bool
- func (l InviteLink) Raw() *tg.ChatInviteExported
- func (l InviteLink) ReplacedWith() (InviteLink, bool)
- func (l InviteLink) RequestNeeded() bool
- func (l InviteLink) Requested() (int, bool)
- func (l InviteLink) Revoked() bool
- func (l InviteLink) StartDate() (time.Time, bool)
- func (l InviteLink) Title() (string, bool)
- func (l InviteLink) Usage() (int, bool)
- func (l InviteLink) UsageLimit() (int, bool)
- type InviteLinks
- func (e InviteLinks) AddNew(ctx context.Context, opts ExportLinkOptions) (InviteLink, error)
- func (e InviteLinks) ApproveJoin(ctx context.Context, user tg.InputUserClass) error
- func (e InviteLinks) DeclineJoin(ctx context.Context, user tg.InputUserClass) error
- func (e InviteLinks) Delete(ctx context.Context, link string) error
- func (e InviteLinks) Edit(ctx context.Context, link string, opts ExportLinkOptions) (InviteLink, error)
- func (e InviteLinks) ExportNew(ctx context.Context, opts ExportLinkOptions) (InviteLink, error)
- func (e InviteLinks) Get(ctx context.Context, link string) (InviteLink, error)
- func (e InviteLinks) Revoke(ctx context.Context, link string) (InviteLink, error)
- type Key
- type Manager
- func (m *Manager) API() *tg.Client
- func (m *Manager) Apply(ctx context.Context, users []tg.UserClass, chats []tg.ChatClass) error
- func (m *Manager) Channel(u *tg.Channel) Channel
- func (m *Manager) Chat(u *tg.Chat) Chat
- func (m *Manager) FromInputPeer(ctx context.Context, p tg.InputPeerClass) (Peer, error)
- func (m *Manager) GetAllChats(ctx context.Context, exceptIDs ...int64) (r GetAllChatsResult, _ error)
- func (m *Manager) GetChannel(ctx context.Context, p tg.InputChannelClass) (Channel, error)
- func (m *Manager) GetChannelAccessHash(userID, channelID int64) (accessHash int64, found bool, err error)
- func (m *Manager) GetChat(ctx context.Context, id int64) (Chat, error)
- func (m *Manager) GetUser(ctx context.Context, p tg.InputUserClass) (User, error)
- func (m *Manager) ImportInvite(ctx context.Context, hash string) (Peer, error)
- func (m *Manager) Init(ctx context.Context) error
- func (m *Manager) JoinLink(ctx context.Context, link string) (Peer, error)
- func (m *Manager) Resolve(ctx context.Context, from string) (Peer, error)
- func (m *Manager) ResolveChannelID(ctx context.Context, id int64) (Channel, error)
- func (m *Manager) ResolveChatID(ctx context.Context, id int64) (Chat, error)
- func (m *Manager) ResolveDeeplink(ctx context.Context, u string) (Peer, error)
- func (m *Manager) ResolveDomain(ctx context.Context, domain string) (Peer, error)
- func (m *Manager) ResolvePeer(ctx context.Context, p tg.PeerClass) (Peer, error)
- func (m *Manager) ResolvePhone(ctx context.Context, phone string) (User, error)
- func (m *Manager) ResolveTDLibID(ctx context.Context, peerID constant.TDLibPeerID) (p Peer, err error)
- func (m *Manager) ResolveUserID(ctx context.Context, id int64) (User, error)
- func (m *Manager) Search(ctx context.Context, q string) (SearchResult, error)
- func (m *Manager) Self(ctx context.Context) (User, error)
- func (m *Manager) SetChannelAccessHash(userID, channelID, accessHash int64) error
- func (m *Manager) UpdateHook(next telegram.UpdateHandler) telegram.UpdateHandler
- func (m *Manager) User(u *tg.User) User
- func (m *Manager) UserResolveHook(ctx context.Context) entity.UserResolver
- type NoopCache
- func (n NoopCache) FindChannel(ctx context.Context, id int64) (*tg.Channel, bool, error)
- func (n NoopCache) FindChannelFull(ctx context.Context, id int64) (*tg.ChannelFull, bool, error)
- func (n NoopCache) FindChat(ctx context.Context, id int64) (*tg.Chat, bool, error)
- func (n NoopCache) FindChatFull(ctx context.Context, id int64) (*tg.ChatFull, bool, error)
- func (n NoopCache) FindUser(ctx context.Context, id int64) (*tg.User, bool, error)
- func (n NoopCache) FindUserFull(ctx context.Context, id int64) (*tg.UserFull, bool, error)
- func (n NoopCache) SaveChannelFulls(ctx context.Context, channels ...*tg.ChannelFull) error
- func (n NoopCache) SaveChannels(ctx context.Context, channels ...*tg.Channel) error
- func (n NoopCache) SaveChatFulls(ctx context.Context, chats ...*tg.ChatFull) error
- func (n NoopCache) SaveChats(ctx context.Context, chats ...*tg.Chat) error
- func (n NoopCache) SaveUserFulls(ctx context.Context, users ...*tg.UserFull) error
- func (n NoopCache) SaveUsers(ctx context.Context, users ...*tg.User) error
- type Options
- type Peer
- type PeerNotFoundError
- type PhoneNotFoundError
- type SearchResult
- type Storage
- type Supergroup
- func (c Supergroup) DisableSlowMode(ctx context.Context) error
- func (c Supergroup) ResetStickerSet(ctx context.Context) error
- func (c Supergroup) SetStickerSet(ctx context.Context, set tg.InputStickerSetClass) error
- func (c Supergroup) SlowmodeEnabled() bool
- func (c Supergroup) ToggleSlowMode(ctx context.Context, seconds int) error
- type User
- func (u User) Block(ctx context.Context) error
- func (u User) Contact() bool
- func (u User) Deleted() bool
- func (u User) Fake() bool
- func (u User) FirstName() (string, bool)
- func (u User) FullRaw(ctx context.Context) (*tg.UserFull, error)
- func (u User) ID() int64
- func (u User) InputPeer() tg.InputPeerClass
- func (u User) InputUser() tg.InputUserClass
- func (u User) InviteTo(ctx context.Context, ch tg.InputChannelClass) error
- func (u User) LangCode() (string, bool)
- func (u User) LastName() (string, bool)
- func (u User) Manager() *Manager
- func (u User) MutualContact() bool
- func (u User) Phone() (string, bool)
- func (u User) Photo(ctx context.Context) (*tg.Photo, bool, error)
- func (u User) Raw() *tg.User
- func (u User) Report(ctx context.Context, reason tg.ReportReasonClass, message string) error
- func (u User) ReportSpam(ctx context.Context) error
- func (u User) Restricted() ([]tg.RestrictionReason, bool)
- func (u User) Scam() bool
- func (u User) Self() bool
- func (u User) Status() (tg.UserStatusClass, bool)
- func (u User) Support() bool
- func (u User) Sync(ctx context.Context) error
- func (u User) TDLibPeerID() constant.TDLibPeerID
- func (u User) ToBot() (Bot, bool)
- func (u User) Unblock(ctx context.Context) error
- func (u User) Username() (string, bool)
- func (u User) Verified() bool
- func (u User) VisibleName() string
- type Value
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bot ¶
type Bot struct {
User
}
Bot is a bot User.
func (Bot) CanBeAdded ¶
CanBeAdded whether can the bot be added to group.
func (Bot) ChatHistory ¶
ChatHistory whether can the bot see all messages in groups.
func (Bot) InlinePlaceholder ¶
InlinePlaceholder returns inline placeholder for this inline bot.
func (Bot) SupportsInline ¶
SupportsInline whether the bot supports inline queries.
type Broadcast ¶
type Broadcast struct {
Channel
}
Broadcast is a broadcast Channel.
func (Broadcast) DiscussionGroup ¶
DiscussionGroup returns linked chat, if any.
func (Broadcast) SetDiscussionGroup ¶
SetDiscussionGroup associates a group to a channel as discussion group for that channel.
func (Broadcast) Signatures ¶
Signatures whether signatures are enabled (channels).
type Cache ¶
type Cache interface { SaveUsers(ctx context.Context, users ...*tg.User) error SaveUserFulls(ctx context.Context, users ...*tg.UserFull) error FindUser(ctx context.Context, id int64) (*tg.User, bool, error) FindUserFull(ctx context.Context, id int64) (*tg.UserFull, bool, error) SaveChats(ctx context.Context, chats ...*tg.Chat) error SaveChatFulls(ctx context.Context, chats ...*tg.ChatFull) error FindChat(ctx context.Context, id int64) (*tg.Chat, bool, error) FindChatFull(ctx context.Context, id int64) (*tg.ChatFull, bool, error) SaveChannels(ctx context.Context, channels ...*tg.Channel) error SaveChannelFulls(ctx context.Context, channels ...*tg.ChannelFull) error FindChannel(ctx context.Context, id int64) (*tg.Channel, bool, error) FindChannelFull(ctx context.Context, id int64) (*tg.ChannelFull, bool, error) }
Cache is peer entities cache.
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
Channel is channel peer.
func (Channel) AdminRights ¶
func (c Channel) AdminRights() (tg.ChatAdminRights, bool)
AdminRights returns admin rights of the user in this channel.
func (Channel) BannedRights ¶
func (c Channel) BannedRights() (tg.ChatBannedRights, bool)
BannedRights returns banned rights of the user in this channel.
func (Channel) CallActive ¶
CallActive whether a group call or livestream is currently active.
func (Channel) CallNotEmpty ¶
CallNotEmpty whether there's anyone in the group call or livestream.
func (Channel) DefaultBannedRights ¶
func (c Channel) DefaultBannedRights() (tg.ChatBannedRights, bool)
DefaultBannedRights returns default chat rights.
func (Channel) DisableReactions ¶
DisableReactions disables reactions.
func (Channel) Fake ¶
Fake whether this user/chat/channel was reported by many users as a fake or scam: be careful when interacting with it.
func (Channel) InputChannel ¶
func (c Channel) InputChannel() tg.InputChannelClass
InputChannel returns input user for this user.
func (Channel) InputPeer ¶
func (c Channel) InputPeer() tg.InputPeerClass
InputPeer returns input peer for this peer.
func (Channel) InviteLinks ¶
func (c Channel) InviteLinks() InviteLinks
InviteLinks returns InviteLinks for this peer.
func (Channel) IsBroadcast ¶ added in v0.56.0
IsBroadcast whether this Channel is Broadcast.
func (Channel) IsSupergroup ¶ added in v0.56.0
IsSupergroup whether this Channel is Supergroup.
func (Channel) NoForwards ¶
NoForwards whether that message forwarding from this channel is not allowed.
func (Channel) ParticipantsCount ¶
ParticipantsCount returns count of participants.
func (Channel) Restricted ¶
func (c Channel) Restricted() ([]tg.RestrictionReason, bool)
Restricted whether this user/chat/channel is restricted.
func (Channel) SetDescription ¶
SetDescription sets new description for this Chat.
func (Channel) SetReactions ¶
SetReactions sets list of available reactions.
Empty list disables reactions at all.
func (Channel) TDLibPeerID ¶
func (c Channel) TDLibPeerID() constant.TDLibPeerID
TDLibPeerID returns TDLibPeerID for this entity.
func (Channel) ToBroadcast ¶
ToBroadcast tries to convert this Channel to Broadcast.
func (Channel) ToSupergroup ¶
func (c Channel) ToSupergroup() (Supergroup, bool)
ToSupergroup tries to convert this Channel to Supergroup.
func (Channel) VisibleName ¶
VisibleName returns visible name of peer.
It returns FirstName + " " + LastName for users, and title for chats and channels.
type Chat ¶
type Chat struct {
// contains filtered or unexported fields
}
Chat is chat peer.
func (Chat) ActualChat ¶
ActualChat returns Channel to which this chat migrated.
Also see MigratedTo.
func (Chat) AdminRights ¶
func (c Chat) AdminRights() (tg.ChatAdminRights, bool)
AdminRights returns admin rights of the user in this channel.
func (Chat) CallActive ¶
CallActive whether a group call or livestream is currently active.
func (Chat) CallNotEmpty ¶
CallNotEmpty whether there's anyone in the group call or livestream.
func (Chat) Deactivated ¶
Deactivated whether the group was migrated.
func (Chat) DefaultBannedRights ¶
func (c Chat) DefaultBannedRights() (tg.ChatBannedRights, bool)
DefaultBannedRights returns default chat rights.
func (Chat) DisableReactions ¶
DisableReactions disables reactions.
func (Chat) Fake ¶
Fake whether this user/chat/channel was reported by many users as a fake or scam: be careful when interacting with it.
func (Chat) InputPeer ¶
func (c Chat) InputPeer() tg.InputPeerClass
InputPeer returns input peer for this peer.
func (Chat) InviteLinks ¶
func (c Chat) InviteLinks() InviteLinks
InviteLinks returns InviteLinks for this peer.
func (Chat) IsBroadcast ¶ added in v0.56.0
IsBroadcast whether this Chat is Broadcast.
func (Chat) IsSupergroup ¶ added in v0.56.0
IsSupergroup whether this Chat is Supergroup.
func (Chat) LeaveAndDelete ¶
LeaveAndDelete leaves this chat and removes the entire chat history of this user in this chat.
func (Chat) MigratedTo ¶
func (c Chat) MigratedTo() (tg.InputChannelClass, bool)
MigratedTo returns a supergroup to which this chat migrated.
func (Chat) NoForwards ¶
NoForwards whether that message forwarding from this channel is not allowed.
func (Chat) ParticipantsCount ¶
ParticipantsCount returns count of participants.
func (Chat) Restricted ¶
func (c Chat) Restricted() ([]tg.RestrictionReason, bool)
Restricted whether this user/chat/channel is restricted.
func (Chat) SetDescription ¶
SetDescription sets new description for this Chat.
func (Chat) SetReactions ¶
SetReactions sets list of available reactions.
Empty list disables reactions at all.
func (Chat) TDLibPeerID ¶
func (c Chat) TDLibPeerID() constant.TDLibPeerID
TDLibPeerID returns TDLibPeerID for this entity.
func (Chat) ToBroadcast ¶
ToBroadcast tries to convert this Chat to Broadcast.
func (Chat) ToSupergroup ¶
func (c Chat) ToSupergroup() (Supergroup, bool)
ToSupergroup tries to convert this Chat to Supergroup.
func (Chat) VisibleName ¶
VisibleName returns visible name of peer.
It returns FirstName + " " + LastName for users, and title for chats and channels.
type ExportLinkOptions ¶
type ExportLinkOptions struct { // Whether users joining the chat via the link need to be approved by chat administrators. RequestNeeded bool // Expiration date. // // If zero, will not be used. ExpireDate time.Time // Maximum number of users that can join using this link. // // If zero, will not be used. UsageLimit int // Title of this link. // // If zero, will not be used. Title string }
ExportLinkOptions is options for ExportNew.
type GetAllChatsResult ¶ added in v0.59.0
GetAllChatsResult is result structure for GetAllChats query.
type InmemoryCache ¶
type InmemoryCache struct {
// contains filtered or unexported fields
}
InmemoryCache is basic in-memory Cache implementation.
func (*InmemoryCache) FindChannel ¶
FindChannel implements Cache.
func (*InmemoryCache) FindChannelFull ¶
func (f *InmemoryCache) FindChannelFull(ctx context.Context, id int64) (*tg.ChannelFull, bool, error)
FindChannelFull implements Cache.
func (*InmemoryCache) FindChatFull ¶
FindChatFull implements Cache.
func (*InmemoryCache) FindUserFull ¶
FindUserFull implements Cache.
func (*InmemoryCache) SaveChannelFulls ¶
func (f *InmemoryCache) SaveChannelFulls(ctx context.Context, channels ...*tg.ChannelFull) error
SaveChannelFulls implements Cache.
func (*InmemoryCache) SaveChannels ¶
SaveChannels implements Cache.
func (*InmemoryCache) SaveChatFulls ¶
SaveChatFulls implements Cache.
func (*InmemoryCache) SaveUserFulls ¶
SaveUserFulls implements Cache.
type InmemoryStorage ¶
type InmemoryStorage struct {
// contains filtered or unexported fields
}
InmemoryStorage is basic in-memory Storage implementation.
func (*InmemoryStorage) FindPhone ¶
func (f *InmemoryStorage) FindPhone(ctx context.Context, phone string) (key Key, value Value, found bool, err error)
FindPhone implements Storage.
func (*InmemoryStorage) GetContactsHash ¶
func (f *InmemoryStorage) GetContactsHash(ctx context.Context) (int64, error)
GetContactsHash implements Storage.
func (*InmemoryStorage) SaveContactsHash ¶
func (f *InmemoryStorage) SaveContactsHash(ctx context.Context, hash int64) error
SaveContactsHash implements Storage.
type InviteLink ¶
type InviteLink struct {
// contains filtered or unexported fields
}
InviteLink represents invite link.
func (InviteLink) CreatedAt ¶
func (l InviteLink) CreatedAt() time.Time
CreatedAt returns time when was this chat invite created.
func (InviteLink) Creator ¶
func (l InviteLink) Creator(ctx context.Context) (User, error)
Creator returns link creator.
func (InviteLink) ExpireDate ¶
func (l InviteLink) ExpireDate() (time.Time, bool)
ExpireDate returns time when does this chat invite expire.
func (InviteLink) Permanent ¶
func (l InviteLink) Permanent() bool
Permanent whether this chat invite has no expiration
func (InviteLink) Raw ¶
func (l InviteLink) Raw() *tg.ChatInviteExported
Raw returns raw tg.ChatInviteExported.
func (InviteLink) ReplacedWith ¶
func (l InviteLink) ReplacedWith() (InviteLink, bool)
ReplacedWith returns new InviteLink, if any.
func (InviteLink) RequestNeeded ¶
func (l InviteLink) RequestNeeded() bool
RequestNeeded whether users joining the chat via the link need to be approved by chat administrators.
func (InviteLink) Requested ¶
func (l InviteLink) Requested() (int, bool)
Requested returns number of pending join requests.
func (InviteLink) Revoked ¶
func (l InviteLink) Revoked() bool
Revoked whether this chat invite was revoked
func (InviteLink) StartDate ¶
func (l InviteLink) StartDate() (time.Time, bool)
StartDate returns time when was this chat invite last modified.
func (InviteLink) Usage ¶
func (l InviteLink) Usage() (int, bool)
Usage returns how many users joined using this link.
func (InviteLink) UsageLimit ¶
func (l InviteLink) UsageLimit() (int, bool)
UsageLimit returns maximum number of users that can join using this link.
type InviteLinks ¶
type InviteLinks struct {
// contains filtered or unexported fields
}
InviteLinks represents invite links of Chat or Channel.
func (InviteLinks) AddNew ¶
func (e InviteLinks) AddNew(ctx context.Context, opts ExportLinkOptions) (InviteLink, error)
AddNew creates an additional invite link for a chat.
func (InviteLinks) ApproveJoin ¶
func (e InviteLinks) ApproveJoin(ctx context.Context, user tg.InputUserClass) error
ApproveJoin approves join request for given user.
func (InviteLinks) DeclineJoin ¶
func (e InviteLinks) DeclineJoin(ctx context.Context, user tg.InputUserClass) error
DeclineJoin declines join request for given user.
func (InviteLinks) Delete ¶
func (e InviteLinks) Delete(ctx context.Context, link string) error
Delete deletes invite link.
Not available for bots.
func (InviteLinks) Edit ¶
func (e InviteLinks) Edit(ctx context.Context, link string, opts ExportLinkOptions) (InviteLink, error)
Edit edits link info.
func (InviteLinks) ExportNew ¶
func (e InviteLinks) ExportNew(ctx context.Context, opts ExportLinkOptions) (InviteLink, error)
ExportNew creates new primary invite link for a chat.
Notice: Any previously generated primary link is revoked.
See also AddNew.
func (InviteLinks) Get ¶
func (e InviteLinks) Get(ctx context.Context, link string) (InviteLink, error)
Get returns link info.
func (InviteLinks) Revoke ¶
func (e InviteLinks) Revoke(ctx context.Context, link string) (InviteLink, error)
Revoke revokes invite link and returns revoked link info.
If the primary link is revoked, a new link is automatically generated.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is peer manager.
NB: this package is completely experimental and still WIP.
Example ¶
package main import ( "context" "fmt" "go.uber.org/zap" "github.com/gotd/td/telegram" "github.com/gotd/td/telegram/peers" "github.com/gotd/td/telegram/updates" "github.com/gotd/td/tg" ) func main() { logger := zap.NewExample() var ( dispatcher = tg.NewUpdateDispatcher() h telegram.UpdateHandler ) client, err := telegram.ClientFromEnvironment(telegram.Options{ Logger: logger.Named("client"), UpdateHandler: telegram.UpdateHandlerFunc(func(ctx context.Context, u tg.UpdatesClass) error { return h.Handle(ctx, u) }), }) if err != nil { panic(err) } peerManager := peers.Options{ Logger: logger, }.Build(client.API()) gaps := updates.New(updates.Config{ Handler: dispatcher, AccessHasher: peerManager, Logger: logger.Named("gaps"), }) h = peerManager.UpdateHook(gaps) if err := client.Run(context.TODO(), func(ctx context.Context) error { if err := peerManager.Init(ctx); err != nil { return err } u, err := peerManager.Self(ctx) if err != nil { return err } _, isBot := u.ToBot() if err := gaps.Auth(ctx, client.API(), u.ID(), isBot, false); err != nil { return err } defer gaps.Logout() p, err := peerManager.Resolve(ctx, "durov") if err != nil { return err } username, _ := p.Username() fmt.Println(username) return nil }); err != nil { panic(err) } }
Output:
func (*Manager) FromInputPeer ¶
FromInputPeer gets Peer from tg.InputPeerClass.
func (*Manager) GetAllChats ¶ added in v0.59.0
func (m *Manager) GetAllChats(ctx context.Context, exceptIDs ...int64) (r GetAllChatsResult, _ error)
GetAllChats gets all chats.
func (*Manager) GetChannel ¶
GetChannel gets Channel using given tg.InputChannelClass.
func (*Manager) GetChannelAccessHash ¶
func (m *Manager) GetChannelAccessHash(userID, channelID int64) (accessHash int64, found bool, err error)
GetChannelAccessHash implements updates.ChannelAccessHasher.
func (*Manager) ImportInvite ¶
ImportInvite imports given hash invite.
func (*Manager) JoinLink ¶
JoinLink joins to private chat using given link or hash. Input examples:
t.me/+AAAAAAAAAAAAAAAA https://t.me/+AAAAAAAAAAAAAAAA t.me/joinchat/AAAAAAAAAAAAAAAA https://t.me/joinchat/AAAAAAAAAAAAAAAA tg:join?invite=AAAAAAAAAAAAAAAA tg://join?invite=AAAAAAAAAAAAAAAA
func (*Manager) Resolve ¶
Resolve uses given string to create new peer promise.
Input examples:
@telegram telegram t.me/telegram https://t.me/telegram tg:resolve?domain=telegram tg://resolve?domain=telegram +13115552368 +1 (311) 555-0123 +1 311 555-6162 13115556162
func (*Manager) ResolveChannelID ¶ added in v0.56.0
ResolveChannelID creates Channel using given id.
func (*Manager) ResolveChatID ¶ added in v0.56.0
ResolveChatID creates Chat using given id.
func (*Manager) ResolveDeeplink ¶
ResolveDeeplink uses given deeplink to create new peer promise.
Input examples:
t.me/telegram https://t.me/telegram tg:resolve?domain=telegram tg://resolve?domain=telegram
func (*Manager) ResolveDomain ¶
ResolveDomain uses given domain to create new peer promise.
May be prefixed with @ or not.
Input examples:
@telegram telegram
func (*Manager) ResolvePeer ¶
ResolvePeer creates Peer using given tg.PeerClass.
func (*Manager) ResolvePhone ¶
ResolvePhone uses given phone to resolve User.
Input example:
+13115552368 +1 (311) 555-0123 +1 311 555-6162 13115556162
Note that Telegram represents phone numbers according to the E.164 standard without the plus sign (”+”) prefix. The resolver therefore takes an easy route and just deletes any non-digit symbols from phone number string.
func (*Manager) ResolveTDLibID ¶
func (m *Manager) ResolveTDLibID(ctx context.Context, peerID constant.TDLibPeerID) (p Peer, err error)
ResolveTDLibID creates Peer using given constant.TDLibPeerID.
func (*Manager) ResolveUserID ¶ added in v0.56.0
ResolveUserID creates User using given id.
func (*Manager) SetChannelAccessHash ¶
SetChannelAccessHash implements updates.ChannelAccessHasher.
func (*Manager) UpdateHook ¶
func (m *Manager) UpdateHook(next telegram.UpdateHandler) telegram.UpdateHandler
UpdateHook returns update middleware hook for collecting entities.
func (*Manager) UserResolveHook ¶
func (m *Manager) UserResolveHook(ctx context.Context) entity.UserResolver
UserResolveHook creates entity.UserResolver attached to this Manager.
type NoopCache ¶
type NoopCache struct{}
NoopCache is no-op implementation of Cache.
func (NoopCache) FindChannel ¶
FindChannel implements Cache.
func (NoopCache) FindChannelFull ¶
FindChannelFull implements Cache.
func (NoopCache) FindChatFull ¶
FindChatFull implements Cache.
func (NoopCache) FindUserFull ¶
FindUserFull implements Cache.
func (NoopCache) SaveChannelFulls ¶
SaveChannelFulls implements Cache.
func (NoopCache) SaveChannels ¶
SaveChannels implements Cache.
func (NoopCache) SaveChatFulls ¶
SaveChatFulls implements Cache.
func (NoopCache) SaveUserFulls ¶
SaveUserFulls implements Cache.
type Peer ¶
type Peer interface { // ID returns entity ID. ID() int64 // TDLibPeerID returns TDLibPeerID for this entity. TDLibPeerID() constant.TDLibPeerID // VisibleName returns visible name of peer. // // It returns FirstName + " " + LastName for users, and title for chats and channels. VisibleName() string // Username returns peer username, if any. Username() (string, bool) // Restricted whether this user/chat/channel is restricted. Restricted() ([]tg.RestrictionReason, bool) // Verified whether this user/chat/channel is verified by Telegram. Verified() bool // Scam whether this user/chat/channel is probably a scam. Scam() bool // Fake whether this user/chat/channel was reported by many users as a fake or scam: be // careful when interacting with it. Fake() bool // InputPeer returns input peer for this peer. InputPeer() tg.InputPeerClass // Sync updates current object. Sync(ctx context.Context) error // Manager returns attached Manager. Manager() *Manager // Report reports a peer for violation of telegram's Terms of Service. Report(ctx context.Context, reason tg.ReportReasonClass, message string) error // Photo returns peer photo, if any. Photo(ctx context.Context) (*tg.Photo, bool, error) }
Peer represents generic peer.
type PeerNotFoundError ¶
PeerNotFoundError is returned when Manager unable to find Peer with given tg.PeerClass.
func (*PeerNotFoundError) Error ¶
func (p *PeerNotFoundError) Error() string
Error implements error.
type PhoneNotFoundError ¶
type PhoneNotFoundError struct {
Phone string
}
PhoneNotFoundError is returned when Manager unable to find contact with given phone.
func (*PhoneNotFoundError) Error ¶
func (c *PhoneNotFoundError) Error() string
Error implements error.
type SearchResult ¶ added in v0.56.0
SearchResult is Search query result.
type Storage ¶
type Storage interface { Save(ctx context.Context, key Key, value Value) error Find(ctx context.Context, key Key) (value Value, found bool, _ error) SavePhone(ctx context.Context, phone string, key Key) error FindPhone(ctx context.Context, phone string) (key Key, value Value, found bool, err error) GetContactsHash(ctx context.Context) (int64, error) SaveContactsHash(ctx context.Context, hash int64) error }
Storage is peer storage.
type Supergroup ¶
type Supergroup struct {
Channel
}
Supergroup is a supergroup Channel.
func (Supergroup) DisableSlowMode ¶
func (c Supergroup) DisableSlowMode(ctx context.Context) error
DisableSlowMode disables slow mode.
func (Supergroup) ResetStickerSet ¶
func (c Supergroup) ResetStickerSet(ctx context.Context) error
ResetStickerSet resets associated sticker set of this supergroup.
func (Supergroup) SetStickerSet ¶
func (c Supergroup) SetStickerSet(ctx context.Context, set tg.InputStickerSetClass) error
SetStickerSet associates a sticker set to this supergroup.
func (Supergroup) SlowmodeEnabled ¶
func (c Supergroup) SlowmodeEnabled() bool
SlowmodeEnabled whether slow mode is enabled for groups to prevent flood in chat.
func (Supergroup) ToggleSlowMode ¶
func (c Supergroup) ToggleSlowMode(ctx context.Context, seconds int) error
ToggleSlowMode Toggle supergroup slow mode: if enabled, users will only be able to send one message per seconds.
If seconds is zero or smaller, slow mode will be disabled.
type User ¶
type User struct {
// contains filtered or unexported fields
}
User is user peer.
func (User) Fake ¶
Fake whether this user/chat/channel was reported by many users as a fake or scam: be careful when interacting with it.
func (User) InputPeer ¶
func (u User) InputPeer() tg.InputPeerClass
InputPeer returns input peer for this peer.
func (User) InputUser ¶
func (u User) InputUser() tg.InputUserClass
InputUser returns input user for this user.
func (User) MutualContact ¶
MutualContact whether this user is a mutual contact.
func (User) ReportSpam ¶
ReportSpam reports a new incoming chat for spam, if the peer settings of the chat allow us to do that.
func (User) Restricted ¶
func (u User) Restricted() ([]tg.RestrictionReason, bool)
Restricted whether this user/chat/channel is restricted.
func (User) Status ¶
func (u User) Status() (tg.UserStatusClass, bool)
Status returns user status, if any.
func (User) TDLibPeerID ¶
func (u User) TDLibPeerID() constant.TDLibPeerID
TDLibPeerID returns TDLibPeerID for this entity.
func (User) VisibleName ¶
VisibleName returns visible name of peer.
It returns FirstName + " " + LastName for users, and title for chats and channels.
Source Files ¶
- apply.go
- atomic.go
- bot.go
- broadcast.go
- channel.go
- chat.go
- errors.go
- get_chats.go
- id.go
- integration.go
- invite_link.go
- invite_links.go
- join.go
- manager.go
- memory_storage.go
- multichat.go
- options.go
- peerid_map.go
- peers.go
- query.go
- query_full.go
- resolve.go
- search.go
- self.go
- storage.go
- supergroup.go
- update.go
- user.go