- Python 89%
- HTML 10.4%
- Makefile 0.4%
- Dockerfile 0.2%
| .github/workflows | ||
| ai | ||
| assets | ||
| handlers | ||
| locales | ||
| tests | ||
| .dockerignore | ||
| .env.example | ||
| .gitignore | ||
| .pre-commit-config.yaml | ||
| CHANGELOG.md | ||
| config.py | ||
| CONTRIBUTING.md | ||
| database.py | ||
| docker-compose.yml | ||
| Dockerfile | ||
| LICENSE | ||
| locales.py | ||
| main.py | ||
| Makefile | ||
| pyproject.toml | ||
| README.md | ||
| README_RU.md | ||
| requirements.txt | ||
| utils.py | ||
Table of Contents
About
GeminiCommBot is a full-featured Telegram bot for working with Google Gemini and OpenAI AI models. It allows users to leverage powerful language models and image generation directly in Telegram, with full support for personal configuration and API key management.
Features
- Google Gemini support: text generation, image analysis, image generation
- OpenAI support: integration with OpenAI API for text generation
- Key management: multiple API keys with automatic rotation
- Flexible configuration: change model, system prompt, generation temperature, and other parameters
- Memory system: Mem0 integration for long-term user memory
- Security: encrypted data storage in the database
- Admin panel: database management, log viewing, notification broadcasting
- Inline mode: use the bot via
@GeminiCommBotin any chat - Beta mode: support for testing new features
Requirements
- Python 3.10+
- Telegram Bot API token from @BotFather
- API keys:
- Google Gemini API key (get one at aistudio.google.com/api-keys)
- OpenAI API key (optional, for OpenAI features)
- Mem0 API token (for memory system)
Installation
1. Clone the repository
git clone https://github.com/IgorVasilekIV/gemini_comm
cd gemini_comm
2. Create a virtual environment
python3 -m venv .venv
source .venv/bin/activate # Linux/macOS
# .venv\Scripts\activate # Windows
3. Install dependencies
pip install -r requirements.txt
Usage
Configure the .env file
Create a .env file in the project root (or copy from .env.example):
# === Bot Tokens ===
MAIN_BOT_TOKEN=xxxxxxxxxx:XXXXX...
TEST_BOT_TOKEN=xxxxxxxxxx:XXXXX...
# === Admin ===
ADMIN_ID=xxxxxxxxxx
# === Database ===
DB_ENCRYPTION_KEY=xxxxxx...
# === AI Services ===
MEM0_TOKEN=m0-xxxxx...
# === Trial (optional) ===
TRIAL_KEY=sk-xxxx
TRIAL_BASE_URL=https://api.xxx
TRIAL_MODEL_CLASSIFICATION=
TRIAL_MODEL_TEXT=
# === Sync Keys (optional) ===
SYNC_KEYS_URL=
# === File Upload (optional) ===
FILE_UPLOAD_URL=https://x0.at
# === Test Keys (optional) ===
TEST_GEMINI_API_KEY=
Generate database encryption key
python3 -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())"
Run the bot
Normal mode:
python3 main.py
Beta mode (with debug logs and test token):
python3 main.py --beta
Using Make (alternative):
make install # install dependencies
make run # normal mode
make run-beta # beta mode
make dev # install with dev dependencies
make lint # run linter
make format # format code
make test # run tests
Project Structure
gemini_comm/
├── main.py # Entry point, bot initialization
├── config.py # Application configuration
├── database.py # SQLite database (with encryption)
├── utils.py # Utilities (file uploads, formatting, memory)
├── requirements.txt # Project dependencies
├── pyproject.toml # Project metadata
│
├── handlers/
│ └── main_handler.py # Main command handlers
│
├── ai/
│ ├── gemini.py # Google Gemini API integration
│ └── openai.py # OpenAI API integration
│
├── tests/
│ ├── test_gemini.py
│ └── test_openai.py
│
├── assets/
│ └── avatar.jpg
│
├── Dockerfile # Docker build
├── docker-compose.yml # Docker Compose configuration
├── Makefile # Development commands
├── LICENSE # MIT License
├── README.md # This file
└── README_RU.md # Russian documentation
Configuration
User configuration system
Each user can configure parameters for Gemini and OpenAI via commands:
Gemini parameters:
api_key— one or more API keys (comma-separated)model— model for text generationmodel_img— model for image generationsystem_instruction— system instruction for the modeltemperature— generation temperature (0.0-2.0)negative_prompt_img— negative prompt for image generation
Database encryption
All sensitive data (API keys) is stored in SQLite with Fernet encryption. The encryption key is loaded from the DB_ENCRYPTION_KEY environment variable.
Commands
Note
< >— required parameter |[ ]— optional parameter
User commands
| Command | Description | Example |
|---|---|---|
/start |
Start the bot, greeting | /start |
/cfg |
View/edit Gemini configuration | /cfg |
/openai |
View/edit OpenAI configuration | /openai |
/fcfg <provider> <parameter> <value> |
Set a parameter | /fcfg gemini model gemini-2.0-flash |
/news |
View latest announcements from admin | /news |
Admin commands
| Command | Description | Example |
|---|---|---|
/logs |
Send the latest log file | /logs |
/getdb <user_id> |
View user configuration | /getdb 123456789 |
/deldb <user_id> |
Delete user configuration | /deldb 123456789 |
/news [title ~ items] |
View latest announcement or create a new one | /news New update ~ Added new model |
Inline mode
Note
Use
@GeminiCommBotin any Telegram chat
| Command | Description |
|---|---|
@GeminiCommBot cfg |
Show Gemini configuration |
@GeminiCommBot openai |
Show OpenAI configuration |
@GeminiCommBot fcfg |
Set a parameter |
@GeminiCommBot [Models] |
View available Gemini models |
@GeminiCommBot <request> |
Send a request to Gemini |
Development
Architecture
Command handling:
- Main router is in handlers/main_handler.py
- Uses aiogram 3.x with FSM (Finite State Machine) for state management
- Inline query support via InlineQuery
AI integration:
- ai/gemini.py — Google Gemini API with key rotation
- ai/openai.py — OpenAI API integration
- Automatic rotation between multiple API keys when quota is exceeded
Database:
- SQLite with Fernet encryption
- Stores each user's configuration and current API key index
- Functions in database.py for CRUD operations
Running tests
python3 -m pytest tests/ -v
python3 -m pytest tests/ --cov=.
Logging
Logging is configured via loguru:
- Normal mode: INFO level
- Beta mode (
--beta): DEBUG level - Logs are output to stderr
License
Support & Contact
- Telegram: @gemini_comm
- Bug reports: create an issue in the repository
- Discussion: @GeminiComm