An intelligent, self-learning Telegram userbot powered by Google's Gemini AI and a persistent MySQL database for long-term memory.
My System is not just a standard userbot; it's a digital extension of the user. It actively listens to conversations it's part of, learns facts about the user, and understands their opinions on various topics. By leveraging a powerful AI model and a structured database, it builds a long-term memory, allowing it to reply to mentions with context, personality, and knowledge that grows over time.
The core philosophy is to create an AI assistant that is indistinguishable from a real person, with an adaptive, witty, and intelligent persona.
- 🧠 AI with Persistent Memory: Learns new facts and opinions from conversations and stores them in a MySQL database, ensuring knowledge is never lost.
- 💬 Context-Aware Replies: Responds intelligently when mentioned by using both short-term (recent chat history) and long-term (facts and opinions) memory.
- 🎭 Adaptive Persona: Dynamically adjusts its response tone based on the context of the query—behaving as a helpful assistant for factual questions, a witty companion for casual chats, and a sharp defender against insults.
- 📜 Advanced Chat Summarization: Quickly get the gist of any conversation with the powerful
.summarizecommand, which can analyze recent messages, unread messages, or messages from a specific user. - 🔒 Secure & Private: Operates as a user account (userbot), giving you full control over its actions and ensuring your data and conversations remain private.
- Core: Python 3.9+
- Telegram API: Telethon
- AI Model: Google Gemini
- Database: MySQL (via aiomysql)
- Configuration: python-dotenv
Follow these steps to get your instance of My System up and running.
- Python 3.9 or higher.
- A running MySQL-compatible database (e.g., local MySQL, PlanetScale, Aiven).
- Your Telegram API_ID and API_HASH. Get them from my.telegram.org.
- A Google API Key for Gemini. Get one from Google AI Studio.
-
Clone the repository:
git clone https://github.com/umaarov/my-system.git cd my-system -
Install the required packages:
pip install -r requirements.txt
-
Configure your environment variables: Create a file named
.envin the project root and populate it with your credentials. You can use the example below as a template.# .env file # --- Telegram Credentials --- API_ID=1234567 API_HASH=your_api_hash_here # --- Google Gemini AI --- GOOGLE_API_KEY=your_google_api_key_here # --- Database Connection --- DB_HOST=your_database_host DB_PORT=3306 DB_USER=your_database_username DB_PASS=your_database_password DB_NAME=your_database_name
-
Set up your user identity: Open
config.pyand change theMY_USERNAMEandMY_ALIASESto match your own Telegram username and real names/nicknames. This is crucial for the bot to know when a message is about you.# config.py MY_USERNAME = "your_telegram_username" MY_ALIASES = ["your_first_name", "your_last_name", "your_nickname"]
-
Initialize the database: Run the setup script once to create all the necessary tables in your database.
python setup_database.py
You should see a success message indicating the tables are ready.
To start the userbot, simply run the main script:
python userbot.pyThe first time you run it, Telethon will ask you to log in with your phone number, password, and 2FA code in the console. After a successful login, a userbot.session file will be created, and subsequent runs will be automatic.
- Summarize Chat: Use the
.summarizecommand in any chat..summarize 50: Summarizes the last 50 messages..summarize @username: Summarizes the last 50 messages from a specific user..summarize unread: Summarizes all unread messages in the chat.
The bot's "memory" is structured across four main tables:
entities: Stores unique nouns identified in conversations (e.g., people, places, topics).facts: Stores specific attributes about entities, particularly the user (e.g.,(entity: dribbblxr, attribute: location, value: Uzbekistan)).user_opinions: Stores the user's sentiment (positive, negative, neutral) towards different entities.conversation_history: Acts as the short-term memory, storing recent messages from chats for contextual replies.