Tổng quan
AHV CLI Bot là gói cài đặt bot Telegram cho Codex CLI và Claude Code. Gói public nằm tại:
https://bot.ahvclaw.com/downloads/telegram-cli-bot-setupNhận tin Telegram, gọi Codex CLI, giữ session và gửi kết quả dài theo nhiều phần.
Nhận tin Telegram, gọi Claude Code, gửi tiến trình trong transcript, theo dõi task dài tới kết quả cuối.
Timer systemd tải manifest, kiểm tra SHA256, cập nhật bot.py và khởi động lại service.
Trang chủ tự đọc manifest để hiển thị phiên bản hiện tại và hash gói cài đặt.
Cài đặt nhanh
Linux
bash <(curl -fsSL https://bot.ahvclaw.com/downloads/telegram-cli-bot-setup/install.sh)Windows PowerShell
irm https://bot.ahvclaw.com/downloads/telegram-cli-bot-setup/install.ps1 | iexmacOS
bash <(curl -fsSL https://bot.ahvclaw.com/downloads/telegram-cli-bot-setup/install-mac.sh)Nếu cài trên server sản xuất, hãy giữ lại file .env hiện có. Script cập nhật được thiết kế để bảo toàn cấu hình token/model/chat id.
Cập nhật thủ công
Dùng khi muốn chủ động kéo bản mới nhất thay vì chờ timer.
Linux có systemd timer
sudo systemctl start telegram-cli-bot-package-update.service
sudo journalctl -u telegram-cli-bot-package-update.service -n 100 --no-pagerKiểm tra phiên bản sau update
cat /opt/bot/tg-claude-bot/VERSION
cat /opt/bot/tg-codex-bot/VERSION
systemctl is-active tg-claude-bot tg-codex-botWindows/macOS
Chạy lại trình cài đặt tương ứng. Đây là đường cập nhật/sửa lỗi chuẩn cho môi trường không dùng systemd.
Thêm bot token mới
Khi cần làm việc đồng thời, hãy tạo thêm một bot instance riêng thay vì dùng chung một token. Mỗi instance có service, app dir và project dir riêng; updater vẫn cập nhật tất cả service đang active.
Thêm Codex Bot instance
curl -fsSL https://bot.ahvclaw.com/downloads/telegram-cli-bot-setup/add-bot-instance.sh | sudo bash -s -- codex main PASTE_CODEX_BOT_TOKEN 6348110855Thêm Claude Bot instance
curl -fsSL https://bot.ahvclaw.com/downloads/telegram-cli-bot-setup/add-bot-instance.sh | sudo bash -s -- claude support PASTE_CLAUDE_BOT_TOKEN 6348110855Kiểm tra
systemctl status tg-codex-bot-main --no-pager
journalctl -u tg-codex-bot-main -n 80 --no-pagerKhông dùng cùng một Telegram bot token cho hai service. Nếu muốn hai session song song, hãy tạo hai bot token khác nhau trong BotFather.
Login Codex và Claude CLI
Bot Telegram chỉ là lớp điều khiển. Codex CLI và Claude Code CLI vẫn cần đăng nhập trên server bằng đúng Linux user chạy service. Mỗi CLI login một lần, token/session sẽ nằm trong home của user tương ứng.
Login Codex Bot
sudo -u codexproxy -H codex login --device-auth
sudo systemctl restart tg-codex-bot
sudo journalctl -u tg-codex-bot -n 80 --no-pagerLogin Claude Bot
sudo -u claudeproxy -H claude login
sudo systemctl restart tg-claude-bot
sudo journalctl -u tg-claude-bot -n 80 --no-pagerKiểm tra nhanh
sudo -u codexproxy -H codex --version
sudo -u claudeproxy -H claude --version
systemctl is-active tg-codex-bot tg-claude-botNếu login mở link hoặc mã xác thực, hãy hoàn tất ngay trên terminal đó. Không chạy cùng một Telegram bot token cho cả Codex và Claude vì hai service sẽ xung đột polling.
Thêm Telegram ID được phép dùng bot
Người dùng nhắn /whoami cho bot để lấy Telegram user id. Từ v0.0.29, Codex Bot và Claude Bot tự đọc lại ALLOWED_USER_ID, ALLOWED_CHAT_ID, ALLOWED_TOPIC_ID khi file .env đổi, nên thêm ID xong nhận ngay không cần restart.
Thêm ID cho cả Codex và Claude
curl -fsSL https://bot.ahvclaw.com/downloads/telegram-cli-bot-setup/allow-telegram-id.sh | sudo bash -s -- both 638048624Chỉ thêm cho một bot
curl -fsSL https://bot.ahvclaw.com/downloads/telegram-cli-bot-setup/allow-telegram-id.sh | sudo bash -s -- codex 638048624
curl -fsSL https://bot.ahvclaw.com/downloads/telegram-cli-bot-setup/allow-telegram-id.sh | sudo bash -s -- claude 638048624Restart thủ công khi cần
sudo systemctl restart tg-codex-bot tg-claude-botLệnh sửa lỗi khi bot lỗi
Sửa lỗi nghĩa là cài lại bộ cập nhật/gói mới nhất, kiểm tra manifest, khởi động lại service và giữ cấu hình hiện tại. Trên Linux, lệnh dưới đây chạy như người dùng thật: tải script repair public, cài lại updater, chạy update ngay, restart bot đang tồn tại và in trạng thái cuối.
Linux sửa toàn bộ bộ cập nhật + bot
curl -fsSL https://bot.ahvclaw.com/downloads/telegram-cli-bot-setup/repair.sh | sudo BOT_PACKAGE_BASE_URL=https://bot.ahvclaw.com/downloads/telegram-cli-bot-setup AUTO_UPDATE_NOTIFY_CHAT_ID=638048624 bashWindows sửa/cập nhật
irm https://bot.ahvclaw.com/downloads/telegram-cli-bot-setup/install.ps1 | iexmacOS sửa/cập nhật
bash <(curl -fsSL https://bot.ahvclaw.com/downloads/telegram-cli-bot-setup/install-mac.sh)Xử lý lỗi thường gặp
| Triệu chứng | Cách xử lý |
|---|---|
| Bot im, không trả lời Telegram | Kiểm tra service: systemctl status tg-claude-bot tg-codex-bot. Xem log: journalctl -u tg-claude-bot -n 120 --no-pager. |
| Claude có transcript nhưng Telegram không nhận kết quả cuối | Đảm bảo package từ v0.0.23 trở lên. Chạy cập nhật thủ công, sau đó kiểm tra log có Telegram sendMessage ok. |
| Model Claude bị từ chối | Kiểm tra CLAUDE_MODEL trong /opt/bot/tg-claude-bot/.env. Nếu model không còn quyền truy cập, đổi model hợp lệ rồi khởi động lại service. |
| Cập nhật lỗi do SHA256 không khớp | Không chạy zip đó. Tải lại manifest/zip, so sánh SHA256, kiểm tra public manifest trên domain mới. |
| Bot gửi được nhưng text bị thiếu | Xem log từng phần: Telegram sendMessage ok ... chars=... preview=.... Nếu không có dòng này, lỗi nằm trước bước gửi Telegram. |
Phát triển tiếp
Repository gốc trên máy build:
C:\Users\Administrator\telegram-cli-bot-setupCác file chính:
claude-bot/bot.py: wrapper Telegram cho Claude Code.codex-bot/bot.py: wrapper Telegram cho Codex CLI.install-package-update-linux.sh: cài timer updater cho Linux.manifest.jsonvàVERSION: metadata public package.landing/bot-ahvclaw/: landing page và wiki public.
Checklist khi sửa code
python test_package_update_assets.py
python -m unittest discover claude-bot
python -m unittest discover codex-bot
python -m py_compile claude-bot\bot.py codex-bot\bot.pyMọi fix bot phải sửa ở package gốc, bump version, rebuild zip, upload public và ép updater trên server cần cập nhật. Không được chỉ vá nóng live server rồi bỏ quên package.
Quy trình release
- Sửa code/tài liệu trong package gốc.
- Tăng phiên bản trong
VERSIONvàmanifest.json. - Đóng gói lại zip bằng script POSIX zip của workspace.
- Cập nhật SHA256 thật vào manifest.
- Chạy kiểm tra đầy đủ.
- Upload lên
ahvclaw:/srv/telegram-cli-bot-setup. - Kiểm tra HTTPS ở
bot.ahvclaw.comvà đường dẫn tương thích cũ. - Ép bộ cập nhật trên server cần nhận bản mới.