Documentation
¶
Overview ¶
Package tgc wraps gotd; it talks to the UI only through model.Event.
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) Block(ctx context.Context, chat *model.Chat)
- func (c *Client) BlockMember(ctx context.Context, token string)
- func (c *Client) Caps() model.Caps
- func (c *Client) Contacts(ctx context.Context)
- func (c *Client) Delete(ctx context.Context, chat *model.Chat, id int)
- func (c *Client) DeleteChat(ctx context.Context, chat *model.Chat)
- func (c *Client) Download(ctx context.Context, m *model.Media, path string)
- func (c *Client) DownloadMap(ctx context.Context, m *model.Media, path string)
- func (c *Client) Edit(ctx context.Context, chat *model.Chat, id int, text string)
- func (c *Client) EditStyled(ctx context.Context, chat *model.Chat, id int, segs []model.Seg)
- func (c *Client) Forward(ctx context.Context, from *model.Chat, id int, to *model.Chat, tmpID int64)
- func (c *Client) Info(ctx context.Context, chat *model.Chat, id, readMax, readInboxMax int)
- func (c *Client) Leave(ctx context.Context, chat *model.Chat)
- func (c *Client) LoadDialogs(ctx context.Context)
- func (c *Client) LoadHistory(ctx context.Context, chat *model.Chat, beforeID, limit int)
- func (c *Client) LoadHistoryAround(ctx context.Context, chat *model.Chat, id, limit int)
- func (c *Client) LoadHistorySince(ctx context.Context, chat *model.Chat, minID, limit int)
- func (c *Client) LoadStickerPack(ctx context.Context, chat *model.Chat, key string)
- func (c *Client) LoadStickers(ctx context.Context, chat *model.Chat)
- func (c *Client) Logout(ctx context.Context) error
- func (c *Client) MarkRead(ctx context.Context, chat *model.Chat, maxID int)
- func (c *Client) Participants(ctx context.Context, chat *model.Chat)
- func (c *Client) Pin(ctx context.Context, chat *model.Chat, id int, pin bool)
- func (c *Client) React(ctx context.Context, chat *model.Chat, id int, e string)
- func (c *Client) ReadMentions(ctx context.Context, chat *model.Chat)
- func (c *Client) ReadReactions(ctx context.Context, chat *model.Chat)
- func (c *Client) Resolve(ctx context.Context, q string, join bool, request uint64)
- func (c *Client) Run(ctx context.Context) error
- func (c *Client) Search(ctx context.Context, chat *model.Chat, q string, limit int)
- func (c *Client) SearchContacts(ctx context.Context, q string, limit int)
- func (c *Client) SearchGifs(ctx context.Context, chat *model.Chat, q string)
- func (c *Client) SearchGlobal(ctx context.Context, q string, limit int)
- func (c *Client) SearchMedia(ctx context.Context, chat *model.Chat, f model.MediaFilter, before int)
- func (c *Client) SearchStickers(ctx context.Context, chat *model.Chat, emoji string)
- func (c *Client) Send(ctx context.Context, chat *model.Chat, text string, tmpID int64)
- func (c *Client) SendFile(ctx context.Context, chat *model.Chat, path, caption string, removeAfter bool, ...)
- func (c *Client) SendGif(ctx context.Context, chat *model.Chat, g model.Gif, tmpID int64)
- func (c *Client) SendPhoto(ctx context.Context, chat *model.Chat, path, caption string, removeAfter bool, ...)
- func (c *Client) SendPre(ctx context.Context, chat *model.Chat, text string, tmpID int64)
- func (c *Client) SendReply(ctx context.Context, chat *model.Chat, text string, replyTo int, tmpID int64)
- func (c *Client) SendSticker(ctx context.Context, chat *model.Chat, s model.Sticker, tmpID int64)
- func (c *Client) SendStyled(ctx context.Context, chat *model.Chat, segs []model.Seg, tmpID int64)
- func (c *Client) Typing(ctx context.Context, chat *model.Chat, cancel bool)
- func (c *Client) WhoReacted(ctx context.Context, chat *model.Chat, id int, rs []model.Reaction)
- func (c *Client) WhoRead(ctx context.Context, chat *model.Chat, id, readMax int)
- func (c *Client) Whois(ctx context.Context, chat *model.Chat)
- func (c *Client) WhoisMember(ctx context.Context, token string)
- type Config
- type Module
- func (m *Module) Cache(net string) (string, bool)
- func (m *Module) CanAdd() bool
- func (m *Module) Claims(string) bool
- func (m *Module) Commands() []module.Command
- func (m *Module) Label() string
- func (m *Module) Launch(_ context.Context, _ module.Host, _ string, ev chan<- model.Event) (model.Backend, error)
- func (m *Module) Load(src module.ConfigSource) error
- func (m *Module) Name() string
- func (m *Module) Networks() []string
- func (m *Module) OpenSetup(h module.Host)
- func (m *Module) Save(dst module.ConfigSink)
- func (m *Module) SessionPath() string
- func (m *Module) Settings() Settings
- func (m *Module) Template() string
- type Settings
Constants ¶
const Net = "telegram"
Net : the network key of Telegram.
Variables ¶
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 ¶
func (*Client) Block ¶
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 ¶
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) Contacts ¶
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 ¶
Delete deletes a message for everybody. The server update comes too: the UI drops the duplicate on Deleted.
func (*Client) DeleteChat ¶
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 ¶
Download downloads m.Loc to path (3 in parallel at most). A file already there = success at once.
func (*Client) DownloadMap ¶
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) EditStyled ¶
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 ¶
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 ¶
Leave leaves a room: a basic group (InputPeerChat) through messages.deleteChatUser(self), a supergroup or a channel through channels.leaveChannel.
func (*Client) LoadDialogs ¶
func (*Client) LoadHistory ¶
LoadHistory loads limit messages before beforeID (0 = the newest ones).
func (*Client) LoadHistoryAround ¶
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 ¶
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 (*Client) Logout ¶
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 ¶
MarkRead, ReadReactions, ReadMentions and Typing send nothing while the FLOOD_WAIT breaker is open: nothing waits for them.
func (*Client) Pin ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) Search ¶
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 ¶
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 ¶
SearchGifs asks @gif for q in chat (q empty: the trending ones).
func (*Client) SearchGlobal ¶
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 (*Client) SendGif ¶
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) 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 ¶
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 ¶
SendStyled : like Send, with formatting on the segments (pre, italic…).
func (*Client) Typing ¶
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 ¶
WhoReacted gives the "who reacted" line of the hover popup of a reaction.
func (*Client) WhoRead ¶
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.
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 (*Module) Cache ¶
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) OpenSetup ¶
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 ¶
SessionPath : one session per identity; a bot and a user account never share the same file.