Slack output format

From KarryViber/Orb · View interactive version

Slack output format is an AI agent skill from the GitHub repository KarryViber/Orb. Slack 频道结构化输出规范 + Web API 写法——标题主消息、Block Kit thread、6 档 markdown、跨调用 anchor、curl/token/读写消息命令。Use when 准备向非 DM 频道推送 cron 报告/审批卡/反思/周报/持仓/书签/调研,或需要用 Slack API 读写消息、管理 thread、发送 Block Kit/attachment、更新并回读验证。

How to use this skill

Skill file

Slack 输出格式规范

所有向 Slack 频道(非 DM、非 thread 内回复)推送的结构化内容统一采用「标题主消息 + Block Kit thread」两步走。Slack Web API 主要通过 curl + Bot token 调用;token 存在 ~/Orb/.env,不要直接 source ~/Orb/.env,而是单独提取变量。

When to Use

频道主消息(1 条,text only)

格式:{emoji} {任务名} MM/DD|{一句话总结}

Thread 正文(Block Kit)

结构:

header  : "{任务名} MM/DD"
section : "• 概况数据(窗口 / 会话数 / 消息数 / 标的数 等)"
divider
section : "## :emoji: 段标题
正文..."
divider
section : "## :emoji: 段标题
正文..."
divider

规则:

语义 → markdown 对照表(核心)

完整 6 档映射见 ~/Orb/profiles/<your-profile>/workspace/CLAUDE.md § Slack 输出格式。这里只列 cron / 反思类高频用法:

| 需要的视觉 | 写 | 渲染成 |

|---|---|---|

| 段标题 | ## :emoji: 标题 | *:emoji: 标题* 独立行 |

| 子段 | ### 子段 | *子段* 独立行 |

| 备注 / metadata | #### 备注 | _备注_ 独立行 |

| 句内重点 | **关键词**(一段 ≤1 个) | *关键词* 行内 |

| 数字 / ID / 路径 / 命令 | ` xxx ` | 灰底 |

| 弱强调 / 引用 / 术语 | *xxx* | _xxx_ 行内 |

铁律:

小字(italic / context 灰字)使用频次

目标:把正常字号的信噪比拉高。Karry 一眼能 grep 到「需要回应的部分」,辅助信息全沉到小字。

默认走小字(*xxx* → 渲染成 _xxx_ italic;多行可用 context block):

正常字号留给(信号位):

禁忌:

Slack API 写法

1. 提取 token

SLACK_BOT_TOKEN=$(grep -E '^SLACK_BOT_TOKEN=' ~/Orb/.env | head -1 | cut -d= -f2- | tr -d "'" '"')

2. 发最小消息

curl -s "https://slack.com/api/chat.postMessage" \
  -d "channel=C01ABC123" \
  -d "text=Hello, Slack!" \
  -H "Authorization: Bearer $SLACK_BOT_TOKEN"

发 thread reply、update、delete、schedule、unfurl 时同样使用 Bot token 和对应 Web API。发完消息后,优先用 conversations.replies 或 conversations.history 回读验证,不要只看 ok=true。

3. 读取一个 Thread

curl -s "https://slack.com/api/conversations.replies" \
  -d "channel=C01ABC123" \
  -d "ts=1775307969.013919" \
  -H "Authorization: Bearer $SLACK_BOT_TOKEN"

4. 列频道

curl -s "https://slack.com/api/conversations.list" \
  -d "limit=200" \
  -d "types=public_channel,private_channel" \
  -H "Authorization: Bearer $SLACK_BOT_TOKEN"

5. 查用户

curl -s "https://slack.com/api/users.info" \
  -d "user=U01ABC123" \
  -H "Authorization: Bearer $SLACK_BOT_TOKEN"

6. 添加 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 / eyes / x)。需要 Bot scope reactions:write。

收到用户附件时的处理

Orb adapter 对不同文件类型的处理结果:

| 文件类型 | agent 拿到 | 应对方式 |

|---|---|---|

| .txt / .md / .json / .py 等文本类 | --- 文件: xxx ---\n内容\n--- EOF --- 注入 prompt | 直读,正常响应 |

| 图片(.png / .jpg / .gif 等) | imagePaths,作为多模态 image block | 直接视觉分析 |

