Skip to content

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ầnYêu cầu
Node.js>= 22.12.0
RAMTối thiểu 4GB
Disk2GB trống
OSmacOS, Linux, Windows

Phần 1: Cài đặt OpenClaw

Bước 1.1: Kiểm tra Node.js

bash
node --version

Cầ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.msi

Bướ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 | iex

Cách 2: npm

bash
npm install -g openclaw@latest

Cách 3: Homebrew (macOS)

bash
brew install openclaw

Bước 1.3: Kiểm tra cài đặt

bash
openclaw --version

Kế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ị)

  1. Truy cập: https://console.anthropic.com
  2. Đăng ký/Đăng nhập
  3. Settings → API Keys
  4. Tạo key mới → Copy

2.2 OpenAI API Key (Tùy chọn)

  1. Truy cập: https://platform.openai.com
  2. 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

  1. Mở Telegram → Tìm @BotFather
  2. Nhấp Start hoặc gửi /start
  3. Gửi /newbot
  4. 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)
  5. 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 onboard

Wizard sẽ hỏi:

  1. Select LLM provider: Chọn anthropic
  2. API Key: Dán sk-ant-xxxxx
  3. Select channel: Chọn telegram
  4. Bot token: Dán 123456789:ABC...
  5. Security mode: Chọn pairing (khuyến nghị)
  6. 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 18789

3.3 File config sau khi setup

~/.openclaw/openclaw.json
json5
{
  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 18789

Output mong đợi:

[Gateway] Listening on port 18789
[Telegram] Bot connected: @myopenclaw_bot
[Agent] Connected to anthropic/claude-3-5-sonnet-20241022

4.2 Test bot

  1. Mở Telegram → Tìm bot của bạn (@myopenclaw_bot)
  2. Gửi: /start
  3. Gửi: Hello!
  4. Đợ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ông

Phầ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 telegram

Tó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 100

Tiếp theo?

Internal documentation for iNET Portal