Meow
  • Python 89%
  • HTML 10.4%
  • Makefile 0.4%
  • Dockerfile 0.2%
Find a file
IgorVasilekIV d282773dc0
Some checks failed
CI / lint (push) Has been cancelled
CodeQL Security Analysis / analyze (push) Has been cancelled
CI / test (push) Has been cancelled
fix: debug message.chat.type only when needed
2026-08-04 20:12:14 +07:00
.github/workflows Add permissions to CI workflow to fix CodeQL alerts 2026-07-20 19:01:29 +07:00
ai replace deprecated 2.5 flash lite model in classification 2026-08-03 03:09:36 +07:00
assets update avatar 2026-07-20 08:23:52 +07:00
handlers fix: debug message.chat.type only when needed 2026-08-04 20:12:14 +07:00
locales fix: <blockquote> formatting in locales 2026-08-03 11:00:50 +07:00
tests fix: trial decrement in inline/groups, fsm fix, more locales, /lang direct input 2026-07-20 06:37:18 +07:00
.dockerignore Refactor classification function and related tests; add HTML response template 2026-07-19 05:44:51 +07:00
.env.example Some fixes with openai.trial_response 2026-08-01 20:01:11 +07:00
.gitignore Refactor and prepare for open-source release 2026-07-19 02:12:08 +07:00
.pre-commit-config.yaml Refactor and prepare for open-source release 2026-07-19 02:12:08 +07:00
CHANGELOG.md changelog upd 2026-07-20 07:23:14 +07:00
config.py Some fixes with openai.trial_response 2026-08-01 20:01:11 +07:00
CONTRIBUTING.md Refactor and prepare for open-source release 2026-07-19 02:12:08 +07:00
database.py fix: trial decrement in inline/groups, fsm fix, more locales, /lang direct input 2026-07-20 06:37:18 +07:00
docker-compose.yml Refactor and prepare for open-source release 2026-07-19 02:12:08 +07:00
Dockerfile Refactor and prepare for open-source release 2026-07-19 02:12:08 +07:00
LICENSE Refactor and prepare for open-source release 2026-07-19 02:12:08 +07:00
locales.py feat: interactive news broadcast, updated locales 2026-07-26 23:35:57 +07:00
main.py feat: add localized bot commands for ru and en, add /lang to menu 2026-07-20 19:27:32 +07:00
Makefile feat: add docker-logs 2026-08-04 12:52:53 +00:00
pyproject.toml fix: trial decrement in inline/groups, fsm fix, more locales, /lang direct input 2026-07-20 06:37:18 +07:00
README.md Some fixes with openai.trial_response 2026-08-01 20:01:11 +07:00
README_RU.md Some fixes with openai.trial_response 2026-08-01 20:01:11 +07:00
requirements.txt fix: trial decrement in inline/groups, fsm fix, more locales, /lang direct input 2026-07-20 06:37:18 +07:00
utils.py fix: universal media handling in news broadcast 2026-08-03 02:26:14 +07:00

GeminiCommBot

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 @GeminiCommBot in 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 generation
  • model_img — model for image generation
  • system_instruction — system instruction for the model
  • temperature — 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 @GeminiCommBot in 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

MIT License

Support & Contact