Package-Level Type Names (total 17, in which 13 are exported)
/* sort exporteds by: | */
Client represents a MTProto client to Telegram. // immutable Client config. // immutablecancelcontext.CancelFunccfg*manager.AtomicConfig // immutableconnclientConn // immutableconnMuxsync.MutexconnsCounteratomic.Int64 Connection factory fields. // immutable Client context. Will be canceled by Run on exit. // immutable Telegram device information. // immutable DCList state.
Domain list (for websocket) // immutable invoker implements tg.Invoker on top of Client and mw. // immutable // immutablemigrationchan struct{} Migration state. // immutable mw is list of middlewares used in invoker, can be blank. // immutable Denotes that no update mode is enabled. // immutable MTProto options. // immutable Wrappers for external world, like logs or PRNG. // immutable Ready signal channel, sends signal when client connection is ready.
Resets on reconnect. // immutable // immutable Restart signal channel. // immutable Connection state. Guarded by connMux.sessionsmap[int]*pool.SyncSessionsessionsMuxsync.Mutex Session storage. // immutable, nillable Connections to non-primary DC.subConnsMuxsync.Mutex Denotes to use Test DCs. // immutable tg provides RPC calls via Client. Uses invoker below. // immutable Tracing. Telegram updates handler. // immutable API returns *tg.Client for calling raw MTProto methods. Auth returns auth client. Config returns current config. DC creates new multi-connection invoker to given DC. Invoke invokes raw MTProto RPC method. It sends input and decodes result
into output. MediaOnly creates new multi-connection invoker to given DC ID.
It connects to MediaOnly DCs. MigrateTo forces client to migrate to another DC. Ping sends low level ping request to Telegram server. Pool creates new multi-connection invoker to current DC. QR returns QR login helper. RandInt64 returns new random int64 from random source.
Useful helper for places in API where random int is required. Run starts client session and blocks until connection close.
The f callback is called on successful session initialization and Run
will return on f() result.
Context of callback will be canceled if fatal error is detected.
The ctx is used for background operations like updates handling or pools.
See `examples/bg-run` and `contrib/gb` package for classic approach without
explicit callback, with Connect and defer close(). Self returns current user.
You can use tg.User.Bot to check whether current user is bot. SendMessage sends message to peer.
Deprecated: use helpers like message.NewSender.(*Client) asHandler() manager.Handler(*Client) createConn(id int64, mode manager.ConnMode, setup manager.SetupCallback) pool.Conn(*Client) createPool(dc int, max int64, creator func() pool.Conn) (*pool.DC, error)(*Client) createPrimaryConn(setup manager.SetupCallback) pool.Conn(*Client) dc(ctx context.Context, dcID int, max int64, dialer mtproto.Dialer) (*pool.DC, error)(*Client) dcList() dcs.List(*Client) ensureRestart(ctx context.Context) error(*Client) exportAuth(ctx context.Context, dcID int) (*tg.AuthExportedAuthorization, error)(*Client) fetchConfig(ctx context.Context)(*Client) handleUpdates(b *bin.Buffer) error init sets fields which needs explicit initialization, like maps or channels. invokeConn directly invokes RPC call on primary connection without any
additional handling. invokeDirect directly invokes RPC method, automatically handling datacenter redirects.(*Client) invokeMigrate(ctx context.Context, dcID int, input bin.Encoder, output bin.Decoder) error(*Client) invokeSub(ctx context.Context, dc int, input bin.Encoder, output bin.Decoder) error(*Client) isPermanentError(err error) bool(*Client) migrateToDc(ctx context.Context, dcID int) error(*Client) onReady()(*Client) onSession(cfg tg.Config, s mtproto.Session) error(*Client) primaryDC(dc int) mtproto.Dialer(*Client) processUpdates(updates tg.UpdatesClass) error(*Client) reconnectUntilClosed(ctx context.Context) error(*Client) resetReady()(*Client) restoreConnection(ctx context.Context) error(*Client) runUntilRestart(ctx context.Context) error(*Client) saveSession(cfg tg.Config, s mtproto.Session) error transfer exports current authorization and imports it to another DC.
See https://core.telegram.org/api/datacenter#authorization-transfer.(*Client) updateInterceptor(updates ...tg.UpdateClass)
*Client : github.com/gotd/td/tg.Invoker
*Client : github.com/gotd/td/telegram/internal/manager.protoConn
func ClientFromEnvironment(opts Options) (*Client, error)
func NewClient(appID int, appHash string, opt Options) *Client
func RunUntilCanceled(ctx context.Context, client *Client) error
Options of Client. AckBatchSize is limit of MTProto ACK buffer size. AckInterval is maximum time to buffer MTProto ACK.Clockclock.Clock CompressThreshold is a threshold in bytes to determine that message
is large enough to be compressed using GZIP.
If < 0, compression will be disabled.
If == 0, default value will be used. DC ID to connect.
If not provided, 2 will be used by default. DCList is initial list of addresses to connect. Device is device config.
Will be sent with session creation request. DialTimeout is timeout of creating connection. ExchangeTimeout is timeout of every key exchange request. Logger is instance of zap.Logger. No logs by default. MaxRetries is limit of send retries.MessageIDmtproto.MessageIDSource Middlewares list allows wrapping tg.Invoker. Can be useful for metrics,
tracing, etc. Note that order is important, see ExampleMiddleware.
Middlewares are called in order from first to last. MigrationTimeout configures migration timeout. NoUpdates enables no updates mode.
Enabled by default if no UpdateHandler is provided. PublicKeys of telegram.
If not provided, embedded public keys will be used. Random is random source. Defaults to crypto. ReconnectionBackoff configures and returns reconnection backoff object. Resolver to use. RetryInterval is duration between send retries. SessionStorage will be used to load and save session data.
NB: Very sensitive data, save with care. OpenTelemetry. UpdateHandler will be called on received update.(*Options) setDefaults()
func OptionsFromEnvironment(opts Options) (Options, error)
func BotFromEnvironment(ctx context.Context, opts Options, setup func(ctx context.Context, client *Client) error, cb func(ctx context.Context, client *Client) error) error
func ClientFromEnvironment(opts Options) (*Client, error)
func NewClient(appID int, appHash string, opt Options) *Client
func OptionsFromEnvironment(opts Options) (Options, error)
func TestClient(ctx context.Context, opts Options, cb func(ctx context.Context, client *Client) error) error
PublicKey is a Telegram server public key.
SessionStorage is alias of mtproto.SessionStorage.
UpdateHandlerFunc type is an adapter to allow the use of
ordinary function as update handler.
UpdateHandlerFunc(f) is an UpdateHandler that calls f. Handle calls f(ctx, u)
UpdateHandlerFunc : UpdateHandler
Package-Level Functions (total 13, in which 6 are exported)
BotFromEnvironment creates bot client using ClientFromEnvironment
connects to server and authenticates it.
Variables:
BOT_TOKEN — token from BotFather.
ClientFromEnvironment creates client using OptionsFromEnvironment
but does not connect to server.
Variables:
APP_ID: app_id of Telegram app.
APP_HASH: app_hash of Telegram app.
NewClient creates new unstarted client.
OptionsFromEnvironment fills unfilled field in opts parameter
using environment variables.
Variables:
SESSION_FILE: path to session file
SESSION_DIR: path to session directory, if SESSION_FILE is not set
ALL_PROXY, NO_PROXY: see https://pkg.go.dev/golang.org/x/net/proxy#FromEnvironment
RunUntilCanceled is client callback which
locks until client context is canceled.
TestClient creates and authenticates user telegram.Client
using Telegram test server.
chainMiddlewares composes new invoker in such order that first element in
chain is called first, and latest "next" argument will be "invoker".
E.g. we have invoker and two middlewares, so order will be following:
0, 1, (invoker), 1 (after "next"), 0 (after "next").
See TestMiddlewareOrder or ExampleMiddleware.
Package-Level Variables (total 3, in which 1 is exported)
AsFloodWait returns wait duration and true boolean if err is
the "FLOOD_WAIT" error.
Client should wait for that duration before issuing new requests with
same method.
Package-Level Constants (total 6, all are exported)
Available MTProto default server addresses.
See https://my.telegram.org/apps.
Available MTProto default server addresses.
See https://my.telegram.org/apps.
ErrFloodWait is error type of "FLOOD_WAIT" error.
Port is default port used by telegram.
Test-only credentials. Can be used with AddrTest and TestAuth to
test authentication.
Reference:
- https://github.com/telegramdesktop/tdesktop/blob/5f665b8ecb48802cd13cfb48ec834b946459274a/docs/api_credentials.md
Test-only credentials. Can be used with AddrTest and TestAuth to
test authentication.
Reference:
- https://github.com/telegramdesktop/tdesktop/blob/5f665b8ecb48802cd13cfb48ec834b946459274a/docs/api_credentials.md
The pages are generated with Goldsv0.6.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.