A feature-rich, production-grade Telegram bot built with .NET 10 β featuring AI conversations, code execution, image generation, weather forecasts, and more.
- GPT-4 & Gemini Integration - Chat with OpenAI GPT-4 or Google Gemini 2.0 Flash
- Thread-Aware Conversations - Maintains context across reply chains
- Image Analysis - GPT-4 Vision support for analyzing images
- Smart Rate Limiting - Prevents abuse while prioritizing VIP users
- AI Image Generation - Create images with DALL-E 3 or Stability.ai SDXL
- Meme Generator - Generate custom memes
- Color Cards - Generate beautiful color palette cards
Execute code in 20+ programming languages directly in Telegram:
- C, C++, C#, F#, VB.NET, TypeScript, JavaScript
- Python, Ruby, PHP, Go, Rust, Java, Kotlin, Scala, Swift
- Clojure, Crystal, Dart, Elixir, Lua, Pascal, Julia
- CommonLisp, SQLite3
- Weather Forecasts - Current weather and forecasts
- BMKG Updates - Indonesian weather agency alerts
- Google Maps - Location search and maps
- Movie Database - Look up movies and TV series with ratings
- Internet Status - Monitor status of major internet services
- Primbon - Indonesian horoscope and predictions
/ask [question]- Chat with AI (GPT-4 or Gemini), supports threaded conversations/art [prompt]- Generate AI images with DALL-E 3 or Stability.ai
/exec [code]or/python,/js,/cpp, etc. - Execute code in 20+ languages
/weather [location]- Get current weather and forecasts/map [query]- Search locations on Google Maps/bmkg- Get Indonesian weather agency (BMKG) updates/movie [title]- Look up movie/TV series info, ratings, and poster/internetstatus- Check status of major internet services
/humor- Get random programming jokes from programmerhumor.io/pick [options]- Random picker (supports space/comma/quoted formats)/primbon [query]- Indonesian horoscope and predictions/khodam [name]- Check your spiritual companion (Indonesian meme)
BotNet uses a sophisticated Command-Handler-Queue pattern built on MediatR:
Telegram Update β UpdateHandler β Command β Queue β Handler β Response
Key Design Principles:
- β Bounded Command Queue - Prevents memory exhaustion (1000 capacity, drop oldest)
- β Rate Limiting - Per-user, per-chat, and per-day limiters with automatic cleanup
- β Background Task Management - Consistent exception handling and metrics
- β Prometheus Metrics - Full observability for production monitoring
- β Memory Leak Prevention - Comprehensive safeguards (see MEMORY_LEAK_AUDIT.md)
- No Critical Memory Leaks - Audited and verified (~500 KB - 4 MB overhead)
- Comprehensive Metrics - Command queue, rate limiters, caches, background tasks
- Exception Handling - Centralized error handling via
BackgroundTask.Run() - Unit Tested - 50+ tests with xUnit and Shouldly
- .NET 10 SDK
- Telegram Bot Token (create one via @BotFather)
-
Clone the repository:
git clone https://github.com/teknologi-umum/botnet.git cd botnet -
Set up secrets:
dotnet user-secrets init --project BotNet dotnet user-secrets set "BotOptions:AccessToken" "your-bot-token" --project BotNet dotnet user-secrets set "HostingOptions:UseLongPolling" "true" --project BotNet
-
Run the bot:
dotnet run --project BotNet
docker build -t botnet .
docker run -e BotOptions__AccessToken=your-token botnetRequired secrets (via User Secrets or environment variables):
{
"BotOptions:AccessToken": "your-telegram-bot-token",
"HostingOptions:UseLongPolling": true,
"OpenAiOptions:ApiKey": "your-openai-key",
"GeminiOptions:ApiKey": "your-gemini-key",
"StabilityOptions:ApiKey": "your-stability-key",
"GoogleMapOptions:ApiKey": "your-google-maps-key",
"OmdbOptions:ApiKey": "your-omdb-api-key"
}- Open the Solution Explorer in VSCode
- Right-click on the BotNet project
- Select Manage User Secrets
- Add the required secrets:
{
"BotOptions:AccessToken": "your-bot-token",
"HostingOptions:UseLongPolling": true
}Optional API keys (add as needed):
{
"BotOptions:AccessToken": "your-bot-token",
"HostingOptions:UseLongPolling": true,
"OpenAiOptions:ApiKey": "your-openai-key",
"GeminiOptions:ApiKey": "your-gemini-key",
"StabilityOptions:ApiKey": "your-stability-key",
"GoogleMapOptions:ApiKey": "your-google-maps-key",
"OmdbOptions:ApiKey": "your-omdb-api-key"
}- Open the Solution Explorer in VSCode
- Right-click on the BotNet project
- Select Build
- Open the Solution Explorer in VSCode
- Right-click on the BotNet project
- Select Run or Debug
The bot will start and connect to Telegram. You'll see log output in the Debug Console.
- Open the Solution Explorer in VSCode
- Right-click on the BotNet.Tests project
- Select Test
Alternatively, use the Test Explorer panel (beaker icon in the sidebar).
- vscode-solution-explorer - Solution Explorer for .NET projects
- C# Dev Kit - Complete C# development experience
- C# - C# language support (included with C# Dev Kit)
- EditorConfig - Maintains consistent coding styles
- GitLens - Enhanced Git capabilities
- Docker - Docker support for containerization
BotNet/ # ASP.NET Core host, webhooks, DI
BotNet.Commands/ # Command DTOs (immutable records)
BotNet.CommandHandlers/ # MediatR handlers (business logic)
BotNet.Services/ # Reusable services (AI, weather, etc.)
BotNet.Tests/ # xUnit tests
dotnet test BotNet.Tests/BotNet.Tests.csprojWe welcome contributions! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Follow the coding conventions:
- β
Use explicit types (no
var) - β Use records for immutable DTOs
- β Constructor injection for dependencies
- β Sequential command processing via queue
- β
Use explicit types (no
- Write tests for new features
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
Built with β€οΈ by Teknologi Umum community.
Live Bot: Try it at @TeknumBot (if deployed)