一個 Bot,多個任務不混亂——Workspace × Telegram 完整設定指南
5 min read
有沒有想過,跟助理說「幫我整理今天的日記」,結果他去動了你工作專案的檔案⋯
這就是沒有正確設定 Workspace 的後果。這篇幫你一次搞定。
本篇學習目標
- 理解整體架構:群組 → 助理 → 工作區
- 學會初始化多個工作區
- 完整設定 Agents + Bindings
- 驗證設定是否生效
整體思路
目標很簡單:
Telegram 群組 A → 助理 A → 工作區 A(只動這裡的檔案)
Telegram 群組 B → 助理 B → 工作區 B(只動這裡的檔案)
私人對話 → 主助理 → 主工作區
實現它需要三個步驟:建立工作區 → 設定 Agents → 設定 Bindings。
第一步:建立工作區
每個助理需要一個專屬目錄。用指令初始化它:
openclaw setup --workspace "~/.openclaw/workspace-main"
openclaw setup --workspace "~/.openclaw/workspace-project-a"
openclaw setup --workspace "~/.openclaw/workspace-project-b"每個工作區會自動產生需要的設定檔(AGENTS.md、SOUL.md、IDENTITY.md 等)。
💡 目錄不存在也沒關係,指令會自動幫你建立。如果你從 git clone 了現成的 workspace,可以跳過這步,直接在 Config 裡指定路徑。
第二步:設定 Agents 與 Bindings
打開 Control UI → Config → Raw JSON,加入以下結構:
情境 A:同一個 Bot,不同群組用不同 workspace
{
"agents": {
"list": [
{ "id": "main", "name": "主站", "workspace": "~/.openclaw/workspace-main", "default": true },
{ "id": "project-a", "name": "專案 A", "workspace": "~/.openclaw/workspace-project-a" },
{ "id": "project-b", "name": "專案 B", "workspace": "~/.openclaw/workspace-project-b" }
]
},
"bindings": [
{ "agentId": "project-a", "match": { "channel": "telegram", "peer": { "kind": "group", "id": "-1001234567890" } } },
{ "agentId": "project-b", "match": { "channel": "telegram", "peer": { "kind": "group", "id": "-1009876543210" } } },
{ "agentId": "main", "match": { "channel": "telegram" } }
],
"channels": {
"telegram": {
"enabled": true,
"botToken": "你的Bot Token",
"dmPolicy": "pairing",
"groups": { "*": { "requireMention": true } }
}
}
}怎麼找群組 ID?
- 在群組發任意一則訊息
- 跑
openclaw logs --follow,找 log 裡的chat.id(通常是負數) - 或把訊息轉發給 @userinfobot
情境 B:不同 Bot 帳號,各自對應不同 workspace
多個 Bot Token,每個 Bot 有自己的助理和工作區:
{
"agents": {
"list": [
{ "id": "main", "name": "主 Bot", "workspace": "~/.openclaw/workspace-main", "default": true },
{ "id": "alerts", "name": "通知 Bot", "workspace": "~/.openclaw/workspace-alerts" }
]
},
"bindings": [
{ "agentId": "main", "match": { "channel": "telegram", "accountId": "default" } },
{ "agentId": "alerts", "match": { "channel": "telegram", "accountId": "alerts" } }
],
"channels": {
"telegram": {
"enabled": true,
"accounts": {
"default": { "botToken": "123456:ABC...", "dmPolicy": "pairing" },
"alerts": { "botToken": "987654:XYZ...", "dmPolicy": "allowlist", "allowFrom": ["tg:你的TelegramID"] }
}
}
}
}⚠️ 使用多帳號時,不要再用頂層的
botToken,全部改寫在accounts裡。
第三步:存檔並驗證
Web UI:按 Config 頁的 Save / Apply。
直接改檔案:儲存 ~/.openclaw/openclaw.json,Gateway 通常會自動重載;不確定就重啟:
openclaw gateway驗證結果:
- 到對應的 Telegram 群組發訊息,確認助理回覆正常
- 跑
openclaw doctor快速健康檢查
設定重點整理
| 目標 | 作法 |
|---|---|
| 建立新 workspace | openclaw setup --workspace "路徑" |
| 不同群組 → 不同 workspace | bindings 裡用 peer: { kind: "group", id: "群組ID" } |
| 不同 Bot → 不同 workspace | channels.telegram.accounts 多帳號 + bindings 用 accountId |
| Bindings 不生效 | 確認具體規則在前面,順序是「先命中先贏」 |