connector

package
v0.0.0-...-844f318 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: AGPL-3.0 Imports: 66 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LoginFlowIDPhone = "phone"
	LoginFlowIDQR    = "qr"

	LoginStepIDComplete = "fi.mau.telegram.login.complete"
)
View Source
const (
	LoginStepIDPhoneNumber = "fi.mau.telegram.login.phone_number"
	LoginStepIDCode        = "fi.mau.telegram.login.code"
	LoginStepIDPassword    = "fi.mau.telegram.login.password"
)
View Source
const LoginStepIDShowQR = "fi.mau.telegram.login.show_qr"

Variables

View Source
var ExampleConfig string

Functions

func APICallWithOnlyChatUpdates

func APICallWithOnlyChatUpdates[U hasChatUpdates](ctx context.Context, t *TelegramClient, fn func() (U, error)) (U, error)

func APICallWithOnlyUserUpdates

func APICallWithOnlyUserUpdates[U hasUserUpdates](ctx context.Context, t *TelegramClient, fn func() (U, error)) (U, error)

func APICallWithUpdates

func APICallWithUpdates[U hasUpdates](ctx context.Context, t *TelegramClient, fn func() (U, error)) (U, error)

Wrapper for API calls that return a response with updates.

Types

type DeviceInfo

type DeviceInfo struct {
	DeviceModel    string `yaml:"device_model"`
	SystemVersion  string `yaml:"system_version"`
	AppVersion     string `yaml:"app_version"`
	SystemLangCode string `yaml:"system_lang_code"`
	LangCode       string `yaml:"lang_code"`
}

type GeoURI

type GeoURI struct {
	Lat  float64
	Long float64
}

func GeoURIFromLatLong

func GeoURIFromLatLong(lat, long float64) GeoURI

func ParseGeoURI

func ParseGeoURI(uri string) (g GeoURI, err error)

func (GeoURI) URI

func (g GeoURI) URI() string

type GhostMetadata

type GhostMetadata struct {
	IsPremium bool `json:"is_premium,omitempty"`
	IsBot     bool `json:"is_bot,omitempty"`
	IsChannel bool `json:"is_channel,omitempty"`
	Blocked   bool `json:"blocked,omitempty"`
	Deleted   bool `json:"deleted,omitempty"`
}

type IGetMessage

type IGetMessage interface {
	GetMessage() tg.MessageClass
}

type IGetMessages

type IGetMessages interface {
	GetMessages() []int
}

type MemberListConfig

type MemberListConfig struct {
	MaxInitialSync        int  `yaml:"max_initial_sync"`
	SyncBroadcastChannels bool `yaml:"sync_broadcast_channels"`
	SkipDeleted           bool `yaml:"skip_deleted"`
}

func (MemberListConfig) NormalizedMaxInitialSync

func (c MemberListConfig) NormalizedMaxInitialSync() int

type MessageMetadata

type MessageMetadata struct {
	ContentHash []byte              `json:"content_hash,omitempty"`
	ContentURI  id.ContentURIString `json:"content_uri,omitempty"`
}

type PhoneLogin

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

func (*PhoneLogin) Cancel

func (p *PhoneLogin) Cancel()

func (*PhoneLogin) Start

func (p *PhoneLogin) Start(ctx context.Context) (*bridgev2.LoginStep, error)

func (*PhoneLogin) SubmitUserInput

func (p *PhoneLogin) SubmitUserInput(ctx context.Context, input map[string]string) (*bridgev2.LoginStep, error)

type PortalMetadata

type PortalMetadata struct {
	IsSuperGroup bool `json:"is_supergroup,omitempty"`
	ReadUpTo     int  `json:"read_up_to,omitempty"`
	MessagesTTL  int  `json:"messages_ttl,omitempty"`
}

type QRLogin

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

func (*QRLogin) Cancel

func (q *QRLogin) Cancel()

func (*QRLogin) Start

func (q *QRLogin) Start(ctx context.Context) (*bridgev2.LoginStep, error)

func (*QRLogin) SubmitUserInput

func (q *QRLogin) SubmitUserInput(ctx context.Context, input map[string]string) (*bridgev2.LoginStep, error)

func (*QRLogin) Wait

func (q *QRLogin) Wait(ctx context.Context) (*bridgev2.LoginStep, error)

type TelegramClient

type TelegramClient struct {
	ScopedStore *store.ScopedStore
	// contains filtered or unexported fields
}

func NewTelegramClient

func NewTelegramClient(ctx context.Context, tc *TelegramConnector, login *bridgev2.UserLogin) (*TelegramClient, error)

func (*TelegramClient) Connect

func (t *TelegramClient) Connect(ctx context.Context) error

