Skip to main content

Telegram webhook server that runs Claude Code or Codex in the background

Project description

Telecode

Tests PyPI

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 CLI
  • local_codex โ€” Execute prompts with Codex CLI
  • local_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

๐Ÿ”ง Troubleshooting

Bot doesn't respond

  • Check webhook URL is accessible
  • Run with -v for 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

telecode-0.1.6.tar.gz (27.3 kB view details)

Uploaded Source

Built Distribution

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

telecode-0.1.6-py3-none-any.whl (24.8 kB view details)

Uploaded Python 3

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

Hashes for telecode-0.1.6.tar.gz
Algorithm Hash digest
SHA256 d2a515b4f519d6d0b28d66622d99daefa80ccb139ba2254a8c3d7e70375f58f4
MD5 e0bdd990a8d4bf541702a39527cab00f
BLAKE2b-256 bbc3f6332e874ef2a7b4c5f2efee9148a44a7d59d9e9acbd6d2100a31d0ce125

See more details on using hashes here.

Provenance

The following attestation bundles were made for telecode-0.1.6.tar.gz:

Publisher: release.yml on polinom/telecode

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for telecode-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 9a3b4e06dd1231c48cb9b7136f4b502de705a56a22d81efeebbe5fdb4ffa8ef0
MD5 ad6cdba3395b0e731ce8262f98c8a43c
BLAKE2b-256 2a32f17cfc95f12c48e90d6f221071ef50a34b3c57ae5067875be411e865ad54

See more details on using hashes here.

Provenance

The following attestation bundles were made for telecode-0.1.6-py3-none-any.whl:

Publisher: release.yml on polinom/telecode

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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