slack-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSlack CLI
Slack CLI
Interact with Slack workspaces from the command line using and direct Slack API calls.
slack-cliAssumeis already installed and configured. If theslack-clicommand is not found or returnsslack, refer to references/INSTALLATION.md for setup instructions.not_inited
使用和直接调用Slack API从命令行与Slack工作区交互。
slack-cli假设已安装并配置完成。 如果slack-cli命令未找到或返回slack,请参考references/INSTALLATION.md获取设置说明。not_inited
When to Use
适用场景
- User wants to send, update, or delete Slack messages
- User wants to read channel history or search messages
- User wants to list channels, users, or conversations
- User wants to upload files to Slack
- User wants to manage reminders, snooze, or presence
- User wants to automate Slack workflows
- 用户想要发送、更新或删除Slack消息
- 用户想要查看频道历史或搜索消息
- 用户想要列出频道、用户或会话
- 用户想要向Slack上传文件
- 用户想要管理提醒、免打扰状态或在线状态
- 用户想要自动化Slack工作流
Setup
设置步骤
If is not available or not configured, see references/INSTALLATION.md for full setup instructions.
slackThe token is stored at the path configured in the binary's variable (typically on macOS). You can also use the environment variable.
slacketcdir/opt/homebrew/etc/slack-cli/.slackSLACK_CLI_TOKEN如果命令不可用或未配置,请查看references/INSTALLATION.md获取完整设置说明。
slack令牌存储在二进制文件变量配置的路径下(macOS上通常为)。您也可以使用环境变量。
slacketcdir/opt/homebrew/etc/slack-cli/.slackSLACK_CLI_TOKENCredential Management with psst
使用psst管理凭证
Store the Slack token in the global psst vault:
bash
psst --global set SLACK_CLI_TOKEN --tag slackFor built-in commands, inject the token via psst:
bash
psst --global SLACK_CLI_TOKEN -- slack chat send 'Hello!' '#channel'For direct API calls, use inline :
psst getbash
curl -s -H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)" "https://slack.com/api/..."将Slack令牌存储在全局psst密钥库中:
bash
psst --global set SLACK_CLI_TOKEN --tag slack对于内置命令,通过psst注入令牌:
bash
psst --global SLACK_CLI_TOKEN -- slack chat send 'Hello!' '#channel'对于直接API调用,使用内联:
psst getbash
curl -s -H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)" "https://slack.com/api/..."Built-in Commands
内置命令
The CLI supports these commands natively:
slackslackChat
聊天
bash
undefinedbash
undefinedSend a message
发送消息
slack chat send 'Hello world!' '#channel'
slack chat send 'Hello world!' '#channel'
Send with rich formatting
发送富格式消息
slack chat send --text 'text' --channel '#channel' --color good --title 'Title' --pretext 'Pretext'
slack chat send --text 'text' --channel '#channel' --color good --title 'Title' --pretext 'Pretext'
Pipe content as a message
将内容通过管道作为消息发送
echo "some output" | slack chat send --channel '#channel'
echo "some output" | slack chat send --channel '#channel'
Update a message (requires timestamp and channel)
更新消息(需要时间戳和频道)
slack chat update 'Updated text' 1405894322.002768 '#channel'
slack chat update 'Updated text' 1405894322.002768 '#channel'
Delete a message
删除消息
slack chat delete 1405894322.002768 '#channel'
slack chat delete 1405894322.002768 '#channel'
Chain: send, capture ts+channel, then update
链式操作:发送、捕获时间戳+频道,然后更新
slack chat send 'hello' '#general' --filter '.ts + "\n" + .channel' |
xargs -n2 slack chat update 'goodbye'
xargs -n2 slack chat update 'goodbye'
undefinedslack chat send 'hello' '#general' --filter '.ts + "\n" + .channel' |
xargs -n2 slack chat update 'goodbye'
xargs -n2 slack chat update 'goodbye'
undefinedFiles
文件
bash
undefinedbash
undefinedUpload a file
上传文件
slack file upload README.md '#channel'
slack file upload README.md '#channel'
Upload with metadata
带元数据上传
slack file upload README.md '#channel' --comment 'See attached' --title 'README'
slack file upload README.md '#channel' --comment 'See attached' --title 'README'
Create a Slack post from markdown
从markdown创建Slack帖子
slack file upload --file post.md --filetype post --title 'Post Title' --channels '#channel'
slack file upload --file post.md --filetype post --title 'Post Title' --channels '#channel'
List files
列出文件
slack file list
slack file list --filter '[.files[] | {id, name, size}]'
slack file list
slack file list --filter '[.files[] | {id, name, size}]'
File info / delete
文件信息 / 删除
slack file info F2147483862
slack file delete F2147483862
undefinedslack file info F2147483862
slack file delete F2147483862
undefinedReminders
提醒
bash
undefinedbash
undefinedAdd a reminder
添加提醒
slack reminder add 'lunch' $(date -v +30M "+%s")
slack reminder add 'lunch' $(date -v +30M "+%s")
List / complete / delete
列出 / 标记完成 / 删除
slack reminder list
slack reminder complete Rm7MGABKT6
slack reminder delete Rm7MGABKT6
undefinedslack reminder list
slack reminder complete Rm7MGABKT6
slack reminder delete Rm7MGABKT6
undefinedSnooze (Do Not Disturb)
免打扰(Snooze)
bash
slack snooze start 60 # Start snooze for 60 minutes
slack snooze info # Check your snooze status
slack snooze end # End snoozebash
slack snooze start 60 # 开启60分钟免打扰
slack snooze info # 查看免打扰状态
slack snooze end # 结束免打扰Presence
在线状态
bash
slack presence active
slack presence awaybash
slack presence active
slack presence awayGlobal Options
全局选项
All commands support:
- — Apply a jq filter to the JSON response
--filter|-f <jq-filter> - — Compact JSON output
--compact|-cp - — No color in jq output
--monochrome|-m - — Enable bash trace for debugging
--trace|-x
所有命令均支持:
- — 对JSON响应应用jq过滤器
--filter|-f <jq-filter> - — 压缩JSON输出
--compact|-cp - — jq输出无颜色
--monochrome|-m - — 启用bash跟踪以调试
--trace|-x
Known Limitations
已知限制
- DMs via built-in CLI don't work reliably. often fails with
slack chat send 'msg' '@user'. Use the direct API pattern below instead.channel_not_found - Messages sent via appear as the Slack App, not as your user. This is a Slack API limitation — even with a user token, the app identity is used.
chat:write
- 通过内置CLI发送私信不可靠。 经常会因
slack chat send 'msg' '@user'失败。请改用下面的直接API调用方式。channel_not_found - 通过发送的消息显示为Slack应用身份,而非您的用户身份。这是Slack API的限制——即使使用用户令牌,仍会使用应用身份。
chat:write
Direct API Calls
直接API调用
The CLI doesn't cover all Slack API methods. For anything beyond the built-in commands, call the Slack API directly using . Read the token from the CLI's config file.
slackcurlslackcurlSending Direct Messages
发送私信
The built-in doesn't handle DMs well. Use the API directly:
slack chat sendbash
undefined内置的无法很好地处理私信。请直接使用API:
slack chat sendbash
undefinedStep 1: Open (or find) the DM channel with a user
步骤1:打开(或查找)与用户的私信频道
DM_CHANNEL=$(curl -s -X POST
-H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)"
-H "Content-Type: application/json"
-d '{"users":"USER_ID"}'
"https://slack.com/api/conversations.open" | jq -r '.channel.id')
-H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)"
-H "Content-Type: application/json"
-d '{"users":"USER_ID"}'
"https://slack.com/api/conversations.open" | jq -r '.channel.id')
DM_CHANNEL=$(curl -s -X POST
-H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)"
-H "Content-Type: application/json"
-d '{"users":"USER_ID"}'
"https://slack.com/api/conversations.open" | jq -r '.channel.id')
-H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)"
-H "Content-Type: application/json"
-d '{"users":"USER_ID"}'
"https://slack.com/api/conversations.open" | jq -r '.channel.id')
Step 2: Send the message
步骤2:发送消息
curl -s -X POST
-H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)"
-H "Content-Type: application/json"
-d "{"channel":"${DM_CHANNEL}","text":"Hello!"}"
"https://slack.com/api/chat.postMessage"
-H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)"
-H "Content-Type: application/json"
-d "{"channel":"${DM_CHANNEL}","text":"Hello!"}"
"https://slack.com/api/chat.postMessage"
> **Requires `im:write` scope.** Without it, `conversations.open` will fail. If you don't have `im:write`, you can work around it by finding an existing DM channel:
> ```bash
> DM_CHANNEL=$(curl -s \
> -H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)" \
> "https://slack.com/api/conversations.list?types=im&limit=200" | \
> jq -r '.channels[] | select(.user == "USER_ID") | .id')
> ```curl -s -X POST
-H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)"
-H "Content-Type: application/json"
-d "{"channel":"${DM_CHANNEL}","text":"Hello!"}"
"https://slack.com/api/chat.postMessage"
-H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)"
-H "Content-Type: application/json"
-d "{"channel":"${DM_CHANNEL}","text":"Hello!"}"
"https://slack.com/api/chat.postMessage"
> **需要`im:write`权限范围。** 没有该权限的话,`conversations.open`会失败。如果您没有`im:write`权限,可以通过查找现有私信频道来解决:
> ```bash
> DM_CHANNEL=$(curl -s \
> -H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)" \
> "https://slack.com/api/conversations.list?types=im&limit=200" | \
> jq -r '.channels[] | select(.user == "USER_ID") | .id')
> ```List Channels
列出频道
bash
curl -s -H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)" \
"https://slack.com/api/conversations.list?types=public_channel,private_channel&limit=200" | \
jq '[.channels[] | {name, id, is_private}]'bash
curl -s -H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)" \
"https://slack.com/api/conversations.list?types=public_channel,private_channel&limit=200" | \
jq '[.channels[] | {name, id, is_private}]'Read Channel History
查看频道历史
bash
undefinedbash
undefinedGet recent messages from a channel (use channel ID)
获取频道最近消息(使用频道ID)
curl -s -H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)"
"https://slack.com/api/conversations.history?channel=CHANNEL_ID&limit=20" |
jq '[.messages[] | {user, text, ts}]'
"https://slack.com/api/conversations.history?channel=CHANNEL_ID&limit=20" |
jq '[.messages[] | {user, text, ts}]'
curl -s -H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)"
"https://slack.com/api/conversations.history?channel=CHANNEL_ID&limit=20" |
jq '[.messages[] | {user, text, ts}]'
"https://slack.com/api/conversations.history?channel=CHANNEL_ID&limit=20" |
jq '[.messages[] | {user, text, ts}]'
Get messages from last 7 days
获取过去7天的消息
OLDEST=$(date -v -7d +%s)
curl -s -H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)"
"https://slack.com/api/conversations.history?channel=CHANNEL_ID&oldest=${OLDEST}&limit=100" |
jq '[.messages[] | {user, text, ts}]'
"https://slack.com/api/conversations.history?channel=CHANNEL_ID&oldest=${OLDEST}&limit=100" |
jq '[.messages[] | {user, text, ts}]'
OLDEST=$(date -v -7d +%s)
curl -s -H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)"
"https://slack.com/api/conversations.history?channel=CHANNEL_ID&oldest=${OLDEST}&limit=100" |
jq '[.messages[] | {user, text, ts}]'
"https://slack.com/api/conversations.history?channel=CHANNEL_ID&oldest=${OLDEST}&limit=100" |
jq '[.messages[] | {user, text, ts}]'
Get messages within a specific date range (oldest and latest are unix timestamps)
获取特定日期范围内的消息(oldest和latest为Unix时间戳)
curl -s -H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)"
"https://slack.com/api/conversations.history?channel=CHANNEL_ID&oldest=${START_TS}&latest=${END_TS}&limit=100" |
jq '[.messages[] | {user, text, ts}]'
"https://slack.com/api/conversations.history?channel=CHANNEL_ID&oldest=${START_TS}&latest=${END_TS}&limit=100" |
jq '[.messages[] | {user, text, ts}]'
undefinedcurl -s -H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)"
"https://slack.com/api/conversations.history?channel=CHANNEL_ID&oldest=${START_TS}&latest=${END_TS}&limit=100" |
jq '[.messages[] | {user, text, ts}]'
"https://slack.com/api/conversations.history?channel=CHANNEL_ID&oldest=${START_TS}&latest=${END_TS}&limit=100" |
jq '[.messages[] | {user, text, ts}]'
undefinedList Users
列出用户
bash
curl -s -H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)" \
"https://slack.com/api/users.list" | \
jq '[.members[] | {name, id, real_name}]'bash
curl -s -H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)" \
"https://slack.com/api/users.list" | \
jq '[.members[] | {name, id, real_name}]'Resolve multiple user IDs (no batch endpoint — fetch all and filter)
解析多个用户ID(无批量端点——获取全部后过滤)
curl -s -H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)"
"https://slack.com/api/users.list" |
jq '[.members[] | select(.id == "U1234" or .id == "U5678") | {id, name: .real_name}]'
"https://slack.com/api/users.list" |
jq '[.members[] | select(.id == "U1234" or .id == "U5678") | {id, name: .real_name}]'
undefinedcurl -s -H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)"
"https://slack.com/api/users.list" |
jq '[.members[] | select(.id == "U1234" or .id == "U5678") | {id, name: .real_name}]'
"https://slack.com/api/users.list" |
jq '[.members[] | select(.id == "U1234" or .id == "U5678") | {id, name: .real_name}]'
undefinedWorkspace Info
工作区信息
bash
undefinedbash
undefinedUse auth.test (not team.info — team.info requires a scope we don't have)
使用auth.test(不要用team.info——team.info需要我们没有的权限范围)
curl -s -H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)"
"https://slack.com/api/auth.test" |
jq '{team, team_id, url}'
"https://slack.com/api/auth.test" |
jq '{team, team_id, url}'
undefinedcurl -s -H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)"
"https://slack.com/api/auth.test" |
jq '{team, team_id, url}'
"https://slack.com/api/auth.test" |
jq '{team, team_id, url}'
undefinedSearch Messages
搜索消息
bash
curl -s -H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)" \
"https://slack.com/api/search.messages?query=keyword&count=10" | \
jq '[.messages.matches[] | {channel: .channel.name, text, ts}]'bash
curl -s -H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)" \
"https://slack.com/api/search.messages?query=keyword&count=10" | \
jq '[.messages.matches[] | {channel: .channel.name, text, ts}]'Reactions
表情反应
bash
undefinedbash
undefinedAdd a reaction
添加表情反应
curl -s -X POST
-H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)"
-H "Content-Type: application/json"
-d '{"channel":"CHANNEL_ID","timestamp":"1234567890.123456","name":"thumbsup"}'
"https://slack.com/api/reactions.add"
-H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)"
-H "Content-Type: application/json"
-d '{"channel":"CHANNEL_ID","timestamp":"1234567890.123456","name":"thumbsup"}'
"https://slack.com/api/reactions.add"
curl -s -X POST
-H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)"
-H "Content-Type: application/json"
-d '{"channel":"CHANNEL_ID","timestamp":"1234567890.123456","name":"thumbsup"}'
"https://slack.com/api/reactions.add"
-H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)"
-H "Content-Type: application/json"
-d '{"channel":"CHANNEL_ID","timestamp":"1234567890.123456","name":"thumbsup"}'
"https://slack.com/api/reactions.add"
Get reactions on a message
获取消息的表情反应
curl -s -H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)"
"https://slack.com/api/reactions.get?channel=CHANNEL_ID×tamp=1234567890.123456"
"https://slack.com/api/reactions.get?channel=CHANNEL_ID×tamp=1234567890.123456"
undefinedcurl -s -H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)"
"https://slack.com/api/reactions.get?channel=CHANNEL_ID×tamp=1234567890.123456"
"https://slack.com/api/reactions.get?channel=CHANNEL_ID×tamp=1234567890.123456"
undefinedThread Replies
线程回复
bash
undefinedbash
undefinedGet replies in a thread (use the parent message ts)
获取线程中的回复(使用父消息的时间戳)
curl -s -H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)"
"https://slack.com/api/conversations.replies?channel=CHANNEL_ID&ts=1234567890.123456" |
jq '[.messages[] | {user, text, ts}]'
"https://slack.com/api/conversations.replies?channel=CHANNEL_ID&ts=1234567890.123456" |
jq '[.messages[] | {user, text, ts}]'
undefinedcurl -s -H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)"
"https://slack.com/api/conversations.replies?channel=CHANNEL_ID&ts=1234567890.123456" |
jq '[.messages[] | {user, text, ts}]'
"https://slack.com/api/conversations.replies?channel=CHANNEL_ID&ts=1234567890.123456" |
jq '[.messages[] | {user, text, ts}]'
undefinedPost to a Thread
回复到线程
bash
curl -s -X POST \
-H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)" \
-H "Content-Type: application/json" \
-d '{"channel":"CHANNEL_ID","text":"reply text","thread_ts":"1234567890.123456"}' \
"https://slack.com/api/chat.postMessage"bash
curl -s -X POST \
-H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)" \
-H "Content-Type: application/json" \
-d '{"channel":"CHANNEL_ID","text":"reply text","thread_ts":"1234567890.123456"}' \
"https://slack.com/api/chat.postMessage"Tips
小贴士
- Channel arguments accept format for built-in commands, but direct API calls require channel IDs (e.g.
#name)CHANNEL_ID - Use with any built-in command to extract specific fields via jq
--filter - Pipe commands together using to chain send/update/delete
--filter '.ts + "\n" + .channel' - For direct API calls, always quote the URL to prevent shell glob expansion
- Pagination: most list endpoints support and
cursorparameters — checklimitin the responseresponse_metadata.next_cursor - To look up a user ID by name:
curl -s -H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)" "https://slack.com/api/users.list" | jq -r '.members[] | select(.real_name | test("Name"; "i")) | {name, id, real_name}' - Message permalinks: — remove the dot from the message timestamp (e.g. ts
https://<workspace>.slack.com/archives/<channel_id>/p<ts_without_dot>becomes1769935497.539749)p1769935497539749
- 内置命令的频道参数接受格式,但直接API调用需要频道ID(例如
#name)CHANNEL_ID - 对任何内置命令使用参数,通过jq提取特定字段
--filter - 使用将命令通过管道连接,实现发送/更新/删除的链式操作
--filter '.ts + "\n" + .channel' - 对于直接API调用,务必给URL加引号,防止shell通配符展开
- 分页:大多数列表端点支持和
cursor参数——请查看响应中的limitresponse_metadata.next_cursor - 通过用户名查找用户ID:
curl -s -H "Authorization: Bearer $(psst --global get SLACK_CLI_TOKEN)" "https://slack.com/api/users.list" | jq -r '.members[] | select(.real_name | test("Name"; "i")) | {name, id, real_name}' - 消息永久链接: —— 移除消息时间戳中的点(例如时间戳
https://<workspace>.slack.com/archives/<channel_id>/p<ts_without_dot>变为1769935497.539749)p1769935497539749