Telegram webhook server that runs Claude Code or Codex in the background
Project description
Telecode
Your AI Terminal Inside Telegram โ Bridge Telegram with Claude Code and Codex. Execute commands, analyze images, transcribe voice, and chat with AIโall from your favorite messenger.
โจ Features
- ๐ค Dual AI Engines โ Switch between Claude Code and Codex on the fly
- ๐ก MCP Server โ Expose AI tools via Model Context Protocol for remote agent access
- ๐ผ๏ธ Vision Processing โ Send screenshots and images for AI analysis
- ๐ค Voice Transcription โ Whisper-powered voice note transcription
- ๐ Text-to-Speech โ Fish Audio integration for audio responses
- โก Real-time Webhooks โ Instant message processing via Telegram webhooks
- ๐ Access Control โ Whitelist users by ID or username
- ๐ฌ Persistent Sessions โ Conversations preserved across messages
๐ Quick Start
Install
pip install telecode
Run
telecode
On first run, you'll be prompted for:
- Telegram Bot Token (get it from @BotFather)
- ngrok Auth Token (optional, for auto-tunneling)
That's it! Find your bot in Telegram and start chatting.
๐ก MCP Server (NEW)
Telecode can expose AI tools via the Model Context Protocol, allowing remote agents to access your local AI engines:
Enable MCP Server
telecode --enable-mcp
The server will display your MCP connection URL:
+----------------------------------------------------+
| MCP Server Configuration: |
| |
| URL: https://your-tunnel.ngrok-free.app/mcp/ |
| (Public ngrok URL - share with remote MCP clients)|
| |
| Available Tools: |
| - local_claude_code: Execute Claude Code CLI |
| - local_codex: Execute Codex CLI |
| - local_cli: Execute shell commands |
+----------------------------------------------------+
MCP Tools
local_claude_codeโ Execute prompts with Claude Code CLIlocal_codexโ Execute prompts with Codex CLIlocal_cliโ Run shell commands on your server
MCP clients can connect to your server and use these tools remotely. Sessions are independent from Telegram, allowing simultaneous use.
๐ฌ Telegram Commands
| Command | Description |
|---|---|
/engine |
Show current AI engine |
/claude |
Switch to Claude Code |
/codex |
Switch to Codex |
/cli <cmd> |
Execute shell command |
/tts_on |
Enable TTS audio responses |
/tts_off |
Disable TTS responses |
๐ฏ Usage Examples
Chat with AI
Simply send any message to interact with the current engine:
You: Write a Python function to reverse a string
Bot: Here's a simple function:
def reverse_string(s):
return s[::-1]
Analyze Images
Send a photo with a caption:
[Screenshot of error]
Caption: "What's causing this bug?"
Bot: This is a NullPointerException at line 42...
Execute Commands
/cli git status
Bot: On branch main
Your branch is up to date...
Voice Messages
Hold the mic button, speak your prompt, release. The bot transcribes and responds.
โ๏ธ Configuration
Configuration is stored in .telecode (local) or ~/.telecode (global):
TELEGRAM_BOT_TOKEN=123456789:ABCdefGHIjklMNOpqrsTUVwxyz
TELECODE_ENGINE=claude
TELECODE_ALLOWED_USERS=123456789,@username
TELECODE_ENABLE_MCP=1
TELECODE_VERBOSE=1
Key Configuration Options
| Variable | Description | Default |
|---|---|---|
TELEGRAM_BOT_TOKEN |
Bot token from @BotFather | Required |
TELEGRAM_TUNNEL_URL |
Public webhook URL | Auto via ngrok |
TELECODE_ENGINE |
Default engine: claude or codex |
claude |
TELECODE_ENABLE_MCP |
Enable MCP server | 0 |
TELECODE_ALLOWED_USERS |
User whitelist (IDs/@usernames) | (empty = all) |
TELECODE_VERBOSE |
Enable verbose logging | 0 |
TELECODE_TTS |
Enable TTS responses | 0 |
๐ Access Control
Restrict bot access to specific users:
# By user ID (get from @userinfobot)
TELECODE_ALLOWED_USERS=123456789,987654321
# By username
TELECODE_ALLOWED_USERS=@alice,@bob
# Mixed
TELECODE_ALLOWED_USERS=123456789,@alice
Leave empty to allow all users.
๐ ๏ธ Development
# Clone and install
git clone https://github.com/polinom/telecode.git
cd telecode
pip install -e .
# Run with auto-reload
telecode --reload -v
# Run tests
pytest -q
CLI Options
telecode --help
Options:
--host HOST Host to bind (default: 0.0.0.0)
--port PORT Port to bind (default: 8000)
--reload Enable auto-reload (dev mode)
--engine {claude,codex} Default engine
--no-ngrok Disable ngrok auto-start
--enable-mcp Enable MCP server
-v, --verbose Enable verbose logging
๐๏ธ Architecture
โโโโโโโโโโโโโโโ
โ Telegram โ
โ Bot API โ
โโโโโโโโฌโโโโโโโ
โ HTTPS
โผ
โโโโโโโโโโโโโโโโ
โ ngrok Tunnel โ
โโโโโโโโฌโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ FastAPI Server โโโโโโถโ MCP Clients โ
โ (Port 8000) โ โโโโโโโโโโโโโโโ
โโโโโโโโฌโโโโโโโโโโโโ
โ
โโโโโดโโโโ
โผ โผ
โโโโโโโโโโ โโโโโโโโโ
โ Claude โ โ Codex โ
โโโโโโโโโโ โโโโโโโโโ
๐ Documentation
- User Guide โ Website with examples
- CLAUDE.md โ Developer guide for AI assistants
- GitHub Issues โ Bug reports and feature requests
๐ง Troubleshooting
Bot doesn't respond
- Check webhook URL is accessible
- Run with
-vfor verbose logs - Verify bot token with @userinfobot
Voice messages fail
pip install openai-whisper
brew install ffmpeg # macOS
Invalid bot token error
The CLI will detect invalid tokens and prompt for a new one automatically.
ngrok authentication failed
Get your auth token from ngrok.com and paste when prompted.
๐ License
MIT โ See LICENSE for details.
Contributing: Issues and PRs welcome! โข Security: Never commit tokens or API keys
โญ Star on GitHub if you find this useful!
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
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 telecode-0.1.6.tar.gz.
File metadata
- Download URL: telecode-0.1.6.tar.gz
- Upload date:
- Size: 27.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2a515b4f519d6d0b28d66622d99daefa80ccb139ba2254a8c3d7e70375f58f4
|
|
| MD5 |
e0bdd990a8d4bf541702a39527cab00f
|
|
| BLAKE2b-256 |
bbc3f6332e874ef2a7b4c5f2efee9148a44a7d59d9e9acbd6d2100a31d0ce125
|
Provenance
The following attestation bundles were made for telecode-0.1.6.tar.gz:
Publisher:
release.yml on polinom/telecode
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
telecode-0.1.6.tar.gz -
Subject digest:
d2a515b4f519d6d0b28d66622d99daefa80ccb139ba2254a8c3d7e70375f58f4 - Sigstore transparency entry: 812314192
- Sigstore integration time:
-
Permalink:
polinom/telecode@46ef0c5f395f83fe3981cf56da2b4b9b6bcb626d -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/polinom
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@46ef0c5f395f83fe3981cf56da2b4b9b6bcb626d -
Trigger Event:
push
-
Statement type:
File details
Details for the file telecode-0.1.6-py3-none-any.whl.
File metadata
- Download URL: telecode-0.1.6-py3-none-any.whl
- Upload date:
- Size: 24.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a3b4e06dd1231c48cb9b7136f4b502de705a56a22d81efeebbe5fdb4ffa8ef0
|
|
| MD5 |
ad6cdba3395b0e731ce8262f98c8a43c
|
|
| BLAKE2b-256 |
2a32f17cfc95f12c48e90d6f221071ef50a34b3c57ae5067875be411e865ad54
|
Provenance
The following attestation bundles were made for telecode-0.1.6-py3-none-any.whl:
Publisher:
release.yml on polinom/telecode
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
telecode-0.1.6-py3-none-any.whl -
Subject digest:
9a3b4e06dd1231c48cb9b7136f4b502de705a56a22d81efeebbe5fdb4ffa8ef0 - Sigstore transparency entry: 812314197
- Sigstore integration time:
-
Permalink:
polinom/telecode@46ef0c5f395f83fe3981cf56da2b4b9b6bcb626d -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/polinom
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@46ef0c5f395f83fe3981cf56da2b4b9b6bcb626d -
Trigger Event:
push
-
Statement type: