slack-cli-api-reference
Slack Web API curl 命令参考——发/更/删消息、thread reply、reactions.add、文件上传 v2、读 thread、频道/用户查询、Block Kit 选型、token 提取、URL→ts 转换、常见坑全集。Use when 查 API 命令语法/参数、排查 `invalid_blocks`/`not_in_channel`/`missing_scope`/消息只剩首行/attachment 静默丢失、或需要 `reactions.add`/`files.getUploadURLExternal`/`chat.getPermalink` 的具体 curl 示例。
- License 许可
- MIT
- 所属仓库
- KarryViber/Orb
- 最近更新
- 2026-05-14
- Stars
- ★ 66
- Forks
- 8
01 前言 Front Matter
- name
- slack-cli-api-reference
- description
- Slack Web API curl 命令参考——发/更/删消息、thread reply、reactions.add、文件上传 v2、读 thread、频道/用户查询、Block Kit 选型、token 提取、URL→ts 转换、常见坑全集。Use when 查 API 命令语法/参数、排查 `invalid_blocks`/`not_in_channel`/`missing_scope`/消息只剩首行/attachment 静默丢失、或需要 `reactions.add`/`files.getUploadURLExternal`/`chat.getPermalink` 的具体 curl 示例。
03 SKILL.md 正文
Slack Web API curl 参考手册
When to Use
- 查具体 curl 命令参数(channel、ts、blocks 字段格式)
- Slack URL → timestamp 转换
- 排查
invalid_blocks/not_in_channel/missing_scope/ 消息只剩首行 - 需要
reactions.add/ 文件上传 /chat.getPermalink的完整示例
Token 提取(必用)
SLACK_BOT_TOKEN=$(grep -E '^SLACK_BOT_TOKEN=' ~/Orb/.env | head -1 | cut -d= -f2- | tr -d "'" '"')
禁止 source ~/Orb/.env——第 26 行 SLACK_HOME_CHANNEL_NAME=Karry Slack DM 未加引号,bash 会把 Slack DM 当命令执行 → bash: Slack: command not found。
必需 Bot Scopes:channels:history · channels:read · groups:history · chat:write · chat:write.public · users:read · files:write · reactions:write
发送消息
发文本 / Thread Reply
始终用 Content-Type: application/json——form-encoded 传 attachments[].blocks 会被 Slack 静默丢弃。
curl -s https://slack.com/api/chat.postMessage \
-H "Authorization: Bearer $SLACK_BOT_TOKEN" \
-H "Content-Type: application/json; charset=utf-8" \
--data-raw '{
"channel": "C01ABC123",
"thread_ts": "1775307969.013919",
"text": "fallback 摘要(不要传空格)",
"blocks": [{"type":"section","text":{"type":"mrkdwn","text":"*详情*"}}],
"unfurl_links": false,
"unfurl_media": false
}'
thread_ts 省略 = 发主消息,带上 = 发 thread reply。
更新消息
curl -s https://slack.com/api/chat.update \
-H "Authorization: Bearer $SLACK_BOT_TOKEN" \
-H "Content-Type: application/json; charset=utf-8" \
--data-raw '{"channel":"C01ABC123","ts":"1775308000.100001","text":"更新内容","blocks":[...]}'
删除消息
curl -s https://slack.com/api/chat.delete \
-d "channel=C01ABC123" -d "ts=1775308000.100001" \
-H "Authorization: Bearer $SLACK_BOT_TOKEN"
定时发送
POST_AT=$(( $(date +%s) + 1800 )) # 30 分钟后
curl -s https://slack.com/api/chat.scheduleMessage \
-d "channel=C01ABC123" -d "text=定时消息" -d "post_at=$POST_AT" \
-H "Authorization: Bearer $SLACK_BOT_TOKEN"
# 查待发队列:chat.scheduledMessages.list
# 取消:chat.deleteScheduledMessage -d "scheduled_message_id=Q12345"
取消息永久链接(ts → URL)
curl -s https://slack.com/api/chat.getPermalink \
-d "channel=C01ABC123" \
-d "message_ts=1775308000.100001" \
-H "Authorization: Bearer $SLACK_BOT_TOKEN"
# 返回 {"ok":true,"permalink":"https://workspace.slack.com/archives/C01ABC/p..."}
添加 Reaction
curl -s https://slack.com/api/reactions.add \
-d "channel=C01ABC123" \
-d "timestamp=1775308000.100001" \
-d "name=white_check_mark" \
-H "Authorization: Bearer $SLACK_BOT_TOKEN"
name = 不带冒号的 emoji slug,如 thumbsup / white_check_mark / x / eyes。需要 reactions:write scope。
文件上传(v2 API)
旧 files.upload 已废弃。三步走:
Step 1:申请上传 URL
curl -s https://slack.com/api/files.getUploadURLExternal \
-d "filename=report.pdf" \
-d "length=$(wc -c < /path/to/file.pdf)" \
-H "Authorization: Bearer $SLACK_BOT_TOKEN"
# 返回 upload_url + file_id
Step 2:上传文件内容
curl -s -X POST "$UPLOAD_URL" \
-H "Content-Type: application/octet-stream" \
--data-binary @/path/to/file.pdf
Step 3:完成上传,关联到频道/thread
curl -s https://slack.com/api/files.completeUploadExternal \
-H "Authorization: Bearer $SLACK_BOT_TOKEN" \
-H "Content-Type: application/json; charset=utf-8" \
--data-raw '{
"files": [{"id":"F08ABC123","title":"报告"}],
"channel_id": "C01ABC123",
"thread_ts": "1775307969.013919",
"initial_comment": "附件请查收"
}'
需要 files:write scope。
读取消息 / Thread
Slack URL → Timestamp 转换
URL:https://workspace.slack.com/archives/C01ABC/p1775307969013919
去掉 p,倒数第 6 位插小数点 → 1775307969.013919
msg_id="1775307969013919"
ts="${msg_id:0:$((${#msg_id}-6))}.${msg_id: -6}"
import re
def slack_url_to_ts(url):
m = re.search(r'/p(\d+)', url)
s = m.group(1)
return f"{s[:-6]}.{s[-6:]}"
读 Thread
curl -s https://slack.com/api/conversations.replies \
-d "channel=C01ABC123" \
-d "ts=1775307969.013919" \
-d "limit=50" \
-H "Authorization: Bearer $SLACK_BOT_TOKEN" | python3 -m json.tool
读频道历史(带时间过滤)
curl -s https://slack.com/api/conversations.history \
-d "channel=C01ABC123" \
-d "oldest=$(TZ=Asia/Tokyo date -v-1d +%s)" \
-d "limit=100" \
-H "Authorization: Bearer $SLACK_BOT_TOKEN"
超 100 条需分页:返回中有 response_metadata.next_cursor,再传 -d "cursor=<value>" 继续拉取,直到 has_more: false。
用户 / 频道查询
# token 状态自检
curl -s https://slack.com/api/auth.test -H "Authorization: Bearer $SLACK_BOT_TOKEN" | python3 -m json.tool
# 用户信息
curl -s https://slack.com/api/users.info -d "user=U01ABC123" -H "Authorization: Bearer $SLACK_BOT_TOKEN"
# 频道信息
curl -s https://slack.com/api/conversations.info -d "channel=C01ABC123" -H "Authorization: Bearer $SLACK_BOT_TOKEN"
# 列全量频道(带分页,需多次 cursor)
curl -s https://slack.com/api/conversations.list \
-d "limit=200" -d "types=public_channel,private_channel" \
-H "Authorization: Bearer $SLACK_BOT_TOKEN"
Block Kit 选型原则
| 场景 | 用什么 | 原因 |
|---|---|---|
| 信息类(反思/日报/巡检/digest) | top-level blocks |
展示稳定,无"空壳"风险 |
| 需要状态色条(告警/优先级) | attachments[].blocks + color |
唯一适合用颜色条的场景 |
| 正文 > 50 blocks | 拆成多条 thread reply | Slack 单消息 50 blocks 硬上限 |
段落结构靠 header / section / divider / context,不靠颜色。
用户反馈"只看到首行"时的恢复动作
- 先
conversations.replies回读,确认 Slack 落地了几条、每条text/blocks实际内容 - 若截断:立即拆成 2-3 条短 thread reply 补发,标注
补发 1/2/补发 2/2 - 补发后再回读验证
blocks字段是否存在,不要只看ok:true
Gotchas
source ~/Orb/.env炸 bash:用 grep + cut 单独提取变量,见上方 Token 提取- form-encoded +
attachments[].blocks静默丢失:改Content-Type: application/json+ top-levelblocks - attachment-only reply 显示空壳:
text传空格 + 内容全在attachments[].blocks→ 某些 Slack 视图渲染为空;改为 top-levelblocks+ 真实textfallback - blocks > 50 → 降级为首行:adapter 若有
if blocks.length > 50: 只发 text fallback的逻辑会静默丢 blocks;改为拆多条 - button
value超长 →invalid_blocks:超 ~2000 chars 报错;改为value="file:<id>.json",payload 存本地文件 invalid_arguments:别用 JSON body 调用不支持 JSON body 的接口;用-d "param=value"form 格式ok:true不代表内容到位:发完必须conversations.replies回读验证blocks/text是否真有内容reactions.add缺 scope:返回missing_scope reactions:write,需在 Slack App 配置里加- 文件上传旧 API 废弃:
files.upload已弃用;用getUploadURLExternal→ upload →completeUploadExternal三步走 reply_broadcast:默认不传;只有需要 reply 同时广播到频道时间线时才传true
04 同仓库更多 Skills
webapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.
vendor-doc-actionability
对外合作文档(交付文档 / POC 文档 / Solution Doc / 提案书)必须为每个「需对方执行」的动作写清具体操作入口(URL / 工单系统 / 脚本路径 / 联系人 + 联系方式 / 步骤编号)。Use when 给客户、vendor、合作方写交付文档、POC 文档、Solution Doc、提案书;或检视已有对外文档是否抽象到无法执行。
vendor-api-param-validation
第三方 API / SDK 集成开工前,强制先列参数 checklist 并对照官方文档逐项验证(名称 / 类型 / 必填 / 默认 / 上限),通过后再编码——不是「写完再调通」。Use when 新接 vendor API/SDK(Slack / LongPort / freee / LLM API 等)、既有集成追加新 endpoint 或新字段、用户说「调通某接口」「接入 X」「集成 X」。
truth-ladder
状态放行三层阶梯(attempted / observed / confirmed)—— 汇报任务、API、命令、消息或外部动作状态时强制分层,避免把"动作已发起"误写成"结果已达成"。Use when 准备写「任务已完成」「API 返回成功」「exit code 0」「用户已收到」「ok:true」类状态汇报;或在 cron 报告 / Slack 回报 / project status / receipt 中表达完成度时。
thread-object-realignment
长 thread 切题后的对象重定协议——thread 历史 ≥5 条且检测到切题信号时,回复前必做「用户最后显式问题对象 vs 待发回复对象」一致性校验,不一致则改写或反问。Use when Slack thread 历史 ≥5 条且当前用户消息出现切题信号(主题词突变、问句指向新实体、时间线跳跃、出现「另外」「话说」「回到 X」「换个话题」等切题语,或 ≥3 turn 后用户显式问题对象与最近 assistant 回复对象不同)。
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with colors/fonts that you can apply to any artifact that has been creating, or can generate a new theme on-the-fly.