A Blazor web application that bridges Telegram bots with the OpenCode AI agent platform. Manage your Telegram bots and AI agents through a web UI, while the bot service automatically creates OpenCode sessions and forwards messages between Telegram and OpenCode.
- Multi-bot support — Run multiple Telegram bots simultaneously, each with its own token
- Automatic sync — Bots marked as
Runningin the database are automatically started; removing the flag stops them - OpenCode integration — Each chat session creates an OpenCode conversation and forwards messages
- SQLite database — Lightweight, zero-configuration storage
Telegram2OpenCode/
├── Components/ # Blazor UI components
│ ├── Pages/
│ │ ├── AiAgent/ # CRUD pages for AI agents
│ │ ├── TelegramBot/ # CRUD pages for Telegram bots
│ │ └── Home.razor # Landing page
│ └── Layout/ # Main layout and navigation
├── Data/ # EF Core DbContext
├── DTOs/ # Data transfer objects with validation
│ └── Mapping/ # Entity ↔ DTO mapping
├── Migrations/ # EF Core migrations
├── Models/ # Entity models (AiAgent, TelegramBot, ChatSessionEntity)
├── Repositories/ # Data access layer (IAiAgentRepository, ITelegramBotRepository, IChatSessionRepository)
├── Services/
│ ├── BotService.cs # Singleton hosted service managing bot clients
│ ├── OpenCodeManager.cs # OpenCode REST API client
│ ├── OpenCodeRunner.cs # CLI wrapper for the opencode executable
│ └── VibeUtils.cs # AI-powered folder path resolution
└── TelegramChatManager/ # Chat session state machine
├── ChatState.cs # Finite state machine enum
└── TelegramChatSession.cs
- .NET 10 SDK
- A Telegram Bot Token from BotFather
- (Optional) An OpenCode instance
-
Clone the repository
git clone https://github.com/yourusername/Telegram2OpenCode.git cd Telegram2OpenCode/Telegram2OpenCode -
Configure the database
Update
appsettings.jsonwith your connection string (SQLite by default):{ "ConnectionStrings": { "DefaultConnection": "Data Source=Telegram2OpenCode.db" } } -
Configure OpenCode API URL
{ "OpenCode": { "ApiUrl": "http://localhost:4096" } } -
Apply migrations
dotnet ef database update
-
Run the application
dotnet run
-
Add a Telegram bot
- Open the web UI at
https://localhost:5001 - Navigate to Telegram Bots → Create Bot
- Enter your bot's name, username, and token from BotFather
- Toggle Start running immediately to start the bot
- Open the web UI at
-
Chat with your bot
- Open Telegram and message your bot
- Send
/startto see the menu 1— Create new session and enter Chat mode2— Pick an existing OpenCode session3— Describe a folder to open (e.g. "my projects folder")- In Chat mode, any message is forwarded to OpenCode and the reply is sent back
The service communicates with OpenCode via:
| Method | Endpoint | Description |
|---|---|---|
| POST | /session |
Create a new conversation |
| POST | /session/{id}/message |
Send message and get reply |
All settings are in appsettings.json:
| Key | Description | Default |
|---|---|---|
ConnectionStrings:DefaultConnection |
SQLite database path | Data Source=Telegram2OpenCode.db |
OpenCode:ApiUrl |
OpenCode API base URL | http://localhost:5000 |
- Frontend: Blazor Server with Interactive Server rendering, Bootstrap 5, inline SVG icons
- Backend: ASP.NET Core, Entity Framework Core
- Database: SQLite
- Bot Library: Telegram.Bot (v22)
- Target: .NET 10
MIT