| commit | 0304cda7cea504f45794440bf73dbdd8593d5a76 | [log] [download] |
|---|---|---|
| author | Rivoreo AutoPilot <autopilot@rivoreo.one> | Thu Dec 11 03:31:28 2025 +0800 |
| committer | Rivoreo AutoPilot <autopilot@rivoreo.one> | Thu Dec 11 03:31:28 2025 +0800 |
| tree | 8bf6e90e36730c8ad5e4d3a32e43ae21133e6bff | |
| parent | a94058cc63fce3a6bcdd02e87ebccd75afbec127 [diff] |
fix(webhook): resolve Docker container networking and session persistence Fix webhook server communication issues in Docker environment and improve session persistence by mounting entire .claude directory instead of just sessions subdirectory. Key changes: - Webhook client: Add WEBHOOK_CALLBACK_HOST environment variable support to use container names instead of localhost in Docker networks - Webhook client: Bind callback server to 0.0.0.0 instead of 127.0.0.1 to allow container-to-container communication - Docker Compose: Add WEBHOOK_CALLBACK_HOST for all 4 bot services - Docker Compose: Mount entire .claude directory for session persistence (was mounting only .claude/sessions which was insufficient) - Add docker-entrypoint.sh for container initialization - Add .env.all.example with complete environment variable documentation - Update .gitignore to exclude runtime data (.claude/, data/, logs) Technical details: - In Docker networks, localhost refers to container's own namespace - Webhook server needs container hostnames for inter-bot communication - SDK requires entire .claude directory, not just sessions subdirectory - Session persistence now survives container rebuilds Fixes: Webhook "Cannot connect to host localhost:30543" error Fixes: "No conversation found with session ID" after image rebuild 🤖 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聊天助手系统!