Go to file
Kailash Nadh cecca90a06 Remove spurious `raise` that's already handled. Closes #107. 2023-09-28 00:01:44 +05:30
tgarchive Remove spurious `raise` that's already handled. Closes #107. 2023-09-28 00:01:44 +05:30
LICENSE First commit 2021-03-20 18:04:44 +05:30
MANIFEST.in First commit 2021-03-20 18:04:44 +05:30
README.md README: add workaround for opaque failure mode of app creation page (#91) 2023-01-27 19:51:51 +05:30
requirements.txt update telethon version to v1.29.3 (#110) 2023-09-08 00:23:28 +05:30
setup.py Add --version flag 2021-05-25 19:47:25 +05:30

README.md

favicon

tg-archive is a tool for exporting Telegram group chats into static websites, preserving chat history like mailing list archives.

Preview

The @fossunited Telegram group archive.

image

How it works

tg-archive uses the Telethon Telegram API client to periodically sync messages from a group to a local SQLite database (file), downloading only new messages since the last sync. It then generates a static archive website of messages to be published anywhere.

Features

  • Periodically sync Telegram group messages to a local DB.
  • Download user avatars locally.
  • Download and embed media (files, documents, photos).
  • Renders poll results.
  • Use emoji alternatives in place of stickers.
  • Single file Jinja HTML template for generating the static site.
  • Year / Month / Day indexes with deep linking across pages.
  • "In reply to" on replies with links to parent messages across pages.
  • RSS / Atom feed of recent messages.

Install

  • Get Telegram API credentials. Normal user account API and not the Bot API.
    • If this page produces an alert stating only "ERROR", disconnect from any proxy/vpn and try again in a different browser.
  • Install with pip3 install tg-archive (tested with Python 3.8.6).

Usage

  1. tg-archive --new --path=mysite (creates a new site. cd into mysite and edit config.yaml).
  2. tg-archive --sync (syncs data into data.sqlite). Note: First time connection will prompt for your phone number + a Telegram auth code sent to the app. On successful auth, a session.session file is created. DO NOT SHARE this session file publicly as it contains the API autorization for your account.
  3. tg-archive --build (builds the static site into the site directory, which can be published)

Customization

Edit the generated template.html and static assets in the ./static directory to customize the site.

Note

  • The sync can be stopped (Ctrl+C) any time to be resumed later.
  • Setup a cron job to periodically sync messages and re-publish the archive.
  • Downloading large media files and long message history from large groups continuously may run into Telegram API's rate limits. Watch the debug output.

Licensed under the MIT license.