tgc

package
v0.0.0-...-1e678a2 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 49 Imported by: 0

Documentation

Overview

Package tgc wraps gotd; it talks to the UI only through model.Event.

Index

Constants

View Source
const Net = "telegram"

Net : the network key of Telegram.

Variables

View Source
var Catalog, _ = fs.Sub(files, "i18n")

Catalog : the texts of the module, in the languages of the client.

Functions

This section is empty.

Types

type Client

type Client struct {
	model.Poster
	// contains filtered or unexported fields
}

func New

func New(cfg Config, events chan<- model.Event) *Client

func (*Client) Block

func (c *Client) Block(ctx context.Context, chat *model.Chat)

Block blocks the peer and reports it as spam. The report comes second: its failure does not fail the block, which is what the user asked for.

func (*Client) BlockMember

func (c *Client) BlockMember(ctx context.Context, token string)

BlockMember blocks and reports a member of the member box, whether a private chat is open with them or not. On success: EvChatGone on their id, which drops the private chat from the list when there was one.

func (*Client) Caps

func (c *Client) Caps() model.Caps

Caps : Telegram does everything the UI knows how to show.

func (*Client) Contacts

func (c *Client) Contacts(ctx context.Context)

Contacts runs contacts.getContacts — the contacts of the account, asked only once per session (the "new chat" overlay). Hash 0: the whole list, never a delta.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, chat *model.Chat, id int)

Delete deletes a message for everybody. The server update comes too: the UI drops the duplicate on Deleted.

func (*Client) DeleteChat

func (c *Client) DeleteChat(ctx context.Context, chat *model.Chat)

DeleteChat deletes the chat: the dialog leaves the list. Private chat and basic group: messages.deleteHistory, MaxID 0 = the whole history and just_clear false also drops the dialog — a basic group stays joined, and its next message brings it back. Supergroup and channel: channels.deleteHistory only empties the history, and only channels.leaveChannel drops the dialog.

func (*Client) Download

func (c *Client) Download(ctx context.Context, m *model.Media, path string)

Download downloads m.Loc to path (3 in parallel at most). A file already there = success at once.

func (*Client) DownloadMap

func (c *Client) DownloadMap(ctx context.Context, m *model.Media, path string)

DownloadMap gets the OSM map of m (Lat/Long); there is no Telegram Loc — an HTTP call to tile.openstreetmap.org through media.Tile, with the same semaphore and the same event back as Download: the UI has nothing to tell apart.

func (*Client) Edit

func (c *Client) Edit(ctx context.Context, chat *model.Chat, id int, text string)

Edit replaces the text of one of my messages.

func (*Client) EditStyled

func (c *Client) EditStyled(ctx context.Context, chat *model.Chat, id int, segs []model.Seg)

EditStyled : like Edit, with formatting on the segments (fences of the draft).

func (*Client) Forward

func (c *Client) Forward(ctx context.Context, from *model.Chat, id int, to *model.Chat, tmpID int64)

Forward : messages.forwardMessages of id, from chat from to chat to.

func (*Client) Info

func (c *Client) Info(ctx context.Context, chat *model.Chat, id, readMax, readInboxMax int)

Info gives the information lines of a message (key "i"). readMax is the ReadOutboxMaxID of the chat (my messages), readInboxMax its ReadInboxMaxID (received messages) — only the UI keeps them up to date, and they are never read again from chat in this goroutine.

func (*Client) Leave

func (c *Client) Leave(ctx context.Context, chat *model.Chat)

Leave leaves a room: a basic group (InputPeerChat) through messages.deleteChatUser(self), a supergroup or a channel through channels.leaveChannel.

func (*Client) LoadDialogs

func (c *Client) LoadDialogs(ctx context.Context)

func (*Client) LoadHistory

func (c *Client) LoadHistory(ctx context.Context, chat *model.Chat, beforeID, limit int)

LoadHistory loads limit messages before beforeID (0 = the newest ones).

func (*Client) LoadHistoryAround

func (c *Client) LoadHistoryAround(ctx context.Context, chat *model.Chat, id, limit int)

LoadHistoryAround loads a page of limit messages centred on id (half before, half after): a precise jump must not end on its target. Direct call, the gotd builder does not expose add_offset.

func (*Client) LoadHistorySince

func (c *Client) LoadHistorySince(ctx context.Context, chat *model.Chat, minID, limit int)

LoadHistorySince loads up to limit messages with an id above minID (sync of a chat at start). minID zero: the recent history.

func (*Client) LoadStickerPack

func (c *Client) LoadStickerPack(ctx context.Context, chat *model.Chat, key string)

func (*Client) LoadStickers

func (c *Client) LoadStickers(ctx context.Context, chat *model.Chat)

