Nhảy tới nội dung

Xây dựng Chatbot Telegram với AI trong 30 phút | Hướng dẫn chi tiết

· 6 phút để đọc
OpenClaw VN Team

Telegram là nền tảng dễ nhất để bắt đầu với OpenClaw. Không cần QR scan như WhatsApp, không cần OAuth phức tạp như Discord.

Chỉ cần bot token là xong!

Tại sao chọn Telegram?

Setup nhanh nhất - Token + paste = done
API mạnh - File sharing, inline buttons, webhooks
Miễn phí - Không limit messages
Cross-platform - Desktop, mobile, web
Developer-friendly - Docs tốt, community lớn


Bước 1: Tạo Bot trên Telegram (5 phút)

1.1. Mở @BotFather

BotFather là "cha đẻ" của mọi bot Telegram. Mở app Telegram và search @BotFather

1.2. Tạo bot mới

Gửi lệnh:

/newbot

Bot sẽ hỏi:

BotFather: Alright, a new bot. How are we going to call it? 
Please choose a name for your bot.

Bạn: OpenClaw VN Assistant

1.3. Chọn username

BotFather: Good. Now let's choose a username for your bot. 
It must end in `bot`. Like this: TetrisBot or tetris_bot.

Bạn: openclaw_vn_assistant_bot
[Username rules]
  • Phải kết thúc bằng bot
  • Chỉ chứa a-z, 0-9, và underscore
  • Phải unique (chưa ai dùng)

1.4. Lấy token

BotFather sẽ trả lời:

Done! Congratulations on your new bot. 

Use this token to access the HTTP API:
1234567890:ABCdefGHIjklMNOpqrsTUVwxyz1234567

For a description of the Bot API, see this page:
https://core.telegram.org/bots/api

QUAN TRỌNG: Copy token này! Sẽ dùng ngay sau.


Bước 2: Kết nối Bot với OpenClaw (10 phút)

Giả sử bạn đã cài OpenClaw (Quick Start)

2.1. Login channel

openclaw channels login telegram

2.2. Paste token

? Enter your Telegram bot token: 
[Paste token ở đây]

2.3. Verify connection

openclaw channels list

Output:

✓ telegram (@openclaw_vn_assistant_bot) - Connected

🎉 Done! Bot đã kết nối.


Bước 3: Test bot (2 phút)

3.1. Tìm bot của bạn

Trong Telegram, search username: @openclaw_vn_assistant_bot

3.2. Start conversation

Click Start hoặc gửi:

/start

Bot sẽ trả lời:

Xin chào! Tôi là OpenClaw - trợ lý AI chạy trên máy của bạn.
Tôi có thể giúp gì cho bạn?

3.3. Thử nghiệm

Bạn: Xin chào! Bạn có thể làm gì?

Bot: Chào bạn! Tôi có thể:
- Trả lời câu hỏi
- Quản lý files trên máy
- Tìm kiếm thông tin
- Nhắc nhở lịch trình
- Và nhiều hơn nữa!

Bạn muốn thử tính năng nào?

Hoạt động!


Bước 4: Customize bot (10 phút)

4.1. Đổi ảnh đại diện

Gửi trong chat với BotFather:

/setuserpic

Chọn bot → Gửi ảnh

4.2. Thêm description

/setdescription

Example:

Trợ lý AI cá nhân chạy trên OpenClaw.
Hỗ trợ tiếng Việt, tự động hóa công việc hàng ngày.

4.3. Set commands

/setcommands

Paste:

start - Bắt đầu conversation
help - Hiện hướng dẫn
status - Check bot status
settings - Cấu hình bot

Giờ user có thể thấy menu commands:

Commands Menu

4.4. About text

/setabouttext

Example:

OpenClaw VN - Self-hosted AI assistant
https://openclaw-vn.dev

Bước 5: Advanced features (Optional)

5.1. Inline buttons

Tạo interactive messages:

