A Telegram bot and a companion web server to save and manage bookmarks from HackerNews and other websites. The application is fully containerized using Docker for easy setup and deployment.
- Telegram Bot: Save links directly from your "Saved Messages" or any private chat with the bot.
- Web Interface: A modern web UI to view, search, filter, and manage your bookmarks.
- Metadata Scraping: Automatically fetches the title, description, and preview image for each link.
- HackerNews Integration: Special handling for HackerNews links to associate an article with its comments page.
- Multi-user & Multilingual Support: The web interface supports multiple users and is available in English and Italian, with automatic language detection and a manual selector. It's easily extensible to other languages.
- Dockerized: All services (bot, webserver, database migration) are containerized for a consistent and isolated environment.
- Testing Suite: Includes a suite of unit and integration tests to ensure code quality and reliability.
Before launching the application, you need to configure a few environment variables.
Create a file named .env inside the telegram_bot/ folder.
# Example file: telegram_bot/.env
API_ID=1234567
API_HASH=abcdef1234567890abcdef1234567890
BOT_TOKEN=1234567890:ABC-DEF1234567890ABC-DEF1234567890
# Set the webserver username to which the bot will associate the bookmarks
WEB_USERNAME=my_web_userAPI_IDeAPI_HASH: Ottienili da my.telegram.org.BOT_TOKEN: Ottienilo da @BotFather su Telegram.WEB_USERNAME: Inserisci il nome utente che creerai per l'interfaccia web (vedi passo successivo).
Il bot ha bisogno di un utente del webserver a cui associare i bookmark. Esegui lo script add_user.py per creare questo utente.
-
Installa la dipendenza necessaria (solo per questo script):
pip install werkzeug
-
Esegui lo script e segui le istruzioni per creare un utente. Assicurati che il nome utente corrisponda a
WEB_USERNAMEimpostato nel file.envdel bot.python add_user.py
Dalla cartella principale del progetto, esegui questo comando:
docker-compose up --build -dQuesto comando:
--build: Ricostruisce le immagini Docker per includere le tue configurazioni.-d: Avvia i container in background (detached mode).
-
Web Interface: Apri il browser e vai su
https://localhost:8443.- Il browser mostrerà un avviso di sicurezza a causa del certificato autofirmato. Accetta il rischio e procedi.
- Effettua il login con le credenziali create con
add_user.py. - L'interfaccia rileverà automaticamente la lingua del tuo browser. Puoi cambiarla manualmente usando il selettore in alto a destra.
-
Telegram Bot: Avvia una chat con il tuo bot su Telegram e inviagli dei link. Appariranno istantaneamente nell'interfaccia web!
Per fermare tutti i container, esegui:
docker-compose downQuesto comando ferma e rimuove i container e la rete, ma non cancella i dati salvati nei volumi (database, sessione del bot e certificati SSL).
L'interfaccia web supporta più lingue (attualmente inglese e italiano).
La lingua viene determinata con la seguente priorità:
- Parametro URL: Puoi forzare una lingua aggiungendo
?lang=ito?lang=enall'URL. - Cookie: Se hai già selezionato una lingua, la scelta viene salvata in un cookie (
lang) e riutilizzata. - Header del Browser: Se non ci sono cookie o parametri, il server controlla l'header
Accept-Languageinviato dal tuo browser. - Default: Se nessuna delle opzioni precedenti ha successo, viene usato l'inglese (
en).
- Crea il file di traduzione: Nella cartella
webserver/locales/, crea un nuovo file JSON (es.es.jsonper lo spagnolo). Copia il contenuto dien.jsone traduci tutti i valori. - Aggiorna il server: Apri
webserver/server.pye aggiungi il nuovo codice lingua alla listaSUPPORTED_LANGUAGES.SUPPORTED_LANGUAGES = ['en', 'it', 'es'] # Aggiungi 'es'
- Aggiorna l'interfaccia: Apri
webserver/htmldata.pye aggiungi la nuova opzione al menu a tendina<select id="langSelector">.
- Docker
- Docker Compose
a. Configure the Bot: Create a file named .env inside the telegram_bot/ folder with your Telegram API credentials and the target web user.
# Example file: telegram_bot/.env
API_ID=...
API_HASH=...
BOT_TOKEN=...
WEB_USERNAME=my_web_userb. Create a Web User: The bot needs a webserver user to associate bookmarks with. Run the add_user.py script. Make sure the username you create matches the WEB_USERNAME you set in the bot's .env file.
# Install dependency (for this script only)
pip install werkzeug
# Run the script and follow the prompts
python add_user.pyFrom the project root directory, run:
docker-compose up --build -d- Web Interface: Open your browser and navigate to
https://localhost:8443. You will see a security warning due to the self-signed certificate; please proceed. Log in with the credentials you created. - Telegram Bot: Start a chat with your bot on Telegram and send it links. They will appear in the web interface.
- Language: The interface will automatically detect your browser's language. You can switch it manually using the selector in the top right.
To stop all services, run:
docker-compose down