func (*TelegramClient) CreateGroup

func (t *TelegramClient) CreateGroup(ctx context.Context, name string, users ...networkid.UserID) (*bridgev2.CreateChatResponse, error)

TODO support channels

func (*TelegramClient) Disconnect

func (t *TelegramClient) Disconnect()

func (*TelegramClient) FetchMessages

func (*TelegramClient) GetBackfillMaxBatchCount

func (c *TelegramClient) GetBackfillMaxBatchCount(ctx context.Context, portal *bridgev2.Portal, task *database.BackfillTask) int

func (*TelegramClient) GetCapabilities

func (t *TelegramClient) GetCapabilities(ctx context.Context, portal *bridgev2.Portal) *bridgev2.NetworkRoomCapabilities

func (*TelegramClient) GetChatInfo

func (t *TelegramClient) GetChatInfo(ctx context.Context, portal *bridgev2.Portal) (*bridgev2.ChatInfo, error)

func (*TelegramClient) GetContactList

func (t *TelegramClient) GetContactList(ctx context.Context) (resp []*bridgev2.ResolveIdentifierResponse, err error)

func (*TelegramClient) GetPushConfigs

func (t *TelegramClient) GetPushConfigs() *bridgev2.PushConfig

func (*TelegramClient) GetUserInfo

func (t *TelegramClient) GetUserInfo(ctx context.Context, ghost *bridgev2.Ghost) (*bridgev2.UserInfo, error)

func (*TelegramClient) HandleMatrixEdit

func (t *TelegramClient) HandleMatrixEdit(ctx context.Context, msg *bridgev2.MatrixEdit) error

func (*TelegramClient) HandleMatrixMessage

func (t *TelegramClient) HandleMatrixMessage(ctx context.Context, msg *bridgev2.MatrixMessage) (resp *bridgev2.MatrixMessageResponse, err error)

func (*TelegramClient) HandleMatrixMessageRemove

func (t *TelegramClient) HandleMatrixMessageRemove(ctx context.Context, msg *bridgev2.MatrixMessageRemove) error

func (*TelegramClient) HandleMatrixReaction

func (t *TelegramClient) HandleMatrixReaction(ctx context.Context, msg *bridgev2.MatrixReaction) (reaction *database.Reaction, err error)

func (*TelegramClient) HandleMatrixReactionRemove

func (t *TelegramClient) HandleMatrixReactionRemove(ctx context.Context, msg *bridgev2.MatrixReactionRemove) error

func (*TelegramClient) HandleMatrixReadReceipt

func (t *TelegramClient) HandleMatrixReadReceipt(ctx context.Context, msg *bridgev2.MatrixReadReceipt) error

func (*TelegramClient) HandleMatrixTyping

func (t *TelegramClient) HandleMatrixTyping(ctx context.Context, msg *bridgev2.MatrixTyping) error

func (*TelegramClient) HandleMute

func (t *TelegramClient) HandleMute(ctx context.Context, msg *bridgev2.MatrixMute) error

func (*TelegramClient) HandleRoomTag

func (t *TelegramClient) HandleRoomTag(ctx context.Context, msg *bridgev2.MatrixRoomTag) error

func (*TelegramClient) IsLoggedIn

func (t *TelegramClient) IsLoggedIn() bool

func (*TelegramClient) IsThisUser

func (t *TelegramClient) IsThisUser(ctx context.Context, userID networkid.UserID) bool

func (*TelegramClient) LogoutRemote

func (t *TelegramClient) LogoutRemote(ctx context.Context)

func (*TelegramClient) PreHandleMatrixReaction

func (*TelegramClient) RegisterPushNotifications

func (t *TelegramClient) RegisterPushNotifications(ctx context.Context, pushType bridgev2.PushType, token string) error

func (*TelegramClient) ResolveIdentifier

func (t *TelegramClient) ResolveIdentifier(ctx context.Context, identifier string, createChat bool) (*bridgev2.ResolveIdentifierResponse, error)

func (*TelegramClient) SearchUsers

func (t *TelegramClient) SearchUsers(ctx context.Context, query string) (resp []*bridgev2.ResolveIdentifierResponse, err error)

func (*TelegramClient) SyncChats

func (t *TelegramClient) SyncChats(ctx context.Context) error

type TelegramConfig

