| commit | 8146a40f940bd0eae74879e44db6d94ed9fb8800 | [log] [download] |
|---|---|---|
| author | Rivoreo AutoPilot <autopilot@rivoreo.one> | Thu Dec 11 03:34:36 2025 +0800 |
| committer | Rivoreo AutoPilot <autopilot@rivoreo.one> | Thu Dec 11 03:34:36 2025 +0800 |
| tree | 5fa6983d9bf2ddcee47a2d98a3cef8acd2cd01c0 | |
| parent | 0304cda7cea504f45794440bf73dbdd8593d5a76 [diff] |
feat(telegram): add message timestamps and MCP-based image analysis Implement message timestamps for AI context awareness and add MCP tool for analyzing Telegram images using claude-agent-sdk's tool support. Message Timestamps: - Add message_time field with local timezone conversion (YYYY-MM-DD HH:MM:SS format) - Display timestamp in user context for AI to see when messages were sent - Support timezone conversion from UTC to local time with fallback handling MCP Image Analysis Tool: - Create telegram_image_tools.py MCP server with analyze_telegram_image tool - Configure MCP server in AgentCore using ClaudeAgentOptions.mcp_servers - Tool reads image files, encodes to base64, returns MCP standard format (type: image, mimeType: image/jpeg, data: base64_string) - Support multiple image formats (jpg, png, gif, webp, bmp) Image Message Flow: - Download user image to temp/telegram/ directory - Prompt Claude to use analyze_telegram_image tool with file path - Claude automatically calls MCP tool to view image via SDK - Tool returns image content in MCP format (PR #175 standard) - Claude analyzes image and replies to user - Cleanup temp file after processing Technical Details: - MCP tool follows anthropics/claude-agent-sdk-python PR #175 standard - User messages do not support direct image blocks (SDK limitation) - Images must be passed through tool_result content (MCP protocol) - Session context preserved: AI retains full conversation history - SDK Automatic Compaction handles context size management Documentation: - Add DOCKER_DEPLOYMENT.md with complete deployment guide - Add DOCKER_DEPLOYMENT_MODES.md explaining multi-bot architecture Related: anthropics/claude-agent-sdk-python#175 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
基于Claude Code SDK的智能AI聊天助手系统,专为Rivoreo社区设计,支持CLI交互、Telegram Bot、SSHOUT聊天室集成和多种AI交互模式。
rivoreo-agent/ ├── src/claude_agent/ # 核心源代码 │ ├── core/ # AI Agent核心逻辑 │ ├── telegram/ # Telegram Bot模块 (完整功能) │ ├── cli/ # 命令行界面 │ ├── sshout/ # SSHOUT聊天室集成 │ ├── mcp/ # MCP工具框架 │ ├── webhook/ # Webhook API系统 │ ├── storage/ # 持久化存储 │ └── utils/ # 通用工具模块 ├── tests/ # 461个测试用例 (100%通过) ├── scripts/ # 启动脚本和工具 ├── configs/ # 配置文件模板 ├── docs/ # 完整项目文档 ├── data/ # 运行时数据存储 └── run/ # 专用运行环境
# 激活虚拟环境 source venv/bin/activate # 验证依赖安装 pip install -r requirements.txt
# 配置Bot Token (configs/local.toml) [telegram] bot_token = "YOUR_BOT_TOKEN" allowed_users = [YOUR_USER_ID] # 启动Telegram Bot cd run/telegrambot ./start_telegrambot.sh
# 基础CLI python scripts/main.py # 增强CLI (支持历史翻查和补全) python scripts/main_enhanced.py
# 配置SSH连接 (configs/default.toml) [sshout] mention_patterns = ["@Claude", "@claude"] # 启动SSHOUT集成 python scripts/main_enhanced.py --sshout
# 配置Webhook服务器 (configs/webhook_server.toml) [webhook] enabled = true auth_token = "your-secure-token" [webhook.server] host = "0.0.0.0" port = 8080 # 启动独立Webhook服务器 ./scripts/start_webhook_server.sh
Webhook服务器用途:
| 模块 | 测试数量 | 通过率 | 覆盖率 |
|---|---|---|---|
| Telegram | 150+ | 100% | 74% |
| Core Agent | 90+ | 100% | 83% |
| Storage | 80+ | 100% | 84% |
| Utils/CLI | 70+ | 100% | 76% |
| SSHOUT/MCP | 60+ | 100% | 70% |
[telegram] bot_token = "BOT_TOKEN" # Telegram Bot Token allowed_users = [123456] # 允许的用户ID列表 allowed_groups = [-1001234567] # 允许的群组ID列表 [telegram.message] stream_update_interval = 1.0 # 流式消息更新间隔 max_message_length = 4096 # 最大消息长度 context_history_limit = 50 # 上下文历史保留数量 [telegram.files] max_file_size_mb = 20 # 最大文件大小 temp_dir = "temp/telegram" # 临时文件目录
[sshout] mention_patterns = ["@Claude", "@claude"] # 提及检测模式 [sshout.server] hostname = "tianjin1.rivoreo.one" # SSHOUT服务器 port = 22333 # SSH端口 username = "sshout" # 登录用户名 [sshout.ssh_key] private_key_path = "assets/ssh-keys/id_ecdsa_sshout_test" timeout = 10 # 连接超时
[webhook] enabled = true # 启用Webhook功能 auth_token = "secure-webhook-token-2024" # API认证Token server_url = "http://localhost:8080" # 服务器URL (可选) [webhook.server] host = "0.0.0.0" # 服务器绑定地址 port = 8080 # 服务器端口 connection_timeout = 10.0 # 连接超时 (秒) request_timeout = 5.0 # 请求超时 (秒) max_retries = 3 # 最大重试次数 retry_delay = 1.0 # 重试延迟 (秒) [logging] level = "INFO" # 日志级别 format = "[%(asctime)s] %(levelname)s %(name)s: %(message)s"
技术背景: Telegram Bot API限制Bot在群组中无法接收其他Bot发送的消息,这导致多Bot系统无法直接通信。Webhook服务器通过HTTP API实现Bot间消息路由,突破了这一限制。
Webhook API端点:
POST /webhook/register - 注册Bot到服务器POST /webhook/broadcast - 广播消息到指定群组GET /webhook/health - 健康检查GET /webhook/stats - 服务器统计信息# 1. 环境配置 export CLAUDE_CONFIG=production export ANTHROPIC_API_KEY="your_api_key" # 2. 配置生产配置文件 cp configs/default.toml configs/production.toml # 编辑 configs/production.toml # 3. 启动服务 python scripts/start_telegram_bot.py
# 构建镜像 docker build -t claude-agent . # 运行容器 docker run -d --name claude-bot \ -e ANTHROPIC_API_KEY=your_key \ -v ./configs:/app/configs \ -v ./data:/app/data \ claude-agent
Bot Token无效
❌ 请配置有效的Telegram Bot Token
解决: 检查 configs/local.toml 中的 bot_token 配置
权限被拒绝
❌ 用户无权限访问
解决: 将用户/群组ID添加到白名单
SSH连接失败
❌ SSHOUT连接失败
解决: 检查SSH密钥权限和网络连通性
消息格式错误
❌ Markdown解析错误
解决: 已修复Markdown清理机制,自动处理格式问题
# 查看Telegram Bot日志 tail -f logs/telegram_bot.log # 查看系统资源使用 htop | grep python # 检查存储使用情况 du -sh data/storage/
# 1. Fork项目并创建功能分支 git checkout -b feature/new-feature # 2. 开发和测试 python -m pytest tests/ -v # 3. 代码检查 python -m pytest tests/ --cov=src/claude_agent --cov-report=term # 4. 提交Pull Request git commit -m "feat: add new feature" git push origin feature/new-feature
MIT License - 详见 LICENSE 文件
⚠️ 重要提醒: 请勿将包含真实Bot Token和API密钥的配置文件提交到版本控制系统。
🎉 项目成就: Rivoreo Agent已成功演进为功能完整、测试完备、生产就绪的企业级智能AI聊天助手系统!