Agent Slack
A TypeScript CLI tool that enables AI agents and humans to interact with Slack workspaces through a simple command interface. Features seamless token extraction from the Slack desktop app and multi-workspace support.
Quick Start
CODEBLOCK0
Authentication
Credentials are extracted automatically from the Slack desktop app on first use. No manual setup required — just run any command and authentication happens silently in the background.
On macOS, the system may prompt for your Keychain password the first time (required to decrypt Slack's stored token). This is a one-time prompt.
IMPORTANT: NEVER guide the user to open a web browser, use DevTools, or manually copy tokens from a browser. Always use agent-slack auth extract to obtain tokens from the desktop app.
Multi-Workspace Support
CODEBLOCK1
Memory
The agent maintains a ~/.config/agent-messenger/MEMORY.md file as persistent memory across sessions. This is agent-managed — the CLI does not read or write this file. Use the Read and Write tools to manage your memory file.
Reading Memory
At the start of every task, read ~/.config/agent-messenger/MEMORY.md using the Read tool to load any previously discovered workspace IDs, channel IDs, user IDs, and preferences.
- - If the file doesn't exist yet, that's fine — proceed without it and create it when you first have useful information to store.
- If the file can't be read (permissions, missing directory), proceed without memory — don't error out.
Writing Memory
After discovering useful information, update ~/.config/agent-messenger/MEMORY.md using the Write tool. Write triggers include:
- - After discovering workspace IDs (from
workspace list) - After discovering useful channel IDs and names (from
channel list, snapshot, etc.) - After discovering user IDs and names (from
user list, user me, etc.) - After the user gives you an alias or preference ("call this the deploys channel", "my main workspace is X")
- After discovering channel structure (sidebar sections, channel categories)
When writing, include the complete file content — the Write tool overwrites the entire file.
What to Store
- - Workspace IDs with names
- Channel IDs with names and purpose
- User IDs with display names
- User-given aliases ("deploys channel", "main workspace")
- Commonly used thread timestamps
- Any user preference expressed during interaction
What NOT to Store
Never store tokens, cookies, credentials, or any sensitive data. Never store full message content (just IDs and channel context). Never store file upload contents.
Handling Stale Data
If a memorized ID returns an error (channel not found, user not found), remove it from MEMORY.md. Don't blindly trust memorized data — verify when something seems off. Prefer re-listing over using a memorized ID that might be stale.
Format / Example
CODEBLOCK2
Memory lets you skip repeated channel list and workspace list calls. When you already know an ID from a previous session, use it directly.
Commands
Auth Commands
CODEBLOCK3
Message Commands
CODEBLOCK4
Channel Commands
CODEBLOCK5
User Commands
CODEBLOCK6
Reaction Commands
CODEBLOCK7
File Commands
CODEBLOCK8
Unread Commands
CODEBLOCK9
Activity Commands
CODEBLOCK10
Saved Items Commands
CODEBLOCK11
Drafts Commands
CODEBLOCK12
Channel Sections Commands
CODEBLOCK13
Snapshot Command
Get comprehensive workspace state for AI agents:
CODEBLOCK14
Returns JSON with:
- - Workspace metadata
- Channels (id, name, topic, purpose)
- Recent messages (ts, text, user, channel)
- Users (id, name, profile)
Output Format
JSON (Default)
All commands output JSON by default for AI consumption:
CODEBLOCK15
Pretty (Human-Readable)
Use --pretty flag for formatted output:
CODEBLOCK16
Common Patterns
See references/common-patterns.md for typical AI agent workflows.
Templates
See templates/ directory for runnable examples:
- -
post-message.sh - Send messages with error handling - INLINECODE21 - Monitor channel for new messages
- INLINECODE22 - Generate workspace summary
Error Handling
All commands return consistent error format:
CODEBLOCK17
Common errors:
- -
NO_WORKSPACE: No authenticated workspace (auto-extraction failed — see Troubleshooting) - INLINECODE24 : Slack API returned an error
- INLINECODE25 : Hit Slack rate limit (auto-retries with backoff)
Configuration
Credentials stored in: INLINECODE26
Format:
CODEBLOCK18
Security: File permissions set to 0600 (owner read/write only)
Limitations
- - No real-time events / Socket Mode
- No channel management (create/archive)
- No workspace admin operations
- No scheduled messages
- No user presence features
- Plain text messages only (no blocks/formatting in v1)
Troubleshooting
Authentication fails or no workspace found
Credentials are normally extracted automatically. If auto-extraction fails, run it manually with debug output:
CODEBLOCK19
Common causes:
- - Slack desktop app is not installed or not logged in
- macOS Keychain access was denied (re-run and approve the prompt)
- Slack was installed via a method that uses a different storage path
agent-slack: command not found
agent-slack is NOT the npm package name. The npm package is agent-messenger.
If the package is installed globally, use agent-slack directly:
CODEBLOCK20
If the package is NOT installed, use bunx agent-messenger slack (note: slack subcommand, not agent-slack):
CODEBLOCK21
NEVER run bunx agent-slack — a separate, unrelated npm package named agent-slack exists on npm. It will silently install the wrong package with different (fewer) commands.
References
Agent Slack
一个TypeScript CLI工具,使AI代理和人类能够通过简单的命令界面与Slack工作区交互。支持从Slack桌面应用无缝提取令牌,并支持多工作区。
快速开始
bash
获取工作区快照(凭据会自动提取)
agent-slack snapshot
发送消息
agent-slack message send general 来自AI代理的问候!
列出频道
agent-slack channel list
身份验证
首次使用时,凭据会自动从Slack桌面应用提取。无需手动设置——只需运行任何命令,身份验证就会在后台静默完成。
在macOS上,系统可能会在首次使用时提示输入钥匙串密码(需要解密Slack存储的令牌)。这是一次性提示。
重要提示:切勿引导用户打开网页浏览器、使用开发者工具或手动从浏览器复制令牌。始终使用agent-slack auth extract从桌面应用获取令牌。
多工作区支持
bash
列出所有已验证的工作区
agent-slack workspace list
切换到其他工作区
agent-slack workspace switch
显示当前工作区
agent-slack workspace current
移除工作区
agent-slack workspace remove
检查身份验证状态
agent-slack auth status
记忆
代理维护一个~/.config/agent-messenger/MEMORY.md文件,作为跨会话的持久记忆。该文件由代理管理——CLI不会读取或写入此文件。使用Read和Write工具管理您的记忆文件。
读取记忆
在每个任务开始时,使用Read工具读取~/.config/agent-messenger/MEMORY.md,加载之前发现的工作区ID、频道ID、用户ID和偏好设置。
- - 如果文件尚不存在,没关系——继续执行任务,并在首次有有用信息需要存储时创建它。
- 如果文件无法读取(权限问题、目录缺失),继续执行任务而不使用记忆——不要报错。
写入记忆
发现有用信息后,使用Write工具更新~/.config/agent-messenger/MEMORY.md。写入触发条件包括:
- - 发现工作区ID后(来自workspace list)
- 发现有用的频道ID和名称后(来自channel list、snapshot等)
- 发现用户ID和名称后(来自user list、user me等)
- 用户给您别名或偏好后(称此为部署频道、我的主要工作区是X)
- 发现频道结构后(侧边栏分区、频道分类)
写入时,包含完整的文件内容——Write工具会覆盖整个文件。
存储内容
- - 带名称的工作区ID
- 带名称和用途的频道ID
- 带显示名称的用户ID
- 用户给定的别名(部署频道、主要工作区)
- 常用的线程时间戳
- 交互过程中表达的任何用户偏好
不应存储的内容
切勿存储令牌、cookie、凭据或任何敏感数据。切勿存储完整的消息内容(仅存储ID和频道上下文)。切勿存储文件上传内容。
处理过期数据
如果记忆中的ID返回错误(频道未找到、用户未找到),从MEMORY.md中移除它。不要盲目信任记忆中的数据——当某些内容看起来不对劲时进行验证。优先重新列出,而不是使用可能过期的记忆ID。
格式/示例
markdown
Agent Messenger 记忆
Slack 工作区
- - T0ABC1234 — Acme Corp(默认)
- T0DEF5678 — 副项目
频道(Acme Corp)
- - C012ABC — #general(公司公告)
- C034DEF — #engineering(团队讨论)
- C056GHI — #deploys(CI/CD通知)
用户(Acme Corp)
- - U0ABC123 — Alice(工程主管)
- U0DEF456 — Bob(后端)
别名
- - 部署 → C056GHI(Acme Corp中的#deploys)
- 主要工作区 → T0ABC1234(Acme Corp)
备注
- - 用户偏好快照使用--pretty输出
- 主要工作区是Acme Corp
记忆让您跳过重复的channel list和workspace list调用。当您已经从之前的会话中知道某个ID时,直接使用它。
命令
身份验证命令
bash
从Slack桌面应用提取令牌(通常自动完成)
agent-slack auth extract
agent-slack auth extract --debug
检查身份验证状态
agent-slack auth status
从工作区注销(默认为当前工作区)
agent-slack auth logout
agent-slack auth logout
消息命令
bash
发送消息
agent-slack message send
agent-slack message send general Hello world
发送线程回复
agent-slack message send general 回复 --thread
列出消息
agent-slack message list
agent-slack message list general --limit 50
跨工作区搜索消息
agent-slack message search
agent-slack message search 项目更新
agent-slack message search from:@user 截止日期 --limit 50
agent-slack message search in:#general 会议 --sort timestamp
按时间戳获取单条消息
agent-slack message get
agent-slack message get general 1234567890.123456
获取线程回复(包含父消息)
agent-slack message replies
agent-slack message replies general 1234567890.123456
agent-slack message replies general 1234567890.123456 --limit 50
agent-slack message replies general 1234567890.123456 --oldest 1234567890.000000
agent-slack message replies general 1234567890.123456 --cursor
更新消息
agent-slack message update
删除消息
agent-slack message delete --force
频道命令
bash
列出频道(默认排除已归档的)
agent-slack channel list
agent-slack channel list --type public
agent-slack channel list --type private
agent-slack channel list --include-archived
获取频道信息
agent-slack channel info
agent-slack channel info general
获取频道历史(消息列表的别名)
agent-slack channel history --limit 100
用户命令
bash
列出用户
agent-slack user list
agent-slack user list --include-bots
获取用户信息
agent-slack user info
获取当前用户
agent-slack user me
反应命令
bash
添加反应
agent-slack reaction add
agent-slack reaction add general 1234567890.123456 thumbsup
移除反应
agent-slack reaction remove
列出消息上的反应
agent-slack reaction list
文件命令
bash
上传文件
agent-slack file upload
agent-slack file upload general ./report.pdf
列出文件
agent-slack file list
agent-slack file list --channel general
获取文件信息
agent-slack file info
未读命令
bash
获取所有频道的未读计数
agent-slack unread counts
获取线程订阅详情
agent-slack unread threads
将频道标记为已读至指定时间戳
agent-slack unread mark
活动命令
bash
列出活动动态(提及、反应、回复)
agent-slack activity list
agent-slack activity list --limit 50
agent-slack activity list --unread
agent-slack activity list --types threadreply,messagereaction
已保存项目命令
bash
列出已保存项目
agent-slack saved list
agent-slack saved list --limit 10
草稿命令
bash
列出所有草稿
agent-slack drafts list
agent-slack drafts list --pretty
频道分区命令
bash
列出频道分区(侧边栏组织)
agent-slack sections list
agent-slack sections list --pretty
快照命令
获取AI代理的全面工作区状态:
bash
完整快照
agent-slack snapshot
过滤快照
agent-slack snapshot --channels-only
agent-slack snapshot --users-only
限制每个频道的消息数
agent-sl