Documentation
¶
Index ¶
- Constants
- Variables
- func ReadAuthLine(in *os.File, hide bool) (string, error)
- type Animation
- type Audio
- type AuthState
- type AuthStateCallback
- type AuthStateMsg
- type BasicGroupFullInfo
- type Chat
- type ChatAction
- type ChatActionCancel
- type ChatActionMsg
- type ChatActionTyping
- type ChatFolder
- type ChatFoldersMsg
- type ChatLastMessageMsg
- type ChatMarkedReadMsg
- type ChatMember
- type ChatMemberStatus
- type ChatMemberStatusAdministrator
- type ChatMemberStatusBanned
- type ChatMemberStatusCreator
- type ChatMemberStatusLeft
- type ChatMemberStatusMember
- type ChatMemberStatusRestricted
- type ChatMentionsReadMsg
- type ChatMuteChangedMsg
- type ChatReactionsReadMsg
- type ChatReadInboxMsg
- type ChatReadOutboxMsg
- type ChatType
- type ChatUnreadReactionsMsg
- type ChatUpdateMsg
- type Client
- func (c *Client) CancelUpload(path string)
- func (c *Client) Close() error
- func (c *Client) CloseContext(ctx context.Context) error
- func (c *Client) CreatePrivateChat(userID int64) (*Chat, error)
- func (c *Client) DataDir() string
- func (c *Client) DeleteMessages(chatID int64, messageIDs []int64, revoke bool) error
- func (c *Client) DeviceCount() (int, error)
- func (c *Client) DiscussionMessage(chatID, messageID int64) (int64, int64, error)
- func (c *Client) DownloadFileSync(key string) (*File, error)
- func (c *Client) DownloadMessageFile(chatID, messageID int64, key string) (*File, error)
- func (c *Client) EditTextMessage(chatID int64, messageID int64, text string) (*Message, error)
- func (c *Client) EditTextMessageWithMentions(chatID int64, messageID int64, text string, mentions []MentionSpan) (*Message, int, error)
- func (c *Client) FilesDir() string
- func (c *Client) ForwardMessages(fromChatID, toChatID int64, messageIDs []int64) ([]*Message, error)
- func (c *Client) GetBasicGroupFullInfo(chatID int64) (*BasicGroupFullInfo, error)
- func (c *Client) GetChat(chatID int64) (*Chat, error)
- func (c *Client) GetChatFolders() ([]*ChatFolder, error)
- func (c *Client) GetChatHistory(chatID, fromMessageID int64, offset, limit int32) ([]*Message, error)
- func (c *Client) GetContacts() ([]*User, error)
- func (c *Client) GetMe() (*User, error)
- func (c *Client) GetMessage(chatID, messageID int64) (*Message, error)
- func (c *Client) GetMessages(chatID int64, messageIDs []int64) ([]*Message, error)
- func (c *Client) GetSupergroupFullInfo(chatID int64) (*SupergroupFullInfo, error)
- func (c *Client) GetSupergroupMembers(chatID int64, offset, limit int32) ([]*ChatMember, error)
- func (c *Client) GetUser(userID int64) (*User, error)
- func (c *Client) IsReady() bool
- func (c *Client) ListChats(limit int) ([]*Chat, error)
- func (c *Client) LoadChats(limit int) error
- func (c *Client) LoadFolderDialogs(folder *ChatFolder, already map[int64]struct{}) ([]*Chat, error)
- func (c *Client) LoadMoreChats(limit int) (int, error)
- func (c *Client) MoreChatsToLoad() bool
- func (c *Client) OpenChat(chatID int64) error
- func (c *Client) ReadAllMentions(chatID int64) (done bool, err error)
- func (c *Client) ReadMentions(chatID int64, messageIDs []int64) error
- func (c *Client) ReadReactions(chatID int64) error
- func (c *Client) ResolveUsername(username string) (*Chat, error)
- func (c *Client) SearchChatMedia(chatID int64, filter MediaFilter, limit int32) ([]*Message, error)
- func (c *Client) SearchChatMembers(chatID int64, query string, limit int) ([]*User, error)
- func (c *Client) SearchChatMessages(chatID int64, query string, fromMessageID int64, limit int32) ([]*Message, error)
- func (c *Client) SearchChats(query string, limit int32) ([]*Chat, error)
- func (c *Client) SearchMessages(query string, limit int32) ([]*Message, error)
- func (c *Client) SendFileMessage(chatID int64, path, caption string, replyToMessageID int64, ...) (*Message, error)
- func (c *Client) SendFileMessageWithMentions(chatID int64, path, caption string, mentions []MentionSpan, ...) (*Message, int, error)
- func (c *Client) SendOpenedFileMessage(chatID int64, f *os.File, caption string, replyToMessageID int64, ...) (*Message, error)
- func (c *Client) SendOpenedFileMessageWithMentions(chatID int64, f *os.File, caption string, mentions []MentionSpan, ...) (*Message, int, error)
- func (c *Client) SendPhotoMessage(chatID int64, path, caption string, replyToMessageID int64, ...) (*Message, error)
- func (c *Client) SendPhotoMessageWithMentions(chatID int64, path, caption string, mentions []MentionSpan, ...) (*Message, int, error)
- func (c *Client) SendRoots() []string
- func (c *Client) SendTextMessage(chatID int64, text string, replyToMessageID, placeholderID int64) (*Message, error)
- func (c *Client) SendTextMessageWithMentions(chatID int64, text string, mentions []MentionSpan, ...) (*Message, int, error)
- func (c *Client) SetPinned(chatID, messageID int64, pinned bool) error
- func (c *Client) SetReaction(chatID, messageID int64, emoji string) error
- func (c *Client) Start() error
- func (c *Client) StartUpload(path string)
- func (c *Client) UnreadMentions(chatID int64, limit int) ([]int64, error)
- func (c *Client) ViewMessages(chatID int64, messageIDs []int64) error
- func (c *Client) WaitReady()
- func (c *Client) WarmPeer(chatID int64)
- type ClientErrorMsg
- type ClientWarningMsg
- type Comments
- type ConnectionState
- type ConnectionStateMsg
- type Contact
- type Document
- type File
- type FileUpdateMsg
- type FormattedText
- type Listener
- type Location
- type MediaFilter
- type MentionSpan
- type Message
- type MessageAnimation
- type MessageAudio
- type MessageChatAddMembers
- type MessageChatChangePhoto
- type MessageChatChangeTitle
- type MessageChatDeleteMember
- type MessageChatJoinByLink
- type MessageContact
- type MessageContent
- type MessageDeletedMsg
- type MessageDocument
- type MessageEditedMsg
- type MessageLocation
- type MessagePhoto
- type MessagePinMessage
- type MessagePoll
- type MessageSendFailedMsg
- type MessageSendSucceededMsg
- type MessageSender
- type MessageSenderChat
- type MessageSenderUser
- type MessageSticker
- type MessageText
- type MessageUnsupported
- type MessageVideo
- type MessageVideoNote
- type MessageVoiceNote
- type NewMessageMsg
- type Photo
- type PhotoSize
- type Poll
- type PollOption
- type QRLoginOptions
- type QRLoginToken
- type Reaction
- type ResyncNeededMsg
- type SendRoots
- type Sticker
- type SupergroupFullInfo
- type TUIAuthorizer
- func (a *TUIAuthorizer) AcceptTermsOfService(ctx context.Context, _ tg.HelpTermsOfService) error
- func (a *TUIAuthorizer) Close()
- func (a *TUIAuthorizer) Code(ctx context.Context, _ *tg.AuthSentCode) (string, error)
- func (a *TUIAuthorizer) Password(ctx context.Context) (string, error)
- func (a *TUIAuthorizer) Phone(ctx context.Context) (string, error)
- func (a *TUIAuthorizer) SetErrorCallback(cb func(error))
- func (a *TUIAuthorizer) SetStateCallback(cb AuthStateCallback)
- func (a *TUIAuthorizer) SignUp(ctx context.Context) (auth.UserInfo, error)
- func (a *TUIAuthorizer) SubmitCode(code string)
- func (a *TUIAuthorizer) SubmitPassword(password string)
- func (a *TUIAuthorizer) SubmitPhone(phone string)
- type TextEntity
- type TextEntityType
- type TextEntityTypeBlockQuote
- type TextEntityTypeBold
- type TextEntityTypeBotCommand
- type TextEntityTypeCode
- type TextEntityTypeEmailAddress
- type TextEntityTypeHashtag
- type TextEntityTypeItalic
- type TextEntityTypeMention
- type TextEntityTypeMentionName
- type TextEntityTypePre
- type TextEntityTypePreCode
- type TextEntityTypeSpoiler
- type TextEntityTypeStrikethrough
- type TextEntityTypeTextURL
- type TextEntityTypeURL
- type TextEntityTypeUnderline
- type TmeLink
- type UploadProgressMsg
- type User
- type UserStatus
- type UserStatusEmpty
- type UserStatusLastMonth
- type UserStatusLastWeek
- type UserStatusOffline
- type UserStatusOnline
- type UserStatusRecently
- type Video
- type VideoNote
- type VoiceNote
- type WebPage
Constants ¶
const AllChatsFolderID int32 = 0
AllChatsFolderID is the ID Telegram reserves for the implicit "All chats" folder. The server only ever names it explicitly via dialogFilterDefault; otherwise the UI is expected to synthesize it.
const MaxDialogsLimit = 500
MaxDialogsLimit caps ListChats so a bad limit cannot walk the whole dialog list. The TUI first paint only loads one recency page; folder membership comes from include/pin peers, not from this cap.
Variables ¶
var ( ErrClientStarted = errors.New("telegram client already started") ErrClientClosed = errors.New("telegram client already closed") )
var ErrLoginRequired = errors.New("login required: run 'telegram-mcp login' first")
ErrLoginRequired is returned by the authorizer in non-interactive mode when the session is not authorized yet.
var ErrQRPasswordPromptRequired = errors.New("QR login requires a 2FA password prompt")
ErrQRPasswordPromptRequired is returned when QR login reaches 2FA but no password prompt was configured.
Functions ¶
Types ¶
type AuthStateCallback ¶
AuthStateCallback is called when the auth state changes. Used to notify the TUI about state transitions.
type AuthStateMsg ¶
type AuthStateMsg struct {
State AuthState
}
AuthStateMsg carries authorization state changes.
type BasicGroupFullInfo ¶
type BasicGroupFullInfo struct {
Description string
MemberCount int32
Members []*ChatMember
}
BasicGroupFullInfo holds full info about a basic group.
type Chat ¶
type Chat struct {
ID int64
Type ChatType
Title string
Username string
// Photo is the small avatar file; ID is a file registry key.
Photo *File
LastMessage *Message
UnreadCount int32
LastReadInboxMessageID int64
LastReadOutboxMessageID int64
// UnreadReactionsCount is how many of the reader's messages carry a
// reaction they have not seen: the heart the phone shows on a chat. It
// is a counter of its own, apart from UnreadCount, and only a dialog
// carries it.
UnreadReactionsCount int32
// UnreadMentionsCount is how many messages in the chat name the reader
// and have not been opened: the @ the phone shows. Like the reactions
// it is a counter of its own, only a dialog carries it, and only a
// group ever has any.
UnreadMentionsCount int32
// Pinned and Order define chat list ordering: pinned first,
// then by Order descending (unix time of the last message).
Pinned bool
Order int64
// Muted mirrors the peer's notification settings: an explicit
// silent flag or a mute-until date in the future.
Muted bool
}
Chat is the domain representation of a Telegram dialog.
type ChatAction ¶
type ChatAction interface {
// contains filtered or unexported methods
}
ChatAction is a user activity in a chat (typing etc).
type ChatActionCancel ¶
type ChatActionCancel struct{}
ChatActionCancel means the user stopped the action.
type ChatActionMsg ¶
type ChatActionMsg struct {
ChatId int64
UserId int64
Action ChatAction
}
ChatActionMsg is sent when someone is typing or performing an action.
type ChatActionTyping ¶
type ChatActionTyping struct{}
ChatActionTyping means the user is typing (or recording/uploading).
type ChatFolder ¶
type ChatFolder struct {
ID int32
Title string
Emoticon string
PinnedChatIDs []int64
IncludedChatIDs []int64
ExcludedChatIDs []int64
// Category flags. Only plain folders (dialogFilter) carry these;
// shared chatlist folders leave them false.
Contacts bool
NonContacts bool
Groups bool
Channels bool
Bots bool
ExcludeMuted bool
ExcludeRead bool
ExcludeArchived bool
// contains filtered or unexported fields
}
ChatFolder is the domain representation of a Telegram folder (a "dialog filter" in the MTProto schema).
Chat IDs are canonical TDLib-style IDs, the same namespace as Chat.ID.
func (*ChatFolder) NeedsPeerFetch ¶
func (f *ChatFolder) NeedsPeerFetch() bool
NeedsPeerFetch reports whether this folder has explicit include/pin peers. The folder list is those peers (plus any type-flag matches already in the recency cache), not a slice of getDialogs.
type ChatFoldersMsg ¶
type ChatFoldersMsg struct {
Folders []*ChatFolder
}
ChatFoldersMsg carries the current chat folder list, in server order.
type ChatLastMessageMsg ¶
ChatLastMessageMsg is sent when a chat's last message changes.
type ChatMarkedReadMsg ¶ added in v0.0.26
ChatMarkedReadMsg is sent when this client has marked a chat read up to MaxMessageId. It is the local half of ChatReadInboxMsg: the server's receipt for a read made by this session does not reliably come back, and without this the chat being read kept its unread badge.
type ChatMember ¶
type ChatMember struct {
MemberID MessageSender
Status ChatMemberStatus
}
ChatMember is a member of a group or channel.
type ChatMemberStatus ¶
type ChatMemberStatus interface {
// contains filtered or unexported methods
}
ChatMemberStatus is the role of a chat member.
type ChatMemberStatusAdministrator ¶
type ChatMemberStatusAdministrator struct {
CustomTitle string
}
type ChatMemberStatusBanned ¶
type ChatMemberStatusBanned struct{}
type ChatMemberStatusCreator ¶
type ChatMemberStatusCreator struct {
CustomTitle string
}
type ChatMemberStatusLeft ¶
type ChatMemberStatusLeft struct{}
type ChatMemberStatusMember ¶
type ChatMemberStatusMember struct{}
type ChatMemberStatusRestricted ¶
type ChatMemberStatusRestricted struct{}
type ChatMentionsReadMsg ¶ added in v0.0.26
ChatMentionsReadMsg is sent when this client has cleared unread mentions in a chat: the ones in MessageIds, or every one when All is set. No MTProto update carries a chat's mention count, so the chat list keeps it live from this and from arriving messages, and has nothing else to go on.
type ChatMuteChangedMsg ¶
ChatMuteChangedMsg is sent when a chat's notification settings change.
type ChatReactionsReadMsg ¶ added in v0.0.26
type ChatReactionsReadMsg struct {
ChatId int64
}
ChatReactionsReadMsg is sent when this client has cleared a chat's unread reactions. It is the reactions' counterpart of ChatMarkedReadMsg, sent for the same reason: the chat list should not have to wait on the server to say what this client just did.
type ChatReadInboxMsg ¶
ChatReadInboxMsg is sent when the read inbox state changes.
type ChatReadOutboxMsg ¶
ChatReadOutboxMsg is sent when the read outbox state changes.
type ChatUnreadReactionsMsg ¶ added in v0.0.26
type ChatUnreadReactionsMsg struct {
ChatId int64
}
ChatUnreadReactionsMsg is sent when somebody reacts to one of the reader's messages and the reaction is flagged unread: the chat now has a reaction to clear. It carries no count. The update says a reaction is unread, not how many of the chat's messages have one, so the most it can say is "at least one".
type ChatUpdateMsg ¶
type ChatUpdateMsg struct {
Chat *Chat
// FromPeer says this chat was built by resolving a PEER rather than by
// reading a dialog, and so is a partial view: it knows who the chat is
// and whether it is muted, and nothing about unread counts, pinning or
// the last message.
//
// The store has to be told, because it cannot tell from the value: a
// chat that is not pinned and a chat whose pin nobody asked about are
// the same struct. Storing one of these as though it were complete is
// what unmuted every chat the reader opened.
FromPeer bool
}
ChatUpdateMsg is sent when chat metadata changes (title, photo, etc) or when a chat is loaded from the dialog list.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps a gotd telegram client with the app-facing API.
func NewClient ¶
func NewClient(cfg *config.Config, authorizer *TUIAuthorizer) *Client
NewClient constructs an update-receiving client without starting it. Register callbacks and update handlers before calling Start.
func NewClientAsync ¶
func NewClientAsync(cfg *config.Config, authorizer *TUIAuthorizer) *Client
NewClientAsync is retained for callers that have nothing to register before startup. Interactive frontends should use NewClient and Start explicitly.
func NewRPCClient ¶
func NewRPCClient(cfg *config.Config, authorizer *TUIAuthorizer) *Client
NewRPCClient constructs an RPC-only client without starting it. no-updates mode: the connection never subscribes to the update stream, so it does not compete with the TUI (or other processes sharing the same session) for realtime updates. Used by telegram-mcp serve.
func NewRPCClientAsync ¶
func NewRPCClientAsync(cfg *config.Config, authorizer *TUIAuthorizer) *Client
NewRPCClientAsync is the compatibility form of NewRPCClient.
func (*Client) CancelUpload ¶ added in v0.0.21
CancelUpload stops an eager upload and forgets it, for an attachment that was discarded before it was sent.
func (*Client) Close ¶
Close shuts the client down and waits for its run loop and state-store cleanup to finish, up to a short process-shutdown bound.
func (*Client) CloseContext ¶
CloseContext is Close with a caller-provided shutdown bound.
func (*Client) CreatePrivateChat ¶
CreatePrivateChat returns a (synthetic) private chat entry for a user. No RPC is needed beyond resolving the user — the real chat is created server-side when the first message is sent.
func (*Client) DeleteMessages ¶
DeleteMessages deletes messages from a chat.
revoke asks Telegram to delete the messages for everyone rather than only for the current user. It is IGNORED for channels and supergroups: channels.deleteMessages has no such flag because channel deletions are always for everyone.
On success the deletion is published immediately so the UI does not wait for the server echo. The server sends its own update shortly after; the message store deletes by filtering on an ID set, so applying the same deletion twice is a no-op.
func (*Client) DeviceCount ¶
DeviceCount is how many sessions are currently authorised on this account, this one included.
It is the number Telegram's own clients show under "Devices", and it is worth a cell in the top bar for the reason Telegram gives it a screen: a count higher than the user expects is how an unauthorised login is noticed. A constant would not be worth the space; this varies, and when it varies it means something.
One RPC, no paging: account.getAuthorizations returns the whole list. The caller fetches it when the connection becomes ready and holds the answer — sessions are created and revoked by hand, on the scale of days, so polling for it would spend requests to watch a number that does not move.
The count is 0 on every error, which is not merely the zero value: 0 is also what "not asked yet" looks like to the only consumer, and both mean the top bar draws no device cell. A caller that wants to tell them apart has the error; a caller that does not can ignore it safely.
func (*Client) DiscussionMessage ¶
DiscussionMessage finds where a channel post's comments live: the chat and the message inside it that the comments hang off.
A post's comments are not in the channel. Telegram copies the post into the linked group and the comments are replies to that copy, so opening them means opening a different chat at a message whose id this client has never seen. This is the only call that knows the translation.
The linked group is announced as a side effect, the same way CreatePrivateChat announces a chat it resolved: the caller is about to open it, and a chat opening with no name is a chat that looks broken for as long as the resolve takes.
Announced through GetChat rather than off the Chats the response already carries. Those are peers, and a chat built from a peer carries Muted=false — which the store would merge over a group the reader had muted on purpose. That is divergence 39 exactly, and the AST guard beside it refused the shortcut when this was first written that way.
func (*Client) DownloadFileSync ¶
DownloadFileSync downloads a registered file to the files dir and returns its local state. Concurrent calls for the same key share one in-flight download via the registry's singleflight group.
A key whose entry is gone is an unknown file here. A file a message shows comes back through Client.DownloadMessageFile, which knows the message to fetch it from.
func (*Client) DownloadMessageFile ¶ added in v0.0.28
DownloadMessageFile is Client.DownloadFileSync for a file a message shows, and the form to use whenever the message is at hand.
The registry is bounded (#33), so the entry behind a key can be gone by the time a reader asks for it: a photo still on screen, scrolled past thousands of files ago. The message is what registered it, so fetching the message again — the same fetch an edit takes — registers it again, and the download goes ahead instead of reporting an unknown file.
func (*Client) EditTextMessage ¶
EditTextMessage edits a text message.
func (*Client) EditTextMessageWithMentions ¶ added in v0.0.28
func (c *Client) EditTextMessageWithMentions(chatID int64, messageID int64, text string, mentions []MentionSpan) (*Message, int, error)
EditTextMessageWithMentions is EditTextMessage for text that mentions users without a username (see MentionSpan). An edit replaces all of a message's entities, so mentions kept through the edit must be passed again. Dropped mentions are counted as in SendTextMessageWithMentions.
func (*Client) ForwardMessages ¶ added in v0.0.18
func (c *Client) ForwardMessages(fromChatID, toChatID int64, messageIDs []int64) ([]*Message, error)
ForwardMessages forwards messages from one chat to another using Telegram's own forwarding RPC, and returns the copies that landed in the destination.
It does not copy content. Re-sending the text, or downloading the media and uploading it again, produces a message that merely looks similar: it loses the "forwarded from" attribution, the original entities, the reply and media semantics, and — the part that matters — the server-side restriction on chats whose content is protected. Forwarding is a thing the server does, and asking it is the only way to get it.
Attribution and captions are preserved (DropAuthor and DropMediaCaptions stay unset). A caller that wants an unattributed copy is asking for a different feature, and Telegram's own clients make it a separate choice rather than a default.
func (*Client) GetBasicGroupFullInfo ¶
func (c *Client) GetBasicGroupFullInfo(chatID int64) (*BasicGroupFullInfo, error)
GetBasicGroupFullInfo returns full info (incl. members) for a basic group.
func (*Client) GetChat ¶
GetChat returns a single chat by canonical chat ID.
The mute flag comes from a second call, because resolving a peer does not report it: notify settings belong to the account's view of the peer, not to the peer. Without it a chat outside the loaded dialog page would look unmuted to everything downstream, and the first message from it would ring — which is the whole reason anybody looks at this function.
func (*Client) GetChatFolders ¶
func (c *Client) GetChatFolders() ([]*ChatFolder, error)
GetChatFolders returns the user's chat folders in server order.
func (*Client) GetChatHistory ¶
func (c *Client) GetChatHistory(chatID, fromMessageID int64, offset, limit int32) ([]*Message, error)
GetChatHistory returns messages of a chat, newest first. fromMessageID paginates backwards (offsetID); offset skips messages.
func (*Client) GetContacts ¶
GetContacts returns the contact list.
func (*Client) GetMessage ¶
GetMessage fetches a single message.
func (*Client) GetMessages ¶ added in v0.0.18
GetMessages fetches several messages of one chat in a single request.
Both messages.getMessages and channels.getMessages take a list, and the callers that refetch after an edit, a reaction or a poll vote have a list — one request per update is the shape Telegram answers with FLOOD_WAIT. [GetMessage] is this with a list of one.
Messages the server did not return are simply absent from the result: a message deleted between the update and the fetch is a normal race, not an error the caller can do anything about.
func (*Client) GetSupergroupFullInfo ¶
func (c *Client) GetSupergroupFullInfo(chatID int64) (*SupergroupFullInfo, error)
GetSupergroupFullInfo returns full info for a supergroup/channel chat.
func (*Client) GetSupergroupMembers ¶
func (c *Client) GetSupergroupMembers(chatID int64, offset, limit int32) ([]*ChatMember, error)
GetSupergroupMembers returns members of a supergroup/channel.
func (*Client) ListChats ¶
ListChats fetches the dialog list from the beginning without emitting any UI events. Telegram returns at most 100 dialogs per request, so larger limits are served by paginating until limit is reached or a short page arrives.
func (*Client) LoadChats ¶
LoadChats fetches the first page of the dialog list and pushes every chat to the UI as a ChatUpdateMsg (this replaces tdlib's updateNewChat flow).
It also arms the pager: whatever it stopped at is where [LoadMoreChats] carries on from, so the reader can reach dialogs older than the first page without the client fetching an account's entire history at startup.
func (*Client) LoadFolderDialogs ¶
func (c *Client) LoadFolderDialogs(folder *ChatFolder, already map[int64]struct{}) ([]*Chat, error)
LoadFolderDialogs fetches dialogs for a folder's include and pin lists. already skips peers whose chat IDs are already in the local store so switching tabs does not re-fetch. One RPC covers up to folderPeerChunk peers — a 30-chat folder is a single round trip, not a 500-dialog walk.
func (*Client) LoadMoreChats ¶ added in v0.0.9
LoadMoreChats fetches the next page after whatever has been loaded so far, pushing each chat to the UI. It reports how many arrived; zero means the list is exhausted and asking again will not change that.
func (*Client) MoreChatsToLoad ¶ added in v0.0.9
MoreChatsToLoad reports whether the dialog list has more to give. False once a short page has arrived, so the UI can stop asking rather than issuing a request per keystroke at the bottom of the list.
func (*Client) OpenChat ¶
OpenChat is a light-weight placeholder kept for API compatibility: gotd needs no open/close chat lifecycle. It emits the chat so the store has it even for chats outside the loaded dialogs.
func (*Client) ReadAllMentions ¶ added in v0.0.26
ReadAllMentions clears every unread mention in a chat, and on success announces it with ChatMentionsReadMsg with All set, for the reason [ViewMessages] announces a read. It is the whole chat, forum topics included: no top message is given.
The call is repeated while the answer carries a positive offset, up to maxReadMentionsCalls times, the way [ReadReactions] repeats its own. Only an answer that says it is done is announced; stopping at the cap leaves the count for the next reload to correct.
done reports whether the server said it had finished. Stopping at the cap is not an error, and it is not done either, so a caller that has to say whether the mentions are gone reads done rather than inferring it from a nil error.
func (*Client) ReadMentions ¶ added in v0.0.26
ReadMentions clears the given unread mentions in a chat, and on success announces it with ChatMentionsReadMsg, for the reason [ViewMessages] announces a read. A mention is cleared by reading its message's contents; reading the history does not do it.
A channel's message IDs are its own numbering, so a supergroup takes the call that names the channel; every other chat takes the one with bare IDs.
func (*Client) ReadReactions ¶ added in v0.0.26
ReadReactions clears a chat's unread reactions, and on success announces it with ChatReactionsReadMsg, for the reason [ViewMessages] announces a read. It is the whole chat, not a thread: no top message is given.
A positive offset in the server's answer means the call has to be made again, which is all the API documents about it. The call is repeated up to maxReadReactionsCalls times. Only an answer that says it is done is announced: stopping at the cap is not an error, but it is not a clear the server confirmed either, so the count stays and the next open asks again.
func (*Client) ResolveUsername ¶ added in v0.0.24
ResolveUsername turns a public @username into the chat behind it.
It is the network half of following a t.me link (see ParseTmeLink): a public link names a username, and a username is not a chat ID until the server says which peer it belongs to.
The chat comes back rather than only its ID, because a username may well name a chat this account has never opened — that is the ordinary case for a link somebody pasted. ResolveDomain teaches the peer manager the access hash on the way through, so the history fetch that follows can work; the returned chat is what gives the caller a title to open it under, and the announcement below is what puts it in the chat list. Both halves of "a chat this client has not seen before" are therefore answered here, exactly as Client.CreatePrivateChat answers them for a contact.
func (*Client) SearchChatMedia ¶
SearchChatMedia returns a chat's messages of one kind, newest first.
This is the rail's data path. Unlike [SearchChatMessages] it takes no query — the filter IS the query, and MTProto answers a filter-only search with the whole server-side index for that kind. Requiring a query here would make "this chat's files" unaskable.
limit is capped rather than rejected: the rail shows a handful of rows, and a caller asking for more than a screenful of them has made an arithmetic mistake, not a request worth failing.
func (*Client) SearchChatMembers ¶ added in v0.0.28
SearchChatMembers finds the members of a chat whom the @-mention picker can offer for query, the text typed after the @.
What it asks depends on the kind of chat:
- A supergroup is searched on the server for query, or asked for its recent members when query is empty. At most limit members come back, in the server's order. As for Client.GetSupergroupMembers, no limit or one past the server's cap of 200 asks for the cap.
- A basic group returns ALL its members, and query and limit are ignored. A basic group is small, so the composer filters the list locally as the query grows and does not ask again.
- A private chat or a broadcast channel returns nil with no error, and no member list is asked for. The picker is not offered there.
Either way each user comes back once. The reader's own account and deleted accounts are left out. So is anyone who has left or been removed, and anyone the answer names only as someone's inviter, promoter or remover. A restricted member is still a member and stays in. Every user in the answer is handed to the peers manager before this returns, so a mention of the one picked has the access hash a send needs to name them by ID.
A refusal from the server is wrapped and returned. A FLOOD_WAIT is not waited out here: the caller is a picker being typed into, and it decides whether a later query is worth asking.
func (*Client) SearchChatMessages ¶
func (c *Client) SearchChatMessages(chatID int64, query string, fromMessageID int64, limit int32) ([]*Message, error)
SearchChatMessages searches messages within a single chat, newest first, like GetChatHistory.
fromMessageID is the pagination offset: 0 starts from the latest message, and paging back means passing the ID of the oldest message already seen. limit is clamped to 1..100 (0 or negative means 100, matching the sibling search and history methods).
One RPC covers every chat kind — messages.search takes the peer, so users, basic groups, supergroups and channels all route through c.inputPeer with no channel-specific variant.
An empty query returns an error rather than a guaranteed server-side SEARCH_QUERY_EMPTY round trip.
func (*Client) SearchChats ¶
SearchChats searches chat titles by query (server-side).
func (*Client) SearchMessages ¶
SearchMessages searches messages globally by query.
func (*Client) SendFileMessage ¶
func (c *Client) SendFileMessage(chatID int64, path, caption string, replyToMessageID int64, placeholderID int64) (*Message, error)
SendFileMessage uploads a local file and sends it as a document, optionally with a caption and as a reply.
placeholderID is the local echo the caller already drew for this send, so the success message can name the row to swap; 0 when there is none.
func (*Client) SendFileMessageWithMentions ¶ added in v0.0.28
func (c *Client) SendFileMessageWithMentions(chatID int64, path, caption string, mentions []MentionSpan, replyToMessageID int64, placeholderID int64) (*Message, int, error)
SendFileMessageWithMentions is SendFileMessage for a caption that mentions users without a username (see MentionSpan). Dropped mentions are counted as in SendTextMessageWithMentions.
func (*Client) SendOpenedFileMessage ¶ added in v0.0.28
func (c *Client) SendOpenedFileMessage(chatID int64, f *os.File, caption string, replyToMessageID int64, placeholderID int64) (*Message, error)
SendOpenedFileMessage is SendFileMessage for a file that is already open, normally by SendRoots.Open: it uploads from f and never opens anything by name, so what is sent is what was checked. f is closed when the send is over, whether or not it succeeded.
func (*Client) SendOpenedFileMessageWithMentions ¶ added in v0.0.28
func (c *Client) SendOpenedFileMessageWithMentions(chatID int64, f *os.File, caption string, mentions []MentionSpan, replyToMessageID int64, placeholderID int64) (*Message, int, error)
SendOpenedFileMessageWithMentions is SendOpenedFileMessage for a caption that mentions users without a username, as SendFileMessageWithMentions is for a send by path.
The chat shows the file under the base of the name it was opened by, which for SendRoots.Open is the path the caller asked for — a link's own name, not its target's.
func (*Client) SendPhotoMessage ¶
func (c *Client) SendPhotoMessage(chatID int64, path, caption string, replyToMessageID int64, placeholderID int64) (*Message, error)
SendPhotoMessage uploads a local image and sends it as a photo, so it renders inline in the chat rather than as a file attachment. Images above photoSizeLimit must be sent with SendFileMessage instead.
placeholderID names the local echo to swap, as in SendFileMessage.
func (*Client) SendPhotoMessageWithMentions ¶ added in v0.0.28
func (c *Client) SendPhotoMessageWithMentions(chatID int64, path, caption string, mentions []MentionSpan, replyToMessageID int64, placeholderID int64) (*Message, int, error)
SendPhotoMessageWithMentions is SendPhotoMessage for a caption that mentions users without a username (see MentionSpan). Dropped mentions are counted as in SendTextMessageWithMentions.
func (*Client) SendRoots ¶ added in v0.0.18
SendRoots is the set of directories a remote caller may send a file from — see config.Config.SendRoots. The MCP and REST servers make their SendRoots from it when they start; the TUI does not use it, because there the person choosing the file is the person running the process.
func (*Client) SendTextMessage ¶
func (c *Client) SendTextMessage(chatID int64, text string, replyToMessageID, placeholderID int64) (*Message, error)
SendTextMessage sends a plain text message, optionally as a reply.
placeholderID is the ID of the local echo the caller already put in the thread, or 0 for callers that draw nothing (the REST and MCP servers). It is handed straight back on the success message so the thread knows which row the confirmed message replaces.
func (*Client) SendTextMessageWithMentions ¶ added in v0.0.28
func (c *Client) SendTextMessageWithMentions(chatID int64, text string, mentions []MentionSpan, replyToMessageID, placeholderID int64) (*Message, int, error)
SendTextMessageWithMentions is SendTextMessage for a draft that mentions users without a username (see MentionSpan). It also reports how many of the mentions were dropped and went out as plain text: the message itself is sent either way, so a drop is not an error, only something the caller may want to tell the user. The count is 0 whenever err is set.
func (*Client) SetPinned ¶
SetPinned pins a message, or unpins it.
Silent, always. Pinning normally posts a service message into the chat announcing it — "X pinned a message" — and a client whose pin key also writes a line into everybody's history is a key people learn not to press. The pin itself is what was asked for; the announcement is not.
func (*Client) SetReaction ¶
SetReaction puts your reaction on a message, or takes it off.
An empty emoji REMOVES. Telegram models a reaction the same way: the request carries a list, and an empty list means "none of them are mine any more" — there is no separate removal call, and inventing one here would be two names for one request.
One reaction at a time, which is what a non-premium account is allowed. The request would take several; sending several to an account that cannot have them fails the whole call, and failing at the far end of a round trip is a worse way to learn about a limit than not offering it.
func (*Client) Start ¶
Start begins authentication and update delivery after all callbacks and update handlers have been registered.
func (*Client) StartUpload ¶ added in v0.0.21
StartUpload begins uploading path so that a send of it later has nothing left to wait for. Calling it for a file that is already uploading, or is uploaded and unsent, does nothing.
func (*Client) UnreadMentions ¶ added in v0.0.26
UnreadMentions lists the IDs of a chat's unread mentions, oldest first, at most limit of them.
func (*Client) ViewMessages ¶
ViewMessages marks messages as read, and on success announces it with ChatMarkedReadMsg. The server's own receipt for this session's read does not reliably come back, so without the announcement the chat being read kept its unread badge. It is sent from the client, not from a caller, so every in-process caller gets it without having to remember. The REST and MCP servers are separate binaries that register no message sink, so there it goes nowhere.
func (*Client) WaitReady ¶
func (c *Client) WaitReady()
WaitReady blocks until the client is authorized and ready.
func (*Client) WarmPeer ¶ added in v0.0.21
WarmPeer resolves chatID in the peers manager in the background, so a cache miss (which costs a users.getUsers/channels.getChannels round trip) is paid when a chat is opened rather than when the first message in it is sent. It is best-effort: the resolution is purely to populate the cache, so any error is dropped rather than surfaced.
type ClientErrorMsg ¶
ClientErrorMsg reports that the Telegram client itself failed, as opposed to a single RPC. Terminal is true when the run loop has exited for good, meaning nothing will arrive until the app reconnects — the session being terminated from another device looks like this.
type ClientWarningMsg ¶
type ClientWarningMsg struct {
Text string
}
ClientWarningMsg reports a permanent, non-fatal degradation of the current run. The client keeps working, but with less than its usual capability, and the user may want to know why.
type Comments ¶
type Comments struct {
// Count is how many comments there are. Zero is a real answer: the
// discussion exists and nobody has used it yet.
Count int32
// ChatID is the linked discussion group, in this client's canonical
// form, or 0 when Telegram did not name it. Without it there is
// nowhere to go, so the row says how many there are and offers no key.
ChatID int64
// Unread is whether anything has been said since this account last
// looked.
Unread bool
}
Comments is the discussion a channel post has, in the group linked to the channel.
A channel is a broadcast: nobody can answer a post in the channel itself. A linked group is where the answers go, and a client that does not say so makes a channel look like a place where nothing can be said back — which is the opposite of what the post's author set up.
type ConnectionState ¶
type ConnectionState int
ConnectionState is the simplified network state.
const ( ConnectionStateConnecting ConnectionState = iota ConnectionStateReady // ConnectionStateDisconnected means the client run loop has exited: // the connection is gone for good and will not recover on its own. // Appended last on purpose — the existing values keep their numbers, // so consumers comparing against them are unaffected. ConnectionStateDisconnected )
type ConnectionStateMsg ¶
type ConnectionStateMsg struct {
State ConnectionState
}
ConnectionStateMsg is sent when the network connection state changes.
type File ¶
File is a downloadable/downloaded file. ID is a registry key (e.g. "doc:123", "photo:456:y", "avatar:-100123").
type FileUpdateMsg ¶
type FileUpdateMsg struct {
File *File
}
FileUpdateMsg is sent when a file download completes.
type FormattedText ¶
type FormattedText struct {
Text string
Entities []*TextEntity
}
FormattedText is text with formatting entities.
func PreviewMarkdown ¶
func PreviewMarkdown(text string) *FormattedText
PreviewMarkdown parses the outgoing markdown subset and returns the FormattedText that would go on the wire.
It is the same parseMarkdown the send path uses, converted through the same entity mapping — so a composer preview built on it cannot drift from what is actually sent. A preview with its own parser is a preview that is right until the day it is not.
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener converts Telegram updates into tea messages and forwards them to the bubbletea program.
func NewListener ¶
NewListener registers update handlers on the client's dispatcher. It must be called before Client.Start; gotd's dispatcher is not safe to mutate once update delivery begins.
type MediaFilter ¶
type MediaFilter int
MediaFilter selects which of a chat's messages a filtered search asks for.
These are Telegram's own server-side indexes, not a scan of loaded history: asking for a chat's pinned messages or its files is one request that returns them however far back they are. Deriving the same lists from the pages this client happens to have loaded would produce a recent-files sample and call it the chat's files.
const ( // MediaFilterPinned is every pinned message, newest first. MediaFilterPinned MediaFilter = iota // MediaFilterFiles is documents: anything sent as a file rather than // as an inline photo. MediaFilterFiles // MediaFilterPhotos is photos and videos. MediaFilterPhotos // MediaFilterLinks is messages containing a URL. MediaFilterLinks )
func (MediaFilter) String ¶
func (f MediaFilter) String() string
String names the filter for error messages and logs.
type MentionSpan ¶ added in v0.0.28
MentionSpan marks a run of the composer's text as a mention of one user.
It is the contract the composer hands over at send time. Offset and Length count RUNES of the text exactly as the user typed it, before any Markdown is parsed; the send path follows the span through marker removal and converts it to the UTF-16 units the wire uses. The composer never has to know whether Markdown is on or what UTF-16 is.
Only a user WITHOUT a username needs a span. A user with one is mentioned as plain "@username" text, which the server recognises on its own, so the composer sends no span for it.
type Message ¶
type Message struct {
ID int64
ChatID int64
SenderID MessageSender
Date int32
EditDate int32
IsOutgoing bool
IsChannelPost bool
IsForwarded bool
// IsPinned is whether this message is one of the chat's pinned ones.
// It is what lets one key toggle: a pin key that cannot tell says
// "pinned" to something already pinned, and the reader has to open the
// rail to find out what it did.
IsPinned bool
// UnreadMention is whether this message names the reader and they have
// not opened it yet: one of the @ marks the phone counts on a chat. Only
// a group's messages carry it; a DM or a channel post never does.
UnreadMention bool
ReplyToMessageID int64
// SendFailed marks a locally echoed message whose send never reached
// the server. It is only ever set on a placeholder — a message this
// client invented so the thread could show the text the instant it was
// typed — and it is what turns that row's pending mark into a failure
// mark. Nothing the server sends ever sets it.
SendFailed bool
Content MessageContent
// Reactions are the emoji tallies on this message, in the order
// Telegram ranks them. Nil when nobody has reacted.
Reactions []*Reaction
// Comments is the discussion thread under a channel post, nil for a
// post with no linked group and for every message that is not one.
Comments *Comments
}
Message is the domain representation of a Telegram message.
type MessageAnimation ¶
type MessageAnimation struct {
Animation *Animation
Caption *FormattedText
}
MessageAnimation is a GIF message.
type MessageAudio ¶
type MessageAudio struct {
Audio *Audio
Caption *FormattedText
}
MessageAudio is an audio (music) message.
type MessageChatAddMembers ¶
type MessageChatAddMembers struct{}
MessageChatAddMembers is a service message about added members.
type MessageChatChangePhoto ¶
type MessageChatChangePhoto struct{}
MessageChatChangePhoto is a service message about a photo change.
type MessageChatChangeTitle ¶
type MessageChatChangeTitle struct {
Title string
}
MessageChatChangeTitle is a service message about a title change.
type MessageChatDeleteMember ¶
type MessageChatDeleteMember struct{}
MessageChatDeleteMember is a service message about a removed member.
type MessageChatJoinByLink ¶
type MessageChatJoinByLink struct{}
MessageChatJoinByLink is a service message about joining via invite link.
type MessageContact ¶
type MessageContact struct {
Contact *Contact
}
MessageContact is a shared contact message.
type MessageContent ¶
type MessageContent interface {
// contains filtered or unexported methods
}
MessageContent is the payload of a message.
type MessageDeletedMsg ¶
MessageDeletedMsg is sent when messages are deleted. ChatId is 0 for non-channel deletions (the update carries no peer).
type MessageDocument ¶
type MessageDocument struct {
Document *Document
Caption *FormattedText
}
MessageDocument is a generic file message.
type MessageEditedMsg ¶
MessageEditedMsg is sent when a message is edited.
type MessageLocation ¶
type MessageLocation struct {
Location *Location
}
MessageLocation is a geo point message.
type MessagePhoto ¶
type MessagePhoto struct {
Photo *Photo
Caption *FormattedText
}
MessagePhoto is a photo message.
type MessagePinMessage ¶
type MessagePinMessage struct{}
MessagePinMessage is a service message about a pinned message.
type MessageSendFailedMsg ¶
MessageSendFailedMsg reports that an outgoing message never reached the server. It names the local placeholder the sender echoed into the thread so that row can be marked failed instead of sitting there pending forever, which would be the client telling a lie it never takes back.
It lives here, next to the success message, because both the app (which surfaces the error text) and the thread (which marks the row) have to see it, and the telegram package is the one they both already import.
type MessageSendSucceededMsg ¶
MessageSendSucceededMsg is sent when a message is successfully sent.
type MessageSender ¶
type MessageSender interface {
// contains filtered or unexported methods
}
MessageSender identifies who sent a message.
type MessageSenderChat ¶
type MessageSenderChat struct {
ChatID int64
}
MessageSenderChat is a message sent on behalf of a chat/channel.
type MessageSenderUser ¶
type MessageSenderUser struct {
UserID int64
}
MessageSenderUser is a message sent by a user.
type MessageSticker ¶
type MessageSticker struct {
Sticker *Sticker
}
MessageSticker is a sticker message.
type MessageText ¶
type MessageText struct {
Text *FormattedText
// WebPage is the link preview Telegram attached to the text, or nil.
// It hangs off the text rather than replacing it: the preview is a
// second reading of a link the sender already wrote out.
WebPage *WebPage
}
MessageText is a plain text message.
type MessageUnsupported ¶
type MessageUnsupported struct {
Type string
}
MessageUnsupported is anything we don't map explicitly.
type MessageVideo ¶
type MessageVideo struct {
Video *Video
Caption *FormattedText
}
MessageVideo is a video message.
type MessageVideoNote ¶
type MessageVideoNote struct {
VideoNote *VideoNote
}
MessageVideoNote is a round video message.
type MessageVoiceNote ¶
type MessageVoiceNote struct {
VoiceNote *VoiceNote
Caption *FormattedText
}
MessageVoiceNote is a voice message.
type NewMessageMsg ¶
type NewMessageMsg struct {
Message *Message
}
NewMessageMsg is sent when a new message arrives.
type Poll ¶
type Poll struct {
Question string
Options []*PollOption
// TotalVoterCount is how many people have voted, which is not the sum
// of the options: a multiple-choice poll counts one voter once and
// their answers several times.
TotalVoterCount int32
// ResultsKnown is whether the server sent per-option tallies at all.
// A poll that hides its results until it closes sends none, and its
// options must then be drawn without bars — an empty bar is a result,
// not the absence of one.
ResultsKnown bool
IsAnonymous bool
IsClosed bool
MultipleChoice bool
IsQuiz bool
// CloseDate is the unix time the poll closes, 0 when it has no
// scheduled end.
CloseDate int32
}
Poll is a poll: its question, its answers, and whatever tallies the server sent with them.
type PollOption ¶
type PollOption struct {
Text string
VoterCount int32
// Percent is this option's share of the vote, apportioned by largest
// remainder so that the options of a poll sum to exactly 100.
Percent int32
// Chosen is whether the local user picked this option. Correct is
// whether a quiz counts it as the right answer — set only once the
// user has answered, since that is when Telegram sends it.
Chosen bool
Correct bool
}
PollOption is one answer of a poll.
type QRLoginOptions ¶
type QRLoginOptions struct {
// ShowQRCode is called whenever Telegram issues or refreshes a QR token.
ShowQRCode func(context.Context, QRLoginToken) error
// PasswordPrompt is called if the account requires 2FA. retry is true
// after an empty or invalid password. The returned byte slice is consumed
// and wiped before the function returns.
PasswordPrompt func(ctx context.Context, retry bool) ([]byte, error)
}
QRLoginOptions supplies the interactive parts of QR authentication.
type QRLoginToken ¶
QRLoginToken is a short-lived Telegram login token to render as a QR code.
type Reaction ¶
type Reaction struct {
// Emoji is the reaction's emoticon, empty for a custom one.
Emoji string
// CustomEmojiID identifies a custom emoji reaction, whose artwork is
// a document this client does not fetch; 0 for a standard reaction.
// A chip drawn from it says a reaction exists and admits it cannot
// show which, rather than substituting an emoji nobody sent.
CustomEmojiID int64
Count int32
// Chosen is whether the local user is one of the reactors. Telegram
// omits it from the copies of a message it sends to everyone (the
// "min" form), so a false here can mean "not known".
Chosen bool
}
Reaction is one emoji's tally on a message.
type ResyncNeededMsg ¶ added in v0.0.26
type ResyncNeededMsg struct {
Reason string
}
ResyncNeededMsg reports that the update stream has a hole the server will not fill: updates.getDifference answered "too long" (everything pending was discarded and the sync point moved past it), or the stored sync state could not be loaded and this run started from the present. Whatever was on screen before it may now be stale, and only a refetch can say what was missed.
type SendRoots ¶ added in v0.0.28
type SendRoots struct {
// contains filtered or unexported fields
}
SendRoots is the set of directories a remote caller — the MCP send_file tool, POST /api/send-file — may send a file from. The servers make one when they start, from config.Config.PrepareSendRoots, and open every file through it; the TUI has none, because there the person choosing the file is the person running the process.
Every root is opened once, when the server starts, and held open until it stops. Opening a root by name on each send would follow whatever the name pointed at by then: with nested roots A and A/B, anyone who can write to A swaps A/B for a link to ~/.ssh, and a root missing at the start can be created later as a link to anywhere. A held root is the directory it was, wherever its name points afterwards.
A nil SendRoots has no roots and refuses every path.
func OpenSendRoots ¶ added in v0.0.28
OpenSendRoots opens dirs, in the order they are to be searched, and holds them open until Close. Blank entries are skipped. A directory that cannot be opened — above all one that does not exist yet — is skipped too, for as long as the SendRoots lives, and reported in errs so the caller can say so.
Each root answers to its name as written, made absolute, and to where it really was when it was opened, so a root under /tmp on macOS also matches the same path under /private/tmp. The names only choose a root; what is opened is always inside the directory held here.
func (*SendRoots) Close ¶ added in v0.0.28
Close releases the roots. Files already opened through them stay open; Open refuses every path from now on, saying the roots are closed. Closing twice does nothing.
func (*SendRoots) Open ¶ added in v0.0.28
Open opens path for a remote caller's send if it names a regular file inside one of the roots. The send then reads that descriptor (see Client.SendOpenedFileMessage) and never goes back to the path.
That is the point of it. Checking a path and then opening it by name leaves a gap in which anyone who can write to a root swaps the checked file for a symlink to one outside, and the upload reads that instead. Here the check is the open: path is made absolute and clean, taken relative to each root in turn (its directory may be resolved to choose the root, see namesFor, but the open never relies on that), and opened through an os.Root, which follows a link only while it stays inside. Whatever the name points at afterwards, what is sent is what was opened.
With no usable root everything is refused. A link inside a root must be relative and stay inside: os.Root refuses an absolute link even when it names a file in the root.
type SupergroupFullInfo ¶
SupergroupFullInfo holds full info about a supergroup or channel.
type TUIAuthorizer ¶
type TUIAuthorizer struct {
// NonInteractive makes Phone/Code/Password fail immediately with
// ErrLoginRequired instead of waiting for user input (headless mode).
NonInteractive bool
// contains filtered or unexported fields
}
TUIAuthorizer implements gotd's auth.UserAuthenticator on top of the channel-based flow used by the TUI.
func NewTUIAuthorizer ¶
func NewTUIAuthorizer(cfg *config.Config) *TUIAuthorizer
func (*TUIAuthorizer) AcceptTermsOfService ¶
func (a *TUIAuthorizer) AcceptTermsOfService(ctx context.Context, _ tg.HelpTermsOfService) error
AcceptTermsOfService implements auth.UserAuthenticator.
func (*TUIAuthorizer) Close ¶
func (a *TUIAuthorizer) Close()
func (*TUIAuthorizer) Code ¶
func (a *TUIAuthorizer) Code(ctx context.Context, _ *tg.AuthSentCode) (string, error)
Code implements auth.CodeAuthenticator.
func (*TUIAuthorizer) Password ¶
func (a *TUIAuthorizer) Password(ctx context.Context) (string, error)
Password implements auth.UserAuthenticator. The 2FA hint is fetched via account.getPassword through hintFunc, which the client wires up before the auth flow starts.
func (*TUIAuthorizer) Phone ¶
func (a *TUIAuthorizer) Phone(ctx context.Context) (string, error)
Phone implements auth.UserAuthenticator. The config-provided phone is consumed once: if the flow fails and retries, the TUI is asked instead of reusing a possibly wrong number.
func (*TUIAuthorizer) SetErrorCallback ¶
func (a *TUIAuthorizer) SetErrorCallback(cb func(error))
SetErrorCallback sets the callback for fatal auth errors (shown in the TUI).
func (*TUIAuthorizer) SetStateCallback ¶
func (a *TUIAuthorizer) SetStateCallback(cb AuthStateCallback)
SetStateCallback sets the callback for auth state changes.
func (*TUIAuthorizer) SubmitCode ¶
func (a *TUIAuthorizer) SubmitCode(code string)
func (*TUIAuthorizer) SubmitPassword ¶
func (a *TUIAuthorizer) SubmitPassword(password string)
func (*TUIAuthorizer) SubmitPhone ¶
func (a *TUIAuthorizer) SubmitPhone(phone string)
type TextEntity ¶
type TextEntity struct {
Offset int32
Length int32
Type TextEntityType
}
TextEntity is a formatting span. Offset and Length are RUNE indices into the owning FormattedText.Text, already converted from the UTF-16 code units Telegram sends — see formattedTextFromTG. Consumers may slice []rune with them directly.
type TextEntityType ¶
type TextEntityType interface {
// contains filtered or unexported methods
}
TextEntityType classifies a formatting span.
type TextEntityTypeBlockQuote ¶
type TextEntityTypeBlockQuote struct{}
type TextEntityTypeBold ¶
type TextEntityTypeBold struct{}
type TextEntityTypeBotCommand ¶
type TextEntityTypeBotCommand struct{}
type TextEntityTypeCode ¶
type TextEntityTypeCode struct{}
type TextEntityTypeEmailAddress ¶
type TextEntityTypeEmailAddress struct{}
type TextEntityTypeHashtag ¶
type TextEntityTypeHashtag struct{}
type TextEntityTypeItalic ¶
type TextEntityTypeItalic struct{}
type TextEntityTypeMention ¶
type TextEntityTypeMention struct{}
type TextEntityTypeMentionName ¶
type TextEntityTypeMentionName struct {
UserID int64
}
type TextEntityTypePre ¶
type TextEntityTypePre struct{}
type TextEntityTypePreCode ¶
type TextEntityTypePreCode struct {
Language string
}
type TextEntityTypeSpoiler ¶
type TextEntityTypeSpoiler struct{}
type TextEntityTypeStrikethrough ¶
type TextEntityTypeStrikethrough struct{}
type TextEntityTypeTextURL ¶
type TextEntityTypeTextURL struct {
URL string
}
type TextEntityTypeURL ¶
type TextEntityTypeURL struct{}
type TextEntityTypeUnderline ¶
type TextEntityTypeUnderline struct{}
type TmeLink ¶ added in v0.0.24
type TmeLink struct {
// Username is the public @name, lower-cased and without the @.
// Telegram usernames are case-insensitive and the resolver only
// accepts the lower-case spelling, so a link written /Telegram and one
// written /telegram must not be two different destinations.
Username string
// ChatID is the canonical TDLib-style chat ID, set only for a
// t.me/c/<id>/… link.
ChatID int64
// MessageID is the message to open the chat AT, or 0 for the newest.
MessageID int64
}
TmeLink is a t.me link that means "go here", already broken into the parts a navigation needs.
Exactly one of Username and ChatID is set: a public link names a username that still has to be resolved over the network, and a private-channel link (t.me/c/…) carries the ID outright and needs no resolution at all. MessageID is 0 for a link to the chat itself.
func ParseTmeLink ¶ added in v0.0.24
ParseTmeLink reads a URI as a Telegram navigation link.
It reports false for everything it is not certain about, and that is the safe direction: a link this refuses still opens, in the browser, exactly as it did before. A link it wrongly accepts would open the WRONG PLACE inside the reader's own account, silently, which is not a failure mode a link cursor is allowed to have.
Refused on purpose, each because following it would not be navigation:
- invite links, /+hash and /joinchat/hash — following one JOINS;
- the action links in [tmeNotNavigation];
- tg:// deeplinks. The scheme carries a dozen verbs (resolve, join, proxy, addstickers, settings) and picking off the one that navigates would leave the rest going to an opener that, on a machine with no Telegram client installed, has no handler for them either. Reading the whole scheme is a bigger feature than this one;
- anything carrying a query string or a fragment. ?start= is a bot deep link, ?comment= names a comment and ?single picks one photo out of an album: each is a modifier this client does not implement, and dropping it silently would go somewhere the link did not say.
A third path segment is refused too. t.me/<chat>/<topic>/<id> is a forum topic, and while the message is reachable, this client has no topic surface to land the reader on — so the browser keeps it until it does.
type UploadProgressMsg ¶ added in v0.0.21
type UploadProgressMsg struct {
Path string
Generation uint64
Uploaded int64
Total int64
Failed bool
}
UploadProgressMsg reports how far an eager attachment upload has got, so the composer's attachment chip can show it. Path is the key the composer knows the file by — the same path it was attached from.
Failed says the upload ended without producing anything. It carries no numbers: the chip drops the percentage rather than freezing it, because the send that follows will upload the file again itself and report its own failure if that fails too.
Generation says which attempt is reporting. The same path can be uploaded twice — attach, discard, attach the same file again — and the abandoned attempt's callbacks are still arriving when the new one starts; the path alone cannot tell them apart. It rises with every upload started, so the consumer can drop anything older than what it is already showing.
type User ¶
type User struct {
ID int64
FirstName string
LastName string
Username string
PhoneNumber string
IsBot bool
Status UserStatus
}
User is the domain representation of a Telegram user.
func LoginWithQR ¶
LoginWithQR authorizes cfg.Storage.SessionFile by scanning a QR code in an already authorized Telegram app. Expired QR tokens are refreshed by gotd.
type UserStatus ¶
type UserStatus interface {
// contains filtered or unexported methods
}
UserStatus describes last-seen state.
type UserStatusEmpty ¶
type UserStatusEmpty struct{}
type UserStatusLastMonth ¶
type UserStatusLastMonth struct{}
type UserStatusLastWeek ¶
type UserStatusLastWeek struct{}
type UserStatusOffline ¶
type UserStatusOffline struct {
WasOnline int32
}
type UserStatusOnline ¶
type UserStatusOnline struct {
Expires int32
}
type UserStatusRecently ¶
type UserStatusRecently struct{}
type Video ¶
type Video struct {
FileName string
Duration int32
Width int
Height int
File *File
Thumbnail *File
}
Video is a video file.