# Telegram Archive

![Telegram Archive](<https://geiserx.github.io/Telegram-Archive/images/banner.svg>)

[![Docker Pulls](<https://img.shields.io/docker/pulls/drumsergio/telegram-archive?style=flat-square&amp;logo=docker>)](<https://hub.docker.com/r/drumsergio/telegram-archive>) [![GitHub Stars](<https://img.shields.io/github/stars/GeiserX/Telegram-Archive?style=flat-square&amp;logo=github>)](<https://github.com/GeiserX/Telegram-Archive/stargazers>) [![Release](<https://img.shields.io/github/v/release/GeiserX/Telegram-Archive?style=flat-square>)](<https://github.com/GeiserX/Telegram-Archive/releases>) [![License: GPL-3.0-or-later](<https://img.shields.io/github/license/GeiserX/Telegram-Archive?style=flat-square>)](<https://github.com/GeiserX/Telegram-Archive/blob/main/LICENSE>)

---

**Telegram Archive** backs up one or more Telegram accounts to a machine you host, in Docker or from the [Python package](<https://geiserx.github.io/Telegram-Archive/getting-started/pip/index.md>). Telegram Desktop's own export is a file you make by hand: it holds no earlier version of an edited message, no deleted message, and nothing reads it like the app. Telegram Archive runs on a schedule, fetches only what is new, keeps every edit and every deletion, and shows the archive in a viewer that reads like Telegram. Start with [Run with Docker](<https://geiserx.github.io/Telegram-Archive/getting-started/docker/index.md>), then [Using the viewer](<https://geiserx.github.io/Telegram-Archive/viewer/using-the-viewer/index.md>). Only the backup talks to Telegram; the viewer only reads the archive.

- **[Run with Docker](<https://geiserx.github.io/Telegram-Archive/getting-started/docker/index.md>)**

  ---

  [Log in to Telegram](<https://geiserx.github.io/Telegram-Archive/getting-started/telegram-login/index.md>), then start the backup and the viewer with the shipped compose file.
- **[Your first backup](<https://geiserx.github.io/Telegram-Archive/getting-started/first-backup/index.md>)**

  ---

  Follow the first run, see what a finished one looks like, and pick the settings to change next.
- **[Using the viewer](<https://geiserx.github.io/Telegram-Archive/viewer/using-the-viewer/index.md>)**

  ---

  Read chats, search messages, browse shared media and see what changed since the last run.
- **[Environment variables](<https://geiserx.github.io/Telegram-Archive/reference/environment-variables/index.md>)**

  ---

  Every setting, its default and what it changes.

## The viewer

![A group chat in the viewer, with a pinned message, a four-photo album, replies and reactions, in the Telegram Day theme](<https://geiserx.github.io/Telegram-Archive/images/screenshots/chat-desktop.png>)

![The same group chat on a phone](<https://geiserx.github.io/Telegram-Archive/images/screenshots/chat-mobile.png>)

On a phone

![A message deleted in Telegram, kept in the archive with its text and a deleted mark](<https://geiserx.github.io/Telegram-Archive/images/screenshots/chat-deleted-mobile.png>)

Deletions kept

![The edit history of a message edited twice, each version with its time](<https://geiserx.github.io/Telegram-Archive/images/screenshots/edit-history-mobile.png>)

Every edit kept

![The group chat in the Telegram Night theme](<https://geiserx.github.io/Telegram-Archive/images/screenshots/chat-mobile-dark.png>)

Telegram Night

The viewer looks and works like the Telegram app, with the archive behind it: chats, folders, forum topics, search, shared media and an info panel. What Telegram no longer shows, it keeps and marks: a [deleted message](<https://geiserx.github.io/Telegram-Archive/viewer/using-the-viewer/#deleted-messages>) stays with its text, an [edited message](<https://geiserx.github.io/Telegram-Archive/viewer/using-the-viewer/#reactions-edits-and-deletions>) keeps its earlier versions, and [What changed](<https://geiserx.github.io/Telegram-Archive/viewer/using-the-viewer/#what-changed>) lists every deletion, edit and new transcript. [Logins, viewer accounts and share links](<https://geiserx.github.io/Telegram-Archive/viewer/access/index.md>) covers who can open which chats, [Themes and wallpaper](<https://geiserx.github.io/Telegram-Archive/viewer/themes/index.md>) the twelve themes, and [Exposing the viewer safely](<https://geiserx.github.io/Telegram-Archive/viewer/exposing/index.md>) a reverse proxy in front of it.

## What it saves

- Messages with their formatting, replies, forwards, reactions, pinned messages, polls and service messages.
- Every edit, with the earlier text, and every deletion, kept and marked. See [Catching changes to older messages](<https://geiserx.github.io/Telegram-Archive/configuration/schedule/#catching-changes-to-older-messages>).
- Photos, videos, voice notes, audio, round videos, GIFs, stickers, documents and link previews, each file stored once. Files over 100 MB are skipped by default. See [Media downloads](<https://geiserx.github.io/Telegram-Archive/configuration/media/index.md>).
- Forum topics, Telegram folders, archived chats, avatars and earlier profile photos.
- [Several accounts](<https://geiserx.github.io/Telegram-Archive/configuration/multiple-accounts/index.md>) in one archive, [transcripts](<https://geiserx.github.io/Telegram-Archive/configuration/transcription/index.md>) of voice messages, and [imports](<https://geiserx.github.io/Telegram-Archive/operations/maintenance/index.md>) of Telegram Desktop exports. Bot chats are skipped unless you [add them](<https://geiserx.github.io/Telegram-Archive/configuration/choosing-chats/index.md>).

## How it runs

```
flowchart TB
    TG[Telegram]
    subgraph backup [Backup container]
        SCH[Scheduler]
        CL[One client per account]
        LI[Real-time listener]
        MIG[Migrations on start]
    end
    DB[(Database<br/>SQLite by default<br/>PostgreSQL optional)]
    MEDIA[(Media folder)]
    TR[Transcription server, optional]
    subgraph viewer [Viewer container]
        WEB[Web viewer on port 8000<br/>reachable from this machine only]
    end
    BR[Browser]

    TG <--> CL
    SCH --> CL
    LI --> CL
    CL --> DB
    CL --> MEDIA
    MIG --> DB
    backup -.->|audio| TR
    DB --> WEB
    MEDIA --> WEB
    WEB <--> BR
```

- Two images, `drumsergio/telegram-archive` for the backup and `drumsergio/telegram-archive-viewer`, share one version number, run on amd64 and arm64, and run as user id 1000.
- The [listener](<https://geiserx.github.io/Telegram-Archive/configuration/listener/index.md>) saves new messages, edits and reactions as they happen. A full backup runs when the container starts, then on a cron [schedule](<https://geiserx.github.io/Telegram-Archive/configuration/schedule/index.md>), once a day by default, to fetch what the listener could not see.
- The archive is [SQLite by default, or PostgreSQL](<https://geiserx.github.io/Telegram-Archive/configuration/database/index.md>). An [upgrade](<https://geiserx.github.io/Telegram-Archive/operations/upgrading/index.md>) is usually a pin change and a restart; [Backing up the archive](<https://geiserx.github.io/Telegram-Archive/operations/backup-and-restore/index.md>) says how to keep a copy.

## What it does not do

- It does not save secret chats.
- It cannot recover messages deleted before the first backup.
- It never sends or changes anything in your account. Only the separate restore script posts archived messages back to a chat, as you. See [Command line and Python API](<https://geiserx.github.io/Telegram-Archive/reference/cli/index.md>).
- The viewer is in English only and has no offline mode.

## Privacy

- The archive stays on your own disk. Nothing leaves it unless you turn on one of the three optional features below.
- The logs never contain message text, chat ids, account labels or phone numbers.
- [Transcription](<https://geiserx.github.io/Telegram-Archive/configuration/transcription/index.md>) sends the audio, its file name and its content hash to the server you configure. No message text or chat details go with it.
- The [event webhook](<https://geiserx.github.io/Telegram-Archive/configuration/event-webhook/index.md>) sends each edit or deletion, message text included, to the URL you configure.
- [Web Push](<https://geiserx.github.io/Telegram-Archive/viewer/live-updates/#what-a-push-contains>) with `PUSH_NOTIFICATIONS=full` sends the chat title, the sender and the first 100 characters of each new message through your browser's push service, encrypted for the browser.

## Getting help

- Something broken: read [Monitoring and troubleshooting](<https://geiserx.github.io/Telegram-Archive/operations/troubleshooting/index.md>), then open an issue with the details it lists.
- A security problem: follow the [security policy](<https://github.com/GeiserX/Telegram-Archive/blob/main/SECURITY.md>), never a public issue.
- What changed between releases: the [changelog on GitHub](<https://github.com/GeiserX/Telegram-Archive/blob/main/docs/CHANGELOG.md>). What is planned: the [Roadmap](<https://geiserx.github.io/Telegram-Archive/roadmap/index.md>).
- Terms these pages use: the [Glossary](<https://geiserx.github.io/Telegram-Archive/reference/glossary/index.md>). Scripting against the viewer: the [HTTP API](<https://geiserx.github.io/Telegram-Archive/reference/api/index.md>). Sending a fix: [Development](<https://geiserx.github.io/Telegram-Archive/development/index.md>).

## License

Telegram Archive is released under the [GPL-3.0-or-later](<https://github.com/GeiserX/Telegram-Archive/blob/main/LICENSE>) license. It is built on [Telethon](<https://github.com/LonamiWebs/Telethon>).
