1 つの Bot で複数タスクを整理する: Workspace x Telegram 完全ガイド

5 min read

「今日の日記を整理して」と頼んだのに、仕事プロジェクトのファイルまで触られたら困りますよね。

それは Workspace の切り分けが不十分 なときに起きます。このガイドで一気に整理しましょう。

このページで学べること

  • 全体の流れ: グループ → アシスタント → Workspace
  • 複数 Workspace の初期化
  • Agents + Bindings の完全設定
  • 設定が効いているか確認する方法

全体像

目指す構成は次のとおりです。

Telegram グループ A  →  Assistant A  →  Workspace A(この中だけ触る)
Telegram グループ B  →  Assistant B  →  Workspace B(この中だけ触る)
DM                   →  Main Assistant → Main Workspace

実現のための手順は 3 つ。Workspace を作る → Agent を定義する → Bindings を定義する


手順 1: Workspace を作る

各アシスタントには専用ディレクトリが必要です。次のように初期化します。

openclaw setup --workspace "~/.openclaw/workspace-main"
openclaw setup --workspace "~/.openclaw/workspace-project-a"
openclaw setup --workspace "~/.openclaw/workspace-project-b"

各 Workspace には AGENTS.mdSOUL.mdIDENTITY.md など必要なファイルが自動生成されます。

💡 ディレクトリが存在しなくてもコマンドが作ってくれます。Git から既存 Workspace を clone したなら、初期化を省いて Config でパスを指定するだけでも構いません。


手順 2: Agents と Bindings を設定する

Control UI → Config → Raw JSON を開いて、次の構造を追加します。

シナリオ A: 同じ Bot、違うグループ、違う Workspace

{
  "agents": {
    "list": [
      { "id": "main",      "name": "Main",      "workspace": "~/.openclaw/workspace-main",      "default": true },
      { "id": "project-a", "name": "Project A", "workspace": "~/.openclaw/workspace-project-a" },
      { "id": "project-b", "name": "Project 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": "your bot token",
      "dmPolicy": "pairing",
      "groups": { "*": { "requireMention": true } }
    }
  }
}

グループ ID の調べ方

  1. グループに何かメッセージを送る
  2. openclaw logs --follow を実行して chat.id を探す
  3. またはメッセージを @userinfobot に転送する

シナリオ B: Bot アカウントごとに別 Workspace

複数の Bot Token があるなら、Bot ごとに独自の Assistant と Workspace を持たせられます。

{
  "agents": {
    "list": [
      { "id": "main",   "name": "Main Bot",   "workspace": "~/.openclaw/workspace-main",   "default": true },
      { "id": "alerts", "name": "Alerts 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:yourTelegramId"] }
      }
    }
  }
}

⚠️ 複数アカウント運用では、トップレベルの botToken は使わず、すべて accounts 配下にまとめます。


手順 3: 保存して確認する

Web UI から: Config ページで Save / Apply を押します。

ファイルを直接編集した場合: ~/.openclaw/openclaw.json を保存します。多くの場合ホットリロードされますが、不安なら再起動します。

openclaw gateway

確認方法

  • 各 Telegram グループでメッセージを送り、正しいアシスタントが返事するか確認する
  • openclaw doctor で簡易ヘルスチェックを行う

覚えておくべきポイント

目的 方法
新しい Workspace を作る openclaw setup --workspace "path"
グループごとに別 Workspace bindingspeer: { kind: "group", id: "groupId" } を使う
Bot ごとに別 Workspace channels.telegram.accountsaccountId を組み合わせる
Bindings が効かない 具体的なルールを前に置く。先に当たったものが勝つ

関連記事