// Trong OpenClaw config hoặc plugin
{
"text": "Chọn action:",
"buttons": [
{"text": "📁 List files", "callback": "list_files"},
{"text": "📅 Check calendar", "callback": "check_cal"}
]
}

5.2. File sharing

Bạn: Gửi cho tôi file report.pdf

Bot: ✅ Đây nhé!
[Sends file]

5.3. Image analysis

Bạn: [Gửi ảnh]
Phân tích ảnh này

Bot: Đây là biểu đồ cột thể hiện...
- Trục X: Tháng
- Trục Y: Doanh thu
- Trend: Tăng đều

5.4. Voice messages (if configured)

Bạn: [Gửi voice message]

Bot: [Transcribe]
Bạn nói: "Nhắc tôi meeting lúc 3PM"

✅ Đã set reminder!

Use Cases thực tế

1. Personal Assistant

8AM: Bot: 🌅 Chào buổi sáng!
Hôm nay bạn có 3 meetings.
Weather: 28°C, Sunny

You: Tóm tắt emails chưa đọc

Bot: Bạn có 12 emails:
[Top 3 important ones...]

2. File Manager

You: Tìm file "presentation.pptx"

Bot: Tìm thấy 2 files:
1. ~/Documents/presentation.pptx (modified today)
2. ~/Downloads/presentation.pptx (3 days ago)

Bạn cần file nào?

You: File 1

Bot: [Sends file via Telegram]

3. Quick Notes

You: Note: Mua sữa về nhà

Bot: ✅ Đã lưu note.
Total notes hôm nay: 5

You: Show notes hôm nay

Bot: 📝 Notes:
1. Meeting prep - 9AM
2. Call client - 11AM
...
5. Mua sữa về nhà - Just now

4. Reminders

You: Remind me "Gửi báo cáo" at 5PM

Bot: ✅ Set reminder cho 5PM hôm nay

[5PM]
Bot: 🔔 Reminder: Gửi báo cáo

Tips & Best Practices

1. Security

ĐỪNG:

  • Share bot token publicly
  • Add bot vào group chưa trust
  • Cho phép strangers chat với bot

NÊN:

# Giới hạn users được phép
openclaw config set telegram.allowedUsers "123456789,987654321"

# Mã hóa sensitive responses
openclaw config set telegram.encryption true

2. Rate Limiting

Telegram giới hạn:

  • 30 messages/second per bot
  • 20 messages/minute per chat

OpenClaw auto-handle, nhưng nếu cần:

openclaw config set telegram.rateLimit.enabled true
openclaw config set telegram.rateLimit.messagesPerSecond 20

3. Error Handling

# Auto-retry failed messages
openclaw config set telegram.retryFailed true

# Alert on errors
openclaw config set telegram.errorNotify true

4. Logging

# Log all messages (for debugging)
openclaw config set telegram.logMessages true

# Log location
~/.openclaw/logs/telegram-YYYY-MM-DD.log

Troubleshooting

Bot không trả lời

Check:

# Gateway running?
openclaw status

# Channel connected?
openclaw channels list

# Logs
openclaw logs --filter telegram

Common issues:

  • Gateway stopped → openclaw gateway
  • Token invalid → Re-login
  • Network issues → Check firewall

"Unauthorized" error

Token sai hoặc bot bị delete.

Fix:

  1. Create new bot qua BotFather
  2. Re-login: openclaw channels login telegram

Messages delayed

Possible causes:

  • High API usage → Check rate limits
  • Poor network → Test: ping api.telegram.org
  • Gateway overloaded → Check openclaw status

Next Steps

🎉 Chúc mừng! Bạn đã có chatbot Telegram hoạt động!

Tiếp theo:

  1. Add WhatsApp: Channels Overview
  2. Automation: Tính năng nâng cao
  3. Plugins: Cấu hình Gateway
  4. Deploy: Production Setup

Join community:


Có câu hỏi? Comment bên dưới hoặc hỏi trong Telegram group!