This repository hosts the source code for a versatile Telegram bot powered by large language models (LLMs). It allows users to interact with AI for various tasks, including image analysis, image creation, web searches for quick answers, and maintaining notes across conversations.
- 🤖 AI Interaction: Chat directly with powerful AI models.
- 🖼️ Image Recognition: Analyze images sent to the bot to understand their content.
- 🎨 Image Generation: Create images based on user descriptions or prompts.
- 🌐 Internet Search: Fetch answers to simple questions using web search capabilities.
- 📝 Note-Taking: A personal diary feature to save notes, reminders, or text snippets between chat sessions.
- ⚙️ Multiple Modes: Switch between different interaction modes like 'general', 'teacher', etc., to tailor the AI's responses.
- ✨ Choice of AI Provider: Supports both Anthropic (Claude) and Google (Gemini) models.
Follow these steps to get your own instance of the bot running.
- .NET 8 SDK and Runtime: Ensure you have the necessary .NET version installed on your system.
- Telegram Bot Token: Obtain a token from BotFather on Telegram.
- AI Provider API Key: Get an API key from either Anthropic or Google, depending on which AI you plan to use.
You can either build the bot from the source code or use pre-compiled binaries.
Option 1: Build from Source
- Clone the Repository:
git clone https://github.com/AleksandrFurmenkovOfficial/ChatWithAI.git cd ChatWithAI - Build the Application:
The executable will typically be found in
dotnet build --configuration Release
bin/Release/net8.0/.
Option 2: Use Pre-compiled Binaries
- Download the latest release binaries from the Releases page.
- Extract the downloaded archive.
Configure the bot using environment variables before running it.
Core Settings:
TELEGRAM_BOT_KEY: (Required) Your Telegram bot token obtained from BotFather.AI_PROVIDER: (Required) Specify the AI provider to use. Set to either"anthropic"or"google".TELEGRAM_ADMIN_USER_ID: (Optional) Your Telegram User ID for administrative commands or privileges.CHAT_CACHE_ALIVE_IN_MINUTES: (Optional) Duration in minutes before a chat session context is reset for non-premium users. Defaults to"5".
AI Provider Settings (Configure one set based on AI_PROVIDER):
-
If
AI_PROVIDERis"anthropic":ANTHROPIC_API_KEY: (Required) Your Anthropic API key.ANTHROPIC_MODEL: (Required) The model to use:"claude-3-7-sonnet-20250219".ANTHROPIC_TEMPERATURE: (Optional) Controls randomness (e.g.,"0.4"). Default value might apply if unset.ANTHROPIC_MAX_TOKENS: (Optional) Maximum tokens for the response (e.g.,"8192"). Default value might apply if unset.
-
If
AI_PROVIDERis"google":GOOGLE_API_KEY: (Required) Your Google AI API key.GOOGLE_MODEL: (Required) The model to use. Choose from"gemini-2.5-pro-preview-03-25"or"gemini-2.5-flash-preview-04-17".GOOGLE_TEMPERATURE: (Optional) Controls randomness (e.g.,"0.4"). Default value might apply if unset.GOOGLE_MAX_TOKENS: (Optional) Maximum tokens for the response (e.g.,"65536"). Default value might apply if unset.
Note: Ensure you set the required variables for the AI provider you selected.
Storage Paths:
The application uses several folders for storing data. Default paths are relative to the executable's location, but can be overridden using environment variables.
-
AI Memory (
MEMORY_FOLDER)- Purpose: Stores conversation history and context for each user session.
- Default Path:
../AiMemory - Permissions: The application needs read, write, and create file permissions within this directory to manage session data.
- Environment Variable:
MEMORY_FOLDER
-
Modes (
MODES_FOLDER)- Purpose: Contains definitions for the available AI interaction modes (e.g., 'teacher', 'translator'). This folder is treated as read-only by the application during runtime.
- Default Path:
Modes(within the executable's directory) - Content: Place plain text files (
.txt) here, where each file's name represents a mode, and its content defines the initial prompt or instructions for that mode. - Implementation: Ensure you have corresponding command classes (similar to
SetBaseMode.cs) implemented to allow users to switch to these defined modes. - Environment Variable:
MODES_FOLDER
-
Access Control (
ACCESS_FOLDER)- Purpose: Manages user access permissions. This folder is treated as read-only by the application during runtime.
- Default Path:
../Access - Content:
ids.txt(Optional): If present, contains a list of Telegram User IDs (one ID per line) allowed to interact with the bot. If this file doesn't exist or is empty, access might be open (depending on implementation).premium_ids.txt(Optional): If present, contains a list of Telegram User IDs (one ID per line) designated as premium users. For these users, the chat session cache (CHAT_CACHE_ALIVE_IN_MINUTES) is ignored, and the full conversation context is preserved indefinitely within theMEMORY_FOLDER.
- Environment Variable:
ACCESS_FOLDER
Make sure these folders exist with the correct structure and content before running the application, and ensure the application has the necessary permissions, especially for the MEMORY_FOLDER.
- Set the environment variables defined in the Configuration section (Core, AI Provider, and optionally Storage Paths). How you set them depends on your operating system (e.g., using
exporton Linux/macOS,setor System Properties on Windows, or a.envfile if supported by your setup). - Ensure the directories specified by
MODES_FOLDERandACCESS_FOLDERexist and contain the necessary files (mode definitions,ids.txt,premium_ids.txtif used). - Ensure the directory specified by
MEMORY_FOLDERexists and the application has write permissions to it. - Navigate to the directory containing the executable (either from your build output or the extracted binary).
- Run the application:
On Windows, it might be:
# Replace 'YourExecutableName' with the actual name, e.g., ChatWithAI ./YourExecutableNameYourExecutableName.exe
- Open Telegram and start chatting with your bot!
PS ChatWithAI.Plugins.Windows.ScreenshotCapture is a bonus for Windows users (^_^). It will be ignored for other platforms, feel free to remove it.