A Telegram bot that bridges messages directly to OpenCode โ an AI coding agent running on your machine
Project description
๐ค Telegram โ OpenCode Bridge Bot
A premium, feature-rich Python bot that bridges your Telegram client directly to OpenCode โ a powerful AI coding agent running on your local machine. Authorize your personal user account and get professional, agentic software engineering assistance right in your pocket.
โจ Features
- Direct OpenCode Integration โ Routes your chat prompts directly to the OpenCode HTTP API or local server processes.
- Dynamic Project Isolation โ Effortlessly view, create, delete, and switch workspace folders on your local machine using an interactive Telegram file explorer interface.
- Mobile File-Upload Uploads โ Send files, code logs, or images directly from Telegram to upload them into your active workspace folder.
- Robust Session Registry โ Seamlessly list, switch, delete, and share conversations, automatically synced with the backend SQLite database.
- Conversational History View (
/history) โ Chronologically fetches the active conversation, filtered of long execution logs, reasoning traces, or step metadata. Messages are sent sequentially with rate-limit respect and support pagination controls. - Live Tool Execution Streaming โ Watch the agent interact with your filesystem, write code, run bash commands, and search the web in real-time (
/enable//disable). - Flexible Model & Agent Mode Selectors โ Swap underlying LLM models on the fly (
/models) and switch agent personas (e.g. Build, Plan, or Webtester) using clean interactive menus (/mode). - Secure by Default โ Enforces a strict user whitelist check on every message and callback action to prevent unauthorized access.
- Robustness & Windows Stability โ Configured with automated API retries, suppressed verbose network noise, and Selector Event Loops for clean subprocess termination on Windows systems.
๐ Prerequisites
- Python 3.10+ installed on your system.
- OpenCode CLI installed and initialized:
npm install -g opencode-ai # or curl -fsSL https://opencode.ai/install | bash
- Telegram Bot Token โ Obtain one instantly via @BotFather.
- Your Telegram User ID โ Retrieve it using @userinfobot, or start the bot and send
/id.
๐ Installation & Setup
Option A: Standard PyPI Installation
Install and run the bot wrapper directly from the terminal:
pip install telegram-opencode-bridge-bot==0.1.9
telegram-opencode-bot
๐ก Tip: Use the
--envflag anytime to reconfigure your variables:telegram-opencode-bot --env
Option B: Manual Git Installation
-
Clone the repository and install dependencies:
git clone https://github.com/MaheshNagabhairava/telegram-opencode-bridge-bot.git cd telegram-opencode-bot pip install -r requirements.txt
-
Start the bot:
python bot.py
๐ก Tip: Use the
--envflag anytime to reconfigure your variables:python bot.py --env
๐ฑ Command Reference
| Command | Parameter | Description |
|---|---|---|
/start |
โ | Prints the welcome card and verifies connectivity to the OpenCode server. |
/help |
โ | Displays a complete guide of all available commands and tips. |
/new |
โ | Clears the current active session cache to start a fresh topic. |
/stop |
โ | Aborts any active running task or model generation process. |
/status |
โ | Prints detailed statistics about the server connection and active session settings. |
/id |
โ | Displays your Telegram User ID (useful for whitelisting). |
/project |
[name] |
Opens the directory explorer. Optionally switches directly to the specified folder. |
/create_project |
<name> |
Creates a new isolated folder workspace inside your primary workspace path. |
/delete_project |
[name] |
Erases a workspace directory from disk (requires inline button verification). |
/sessions |
โ | Lists your recent conversations in the current workspace to allow switching. |
/history |
[count] |
Displays the chronological history of the active session, split into text batches. |
/delete |
โ | Prompts an inline keyboard to permanently delete a session. |
/models |
โ | Lists all models available on the OpenCode server to easily select a default. |
/mode |
โ | Opens a menu to select agent personas (e.g. Build, Plan, custom testers). |
/plan |
โ | Quick switch shortcut to Plan Mode (read-only analysis). |
/build |
โ | Quick switch shortcut to Build Mode (read, write, execute permissions). |
/enable |
โ | Enables real-time streaming of tool calls, shell executions, and file edits. |
/disable |
โ | Disables streaming; the bot will only report the final LLM response. |
/share |
โ | Fetches a public, shareable web preview URL of the active conversation. |
/update |
โ | Update to a new available version. |
โ๏ธ Configuration Variables
The following parameters can be defined in your .env configuration file:
| Variable | Type | Description | Default |
|---|---|---|---|
TELEGRAM_BOT_TOKEN |
String | Secret token issued by @BotFather. | Required |
AUTHORIZED_USERS |
List | Comma-separated list of whitelisted Telegram User IDs. | Required |
OPENCODE_SERVER_URL |
String | The target URL hosting the OpenCode endpoint. | http://localhost:4096 |
OPENCODE_SERVER_USERNAME |
String | Optional Basic Auth username for server login. | (empty) |
OPENCODE_SERVER_PASSWORD |
String | Optional Basic Auth password for server login. | (empty) |
OPENCODE_MODEL |
String | The default LLM provider/model key configured. | opencode/deepseek-v4-flash-free |
OPENCODE_WORK_DIR |
String | Local parent path containing your projects. | . |
PROJECT_SCAN_DEPTH |
Integer | Max recursion depth used to search project directories. | 2 |
MAX_MESSAGE_LENGTH |
Integer | Maximum character limit before chunking Telegram texts. | 4000 |
RESPONSE_TIMEOUT |
Integer | Request timeout in seconds (set 0 to disable timeouts). |
300 |
DB_PATH |
String | Storage path for the SQLite session manager. | sessions.db |
๐๏ธ Architecture Layout
๐ค Telegram Client (Mobile / Desktop)
โ
โผ (HTTPS Long Polling / Webhook)
๐ค Telegram Bridge Bot (Python)
โ
โผ (HTTP Local API / SSE Events)
๐ป OpenCode Server (localhost:4096)
โ
โโโโโโโโโโดโโโโโโโโโ
โผ โผ
๐ค LLM Provider ๐ Local Workspace
(Claude/DeepSeek/etc.) (Shell / Filesystem)
๐ Security Policy
[!WARNING] This bot allows remote execution of shell commands, filesystem operations, and internet fetching on the host machine.
- Keep
AUTHORIZED_USERSconfigured strictly with your own Telegram User ID.- Avoid exposing your Telegram Bot Token or sharing public URLs if your host machine handles sensitive information.
- Verify tool permissions in the console log if executing arbitrary files.
๐ Project Structure
telegram-opencode-bot/
โโโ bot.py # Main entry point, loops, and setup
โโโ config.py # validated configuration loader
โโโ sessions.db # Persistent SQL database (generated)
โโโ requirements.txt # python dependencies
โโโ handlers/
โ โโโ commands.py # Slash command handlers (/start, /history, etc.)
โ โโโ messages.py # Text & file message routing logic
โโโ opencode/
โ โโโ client.py # Async HTTP client wrapper for OpenCode API
โ โโโ server.py # Background subprocess lifecycle management
โโโ sessions/
โ โโโ manager.py # SQL persistence and state registry
โโโ utils/
โโโ formatting.py # Conversions, splits, and custom table layouts
โโโ security.py # Rate-limiting, whitelist guards, and checks
๐ License
Distributed under the MIT License. See LICENSE for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file telegram_opencode_bridge_bot-0.1.9.tar.gz.
File metadata
- Download URL: telegram_opencode_bridge_bot-0.1.9.tar.gz
- Upload date:
- Size: 55.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
289efe1557665f2897405bef1a601f60c989832e36c6ab10d226eef90e52cdc4
|
|
| MD5 |
ffd5c48c243120621ec4302e1f44475b
|
|
| BLAKE2b-256 |
e17db9681d5a5c2182ae6359ef83592e31824f120be86e657a059eefea260248
|
File details
Details for the file telegram_opencode_bridge_bot-0.1.9-py3-none-any.whl.
File metadata
- Download URL: telegram_opencode_bridge_bot-0.1.9-py3-none-any.whl
- Upload date:
- Size: 56.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3b3ec1a98958d6d50b7510b521c11c73b370c44263dfbd397564545950efc2a
|
|
| MD5 |
4ebbb3b47a497fae031e948224498cea
|
|
| BLAKE2b-256 |
41741efcae962c46ca406f9e112070a4f51818a61f6c92401c5b55ef4d013dd9
|