How ruslanriabokin/news_bot_aiogram_dialog works
Overview of the Project
• This project is a Telegram news automation bot whose primary purpose is to automate retrieval, processing (translation and summarization), and scheduled publishing of news items into Telegram channels.
• The system uses various components such as a Telegram bot (powered by aiogram-dialog), a news processing module, a multi-technology database layer, and a web interface (also containing an alternative Azure SQL version) for administration or additional user interaction.
Main Components
a. Telegram Bot Module:
• Files: news_bot.py, bot_create_news_aiogram_dialog.py, bot_router_aiogram_dialog.py, edit_subscriptions_aiogram_dialog.py, states_class_aiogram_dialog.py, subscription_list_aiogram_dialog.py.
• Function: Manages interactions with users via Telegram. It handles input for news topics, ensures admin rights, and triggers dialogues using the aiogram-dialog library.
b. News Processing Module:
• Files: Items under news_processing/ (news_API.py, news_bot_show_topics.py, news_image_processing.py, news_pre_publisher.py, news_publisher.py, processing_API.py, scheduler.py, scrapers.py, ttl_cache_class.py).
• Function: Responsible for interacting with external news APIs, processing the fetched news (including translation and summarization), caching results, and managing schedule/publishing of news content.
c. Database Abstraction Layer:
• Files: Under the db_layer/ directory (abstract_database.py, azure_sql_database.py, my_sql_database.py, sqlite_database.py, db_factory.py, sql_data_service.py).
• Function: Provides an abstraction for different database engines (SQLite, MySQL, Azure SQL) to store topics, subscriptions, and possibly logs or configuration data.
d. Configuration:
• File: config.py.
• Function: Contains necessary API keys, tokens, and settings that link together the various modules such as the Telegram Bot and the news processing integration as well as DB connection details.
e. Web Interface:
• Files: Located in the web_interface/ directory (app.py, app_azure_sql.py, plus static assets and template files).
• Function: Provides a GUI for interacting with the bot’s functionalities, potentially an administrative portal for managing news channels or subscriptions and perhaps monitoring bot performance.
f. Deployment & Auxiliary Scripts:
• Dockerfile and .dockerignore: Used for containerizing the application ensuring consistent deployment.
• Additional instruction files (instruction.pdf, instruction.py) provide usage and deployment guidelines that are also essential design references for deployment strategy.
• requirements.txt: Lists all dependencies relevant to each module.
Understanding the Component Interactions
• The Telegram Bot Module handles user inputs and dispatches commands to the News Processing Module.
• The News Processing Module fetches news through external APIs and then processes the news (translation, summarization, caching) before handing off to the scheduled publishing engine.
• The scheduled publishing component (scheduler.py) ensures that processed news items are published at predetermined intervals or per user specification.
• Database interactions, abstracted in the db_layer, occur both from the Telegram bot and the processing modules to manage dynamic content such as subscription lists, topics, and publishing logs.
• The Web Interface module provides another point of interaction enabling users or administrators to view details and possibly manage configurations, often interacting with the database as well.
• Docker and configuration files tie all components together and allow for well-defined environmental setups.
Architectural Patterns and Design Principles
• Separation of Concerns: Each module (dialog bot, news processing, database layer, web interface) is responsible for a distinct part of the functionality.
• Abstraction Layer for Databases: The db_layer uses abstract classes and a factory pattern (db_factory.py) to handle multiple database backends.
• API-Driven Processing: The system relies on external news APIs which necessitate a clear definition of the API integration points.
• Modular Design: Distinct directories for news processing, database interactions, and web components suggest a modular approach that can be further decomposed if the project scales.
• Scheduler Component: Following a scheduled-based pattern to trigger periodic publishing.
Essential Elements
• Components: Telegram Bot, News Processing (sub-components like API interactions, processing logic, scheduler), Database Abstraction Layer, Web Interface.
• Labels and Technology Stack: Annotate each component with references to technologies used (e.g., aiogram-dialog for Telegram, Python libraries for translation/summarization, Docker for deployment, specific DB libraries).
• Environment & Deployment: Represent Docker as a container boundary, and indicate the use of environment variables and configuration files.