peers

package
v0.116.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 17 Imported by: 26

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

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

func (b Bot) BotInfo(ctx context.Context) (tg.BotInfo, error)

BotInfo returns bot info.

func (Bot) CanBeAdded

func (b Bot) CanBeAdded() bool

CanBeAdded whether can the bot be added to group.

func (Bot) ChatHistory

func (b Bot) ChatHistory() bool

ChatHistory whether can the bot see all messages in groups.

func (Bot) InlineGeo

func (b Bot) InlineGeo() bool

InlineGeo whether the bot can request our geolocation in inline mode.

func (Bot) InlinePlaceholder

func (b Bot) InlinePlaceholder() (string, bool)

InlinePlaceholder returns inline placeholder for this inline bot.

func (Bot) SupportsInline

func (b Bot) SupportsInline() bool

SupportsInline whether the bot supports inline queries.

type Broadcast

type Broadcast struct {
	Channel
}

Broadcast is a broadcast Channel.

func (Broadcast) DiscussionGroup

func (b Broadcast) DiscussionGroup(ctx context.Context) (Channel, bool, error)

DiscussionGroup returns linked chat, if any.

func (Broadcast) SetDiscussionGroup

func (b Broadcast) SetDiscussionGroup(ctx context.Context, p tg.InputChannelClass) error

SetDiscussionGroup associates a group to a channel as discussion group for that channel.

func (Broadcast) Signatures

func (b Broadcast) Signatures() bool

Signatures whether signatures are enabled (channels).

func (Broadcast) ToggleSignatures

func (b Broadcast) ToggleSignatures(ctx context.Context, enabled bool) error

ToggleSignatures enable/disable message signatures in 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.

See https://core.telegram.org/api/rights.

func (Channel) BannedRights

func (c Channel) BannedRights() (tg.ChatBannedRights, bool)

BannedRights returns banned rights of the user in this channel.

See https://core.telegram.org/api/rights.

func (Channel) CallActive

func (c Channel) CallActive() bool

CallActive whether a group call or livestream is currently active.

func (Channel) CallNotEmpty

func (c Channel) CallNotEmpty() bool

CallNotEmpty whether there's anyone in the group call or livestream.

func (Channel) Creator

func (c Channel) Creator() bool

Creator whether the current user is the creator of this channel.

func (Channel) DefaultBannedRights

func (c Channel) DefaultBannedRights() (tg.ChatBannedRights, bool)

DefaultBannedRights returns default chat rights.

See https://core.telegram.org/api/rights.

func (Channel) Delete

func (c Channel) Delete(ctx context.Context) error

Delete deletes this channel.

func (Channel) DisableReactions

func (c Channel) DisableReactions(ctx context.Context) error

DisableReactions disables reactions.

func (Channel) Fake

func (c Channel) Fake() bool

Fake whether this user/chat/channel was reported by many users as a fake or scam: be careful when interacting with it.

func (Channel) FullRaw

func (c Channel) FullRaw(ctx context.Context) (*tg.ChannelFull, error)

FullRaw returns *tg.ChannelFull for this Channel.

func (Channel) HasGeo

func (c Channel) HasGeo() bool

HasGeo whether this channel has a geoposition.

func (c Channel) HasLink() bool

HasLink whether this channel has a private join link.

func (Channel) ID

func (c Channel) ID() int64

ID returns entity ID.

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 (c Channel) InviteLinks() InviteLinks

InviteLinks returns InviteLinks for this peer.

func (Channel) IsBroadcast added in v0.56.0

func (c Channel) IsBroadcast() bool

IsBroadcast whether this Channel is Broadcast.

func (Channel) IsSupergroup added in v0.56.0

func (c Channel) IsSupergroup() bool

IsSupergroup whether this Channel is Supergroup.

func (Channel) Join

func (c Channel) Join(ctx context.Context) error

Join joins this channel.

func (Channel) Leave

func (c Channel) Leave(ctx context.Context) error

Leave leaves this channel.

func (Channel) Left

func (c Channel) Left() bool

Left whether the current user has left this channel.

