Agent SlackBot
A TypeScript CLI tool that enables AI agents and humans to interact with Slack workspaces using bot tokens (xoxb-). Unlike agent-slack which extracts user tokens from the desktop app, agent-slackbot uses standard Slack Bot tokens for server-side and CI/CD integrations.
Quick Start
CODEBLOCK0
Authentication
Bot Token Setup
agent-slackbot uses Slack Bot tokens (xoxb-) which you get from the Slack App configuration:
CODEBLOCK1
Multi-Bot Management
Store multiple bot tokens and switch between them:
CODEBLOCK2
The --bot <id> flag is available on all commands to override the active bot for a single invocation.
Getting a Bot Token
- 1. Go to api.slack.com/apps
- Create New App (or select existing)
- Go to OAuth & Permissions
- Add required bot token scopes (see below)
- Install app to workspace
- Copy the Bot User OAuth Token (starts with
xoxb-)
Required Bot Token Scopes
| Scope | Used For |
|---|
| INLINECODE2 | Sending messages |
| INLINECODE3 |
Reading public channel messages |
|
channels:read | Listing public channels |
|
channels:join | Joining public channels |
|
groups:history | Reading private channel messages |
|
groups:read | Listing private channels |
|
users:read | Listing users |
|
users:read.email | Reading user email addresses |
|
reactions:write | Adding/removing reactions |
|
reactions:read | Listing reactions |
Environment Variables (CI/CD)
For CI/CD pipelines, set these environment variables instead of using auth set:
CODEBLOCK3
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
auth status) - After discovering useful channel IDs and names (from
channel list, etc.) - After discovering user IDs and names (from
user list, etc.) - After the user gives you an alias or preference ("call this the alerts bot", "my main workspace is X")
- After setting up bot identifiers (from
auth list)
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
- Bot identifiers and their purposes
- User-given aliases ("alerts bot", "deploys channel")
- Any user preference expressed during interaction
What NOT to Store
Never store bot tokens, 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
CODEBLOCK4
Memory lets you skip repeated channel list and auth list calls. When you already know an ID from a previous session, use it directly.
Commands
Message Commands
CODEBLOCK5
Channel Commands
CODEBLOCK6
User Commands
CODEBLOCK7
Reaction Commands
CODEBLOCK8
Output Format
JSON (Default)
All commands output JSON by default for AI consumption:
CODEBLOCK9
Pretty (Human-Readable)
Use --pretty flag for formatted output:
CODEBLOCK10
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 - INLINECODE32 - Monitor channel for new messages
- INLINECODE33 - Generate workspace summary
Error Handling
All commands return consistent error format:
CODEBLOCK11
Common errors:
- -
missing_token: No credentials configured - INLINECODE35 : Token is not a bot token (must start with xoxb-)
- INLINECODE36 : Bot needs to join the channel first
- INLINECODE37 : Hit rate limit (auto-retries with backoff)
Configuration
Credentials stored in: INLINECODE38
Format:
CODEBLOCK12
Security: File permissions set to 0600 (owner read/write only)
Key Differences from agent-slack
| Feature | agent-slack | agent-slackbot |
|---|
| Token type | User token (xoxc-) | Bot token (xoxb-) |
| Token source |
Auto-extracted from desktop app | Manual from Slack App config |
| Message search | Yes | No (requires user token) |
| File operations | Yes | No |
| Snapshot | Yes | No |
| Edit/delete messages | Any message | Bot's own messages only |
| Workspace management | Multi-workspace | Multi-bot, multi-workspace |
| CI/CD friendly | Requires desktop app | Yes (just set token) |
Limitations
- - No real-time events / Socket Mode
- No message search (requires user token scope)
- No file upload/download
- No workspace snapshot
- Bot can only edit/delete its own messages
- Bot must be invited to private channels
- No scheduled messages
- Plain text messages only (no blocks/formatting)
Troubleshooting
agent-slackbot: command not found
agent-slackbot is NOT the npm package name. The npm package is agent-messenger.
If the package is installed globally, use agent-slackbot directly:
CODEBLOCK13
If the package is NOT installed, use bunx agent-messenger slackbot:
CODEBLOCK14
NEVER run bunx agent-slackbot — it will fail or install a wrong package since agent-slackbot is not the npm package name.
References
Agent SlackBot
一个TypeScript CLI工具,使AI代理和人类能够使用机器人令牌(xoxb-)与Slack工作区交互。与从桌面应用提取用户令牌的agent-slack不同,agent-slackbot使用标准的Slack机器人令牌进行服务器端和CI/CD集成。
快速开始
bash
设置你的机器人令牌
agent-slackbot auth set xoxb-your-bot-token
或者为多机器人设置自定义机器人标识符
agent-slackbot auth set xoxb-your-bot-token --bot deploy --name 部署机器人
验证身份认证
agent-slackbot auth status
发送消息
agent-slackbot message send C0ACZKTDDC0 来自机器人的问候!
列出频道
agent-slackbot channel list
身份认证
机器人令牌设置
agent-slackbot使用从Slack应用配置中获取的Slack机器人令牌(xoxb-):
bash
设置机器人令牌(保存前会向Slack API验证)
agent-slackbot auth set xoxb-your-bot-token
设置自定义机器人标识符
agent-slackbot auth set xoxb-your-bot-token --bot deploy --name 部署机器人
检查认证状态
agent-slackbot auth status
清除已存储的凭据
agent-slackbot auth clear
多机器人管理
存储多个机器人令牌并在它们之间切换:
bash
添加多个机器人
agent-slackbot auth set xoxb-deploy-token --bot deploy --name 部署机器人
agent-slackbot auth set xoxb-alert-token --bot alert --name 告警机器人
列出所有已存储的机器人
agent-slackbot auth list
切换活动机器人
agent-slackbot auth use deploy
为单个命令使用特定机器人(无需切换)
agent-slackbot message send C0ACZKTDDC0 告警! --bot alert
移除已存储的机器人
agent-slackbot auth remove deploy
消除跨工作区相同ID机器人的歧义
agent-slackbot auth use T123456/deploy
所有命令均可使用--bot 标志来覆盖单次调用的活动机器人。
获取机器人令牌
- 1. 前往 api.slack.com/apps
- 创建新应用(或选择现有应用)
- 进入 OAuth & 权限
- 添加所需的机器人令牌作用域(见下文)
- 将应用安装到工作区
- 复制 机器人用户OAuth令牌(以xoxb-开头)
所需机器人令牌作用域
| 作用域 | 用途 |
|---|
| chat:write | 发送消息 |
| channels:history |
读取公共频道消息 |
| channels:read | 列出公共频道 |
| channels:join | 加入公共频道 |
| groups:history | 读取私有频道消息 |
| groups:read | 列出私有频道 |
| users:read | 列出用户 |
| users:read.email | 读取用户邮箱地址 |
| reactions:write | 添加/移除表情反应 |
| reactions:read | 列出表情反应 |
环境变量(CI/CD)
对于CI/CD流水线,设置以下环境变量而非使用auth set:
bash
export E2ESLACKBOTTOKEN=xoxb-your-bot-token
export E2ESLACKBOTWORKSPACE_ID=T123456
export E2ESLACKBOTWORKSPACE_NAME=我的工作区
记忆
代理维护一个~/.config/agent-messenger/MEMORY.md文件作为跨会话的持久记忆。该文件由代理管理——CLI不会读取或写入此文件。使用读取和写入工具管理你的记忆文件。
读取记忆
在每个任务开始时,使用读取工具读取~/.config/agent-messenger/MEMORY.md,加载之前发现的任何工作区ID、频道ID、用户ID和偏好。
- - 如果文件尚不存在,没关系——继续执行,并在首次有有用信息需要存储时创建它。
- 如果文件无法读取(权限问题、目录缺失),继续执行而不使用记忆——不要报错退出。
写入记忆
发现有用信息后,使用写入工具更新~/.config/agent-messenger/MEMORY.md。写入触发条件包括:
- - 发现工作区ID后(来自auth status)
- 发现有用的频道ID和名称后(来自channel list等)
- 发现用户ID和名称后(来自user list等)
- 用户给你别名或偏好后(把这个称为告警机器人,我的主要工作区是X)
- 设置机器人标识符后(来自auth list)
写入时,包含完整的文件内容——写入工具会覆盖整个文件。
存储内容
- - 带名称的工作区ID
- 带名称和用途的频道ID
- 带显示名称的用户ID
- 机器人标识符及其用途
- 用户给定的别名(告警机器人、部署频道)
- 交互过程中表达的任何用户偏好
不存储内容
切勿存储机器人令牌、凭据或任何敏感数据。切勿存储完整消息内容(仅存储ID和频道上下文)。切勿存储文件上传内容。
处理过期数据
如果记忆中的ID返回错误(频道未找到、用户未找到),将其从MEMORY.md中移除。不要盲目信任记忆中的数据——当某些内容看起来异常时进行验证。优先重新列出,而非使用可能过期的记忆ID。
格式/示例
markdown
代理信使记忆
Slack工作区(机器人)
机器人(Acme公司)
- - deploy — 部署机器人(活动)
- alert — 告警机器人
频道(Acme公司)
- - C012ABC — #general(公司公告)
- C034DEF — #engineering(团队讨论)
- C056GHI — #deploys(CI/CD通知)
用户(Acme公司)
- - U0ABC123 — 爱丽丝(工程主管)
- U0DEF456 — 鲍勃(后端)
别名
- - 部署 → C056GHI(Acme公司中的#deploys)
备注
- - 部署机器人用于CI/CD通知
- 告警机器人用于错误监控
记忆让你可以跳过重复的channel list和auth list调用。当你已经从之前的会话中知道某个ID时,直接使用它。
命令
消息命令
bash
发送消息
agent-slackbot message send <频道> <文本>
agent-slackbot message send C0ACZKTDDC0 你好世界
发送线程回复
agent-slackbot message send C0ACZKTDDC0 回复 --thread <时间戳>
列出消息
agent-slackbot message list <频道>
agent-slackbot message list C0ACZKTDDC0 --limit 50
按时间戳获取单条消息
agent-slackbot message get <频道> <时间戳>
获取线程回复(包含父消息)
agent-slackbot message replies <频道> <线程时间戳>
agent-slackbot message replies C0ACZKTDDC0 1234567890.123456 --limit 50
更新消息(仅限机器人自己的消息)
agent-slackbot message update <频道> <时间戳> <新文本>
删除消息(仅限机器人自己的消息)
agent-slackbot message delete <频道> <时间戳> --force
频道命令
bash
列出机器人可见的频道
agent-slackbot channel list
agent-slackbot channel list --limit 50
获取频道信息
agent-slackbot channel info <频道>
agent-slackbot channel info C0ACZKTDDC0
用户命令
bash
列出用户
agent-slackbot user list
agent-slackbot user list --limit 50
获取用户信息
agent-slackbot user info <用户ID>
表情反应命令
bash
添加表情反应
agent-slackbot reaction add <频道> <时间戳> <表情>
agent-slackbot reaction add C0ACZKTDDC0 1234567890.123456 thumbsup
移除表情反应
agent-slackbot reaction remove <频道> <时间戳> <表情>
输出格式
JSON(默认)
所有命令默认输出JSON供AI消费:
json
{
ts: 1234567890.123456,
channel: C0ACZ