Documentation
¶
Overview ¶
Package td implements the tdlib network transport over gotd/td's telegram.Client. It constructs the client from tdlib options, persists the MTProto session through an injected store, forwards raw updates to an injected sink, and manages the blocking Run lifecycle. It does not own the authorization state machine (RFC 0006) or update reconciliation (RFC 0013).
The package is self-contained: it depends on gotd/td and small local interfaces (Session, UpdateSink), never on the root tdlib package, so the root package can import it without an import cycle.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AsFloodWait ¶
AsFloodWait returns the back-off duration and true if err is a FLOOD_WAIT or FLOOD_PREMIUM_WAIT error.
func IsMigrate ¶
IsMigrate reports whether err is a _MIGRATE family error (PHONE_MIGRATE, NETWORK_MIGRATE, FILE_MIGRATE, etc.). gotd/td handles DC migration transparently; this helper exists for logging and diagnostics only.
func IsPermanent ¶
IsPermanent reports whether err should terminate the Run loop rather than trigger a reconnect.
func IsUnauthorized ¶
IsUnauthorized reports whether err is a 401-class auth error. Callers use it to trigger an auth state transition (RFC 0006).
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is a live gotd/td connection implementing the tdlib transport. It is created with Build and driven with Run; all other methods are safe to call concurrently and block on readiness as needed.
func Build ¶
Build constructs a Conn from opts but does not start the network connection. Call Run to start the connection lifecycle.
func (*Conn) Close ¶
Close releases transport resources. Connection teardown is owned by Run via context cancellation, so there is nothing extra to release here; Close exists to satisfy the transport contract and is safe to call any time.
type Options ¶
type Options struct {
// AppID and AppHash are the Telegram application credentials (mandatory).
AppID int
AppHash string
// DeviceModel, SystemVersion and AppVersion are reported in initConnection.
DeviceModel string
SystemVersion string
AppVersion string
// TestDC selects the Telegram test DC list when true.
TestDC bool
// Session persists the MTProto session blob (mandatory).
Session Session
// Updates receives raw update batches from the network layer (mandatory).
Updates UpdateSink
// Logger is the tdlib logger; no-op when nil. gotd/td's own internal logging
// is left disabled.
Logger log.Logger
// TracerProvider instruments RPC calls; defaults to the OTEL no-op provider.
TracerProvider trace.TracerProvider
// Middlewares wrap every outgoing RPC, e.g. a flood-wait waiter.
Middlewares []telegram.Middleware
// OnSelfSuccess and OnSelfError are the auth seam (RFC 0006); they map
// directly onto the telegram.Options callbacks of the same name.
OnSelfSuccess func(self *tg.User)
OnSelfError func(ctx context.Context, err error) error
}
Options configures a Conn.
type Session ¶
type Session interface {
Load(ctx context.Context) ([]byte, error)
Store(ctx context.Context, data []byte) error
}
Session is the minimal MTProto-session blob store Conn needs. It is satisfied by an adapter in the root package over the SQLite key-value store. Load returns (nil, nil) when no session has been persisted yet.
type UpdateSink ¶
type UpdateSink interface {
Handle(ctx context.Context, u tg.UpdatesClass) error
}
UpdateSink receives raw, unreconciled update batches from the network layer. Its signature mirrors telegram.UpdateHandler; the reconciliation engine (RFC 0013) implements it. Handle must not block.