td/examples at main · gotd/td · GitHub
Skip to content

Latest commit

 

History

History

examples

Folders and files

README.md

Examples

Most examples use environment variable client builders. You can do it manually, see bot-auth-manual for example.

  1. Obtain api_id and api_hash for your application and set as APP_ID, APP_HASH
  2. Set SESSION_FILE to something like ~/session.yourbot.json for persistent auth
  3. Run example.

Please don't share APP_ID or APP_HASH, it can't be easily rotated.

Name Description Features
userbot Userbot example with peer storage and flood wait middelware Custom auth flow, session.Storage, PeerStorage, ResolverCache
send-message User login by code, file session, send to a channel/user session.FileStorage, code login, reconnect via stored session, sender.Resolve
save-media Userbot saving media you reply to with "save" UpdateDispatcher, fetch replied message, query/messages Elem.File, downloader
bot-auth-manual Bot authentication session.Storage, setup without environment variables
bot-echo Echo bot UpdateDispatcher, message sender
bot-upload One-shot uploader for bot NoUpdates flag, uploads with MIME, custom file name and as audio, resolving peer by username, HTML message
bot-inline Inline bot answering inline queries UpdateDispatcher OnBotInlineQuery, message/inline results builder, message/styling
gif-download Saved gif backup (and restore) for user Download, upload, middlewares with rate limit, unpack
get-participants List channel/supergroup participants peers.Manager username resolve, query/channels/participants iterator (channels.getParticipants)
takeout Export account data (contacts) takeout session helper (account.initTakeoutSession), takeout-wrapped API calls
deeplink Parse t.me / tg: deeplinks (offline, no login) deeplink.Parse, deeplink.IsDeeplinkLike, link type routing
dialogs List dialogs and dump recent Saved Messages query.GetDialogs and query.Messages(...).GetHistory iterators
rich-message Send a structured rich message to Saved Messages message/rich page blocks and inline rich text, Builder.RichMessage
upload-url Upload a file from a URL to Saved Messages uploader/source HTTPSource, uploader.FromSource streaming upload
bot-bigbuckbunny Bot replying to any message with a video client.Pool(N) multi-connection upload pool, uploader.WithThreads/WithProgress, temp-file caching, video upload
bg-run Using client without Run contrib/bg package
account-banned Detect banned/deactivated account vs dead proxy OnSelfError hook, auth.IsUnauthorized (401), banned flag, permanent reconnection stop
pretty-print Pretty-print requests, responses and updates The tgp package, middleware and custom UpdateHandler for all updates
updates Updates engine example The updates package that recovers missed updates
mtproxy-connect Connect through an MTProxy and check MTProto without login dcs.MTProxy resolver, FakeTLS, pre-auth help.getNearestDC
tdesktop-mimic Connect indistinguishably from Telegram Desktop, no login telegram.TDesktopResolver (Obfuscated2 + abridged), telegram.DeviceTDesktopWindows, pre-auth help.getNearestDC

Environment variables

Name Description
BOT_TOKEN Token from BotFather
APP_ID api_id of Telegram app from my.telegram.org
APP_HASH api_hash of Telegram app from my.telegram.org
SESSION_FILE Path to session file, like /home/super-bot/.gotd/session.super-bot.json
SESSION_DIR Path to session directory, if SESSION_FILE is not set, like /home/super-bot/.gotd

Support

Still don't know how to use specific features? See user support.