A script for a Telegram bot that deletes non-photo material from a group chat topic.
To run this script with the right Python version and all the dependencies, please use uv:
Installation instructions for uv
Install uv (and git) on Windows 11+ with PowerShell:
irm https://astral.sh/uv/install.ps1 | iex
$env:Path = "$env:USERPROFILE\.local\bin;$env:Path"
# git doesn't come with Windows 11 by default
winget install -e --id Git.Git
On macOS or Linux:
curl -LsSf https://astral.sh/uv/install.sh | sh
source $HOME/.local/bin/env
Or, if you only have access to Python (as is the case for PythonAnywhere's free tier):
pip install --upgrade uv
Then, run the script:
git clone https://github.com/vovavili/media_only_tg_bot.git
cd media_only_tg_bot
# Make sure to create a .env or .env.prod file at this step
uv run -m src.media_only_topic
Prior to running the script, please make sure your .env
or .env.prod
file contains the following variables. To find out
how to get them, please refer to the
following guide:
- BOT_TOKEN - an API token for your bot.
- TOPIC_ID - an ID for your group chat topic.
- GROUP_CHAT_ID - an ID for your group chat.
- ENVIRONMENT - if you intend on running this script on a VPS, this improves logging information in your production system. Has to be either "development" or "production."
Required only in production, to send an email message on failure:
- SMTP_HOST - SMTP server address (e.g., smtp.gmail.com).
- SMTP_USER - Email username/address for SMTP authentication.
- SMTP_PASSWORD - Email password or app-specific password (in case of something like Gmail).
Based on my experience, this script runs on PythonAnywhere's free tier just fine, though for particularly active group chats it might be too limited. Keep in mind that, for the free tier, logging emails are restricted to Gmail only.