| PDF | [附件: xxx (application/pdf, N bytes)] | 调 pdf skill:pymupdf 提取文本 |

| docx | [附件: xxx (application/vnd.openxmlformats..., N bytes)] | 调 ocr-and-documents skill:python-docx |

| xlsx / csv | [附件: xxx (application/vnd.openxmlformats..., N bytes)] | 调 xlsx skill:openpyxl / pandas |

| 超 100KB 文本 | [附件: xxx — 超出大小限制] | 告知用户文件过大,建议拆分或提供关键片段 |

铁律:收到 [附件: xxx] 格式提示时,不能沉默——必须明确告知用户「已收到文件,正在用工具提取内容」,并主动调对应 skill,不要假装没看见或只输出文件名。

跨调用 Anchor 持久化

触发场景:同一类项目在一天内会被多次产出(new seed、bookmark 卡、cron 推送等),但希望它们聚合到同一个 main thread(首条创建、后续作为 thread reply 追加),跨日自动轮换到新 thread。

反例(踩过的坑):依赖运行时猜测「今天有没有发过」——拉 conversations.history、对比时间戳、按文本匹配——任意一个都不可靠(频道有别人消息、time skew、文案变动),最终散成多个 main thread。已知案例:seeds_importers.py 早期实现散发,2026-04-27 才补 data/seeds-daily-anchor.json 闭环。

正解:把 anchor 持久化为显式 JSON 状态文件。

文件位置:~/Orb/profiles/<your-profile>/data/<task>-daily-anchor.json

最小 schema:

{
  "date": "2026-04-28",
  "channel": "C0123456789",
  "main_ts": "1777306842.573899"
}

调用流程(每次要发新内容时):

  1. 读 anchor JSON,比对 date 字段:
  1. chat.postMessage 发 main 消息 → 拿到新 ts
  2. 覆盖 anchor JSON:{"date":"<today JST>","channel":"<C…>","main_ts":"<新 ts>"}
  3. 当天后续投递回到步骤 1

铁律:

适用任务清单(已用 / 待补):

Assistant Thread / Stream API(只读参考,不要直接调)

以下 API 归 Orb adapter/scheduler 独占管理,外部脚本和 agent 不要直接调用,否则会踩 message_not_owned_by_app / message_not_in_streaming_state:

| API | 归属 | 说明 |

|---|---|---|

| assistant.threads.setStatus | adapter | 显示 "Cooking…" / 工具名等气泡,turn 期间自动刷新(每 20s re-arm) |

| assistant.threads.setTitle | adapter | 设置 assistant thread 标题 |

| assistant.threads.setSuggestedPrompts | adapter | 设置建议提示词 |

| chat.startStream | scheduler | 启动 task card timeline stream |

| chat.appendStream | scheduler | 向 stream 追加 task_update chunks |

| chat.stopStream | scheduler | 关闭 stream 并写入最终 markdown/blocks |

handler 脚本(profiles/<your-profile>/scripts/handlers/)收到 block_action 回调后用 chat.update 更新审批卡,不要尝试用 stream API 改 bot 发的消息——stream 所有权归 daemon,handler 拿不到。

Stream chunks 双发陷阱(写 stream renderer / 改 stopStream 前必读)

Slack stream 的 task_update.details 对同一个 id 的 chunk 会跨 appendStream concat 累积——这是官方未明文但实测稳定的行为。

事故签名:finalize 后文本重复,例如 Distilled from N probesDistilled from N probes。

根因:result/finalize 路径先 appendStream(chunks) 再 stopStream({ chunks }) 发送同一批 final chunks,Slack 把 details 又拼了一次。

正确姿势:

审查 stream renderer 时盯这几条路径:

参考 lesson:profiles/<your-profile>/data/lessons/slack-stream-stopstream-chunks-pitfall.md

Reference 索引

命令语法、URL→ts 转换、reactions.add、文件上传 v2(getUploadURLExternal)、chat.getPermalink、频道/用户查询、cursor 分页、常见报错全集,见 skill slack-cli-api-reference(搜索关键词 invalid_blocks / reactions.add / getUploadURLExternal / chat.getPermalink / conversations.replies 时自动触发)。

Gotchas

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.