func (*Client) Logout

func (c *Client) Logout(ctx context.Context) error

Logout ends the account session on the server: auth.logOut on the home DC and on every other DC the authorization went to, then gotd empties the session file — it also holds the authorized keys of those DCs. The next Run makes a new auth key and goes through the QR flow again.

func (*Client) MarkRead

func (c *Client) MarkRead(ctx context.Context, chat *model.Chat, maxID int)

MarkRead, ReadReactions, ReadMentions and Typing send nothing while the FLOOD_WAIT breaker is open: nothing waits for them.

func (*Client) Participants

func (c *Client) Participants(ctx context.Context, chat *model.Chat)

func (*Client) Pin

func (c *Client) Pin(ctx context.Context, chat *model.Chat, id int, pin bool)

Pin pins (pin true) or unpins a message. The update the RPC gives back goes through the hook middleware (see New) and comes back as OnPinnedMessages → EvPinned: nothing more to post here.

func (*Client) React

func (c *Client) React(ctx context.Context, chat *model.Chat, id int, e string)

React sends my reaction on a message; emoji == "" removes my reaction. The state up to date also comes through OnMessageReactions (server, or echo of this RPC): EvReactions replaces the list, posting twice does nothing.

func (*Client) ReadMentions

func (c *Client) ReadMentions(ctx context.Context, chat *model.Chat)

ReadMentions marks the mentions of me in chat as read on the server — readHistory leaves them on, and the @ badge of the official clients with them. Fire and forget like MarkRead.

func (*Client) ReadReactions

func (c *Client) ReadReactions(ctx context.Context, chat *model.Chat)

ReadReactions marks the reactions to my messages in chat as read on the server — the badge of the official clients goes. Fire and forget like MarkRead.

func (*Client) Resolve

func (c *Client) Resolve(ctx context.Context, q string, join bool, request uint64)

Resolve takes an @username, a t.me/username link, a phone number, or the id of a peer already seen (a member with no @username clicked in the F3 box). join=true joins a channel that was left.

func (*Client) Run

func (c *Client) Run(ctx context.Context) error

Run blocks: connection, authentication, then the update loop.

func (*Client) Search

func (c *Client) Search(ctx context.Context, chat *model.Chat, q string, limit int)

Search runs messages.search in a chat, limit results at most, from the oldest to the newest. The default filter of the builder (InputMessagesFilterEmpty) takes every kind of message.

func (*Client) SearchContacts

func (c *Client) SearchContacts(ctx context.Context, q string, limit int)

SearchContacts runs contacts.search — contacts, public rooms and channels whose name matches q, limit results at most. The peers come from the entities of the answer (access hash included): no network lookup after, neither to show the list nor to open the chat.

func (*Client) SearchGifs

func (c *Client) SearchGifs(ctx context.Context, chat *model.Chat, q string)

SearchGifs asks @gif for q in chat (q empty: the trending ones).

func (*Client) SearchGlobal

func (c *Client) SearchGlobal(ctx context.Context, q string, limit int)

SearchGlobal runs messages.searchGlobal over every chat, limit results at most (from the newest to the oldest, server order). The names come from the entities of the answer: a message whose chat is not there is dropped rather than resolved through the network (one result per unknown chat = as many calls, so a sure FLOOD_WAIT).

func (*Client) SearchMedia

func (c *Client) SearchMedia(ctx context.Context, chat *model.Chat, f model.MediaFilter, before int)

SearchMedia posts one page of the media of tab f older than before.

func (*Client) SearchStickers

func (c *Client) SearchStickers(ctx context.Context, chat *model.Chat, emoji string)

func (*Client) Send

func (c *Client) Send(ctx context.Context, chat *model.Chat, text string, tmpID int64)

func (*Client) SendFile

func (c *Client) SendFile(ctx context.Context, chat *model.Chat, path, caption string, removeAfter bool, tmpID int64)

func (*Client) SendGif

func (c *Client) SendGif(ctx context.Context, chat *model.Chat, g model.Gif, tmpID int64)

SendGif posts an inline result in chat. EvSent like a text send: the UI unpends its line, and the echo comes back through the updates of the RPC.

func (*Client) SendPhoto

func (c *Client) SendPhoto(ctx context.Context, chat *model.Chat, path, caption string, removeAfter bool, tmpID int64)

SendPhoto sends a local image as a photo, caption optional. SendFile does the same as a document (name and mime kept).

EvSent like the text sends: the UI has already shown the send as a pending line, and the receipt unpends it. The echo of the sent message comes back besides, through the updates of the RPC (fed back by hook.UpdateHook, see New); whichever of the two comes first, the window keeps one line. removeAfter : work file (pasted image), erased once the send worked; a file chosen by the user never is.

