適用於 OpenClaw v2026.2 | 本文假設你已完成 OpenClaw 安裝,有一個可用的 Telegram Bot Token(免費取得)。
TL;DR: Telegram 是設定最簡單的頻道:建立 Bot(@BotFather)、取得 Token、設定到 ~/.openclaw/openclaw.json、啟動 Gateway。預設啟用 DM 配對保護,群組需 @提及才回應。同時涵蓋 WhatsApp(掃碼登入)、Discord(Bot Token)、Slack 設定。
為什麼從 Telegram 開始?
頻道對比
| 特性 | Telegram | Discord | Slack | iMessage | |
|---|---|---|---|---|---|
| 設定難度 | ⭐ 簡單 | ⭐⭐ 中等 | ⭐⭐ 中等 | ⭐⭐ 中等 | ⭐⭐⭐ 複雜 |
| 免費使用 | ✅ | ✅ | ✅ | ✅ | ✅ |
| Bot API | ✅ 完善 | ⚠️ 有限 | ✅ 完善 | ✅ 完善 | ⚠️ 有限 |
| 群組支援 | ✅ | ✅ | ✅ | ✅ | ⚠️ |
| 檔案支援 | ✅ 2GB | ✅ 100MB | ✅ 25MB | ✅ 1GB | ✅ |
| 國內可用 | ⚠️ 需代理 | ✅ | ⚠️ 需代理 | ⚠️ 需代理 | ✅ |
| 推薦指數 | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐ |
選擇 Telegram 的理由
- 設定最簡單:只需建立 Bot 取得 Token 即可
- 文件最完善:Telegram Bot API 是業界標竿
- 功能最豐富:支援命令、按鈕、內聯查詢等
- 社群最活躍:問題容易找到解決方案
Telegram Bot 建立
步驟 1:找到 BotFather
- 開啟 Telegram 應用
- 搜尋
@BotFather(官方 Bot 管理工具) - 點擊進入對話
sequenceDiagram
participant U as 你
participant BF as BotFather
participant TG as Telegram
U->>BF: /newbot
BF->>U: 輸入 Bot 顯示名稱
U->>BF: My OpenClaw Assistant
BF->>U: 輸入 Bot 使用者名稱(必須以 bot 結尾)
U->>BF: myclaw_bot
BF->>TG: 建立 Bot
TG-->>BF: Bot 建立成功
BF->>U: 回傳 API Token
步驟 2:建立新 Bot
在 BotFather 中發送命令:
/newbot
按提示操作:
- Bot 顯示名稱:如
My OpenClaw(可以有空格) - Bot 使用者名稱:如
myclaw_bot(必須以bot結尾)
建立成功後,BotFather 會回傳:
Done! Congratulations on your new bot...
Use this token to access the HTTP API:
7123456789:AAHxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Keep your token secure...
⚠️ 重要:妥善保管 API Token,它擁有完全控制你 Bot 的權限。
步驟 3:設定 Bot 資訊(可選)
# 在 BotFather 中設定 Bot 頭像
/setuserpic
# 選擇你的 Bot,上傳圖片
# 設定 Bot 描述
/setdescription
# 選擇你的 Bot,輸入描述文字
# 設定 Bot 簡介
/setabouttext
# 選擇你的 Bot,輸入簡介文字
# 設定 Bot 命令
/setcommands
# 輸入命令列表,如:
# start - 開始使用
# help - 取得說明
# status - 查看狀態
設定 OpenClaw
方式 A:環境變數(快速測試)
# 設定環境變數
export TELEGRAM_BOT_TOKEN="7123456789:AAHxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# 啟動 Gateway
openclaw gateway
方式 B:設定檔(推薦正式環境)
編輯 ~/.openclaw/openclaw.json:
{
"agent": {
"model": "anthropic/claude-opus-4-6"
},
"channels": {
"telegram": {
"botToken": "7123456789:AAHxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
}
}
方式 C:使用 CLI 設定
# 互動式設定
openclaw config set channels.telegram.botToken "7123456789:AAH..."
# 或透過 onboard 精靈
openclaw onboard
驗證設定
# 檢查設定
openclaw config get channels.telegram.botToken
# 執行診斷
openclaw doctor
# 啟動 Gateway(除錯模式)
openclaw gateway --verbose
成功啟動後,你應該看到類似日誌:
[INFO] Gateway starting on port 18789
[INFO] Telegram channel connected
[INFO] Bot: @myclaw_bot
[INFO] Waiting for messages...
安全設定
DM 配對機制
預設情況下,OpenClaw 啟用 DM 配對機制(dmPolicy: "pairing"),防止陌生人濫用你的 Bot。
sequenceDiagram
participant S as 陌生人
participant B as Bot
participant G as Gateway
participant O as 你
S->>B: 發送訊息 "你好"
B->>G: 訊息到達
G->>G: 檢查配對狀態
G-->>B: 未配對,回傳配對碼
B-->>S: "請配對:配對碼 ABC123"
S->>O: 告訴你配對碼
O->>G: openclaw pairing approve telegram ABC123
G->>G: 加入白名單
G-->>S: 配對成功,可以對話
設定 DM 策略
{
"channels": {
"telegram": {
"botToken": "your_token",
"dmPolicy": "pairing",
"allowFrom": []
}
}
}
| 策略 | 說明 | 風險等級 |
|---|---|---|
pairing |
新使用者需要配對碼 | ⭐ 安全(預設) |
open |
任何人都可以發訊息 | ⭐⭐⭐ 危險 |
管理配對請求
# 查看待配對列表
openclaw pairing list
# 輸出範例:
# Channel Code User Created
# telegram ABC123 @stranger 2026-02-26 10:30:00
# 批准配對
openclaw pairing approve telegram ABC123
# 拒絕配對
openclaw pairing reject telegram ABC123
# 查看已配對使用者
openclaw pairing show telegram
白名單模式
只允許特定使用者發送訊息:
{
"channels": {
"telegram": {
"botToken": "your_token",
"dmPolicy": "open",
"allowFrom": [123456789, 987654321]
}
}
}
💡 取得 Telegram 使用者 ID:向
@userinfobot發送任意訊息,它會回傳你的數字 ID。
群組設定
基本群組設定
{
"channels": {
"telegram": {
"botToken": "your_token",
"groups": {
"*": {
"requireMention": true
}
}
}
}
}
| 設定項 | 說明 |
|---|---|
"*" |
匹配所有群組 |
requireMention |
群組中需要 @提及 Bot 才回應 |
多群組差異化設定
{
"channels": {
"telegram": {
"botToken": "your_token",
"groups": {
"-100123456789": {
"requireMention": false,
"name": "工作群"
},
"-100987654321": {
"requireMention": true,
"name": "閒聊群"
},
"*": {
"requireMention": true
}
}
}
}
}
💡 取得群組 ID:將 Bot 加入群組後,在群組中發送任意訊息,查看 Gateway 日誌即可看到群組 ID。
將 Bot 加入群組
- 在群組設定中點擊「新增成員」
- 搜尋你的 Bot 使用者名稱(如
@myclaw_bot) - 選擇新增
- (可選)將 Bot 設為管理員以取得更多權限
WhatsApp 設定
方式:掃碼登入
WhatsApp 使用 Web 協定,需要掃碼綁定:
# 啟動登入流程
openclaw channels login whatsapp
# 終端機顯示二維碼
# 使用手機 WhatsApp 掃描:
# 設定 > 已連結的裝置 > 連結裝置 > 掃描二維碼
sequenceDiagram
participant U as 使用者
participant C as CLI
participant W as WhatsApp
participant G as Gateway
U->>C: openclaw channels login whatsapp
C->>W: 請求二維碼
W-->>C: 回傳二維碼
C->>U: 顯示二維碼
U->>W: 手機掃碼
W-->>C: 認證成功
C->>G: 儲存認證資訊
G-->>U: WhatsApp 已連線
設定範例
{
"channels": {
"whatsapp": {
"allowFrom": ["+8613800138000"],
"groups": {
"*": {
"requireMention": true
}
}
}
}
}
WhatsApp 限制
| 限制項 | 說明 |
|---|---|
| 手機在線 | 需要 WhatsApp 手機端在線以維持連線 |
| 訊息延遲 | 可能存在幾秒到幾分鐘的延遲 |
| 檔案大小 | 最大 100MB |
| 號碼風險 | 頻繁使用可能導致號碼被限制 |
Discord 設定
建立 Discord Bot
- 存取 Discord Developer Portal
- 點擊「New Application」
- 輸入名稱,如
OpenClaw Assistant - 進入「Bot」頁面,點擊「Add Bot」
- 複製 Token(注意不是 Application ID)
設定 OAuth2 權限
- 進入「OAuth2」>「URL Generator」
- 勾選以下權限:
| 權限類別 | 具體權限 |
|---|---|
| Bot Permissions | |
| General | Read Messages/View Channels |
| General | Send Messages |
| General | Send Messages in Threads |
| General | Manage Messages |
| General | Embed Links |
| General | Attach Files |
| General | Read Message History |
| Text | Add Reactions |
| Text | Use Slash Commands |
- 複製產生的邀請連結
- 在瀏覽器開啟連結,將 Bot 邀請到伺服器
設定範例
{
"channels": {
"discord": {
"token": "MTk4NjIyNDgzNDc...",
"guilds": {
"*": {
"requireMention": true
}
}
}
}
}
Discord 特性設定
{
"channels": {
"discord": {
"token": "your_token",
"commands": {
"native": true,
"text": true
},
"mediaMaxMb": 25
}
}
}
| 設定項 | 說明 |
|---|---|
commands.native |
啟用 Discord 原生斜線命令 |
commands.text |
啟用文字命令(如 /help) |
mediaMaxMb |
媒體檔案大小限制 |
Slack 設定
建立 Slack App
- 存取 Slack API
- 點擊「Create New App」
- 選擇「From scratch」
- 輸入 App 名稱,選擇工作區
設定 OAuth 權限
在「OAuth & Permissions」頁面新增以下 Bot Token Scopes:
app_mentions:read
channels:history
channels:read
chat:write
files:read
files:write
groups:history
groups:read
im:history
im:read
im:write
mpim:history
mpim:read
mpim:write
reactions:read
reactions:write
users:read
安裝到工作區
- 點擊「Install to Workspace」
- 授權權限
- 複製 Bot User OAuth Token(以
xoxb-開頭)
設定範例
{
"channels": {
"slack": {
"botToken": "xoxb-...",
"appToken": "xapp-...",
"signingSecret": "..."
}
}
}
啟用 Socket Mode(推薦)
- 在「Socket Mode」頁面啟用
- 產生 App-Level Token
- 設定到 OpenClaw:
{
"channels": {
"slack": {
"botToken": "xoxb-...",
"appToken": "xapp-...",
"socketMode": true
}
}
}
多頻道同時啟用
完整設定範例
{
"agent": {
"model": "anthropic/claude-opus-4-6"
},
"gateway": {
"port": 18789,
"bind": "loopback"
},
"channels": {
"telegram": {
"botToken": "telegram_bot_token",
"dmPolicy": "pairing",
"groups": {
"*": { "requireMention": true }
}
},
"whatsapp": {
"allowFrom": ["+8613800138000"]
},
"discord": {
"token": "discord_token",
"guilds": {
"*": { "requireMention": true }
}
},
"slack": {
"botToken": "xoxb-...",
"appToken": "xapp-..."
}
}
}
訊息路由示意
flowchart TB
subgraph Users["使用者"]
WA[WhatsApp 使用者]
TG[Telegram 使用者]
DC[Discord 使用者]
SL[Slack 使用者]
end
subgraph Gateway["Gateway"]
MR[Message Router]
SM[Session Manager]
end
subgraph Agent["Pi Agent"]
AI[AI 核心]
CTX[共用上下文]
end
WA --> MR
TG --> MR
DC --> MR
SL --> MR
MR --> SM
SM --> AI
AI --> CTX
所有頻道共用同一個 Agent,上下文統一管理。這意味著:
- 在 Telegram 問的問題,可以在 WhatsApp 繼續討論
- 不同頻道的使用者可以共用同一份記憶
- 每個頻道可以有獨立的工作階段隔離策略
工作階段管理命令
所有頻道通用命令(在聊天中發送):
| 命令 | 功能 | 範例 |
|---|---|---|
/status |
查看工作階段狀態 | 顯示模型、Token 使用量 |
/new 或 /reset |
重設工作階段 | 清除上下文,開始新對話 |
/compact |
壓縮上下文 | 摘要歷史,釋放 Token |
/think <level> |
設定思考級別 | /think high |
/verbose on/off |
開關詳細輸出 | /verbose on |
/usage off/tokens/full |
使用量顯示模式 | /usage full |
故障排查
Telegram Bot 無回應
症狀:發送訊息後無回覆
排查步驟:
# 1. 檢查 Gateway 是否執行
curl http://127.0.0.1:18789/health
# 2. 檢查 Bot Token
openclaw config get channels.telegram.botToken
# 3. 查看詳細日誌
openclaw gateway --verbose
# 4. 使用 doctor 診斷
openclaw doctor
常見原因:
| 錯誤訊息 | 原因 | 解決方案 |
|---|---|---|
401 Unauthorized |
Token 無效 | 重新取得 Token |
409 Conflict |
Webhook 衝突 | 刪除舊 Webhook |
403 Forbidden |
Bot 被封鎖 | 聯繫 Telegram 支援 |
Connection refused |
Gateway 未執行 | 啟動 Gateway |
WhatsApp 掃碼失敗
症狀:掃碼後顯示失敗
解決方案:
# 重新產生二維碼
openclaw channels logout whatsapp
openclaw channels login whatsapp
# 檢查網路
ping web.whatsapp.com
# 清除憑證快取
rm -rf ~/.openclaw/credentials/whatsapp*
Discord Bot 無權限
症狀:Bot 在伺服器中無回應或無權限
解決方案:
- 檢查 Bot 角色權限
- 確認 Bot 已被邀請到伺服器
- 重新邀請 Bot(使用正確的 OAuth URL)
# 查看日誌中的權限錯誤
openclaw gateway --verbose 2>&1 | grep -i permission
設定不生效
症狀:修改設定後行為未變化
解決方案:
# 1. 重新啟動 Gateway
openclaw gateway --restart
# 2. 清除快取
rm -rf ~/.openclaw/cache/*
# 3. 驗證設定檔語法
cat ~/.openclaw/openclaw.json | jq .
# 4. 檢查設定優先順序
openclaw config list
安全最佳實務
1. Token 安全
# 不要將 Token 提交到版本控制
echo ".openclaw/" >> .gitignore
# 使用環境變數儲存敏感資訊
export TELEGRAM_BOT_TOKEN="your_token"
# 定期輪換 Token(在 BotFather 中)
# /revoke 命令可以重新產生 Token
2. 存取控制
{
"channels": {
"telegram": {
"dmPolicy": "pairing",
"allowFrom": [],
"groups": {
"*": { "requireMention": true }
}
}
},
"agents": {
"defaults": {
"sandbox": {
"mode": "non-main"
}
}
}
}
3. 日誌稽核
# 啟用詳細日誌
openclaw gateway --verbose
# 查看工作階段歷史
openclaw sessions list
openclaw sessions show <session-id>
# 稽核命令執行
grep "bash" ~/.openclaw/logs/gateway.log
下一步
恭喜!你已經完成了第一個頻道的設定。現在可以:
- 測試對話 → 在設定的頻道中發送訊息
- 安裝 Skills → 擴充 AI 能力
- 設定多頻道 → 新增更多頻道
本篇小結:
- 掌握了 Telegram Bot 建立和設定
- 理解了 DM 配對和群組設定
- 學會了 WhatsApp、Discord、Slack 的設定方法
- 了解了多頻道同時啟用的方式
- 掌握了常見問題的排查方法
更新記錄:
- 2026-02-26:初版發布,基於 OpenClaw v2026.2
系列導航:
- ← 上一篇:環境搭建與首次執行
- → 下一篇:Gateway 核心概念解析