Skip to content

teknologi-umum/botnet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– BotNet

A feature-rich, production-grade Telegram bot built with .NET 10 β€” featuring AI conversations, code execution, image generation, weather forecasts, and more.

.NET License

✨ Features

🧠 AI & Conversations

  • 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

🎨 Creative Tools

  • 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

πŸ’» Code Execution

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

🌦️ Information Services

  • 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

πŸ”§ Available Commands

AI & Creative

  • /ask [question] - Chat with AI (GPT-4 or Gemini), supports threaded conversations
  • /art [prompt] - Generate AI images with DALL-E 3 or Stability.ai

Code & Data

  • /exec [code] or /python, /js, /cpp, etc. - Execute code in 20+ languages

Information

  • /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

Fun & Misc

  • /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)

πŸ—οΈ Architecture

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)

πŸ“Š Production-Ready

  • 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

πŸš€ Quick Start

Prerequisites

Build and Run

  1. Clone the repository:

    git clone https://github.com/teknologi-umum/botnet.git
    cd botnet
  2. 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
  3. Run the bot:

    dotnet run --project BotNet

Docker Deployment

docker build -t botnet .
docker run -e BotOptions__AccessToken=your-token botnet

Configuration

Required 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"
}

πŸ’» Using Visual Studio Code

Prerequisites

Setting Up User Secrets

  1. Open the Solution Explorer in VSCode
  2. Right-click on the BotNet project
  3. Select Manage User Secrets
  4. 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"
}

Building the Project

  1. Open the Solution Explorer in VSCode
  2. Right-click on the BotNet project
  3. Select Build

Running the Bot

  1. Open the Solution Explorer in VSCode
  2. Right-click on the BotNet project
  3. Select Run or Debug

The bot will start and connect to Telegram. You'll see log output in the Debug Console.

Running Tests

  1. Open the Solution Explorer in VSCode
  2. Right-click on the BotNet.Tests project
  3. Select Test

Alternatively, use the Test Explorer panel (beaker icon in the sidebar).

Recommended Extensions

πŸ› οΈ Development

Project Structure

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

Running Tests

dotnet test BotNet.Tests/BotNet.Tests.csproj

🀝 Contributing

We welcome contributions! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Follow the coding conventions:
    • βœ… Use explicit types (no var)
    • βœ… Use records for immutable DTOs
    • βœ… Constructor injection for dependencies
    • βœ… Sequential command processing via queue
  4. Write tests for new features
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

Built with ❀️ by Teknologi Umum community.


Live Bot: Try it at @TeknumBot (if deployed)

About

Telegram Bot written in .NET

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 9

Languages