Docker Hub repository for Telegram Exporter
GitHub Packages for Telegram Exporter
Telegram Exporter is a Python application designed to export and store messages from Telegram chats, groups, or channels into a SQLite database. The application supports formatting messages into HTML and automatically generates CSV and JSON files for easy data analysis and integration with other tools.
The application is particularly useful for:
- Archiving messages from personal or public Telegram groups.
- Analyzing chat data with external tools like Excel, Python scripts, or web services.
- Exporting messages for research, reporting, or integration into third-party systems.
- Comprehensive Data Export:
- Exports messages along with metadata like date, URLs, and chat IDs.
- Supports rich text formatting with styles like bold, italic, and underline.
- Automatic File Generation:
- Automatically generates
html.csv
andhtml.json
after every export to ensure your data is always up-to-date.
- Automatically generates
- SQLite Database Storage:
- Efficiently stores messages with options for filtering and querying.
- Dockerized Deployment:
- Deployable using a pre-built Docker image for easy scalability and cross-platform support.
- CI/CD Integration:
- Automatically builds and pushes Docker images to Docker Hub upon successful tests.
- Cross-version Compatibility:
- Supports Python 3.10, 3.11, and 3.12.
- Python version 3.10 to 3.12 (Python 3.13 is not supported due to deprecated modules like
imghdr
). - Git
- Docker (optional for containerized deployment)
-
Clone the repository:
git clone https://github.com/VladimirVereshchagin/telegram_exporter.git cd telegram_exporter
-
Create a virtual environment:
python -m venv venv
-
Activate the virtual environment:
-
On Windows:
venv\Scripts\activate
-
On macOS/Linux:
source venv/bin/activate
-
-
Install dependencies:
pip install -r requirements.txt
-
Configure environment variables:
-
Rename
.env.example
to.env
and fill in your credentials:API_ID=your_api_id API_HASH=your_api_hash PHONE=your_phone_number_with_country_code
-
You can export messages from any chat, group, or channel you have access to.
Run the application without any arguments to export messages from your "Saved Messages":
python telegram_exporter/main.py
Use the --chat
argument with the username, ID, or link to the chat:
python telegram_exporter/main.py --chat username_or_link
-
By username:
python telegram_exporter/main.py --chat example_user
-
By channel link:
python telegram_exporter/main.py --chat https://t.me/example_channel
-
By chat ID:
python telegram_exporter/main.py --chat -1001234567890
Note: Ensure you have access to the specified chat, group, or channel.
For quick deployment, use the pre-built Docker image available on Docker Hub.
docker run -d \
--name telegram_exporter \
--env-file .env \
-v $(pwd)/data:/app/data \
vladimirvereschagin/telegram_exporter:latest
After running the application, the following files will be updated in the data directory:
- db.sqlite3 — SQLite database containing exported messages.
- html.csv — CSV file with messages and URLs.
- html.json — JSON file with messages and URLs.
GitHub Actions is configured to automatically:
- Lint the code with
flake8
. - Run unit tests.
- Build and push Docker images to:
The application automatically extracts URLs from messages and saves them in the urls
column in the database. This includes:
- Direct links in the message text.
- Links contained in message entities (e.g., formatted links where display text differs from the URL).
Run the following command to execute all tests:
python -m unittest discover tests
For linting:
flake8 telegram_exporter tests
If you have any questions or suggestions, please create an issue or pull request in the project repository.
If you'd like to contribute, please follow the Contribution Guide.
This project is distributed under the MIT License. See the LICENSE file for details.