Slack
GolemBot 通过 Socket Mode 连接 Slack,无需公网 URL。支持私信(DM)和频道内 @mention 响应。
前置条件
- 拥有管理员权限的 Slack 工作区
- Node.js ≥ 18
安装 SDK
bash
npm install @slack/bolt创建 Slack App
- 前往 api.slack.com/apps,点击 Create New App → From scratch。
- 在 Socket Mode 中开启,并生成一个 App-Level Token(权限范围:
connections:write)。复制xapp-...开头的 token。 - 在 OAuth & Permissions → Bot Token Scopes 下添加:
chat:write— 发送消息im:history— 读取私信channels:history— 读取频道消息(用于 @mention)
- 在 Event Subscriptions → Subscribe to bot events 下添加:
message.im— 私信事件app_mention— 频道 @mention 事件
- 将 App 安装到工作区,复制 Bot Token(
xoxb-...)。
配置 golem.yaml
yaml
name: my-assistant
engine: claude-code
channels:
slack:
botToken: ${SLACK_BOT_TOKEN} # xoxb-...
appToken: ${SLACK_APP_TOKEN} # xapp-...运行前设置环境变量:
bash
export SLACK_BOT_TOKEN=xoxb-...
export SLACK_APP_TOKEN=xapp-...
golem gateway工作原理
| 场景 | 行为 |
|---|---|
| 私信(DM) | 始终响应 |
频道 @mention(@机器人 消息) | 去掉 <@BOT_ID> 前缀后处理 |
| 频道普通消息(无 @mention) | 忽略 |
每个会话(私信或频道)维护独立的对话上下文。
消息长度限制
响应超过 4,000 字符 时会自动分段发送。