Package: tgc
TelegramBackupThis is the Telegram adapter fortg-blog, a front-end for displaying telegram (or any compatible) channel data as an interactive web page.MotivationTelegram has become increasingly fragile, recentlyrevoking usernames for inactive channels, and often randomly banning regular users misclassified as spam. During the username revoking, many channels of deceased individuals have been remove from public space, no longer accessible usingt.melinks. This tool helps to maintain Telegram channel data in case of an accidental event, and also to publicly display inactive channels that have been revoked.Demos / ExamplesYou can add this to your blog so that it syncs with your telegram channel (e.g.Azalea's Blog).You can also use this to back up and display another person's channel (e.g.donotexist_A's backup on One Among Us).UsageInstallationFirst, install Python>= 3.11. Then, runpip install tgcThen, to support video/animation/sticker conversion, you have to install the following non-python dependencies:Install Node 19.2 and yarn 1.22yarn global add puppeteer-lottie-cliInstallffmpegusing your system package managerMode 1: Convert Telegram ExportIf you only need a one-time export, you can use mode 1. To do this, you first need to export a channel usingtdesktop.To convert an export file into a format supported bytg-blog, you can runtgce <export path>Mode 2: Crawl Channel using MTProto APIIf you have the permission to add a bot account to a channel, or invite a self-bot account, you can use the MTProto crawler for automatic incremental export updates. (Please, do not log into your own Telegram account for crawling, there's a very high chance of being mis-classified as spam and get banned)Using this method, it can automatically update the channel backup incrementally, and the information will be more complete. However, it is more difficult to set up than mode 1.Setup API KeysObtainapi_idandapi_hashby creating your Telegram application (Official Guide)Log intohttps://my.telegram.org/appsFill out the form to create an applicationOr, if you want to go against Telegram's EULA for your convenience, you can leave them blank to use Telegram's official client's API hash at your own risk.Choose which type of account to log in:Bot account: Create a bot using the@BotFatherbot.Self-bot account: Leavebot_tokenblank, it will prompt you to login. You should only use a self-bot when you're not the admin of the channel (because inviting a bot requires admin access).Fill in the tokens in~/.config/tgc/config.tomlas shown below# Telegram API id & hashapi_id=10000000api_hash="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"# Telegram bot token (leave blank to log into self-bot account)bot_token="0000000000:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"After setting up the keys, you can proceed to setting up the channel:Setup Channels to be CrawledEither invite your bot to the channel or join the channel on your self-bot accountForward a channel message to@RawDataBotto obtain the channel ID. (You'll see a JSON response, and you can find the ID from theforward_from_chatfield)Fill in the channel info in~/.config/tgc/config.tomlas shown below# One export entry in a list of exports[[exports]]chat_id=-1001191767119# Telegram channel chat idpath="exports/hykilp"# Output PathAfter all setup is complete, you can proceed to running the crawler.Running the CrawlerSimply run thetgccommand.Additional ConfigYou can set additional configuration for each export entry like below:FieldDescriptionTypesize_limit_mbLimit downloaded file size (skip large files)floatRSS Feed GenerationIf you want to generate RSS feed, you can add the following under the export entry:[[exports]]chat_id=-1001191767119# Telegram channel chat idpath="exports/hykilp"# Output Path[exports.rss]title="小桂桂的回忆录 📒"link="https://aza.moe/life"description="「我们所经历的每个平凡的日常，也许就是连续发生的奇迹」"language="zh-cn"image_url="https://aza.moe/meru_256px.png"Automatic Updates using GitHub ActionsIf you want to automatically backup/sync telegram channel data using GitHub Actions, you can do this.Create yourconfig.tomlMake a fork ofhttps://github.com/hykilpikonna/blog-dataIn GitHub's Settings tab, create a secret calledTGC_CONFIG, and paste yourconfig.tomlthere.Remember to set asize_limit_mbto below 100 so that git lfs won't warn you for pushing large files.