A Telegram bot built with Telethon library.
- Install dependencies:
pip install -r requirements.txt-
Get your Telegram API credentials:
- Go to https://my.telegram.org
- Log in with your phone number
- Go to "API Development"
- Create a new application
- Copy your
api_idandapi_hash
-
Set up your configuration:
Option 1: Environment Variables
export TELEGRAM_API_ID=your_api_id_here export TELEGRAM_API_HASH=your_api_hash_here export TELEGRAM_SESSION_NAME=your_session_name export TELEGRAM_DEFAULT_RECIPIENT=username_or_chat_id
Option 2: .env file Create a
.envfile in the project root:TELEGRAM_API_ID=your_api_id_here TELEGRAM_API_HASH=your_api_hash_here TELEGRAM_SESSION_NAME=your_session_name TELEGRAM_DEFAULT_RECIPIENT=username_or_chat_id TELEGRAM_DEFAULT_FILE_PATH=/path/to/your/file -
Run the bot:
python client.py- Never commit your actual API credentials to version control
- The
.envfile is already in.gitignoreto prevent accidental commits - Use environment variables in production environments
- Keep your
api_hashsecret and secure
All configuration options can be found in config.py and can be overridden using environment variables:
TELEGRAM_API_ID: Your Telegram API IDTELEGRAM_API_HASH: Your Telegram API hashTELEGRAM_SESSION_NAME: Session name for the clientTELEGRAM_DEFAULT_RECIPIENT: Default recipient for messagesTELEGRAM_DEFAULT_FILE_PATH: Default file path for file operations