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. Setupcp.env.example.envnano.env# Add your bot token and user ID# 4. Install & Runpython3-mvenvvenvsourcevenv/bin/activatepipinstall-rrequirements.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
Message @BotFather on Telegram
Create new bot: /newbot
Choose name: "Michi AI Bot"
Choose username: michi_ai_bot
Copy token:
2. Get Your Telegram User ID
Message @userinfobot
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:
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:
Check bot is running:
If no output, bot is not running. Start it with ./start_bot.sh
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
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
Verify bot token:
Check this matches the token from @BotFather
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:
Test Claude Code directly:
Check Claude Code is authenticated:
Verify working directory:
Fixes:
Bot works but no files are created
Problem: Bot says task complete but no files appear.
Check:
Verify working directory:
Check workflow results in database:
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:
analyze https://www.anthropic.com/engineering/demystifying-evals-for-ai-agents,
generate manga comic, commit to github
create infographic from https://example.com/paper.pdf, publish to X
You: create a Python script that prints hello world
Bot: ⏳ Processing with Claude Code...
Bot: 🤖 Processing your request...
Bot: 📄 Created hello_world.py
Bot: ✅ Task Complete! (ID: a1b2c3d4)
Created files:
• hello_world.py
You: analyze https://www.anthropic.com
Bot: ⏳ Processing with Claude Code...
Bot: 🤖 Processing your request...
Bot: 📄 Created anthropic-analysis.md
Bot: ✅ Task Complete! (ID: e5f6g7h8)
Created files:
• anthropic-analysis.md
You: analyze article https://example.com/article,
create infographic, commit to github
Bot: ⏳ Processing with Claude Code...
Bot: 🤖 Processing your request...
Bot: 📄 Created article-analysis.md
Bot: 🎨 Generating infographic...
Bot: 📄 Created infographic.png
Bot: 📝 Committing to GitHub...
Bot: ✅ Committed: 8c521e2
Bot: 🎉 Task Complete! (ID: i9j0k1l2)
Created files:
• article-analysis.md
• infographic.png
You: /baoyu-comic create manga about AI agents
Bot: ⏳ Processing with Claude Code...
Bot: 🤖 Processing your request...
Bot: 🎨 Generating comic panels...
Bot: 📄 Created ai-agents-comic/page-1.png
Bot: 📄 Created ai-agents-comic/page-2.png
Bot: ✅ Task Complete! (ID: m3n4o5p6)
# Find the latest bot output file
ls -lt /private/tmp/claude/-Users-xiaowei-wan-code-kuma-blog/tasks/*.output | head -1
# Watch logs in real-time
tail -f /private/tmp/claude/-Users-xiaowei-wan-code-kuma-blog/tasks/[TASK_ID].output
grep TELEGRAM_BOT_TOKEN .env
claude --print "what is 2+2?"
# Fix 1: Update user ID
nano .env
# Change TELEGRAM_ADMIN_USER_ID to your actual ID
# Save and restart bot
# Fix 2: Restart bot with correct directory
pkill -f "python.*bot.py"
cd /Users/xiaowei.wan/code/kuma-blog/AI/kuma-ai-agents/michi-telegram-bot
./start_bot.sh
# Fix 3: Check you're messaging the correct bot
# Go to @BotFather and use /mybots to see all your bots
# Make sure you're messaging the one with the token in your .env
cd /Users/xiaowei.wan/code/kuma-blog
claude --print "help me test"
claude --version # Should show version
claude auth status # Check authentication
ls -la /Users/xiaowei.wan/code/kuma-blog
# Should be a valid directory with .git folder
# Install Claude Code if missing
brew install claude
# Authenticate Claude Code
claude auth login
# Update working directory in .env if needed
nano .env
# Set CLAUDE_CODE_WORKING_DIR to a valid git repository path
echo $CLAUDE_CODE_WORKING_DIR
ls -la /Users/xiaowei.wan/code/kuma-blog
sqlite3 bot_state.db "SELECT * FROM workflows ORDER BY created_at DESC LIMIT 1;"
# Configure git if not set
git config user.name "Your Name"
git config user.email "your@email.com"
# Check you're in a git repository
cd /Users/xiaowei.wan/code/kuma-blog
git status # Should show git info, not "not a git repository"
# Check for conflicts
git status
# Resolve any merge conflicts or uncommitted changes
# Find current bot task ID
ps aux | grep "python.*bot.py"
# Watch logs live
tail -f /private/tmp/claude/-Users-xiaowei-wan-code-kuma-blog/tasks/[TASK_ID].output
# Send a test message to your bot
# You should see:
# - 📨 Received message from user [ID]: [message]
# - 🔑 Expected admin user ID: [ID]
# - executors.claude_executor - INFO - Executing Claude Code with message: [message]
tmux new -s michi-bot
cd /Users/xiaowei.wan/code/kuma-blog/AI/kuma-ai-agents/michi-telegram-bot
source venv/bin/activate
python bot.py
# Detach: Ctrl+B, then D
# Reattach: tmux attach -t michi-bot