michi_ai_bot - Telegram Integration for Claude Code

Natural language interface to Claude Code content generation workflows.

Chat with Claude Code via Telegram! Send any message to your bot and Claude Code handles the rest - from simple code generation to complex content creation with automatic git commits.

Quick Start

# 1. Get bot token from @BotFather on Telegram
# 2. Get your Telegram user ID from @userinfobot
# 3. Setup
cp .env.example .env
nano .env  # Add your bot token and user ID

# 4. Install & Run
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
./start_bot.sh

# 5. Message your bot on Telegram!

Features

  • 🤖 Direct Claude Code CLI integration - No intermediary LLM, your message goes straight to Claude

  • 🎨 Content generation - Manga comics, infographics, slides, and more via Claude Code skills

  • 📝 Automatic git commits - Generated content is automatically committed with conventional messages

  • 📊 Real-time progress updates - See what Claude is doing as it works

  • 🔒 Single-user authorization - Only your Telegram account can use your bot

  • Simple architecture - Telegram → Claude Code → Results (no parsing layer!)

Setup

1. Get Telegram Bot Token

  1. Message @BotFather on Telegram

  2. Create new bot: /newbot

  3. Choose name: "Michi AI Bot"

  4. Choose username: michi_ai_bot

  5. Copy token:

2. Get Your Telegram User ID

  1. Message @userinfobot

  2. Copy your user ID (e.g., 123456789)

3. Configure Environment

Fill in:

  • TELEGRAM_BOT_TOKEN: From @BotFather

  • TELEGRAM_ADMIN_USER_ID: From @userinfobot

  • Other values should be correct by default (Claude Code binary path and working directory)

4. Install Dependencies

5. Run Bot

Easy way (recommended):

Manual way:

Expected output:

Usage

Basic Commands

  • /start - Show welcome message

  • /help - Show help

  • /status - Check bot status

Natural Language Instructions

Example 1: Simple analysis

Example 2: Generate comic

Example 3: Create infographic

Usage Examples with Expected Output

Example 1: Simple Code Generation

Example 2: URL Analysis

Example 3: Complex Workflow

Example 4: Using Specific Skills

Workflow Keywords

Claude Code understands natural language, so you can phrase requests any way you like. Common patterns:

  • Content Analysis: "analyze", "summarize", "fetch", + URL

  • Code Generation: "create", "write", "build" + description

  • Image Generation: "comic", "manga", "infographic", "diagram"

  • Documentation: "document", "explain", "write docs for"

  • Git Operations: "commit", "push to github"

  • Publishing: "publish to X", "post to twitter"

How It Works

Simple Architecture

This bot uses a direct pass-through architecture - no intermediary LLM for parsing or interpretation. Every message you send goes straight to Claude Code CLI.

What Happens When You Send a Message

Step 1: Authorization

Only messages from your configured Telegram user ID are processed.

Step 2: Direct Execution

Step 3: Live Progress Updates As Claude Code works, the bot updates your message in real-time:

  • "⏳ Processing with Claude Code..."

  • "🤖 Processing your request..."

  • "📄 Created hello_world.py"

Step 4: Results Delivery When complete, you receive:

  • ✅ Success message with list of files created

  • 📊 Output summary or snippets

  • ❌ Error message if something failed

Why This Architecture?

Before (Complex):

  • Required Gemini API key

  • Two LLM calls per request

  • Potential parsing errors

  • API quotas and rate limits

Now (Simple):

  • ✅ No external API dependencies

  • ✅ Single LLM call

  • ✅ Claude Code handles all interpretation

  • ✅ More reliable and predictable

Key Components

1. Message Handler (handlers/message_handler.py)

  • Receives all text messages

  • Checks authorization

  • Forwards to orchestrator

2. Orchestrator (workflows/orchestrator.py)

  • Creates workflow tracking ID

  • Calls Claude Code executor

  • Manages state in SQLite

3. Claude Executor (executors/claude_executor.py)

  • Runs: claude --print "user message"

  • Streams output line by line

  • Extracts file paths from output

  • Reports progress via callback

4. State Manager (workflows/state_manager.py)

  • Stores workflow in SQLite database

  • Tracks: message, status, results, timestamps

  • Enables debugging and history

File Structure

Troubleshooting

Bot doesn't respond to messages

Problem: You send messages but get no response.

Diagnosis Steps:

  1. Check bot is running:

    If no output, bot is not running. Start it with ./start_bot.sh

  2. Verify your Telegram user ID:

    • Message @userinfobot on Telegram

    • Compare the ID it gives you with TELEGRAM_ADMIN_USER_ID in your .env file

    • If they don't match, update .env and restart bot

  3. Check bot logs for authorization errors:

    Look for:

    • 📨 Received message from user [ID] - confirms message received

    • ⛔ Unauthorized access - means your user ID doesn't match

    • 🔑 Expected admin user ID: [ID] - shows configured admin ID

  4. Verify bot token:

    Check this matches the token from @BotFather

  5. Test Claude Code CLI:

    Should return "4". If it fails, Claude Code is not installed or authenticated.

Common Fixes:

Bot responds but Claude Code fails

Problem: Bot says "⏳ Processing..." but then errors out.

Diagnosis:

  1. Test Claude Code directly:

  2. Check Claude Code is authenticated:

  3. Verify working directory:

Fixes:

Bot works but no files are created

Problem: Bot says task complete but no files appear.

Check:

  1. Verify working directory:

  2. Check workflow results in database:

  3. Look for file paths in bot output: Files created by Claude Code should appear in the working directory.

Git commit fails

Problem: Files are created but git commit fails.

Fixes:

Debug Mode

Enable detailed logging by monitoring the bot output:

Development

Run in background (tmux)

View logs

Future Enhancements

Last updated