Điều khiển Hermes Agent từ xa qua Telegram bot (setup + commands)

Chia sẻ bài viết

Mục lục
Minh hoạ điều khiển Hermes Agent qua Telegram bot từ phone

VPS chạy Hermes 24/7 trên đám mây, còn bạn ngồi quán cà phê với cái điện thoại. Cách đơn giản nhất để ra lệnh: Telegram bot. Hermes có gateway sẵn cho Telegram, Discord, Slack, WhatsApp, Signal và CLI - chỉ cần config 5 phút là điều khiển được agent từ phone, nhận lại screenshot, file, kết quả ngay trong chat.

Vì sao Telegram là lựa chọn tốt nhất

So với 4 gateway còn lại Hermes hỗ trợ, Telegram có 3 lợi thế:

  • Bot API miễn phí, không giới hạn: gửi text, ảnh, file, voice thoải mái
  • Tạo bot trong 30 giây qua BotFather: không cần đăng ký dev account
  • Client đa nền tảng: iOS, Android, web, desktop đều sync chung

WhatsApp/Signal cần số điện thoại + thủ tục business API phiền hà. Discord/Slack tốt nếu bạn dùng nó cho team, còn cá nhân thì Telegram thắng tuyệt đối.

Bước 1: Tạo bot qua BotFather

Mở Telegram, search @BotFather, gõ:

/newbot
HermesController          # tên hiển thị
my_hermes_vps_bot         # username (phải kết thúc bằng "bot")

BotFather trả về token dạng:

7234567890:AAH-xxx-yyy-zzz-1234567890abcd

Lưu token này cẩn thận - đây là chìa khoá điều khiển bot, lộ ra ai cũng spam vào VPS bạn được.

Tiếp theo, lấy chat_id của bạn. Send tin nhắn bất kỳ vào bot vừa tạo, rồi mở URL trên browser:

https://api.telegram.org/bot7234567890:AAH-xxx.../getUpdates