func (Channel) Manager added in v0.56.0

func (c Channel) Manager() *Manager

Manager returns attached Manager.

func (Channel) NoForwards

func (c Channel) NoForwards() bool

NoForwards whether that message forwarding from this channel is not allowed.

func (Channel) ParticipantsCount

func (c Channel) ParticipantsCount() int

ParticipantsCount returns count of participants.

func (Channel) Photo

func (c Channel) Photo(ctx context.Context) (*tg.Photo, bool, error)

Photo returns peer photo, if any.

func (Channel) Raw

func (c Channel) Raw() *tg.Channel

Raw returns raw *tg.Channel.

func (Channel) Report

func (c Channel) Report(ctx context.Context, reason tg.ReportReasonClass, message string) error

Report reports a peer for violation of telegram's Terms of Service.

func (Channel) Restricted

func (c Channel) Restricted() ([]tg.RestrictionReason, bool)

Restricted whether this user/chat/channel is restricted.

func (Channel) Scam

func (c Channel) Scam() bool

Scam whether this user/chat/channel is probably a scam.

func (Channel) SetDescription

func (c Channel) SetDescription(ctx context.Context, about string) error

SetDescription sets new description for this Chat.

func (Channel) SetReactions

func (c Channel) SetReactions(ctx context.Context, reactions ...tg.ReactionClass) error

SetReactions sets list of available reactions.

Empty list disables reactions at all.

func (Channel) SetTitle

func (c Channel) SetTitle(ctx context.Context, title string) error

SetTitle sets new title for this Chat.

func (Channel) Sync

func (c Channel) Sync(ctx context.Context) error

Sync updates current object.

func (Channel) TDLibPeerID

func (c Channel) TDLibPeerID() constant.TDLibPeerID

TDLibPeerID returns TDLibPeerID for this entity.

func (Channel) ToBroadcast

func (c Channel) ToBroadcast() (Broadcast, bool)

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

func (c Channel) Username() (string, bool)

Username returns peer username, if any.

func (Channel) Verified

func (c Channel) Verified() bool

Verified whether this user/chat/channel is verified by Telegram.

func (Channel) VisibleName

func (c Channel) VisibleName() string

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

func (c Chat) ActualChat(ctx context.Context) (Channel, bool, error)

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.

See https://core.telegram.org/api/rights.

func (Chat) CallActive

func (c Chat) CallActive() bool

CallActive whether a group call or livestream is currently active.

func (Chat) CallNotEmpty

func (c Chat) CallNotEmpty() bool

CallNotEmpty whether there's anyone in the group call or livestream.

func (Chat) Creator

func (c Chat) Creator() bool

Creator whether the current user is the creator of this group.

func (Chat) Deactivated

func (c Chat) Deactivated() bool

Deactivated whether the group was migrated.

func (Chat) DefaultBannedRights

func (c Chat) DefaultBannedRights() (tg.ChatBannedRights, bool)

DefaultBannedRights returns default chat rights.

See https://core.telegram.org/api/rights.

func (Chat) DisableReactions

func (c Chat) DisableReactions(ctx context.Context) error

DisableReactions disables reactions.

func (Chat) Fake

func (c Chat) Fake() bool

Fake whether this user/chat/channel was reported by many users as a fake or scam: be careful when interacting with it.

func (Chat) FullRaw

func (c Chat) FullRaw(ctx context.Context) (*tg.ChatFull, error)

FullRaw returns *tg.ChatFull for this Chat.

func (Chat) ID

func (c Chat) ID() int64

ID returns entity ID.

func (Chat) InputPeer

func (c Chat) InputPeer() tg.InputPeerClass

InputPeer returns input peer for this peer.

func (c Chat) InviteLinks() InviteLinks

InviteLinks returns InviteLinks for this peer.

func (Chat) IsBroadcast added in v0.56.0

func (c Chat) IsBroadcast() bool

IsBroadcast whether this Chat is Broadcast.

func (Chat) IsSupergroup added in v0.56.0

func (c Chat) IsSupergroup() bool

