slack

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Slack Automation

Slack自动化

Interact with Slack workspaces to check messages, extract data, and automate common tasks.
与Slack工作区交互,查看消息、提取数据并自动化常见任务。

Quick Start

快速开始

Connect to an existing Slack browser session or open Slack:
bash
undefined
连接到现有的Slack浏览器会话或打开Slack:
bash
undefined

Connect to existing session on port 9222 (typical for already-open Slack)

连接到端口9222上的现有会话(通常用于已打开的Slack)

agent-browser connect 9222
agent-browser connect 9222

Or open Slack if not already running

或者如果Slack未运行则打开它

agent-browser open https://app.slack.com

Then take a snapshot to see what's available:

```bash
agent-browser snapshot -i
agent-browser open https://app.slack.com

然后拍摄快照查看可用元素:

```bash
agent-browser snapshot -i

Core Workflow

核心工作流

  1. Connect/Navigate: Open or connect to Slack
  2. Snapshot: Get interactive elements with refs (
    @e1
    ,
    @e2
    , etc.)
  3. Navigate: Click tabs, expand sections, or navigate to specific channels
  4. Extract/Interact: Read data or perform actions
  5. Screenshot: Capture evidence of findings
bash
undefined
  1. 连接/导航:打开或连接到Slack
  2. 快照:获取带引用标识(
    @e1
    @e2
    等)的交互元素
  3. 导航:点击标签页、展开分区或导航到特定频道
  4. 提取/交互:读取数据或执行操作
  5. 截图:捕获操作结果的证据
bash
undefined

Example: Check unread channels

示例:检查未读频道

agent-browser connect 9222 agent-browser snapshot -i
agent-browser connect 9222 agent-browser snapshot -i

Look for "More unreads" button

查找“更多未读”按钮

agent-browser click @e21 # Ref for "More unreads" button agent-browser screenshot slack-unreads.png
undefined
agent-browser click @e21 # “更多未读”按钮的引用标识 agent-browser screenshot slack-unreads.png
undefined

Common Tasks

常见任务

Checking Unread Messages

检查未读消息

bash
undefined
bash
undefined

Connect to Slack

连接到Slack

agent-browser connect 9222
agent-browser connect 9222

Take snapshot to locate unreads button

拍摄快照定位未读消息按钮

agent-browser snapshot -i
agent-browser snapshot -i

Look for:

查找以下元素:

- "More unreads" button (usually near top of sidebar)

- “更多未读”按钮(通常位于侧边栏顶部附近)

- "Unreads" toggle in Activity tab (shows unread count)

- 活动标签页中的“未读”切换按钮(显示未读计数)

- Channel names with badges/bold text indicating unreads

- 带有标识徽章/粗体文本的频道名称(表示有未读消息)

Navigate to Activity tab to see all unreads in one view

导航到活动标签页,在一个视图中查看所有未读消息

agent-browser click @e14 # Activity tab (ref may vary) agent-browser wait 1000 agent-browser screenshot activity-unreads.png
agent-browser click @e14 # 活动标签页(引用标识可能不同) agent-browser wait 1000 agent-browser screenshot activity-unreads.png

Or check DMs tab

或者检查私信标签页

agent-browser click @e13 # DMs tab agent-browser screenshot dms.png
agent-browser click @e13 # 私信标签页 agent-browser screenshot dms.png

Or expand "More unreads" in sidebar

或者展开侧边栏中的“更多未读”

agent-browser click @e21 # More unreads button agent-browser wait 500 agent-browser screenshot expanded-unreads.png
undefined
agent-browser click @e21 # 更多未读按钮 agent-browser wait 500 agent-browser screenshot expanded-unreads.png
undefined

Navigating to a Channel

导航到频道

bash
undefined
bash
undefined

Search for channel in sidebar or by name

在侧边栏中按名称搜索频道

agent-browser snapshot -i
agent-browser snapshot -i

Look for channel name in the list (e.g., "engineering", "product-design")

在列表中查找频道名称(例如“engineering”、“product-design”)

Click on the channel treeitem ref

点击频道树项的引用标识

agent-browser click @e94 # Example: engineering channel ref agent-browser wait --load networkidle agent-browser screenshot channel.png
undefined
agent-browser click @e94 # 示例:engineering频道的引用标识 agent-browser wait --load networkidle agent-browser screenshot channel.png
undefined

