OpenClaw 多飞书机器人配置指南

0 阅读3分钟

本文档介绍如何在 OpenClaw 中配置多个飞书机器人,分别绑定到不同的 Agent。


一、创建 Agent

1.1 创建 Agent 步骤

# 创建新的 Agent
openclaw agents add <agent名称>

# 示例:创建 dailynews agent
openclaw agents add dailynews

1.2 查看 Agent 列表

openclaw agents list

输出示例:

Agents:
- main (default)
  Identity: 💼✨ 小美
  Workspace: ~/.openclaw/workspace
- dailynews
  Workspace: ~/.openclaw/workspace-dailynews

1.3 配置 Agent 文件

每个 Agent 需要有自己的 workspace 目录和相关配置文件:

文件说明
IDENTITY.mdAgent 身份信息(名字、性格、emoji)
SOUL.mdAgent 核心价值观和行为准则
USER.md人类用户信息
AGENTS.mdAgent 的行为规范
HEARTBEAT.md主动模式任务清单
MEMORY.md长期记忆

1.4 Agent 完整配置示例

{
  "agents": {
    "list": [
      {
        "id": "main",
        "default": true,
        "name": "小美",
        "workspace": "/home/username/.openclaw/workspace"
      },
      {
        "id": "dailynews",
        "name": "dailynews",
        "workspace": "/home/username/.openclaw/workspace-dailynews"
      },
      {
        "id": "dev",
        "name": "开发助理",
        "workspace": "/home/username/.openclaw/workspace-dev"
      }
    ]
  }
}

二、配置 Channel(飞书)

2.1 在飞书开放平台创建机器人

  1. 打开 飞书开放平台
  2. 创建企业自建应用
  3. 在应用详情中获取:
    • App ID(如 cli_xxx
    • App Secret
  4. 添加权限:
    • contact:contact.base:readonly - 读取通讯录
    • im:message:send_as_bot - 发消息
    • im:message:receive - 收消息
  5. 发布应用

2.2 配置 openclaw.json

{
  "channels": {
    "feishu": {
      "enabled": true,
      "defaultAccount": "main",
      "domain": "feishu",
      "accounts": {
        "main": {
          "appId": "cli_第一个机器人的appId",
          "appSecret": "第一个机器人的secret"
        },
        "dailynews": {
          "appId": "cli_第二个机器人的appId",
          "appSecret": "第二个机器人的secret"
        },
        "dev": {
          "appId": "cli_第三个机器人的appId",
          "appSecret": "第三个机器人的secret"
        }
      }
    }
  }
}

2.3 验证 Channel 配置

openclaw channels list

输出示例:

Chat channels:
- Feishu main: configured, enabled
- Feishu dailynews: configured, enabled
- Feishu dev: configured, enabled

三、绑定 Agent 到 Channel

3.1 使用命令绑定

# 绑定 agent 到指定飞书账号
openclaw agents bind --agent <agentId> --bind feishu:<accountId>

# 示例
openclaw agents bind --agent main --bind feishu:main
openclaw agents bind --agent dailynews --bind feishu:dailynews

3.2 或直接在配置文件中添加 bindings

{
  "bindings": [
    {
      "agentId": "main",
      "match": {
        "channel": "feishu",
        "accountId": "main"
      }
    },
    {
      "agentId": "dailynews",
      "match": {
        "channel": "feishu",
        "accountId": "dailynews"
      }
    },
    {
      "agentId": "dev",
      "match": {
        "channel": "feishu",
        "accountId": "dev"
      }
    }
  ]
}

3.3 查看绑定结果

openclaw agents bindings

输出示例:

Routing bindings:
- dailynews <- feishu accountId=dailynews
- main <- feishu accountId=main
- dev <- feishu accountId=dev

四、配置用户白名单

4.1 创建白名单文件

适用openclaw pairing approve 形式配置飞书后,发现只能同时有一个正常工作,所以改用白名单形式

vim ~/.openclaw/credentials/feishu-allowFrom.json

内容:

{
  "version": 1,
  "allowFrom": [
    "ou_用户的open_id_1",
    "ou_用户的open_id_2"
  ]
}

4.2 获取用户 open_id

推荐使用飞书开放平台的 API 工具获取:

  1. 打开 open.feishu.cn/document/se…
  2. 在页面中的 user_id 参数处选择用户
  3. 点击"尝试"按钮
  4. 返回结果中会显示用户的 user_idopen_id

或者在飞书中:

  • 打开用户主页 → 点击分享 → 复制链接,链接中包含用户ID

4.3 说明

  • 使用 allowFrom 白名单后,不需要执行 openclaw pairing approve
  • 白名单更安全,只允许特定用户使用该机器人

五、重启并验证

5.1 重启 Gateway

openclaw gateway restart

5.2 测试

用不同的飞书机器人发送消息,检查是否路由到对应的 Agent。


六、注意事项

6.1 多账号限制

  • OpenClaw 当前版本(2026.3.x)飞书多账号功能在完善中
  • 主要限制:一次只能配对(pairing)一个机器人
  • 解决:使用 allowFrom 白名单机制,避免 pairing

七、完整配置示例

{
  "agents": {
    "list": [
      {
        "id": "main",
        "default": true,
        "name": "小美",
        "workspace": "/home/username/.openclaw/workspace"
      },
      {
        "id": "dailynews",
        "name": "dailynews",
        "workspace": "/home/username/.openclaw/workspace-dailynews"
      }
    ]
  },
  "channels": {
    "feishu": {
      "enabled": true,
      "defaultAccount": "main",
      "domain": "feishu",
      "accounts": {
        "main": {
          "appId": "cli_xxx1",
          "appSecret": "secret1"
        },
        "dailynews": {
          "appId": "cli_xxx2",
          "appSecret": "secret2"
        }
      }
    }
  },
  "bindings": [
    {
      "agentId": "main",
      "match": {
        "channel": "feishu",
        "accountId": "main"
      }
    },
    {
      "agentId": "dailynews",
      "match": {
        "channel": "feishu",
        "accountId": "dailynews"
      }
    }
  ]
}

八、常见问题

Q: 提示 "access not configured"

A: 确认 channels.feishu.accounts 中是否配置了对应账号

Q: 提示权限错误

A: 需要在飞书开放平台授权:
open.feishu.cn/app/{appId}…

Q: 绑定后不生效

A: 执行 openclaw gateway restart 重启 Gateway