IsSupergroup whether this Chat is Supergroup.

func (Chat) Leave

func (c Chat) Leave(ctx context.Context) error

Leave leaves this chat.

func (Chat) LeaveAndDelete

func (c Chat) LeaveAndDelete(ctx context.Context) error

LeaveAndDelete leaves this chat and removes the entire chat history of this user in this chat.

func (Chat) Left

func (c Chat) Left() bool

Left whether the current user has left this group.

func (Chat) Manager added in v0.56.0

func (c Chat) Manager() *Manager

Manager returns attached Manager.

func (Chat) MigratedTo

func (c Chat) MigratedTo() (tg.InputChannelClass, bool)

MigratedTo returns a supergroup to which this chat migrated.

func (Chat) NoForwards

func (c Chat) NoForwards() bool

NoForwards whether that message forwarding from this channel is not allowed.

func (Chat) ParticipantsCount

func (c Chat) ParticipantsCount() int

ParticipantsCount returns count of participants.

func (Chat) Photo

func (c Chat) Photo(ctx context.Context) (*tg.Photo, bool, error)

Photo returns peer photo, if any.

func (Chat) Raw

func (c Chat) Raw() *tg.Chat

Raw returns raw *tg.Chat.

func (Chat) Report

func (c Chat) Report(ctx context.Context, reason tg.ReportReasonClass, message string) error

Report reports a peer for violation of telegram's Terms of Service.

func (Chat) Restricted

func (c Chat) Restricted() ([]tg.RestrictionReason, bool)

Restricted whether this user/chat/channel is restricted.

func (Chat) Scam

func (c Chat) Scam() bool

Scam whether this user/chat/channel is probably a scam.

func (Chat) SetDescription

func (c Chat) SetDescription(ctx context.Context, about string) error

SetDescription sets new description for this Chat.

func (Chat) SetReactions

func (c Chat) SetReactions(ctx context.Context, reactions ...tg.ReactionClass) error

SetReactions sets list of available reactions.

Empty list disables reactions at all.

func (Chat) SetTitle

func (c Chat) SetTitle(ctx context.Context, title string) error

SetTitle sets new title for this Chat.

func (Chat) Sync

func (c Chat) Sync(ctx context.Context) error

Sync updates current object.

func (Chat) TDLibPeerID

func (c Chat) TDLibPeerID() constant.TDLibPeerID

TDLibPeerID returns TDLibPeerID for this entity.

func (Chat) ToBroadcast

func (c Chat) ToBroadcast() (Broadcast, bool)

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

func (c Chat) Username() (string, bool)

Username returns peer username, if any.

func (Chat) Verified

func (c Chat) Verified() bool

Verified whether this user/chat/channel is verified by Telegram.

func (Chat) VisibleName

func (c Chat) VisibleName() string

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 InmemoryCache

type InmemoryCache struct {
	// contains filtered or unexported fields
}

InmemoryCache is basic in-memory Cache implementation.

func (*InmemoryCache) FindChannel

func (f *InmemoryCache) FindChannel(ctx context.Context, id int64) (*tg.Channel, bool, error)

FindChannel implements Cache.

func (*InmemoryCache) FindChannelFull

func (f *InmemoryCache) FindChannelFull(ctx context.Context, id int64) (*tg.ChannelFull, bool, error)

FindChannelFull implements Cache.

func (*InmemoryCache) FindChat

func (f *InmemoryCache) FindChat(ctx context.Context, id int64) (*tg.Chat, bool, error)

FindChat implements Cache.

func (*InmemoryCache) FindChatFull

func (f *InmemoryCache) FindChatFull(ctx context.Context, id int64) (*tg.ChatFull, bool, error)

FindChatFull implements Cache.

func (*InmemoryCache) FindUser

func (f *InmemoryCache) FindUser(ctx context.Context, id int64) (*tg.User, bool, error)

FindUser implements Cache.

func (*InmemoryCache) FindUserFull

func (f *InmemoryCache) FindUserFull(ctx context.Context, id int64) (*tg.UserFull, bool, error)