Finding Messages/Threads

查找消息/线程

bash
undefined
bash
undefined

Use Slack search

使用Slack搜索功能

agent-browser snapshot -i agent-browser click @e5 # Search button (typical ref) agent-browser fill @e_search "keyword" agent-browser press Enter agent-browser wait --load networkidle agent-browser screenshot search-results.png
undefined
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
undefined

Extracting Channel Information

提取频道信息

bash
undefined
bash
undefined

Get list of all visible channels

获取所有可见频道的列表

agent-browser snapshot --json > slack-snapshot.json
agent-browser snapshot --json > slack-snapshot.json

Parse for channel names and metadata

解析频道名称和元数据

Look for treeitem elements with level=2 (sub-channels under sections)

查找level=2的树项元素(分区下的子频道)

undefined
undefined

Checking Channel Details

检查频道详情

bash
undefined
bash
undefined

Open a channel

打开一个频道

agent-browser click @e_channel_ref agent-browser wait 1000
agent-browser click @e_channel_ref agent-browser wait 1000

Get channel info (members, description, etc.)

获取频道信息(成员、描述等)

agent-browser snapshot -i agent-browser screenshot channel-details.png
agent-browser snapshot -i agent-browser screenshot channel-details.png

Scroll through messages

滚动查看消息

agent-browser scroll down 500 agent-browser screenshot channel-messages.png
undefined
agent-browser scroll down 500 agent-browser screenshot channel-messages.png
undefined

Taking Notes/Capturing State

记录笔记/捕获状态

When you need to document findings from Slack:
bash
undefined
当你需要记录Slack中的发现时:
bash
undefined

Take annotated screenshot (shows element numbers)

拍摄带注释的截图(显示元素编号)

agent-browser screenshot --annotate slack-state.png
agent-browser screenshot --annotate slack-state.png

Take full-page screenshot

拍摄全页截图

agent-browser screenshot --full slack-full.png
agent-browser screenshot --full slack-full.png

Get current URL for reference

获取当前URL作为参考

agent-browser get url
agent-browser get url

Get page title

获取页面标题

agent-browser get title
undefined
agent-browser get title
undefined

Sidebar Structure

侧边栏结构

Understanding Slack's sidebar helps you navigate efficiently:
- Threads
- Huddles
- Drafts & sent
- Directories
- [Section Headers - External connections, Starred, Channels, etc.]
  - [Channels listed as treeitems]
- Direct Messages
  - [DMs listed]
- Apps
  - [App shortcuts]
- [More unreads] button (toggles unread channels list)
Key refs to look for:
  • @e12
    - Home tab (usually)
  • @e13
    - DMs tab
  • @e14
    - Activity tab
  • @e5
    - Search button
  • @e21
    - More unreads button (varies by session)
了解Slack的侧边栏结构有助于高效导航:
- 线程
- 语音会议
- 草稿与已发送消息
- 通讯录
- [分区标题 - 外部连接、已星标、频道等]
  - [频道以树项形式列出]
- 直接消息
  - [私信列表]
- 应用
  - [应用快捷方式]
- [更多未读]按钮(切换未读频道列表)
需要关注的关键引用标识:
  • @e12
    - 主页标签页(通常)
  • @e13
    - 私信标签页
  • @e14
    - 活动标签页
  • @e5
    - 搜索按钮
  • @e21
    - 更多未读按钮(会随会话变化)

Tabs in Slack

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

从Slack提取数据

Get Text Content

获取文本内容

bash
undefined
bash
undefined

Get a message or element's text

获取消息或元素的文本

agent-browser get text @e_message_ref
undefined
agent-browser get text @e_message_ref
undefined

Parse Accessibility Tree

解析无障碍树

bash
undefined
bash
undefined

Full snapshot as JSON for programmatic parsing

以JSON格式导出完整快照用于程序化解析

agent-browser snapshot --json > output.json
agent-browser snapshot --json > output.json

Look for:

查找以下内容:

- Channel names (name field in treeitem)

- 频道名称(树项中的name字段)

- Message content (in listitem/document elements)

- 消息内容(列表项/文档元素中)

- User names (button elements with user info)

- 用户名(包含用户信息的按钮元素)

- Timestamps (link elements with time info)

- 时间戳(包含时间信息的链接元素)

