claude-code-remote-remake/test-telegram-setup.sh

122 lines
3.4 KiB
Bash
Raw Permalink Normal View History

Telegram&Line support (#17) * feat: Add LINE and Telegram messaging support This major enhancement extends Claude Code Remote with multi-platform messaging support: ## 🚀 New Features ### LINE Messaging Support - LINE Bot API integration with token-based commands - Secure webhook handler with signature verification - Session management with 24-hour expiration - Support for both individual and group chats - User/Group ID whitelist security ### Telegram Bot Support - Telegram Bot API with interactive buttons - Slash command support (/cmd TOKEN command) - Callback query handling for better UX - Group and private chat support - Chat ID-based authorization ### Multi-Platform Architecture - Unified notification system supporting all platforms - Platform-agnostic session management - Configurable channel enabling/disabling - Parallel webhook server support ## 🛠️ Technical Implementation ### Core Components - `src/channels/line/` - LINE messaging implementation - `src/channels/telegram/` - Telegram bot implementation - `src/utils/controller-injector.js` - Command injection utility - Multi-platform webhook servers with Express.js ### Configuration & Documentation - Updated `.env.example` with all platform options - Comprehensive setup guides for each platform - Testing guide with ngrok instructions - Updated README with multi-platform support ### Developer Experience - npm scripts for easy platform startup - Unified webhook launcher (`start-all-webhooks.js`) - Individual platform launchers - Enhanced error handling and logging ## 🔧 Usage Examples **Telegram:** `/cmd ABC12345 analyze this code` **LINE:** `Token ABC12345 analyze this code` **Email:** Reply to notification emails ## 📋 Backward Compatibility - All existing email functionality preserved - Configuration migration path provided - No breaking changes to existing hooks 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * feat: Complete Telegram Remote Control System with Direct Chat Mode ### 🚀 Major Features Added - **Direct Chat Mode**: Users can chat with Claude naturally without /cmd tokens - **Smart Monitoring**: Intelligent response detection with historical processing - **One-Click Startup**: Complete system management via startup script - **Auto-Notification**: Real-time Claude response detection and Telegram delivery ### 📱 Telegram Integration - `telegram-direct-mode.js`: Direct conversation interface - `telegram-polling.js`: Command polling with token validation - Enhanced notification system with markdown formatting ### 🧠 Smart Monitoring System - `smart-monitor.js`: Advanced response detection with history awareness - `simple-monitor.js`: Lightweight monitoring alternative - `auto-notification-daemon.js`: Background notification service ### 🛠️ System Management - `start-telegram-claude.sh`: Complete service management script - Environment validation and dependency checking - Color-coded status reporting and log management - Process lifecycle management (start/stop/restart/status) ### 📖 Documentation & Testing - `TELEGRAM_CLAUDE_GUIDE.md`: Comprehensive user guide - Complete test suite for all components - Usage examples and troubleshooting guide ### 🔧 Core Improvements - Enhanced `controller-injector.js` with proper Enter key handling - Updated `tmux-monitor.js` with real-time output monitoring - Improved error handling and logging throughout - Session management with automatic cleanup ### 🎯 Key Capabilities - **Seamless Communication**: Direct Telegram ⟷ Claude integration - **Full Automation**: No manual intervention required - **Robust Monitoring**: Never miss Claude responses - **Easy Deployment**: Single script startup and management - **Multi-Modal Support**: Ready for LINE integration expansion ### 📊 System Architecture ``` User → Telegram Bot → Direct Injection → Claude Session → Smart Monitor → Auto Notification → User ``` This completes the transformation from email-based to messaging-app-based remote Claude control, providing a modern, efficient, and user-friendly interface for remote AI interaction. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * docs: Enhance documentation and smart monitoring system - Add comprehensive CLAUDE.md for Claude Code development guidance - Update README.md with multi-platform focus and improved instructions - Enhance smart-monitor.js with auto-approval for tool permissions - Improve start-telegram-claude.sh with better tmux session management - Add auto-approver.js for automated tool permission handling Key improvements: - Multi-platform documentation (Telegram, LINE, Email, Local) - Enhanced troubleshooting and command reference sections - Smart monitoring with historical response detection - Automated tool permission approval workflow - Better tmux integration and session management 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * chore: Add CLAUDE.md to .gitignore and remove from tracking - Add CLAUDE.md to .gitignore under "Claude Code development files" section - Remove CLAUDE.md from git tracking while preserving local file - CLAUDE.md should remain as local development documentation only 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * feat: Complete Telegram integration with multi-channel notifications - ✅ Enhanced Telegram bot with smart buttons for personal/group chats - ✅ Multi-channel notification system (Desktop, Telegram, Email, LINE) - ✅ Smart sound alerts with customizable audio feedback - ✅ Real-time command injection with tmux session management - ✅ Intelligent session detection and conversation content extraction - ✅ Unified README documentation with complete setup guides - 🧹 Clean up legacy files and consolidate documentation - 📱 Add setup scripts for easy Telegram configuration - 🔧 Enhance webhook system with improved error handling 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Update processed messages --------- Co-authored-by: laihenyi <henyi@henyi.org> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: laihenyi <laihenyi@users.noreply.github.com>
2025-08-02 04:21:26 +08:00
#!/bin/bash
# Claude Code Remote - Telegram Setup Test Script
# This script tests all components of the Telegram setup
echo "🧪 Claude Code Remote - Telegram Setup Test"
echo "==========================================="
# Load environment variables
if [ -f ".env" ]; then
echo "✅ .env file found"
source .env
else
echo "❌ .env file not found"
exit 1
fi
# Check required environment variables
if [ -z "$TELEGRAM_BOT_TOKEN" ]; then
echo "❌ TELEGRAM_BOT_TOKEN not set in .env"
exit 1
else
echo "✅ TELEGRAM_BOT_TOKEN found"
fi
if [ -z "$TELEGRAM_CHAT_ID" ]; then
echo "❌ TELEGRAM_CHAT_ID not set in .env"
exit 1
else
echo "✅ TELEGRAM_CHAT_ID found"
fi
if [ -z "$TELEGRAM_WEBHOOK_URL" ]; then
echo "❌ TELEGRAM_WEBHOOK_URL not set in .env"
exit 1
else
echo "✅ TELEGRAM_WEBHOOK_URL found: $TELEGRAM_WEBHOOK_URL"
fi
# Test Telegram bot connection
echo ""
echo "🔧 Testing Telegram bot connection..."
response=$(curl -s -X POST "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage" \
-H "Content-Type: application/json" \
-d "{\"chat_id\": $TELEGRAM_CHAT_ID, \"text\": \"🧪 Setup test from Claude Code Remote\"}")
if echo "$response" | grep -q '"ok":true'; then
echo "✅ Telegram bot connection successful"
else
echo "❌ Telegram bot connection failed"
echo "Response: $response"
exit 1
fi
# Check webhook status
echo ""
echo "🔧 Checking webhook status..."
webhook_response=$(curl -s "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/getWebhookInfo")
if echo "$webhook_response" | grep -q "$TELEGRAM_WEBHOOK_URL"; then
echo "✅ Webhook is correctly set"
else
echo "⚠️ Webhook not set to expected URL"
echo "Expected: $TELEGRAM_WEBHOOK_URL"
echo "Response: $webhook_response"
fi
# Check if claude-hooks.json exists
if [ -f "claude-hooks.json" ]; then
echo "✅ claude-hooks.json found"
else
echo "❌ claude-hooks.json not found"
exit 1
fi
# Test notification script
echo ""
echo "🔧 Testing notification script..."
node claude-hook-notify.js completed
# Check if required processes are running
echo ""
echo "🔧 Checking running processes..."
if pgrep -f "ngrok" > /dev/null; then
echo "✅ ngrok is running"
else
echo "⚠️ ngrok not found - make sure to run: ngrok http 3001"
fi
if pgrep -f "start-telegram-webhook" > /dev/null; then
echo "✅ Telegram webhook service is running"
else
echo "⚠️ Telegram webhook service not running - run: node start-telegram-webhook.js"
fi
# Check tmux sessions
echo ""
echo "🔧 Checking tmux sessions..."
if command -v tmux >/dev/null 2>&1; then
if tmux list-sessions 2>/dev/null | grep -q "claude-code"; then
echo "✅ claude-code tmux session found"
else
echo "⚠️ claude-code tmux session not found - create with: tmux new-session -s claude-code"
fi
else
echo "⚠️ tmux not installed"
fi
echo ""
echo "📋 Setup Test Summary:"
echo "====================="
echo "If all items above show ✅, your setup is ready!"
echo ""
echo "Next steps:"
echo "1. Make sure ngrok is running: ngrok http 3001"
echo "2. Make sure webhook service is running: node start-telegram-webhook.js"
echo "3. Start Claude in tmux with hooks:"
echo " tmux attach -t claude-code"
echo " export CLAUDE_HOOKS_CONFIG=$(pwd)/claude-hooks.json"
echo " claude"
echo ""
echo "Test by running a task in Claude - you should get a Telegram notification!"