FindUserFull implements Cache.

func (*InmemoryCache) SaveChannelFulls

func (f *InmemoryCache) SaveChannelFulls(ctx context.Context, channels ...*tg.ChannelFull) error

SaveChannelFulls implements Cache.

func (*InmemoryCache) SaveChannels

func (f *InmemoryCache) SaveChannels(ctx context.Context, channels ...*tg.Channel) error

SaveChannels implements Cache.

func (*InmemoryCache) SaveChatFulls

func (f *InmemoryCache) SaveChatFulls(ctx context.Context, chats ...*tg.ChatFull) error

SaveChatFulls implements Cache.

func (*InmemoryCache) SaveChats

func (f *InmemoryCache) SaveChats(ctx context.Context, chats ...*tg.Chat) error

SaveChats implements Cache.

func (*InmemoryCache) SaveUserFulls

func (f *InmemoryCache) SaveUserFulls(ctx context.Context, users ...*tg.UserFull) error

SaveUserFulls implements Cache.

func (*InmemoryCache) SaveUsers

func (f *InmemoryCache) SaveUsers(ctx context.Context, users ...*tg.User) error

SaveUsers implements Cache.

type InmemoryStorage

type InmemoryStorage struct {
	// contains filtered or unexported fields
}

InmemoryStorage is basic in-memory Storage implementation.

func (*InmemoryStorage) Find

func (f *InmemoryStorage) Find(ctx context.Context, key Key) (value Value, found bool, _ error)

Find implements Storage.

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

func (f *InmemoryStorage) Save(ctx context.Context, key Key, value Value) error

Save implements Storage.

func (*InmemoryStorage) SaveContactsHash

func (f *InmemoryStorage) SaveContactsHash(ctx context.Context, hash int64) error

SaveContactsHash implements Storage.

func (*InmemoryStorage) SavePhone

func (f *InmemoryStorage) SavePhone(ctx context.Context, phone string, key Key) error

SavePhone implements Storage.

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 (l InviteLink) Link() string

Link returns chat invitation link.

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

func (l InviteLink) Title() (string, bool)

Title of this link.

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 struct {
	// contains filtered or unexported fields
}

InviteLinks represents invite links of Chat or Channel.

func (InviteLinks) AddNew

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 Key

type Key struct {
	Prefix string
	ID     int64
}

Key is storage key.

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"

	"github.com/go-faster/errors"
	"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)

	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	if err := client.Run(ctx, 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.Run(ctx, client.API(), u.ID(), updates.AuthOptions{IsBot: isBot}); err != nil {
			return errors.Wrap(err, "gaps")
		}
		return nil
	}); err != nil {
		panic(err)
	}
}
Output:

func (*Manager) API added in v0.56.0

func (m *Manager) API() *tg.Client

API returns used Client.

func (*Manager) Apply

func (m *Manager) Apply(ctx context.Context, users []tg.UserClass, chats []tg.ChatClass) error

Apply adds given entities to manager state.

func (*Manager) Channel

func (m *Manager) Channel(u *tg.Channel) Channel

Channel creates new Channel, attached to this manager.

func (*Manager) Chat

func (m *Manager) Chat(u *tg.Chat) Chat

Chat creates new Chat, attached to this manager.

func (*Manager) FromInputPeer

func (m *Manager) FromInputPeer(ctx context.Context, p tg.InputPeerClass) (Peer, error)

FromInputPeer gets Peer from tg.InputPeerClass.

func (*Manager) GetChannel

func (m *Manager) GetChannel(ctx context.Context, p tg.InputChannelClass) (Channel, error)

GetChannel gets Channel using given tg.InputChannelClass.

func (*Manager) GetChannelAccessHash

func (m *Manager) GetChannelAccessHash(ctx context.Context, userID, channelID int64) (accessHash int64, found bool, err error)

GetChannelAccessHash implements updates.ChannelAccessHasher.

func (*Manager) GetChat

func (m *Manager) GetChat(ctx context.Context, id int64) (Chat, error)

GetChat gets Chat using given id.

func (*Manager) GetUser