undefined
undefined

Count Unreads

统计未读数量

bash
undefined
bash
undefined

After expanding unreads section:

展开未读分区后:

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

Each treeitem with a channel name in the unreads section is one unread

未读分区中每个带频道名称的树项代表一个未读频道

undefined
undefined

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.
  • 连接到现有会话:如果Slack已打开,使用
    agent-browser connect 9222
    。这比打开新浏览器更快。
  • 点击前拍摄快照:在点击按钮前始终使用
    snapshot -i
    来识别引用标识。
  • 导航后重新拍摄快照:导航到新频道或分区后,拍摄新快照以查找新的引用标识。
  • 使用JSON快照进行解析:当需要提取结构化数据时,使用
    snapshot --json
    获取机器可读的输出。
  • 控制交互节奏:在快速交互之间添加
    sleep 1
    ,让UI有时间更新。
  • 检查无障碍树:无障碍树显示屏幕阅读器(以及你的自动化工具)能看到的内容。如果元素不在快照中,它可能是隐藏的或需要滚动才能显示。
  • 滚动侧边栏:如果频道列表过长,使用
    agent-browser scroll down 300 --selector ".p-sidebar"
    在Slack侧边栏内滚动。

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.
  • 无法访问Slack API:此工具使用浏览器自动化,而非Slack API。无需OAuth、webhook或机器人令牌。
  • 会话相关性:截图和快照与当前浏览器会话绑定。
  • 速率限制:Slack可能会对快速交互进行速率限制。必要时在命令之间添加延迟。
  • 工作区限制:你只能操作自己的工作区,不支持跨工作区自动化。

Debugging

调试

Check console for errors

检查控制台错误

bash
agent-browser console
agent-browser errors
bash
agent-browser console
agent-browser errors

View raw HTML of an element

查看元素的原始HTML

bash
undefined
bash
undefined

Snapshot shows the accessibility tree. If an element isn't there,

快照显示的是无障碍树。如果元素不在其中,

it may not be interactive (e.g., div instead of button)

它可能无法交互(例如是div而非按钮)

Use snapshot -i -C to include cursor-interactive divs

使用snapshot -i -C包含可通过光标交互的div元素

agent-browser snapshot -i -C
undefined
agent-browser snapshot -i -C
undefined

Get current page state

获取当前页面状态

bash
agent-browser get url
agent-browser get title
agent-browser screenshot page-state.png
bash
agent-browser get url
agent-browser get title
agent-browser screenshot page-state.png

Example: Full Unread Check

示例:完整未读检查

bash
#!/bin/bash
bash
#!/bin/bash

Connect to Slack

连接到Slack

agent-browser connect 9222
agent-browser connect 9222

Take initial snapshot

拍摄初始快照

echo "=== Checking Slack unreads ===" agent-browser snapshot -i > snapshot.txt
echo "=== 检查Slack未读消息 ===" agent-browser snapshot -i > snapshot.txt

Check Activity tab for unreads

检查活动标签页的未读消息

agent-browser click @e14 # Activity tab agent-browser wait 1000 agent-browser screenshot activity.png ACTIVITY_RESULT=$(agent-browser get text @e_main_area) echo "Activity: $ACTIVITY_RESULT"
agent-browser click @e14 # 活动标签页 agent-browser wait 1000 agent-browser screenshot activity.png ACTIVITY_RESULT=$(agent-browser get text @e_main_area) echo "活动标签页:$ACTIVITY_RESULT"

Check DMs

检查私信

agent-browser click @e13 # DMs tab agent-browser wait 1000 agent-browser screenshot dms.png
agent-browser click @e13 # 私信标签页 agent-browser wait 1000 agent-browser screenshot dms.png

Check unread channels in sidebar

检查侧边栏中的未读频道

agent-browser click @e21 # More unreads button agent-browser wait 500 agent-browser snapshot -i > unreads-expanded.txt agent-browser screenshot unreads.png
agent-browser click @e21 # 更多未读按钮 agent-browser wait 500 agent-browser snapshot -i > unreads-expanded.txt agent-browser screenshot unreads.png

Summary

总结

echo "=== Summary ===" echo "See activity.png, dms.png, and unreads.png for full details"
undefined
echo "=== 总结 ===" echo "查看activity.png、dms.png和unreads.png获取完整详情"
undefined

References

参考资料