A robust Telegram bot functioning as a system orchestrator for your Linux machine. Built with .NET 9, this application incorporates both a generic Worker Service (for long-polling Telegram messages) and a Minimal API WebHost (for receiving system Webhooks).
The current implementation utilizes Clean Architecture, the Command Pattern, and strict Authorization Policies to ensure secure interactions.
Currently migrated/implemented commands under the new .NET core:
| Command | Description |
|---|---|
/shell <cmd> |
Securely executes any Bash shell command with timeouts. |
/k8s <cmd> |
Executes Kubernetes commands specifically bound to ~/Documents/Documents/K8s/Setup. |
/ask <prompt> |
Sends natural language prompts to your local external Python script gemini_cli.py. |
/upload |
Whenever you upload a document in chat, it receives and locally saves it to ~/Downloads. |
n8n Webhook |
The bot runs a local Minimal API listening at POST /webhook/n8n to alert you of automated signals (e.g. trading alerts). |
- Strict User Authorization: The bot ignores all messages and updates that do not match the configured
ALLOWED_CHAT_ID, guaranteeing that only the owner can trigger orchestrations.
- Worker Service: Uses generic
IHostedServiceto listen for Telegram events transparently. - Dependency Injection: Services (
IShellService,IGeminiService), Commands, and the DB Context are modularly configured in the DI Container. - SQLite Database (EF Core): Maintains entity sets for
ChatMessageandStoryState. Automatically createsMyLinuxBot.dblocally.
1. Install Prerequisites: Ensure you have the .NET 9 SDK installed on your Linux machine.
2. Clone the repository:
git clone https://github.com/My-Own-Working-Space/TelegramBot.git
cd TelegramBot/MyLinuxBot3. Set Environment Variables:
Create or edit the .env file within the MyLinuxBot/ folder:
TELEGRAM_BOT_TOKEN=your_token_from_botfather
ALLOWED_CHAT_ID=your_telegram_user_idNavigate to the .NET application root folder and use the .NET CLI:
cd MyLinuxBot
dotnet build
dotnet runOptionally, you can utilize the included Dockerfile to build an optimized Linux Container.
MIT