Tìm trường "chat":{"id":123456789,.... Số đó là chat_id của bạn. Lưu lại.

Bước 2: Config Hermes gateway

Trong ~/.hermes/config.toml thêm block:

[gateway.telegram]
enabled = true
bot_token = "${TELEGRAM_BOT_TOKEN}"
allowed_chat_ids = [123456789]
default_chat_id = 123456789

# Optional: tên hiển thị khi reply
agent_name = "Hermes-VPS"

# Optional: auto-reply mỗi message hay đợi /command
mode = "command"  # hoặc "chat"

Set env và start Hermes:

export TELEGRAM_BOT_TOKEN='7234567890:AAH-xxx-...'
hermes --gateway telegram

Log nên ra:

[gateway.telegram] Connected. Bot @my_hermes_vps_bot ready.
[gateway.telegram] Allowed chat_ids: [123456789]
[gateway.telegram] Mode: command

Bước 3: Test command đầu tiên

Mở Telegram, vào chat với bot, gõ:

/start

Bot reply:

Hermes-VPS đang online. Một số command:
/help - list command
/skills - skill khả dụng
/run  - giao task tự nhiên
/screenshot  - chụp ảnh URL
/status - tình trạng VPS

Thử lệnh thật:

/run check tỷ giá USD/VND hôm nay

Bot reply trong 5-10 giây:

[check_usd_vnd_rate] -> {"buy": 25430, "sell": 25590, ...}
Tỷ giá Vietcombank hôm nay:
- Mua tiền mặt: 25,430 VND/USD
- Bán chuyển khoản: 25,590 VND/USD
Cập nhật: 09:15 29/05/2026

Bước 4: Nhận file và screenshot

Đây là phần đẹp nhất - bot tự gửi file/ảnh khi task tạo output:

/run chụp screenshot https://tnd.vn full page, gửi mình qua đây

Bot reply:

[browser.screenshot url=https://tnd.vn full_page=true]
-> /tmp/screenshot-20260529-091523.png
[telegram.send_photo path=...] OK
(kèm ảnh)

Tương tự với file JSON, CSV, PDF - Hermes tự chọn send_document hay send_photo tuỳ MIME type.

💡 Mẹo: Telegram giới hạn 50MB/file qua Bot API. File lớn hơn (video, dataset) upload lên storage rồi gửi link.

Bước 5: Voice input - ra lệnh bằng giọng nói

Hermes hỗ trợ voice message: bạn record voice, agent transcribe (qua Whisper hoặc tương tự) rồi execute. Bật trong config:

[gateway.telegram.voice]
enabled = true
transcribe_provider = "openai_whisper"  # hoặc local "whisper.cpp"
api_key = "${OPENAI_API_KEY}"
language = "vi"

Workflow:

  1. Bạn giữ nút mic trong Telegram, nói: "Kiểm tra số đơn hàng hôm nay trên Shopify"
  2. Bot transcribe -> "Kiểm tra số đơn hàng hôm nay trên Shopify"
  3. Hermes hiểu intent, chạy browser automation login Shopify, đếm order
  4. Reply text + screenshot

Nếu không muốn tốn OpenAI credit, dùng whisper.cpp local (cài bằng apt install whisper.cpp hoặc build từ source). Chất lượng vẫn tốt cho tiếng Việt với model medium.

Security - bắt buộc làm

Bot token + chat_id allowlist là 2 lớp bảo vệ chính. Quên cái nào là VPS bạn open cho cả internet.

1. allowed_chat_ids là whitelist tuyệt đối

Hermes chỉ phản hồi message từ chat_id trong list. Tin nhắn từ chat_id khác bị drop. Đừng để empty list - empty = allow all.

allowed_chat_ids = [123456789, 987654321]  # bạn và team

2. Token không hardcode

Để token trong env hoặc file ~/.hermes/.env (chmod 600). Đừng commit lên Git, đừng paste vào chat public.

# ~/.hermes/.env
TELEGRAM_BOT_TOKEN=7234567890:AAH-xxx-...
OPENAI_API_KEY=sk-...
WP_PASS=...
chmod 600 ~/.hermes/.env

3. Rate-limit command

Nếu sợ ai đó (cùng chat_id) spam command tốn LLM cost:

[gateway.telegram.rate_limit]
max_commands_per_minute = 10
max_commands_per_hour = 100

4. Restricted commands

Một số command nguy hiểm (xoá file, sudo, restart server) nên require keyword confirm:

[gateway.telegram.confirm_required]
commands = ["rm", "shutdown", "reboot", "drop table", "delete"]
keyword = "yes-i-am-sure"

Khi bạn gõ /run xoá file /tmp/*, bot reply: "Bạn chắc chứ? Reply 'yes-i-am-sure' để xác nhận."

⚠️ Lưu ý: Nếu bot token lộ ra (commit nhầm vào public repo), revoke ngay qua BotFather: /revoke @my_hermes_vps_bot. Token cũ chết, sinh token mới.

Use case thật mình hay dùng

Khi nàoCommand Telegram
Sáng dậy, check shop/run đếm order pending Shopify hôm nay
Đang đi, cần search/run search "n8n self-host vs cloud", tóm tắt
Check VPS health/status
Quên restart service/run restart nginx trên VPS
Gửi báo cáo nhanh/run generate báo cáo doanh số tuần thành PDF
Theo dõi đối thủ/run scrape giá top 5 SP của shop X

Bot chạy ngầm với systemd

Để Hermes + Telegram gateway chạy mãi mãi, tạo systemd service. File /etc/systemd/system/hermes.service:

[Unit]
Description=Hermes Agent with Telegram gateway
After=network.target

[Service]
Type=simple
User=user
WorkingDirectory=/home/user
EnvironmentFile=/home/user/.hermes/.env
ExecStart=/home/user/.hermes/venv/bin/hermes --gateway telegram --headless
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

Enable và start:

sudo systemctl daemon-reload
sudo systemctl enable hermes
sudo systemctl start hermes
sudo systemctl status hermes

Khi VPS reboot, Hermes tự lên lại. Khi crash, restart sau 10s.

Multi-bot pattern - tách bot theo domain

Khi dùng nhiều, bạn sẽ muốn tách: bot này quản shop, bot kia quản dev, bot khác là personal assistant. Hermes hỗ trợ multi-gateway instance:

[gateway.telegram_shop]
bot_token = "${TG_TOKEN_SHOP}"
allowed_chat_ids = [123456789]
default_skill_filter = ["shopify_*", "woocommerce_*"]

[gateway.telegram_dev]
bot_token = "${TG_TOKEN_DEV}"
allowed_chat_ids = [123456789]
default_skill_filter = ["git_*", "deploy_*", "monitor_*"]

Mỗi bot chỉ load subset skill, an toàn hơn (không nhỡ tay xoá DB từ bot shop) và LLM context gọn hơn.

Performance: Hermes + Telegram cần VPS thế nào

Gateway Telegram chỉ tốn ~50-100MB RAM. Phần nặng là LLM call, browser tool, skill execution. Mức tối thiểu để chạy ổn:

  • VPS 50 (4vCPU/4GB) ổn cho 1-2 task song song, không browser-heavy
  • VPS 80 (6vCPU/6GB) ổn cho 5+ task song song có browser
  • Bandwidth: ~5GB/tháng nếu chỉ text, ~30-50GB nếu nhiều screenshot/voice

Xem chi tiết về VPS cho dev tự host AI để chọn đúng.

Checklist deploy Telegram bot

  • Bot tạo qua BotFather, lưu token vào env
  • chat_id của bạn lấy từ getUpdates, add vào allowed_chat_ids
  • Hermes config có block [gateway.telegram]
  • Test /start nhận reply đúng
  • Voice + transcribe (optional) đã enable nếu cần
  • Confirm-required cho destructive command
  • Rate limit set
  • Systemd service chạy ổn qua reboot

Bài viết liên quan

VPS chạy Hermes + Telegram bot 24/7

VPS 50 (4vCPU/4GB Ceph SSD NVMe, RAM ECC, 639k/tháng) là entry point hợp lý cho cá nhân muốn điều khiển Hermes qua phone. Cần browser tool nặng thì lên VPS 80.

Xem bảng giá VPS

2009
15+ năm vận hành liên tục
10+
tập đoàn lớn tin dùng
100+
doanh nghiệp SMB Việt
30 ngày
đổi key lỗi miễn phí
Phần mềm bản quyền chính hãng chúng tôi cung cấp
Bản quyền chính hãng Hóa đơn VAT đầy đủ Đổi key lỗi 30 ngày Vận hành từ 2009 MST 0200994870 Hotline 0225.999.6666