通用开发工程师行政/运营沟通协作流程优化

Slack 自动化

Slack Browser Automation

Interact with Slack workspaces using browser automation — check unreads, navigate channels, send messages, search conversations, and extract data

作者: Vercel Labs建设者v1.0.0
slackbrowser automationmessagingagent-browserworkspace

Slack 自动化

通过浏览器自动化与 Slack 工作区交互,用于查看未读、切换频道、发送消息、搜索对话和提取信息。

快速开始

连接到已有 Slack 浏览器会话,或直接打开 Slack:

# 连接到 9222 端口上的现有会话(通常用于已打开 Slack 的场景)
agent-browser connect 9222

# 若未打开 Slack,可直接访问
agent-browser open https://app.slack.com

然后先抓取一次快照,查看当前可交互元素:

agent-browser snapshot -i

核心流程

  1. 连接/导航:打开或连接 Slack
  2. 抓快照:获取交互元素引用(@e1@e2 等)
  3. 页面导航:点击标签页、展开分组、进入目标频道
  4. 读取/操作:提取数据或执行操作
  5. 截图留证:保留结果证据
# 示例:检查未读频道
agent-browser connect 9222
agent-browser snapshot -i
# 查找 "More unreads" 按钮
agent-browser click @e21
agent-browser screenshot slack-unreads.png

常见任务

查看未读消息

agent-browser connect 9222
agent-browser snapshot -i

# 重点查找:
# - "More unreads" 按钮(通常在侧栏上方)
# - Activity 标签中的未读入口/计数
# - 带徽标或加粗的频道名称

agent-browser click @e14  # Activity(引用会变化)
agent-browser wait 1000
agent-browser screenshot activity-unreads.png

进入指定频道

agent-browser snapshot -i
agent-browser click @e94  # 示例:某频道引用
agent-browser wait --load networkidle
agent-browser screenshot channel.png

搜索消息/线程

agent-browser snapshot -i
agent-browser click @e5
agent-browser fill @e_search "keyword"
agent-browser press Enter
agent-browser wait --load networkidle
agent-browser screenshot search-results.png

提取频道信息

agent-browser snapshot --json > slack-snapshot.json
# 在 JSON 中解析频道名、层级、元数据

记录现场信息

agent-browser screenshot --annotate slack-state.png
agent-browser screenshot --full slack-full.png
agent-browser get url
agent-browser get title

侧栏结构速览

典型 Slack 侧栏包含:

  • Threads
  • Huddles
  • Drafts & sent
  • Directories
  • 各类分组(Starred、Channels 等)
  • Direct Messages
  • Apps
  • More unreads(展开未读频道)

常见引用(实际以快照为准):

  • @e12:Home
  • @e13:DMs
  • @e14:Activity
  • @e5:Search
  • @e21:More unreads

数据提取

获取文本

agent-browser get text @e_message_ref

解析无障碍树(推荐)

agent-browser snapshot --json > output.json

可从中提取:

  • 频道名称(treeitem
  • 消息内容(listitem / document
  • 用户信息
  • 时间戳

统计未读频道

agent-browser snapshot -i | grep -c "treeitem"

最佳实践

  • 优先 connect 9222 复用现有会话,速度更快。
  • 点击前先 snapshot -i,避免误点错误引用。
  • 页面切换后立即重新快照,引用常会变化。
  • 需要结构化抽取时使用 snapshot --json
  • 高频操作间加短等待(如 sleep 1 / wait 500)。
  • 侧栏过长时用 scroll --selector ".p-sidebar" 定位目标。

限制说明

  • 本技能走浏览器自动化,不是 Slack API。
  • 截图与快照仅对当前会话有效。
  • 交互过快可能触发 Slack 限流。
  • 仅能操作当前登录的工作区。

调试建议

agent-browser console
agent-browser errors
agent-browser snapshot -i -C
agent-browser get url
agent-browser get title
agent-browser screenshot page-state.png

参考

  • Slack 帮助文档:https://slack.com/help
  • Web 入口:https://app.slack.com
  • 快捷键:在 Slack 中输入 ?