func (m *Manager) GetUser(ctx context.Context, p tg.InputUserClass) (User, error)

GetUser gets User using given tg.InputUserClass.

func (*Manager) ImportInvite

func (m *Manager) ImportInvite(ctx context.Context, hash string) (Peer, error)

ImportInvite imports given hash invite.

func (*Manager) Init

func (m *Manager) Init(ctx context.Context) error

Init initializes Manager.

func (m *Manager) JoinLink(ctx context.Context, link string) (Peer, error)

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

func (m *Manager) Resolve(ctx context.Context, from string) (Peer, error)

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

func (m *Manager) ResolveChannelID(ctx context.Context, id int64) (Channel, error)

ResolveChannelID creates Channel using given id.

func (*Manager) ResolveChatID added in v0.56.0

func (m *Manager) ResolveChatID(ctx context.Context, id int64) (Chat, error)

ResolveChatID creates Chat using given id.

func (m *Manager) ResolveDeeplink(ctx context.Context, u string) (Peer, error)

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) ResolveDeeplinkJoin added in v0.106.0

func (m *Manager) ResolveDeeplinkJoin(ctx context.Context, u string) (tg.ChatInviteClass, error)

func (*Manager) ResolveDomain

func (m *Manager) ResolveDomain(ctx context.Context, domain string) (Peer, error)

ResolveDomain uses given domain to create new peer promise.

May be prefixed with @ or not.

Input examples:

@telegram
telegram

func (*Manager) ResolvePeer

func (m *Manager) ResolvePeer(ctx context.Context, p tg.PeerClass) (Peer, error)

ResolvePeer creates Peer using given tg.PeerClass.

func (*Manager) ResolvePhone

func (m *Manager) ResolvePhone(ctx context.Context, phone string) (User, error)

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

func (m *Manager) ResolveUserID(ctx context.Context, id int64) (User, error)

ResolveUserID creates User using given id.

func (*Manager) Search added in v0.56.0

func (m *Manager) Search(ctx context.Context, q string) (SearchResult, error)

Search searches peers by given query.

func (*Manager) Self

func (m *Manager) Self(ctx context.Context) (User, error)

Self returns current User.

func (*Manager) SetChannelAccessHash

func (m *Manager) SetChannelAccessHash(ctx context.Context, userID, channelID, accessHash int64) error

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

func (m *Manager) User(u *tg.User) User

User creates new User, attached to this manager.

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

func (n NoopCache) FindChannel(ctx context.Context, id int64) (*tg.Channel, bool, error)

FindChannel implements Cache.

func (NoopCache) FindChannelFull

func (n NoopCache) FindChannelFull(ctx context.Context, id int64) (*tg.ChannelFull, bool, error)

FindChannelFull implements Cache.

func (NoopCache) FindChat

func (n NoopCache) FindChat(ctx context.Context, id int64) (*tg.Chat, bool, error)

FindChat implements Cache.

func (NoopCache) FindChatFull

func (n NoopCache) FindChatFull(ctx context.Context, id int64) (*tg.ChatFull, bool, error)

FindChatFull implements Cache.

func (NoopCache) FindUser

func (n NoopCache) FindUser(ctx context.Context, id int64) (*tg.User, bool, error)

FindUser implements Cache.

func (NoopCache) FindUserFull

func (n NoopCache) FindUserFull(ctx context.Context, id int64) (*tg.UserFull, bool, error)

FindUserFull implements Cache.

func (NoopCache) SaveChannelFulls

func (n NoopCache) SaveChannelFulls(ctx context.Context, channels ...*tg.ChannelFull) error

SaveChannelFulls implements Cache.

func (NoopCache) SaveChannels

func (n NoopCache) SaveChannels(ctx context.Context, channels ...*tg.Channel) error

SaveChannels implements Cache.

func (NoopCache) SaveChatFulls

func (n NoopCache) SaveChatFulls(ctx context.Context, chats ...*tg.ChatFull) error

SaveChatFulls implements Cache.

func (NoopCache) SaveChats

