用途:当需要通过 Slack Web API 读取或操作 Slack 数据时使用本技能,借助随附的 Bun+TypeScript CLI 封装以机器人令牌调用各类 Slack Web API 方法。
前置条件:确保 shell 环境中已设置 SLACK_TOKEN;从本仓库运行脚本(使用本地 @slack/web-api 依赖)。
脚本与命令:脚本为 scripts/slack_web_api.ts。支持的命令包括 list_channels、post、post_table、delete、search、channel_history、thread、reactions_add、reactions_remove。可选参数:--resolve_users true 添加 user_name 字段;--include_threads true 在 channel_history 中嵌入完整话题回复。
post 支持富消息输入:--text_file 从文件读取多行正文;--unescape_text true 将 --text 中的 \n/\t 转义转换为真实换行/制表符;--blocks_json 或 --blocks_file 传入 Block Kit;--attachments_json 或 --attachments_file 传入旧式附件;还支持 --thread_ts、--reply_broadcast true、--unfurl_links false、--unfurl_media false、--mrkdwn true。post_table 支持 --headers_json/--headers_file、--rows_json/--rows_file、--title、--text、--include_index true、--max_rows(默认 20)、--max_col_width(默认 32)。所有命令将 JSON 输出到 stdout。
用法示例:列出频道的命令为 SLACK_TOKEN=... bun ./.codex/skills/slack-web-api/scripts/slack_web_api.ts list_channels --all true;发送消息为 post --channel C123 --text "Hello";搜索为 search --query "in:#general budget review" --count 100;读取频道历史为 channel_history --channel C123 --all true;获取话题为 thread --channel C123 --ts 1712345678.9012 --all true --resolve_users true;表情回应为 reactions_add 与 reactions_remove;删除消息为 delete --channel C123 --ts 1712345678.9012。
常见模式:先用 channel_history 拉取历史到 JSON 文件,再在本地做摘要、关键词提取、时间线等分析。
限制与说明:建议使用频道 ID(C.../G...)以保证可靠;search 依赖 Slack 的搜索索引,channel_history 为原始频道数据;若 API 权限被限制返回结果,需要在 Slack 应用设置中更新机器人权限范围。