{"id":13610094,"url":"https://github.com/gotd/td","last_synced_at":"2026-02-07T19:19:43.706Z","repository":{"id":36963006,"uuid":"312623308","full_name":"gotd/td","owner":"gotd","description":"Telegram client, in Go. (MTProto API)","archived":false,"fork":false,"pushed_at":"2025-04-08T07:38:01.000Z","size":56987,"stargazers_count":1712,"open_issues_count":71,"forks_count":148,"subscribers_count":27,"default_branch":"main","last_synced_at":"2025-04-10T18:42:20.906Z","etag":null,"topics":["bot-api","go","golang","mtproto","tdlib","telegram","telegram-api","telegram-bot"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gotd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":".github/SUPPORT.md","governance":null,"roadmap":"ROADMAP.md","authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"polar":"gotd"}},"created_at":"2020-11-13T16:10:09.000Z","updated_at":"2025-04-10T16:11:43.000Z","dependencies_parsed_at":"2023-09-22T22:13:24.195Z","dependency_job_id":"4de6c8b7-5e56-45b9-a7ad-83bffd165e8d","html_url":"https://github.com/gotd/td","commit_stats":{"total_commits":2702,"total_committers":28,"mean_commits":96.5,"dds":0.6780162842339008,"last_synced_commit":"1bf78b6f6d86de0b735de9a5dd365d82de91a0d9"},"previous_names":["ernado/td"],"tags_count":206,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotd%2Ftd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotd%2Ftd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotd%2Ftd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotd%2Ftd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gotd","download_url":"https://codeload.github.com/gotd/td/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248641436,"owners_count":21138205,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bot-api","go","golang","mtproto","tdlib","telegram","telegram-api","telegram-bot"],"created_at":"2024-08-01T19:01:41.138Z","updated_at":"2026-02-07T19:19:43.654Z","avatar_url":"https://github.com/gotd.png","language":"Go","readme":"# td [![Go Reference](https://img.shields.io/badge/go-pkg-00ADD8)](https://pkg.go.dev/github.com/gotd/td#section-documentation) [![codecov](https://img.shields.io/codecov/c/github/gotd/td?label=cover)](https://codecov.io/gh/gotd/td) [![beta](https://img.shields.io/badge/-beta-yellow)](https://go-faster.org/docs/projects/status#beta)\n\nTelegram MTProto API client in Go for users and bots.\n\n[![Telegram: English chat](https://api.go-faster.org/badge/telegram/gotd_en?title=EN\u0026v=1)](https://t.me/gotd_en) [![Telegram: Russian chat](https://api.go-faster.org/badge/telegram/gotd_ru?title=RU\u0026v=1)](https://t.me/gotd_ru) [![Telegram: Chinese chat](https://api.go-faster.org/badge/telegram/gotd_zhcn?title=CN\u0026v=1)](https://t.me/gotd_zhcn) [![Telegram: Online count](https://api.go-faster.org/badge/telegram/online?groups=gotd_ru\u0026groups=gotd_en\u0026groups=gotd_zhcn)](https://t.me/gotd_en)\n\n* [Examples](examples)\n* [Security policy](.github/SECURITY.md)\n* [User support and dev chat](.github/SUPPORT.md)\n* [Roadmap](ROADMAP.md)\n* [Contributing](CONTRIBUTING.md)\n* [Architecture](ARCHITECTURE.md)\n* [Generated Go Documentation](https://ref.gotd.dev/pkg/github.com/gotd/td/tg.html)\n\nBefore using this library, read [How To Not Get Banned](.github/SUPPORT.md#how-to-not-get-banned) guide.\n\nDue to limitations of `pkg.go.dev`, documentation for `tg` package is not shown, but there is [hosted version](https://ref.gotd.dev/pkg/github.com/gotd/td/tg.html).\n\n## Higher level libraries\n\nThe `gotd` itself is a pretty low-level library, and you may want to use higher level libraries instead:\n- [GoTGProto][gotgproto] is a helper package for gotd library, It aims to make td's raw functions easy-to-use with the help of features like using session strings, custom helper functions, storing peers and extracting chat or user ids through it etc.\n\n[gotgproto]: https://github.com/celestix/gotgproto\n\n## Usage\n\n```console\ngo get github.com/gotd/td\n```\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\n\t\"github.com/gotd/td/telegram\"\n)\n\nfunc main() {\n\t// https://core.telegram.org/api/obtaining_api_id\n\tclient := telegram.NewClient(appID, appHash, telegram.Options{})\n\tif err := client.Run(context.Background(), func(ctx context.Context) error {\n\t\t// It is only valid to use client while this function is not returned\n\t\t// and ctx is not cancelled.\n\t\tapi := client.API()\n\n\t\t// Now you can invoke MTProto RPC requests by calling the API.\n\t\t// ...\n\n\t\t// Return to close client connection and free up resources.\n\t\treturn nil\n\t}); err != nil {\n\t\tpanic(err)\n\t}\n\t// Client is closed.\n}\n```\n\nSee [examples](examples) for more info.\n\n## Features\n\n* Full MTProto 2.0 implementation in Golang, directly access any MTProto method with [telegram.Client.API()](https://pkg.go.dev/github.com/gotd/td@v0.60.0/telegram#Client.API)\n* Highly optimized, low memory (150kb per idle client) and CPU overhead, can handle thousands concurrent clients\n* Code for Telegram types generated by `./cmd/gotdgen` (based on [gotd/tl](https://github.com/gotd/tl) parser) with embedded [official documentation](https://core.telegram.org/schema)\n* Pluggable session storage\n* Automatic re-connects with keepalive\n* Vendored Telegram public keys that are kept up-to-date\n* Rigorously tested\n  * End-to-end with real Telegram server in CI\n  * End-to-end with gotd Telegram server (in pure Go)\n  * Lots of unit testing\n  * Fuzzing\n  * 24/7 canary bot in production that tests reconnects, update handling, memory leaks and performance\n* No runtime reflection overhead\n* [Conforms](https://github.com/gotd/td/issues/155) to [Security guidelines](https://core.telegram.org/mtproto/security_guidelines) for Telegram client software developers\n  * Secure PRNG used for crypto\n  * Replay attack protection\n* 2FA support\n* MTProxy support\n* Various helpers that lighten the complexity of the Telegram API\n  * [uploads](https://pkg.go.dev/github.com/gotd/td/telegram/uploader) for big and small files with multiple streams for single file and progress reporting\n  * [downloads](https://pkg.go.dev/github.com/gotd/td/telegram/downloader) with CDN support, also multiple streams\n  * [messages](https://pkg.go.dev/github.com/gotd/td/telegram/message) with various convenience builders and text styling support\n  * [query](https://pkg.go.dev/github.com/gotd/td/telegram/query) with pagination helpers\n  * [middleware](https://pkg.go.dev/github.com/gotd/td/telegram#Middleware) for [rate limiting](https://pkg.go.dev/github.com/gotd/contrib/middleware/ratelimit) and [FLOOD_WAIT handling](https://pkg.go.dev/github.com/gotd/contrib/middleware/floodwait)\n* Connection pooling\n* Automatic datacenter migration and redirects handling\n* Graceful [request cancellation](https://core.telegram.org/mtproto/service_messages#cancellation-of-an-rpc-query) via context\n* WebSocket transport support (works in WASM)\n\n## Status\n\nThe goal of this project is to implement a stable, performant and safe client for Telegram in pure Go while\nhaving a simple and convenient API and a feature parity with TDLib.\n\nThis project is fully non-commercial and not affiliated with any commercial organization\n(including Telegram LLC).\n\n## Examples\n\nSee [examples](examples) directory.\n\nAlso take a look at\n\n* [go-faster/bot](https://github.com/go-faster/bot) as example of sophisticated telegram bot integration with GitHub\n* [gotd/cli](https://github.com/gotd/cli), command line interface for subset of telegram methods.\n\n### Auth\n\n#### User\n\nYou can use `td/telegram/auth.Flow` to simplify user authentications.\n\n```go\ncodePrompt := func(ctx context.Context, sentCode *tg.AuthSentCode) (string, error) {\n    // NB: Use \"golang.org/x/crypto/ssh/terminal\" to prompt password.\n    fmt.Print(\"Enter code: \")\n    code, err := bufio.NewReader(os.Stdin).ReadString('\\n')\n    if err != nil {\n        return \"\", err\n    }\n    return strings.TrimSpace(code), nil\n}\n// This will setup and perform authentication flow.\n// If account does not require 2FA password, use telegram.CodeOnlyAuth\n// instead of telegram.ConstantAuth.\nif err := auth.NewFlow(\n    auth.Constant(phone, password, auth.CodeAuthenticatorFunc(codePrompt)),\n    auth.SendCodeOptions{},\n).Run(ctx, client.Auth()); err != nil {\n    panic(err)\n}\n```\n\n#### Bot\n\nUse bot token from [@BotFather](https://telegram.me/BotFather).\n\n```go\nif err := client.Auth().Bot(ctx, \"token:12345\"); err != nil {\n    panic(err)\n}\n```\n\n### Calling MTProto directly\n\nYou can use the generated `tg.Client` that allows calling any MTProto method\ndirectly.\n\n```go\n// Grab these from https://my.telegram.org/apps.\n// Never share it or hardcode!\nclient := telegram.NewClient(appID, appHash, telegram.Options{})\nclient.Run(ctx, func(ctx context.Context) error {\n  // Grab token from @BotFather.\n  if _, err := client.Auth().Bot(ctx, \"token:12345\"); err != nil {\n    return err\n  }\n  state, err := client.API().UpdatesGetState(ctx)\n  if err != nil {\n    return err\n  }\n  // Got state: \u0026{Pts:197 Qts:0 Date:1606855030 Seq:1 UnreadCount:106}\n  // This will close client and cleanup resources.\n  return nil\n})\n```\n\n### Generated code\n\nThe code output of `gotdgen` contains references to TL types, examples, URL to\nofficial documentation and [extracted](https://github.com/gotd/getdoc) comments from it.\n\nFor example, the [auth.Authorization](https://core.telegram.org/type/auth.Authorization) type in `tg/tl_auth_authorization_gen.go`:\n\n```go\n// AuthAuthorizationClass represents auth.Authorization generic type.\n//\n// See https://core.telegram.org/type/auth.Authorization for reference.\n//\n// Example:\n//  g, err := DecodeAuthAuthorization(buf)\n//  if err != nil {\n//      panic(err)\n//  }\n//  switch v := g.(type) {\n//  case *AuthAuthorization: // auth.authorization#cd050916\n//  case *AuthAuthorizationSignUpRequired: // auth.authorizationSignUpRequired#44747e9a\n//  default: panic(v)\n//  }\ntype AuthAuthorizationClass interface {\n\tbin.Encoder\n\tbin.Decoder\n\tconstruct() AuthAuthorizationClass\n}\n```\n\nAlso, the corresponding [auth.signIn](https://core.telegram.org/method/auth.signIn) method:\n\n```go\n// AuthSignIn invokes method auth.signIn#bcd51581 returning error if any.\n// Signs in a user with a validated phone number.\n//\n// See https://core.telegram.org/method/auth.signIn for reference.\nfunc (c *Client) AuthSignIn(ctx context.Context, request *AuthSignInRequest) (AuthAuthorizationClass, error) {}\n```\n\nThe generated constructors contain detailed official documentation, including links:\n\n```go\n// FoldersDeleteFolderRequest represents TL type `folders.deleteFolder#1c295881`.\n// Delete a peer folder¹\n//\n// Links:\n//  1) https://core.telegram.org/api/folders#peer-folders\n//\n// See https://core.telegram.org/method/folders.deleteFolder for reference.\ntype FoldersDeleteFolderRequest struct {\n    // Peer folder ID, for more info click here¹\n    //\n    // Links:\n    //  1) https://core.telegram.org/api/folders#peer-folders\n    FolderID int\n}\n```\n\n## Contributions\n\nHuge thanks to all contributors. Dealing with a project of this scale alone is impossible.\n\nSpecial thanks:\n\n* [tdakkota](https://github.com/tdakkota)\n  * Two-factor authentication (SRP)\n  * Proxy support\n  * Update dispatcher\n  * Complete transport support (abridged, padded intermediate and full)\n  * Telegram server for end-to-end testing\n  * Multiple major refactorings, including critical cryptographical scope reduction\n  * Code generation improvements (vector support, multiple modes for pretty-print)\n  * And many other cool things and performance improvements\n* [shadowspore](https://github.com/shadowspore)\n  * Background pings\n  * Links in generated documentation\n  * Message acknowledgements\n  * Retries\n  * RPC Engine\n  * Gap (Updates) engine\n\n## Reference\n\nThe MTProto protocol description is [hosted](https://core.telegram.org/mtproto#general-description) by Telegram.\n\nMost important parts for client implementations:\n\n* [Security guidelines](https://core.telegram.org/mtproto/security_guidelines) for client software developers\n\nCurrent implementation [mostly conforms](https://github.com/gotd/td/issues/155) to security guidelines, but no\nformal security audit were performed.\n\n## Prior art\n\n* [Lonami/grammers](https://github.com/Lonami/grammers) (Great Telegram client in Rust, many test vectors were used as reference)\n* [sdidyk/mtproto](https://github.com/sdidyk/mtproto), [cjongseok/mtproto](https://github.com/cjongseok/mtproto), [xelaj/mtproto](https://github.com/xelaj/mtproto) (MTProto 1.0 in go)\n\n## Who is using gotd?\n\n- The [iyear/tdl](https://github.com/iyear/tdl), 📥 Telegram Downloader, but more than a downloader\n\n[\u003cimg src=\"https://user-images.githubusercontent.com/43930873/142855897-7091ced0-4fe8-4f8d-ad43-e9db2723bacc.png\" width=\"150\"\u003e](https://telq.org)\n\nDrop a comment [here](https://github.com/gotd/td/issues/568) to add your project.\n\n## License\n\nMIT License\n\nCreated by Aleksandr (ernado) Razumov\n\n2020\n\n## Links\n\n- [Examples](https://github.com/gotd/td/blob/-/examples/README.md)\n- [Security policy](https://github.com/gotd/td/blob/-/.github/SECURITY.md)\n- [User support and dev chat](https://github.com/gotd/td/blob/-/.github/SUPPORT.md)\n- [Roadmap](https://github.com/gotd/td/blob/-/ROADMAP.md)\n- [Contributing](https://github.com/gotd/td/blob/-/CONTRIBUTING.md)\n- [Architecture](https://github.com/gotd/td/blob/-/ARCHITECTURE.md)\n- [Generated Go Documentation](https://ref.gotd.dev/pkg/github.com/gotd/td/tg.html)\n","funding_links":["https://polar.sh/gotd"],"categories":["Go","Bots"],"sub_categories":["Bot Libs"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgotd%2Ftd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgotd%2Ftd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgotd%2Ftd/lists"}