Slack
当你希望 Agent 在 Slack workspace 的私信、频道或 thread 中回复时,可以连接 Slack。
前提条件
- 已有 Cloud Agents Agent。
- 有权限在 workspace 中创建或管理 Slack app。
- 有权限把 app 安装到 workspace。
创建 Slack app
- 打开 Slack API Apps。
- 从头创建一个 app。
- 在 App Home 下添加 bot user。
- 打开 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
- 打开 Settings -> Channels。
- 创建新渠道并选择 Slack。
- 选择要接收消息的 Agent。
- 输入标签、
xoxb-bot token,以及 Basic Information 中的 signing secret。 - 创建渠道。
- 从渠道详情页复制 inbound URL。
- 在 Slack Event Subscriptions 中把 inbound URL 粘贴为 Request URL。
- 运行渠道测试。
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。