1. 创建 Slack App
首先需要在 Slack 上创建一个 App:
1. 访问 https://api.slack.com/apps
2. 点击 "Create New App"
3. 选择 "From scratch"
4. 输入 App 名称(例如:Clawdbot)
5. 选择工作空间
6. 创建完成后,进入 App 设置页面
2. 配置 Bot Token
在 Slack App 设置中:
1. 进入 Basic Information 页面
2. 滚动到 App-Level Tokens 部分
3. 点击 Create Token
4. 命名 token(例如:Clawdbot-App-Level-Token)
5. 选择权限范围:connections:write
6. 保存 token(格式:xapp-...) - 这是 App Token
7. 进入 OAuth & Permissions 页面
8. 添加 Bot Token Scopes(根据需要选择):
- chat:write - 发送消息
- chat:write.public - 在公开频道发送消息
- channels:join - 加入频道
- channels:history - 读取频道消息
- groups:history - 读取私有频道消息
- im:history - 读取私信消息
- mpim:history - 读取群组私信消息
- reactions:write - 添加表情回应
9. 安装 App 到工作空间
10. 复制生成的 Bot User OAuth Token(格式:xoxb-...)
3. 在 Clawdbot 中配置 Slack
使用以下命令添加 Slack 配置:
clawdbot channels add \
--channel slack \
--bot-token "xoxb-你的bot-token" \
--app-token "xapp-你的app-token"
或者如果使用环境变量(更安全的方式):
# 设置环境变量
export CLAWDBOT_SLACK_BOT_TOKEN="xoxb-你的bot-token"
export CLAWDBOT_SLACK_APP_TOKEN="xapp-你的app-token"
# 添加配置
clawdbot channels add --channel slack --use-env
4. 启用事件订阅(可选但推荐)
在 Slack App 设置中:
1. 进入 Event Subscriptions 页面
2. 启用 Enable Events
3. 设置 Request URL(需要 Clawdbot gateway 运行后提供)
4. 订阅事件:
- message.channels
- message.groups
- message.im
- message.mpim
5. 保存更改
5. 验证连接
# 查看通道状态
clawdbot channels status
# 查看配置的通道
clawdbot channels list
6. 测试发送消息
clawdbot message send \
--channel slack \
--target <channel-id或频道名> \
--message "Hello from Clawdbot!"
----
上述写法可能会有问题,会收不到消息,所以只能:
步骤 2: 在 Slack App 中启用 Socket Mode
1. 进入 Socket Mode 页面(在左侧导航栏)
2. 启用 Socket Mode("Use Socket Mode" 按钮应该开启)
3. 使用上面的 App-Level Token
4. 保存更改
步骤 3: 订阅事件(必需)
1. 进入 Event Subscriptions 页面
2. 启用 Events("Enable Events" 开关打开)
3. 在 "Subscribe to bot events" 下添加:
- message.channels (公开频道消息)
- app_mention (被提及时)
4. 点击 Save Changes
必须要订阅事件,由于 web 订阅对于 clawdbot 来说不可实现,因为他要么 local 要么 tailnet,正常网页会收不到消息,只有走 socket mode 才 OK
----
再更新:
chat:write (发送消息)
chat:write.public (在公开频道发送消息)
channels:history (读取公开频道消息)
channels:join (加入频道)
channels:read (读取频道信息)
groups:history (读取私有频道消息)
groups:read (读取私有频道信息)
im:history (读取私信)
im:read (读取私信信息)
im:write (发送私信)
mpim:history (读取群组私信)
mpim:read (读取群组私信信息)
mpim:write (发送群组私信)
users:read (读取用户信息)
app_mentions:read (读取提及时)
权限要给足,不然 cron的消息收不到
权限要给足,不然 cron的消息收不到

