peer

package
v0.33.3 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2021 License: MIT Imports: 7 Imported by: 30

Documentation

Overview

Package peer conatains some peer resolving and extracting helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToInputChannel added in v0.33.0

func ToInputChannel(channel tg.InputPeerClass) (tg.InputChannelClass, bool)

ToInputChannel converts given peer to input channel if possible.

func ToInputUser added in v0.33.0

func ToInputUser(user tg.InputPeerClass) (tg.InputUserClass, bool)

ToInputUser converts given peer to input user if possible.

Types

type DialogKey added in v0.27.0

type DialogKey struct {
	Kind       Kind
	ID         int
	AccessHash int64
}

DialogKey is a generic peer key.

func (*DialogKey) FromInputPeer added in v0.27.0

func (d *DialogKey) FromInputPeer(peer tg.InputPeerClass) error

FromInputPeer fills key using given peer.

func (*DialogKey) FromPeer added in v0.27.0

func (d *DialogKey) FromPeer(peer tg.PeerClass) error

FromPeer fills key using given peer.

type Entities

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

Entities is simple peer entities storage.

func EntitiesFromResult

func EntitiesFromResult(r EntitySearchResult) Entities

EntitiesFromResult fills Entities struct using given context.

func EntitiesFromUpdate

func EntitiesFromUpdate(uctx tg.Entities) Entities

EntitiesFromUpdate fills Entities struct using given context.

func NewEntities

func NewEntities(
	users map[int]*tg.User,
	chats map[int]*tg.Chat,
	channels map[int]*tg.Channel,
) Entities

NewEntities creates new Entities struct.

func (Entities) Channel added in v0.33.0

func (ent Entities) Channel(id int) (*tg.Channel, bool)

Channel finds channel by given ID.

func (Entities) Chat added in v0.33.0

func (ent Entities) Chat(id int) (*tg.Chat, bool)

Chat finds chat by given ID.

func (Entities) ExtractPeer

func (ent Entities) ExtractPeer(peerID tg.PeerClass) (tg.InputPeerClass, error)

ExtractPeer finds and creates InputPeerClass using given PeerClass.

func (Entities) Fill

func (ent Entities) Fill(
	users map[int]*tg.User,
	chats map[int]*tg.Chat,
	channels map[int]*tg.Channel,
)

Fill adds and updates all entities from given maps.

func (Entities) FillFromResult

func (ent Entities) FillFromResult(r EntitySearchResult)

FillFromResult adds and updates all entities from given result.

func (Entities) FillFromUpdate

func (ent Entities) FillFromUpdate(uctx tg.Entities)

FillFromUpdate adds and updates all entities from given updates.

func (Entities) User added in v0.33.0

func (ent Entities) User(id int) (*tg.User, bool)

User finds user by given ID.

type EntitySearchResult

type EntitySearchResult interface {
	MapChats() tg.ChatClassArray
	MapUsers() tg.UserClassArray
}

EntitySearchResult is abstraction for different RPC responses which contains entities.

type Kind added in v0.27.0

type Kind int

Kind represents peer kind.

const (
	// User is a private chat with user.
	User Kind = iota
	// Chat is a legacy chat.
	Chat
	// Channel is a supergroup/channel.
	Channel
)

type LRUResolver

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

LRUResolver is simple decorator for Resolver to cache result in LRU.

func NewLRUResolver

func NewLRUResolver(next Resolver, capacity int) *LRUResolver

NewLRUResolver creates new LRUResolver.

func (*LRUResolver) ResolveDomain added in v0.31.0

func (l *LRUResolver) ResolveDomain(ctx context.Context, domain string) (tg.InputPeerClass, error)

ResolveDomain implements Resolver.

func (*LRUResolver) ResolvePhone added in v0.30.0

func (l *LRUResolver) ResolvePhone(ctx context.Context, phone string) (tg.InputPeerClass, error)

ResolvePhone implements Resolver.

type Promise added in v0.27.0

type Promise func(ctx context.Context) (tg.InputPeerClass, error)

Promise is a peer promise.

func OnlyChannel added in v0.30.0

func OnlyChannel(p Promise) Promise

OnlyChannel returns Promise which returns error if resolved peer is not a channel.

func OnlyChat added in v0.30.0

func OnlyChat(p Promise) Promise

OnlyChat returns Promise which returns error if resolved peer is not a chat.

func OnlyUser added in v0.30.0

func OnlyUser(p Promise) Promise

OnlyUser returns Promise which returns error if resolved peer is not a user.

func Resolve added in v0.27.0

func Resolve(r Resolver, from string) Promise

Resolve uses given string to create new peer promise. It resolves peer of message using given Resolver. 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 ResolveDeeplink(r Resolver, u string) Promise

ResolveDeeplink uses given deeplink to create new peer promise. Deeplink is a URL like https://t.me/telegram. It resolves peer of message using given Resolver. Input examples:

t.me/telegram
https://t.me/telegram
tg:resolve?domain=telegram
tg://resolve?domain=telegram

func ResolveDomain added in v0.27.0

func ResolveDomain(r Resolver, domain string) Promise

ResolveDomain uses given domain to create new peer promise. It resolves peer of message using given Resolver. Can has prefix with @ or not. Input examples:

@telegram
telegram

func ResolvePhone added in v0.30.0

func ResolvePhone(r Resolver, phone string) Promise

ResolvePhone uses given phone to create new peer promise. It resolves peer of message using given Resolver. 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.

type PromiseDecorator added in v0.30.0

type PromiseDecorator = func(Promise) Promise

PromiseDecorator is a decorator of peer promise.

type Resolver

type Resolver interface {
	ResolveDomain(ctx context.Context, domain string) (tg.InputPeerClass, error)
	ResolvePhone(ctx context.Context, phone string) (tg.InputPeerClass, error)
}

Resolver is a abstraction to resolve domains and Telegram deeplinks.

func DefaultResolver

func DefaultResolver(raw *tg.Client) Resolver

DefaultResolver creates and returns default resolver.

Jump to

Keyboard shortcuts

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