Slack Automation
Interact with Slack workspaces to check messages, extract data, and automate common tasks.
Quick Start
Connect to an existing Slack browser session or open Slack:
CODEBLOCK0
Then take a snapshot to see what's available:
CODEBLOCK1
Core Workflow
- 1. Connect/Navigate: Open or connect to Slack
- Snapshot: Get interactive elements with refs (
@e1, @e2, etc.) - Navigate: Click tabs, expand sections, or navigate to specific channels
- Extract/Interact: Read data or perform actions
- Screenshot: Capture evidence of findings
CODEBLOCK2
Common Tasks
Checking Unread Messages
CODEBLOCK3
Navigating to a Channel
CODEBLOCK4
Finding Messages/Threads
CODEBLOCK5
Extracting Channel Information
CODEBLOCK6
Checking Channel Details
CODEBLOCK7
Taking Notes/Capturing State
When you need to document findings from Slack:
CODEBLOCK8
Sidebar Structure
Understanding Slack's sidebar helps you navigate efficiently:
CODEBLOCK9
Key refs to look for:
- -
@e12 - Home tab (usually) - INLINECODE3 - DMs tab
- INLINECODE4 - Activity tab
- INLINECODE5 - Search button
- INLINECODE6 - More unreads button (varies by session)
Tabs in Slack
After clicking on a channel, you'll see tabs:
- - Messages - Channel conversation
- Files - Shared files
- Pins - Pinned messages
- Add canvas - Collaborative canvas
- Other tabs depending on workspace setup
Click tab refs to switch views and get different information.
Extracting Data from Slack
Get Text Content
CODEBLOCK10
Parse Accessibility Tree
CODEBLOCK11
Count Unreads
CODEBLOCK12
Best Practices
- - Connect to existing sessions: Use
agent-browser connect 9222 if Slack is already open. This is faster than opening a new browser. - Take snapshots before clicking: Always
snapshot -i to identify refs before clicking buttons. - Re-snapshot after navigation: After navigating to a new channel or section, take a fresh snapshot to find new refs.
- Use JSON snapshots for parsing: When you need to extract structured data, use
snapshot --json for machine-readable output. - Pace interactions: Add
sleep 1 between rapid interactions to let the UI update. - Check accessibility tree: The accessibility tree shows what screen readers (and your automation) can see. If an element isn't in the snapshot, it may be hidden or require scrolling.
- Scroll in sidebar: Use
agent-browser scroll down 300 --selector ".p-sidebar" to scroll within the Slack sidebar if channel list is long.
Limitations
- - Cannot access Slack API: This uses browser automation, not the Slack API. No OAuth, webhooks, or bot tokens needed.
- Session-specific: Screenshots and snapshots are tied to the current browser session.
- Rate limiting: Slack may rate-limit rapid interactions. Add delays between commands if needed.
- Workspace-specific: You interact with your own workspace -- no cross-workspace automation.
Debugging
Check console for errors
CODEBLOCK13
View raw HTML of an element
CODEBLOCK14
Get current page state
CODEBLOCK15
Example: Full Unread Check
CODEBLOCK16
References
- - Slack docs: https://slack.com/help
- Web experience: https://app.slack.com
- Keyboard shortcuts: Type
? in Slack for shortcut list
Slack 自动化
与 Slack 工作区交互,检查消息、提取数据并自动化常见任务。
快速开始
连接到现有的 Slack 浏览器会话或打开 Slack:
bash
连接到端口 9222 上的现有会话(通常用于已打开的 Slack)
agent-browser connect 9222
如果 Slack 尚未运行,则打开它
agent-browser open https://app.slack.com
然后拍摄快照以查看可用内容:
bash
agent-browser snapshot -i
核心工作流程
- 1. 连接/导航:打开或连接到 Slack
- 快照:获取带有引用(@e1、@e2 等)的交互式元素
- 导航:点击标签页、展开部分或导航到特定频道
- 提取/交互:读取数据或执行操作
- 截图:捕获查找结果的证据
bash
示例:检查未读频道
agent-browser connect 9222
agent-browser snapshot -i
查找更多未读按钮
agent-browser click @e21 # 更多未读按钮的引用
agent-browser screenshot slack-unreads.png
常见任务
检查未读消息
bash
连接到 Slack
agent-browser connect 9222
拍摄快照以定位未读按钮
agent-browser snapshot -i
查找:
- 更多未读按钮(通常在侧边栏顶部附近)
- 活动标签页中的未读开关(显示未读计数)
- 带有徽章或粗体文本指示未读的频道名称
导航到活动标签页以在一个视图中查看所有未读
agent-browser click @e14 # 活动标签页(引用可能不同)
agent-browser wait 1000
agent-browser screenshot activity-unreads.png
或检查私信标签页
agent-browser click @e13 # 私信标签页
agent-browser screenshot dms.png
或展开侧边栏中的更多未读
agent-browser click @e21 # 更多未读按钮
agent-browser wait 500
agent-browser screenshot expanded-unreads.png
导航到频道
bash
在侧边栏中按名称搜索频道
agent-browser snapshot -i
在列表中查找频道名称(例如engineering、product-design)
点击频道树项引用
agent-browser click @e94 # 示例:engineering 频道引用
agent-browser wait --load networkidle
agent-browser screenshot channel.png
查找消息/线程
bash
使用 Slack 搜索
agent-browser snapshot -i
agent-browser click @e5 # 搜索按钮(典型引用)
agent-browser fill @e_search 关键词
agent-browser press Enter
agent-browser wait --load networkidle
agent-browser screenshot search-results.png
提取频道信息
bash
获取所有可见频道的列表
agent-browser snapshot --json > slack-snapshot.json
解析频道名称和元数据
查找 level=2 的 treeitem 元素(部分下的子频道)
检查频道详情
bash
打开频道
agent-browser click @e
channelref
agent-browser wait 1000
获取频道信息(成员、描述等)
agent-browser snapshot -i
agent-browser screenshot channel-details.png
滚动浏览消息
agent-browser scroll down 500
agent-browser screenshot channel-messages.png
记录笔记/捕获状态
当您需要记录 Slack 中的发现时:
bash
拍摄带注释的截图(显示元素编号)
agent-browser screenshot --annotate slack-state.png
拍摄全页截图
agent-browser screenshot --full slack-full.png
获取当前 URL 以供参考
agent-browser get url
获取页面标题
agent-browser get title
侧边栏结构
了解 Slack 的侧边栏有助于高效导航:
- - 线程
- 会议
- 草稿和已发送
- 目录
- [部分标题 - 外部连接、星标、频道等]
- [频道列为 treeitem]
- [私信列出]
- [应用快捷方式]
要查找的关键引用:
- - @e12 - 首页标签页(通常)
- @e13 - 私信标签页
- @e14 - 活动标签页
- @e5 - 搜索按钮
- @e21 - 更多未读按钮(因会话而异)
Slack 中的标签页
点击频道后,您将看到标签页:
- - 消息 - 频道对话
- 文件 - 共享文件
- 固定 - 固定消息
- 添加画布 - 协作画布
- 其他标签页取决于工作区设置
点击标签页引用以切换视图并获取不同信息。
从 Slack 提取数据
获取文本内容
bash
获取消息或元素的文本
agent-browser get text @e
messageref
解析无障碍树
bash
完整快照为 JSON 格式,用于编程解析
agent-browser snapshot --json > output.json
查找:
- 频道名称(treeitem 中的 name 字段)
- 消息内容(在 listitem/document 元素中)
- 用户名(包含用户信息的 button 元素)
- 时间戳(包含时间信息的 link 元素)
统计未读数量
bash
展开未读部分后:
agent-browser snapshot -i | grep -c treeitem
未读部分中每个带有频道名称的 treeitem 代表一个未读
最佳实践
- - 连接到现有会话:如果 Slack 已打开,使用 agent-browser connect 9222。这比打开新浏览器更快。
- 点击前拍摄快照:在点击按钮前始终执行 snapshot -i 以识别引用。
- 导航后重新拍摄快照:导航到新频道或部分后,拍摄新快照以查找新引用。
- 使用 JSON 快照进行解析:当需要提取结构化数据时,使用 snapshot --json 获取机器可读输出。
- 控制交互节奏:在快速交互之间添加 sleep 1 以让 UI 更新。
- 检查无障碍树:无障碍树显示屏幕阅读器(和您的自动化工具)可以看到的内容。如果元素不在快照中,它可能被隐藏或需要滚动。
- 在侧边栏中滚动:如果频道列表很长,使用 agent-browser scroll down 300 --selector .p-sidebar 在 Slack 侧边栏内滚动。
限制
- - 无法访问 Slack API:这使用浏览器自动化,而非 Slack API。无需 OAuth、webhooks 或机器人令牌。
- 会话特定:截图和快照与当前浏览器会话绑定。
- 速率限制:Slack 可能对快速交互进行速率限制。如有需要,在命令之间添加延迟。
- 工作区特定:您与自己的工作区交互——不支持跨工作区自动化。
调试
检查控制台错误
bash
agent-browser console
agent-browser errors
查看元素的原始 HTML
bash
快照显示无障碍树。如果元素不存在,
它可能不可交互(例如,div 而不是 button)
使用 snapshot -i -C 包含光标可交互的 div
agent-browser snapshot -i -C
获取当前页面状态
bash
agent-browser get url
agent-browser get title
agent-browser screenshot page-state.png
示例:完整未读检查
bash
#!/bin/bash
连接到 Slack
agent-browser connect 9222
拍摄初始快照
echo === 检查 Slack 未读 ===
agent-browser snapshot -i > snapshot.txt
检查活动标签页中的未读
agent-browser click @e14 # 活动标签页
agent-browser wait 1000
agent-browser screenshot activity.png
ACTIVITY
RESULT=$(agent-browser get text @emain_area)
echo 活动:$ACTIVITY_RESULT
检查私信
agent-browser click @e13 # 私信标签页
agent-browser wait 1000
agent-browser screenshot dms.png
检查侧边栏中的未读频道
agent-browser click @e21 # 更多未读按钮
agent-browser wait 500
agent-browser snapshot -i > unreads-expanded.txt
agent-browser screenshot unreads.png
摘要
echo === 摘要 ===
echo 查看 activity.png、dms.png 和 unreads.png 获取完整