3. Installation & Telegram Setup
Thời gian: 15-20 phút | Mục tiêu: Cài đặt OpenClaw và chạy Telegram bot
Yêu cầu hệ thống
| Thành phần | Yêu cầu |
|---|---|
| Node.js | >= 22.12.0 |
| RAM | Tối thiểu 4GB |
| Disk | 2GB trống |
| OS | macOS, Linux, Windows |
Phần 1: Cài đặt OpenClaw
Bước 1.1: Kiểm tra Node.js
bash
node --versionCần >= 22.12.0. Nếu chưa có:
bash
# macOS (dùng Homebrew)
brew install node@22
# Ubuntu/Debian
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs
# Windows
curl -fsSL https://nodejs.org/dist/v22.12.0/node-v22.12.0-x64.msi -o node.msi
msiexec /i node.msiBước 1.2: Cài đặt OpenClaw
Cách 1: Script (Khuyến nghị)
bash
# macOS/Linux
curl -fsSL https://openclaw.ai/install.sh | bash
# Windows
iwr -useb https://openclaw.ai/install.ps1 | iexCách 2: npm
bash
npm install -g openclaw@latestCách 3: Homebrew (macOS)
bash
brew install openclawBước 1.3: Kiểm tra cài đặt
bash
openclaw --versionKết quả mong đợi: openclaw/1.x.x
Phần 2: Chuẩn bị API Keys
2.1 Lấy Anthropic API Key (Khuyến nghị)
- Truy cập: https://console.anthropic.com
- Đăng ký/Đăng nhập
- Settings → API Keys
- Tạo key mới → Copy
2.2 OpenAI API Key (Tùy chọn)
- Truy cập: https://platform.openai.com
- API Keys → Create new secret key
2.3 Lưu API Key
bash
# macOS/Linux - thêm vào ~/.bashrc hoặc ~/.zshrc
export ANTHROPIC_API_KEY="sk-ant-xxxxx"
export OPENAI_API_KEY="sk-xxxxx"
# Windows PowerShell - thêm vào profile
$env:ANTHROPIC_API_KEY="sk-ant-xxxxx"Phần 3: Cấu hình Telegram
3.1 Tạo Bot với BotFather
- Mở Telegram → Tìm
@BotFather - Nhấp Start hoặc gửi
/start - Gửi
/newbot - Trả lời các câu hỏi:
- Tên hiển thị:
My OpenClaw Bot - Username:
myopenclaw_bot(phải kết thúc bằng_bot)
- Tên hiển thị:
- Sao chép token (VD:
123456789:ABCdefGHIjklMNOpqrSTUvwxyz)
3.2 Cấu hình OpenClaw
Cách 1: Dùng wizard (Khuyến nghị)
bash
openclaw onboardWizard sẽ hỏi:
- Select LLM provider: Chọn
anthropic - API Key: Dán
sk-ant-xxxxx - Select channel: Chọn
telegram - Bot token: Dán
123456789:ABC... - Security mode: Chọn
pairing(khuyến nghị) - Gateway port: Enter để dùng 18789
Cách 2: Manual config
bash
# Set từng giá trị
openclaw config set agent.model "anthropic/claude-3-5-sonnet-20241022"
openclaw config set agent.apiKey "${ANTHROPIC_API_KEY}"
openclaw config set channels.telegram.botToken "${TELEGRAM_BOT_TOKEN}"
openclaw config set gateway.port 187893.3 File config sau khi setup
~/.openclaw/openclaw.jsonjson5
{
agent: {
model: "anthropic/claude-3-5-sonnet-20241022",
apiKey: "${ANTHROPIC_API_KEY}",
},
gateway: {
port: 18789,
bind: "loopback",
},
channels: {
telegram: {
botToken: "${TELEGRAM_BOT_TOKEN}",
},
},
}Phần 4: Khởi động và Test
4.1 Khởi động Gateway
bash
openclaw gateway --port 18789Output mong đợi:
[Gateway] Listening on port 18789
[Telegram] Bot connected: @myopenclaw_bot
[Agent] Connected to anthropic/claude-3-5-sonnet-202410224.2 Test bot
- Mở Telegram → Tìm bot của bạn (
@myopenclaw_bot) - Gửi:
/start - Gửi:
Hello! - Đợi phản hồi từ AI
Thành công nếu bot phản hồi!
4.3 Mở Dashboard
Truy cập: http://127.0.0.1:18789/
- Chat với AI
- Xem/cấu hình settings
- Theo dõi sessions
Phần 5: Cài đặt Daemon (Tùy chọn)
Để Gateway tự động chạy khi khởi động:
bash
# macOS
openclaw onboard --install-daemon
# Linux (systemd)
openclaw service install
sudo systemctl enable openclaw
sudo systemctl start openclaw
# Windows
# Dùng Task Scheduler hoặc chạy thủ côngPhần 6: Troubleshooting
"openclaw: command not found"
bash
# Kiểm tra npm global path
npm bin -g
# Thêm vào PATH
export PATH="$PATH:$(npm bin -g)""Cannot find module"
bash
# Cài lại
npm uninstall -g openclaw
npm install -g openclaw@latest"Invalid API Key"
- Kiểm tra key có đúng không
- Đảm bảo key được export vào environment
- Kiểm tra
openclaw config show agent.apiKey
Bot không phản hồi
bash
# Kiểm tra logs
openclaw logs --tail 50
# Kiểm tra channel status
openclaw channels status telegramTóm tắt commands
bash
# Cài đặt
curl -fsSL https://openclaw.ai/install.sh | bash
# Chạy wizard
openclaw onboard
# Khởi động
openclaw gateway --port 18789
# Kiểm tra
openclaw status
openclaw doctor
# Xem logs
openclaw logs --tail 100Tiếp theo?
- Bài 4: Security - Pairing, Allowlist, DM Policy
- Bài 5: Daily Usage - Commands, Tools, Workflows