func (*Client) SendPre

func (c *Client) SendPre(ctx context.Context, chat *model.Chat, text string, tmpID int64)

SendPre : like Send, but text goes as a code block (multiline paste).

func (*Client) SendReply

func (c *Client) SendReply(ctx context.Context, chat *model.Chat, text string, replyTo int, tmpID int64)

SendReply : like Send, as a reply to the message replyTo.

func (*Client) SendSticker

func (c *Client) SendSticker(ctx context.Context, chat *model.Chat, s model.Sticker, tmpID int64)

SendSticker posts the document of a sticker of the box. ponytail: an expired file reference (a box kept open for hours) fails the send with its error; ask the pack again then if it shows up.

func (*Client) SendStyled

func (c *Client) SendStyled(ctx context.Context, chat *model.Chat, segs []model.Seg, tmpID int64)

SendStyled : like Send, with formatting on the segments (pre, italic…).

func (*Client) Typing

func (c *Client) Typing(ctx context.Context, chat *model.Chat, cancel bool)

Typing tells "typing" in chat. cancel (a send) is ignored, as on Discord: the other clients drop the line of a peer when its message comes, so the cancel would double the requests of every send for nothing. Fire and forget like MarkRead: no error comes up, a missed typing hint does not deserve an error path.

func (*Client) WhoReacted

func (c *Client) WhoReacted(ctx context.Context, chat *model.Chat, id int, rs []model.Reaction)

WhoReacted gives the "who reacted" line of the hover popup of a reaction.

func (*Client) WhoRead

func (c *Client) WhoRead(ctx context.Context, chat *model.Chat, id, readMax int)

WhoRead gives the "who read" line of the hover popup of the tick: read date in a private chat, names of the readers in a group, plain read state elsewhere. readMax is the ReadOutboxMaxID kept by the UI.

func (*Client) Whois

func (c *Client) Whois(ctx context.Context, chat *model.Chat)

Whois runs users.getFullUser on a private chat → lines ready to show, and the presence on the way (the account may show up in no update at all).

func (*Client) WhoisMember

func (c *Client) WhoisMember(ctx context.Context, token string)

WhoisMember gives the profile of a member of the member box, with no private chat open with them.

type Config

type Config struct {
	AppID       int
	AppHash     string
	BotToken    string
	SessionPath string
}

type Module

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

Module : the Telegram account — the flat keys api_id, api_hash, bot_token of config.toml, or the telegram section, which wins; then the TG_* variables, which win over both and never go back into the file (a dotfiles repository, a backup…).

func NewModule

func NewModule() *Module

func (*Module) Cache

func (m *Module) Cache(net string) (string, bool)

Cache : a bot and an account do not share their cache. The files of the versions before the split by network (orphans at the root of the cache) are dropped here, best effort: everything comes back under the network at the first write. ponytail: "history" here is the pre-split legacy directory name, not a network id — a future network literally named "history" would get its cache directory wiped on every start. Rename this cleanup (or check the network name) if that day comes; unlikely enough not to guard now.

func (*Module) CanAdd

func (m *Module) CanAdd() bool

CanAdd : no credentials yet, neither in the file nor in TG_*.

func (*Module) Claims

func (m *Module) Claims(string) bool

func (*Module) Commands

func (m *Module) Commands() []module.Command

func (*Module) Label

func (m *Module) Label() string

func (*Module) Launch

func (m *Module) Launch(_ context.Context, _ module.Host, _ string, ev chan<- model.Event) (model.Backend, error)

func (*Module) Load

func (m *Module) Load(src module.ConfigSource) error

func (*Module) Name

func (m *Module) Name() string

func (*Module) Networks

func (m *Module) Networks() []string

func (*Module) OpenSetup

func (m *Module) OpenSetup(h module.Host)

OpenSetup : the page of the hub — how to get an application of one's own on my.telegram.org, and its two values. A personal account only: a bot token stays in config.toml.

func (*Module) Save

func (m *Module) Save(dst module.ConfigSink)

Save writes the three flat keys as the file had them (0 and "" when it had none, as before), and the section only when the file had one.

func (*Module) SessionPath

func (m *Module) SessionPath() string

SessionPath : one session per identity; a bot and a user account never share the same file.

func (*Module) Settings

func (m *Module) Settings() Settings

Settings : the effective values (environment included).

func (*Module) Template

func (m *Module) Template() string

Template : the Telegram block of a new config.toml — top-level keys.

type Settings

type Settings struct {
	APIID    int    `toml:"api_id"`
	APIHash  string `toml:"api_hash"`
	BotToken string `toml:"bot_token"`
}

Settings : the telegram section, or the historic flat keys of the same names at the top of config.toml.

Jump to

Keyboard shortcuts

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