This project implements a simple echo Telegram bot with logging capabilities using ClickHouse database. The bot also features user authentication and request throttling.
- Echo Messages: The bot sends back any message it receives from an authorized user.
- User Authentication: Only users that are whitelisted can interact with the bot.
- ClickHouse Logging: All user interactions with the bot are logged in a ClickHouse database.
- Throttling: Users are limited in the number of requests they can send to the bot within a certain time frame to prevent flooding.
Clone the repository and navigate to the cloned directory:
bashCopy code
git clone https://github.com/yourusername/telegram-bot-clickhouse-logging.git cd telegram-bot-clickhouse-logging
- Python 3.8+
- aiohttp
- aiogram
- asynch
- configparser
- ClickHouse server
Install the Python requirements:
bashCopy code
pip install -r requirements.txt
Create a bot on Telegram and get your bot token. How to create a bot
Set up a ClickHouse server. ClickHouse Installation Instructions
In config/settings.ini
:
- Under
[TELEGRAM]
, setBOT_TOKEN
to your Telegram bot token. - Under
[CLICKHOUSE]
, set:HOST
to your ClickHouse server host.PORT
to your ClickHouse server port.DATABASE
to your ClickHouse database name.USER
to your ClickHouse username.PASSWORD
to your ClickHouse password.TABLE
to your ClickHouse table name for logging.
In config/bot_lists.ini
:
- Under
[WHITELIST]
, setLIST
to a comma-separated list of Telegram user IDs that are authorized to use the bot.
To start the bot:
bashCopy code
python function/main_bot.py
The main files and directories in this project include:
function/main_bot.py
: The main bot script.function/bot_helper.py
: Contains helper functions used by the bot.function/bot_middleware.py
: Contains middleware classes for ClickHouse logging, user authentication, and request throttling.bot_config.py
: Sets up the bot, dispatcher, and ClickHouse client.config/
: Directory containing configuration files.
Andrei Siniauski
This project is licensed under the MIT License.
- aiogram for the Python framework for Telegram Bot API.
- aiohttp for the HTTP client/server for asyncio.
- ClickHouse for the open source column-oriented database management system that allows generating analytical data reports in real time.