Documentation
¶
Index ¶
- func ApplyTdlibParameters(tdjson *TDJSON, clientID int32, tdlibBaseDirectory string, apiID int32, ...) error
- func BuildIdentityLabelFromUser(user User) string
- func ConfigureLogging(tdjson *TDJSON)
- func CreatePrivateChat(tdjson *TDJSON, clientID int32, userID int64) (int64, error)
- func DownloadFile(tdjson *TDJSON, clientID int32, fileID int32, timeout time.Duration) (string, error)
- func EnsureTdlibDirectories(tdlibBaseDirectory string) (string, string, error)
- func FetchChatIdentifiers(tdjson *TDJSON, clientID int32, limit int) ([]int64, error)
- func FetchChatTitle(tdjson *TDJSON, clientID int32, chatID int64) (string, error)
- func FetchUserDisplayName(tdjson *TDJSON, clientID int32, userID int64) (string, error)
- func FetchUserHandle(tdjson *TDJSON, clientID int32, userID int64) (string, error)
- func LogOutSession(tdjson *TDJSON, clientID int32) error
- func MarkMessagesRead(tdjson *TDJSON, clientID int32, chatID int64, messageIDs []int64) error
- func OpenChat(tdjson *TDJSON, clientID int32, chatID int64) error
- func PersistIdentity(configuration config.Config, configPath string, user User) (config.Config, error)
- func ProvideAuthenticationPhoneNumber(tdjson *TDJSON, clientID int32, phoneNumber string) error
- func ReceiveUpdates(tdjson *TDJSON) (string, error)
- func RequireAuthenticatedSession() error
- func ResolveChatIdentifierByUsername(tdjson *TDJSON, clientID int32, username string) (int64, error)
- func ResolveIdentityLabel(configuration config.Config, configPath string) (string, config.Config, error)
- func ResolveUserIdentifierByUsername(tdjson *TDJSON, clientID int32, username string) (int64, error)
- func SendLocalFileMessage(tdjson *TDJSON, clientID int32, chatID int64, path, caption string) (int64, string, error)
- func SendRequestAndWait(tdjson *TDJSON, clientID int32, requestJSON string, extraTag string, ...) (string, error)
- func SendTextMessage(tdjson *TDJSON, clientID int32, chatID int64, text string) (int64, error)
- func SubmitAuthenticationCode(tdjson *TDJSON, clientID int32, code string) error
- func SubmitAuthenticationPassword(tdjson *TDJSON, clientID int32, password string) error
- func WaitForSendCompletion(tdjson *TDJSON, clientID int32, temporaryMessageID int64, ...) error
- func WaitForUpdateType(tdjson *TDJSON, clientID int32, wantedType string, timeout time.Duration) (string, error)
- type ApplyTdlibParametersRequest
- type AuthorizationState
- type ChatHistory
- type ChatInfo
- type Content
- type File
- type FormattedText
- func FormatOutgoingText(tdjson *TDJSON, clientID int32, text string) FormattedText
- func FormatOutgoingTextBestEffort(tdjson *TDJSON, clientID int32, text string) FormattedText
- func ParseMarkdownText(tdjson *TDJSON, clientID int32, text string, version int) (FormattedText, error)
- func ParseMarkdownV1Text(tdjson *TDJSON, clientID int32, text string) (FormattedText, error)
- func ParseMarkdownV2Text(tdjson *TDJSON, clientID int32, text string) (FormattedText, error)
- func ParseOutgoingMarkdownText(tdjson *TDJSON, clientID int32, text string) (FormattedText, error)
- func PlainFormattedText(text string) FormattedText
- type Message
- func FetchChatHistory(tdjson *TDJSON, clientID int32, chatID int64, limit int) ([]Message, error)
- func FetchChatHistorySnapshot(tdjson *TDJSON, clientID int32, chatID int64, limit int) ([]Message, error)
- func FetchUnreadIncoming(tdjson *TDJSON, clientID int32, chatID, lastReadInboxMessageID int64) ([]Message, error)
- type NewMessageUpdate
- type PhotoSize
- type SenderID
- type TDJSON
- type UpdateNewMessage
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyTdlibParameters ¶
func ConfigureLogging ¶
func ConfigureLogging(tdjson *TDJSON)
func CreatePrivateChat ¶
func DownloadFile ¶
func DownloadFile(tdjson *TDJSON, clientID int32, fileID int32, timeout time.Duration) (string, error)
DownloadFile downloads a file by id and blocks until it completes, returning the local path within TDLib's file cache. Uses a synchronous downloadFile so the reply only arrives once the download has finished.
func EnsureTdlibDirectories ¶
func FetchChatIdentifiers ¶
func FetchChatTitle ¶
func FetchUserDisplayName ¶
func FetchUserHandle ¶
FetchUserHandle returns a user's "@username" (the stable handle the agent tier keys allow-list, claims, and contacts on), or "" when the user has no public username. It tolerates both the legacy `username` field and the newer `usernames.active_usernames` shape.
func LogOutSession ¶
func MarkMessagesRead ¶
MarkMessagesRead marks the given messages read (and sends read receipts), so they won't be triaged again.
func PersistIdentity ¶
func ReceiveUpdates ¶
func RequireAuthenticatedSession ¶
func RequireAuthenticatedSession() error
func ResolveIdentityLabel ¶
func SendLocalFileMessage ¶
func SendLocalFileMessage(tdjson *TDJSON, clientID int32, chatID int64, path, caption string) (int64, string, error)
SendLocalFileMessage sends a local file to a chat as the appropriate media type with an optional caption. It returns the temporary message id (the upload runs asynchronously — use WaitForSendCompletion to block until done) and a human-readable label for the media kind.
func SendRequestAndWait ¶
func SendRequestAndWait(tdjson *TDJSON, clientID int32, requestJSON string, extraTag string, timeout time.Duration) (string, error)
SendRequestAndWait sends a request and blocks until the matching reply (by @extra) arrives, the timeout elapses, or the client is closed. The extraTag is suffixed with a per-client sequence number so concurrent callers reusing the same logical tag (e.g. "get-user") never collide on the pending map.
func SendTextMessage ¶
func WaitForSendCompletion ¶
func WaitForSendCompletion(tdjson *TDJSON, clientID int32, temporaryMessageID int64, timeout time.Duration) error
WaitForSendCompletion blocks until the message with the given temporary id finishes uploading/sending (or fails). Needed for one-shot commands so the process doesn't exit and cancel the upload before it completes.
Types ¶
type ApplyTdlibParametersRequest ¶
type ApplyTdlibParametersRequest struct {
Type string `json:"@type"`
DatabaseDirectory string `json:"database_directory"`
FilesDirectory string `json:"files_directory"`
UseFileDatabase bool `json:"use_file_database"`
UseChatInfoDatabase bool `json:"use_chat_info_database"`
UseMessageDatabase bool `json:"use_message_database"`
UseSecretChats bool `json:"use_secret_chats"`
ApiID int32 `json:"api_id"`
ApiHash string `json:"api_hash"`
SystemLanguageCode string `json:"system_language_code"`
DeviceModel string `json:"device_model"`
SystemVersion string `json:"system_version"`
ApplicationVersion string `json:"application_version"`
EnableStorageOptimizer bool `json:"enable_storage_optimizer"`
}
type AuthorizationState ¶
type AuthorizationState string
const ( AuthStateUnknown AuthorizationState = "unknown" AuthStateWaitTdlibParameters AuthorizationState = "authorizationStateWaitTdlibParameters" AuthStateWaitPhoneNumber AuthorizationState = "authorizationStateWaitPhoneNumber" AuthStateWaitCode AuthorizationState = "authorizationStateWaitCode" AuthStateWaitPassword AuthorizationState = "authorizationStateWaitPassword" AuthStateReady AuthorizationState = "authorizationStateReady" AuthStateLoggingOut AuthorizationState = "authorizationStateLoggingOut" AuthStateClosing AuthorizationState = "authorizationStateClosing" AuthStateClosed AuthorizationState = "authorizationStateClosed" )
func FetchAuthorizationState ¶
func FetchAuthorizationState(tdjson *TDJSON, clientID int32) (AuthorizationState, error)
func ParseUpdateAuthorizationState ¶
func ParseUpdateAuthorizationState(updateJSON string) (AuthorizationState, bool)
ParseUpdateAuthorizationState returns the new authorization state from an updateAuthorizationState event (false for any other update), so a long-running client can react when the session is logged out or closed remotely.
type ChatHistory ¶
type ChatHistory struct {
Messages []Message `json:"messages"`
}
type ChatInfo ¶
type ChatInfo struct {
ID int64
Title string
TypeName string // "private" | "group" | "other"
UserID int64 // for private chats: the other user
UnreadCount int
LastReadInboxMessageID int64
}
ChatInfo carries the unread state we need to triage a chat.
type Content ¶
type Content struct {
Type string `json:"@type"`
Text struct {
Text string `json:"text"`
} `json:"text"`
Caption struct {
Text string `json:"text"`
} `json:"caption"`
Photo *struct {
Sizes []PhotoSize `json:"sizes"`
} `json:"photo"`
Video *struct {
FileName string `json:"file_name"`
Video File `json:"video"`
} `json:"video"`
Audio *struct {
FileName string `json:"file_name"`
Audio File `json:"audio"`
} `json:"audio"`
Document *struct {
FileName string `json:"file_name"`
Document File `json:"document"`
} `json:"document"`
Animation *struct {
FileName string `json:"file_name"`
Animation File `json:"animation"`
} `json:"animation"`
VoiceNote *struct {
Voice File `json:"voice"`
} `json:"voice_note"`
VideoNote *struct {
Video File `json:"video"`
} `json:"video_note"`
Sticker *struct {
Sticker File `json:"sticker"`
} `json:"sticker"`
}
func (Content) CaptionOrText ¶
CaptionOrText returns the caption (for media) or text (for text messages).
type File ¶
type File struct {
ID int32 `json:"id"`
Size int64 `json:"size"`
Local struct {
Path string `json:"path"`
IsDownloadingCompleted bool `json:"is_downloading_completed"`
} `json:"local"`
Remote struct {
UniqueID string `json:"unique_id"`
} `json:"remote"`
}
File mirrors the TDLib "file" object (only the fields we use).
type FormattedText ¶
type FormattedText struct {
Type string `json:"@type"`
Text string `json:"text"`
Entities []any `json:"entities,omitempty"`
}
func FormatOutgoingText ¶
func FormatOutgoingText(tdjson *TDJSON, clientID int32, text string) FormattedText
func FormatOutgoingTextBestEffort ¶
func FormatOutgoingTextBestEffort(tdjson *TDJSON, clientID int32, text string) FormattedText
func ParseMarkdownText ¶
func ParseMarkdownV1Text ¶
func ParseMarkdownV1Text(tdjson *TDJSON, clientID int32, text string) (FormattedText, error)
func ParseMarkdownV2Text ¶
func ParseMarkdownV2Text(tdjson *TDJSON, clientID int32, text string) (FormattedText, error)
func ParseOutgoingMarkdownText ¶
func ParseOutgoingMarkdownText(tdjson *TDJSON, clientID int32, text string) (FormattedText, error)
func PlainFormattedText ¶
func PlainFormattedText(text string) FormattedText
type Message ¶
type Message struct {
ID int64 `json:"id"`
ChatID int64 `json:"chat_id"`
Date int64 `json:"date"`
IsOutgoing bool `json:"is_outgoing"`
SenderID SenderID `json:"sender_id"`
Content Content `json:"content"`
}
func FetchChatHistory ¶
func FetchUnreadIncoming ¶
func FetchUnreadIncoming(tdjson *TDJSON, clientID int32, chatID, lastReadInboxMessageID int64) ([]Message, error)
FetchUnreadIncoming returns the unread incoming messages in a chat (those with id > lastReadInboxMessageID), paginating back past any newer outgoing messages (e.g. an auto-reply) so they aren't missed. Newest first.
type NewMessageUpdate ¶
type NewMessageUpdate struct {
Type string `json:"@type"`
Message struct {
ID int64 `json:"id"`
ChatID int64 `json:"chat_id"`
Content struct {
Type string `json:"@type"`
Text struct {
Text string `json:"text"`
} `json:"text"`
} `json:"content"`
} `json:"message"`
}
func ParseNewMessage ¶
func ParseNewMessage(updateJSON string) (*NewMessageUpdate, bool)
type PhotoSize ¶
type PhotoSize struct {
Type string `json:"type"`
Photo File `json:"photo"`
Width int `json:"width"`
Height int `json:"height"`
}
PhotoSize mirrors the TDLib "photoSize" object.
type UpdateNewMessage ¶
func ParseUpdateNewMessage ¶
func ParseUpdateNewMessage(updateJSON string) (*UpdateNewMessage, bool)