{"id":13731706,"url":"https://github.com/zelenin/go-tdlib","last_synced_at":"2025-05-15T04:05:42.371Z","repository":{"id":41140540,"uuid":"146748195","full_name":"zelenin/go-tdlib","owner":"zelenin","description":"Go wrapper for TDLib (Telegram Database Library)","archived":false,"fork":false,"pushed_at":"2025-04-28T17:04:59.000Z","size":2310,"stargazers_count":489,"open_issues_count":2,"forks_count":107,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-04-28T17:45:40.016Z","etag":null,"topics":["go","tdlib","telegram"],"latest_commit_sha":null,"homepage":null,"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/zelenin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-08-30T12:44:21.000Z","updated_at":"2025-04-28T17:05:03.000Z","dependencies_parsed_at":"2024-11-14T22:32:34.180Z","dependency_job_id":"1dd959a9-b579-456d-8ee8-58277c0821a2","html_url":"https://github.com/zelenin/go-tdlib","commit_stats":null,"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zelenin%2Fgo-tdlib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zelenin%2Fgo-tdlib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zelenin%2Fgo-tdlib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zelenin%2Fgo-tdlib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zelenin","download_url":"https://codeload.github.com/zelenin/go-tdlib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254270645,"owners_count":22042859,"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":["go","tdlib","telegram"],"created_at":"2024-08-03T02:01:36.603Z","updated_at":"2025-05-15T04:05:37.343Z","avatar_url":"https://github.com/zelenin.png","language":"Go","funding_links":[],"categories":["Go","Bindings"],"sub_categories":["Go"],"readme":"# go-tdlib\n\nGo wrapper for [TDLib (Telegram Database Library)](https://github.com/tdlib/td) with full support of the TDLib.\nCurrent supported version of TDLib corresponds to the commit hash [b498497](https://github.com/tdlib/td/commit/b498497bbfd6b80c86f800b3546a0170206317d3), updated on 2025-03-16\n\n## TDLib installation\n\nUse [TDLib build instructions](https://tdlib.github.io/td/build.html) with checkmarked `Install built TDLib to /usr/local instead of placing the files to td/tdlib`. Don't forget to checkout a supported commit (see above).\n\n## Custom TDLib Path\n\nIf you have TDLib installed in a custom location, use environment variables to specify the include and library paths:\n\n```shell\nCGO_CFLAGS=-I/path/to/tdlib/include \\\nCGO_LDFLAGS=\"-Wl,-rpath,/path/to/tdlib/lib -L/path/to/tdlib/lib -ltdjson\" \\\ngo build ...\n```\n\n### Windows\n\nBuild with environment variables (use full paths):\n\n```\nCGO_ENABLED=1\nCGO_CFLAGS=-IC:/path/to/tdlib/build/tdlib/include\nCGO_LDFLAGS=-LC:/path/to/tdlib/build/tdlib/bin -ltdjson\n```\n\nExample for PowerShell:\n\n```powershell\n$env:CGO_ENABLED=1; $env:CGO_CFLAGS=\"-IC:/td/tdlib/include\"; $env:CGO_LDFLAGS=\"-LC:/td/tdlib/bin -ltdjson\"; go build -trimpath -ldflags=\"-s -w\" -o demo.exe .\\cmd\\demo.go\n```\nTo run, put the .dll from C:/td/tdlib/bin to the directory with the compiled .exe.\n\n## Usage\n\n### Client\n\n[Register an application](https://my.telegram.org/apps) to obtain an api_id and api_hash \n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"github.com/zelenin/go-tdlib/client\"\n\t\"log\"\n\t\"os\"\n\t\"os/signal\"\n\t\"path/filepath\"\n\t\"syscall\"\n)\n\nconst (\n\tapiId   = 00000\n\tapiHash = \"8pu9yg32qkuukj83ozaqo5zzjwhkxhnk\"\n)\n\nfunc main() {\n\ttdlibParameters := \u0026client.SetTdlibParametersRequest{\n\t\tUseTestDc:              false,\n\t\tDatabaseDirectory:      filepath.Join(\".tdlib\", \"database\"),\n\t\tFilesDirectory:         filepath.Join(\".tdlib\", \"files\"),\n\t\tUseFileDatabase:        true,\n\t\tUseChatInfoDatabase:    true,\n\t\tUseMessageDatabase:     true,\n\t\tUseSecretChats:         false,\n\t\tApiId:                  apiId,\n\t\tApiHash:                apiHash,\n\t\tSystemLanguageCode:     \"en\",\n\t\tDeviceModel:            \"Server\",\n\t\tSystemVersion:          \"1.0.0\",\n\t\tApplicationVersion:     \"1.0.0\",\n\t}\n    // client authorizer\n    authorizer := client.ClientAuthorizer(tdlibParameters)\n    go client.CliInteractor(authorizer)\n\n    // or bot authorizer\n    // botToken := \"000000000:gsVCGG5YbikxYHC7bP5vRvmBqJ7Xz6vG6td\"\n    // authorizer := client.BotAuthorizer(tdlibParameters, botToken)\n\n\t_, err := client.SetLogVerbosityLevel(\u0026client.SetLogVerbosityLevelRequest{\n\t\tNewVerbosityLevel: 1,\n\t})\n\tif err != nil {\n\t\tlog.Fatalf(\"SetLogVerbosityLevel error: %s\", err)\n\t}\n\n\ttdlibClient, err := client.NewClient(authorizer)\n\tif err != nil {\n\t\tlog.Fatalf(\"NewClient error: %s\", err)\n\t}\n\n\tversionOption, err := client.GetOption(\u0026client.GetOptionRequest{\n\t\tName: \"version\",\n\t})\n\tif err != nil {\n\t\tlog.Fatalf(\"GetOption error: %s\", err)\n\t}\n\n\tcommitOption, err := client.GetOption(\u0026client.GetOptionRequest{\n\t\tName: \"commit_hash\",\n\t})\n\tif err != nil {\n\t\tlog.Fatalf(\"GetOption error: %s\", err)\n\t}\n\n\tlog.Printf(\"TDLib version: %s (commit: %s)\", versionOption.(*client.OptionValueString).Value, commitOption.(*client.OptionValueString).Value)\n\n\tif commitOption.(*client.OptionValueString).Value != client.TDLIB_VERSION {\n\t\tlog.Printf(\"TDLib version supported by the library (%s) is not the same as TDLib version (%s)\", client.TDLIB_VERSION, commitOption.(*client.OptionValueString).Value)\n\t}\n\n\tme, err := tdlibClient.GetMe(context.Background())\n\tif err != nil {\n\t\tlog.Fatalf(\"GetMe error: %s\", err)\n\t}\n\n\tlog.Printf(\"Me: %s %s\", me.FirstName, me.LastName)\n\n\tch := make(chan os.Signal, 2)\n\tsignal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)\n\t\u003c-ch\n\ttdlibClient.Close(context.Background())\n\tos.Exit(1)\n}\n\n```\n\n### QR Code login\n\n```go\npackage main\n\nimport (\n\t\"github.com/skip2/go-qrcode\"\n\t\"log\"\n\t\"path/filepath\"\n\n\t\"github.com/zelenin/go-tdlib/client\"\n)\n\nconst (\n\tapiId   = 00000\n\tapiHash = \"8pu9yg32qkuukj83ozaqo5zzjwhkxhnk\"\n)\n\nfunc main() {\n\ttdlibParameters := \u0026client.SetTdlibParametersRequest{\n\t\tUseTestDc:              false,\n\t\tDatabaseDirectory:      filepath.Join(\".tdlib\", \"database\"),\n\t\tFilesDirectory:         filepath.Join(\".tdlib\", \"files\"),\n\t\tUseFileDatabase:        true,\n\t\tUseChatInfoDatabase:    true,\n\t\tUseMessageDatabase:     true,\n\t\tUseSecretChats:         false,\n\t\tApiId:                  apiId,\n\t\tApiHash:                apiHash,\n\t\tSystemLanguageCode:     \"en\",\n\t\tDeviceModel:            \"Server\",\n\t\tSystemVersion:          \"1.0.0\",\n\t\tApplicationVersion:     \"1.0.0\",\n\t}\n\t// client authorizer\n\tauthorizer := client.QrAuthorizer(tdlibParameters, func(link string) error {\n\t\treturn qrcode.WriteFile(link, qrcode.Medium, 256, \"qr.png\")\n\t})\n\n\ttdlibClient, err := client.NewClient(authorizer)\n\tif err != nil {\n\t\tlog.Fatalf(\"NewClient error: %s\", err)\n\t}\n}\n\n````\n\n### Receive updates\n\n```go\nresHandCallback := func(result client.Type) {\n    log.Printf(\"%#v\", result.GetType())\n}\n\ntdlibClient, err := client.NewClient(authorizer, client.WithResultHandler(client.NewCallbackResultHandler(resHandCallback)))\nif err != nil {\n    log.Fatalf(\"NewClient error: %s\", err)\n}\n```\n\n### Proxy support\n\n```go\nproxy := client.WithProxy(\u0026client.AddProxyRequest{\n    Server: \"1.1.1.1\",\n    Port:   1080,\n    Enable: true,\n    Type: \u0026client.ProxyTypeSocks5{\n        Username: \"username\",\n        Password: \"password\",\n    },\n})\n\ntdlibClient, err := client.NewClient(authorizer, proxy)\n\n```\n\n## Example\n\n[Example application](https://github.com/zelenin/go-tdlib/tree/master/example)\n\n```\ncd example\ndocker build --network host --progress plain --tag tdlib-test .\ndocker run --rm -it -e \"API_ID=00000\" -e \"API_HASH=abcdef0123456789\" tdlib-test ash\n./app\n```\n\n## Notes\n\n* WIP. Library API can be changed in the future\n* The package includes a .tl-parser and generated [json-schema](https://github.com/zelenin/go-tdlib/tree/master/data) for creating libraries in other languages\n\n## Author\n\n[Aleksandr Zelenin](https://github.com/zelenin/), e-mail: [aleksandr@zelenin.me](mailto:aleksandr@zelenin.me)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzelenin%2Fgo-tdlib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzelenin%2Fgo-tdlib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzelenin%2Fgo-tdlib/lists"}