跳转至

设置

安装插件,创建 Slack 应用,并为 OpenClaw 提供所需的 Token。

安装

openclaw plugins install @openclaw/slack

plugins install 注册并启用插件。在配置下面的 Slack 应用和频道设置之前,它不会执行任何操作。有关通用插件安装规则,请参阅 插件。

快速设置

本节的清单会创建工作区范围的安装。对于 Enterprise Grid 组织安装,请改用专用的 全组织清单和工作流。

1. 创建新的 Slack 应用

    打开 [api.slack.com/apps](https://api.slack.com/apps/new) → **创建新应用** → **从清单创建** → 选择你的工作区 → 粘贴以下其中一个清单 → **下一步** → **创建**。
{
  "display_information": {
    "name": "OpenClaw",
    "description": "Slack connector for OpenClaw"
  },
  "features": {
    "bot_user": { "display_name": "OpenClaw", "always_online": true },
    "app_home": {
      "home_tab_enabled": true,
      "messages_tab_enabled": true,
      "messages_tab_read_only_enabled": false
    },
    "agent_view": {
      "agent_description": "OpenClaw connects Slack Agent View conversations to OpenClaw agents.",
      "suggested_prompts": [
        { "title": "What can you do?", "message": "What can you help me with?" },
        {
          "title": "Summarize this channel",
          "message": "Summarize the recent activity in this channel."
        },
        { "title": "Draft a reply", "message": "Help me draft a reply." }
      ]
    },
    "slash_commands": [
      {
        "command": "/openclaw",
        "description": "Send a message to OpenClaw",
        "should_escape": false
      }
    ]
  },
  "oauth_config": {
    "scopes": {
      "bot": [
        "app_mentions:read",
        "assistant:write",
        "channels:history",
        "channels:read",
        "chat:write",
        "commands",
        "emoji:read",
        "files:read",
        "files:write",
        "groups:history",
        "groups:read",
        "im:history",
        "im:read",
        "im:write",
        "mpim:history",
        "mpim:read",
        "mpim:write",
        "pins:read",
        "pins:write",
        "reactions:read",
        "reactions:write",
        "usergroups:read",
        "users:read"
      ]
    }
  },
  "settings": {
    "socket_mode_enabled": true,
    "event_subscriptions": {
      "bot_events": [
        "app_home_opened",
        "app_mention",
        "app_context_changed",
        "agent_session_stopped",
        "agent_session_title_changed",
        "channel_rename",
        "member_joined_channel",
        "member_left_channel",
        "message.channels",
        "message.groups",
        "message.im",
        "message.mpim",
        "pin_added",
        "pin_removed",
        "reaction_added",
        "reaction_removed"
      ]
    }
  }
}
{
  "display_information": {
    "name": "OpenClaw",
    "description": "Slack connector for OpenClaw"
  },
  "features": {
    "bot_user": { "display_name": "OpenClaw", "always_online": true },
    "app_home": {
      "home_tab_enabled": true,
      "messages_tab_enabled": true,
      "messages_tab_read_only_enabled": false
    },
    "agent_view": {
      "agent_description": "OpenClaw connects Slack Agent View conversations to OpenClaw agents.",
      "suggested_prompts": [
        { "title": "What can you do?", "message": "What can you help me with?" },
        {
          "title": "Summarize this channel",
          "message": "Summarize the recent activity in this channel."
        },
        { "title": "Draft a reply", "message": "Help me draft a reply." }
      ]
    },
    "slash_commands": [
      {
        "command": "/openclaw",
        "description": "Send a message to OpenClaw",
        "should_escape": false
      }
    ]
  },
  "oauth_config": {
    "scopes": {
      "bot": [
        "app_mentions:read",
        "assistant:write",
        "channels:history",
        "channels:read",
        "chat:write",
        "commands",
        "groups:history",
        "groups:read",
        "im:history",
        "im:read",
        "im:write",
        "users:read"
      ]
    }
  },
  "settings": {
    "socket_mode_enabled": true,
    "event_subscriptions": {
      "bot_events": [
        "app_home_opened",
        "app_mention",
        "app_context_changed",
        "agent_session_stopped",
        "agent_session_title_changed",
        "message.channels",
        "message.groups",
        "message.im"
      ]
    }
  }
}

Note

推荐 匹配 Slack 插件的完整功能集:App Home、斜杠命令、文件、表情回应、置顶、群组 DM 和 emoji/usergroup 读取。当工作区策略限制权限范围时,请选择 最小——它涵盖 DM、频道/群组历史记录、提及和斜杠命令,但移除了文件、表情回应、置顶、群组 DM(mpim:*)、emoji:read 和 usergroups:read。有关每个权限范围的说明以及额外斜杠命令等可添加选项,请参阅 清单和权限范围检查清单。

Slack 创建应用后:

        - **基本信息 -> 应用级令牌 -> 生成令牌和权限范围**:添加 `connections:write`,保存,并复制应用级令牌。
        - **安装应用 -> 安装到工作区**:复制 Bot User OAuth 令牌。

**2. 配置 OpenClaw**

        推荐的 SecretRef 配置:

```bash
export SLACK_APP_TOKEN=slack-app-token-example
export SLACK_BOT_TOKEN=slack-bot-token-example
cat > slack.socket.patch.json5 <<'JSON5'
{
  channels: {
    slack: {
      enabled: true,
      mode: "socket",
      appToken: { source: "env", provider: "default", id: "SLACK_APP_TOKEN" },
      botToken: { source: "env", provider: "default", id: "SLACK_BOT_TOKEN" },
    },
  },
}
JSON5
openclaw config patch --file ./slack.socket.patch.json5 --dry-run
openclaw config patch --file ./slack.socket.patch.json5
```

        在配置 `channels.slack` 后,默认账户凭据回退。请在网关进程环境中设置这些变量(在启动网关的 shell 中导出它们,或将其添加到服务管理器环境中):

```bash
export SLACK_APP_TOKEN=slack-app-token-example
export SLACK_BOT_TOKEN=slack-bot-token-example
```

**3. 启动网关**

```bash
openclaw gateway
```

1. 创建新的 Slack 应用

    打开 [api.slack.com/apps](https://api.slack.com/apps/new) → **创建新应用** → **从清单创建** → 选择你的工作区 → 粘贴以下其中一个清单 → 将 `https://gateway-host.example.com/slack/events` 替换为你的公共网关 URL → **下一步** → **创建**。
{
  "display_information": {
    "name": "OpenClaw",
    "description": "Slack connector for OpenClaw"
  },
  "features": {
    "bot_user": { "display_name": "OpenClaw", "always_online": true },
    "app_home": {
      "home_tab_enabled": true,
      "messages_tab_enabled": true,
      "messages_tab_read_only_enabled": false
    },
    "agent_view": {
      "agent_description": "OpenClaw connects Slack Agent View conversations to OpenClaw agents.",
      "suggested_prompts": [
        { "title": "What can you do?", "message": "What can you help me with?" },
        {
          "title": "Summarize this channel",
          "message": "Summarize the recent activity in this channel."
        },
        { "title": "Draft a reply", "message": "Help me draft a reply." }
      ]
    },
    "slash_commands": [
      {
        "command": "/openclaw",
        "description": "Send a message to OpenClaw",
        "should_escape": false,
        "url": "https://gateway-host.example.com/slack/events"
      }
    ]
  },
  "oauth_config": {
    "scopes": {
      "bot": [
        "app_mentions:read",
        "assistant:write",
        "channels:history",
        "channels:read",
        "chat:write",
        "commands",
        "emoji:read",
        "files:read",
        "files:write",
        "groups:history",
        "groups:read",
        "im:history",
        "im:read",
        "im:write",
        "mpim:history",
        "mpim:read",
        "mpim:write",
        "pins:read",
        "pins:write",
        "reactions:read",
        "reactions:write",
        "usergroups:read",
        "users:read"
      ]
    }
  },
  "settings": {
    "event_subscriptions": {
      "request_url": "https://gateway-host.example.com/slack/events",
      "bot_events": [
        "app_home_opened",
        "app_mention",
        "app_context_changed",
        "agent_session_stopped",
        "agent_session_title_changed",
        "channel_rename",
        "member_joined_channel",
        "member_left_channel",
        "message.channels",
        "message.groups",
        "message.im",
        "message.mpim",
        "pin_added",
        "pin_removed",
        "reaction_added",
        "reaction_removed"
      ]
    },
    "interactivity": {
      "is_enabled": true,
      "request_url": "https://gateway-host.example.com/slack/events",
      "message_menu_options_url": "https://gateway-host.example.com/slack/events"
    }
  }
}
{
  "display_information": {
    "name": "OpenClaw",
    "description": "Slack connector for OpenClaw"
  },
  "features": {
    "bot_user": { "display_name": "OpenClaw", "always_online": true },
    "app_home": {
      "home_tab_enabled": true,
      "messages_tab_enabled": true,
      "messages_tab_read_only_enabled": false
    },
    "agent_view": {
      "agent_description": "OpenClaw connects Slack Agent View conversations to OpenClaw agents.",
      "suggested_prompts": [
        { "title": "What can you do?", "message": "What can you help me with?" },
        {
          "title": "Summarize this channel",
          "message": "Summarize the recent activity in this channel."
        },
        { "title": "Draft a reply", "message": "Help me draft a reply." }
      ]
    },
    "slash_commands": [
      {
        "command": "/openclaw",
        "description": "Send a message to OpenClaw",
        "should_escape": false,
        "url": "https://gateway-host.example.com/slack/events"
      }
    ]
  },
  "oauth_config": {
    "scopes": {
      "bot": [
        "app_mentions:read",
        "assistant:write",
        "channels:history",
        "channels:read",
        "chat:write",
        "commands",
        "groups:history",
        "groups:read",
        "im:history",
        "im:read",
        "im:write",
        "users:read"
      ]
    }
  },
  "settings": {
    "event_subscriptions": {
      "request_url": "https://gateway-host.example.com/slack/events",
      "bot_events": [
        "app_home_opened",
        "app_mention",
        "app_context_changed",
        "agent_session_stopped",
        "agent_session_title_changed",
        "message.channels",
        "message.groups",
        "message.im"
      ]
    },
    "interactivity": {
      "is_enabled": true,
      "request_url": "https://gateway-host.example.com/slack/events",
      "message_menu_options_url": "https://gateway-host.example.com/slack/events"
    }
  }
}

Note

推荐模式与 Slack 插件的完整功能集一致;最小模式会删除文件、反应、固定消息、群组 DM(mpim:*)、emoji:read 和 usergroups:read 权限,适用于受限工作区。有关每个 scope 的详细理由,请参阅 Manifest 与 scope 检查清单。

Info

这三个 URL 字段(slash_commands[].url、event_subscriptions.request_url 和 interactivity.request_url / message_menu_options_url)都指向同一个 OpenClaw 端点。Slack 的 manifest 架构要求它们分别命名,但 OpenClaw 按负载类型路由,因此单个 webhookPath(默认 /slack/events)就足够了。在 HTTP 模式下,没有 slash_commands[].url 的斜杠命令会静默失效。

创建 Slack 应用后:

- **Basic Information → App Credentials**:复制 **Signing Secret** 用于请求验证。
- **Install App -> Install to Workspace**:复制 Bot User OAuth Token。

2. 配置 OpenClaw

    推荐的 SecretRef 配置:
export SLACK_BOT_TOKEN=slack-bot-token-example
export SLACK_SIGNING_SECRET=slack-signing-secret-example
cat > slack.http.patch.json5 <<'JSON5'
{
  channels: {
    slack: {
      enabled: true,
      mode: "http",
      botToken: { source: "env", provider: "default", id: "SLACK_BOT_TOKEN" },
      signingSecret: { source: "env", provider: "default", id: "SLACK_SIGNING_SECRET" },
      webhookPath: "/slack/events",
    },
  },
}
JSON5
openclaw config patch --file ./slack.http.patch.json5 --dry-run
openclaw config patch --file ./slack.http.patch.json5

Note

为多账户 HTTP 模式使用唯一的 webhook 路径

为每个账户分配不同的 webhookPath(默认 /slack/events),以避免注册冲突。

3. 启动网关

openclaw gateway

用户身份(以真实身份发帖)

用户身份模式允许 OpenClaw 以授权 Slack 应用的人类用户身份进行读取和发帖。userToken 是实际使用的身份;配套的 Slack 应用通过 Socket Mode 或 HTTP 请求 URL 承载 Events API 流量。配套应用不需要 bot 用户或 bot token。

按以下步骤设置配套应用:

  1. 在 OAuth & Permissions -> User Token Scopes 下,添加以下用户级权限:

  2. 历史记录:channels:history、groups:history、im:history、mpim:history

  3. 会话查找:channels:read、groups:read、im:read、mpim:read
  4. 用户:users:read
  5. 发帖:chat:write(消息将以授权用户的身份发送)
  6. 打开 DM:im:write、mpim:write

  7. 在 Event Subscriptions -> Subscribe to events on behalf of users 下,添加以下用户事件。不要只将它们添加到 bot 事件列表中:

  8. message.channels

  9. message.groups
  10. message.im
  11. message.mpim

  12. 选择一种事件传输方式:

  13. Socket Mode:启用 Socket Mode,并创建具有 connections:write 权限的应用级令牌。将其配置为 appToken。

  14. HTTP Request URL:将 Event Subscriptions 指向公开的 OpenClaw Slack 端点,并复制 Basic Information -> App Credentials -> Signing Secret。将其配置为 signingSecret。

  15. 安装或重新安装应用,以目标人类用户身份授权,并将生成的用户 OAuth token 复制到 userToken 中。

Socket Mode 配置:

{
  channels: {
    slack: {
      postAs: "user",
      userToken: "<xoxp>",
      appToken: "<xapp>",
    },
  },
}

HTTP 请求 URL 配置:

{
  channels: {
    slack: {
      postAs: "user",
      mode: "http",
      userToken: "<xoxp>",
      signingSecret: "<signing-secret>",
      webhookPath: "/slack/events",
    },
  },
}

Warning

私聊和群组私聊仅能通过上述用户级事件订阅工作。bot 无法加入人类 1:1 私聊,也无法被插入到现有群组私聊中。配套应用是不可见的管道:其他 Slack 成员看到的是来自授权人类用户的消息,而不是 OpenClaw bot 的消息。

OpenClaw 会自动丢弃由已解析的人类身份发出的用户级消息事件,因此它发送的消息不会触发自我回复。

令牌模型

  • Bot 身份(默认)在 Socket Mode 下需要 botToken + appToken,或在 HTTP 模式下需要 botToken + signingSecret。
  • 用户身份在 Socket Mode 下需要 userToken + appToken,或在 HTTP 模式下需要 userToken + signingSecret。它不使用 bot token。
  • 中继模式需要 botToken 以及 relay.url、relay.authToken 和 relay.gatewayId;它不使用 app token 或 signing secret。
  • botToken、appToken、signingSecret、relay.authToken 和 userToken 接受明文字符串或 SecretRef 对象。
  • 配置中的令牌会覆盖环境变量回退值。
  • SLACK_BOT_TOKEN、SLACK_APP_TOKEN 和 SLACK_USER_TOKEN 环境变量回退值仅适用于默认账户。
  • userToken 默认采用只读行为(userTokenReadOnly: true)。

状态快照行为:

  • Slack 账户检查会跟踪每个凭据的 *Source 和 *Status 字段(botToken、appToken、signingSecret、userToken)。
  • 状态为 available、configured_unavailable 或 missing。
  • configured_unavailable 表示账户已通过 SecretRef 或其他非内联机密源配置,但当前命令/运行时路径无法解析实际值。
  • 在 HTTP 模式下,包含 signingSecretStatus。Socket Mode 对 bot 身份使用 botTokenStatus + appTokenStatus,对用户身份使用 userTokenStatus + appTokenStatus。

Tip

对于 bot 身份,操作和目录读取可以优先使用可选的用户 token;除非 userTokenReadOnly: false 允许回退,否则写入继续使用 bot token。对于 postAs: "user",读取和写入始终使用 userToken。

本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 cl/openclaw