Skip to main content

TelegramBackup

This is the Telegram adapter for tg-blog, a front-end for displaying telegram (or any compatible) channel data as an interactive web page.

Motivation

Telegram has become increasingly fragile, recently revoking 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 using t.me links. 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 / Examples

Usage

Installation

First, install Python >= 3.11. Then, run pip install tgc

Then, to support video/animation/sticker conversion, you have to install the following non-python dependencies:

  1. Install Node 19.2 and yarn 1.22
  2. yarn global add puppeteer-lottie-cli
  3. Install ffmpeg using your system package manager

Mode 1: Convert Telegram Export

If you only need a one-time export, you can use mode 1. To do this, you first need to export a channel using tdesktop.

To convert an export file into a format supported by tg-blog, you can run tgce <export path>

Mode 2: Crawl Channel using MTProto API

If 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 Keys

  1. Obtain api_id and api_hash by creating your Telegram application (Official Guide)
    1. Log into https://my.telegram.org/apps
    2. Fill out the form to create an application
    3. Or, 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.
  2. Choose which type of account to log in:
    1. Bot account: Create a bot using the @BotFather bot.
    2. Self-bot account: Leave bot_token blank, 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).
  3. Fill in the tokens in ~/.config/tgc/config.toml as shown below
# Telegram API id & hash
api_id = 10000000
api_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 Crawled

  1. Either invite your bot to the channel or join the channel on your self-bot account
  2. Forward a channel message to @RawDataBot to obtain the channel ID. (You'll see a JSON response, and you can find the ID from the forward_from_chat field)
  3. Fill in the channel info in ~/.config/tgc/config.toml as shown below
# One export entry in a list of exports
[[exports]]
chat_id = -1001191767119    # Telegram channel chat id
path = "exports/hykilp"     # Output Path

After all setup is complete, you can proceed to running the crawler.

Running the Crawler

Simply run the tgc command.

Additional Config

You can set additional configuration for each export entry like below:

Field Description Type
size_limit_mb Limit downloaded file size (skip large files) float

RSS Feed Generation

If you want to generate RSS feed, you can add the following under the export entry:

[[exports]]
chat_id = -1001191767119    # Telegram channel chat id
path = "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 Actions

If you want to automatically backup/sync telegram channel data using GitHub Actions, you can do this.

  1. Create your config.toml
  2. Make a fork of https://github.com/hykilpikonna/blog-data
  3. In GitHub's Settings tab, create a secret called TGC_CONFIG, and paste your config.toml there.
  4. Remember to set a size_limit_mb to below 100 so that git lfs won't warn you for pushing large files.

Metadata

Release files for tgc 1.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tgc 1.1.5
File Size Uploaded Provenance Actions
tgc-1.1.5.tar.gz 40.2 kB With provenance Details for tgc-1.1.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tgc 1.1.5
File Interpreter ABI Platform Actions
tgc-1.1.5-py3-none-any.whl Python 3 none any Details for tgc-1.1.5-py3-none-any.whl

Total release size: 62.5 kB

Release files / tgc-1.1.5.tar.gz

Download URL tgc-1.1.5.tar.gz
Size 40.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f5809801561593bf2ccb048f5a13b521b3c9d4ddab7a0d06844e22a747572b4e
BLAKE2b-256 checksum
How to use checksums
c27bdb4f4964bc7faf880f9310e7ca7c52df108a800640d2d1b2ca6c1264d879
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.

Transparency log

Release files / tgc-1.1.5-py3-none-any.whl

Download URL tgc-1.1.5-py3-none-any.whl
Size 22.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
caa21855de2a5df69a41a7c4a2f3cfc5758083e8bc2a51662bda9dbfc73a79c8
BLAKE2b-256 checksum
How to use checksums
03e3b29964bde3760d666c9e5eb4a4c133f38789fb47ecfb4d7c15ddcb9c6806
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.

Transparency log

Security for tgc 1.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for tgc-1.1.5.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page