type TelegramConfig struct {
	APIID   int    `yaml:"api_id"`
	APIHash string `yaml:"api_hash"`

	DeviceInfo DeviceInfo `yaml:"device_info"`

	AnimatedSticker   media.AnimatedStickerConfig `yaml:"animated_sticker"`
	ImageAsFilePixels int                         `yaml:"image_as_file_pixels"`

	DisableViewOnce     bool `yaml:"disable_view_once"`
	DisableDisappearing bool `yaml:"disable_disappearing"`

	MemberList MemberListConfig `yaml:"member_list"`

	MaxMemberCount int `yaml:"max_member_count"`

	Ping struct {
		IntervalSeconds int `yaml:"interval_seconds"`
		TimeoutSeconds  int `yaml:"timeout_seconds"`
	} `yaml:"ping"`

	Sync struct {
		UpdateLimit int  `yaml:"update_limit"`
		CreateLimit int  `yaml:"create_limit"`
		DirectChats bool `yaml:"direct_chats"`
	} `yaml:"sync"`

	AlwaysCustomEmojiReaction bool `yaml:"always_custom_emoji_reaction"`

	SavedMessagesAvatar id.ContentURIString `yaml:"saved_message_avatar"`
}

func (TelegramConfig) ShouldBridge

func (c TelegramConfig) ShouldBridge(participantCount int) bool

type TelegramConnector

type TelegramConnector struct {
	Bridge *bridgev2.Bridge
	Config TelegramConfig
	Store  *store.Container
	// contains filtered or unexported fields
}

func (*TelegramConnector) CreateLogin

func (tg *TelegramConnector) CreateLogin(ctx context.Context, user *bridgev2.User, flowID string) (bridgev2.LoginProcess, error)

func (*TelegramConnector) Download

func (tc *TelegramConnector) Download(ctx context.Context, mediaID networkid.MediaID, params map[string]string) (mediaproxy.GetMediaResponse, error)

func (*TelegramConnector) GetCapabilities

func (tg *TelegramConnector) GetCapabilities() *bridgev2.NetworkGeneralCapabilities

func (*TelegramConnector) GetConfig

func (tg *TelegramConnector) GetConfig() (example string, data any, upgrader up.Upgrader)

func (*TelegramConnector) GetDBMetaTypes

func (tg *TelegramConnector) GetDBMetaTypes() database.MetaTypes

func (*TelegramConnector) GetLoginFlows

func (tg *TelegramConnector) GetLoginFlows() []bridgev2.LoginFlow

func (*TelegramConnector) GetName

func (tg *TelegramConnector) GetName() bridgev2.BridgeName

func (*TelegramConnector) Init

func (tg *TelegramConnector) Init(bridge *bridgev2.Bridge)

func (*TelegramConnector) LoadUserLogin

func (tc *TelegramConnector) LoadUserLogin(ctx context.Context, login *bridgev2.UserLogin) (err error)

func (*TelegramConnector) SetMaxFileSize

func (tg *TelegramConnector) SetMaxFileSize(maxSize int64)

func (*TelegramConnector) SetUseDirectMedia

func (tg *TelegramConnector) SetUseDirectMedia()

func (*TelegramConnector) Start

func (tg *TelegramConnector) Start(ctx context.Context) error

func (*TelegramConnector) ValidateConfig

func (tg *TelegramConnector) ValidateConfig() error

type UpdateDispatcher

type UpdateDispatcher struct {
	tg.UpdateDispatcher
	EntityHandler func(context.Context, tg.Entities) error
}

func (UpdateDispatcher) Handle

func (u UpdateDispatcher) Handle(ctx context.Context, updates tg.UpdatesClass) error

type UserLoginMetadata

type UserLoginMetadata struct {
	Phone     string           `json:"phone"`
	Session   UserLoginSession `json:"session"`
	TakeoutID int64            `json:"takeout_id,omitempty"`

	TakeoutDialogCrawlDone   bool               `json:"takeout_portal_crawl_done,omitempty"`
	TakeoutDialogCrawlCursor networkid.PortalID `json:"takeout_portal_crawl_cursor,omitempty"`

	PinnedDialogs []networkid.PortalID `json:"pinned_dialogs,omitempty"`

	PushEncryptionKey []byte `json:"push_encryption_key,omitempty"`
}

type UserLoginSession

type UserLoginSession struct {
	AuthKey       []byte `json:"auth_key,omitempty"`
	Datacenter    int    `json:"dc_id,omitempty"`
	ServerAddress string `json:"server_address,omitempty"`
	ServerPort    int    `json:"port,omitempty"`
	Salt          int64  `json:"salt,omitempty"`
}

func (UserLoginSession) HasAuthKey

func (u UserLoginSession) HasAuthKey() bool

func (*UserLoginSession) Load

func (*UserLoginSession) Save

func (s *UserLoginSession) Save(ctx context.Context, data *session.Data) error

Directories

Path Synopsis
Package waveform implements encoding and decoding of a Telegram waveform.
Package waveform implements encoding and decoding of a Telegram waveform.

Jump to

Keyboard shortcuts

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