func (n NoopCache) SaveChats(ctx context.Context, chats ...*tg.Chat) error

SaveChats implements Cache.

func (NoopCache) SaveUserFulls

func (n NoopCache) SaveUserFulls(ctx context.Context, users ...*tg.UserFull) error

SaveUserFulls implements Cache.

func (NoopCache) SaveUsers

func (n NoopCache) SaveUsers(ctx context.Context, users ...*tg.User) error

SaveUsers implements Cache.

type Options

type Options struct {
	Storage Storage
	Cache   Cache
	Logger  *zap.Logger
}

Options is options of Manager

func (Options) Build

func (o Options) Build(api *tg.Client) *Manager

Build creates new Manager.

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

type PeerNotFoundError struct {
	Peer tg.PeerClass
}

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

type SearchResult struct {
	MyResults []Peer
	Results   []Peer
}

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

func (u User) Block(ctx context.Context) error

Block blocks this user.

func (User) Contact

func (u User) Contact() bool

Contact whether this user is a contact.

func (User) Deleted

func (u User) Deleted() bool

Deleted whether the account of this user was deleted.

func (User) Fake

func (u User) Fake() bool

Fake whether this user/chat/channel was reported by many users as a fake or scam: be careful when interacting with it.

func (User) FirstName

func (u User) FirstName() (string, bool)

FirstName returns first name.

func (User) FullRaw

func (u User) FullRaw(ctx context.Context) (*tg.UserFull, error)

FullRaw returns *tg.UserFull for this User.

func (User) ID

func (u User) ID() int64

ID returns entity ID.

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

func (u User) InviteTo(ctx context.Context, ch tg.InputChannelClass) error

InviteTo invites User to given channel.

func (User) LangCode

func (u User) LangCode() (string, bool)

LangCode returns users lang code, if any.

func (User) LastName

func (u User) LastName() (string, bool)

LastName returns last name.

func (User) Manager added in v0.56.0

func (u User) Manager() *Manager

Manager returns attached Manager.

func (User) MutualContact

func (u User) MutualContact() bool

MutualContact whether this user is a mutual contact.

func (User) Phone

func (u User) Phone() (string, bool)

Phone returns phone, if any.

func (User) Photo

func (u User) Photo(ctx context.Context) (*tg.Photo, bool, error)

Photo returns peer photo, if any.

func (User) Raw

func (u User) Raw() *tg.User

Raw returns raw *tg.User.

func (User) Report

func (u User) Report(ctx context.Context, reason tg.ReportReasonClass, message string) error

Report reports a peer for violation of telegram's Terms of Service.

func (User) ReportSpam

func (u User) ReportSpam(ctx context.Context) error

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

func (u User) Scam() bool

Scam whether this user/chat/channel is probably a scam.

func (User) Self

func (u User) Self() bool

Self whether this user indicates the currently logged-in user.

func (User) Status

func (u User) Status() (tg.UserStatusClass, bool)

Status returns user status, if any.

func (User) Support

func (u User) Support() bool

Support whether this is an official support user.

func (User) Sync

func (u User) Sync(ctx context.Context) error

Sync updates current object.

func (User) TDLibPeerID

func (u User) TDLibPeerID() constant.TDLibPeerID

TDLibPeerID returns TDLibPeerID for this entity.

func (User) ToBot

func (u User) ToBot() (Bot, bool)

ToBot tries to convert this User to Bot.

func (User) Unblock

func (u User) Unblock(ctx context.Context) error

Unblock unblocks this user.

func (User) Username

func (u User) Username() (string, bool)

Username returns peer username, if any.

func (User) Verified

func (u User) Verified() bool

Verified whether this user/chat/channel is verified by Telegram.

func (User) VisibleName

func (u User) VisibleName() string

VisibleName returns visible name of peer.

It returns FirstName + " " + LastName for users, and title for chats and channels.

type Value

type Value struct {
	AccessHash int64
}

Value is storage value.

Directories

Path Synopsis
Package members defines interfaces for working with chat/channel members.
Package members defines interfaces for working with chat/channel members.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL