telegram

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultFloodWaitLimit = 30 * time.Second
	MaxFloodWaitLimit     = 5 * time.Minute
)

Variables

View Source
var (
	ErrPendingAuthExpired = errors.New("pending auth expired")
	ErrPendingAuthInvalid = errors.New("pending auth state is invalid")
)

Functions

func ConfirmedMutationOutputError

func ConfirmedMutationOutputError(result MutationResult, err error) error

func ParseAPIID

func ParseAPIID(value string) (int64, error)

func ValidateFloodWaitLimit

func ValidateFloodWaitLimit(limit time.Duration) error

Types

type Account

type Account struct {
	ID        int64  `json:"id"`
	Username  string `json:"username,omitempty"`
	FirstName string `json:"first_name,omitempty"`
	LastName  string `json:"last_name,omitempty"`
	Phone     string `json:"phone,omitempty"`
}

type App

type App struct {
	Config         config.Config
	Profile        string
	Paths          config.Paths
	Secrets        secrets.Store
	FloodWaitLimit time.Duration
	In             io.Reader
	Out            io.Writer
	Err            io.Writer
}

func (App) AuthComplete

func (a App) AuthComplete(ctx context.Context, code, password string) (AuthStatus, error)

func (App) AuthStart

func (a App) AuthStart(ctx context.Context, phone string) (AuthStartStatus, error)

func (App) Chats

func (a App) Chats(ctx context.Context, opts ChatOptions) (ChatPage, error)

func (App) DeleteMessage

func (a App) DeleteMessage(ctx context.Context, peerToken string, msgID int, scope DeleteScope) (MutationResult, error)

func (App) DownloadMedia

func (a App) DownloadMedia(ctx context.Context, opts MediaDownloadOptions) (MediaDownloadResult, error)

func (App) Edit

func (a App) Edit(ctx context.Context, peerToken string, msgID int, text string) (MutationResult, error)

func (App) History

func (a App) History(ctx context.Context, peerToken string, limit int) (MessagePage, error)

func (App) Inbox

func (a App) Inbox(ctx context.Context, opts ChatOptions, mode string) (ChatPage, error)

func (App) Login

func (a App) Login(ctx context.Context, opts LoginOptions) (AuthStatus, error)

func (App) LogoutRemote

func (a App) LogoutRemote(ctx context.Context) error

func (App) PeerInfo

func (a App) PeerInfo(token string) PeerInfo

func (App) PreviewMutation

func (a App) PreviewMutation(ctx context.Context, action, peerToken string, msgID int, scope DeleteScope) (MutationPreview, error)

func (App) React

func (a App) React(ctx context.Context, peerToken string, msgID int, emoji string) (MutationResult, error)

func (App) Read

func (a App) Read(ctx context.Context, opts ReadOptions) (MessagePage, error)

func (App) ResetLocalAuth

func (a App) ResetLocalAuth(ctx context.Context) error

func (App) Run

func (a App) Run(ctx context.Context, fn func(ctx context.Context, c *telegram.Client) error) error

func (App) Search

func (a App) Search(ctx context.Context, opts SearchOptions) (MessagePage, error)

func (App) Send

func (a App) Send(ctx context.Context, peerToken, text string, replyTo int) (MutationResult, error)

func (App) SetAPIHash

func (a App) SetAPIHash(ctx context.Context, hash string) error

func (App) Status

func (a App) Status(ctx context.Context) (AuthStatus, error)

type AuthStartStatus

type AuthStartStatus struct {
	Profile           string `json:"profile"`
	Phone             string `json:"phone"`
	CodeSent          bool   `json:"code_sent"`
	CodeType          string `json:"code_type,omitempty"`
	TimeoutSeconds    int    `json:"timeout_seconds,omitempty"`
	AlreadyAuthorized bool   `json:"already_authorized,omitempty"`
}

type AuthStatus

type AuthStatus struct {
	Profile    string   `json:"profile"`
	Authorized bool     `json:"authorized"`
	Account    *Account `json:"account,omitempty"`
}

type Chat

type Chat struct {
	Ref                 string `json:"ref"`
	Kind                string `json:"kind"`
	ID                  int64  `json:"id"`
	Title               string `json:"title"`
	Username            string `json:"username,omitempty"`
	UnreadCount         int    `json:"unread_count"`
	UnreadMentionsCount int    `json:"unread_mentions_count,omitempty"`
	TopMessageID        int    `json:"top_message_id,omitempty"`
	LastMessageDate     string `json:"last_message_date,omitempty"`
	LastMessagePreview  string `json:"last_message_preview,omitempty"`
}

type ChatOptions

type ChatOptions struct {
	Limit  int
	Cursor string
}

type ChatPage

type ChatPage struct {
	Items   []Chat
	Receipt RetrievalReceipt
}

type DeleteScope

type DeleteScope string
const (
	DeleteScopeForMe  DeleteScope = "for_me"
	DeleteScopeRevoke DeleteScope = "revoke"
)

type LoginOptions

type LoginOptions struct {
	Phone          string
	Code           string
	Password       string
	NonInteractive bool
}

type MediaDownloadOptions

type MediaDownloadOptions struct {
	Peer      string
	MessageID int
	OutDir    string
}

type MediaDownloadResult

type MediaDownloadResult struct {
	OK           bool   `json:"ok"`
	PeerRef      string `json:"peer_ref"`
	MessageID    int    `json:"message_id"`
	Path         string `json:"path"`
	Bytes        int64  `json:"bytes"`
	MediaType    string `json:"media_type"`
	MimeType     string `json:"mime_type,omitempty"`
	FileName     string `json:"file_name"`
	StorageType  string `json:"storage_type,omitempty"`
	DownloadedAt string `json:"downloaded_at"`
}

type Message

type Message struct {
	ID                   int             `json:"id"`
	Date                 string          `json:"date,omitempty"`
	Text                 string          `json:"text,omitempty"`
	Outgoing             bool            `json:"outgoing"`
	Post                 bool            `json:"post,omitempty"`
	Media                string          `json:"media,omitempty"`
	Service              string          `json:"service,omitempty"`
	SourcePeerRef        string          `json:"source_peer_ref,omitempty"`
	SourcePeerLabel      string          `json:"source_peer_label,omitempty"`
	SenderPeerRef        string          `json:"sender_peer_ref,omitempty"`
	SenderLabel          string          `json:"sender_label,omitempty"`
	ReplyToMessageID     int             `json:"reply_to_message_id,omitempty"`
	ThreadID             int             `json:"thread_id,omitempty"`
	ForumTopic           bool            `json:"forum_topic,omitempty"`
	ForwardedFromPeerRef string          `json:"forwarded_from_peer_ref,omitempty"`
	ForwardedFromLabel   string          `json:"forwarded_from_label,omitempty"`
	ForwardedDate        string          `json:"forwarded_date,omitempty"`
	EditDate             string          `json:"edit_date,omitempty"`
	GroupedID            int64           `json:"grouped_id,omitempty"`
	Entities             []MessageEntity `json:"entities,omitempty"`
}

type MessageEntity

type MessageEntity struct {
	Type   string `json:"type"`
	Offset int    `json:"offset"`
	Length int    `json:"length"`
}

type MessagePage

type MessagePage struct {
	Items   []Message
	Receipt RetrievalReceipt
}

type MutationError

type MutationError struct {
	Outcome              MutationOutcome
	RetrySafe            bool
	ReconciliationHandle string
	Err                  error
}

func (MutationError) Error

func (e MutationError) Error() string

func (MutationError) MutationOutcomeCode

func (e MutationError) MutationOutcomeCode() string

func (MutationError) MutationReconciliationHandle

func (e MutationError) MutationReconciliationHandle() string

func (MutationError) MutationRetrySafe

func (e MutationError) MutationRetrySafe() bool

func (MutationError) Unwrap

func (e MutationError) Unwrap() error

type MutationOutcome

type MutationOutcome string
const (
	MutationConfirmed      MutationOutcome = "confirmed"
	MutationRejected       MutationOutcome = "rejected"
	MutationOutcomeUnknown MutationOutcome = "outcome_unknown"
)

type MutationPreview

type MutationPreview struct {
	OK        bool        `json:"ok"`
	DryRun    bool        `json:"dry_run"`
	Action    string      `json:"action"`
	PeerRef   string      `json:"peer_ref"`
	MessageID int         `json:"message_id,omitempty"`
	Scope     DeleteScope `json:"scope,omitempty"`
	Timestamp string      `json:"timestamp"`
}

type MutationResult

type MutationResult struct {
	OK                   bool            `json:"ok"`
	Outcome              MutationOutcome `json:"outcome"`
	RetrySafe            bool            `json:"retry_safe"`
	Action               string          `json:"action"`
	PeerRef              string          `json:"peer_ref"`
	MessageID            int             `json:"message_id,omitempty"`
	MessageIDs           []int           `json:"message_ids,omitempty"`
	ReconciliationHandle string          `json:"reconciliation_handle"`
	Timestamp            string          `json:"timestamp"`
}

type PeerInfo

type PeerInfo struct {
	Ref      string `json:"ref"`
	Kind     string `json:"kind,omitempty"`
	Title    string `json:"title,omitempty"`
	Username string `json:"username,omitempty"`
}

type ReadOptions

type ReadOptions struct {
	Peer          string
	Limit         int
	Since         time.Time
	Until         time.Time
	AfterID       int
	BeforeID      int
	AroundID      int
	Chronological bool
	Cursor        string
}

type RetrievalReceipt

type RetrievalReceipt struct {
	RequestedCount int    `json:"requested_count"`
	ReturnedCount  int    `json:"returned_count"`
	Complete       *bool  `json:"complete"`
	Truncated      bool   `json:"truncated"`
	NextCursor     string `json:"next_cursor,omitempty"`
	InputCursor    string `json:"input_cursor,omitempty"`
	ServerTotal    *int   `json:"server_total,omitempty"`
	Pages          int    `json:"pages"`
}

type SearchOptions

type SearchOptions struct {
	Query  string
	Peer   string
	Limit  int
	Cursor string
}

Jump to

Keyboard shortcuts

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