This is a Python-based Telegram bot that periodically checks the BaselHack Shop for ticket availability. If tickets are found, it sends a notification to a specified Telegram chat and an email to a configured address.
- Automated Checking: Periodically checks for tickets using an async architecture.
- Telegram Integration: Control the bot and receive status updates via Telegram commands.
- Email Notifications: Get an email notification the moment tickets become available.
- Silent Mode: Toggle off routine notifications to only be alerted on success or failure.
- Systemd Service: Includes a
systemdservice file for easy deployment on a Linux server. - Configurable: All settings are managed through a
.envfile.
Once the bot is running, you can interact with it in your configured Telegram chat:
-
/start [interval]Starts the periodic checks. You can optionally provide an interval in seconds. If not provided, it uses theCHECK_INTERVAL_SECONDSfrom the.envfile. Example:/start 300(checks every 5 minutes) -
/stopStops the periodic checks. -
/checkTriggers an immediate, one-time check for ticket availability. -
/togglesilentTurns silent mode ON or OFF. When ON, you will only be notified if tickets are found or if a check fails. -
/testemailSends a test email to your configured address to verify your settings.
- Python 3.8+
- A Telegram Bot Token (get one from BotFather)
- Your Telegram Chat ID (you can get it from a bot like @userinfobot)
- An email account (e.g., Gmail) to send notifications from.
-
Clone the repository:
git clone <repository_url> cd basel-hack-ticket-bot
-
Create a virtual environment:
python3 -m venv venv source venv/bin/activate -
Install the dependencies:
pip install -r requirements.txt
-
Configure environment variables: Create a file named
.envin the project root and add the following content. Fill in your actual credentials.# Telegram Bot Configuration TELEGRAM_BOT_TOKEN="YOUR_TELEGRAM_BOT_TOKEN" TELEGRAM_CHAT_ID="YOUR_TELEGRAM_CHAT_ID" # Checker Configuration CHECK_INTERVAL_SECONDS=1200 # Default check interval in seconds (e.g., 1200 for 20 minutes) TARGET_URL="https://www.baselhack.ch/index.php?p=actions/sprig-core/components/render&sprig%3Aconfig=de1263fa40f93733713fe33b328388ebf8598d21ac75f3a0c817ef386a8d91a1%7B%22id%22%3A%22ticket%22%2C%22siteId%22%3A2%2C%22template%22%3A%22_components%5C%2Fsprig%5C%2Fproduct.twig%22%2C%22variables%22%3A%7B%22productId%22%3A13662%7D%7D" # Email Notification Configuration (for when tickets are found) EMAIL_HOST="smtp.gmail.com" # Example for Gmail EMAIL_PORT=587 EMAIL_USE_TLS=True EMAIL_HOST_USER="[email protected]" EMAIL_HOST_PASSWORD="your_gmail_app_password" # Use an App Password for Gmail EMAIL_RECIPIENT="[email protected]"
Note on Gmail: If you are using a Gmail account to send emails, you'll need to generate an "App Password" for this bot. You can find instructions on how to do that here.
To run the bot directly from your terminal (for testing or development):
source venv/bin/activate
python bot.pyTo run the bot as a persistent background service on a Linux server:
-
Edit the service file: Open
basel-hack-ticket-bot.serviceand replace the placeholder values with your actual user, group, and project path.User=your_userGroup=your_groupWorkingDirectory=/path/to/your/basel-hack-ticket-botExecStart=/path/to/your/basel-hack-ticket-bot/venv/bin/python bot.py
-
Install and start the service:
# Move the service file to the systemd directory sudo cp basel-hack-ticket-bot.service /etc/systemd/system/ # Reload the systemd daemon to recognize the new service sudo systemctl daemon-reload # Enable the service to start on boot sudo systemctl enable basel-hack-ticket-bot.service # Start the service immediately sudo systemctl start basel-hack-ticket-bot.service
-
Check the service status: You can check if the service is running correctly with:
sudo systemctl status basel-hack-ticket-bot.service
And view its logs with:
sudo journalctl -u basel-hack-ticket-bot -f
Disclaimer: This bot is for educational purposes. Please use it responsibly and respect the website's terms of service.