Skip to main content

A Telegram bot that bridges messages directly to OpenCode โ€” an AI coding agent running on your machine

Project description

๐Ÿค– Telegram โ†’ OpenCode Bridge Bot

A lightweight Python bot that bridges your Telegram messages directly to OpenCode โ€” an AI coding agent running on your machine. Think of it as having Claude/GPT-powered coding assistance right in your pocket via Telegram.

โœจ Features

  • Direct OpenCode integration โ€” routes your messages to OpenCode's HTTP API
  • Persistent sessions โ€” conversations maintain context across messages
  • Session management โ€” create, delete, switch, list, and share sessions
  • Model switching โ€” change AI models on the fly (/model)
  • Plan/Build modes โ€” toggle between read-only analysis and full execution
  • Smart formatting โ€” code blocks with syntax highlighting in Telegram
  • Auto message splitting โ€” handles responses longer than Telegram's 4096 char limit
  • Security โ€” whitelist-based access control + rate limiting
  • Workspace Switching โ€” Switching from one workspace to another
  • Uploading from Mobile to WorkSpace - U can upload the documents/images from your mobile to the opencode agent workspace
  • Workspace Management โ€” Creation and deletion of the workspace/folder

๐Ÿ“‹ Prerequisites

  1. Python 3.10+
  2. OpenCode CLI โ€” install via:
    npm install -g opencode-ai
    # or
    curl -fsSL https://opencode.ai/install | bash
    
  3. Telegram Bot Token โ€” get one from @BotFather
  4. Your Telegram User ID โ€” send /id to the bot after setup, or use @userinfobot

Quick Installation:

pip install telegram-opencode-bridge-bot==0.1.7
telegram-opencode-bot
telegram-opencode-bot --env (use --env flag if u want to re-configure later anytime)

Manuall Installation:

1. Clone & Install

cd telegram-opencode-bot
pip install -r requirements.txt

2. Run the Bot

python bot.py
python bot.py --env (use --env flag if u want to re-configure later anytime)

๐Ÿ’ก Tip: Don't know your Telegram user ID? Start the bot with AUTHORIZED_USERS=0 temporarily, send /id to the bot, then update the .env with your real ID.

3. Chat!

Open Telegram, find your bot, and start asking! ๐ŸŽ‰

๐Ÿ“ฑ Commands

Command Description
/start Welcome message & connection check
/help Show all commands
/new Start a fresh conversation
/sessions List your recent sessions/conversations and to select a session/conversation
/plan plan mode
/build build mode
/share Share current session/conversation (public URL)
/status Check connection & session details
/id Show your Telegram user ID
/stop Abort active model processing
/models List all available providers, models and to select the model
/project To view the current workspace, sub folder workspaces and to change the workspace
/enable To enable the streaming
/disable To disable the streaming
/create_project To create new project/folder/workspace
/delete_project To create new project/folder/workspace
/delete To delete a conversation

๐Ÿ—๏ธ Architecture

Telegram User
    โ”‚
    โ–ผ
Telegram Bot (Python)
    โ”‚
    โ”œโ”€โ”€โ–บ OpenCode HTTP API (localhost:4096)  โ† primary
            โ”‚
            โ”œโ”€โ”€โ–บ LLM Provider (Claude/GPT/Gemini)
            โ””โ”€โ”€โ–บ Local Filesystem & Shell

โš™๏ธ Configuration

Variable Description Default
TELEGRAM_BOT_TOKEN Bot token from @BotFather Required
AUTHORIZED_USERS Comma-separated Telegram user IDs Required
OPENCODE_SERVER_URL OpenCode HTTP API URL http://localhost:4096
OPENCODE_SERVER_USERNAME OpenCode auth username (empty)
OPENCODE_SERVER_PASSWORD OpenCode auth password (empty)
OPENCODE_MODEL Default AI model anthropic/claude-sonnet-4
OPENCODE_WORK_DIR Working directory for OpenCode .
MAX_MESSAGE_LENGTH Max Telegram message length 4000
RESPONSE_TIMEOUT Max wait for response (seconds) 0
DB_PATH SQLite database path sessions.db

๐Ÿ”’ Security

  • User whitelist โ€” only Telegram user IDs in AUTHORIZED_USERS can use the bot
  • Rate limiting โ€” 20 requests per minute per user (configurable)
  • No public exposure โ€” designed to run on your local machine

โš ๏ธ Warning: This bot executes AI-driven code on your machine. Only authorize trusted users.

๐Ÿ“ Project Structure

telegram-opencode-bot/
โ”œโ”€โ”€ bot.py                  # Main entry point
โ”œโ”€โ”€ config.py               # Environment configuration
โ”œโ”€โ”€ handlers/
โ”‚   โ”œโ”€โ”€ commands.py         # Slash command handlers
โ”‚   โ””โ”€โ”€ messages.py         # Text message โ†’ OpenCode bridge
โ”œโ”€โ”€ opencode/
โ”‚   โ”œโ”€โ”€ client.py           # OpenCode HTTP API client
โ”‚   
โ”œโ”€โ”€ sessions/
โ”‚   โ””โ”€โ”€ manager.py          # Per-user session tracking (SQLite)
โ”œโ”€โ”€ utils/
โ”‚   โ”œโ”€โ”€ formatting.py       # Telegram message formatting
โ”‚   โ””โ”€โ”€ security.py         # Auth, rate limiting, sanitization
โ”œโ”€โ”€ .env.example            # Environment template
โ”œโ”€โ”€ requirements.txt        # Python dependencies
โ””โ”€โ”€ README.md               # This file

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

telegram_opencode_bridge_bot-0.1.7.tar.gz (48.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

telegram_opencode_bridge_bot-0.1.7-py3-none-any.whl (50.8 kB view details)

Uploaded Python 3

File details

Details for the file telegram_opencode_bridge_bot-0.1.7.tar.gz.

File metadata

File hashes

Hashes for telegram_opencode_bridge_bot-0.1.7.tar.gz
Algorithm Hash digest
SHA256 d0e8da8f3f345ede5ee3e2a283ef11803ba04c5221c5d0839a876425a0541e33
MD5 6b94a84a1d6be37443a2c27dd95e3c5e
BLAKE2b-256 de34c6c07b9678b0876e58c108b62a7f97ef1a556687928c88c876e8a73f95ed

See more details on using hashes here.

File details

Details for the file telegram_opencode_bridge_bot-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for telegram_opencode_bridge_bot-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 670763147431c14f95010e8183287442d20bc263415e7e3a9464cc27782cb528
MD5 492b2a0b48afc28957384c80b1bb22e0
BLAKE2b-256 e3b9e8a82e0919a569ed42e10638059995671b238042b48be2c01ed4be9607cc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page