Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Telegram2OpenCode

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.

Features

  • Multi-bot support — Run multiple Telegram bots simultaneously, each with its own token
  • Automatic sync — Bots marked as Running in 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

Architecture

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

Prerequisites

Getting Started

  1. Clone the repository

    git clone https://github.com/yourusername/Telegram2OpenCode.git
    cd Telegram2OpenCode/Telegram2OpenCode
  2. Configure the database

    Update appsettings.json with your connection string (SQLite by default):

    {
      "ConnectionStrings": {
        "DefaultConnection": "Data Source=Telegram2OpenCode.db"
      }
    }
  3. Configure OpenCode API URL

    {
      "OpenCode": {
        "ApiUrl": "http://localhost:4096"
      }
    }
  4. Apply migrations

    dotnet ef database update
  5. Run the application

    dotnet run
  6. Add a Telegram bot

    • Open the web UI at https://localhost:5001
    • Navigate to Telegram BotsCreate Bot
    • Enter your bot's name, username, and token from BotFather
    • Toggle Start running immediately to start the bot
  7. Chat with your bot

    • Open Telegram and message your bot
    • Send /start to see the menu
    • 1 — Create new session and enter Chat mode
    • 2 — Pick an existing OpenCode session
    • 3 — 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

API Endpoints (OpenCode)

The service communicates with OpenCode via:

Method Endpoint Description
POST /session Create a new conversation
POST /session/{id}/message Send message and get reply

Configuration

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

Stack

  • 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

License

MIT

About

OpenCode Telegram Bridge

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages