CA
文档首页

Slack

当你希望 Agent 在 Slack workspace 的私信、频道或 thread 中回复时,可以连接 Slack。

前提条件

  • 已有 Cloud Agents Agent。
  • 有权限在 workspace 中创建或管理 Slack app。
  • 有权限把 app 安装到 workspace。

创建 Slack app

  1. 打开 Slack API Apps
  2. 从头创建一个 app。
  3. 在 App Home 下添加 bot user。
  4. 打开 OAuth & Permissions,并添加使用场景所需的 bot scopes。

推荐 bot scopes:

Scope用途
app_mentions:read接收频道中 mention bot 的消息。
chat:write发送 Agent 回复。
im:history接收私信。
im:read让 bot 访问 DM 会话。
im:write让 bot 发送 DM。
channels:history可选,用于 public channel 消息事件。
groups:history可选,用于 private channel 消息事件。

把 app 安装到 workspace,并复制 Bot User OAuth Token。它通常以 xoxb- 开头。

连接到 Cloud Agents

  1. 打开 Settings -> Channels
  2. 创建新渠道并选择 Slack。
  3. 选择要接收消息的 Agent。
  4. 输入标签、xoxb- bot token,以及 Basic Information 中的 signing secret。
  5. 创建渠道。
  6. 从渠道详情页复制 inbound URL。
  7. 在 Slack Event Subscriptions 中把 inbound URL 粘贴为 Request URL。
  8. 运行渠道测试。

Event subscriptions

启用 Event Subscriptions,并添加这些 bot events:

Event用途
app_mention用户在频道中 mention bot 时接收消息。
message.im接收发给 bot 的私信。

修改 scopes 或 event subscriptions 后,请重新安装 Slack app 到 workspace。

推荐设置

设置建议
Mention only频道中建议开启,让 Agent 只在被 mention 时回复。DM 仍然可用。
Shared session默认关闭,除非 Slack 频道中的所有人都应该共享同一段对话。
Thread isolation建议开启,让 Slack thread 映射到独立 Agent 会话。
Progress mode如果希望 Agent 工作时更新同一条消息,使用 preview。

验证

打开渠道详情页并运行 Test。健康的渠道会确认 Slack bot 身份和 active 状态。

排查问题

  • Request URL 验证失败:确认 signing secret,并粘贴 Cloud Agents 当前显示的 inbound URL。
  • Bot 不回复 DM:订阅 message.im 并重新安装 app。
  • Bot 不回复频道消息:订阅 app_mention,把 bot 邀请到频道,并 mention 它。
  • Scope 修改未生效:修改 scopes 后重新安装 Slack app。

另请参阅