slack-cli

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Slack CLI

Slack CLI

Use the Slack CLI to create, run, and manage Slack apps — including calling Web API methods directly and searching Slack developer documentation from the terminal.
For initial setup (sandbox creation, project scaffolding from templates), use the
slack:create-slack-app
skill instead.

使用Slack CLI从终端创建、运行和管理Slack应用——包括直接调用Web API方法,以及从终端搜索Slack开发者文档。
如果是初始设置(创建沙箱、从模板搭建项目),请使用
slack:create-slack-app
技能。

Step 1: Detect the Slack CLI

步骤1:检测Slack CLI

Resolve the path to the public Slack CLI before running any other command. We refer to the resolved value as
SLACK_CMD
— substitute it everywhere below. Try 1a → 1b → 1c in order; do not skip ahead.
在运行任何其他命令之前,先确定公开版Slack CLI的路径。我们将确定后的路径称为
SLACK_CMD
——请在下文所有位置替换为实际路径。按顺序尝试1a → 1b → 1c,不要跳过。

1a. Standard install path (preferred — no verification needed)

1a. 标准安装路径(首选——无需验证)

The official install scripts place the binary at a fixed per-user path. If the file exists, use it directly: only the install script writes to that path.
  • macOS / Linux:
    ~/.slack/bin/slack
  • Windows:
    %USERPROFILE%\AppData\Local\slack-cli\bin\slack.exe
    (or
    %USERPROFILE%\.slack-cli\bin\slack.exe
    as a fallback)
POSIX shell:
bash
[ -x "$HOME/.slack/bin/slack" ] && echo "$HOME/.slack/bin/slack"
PowerShell:
powershell
$p = "$env:USERPROFILE\AppData\Local\slack-cli\bin\slack.exe"
if (Test-Path $p) { $p } elseif (Test-Path "$env:USERPROFILE\.slack-cli\bin\slack.exe") { "$env:USERPROFILE\.slack-cli\bin\slack.exe" }
If a path is returned, set
SLACK_CMD
to that absolute path and proceed to Step 2. Do not also run
_fingerprint
.
官方安装脚本会将二进制文件放在固定的用户专属路径。如果文件存在,可直接使用:只有安装脚本会写入该路径。
  • macOS / Linux:
    ~/.slack/bin/slack
  • Windows:
    %USERPROFILE%\AppData\Local\slack-cli\bin\slack.exe
    (备用路径为
    %USERPROFILE%\.slack-cli\bin\slack.exe
POSIX shell命令:
bash
[ -x "$HOME/.slack/bin/slack" ] && echo "$HOME/.slack/bin/slack"
PowerShell命令:
powershell
$p = "$env:USERPROFILE\AppData\Local\slack-cli\bin\slack.exe"
if (Test-Path $p) { $p } elseif (Test-Path "$env:USERPROFILE\.slack-cli\bin\slack.exe") { "$env:USERPROFILE\.slack-cli\bin\slack.exe" }
如果返回路径,请将
SLACK_CMD
设置为该绝对路径,然后进入步骤2。无需运行
_fingerprint

1b.
slack
on PATH (verify with fingerprint)

1b. PATH中的
slack
命令(通过指纹验证)

If 1a found nothing, try
slack
on PATH:
bash
slack _fingerprint 2>/dev/null
If it outputs
d41d8cd98f00b204e9800998ecf8427e
, set
SLACK_CMD=slack
and proceed.
如果1a未找到任何结果,尝试PATH中的
slack
命令:
bash
slack _fingerprint 2>/dev/null
如果输出为
d41d8cd98f00b204e9800998ecf8427e
,设置
SLACK_CMD=slack
并继续。

1c. Ask about an alias, or install

1c. 询问别名或进行安装

If 1b fails or returns a different value, ask the developer using AskUserQuestion:
  • "The
    slack
    command on your system doesn't appear to be the public Slack CLI. Do you have it installed under a different name or alias?"
  • Options: "Yes, it's aliased as..." (let them provide the alias), "No, I need to install it"
  • If they provide an alias, verify it with
    <alias> _fingerprint 2>/dev/null
    and set
    SLACK_CMD=<alias>
    .
  • If they need to install it, run:
    text
    curl -fsSL https://downloads.slack-edge.com/slack-cli/install.sh | bash
    Then re-run 1a — the install script will have written
    ~/.slack/bin/slack
    .
Common mistakes: Don't use
which slack
to discover the binary —
which
resolves any shell alias and defeats the point of 1a. In Git Bash on Windows, use the POSIX probe form, not PowerShell.

如果1b失败或返回不同值,请使用AskUserQuestion询问开发者:
  • "你系统中的
    slack
    命令似乎不是公开版Slack CLI。你是否使用其他名称或别名安装了它?"
  • 选项:"是的,它的别名是..."(让开发者提供别名),"没有,我需要安装它"
  • 如果开发者提供别名,使用
    <alias> _fingerprint 2>/dev/null
    验证,然后设置
    SLACK_CMD=<alias>
  • 如果需要安装,运行:
    text
    curl -fsSL https://downloads.slack-edge.com/slack-cli/install.sh | bash
    然后重新运行1a——安装脚本会将文件写入
    ~/.slack/bin/slack
常见错误:不要使用
which slack
查找二进制文件——
which
会解析任何shell别名,导致1a的验证失效。在Windows的Git Bash中,请使用POSIX探测格式,而非PowerShell。

Step 2: Command Discovery via Help

步骤2:通过帮助文档发现命令

Always run
SLACK_CMD <command> --help
before constructing a command you have not used in the current session.
Do not guess at flags — the help output is the source of truth.
  • SLACK_CMD help
    — lists all available command groups
  • SLACK_CMD <command> --help
    — shows subcommands, flags, and usage examples
**在当前会话中构建未使用过的命令之前,务必先运行
SLACK_CMD <command> --help
。**不要猜测参数——帮助输出是权威来源。
  • SLACK_CMD help
    ——列出所有可用命令组
  • SLACK_CMD <command> --help
    ——显示子命令、参数和使用示例

Resolving
--app
and
--team
values

解析
--app
--team
参数值

When a command requires
--app
or
--team
:
  • App ID: Run
    SLACK_CMD app list
    from the project directory to see installed apps and their IDs.
  • Team ID: Run
    SLACK_CMD auth list
    to see authenticated workspaces and their team IDs.

当命令需要
--app
--team
时:
  • 应用ID:从项目目录运行
    SLACK_CMD app list
    ,查看已安装的应用及其ID。
  • 团队ID:运行
    SLACK_CMD auth list
    ,查看已验证的工作区及其团队ID。

Step 3: Searching Documentation (
slack docs search
)

步骤3:搜索文档(
slack docs search

Search Slack's developer documentation directly from the terminal.
bash
SLACK_CMD docs search "<query>" --output=text --limit=5
Use
--output=text
for concise terminal-readable results. Use this when you are already running CLI commands and want to:
  • Check a Slack feature before implementing it
  • Verify API behavior or required scopes
  • Look up Block Kit elements, event types, or method parameters

直接从终端搜索Slack开发者文档。
bash
SLACK_CMD docs search "<query>" --output=text --limit=5
使用
--output=text
获取适合终端阅读的简洁结果。当你正在运行CLI命令,且需要以下操作时使用该命令:
  • 在实现前检查Slack功能
  • 验证API行为或所需权限
  • 查询Block Kit元素、事件类型或方法参数

Step 4: Calling Web API Methods (
slack api
)

步骤4:调用Web API方法(
slack api

Call any Slack Web API method directly. Run
SLACK_CMD api --help
for full details and examples.
Parameters are passed as positional
key=value
pairs (NOT
--key=value
flags):
bash
SLACK_CMD api chat.postMessage channel=C0123456789 text="Hello from the CLI"
Important distinction:
--team
,
--token
,
--json
, and
--data
are meta-flags (prefixed with
--
). API method parameters use positional
key=value
syntax without dashes.
Reference: Full method list at https://docs.slack.dev/reference/methods.md.

直接调用任何Slack Web API方法。运行
SLACK_CMD api --help
获取完整详情和示例。
参数以位置参数
key=value
的形式传递(不是
--key=value
参数):
bash
SLACK_CMD api chat.postMessage channel=C0123456789 text="Hello from the CLI"
重要区别
--team
--token
--json
--data
是元参数(以
--
开头)。API方法参数使用不带短横线的位置
key=value
语法。
参考:完整方法列表见https://docs.slack.dev/reference/methods.md

Step 5: Authentication (
slack auth
)

步骤5:身份验证(
slack auth

When to run this flow

何时运行此流程

Slack auth is per-team, not a single boolean. Run the seamless login flow below whenever any of these is true:
  • The developer is not authenticated to any team yet.
  • The developer wants to add a new team / workspace / sandbox, even if
    SLACK_CMD auth list
    already shows other teams.
  • The developer asks to log in, switch teams, or re-authenticate.
SLACK_CMD auth list
showing other teams is not a reason to skip login — those are different teams. Ask the developer which team they want, then run the flow.
Slack身份验证是按团队划分的,不是单一的布尔状态。当出现以下任一情况时,运行下方的无缝登录流程:
  • 开发者尚未验证任何团队。
  • 开发者想要添加新团队/工作区/沙箱,即使
    SLACK_CMD auth list
    已显示其他团队。
  • 开发者要求登录、切换团队或重新验证。
SLACK_CMD auth list
显示其他团队不是跳过登录的理由——这些是不同的团队。询问开发者想要哪个团队,然后运行流程。

Inspect existing auth (optional)

检查现有身份验证(可选)

bash
SLACK_CMD auth list
Use this to show the developer which teams are already authenticated, or to confirm a successful login. Do not treat a non-empty list as "auth complete" when the developer asked to log in to a new team.
bash
SLACK_CMD auth list
使用此命令向开发者展示已验证的团队,或确认登录成功。当开发者要求登录新团队时,不要将非空列表视为“身份验证完成”。

Run the seamless login flow

运行无缝登录流程

The agent drives this end-to-end — no separate terminal window, no browser confirmation.
SLACK_CMD login --no-prompt
makes the CLI emit a single-use ticket and exit immediately instead of waiting on stdin. Slack itself renders the challenge code inside a workspace modal when the developer sends the
/slackauthticket
slash command — there is no browser step. The agent submits the challenge back to the CLI to complete login.
1. Start login and capture the ticket
bash
SLACK_CMD login --no-prompt
The CLI prints a
/slackauthticket <ticket>
slash command and exits. Capture the ticket — you will need it in step 4. Sample output:
text
📋 Run the following slash command from any Slack channel in the workspace
   you'd like to authenticate

   /slackauthticket eyJ0eXAiOiJKV1QiLCJh…

? Slack will then show you a challenge code. Submit it via:
   slack login --ticket <ticket> --challenge <code>
2. Hand the slash command to the developer
Show the full
/slackauthticket …
line and ask the developer to paste it into the message box of the Slack workspace they want to authenticate, then send it. Slack responds with a modal containing a short challenge code (e.g.
JDt1IK7X
).
3. Collect the challenge code
Use
AskUserQuestion
to ask the developer for the challenge code shown in the Slack modal. Wait for their answer — do not guess or default.
4. Complete login
bash
SLACK_CMD login --ticket <ticket> --challenge <code>
On success the CLI returns the team name and ID. Verify with
SLACK_CMD auth list
and report the team back to the developer.
Troubleshooting: tickets are single-use and time-limited. If step 4 fails with an invalid/expired ticket or wrong challenge, restart from step 1 with a fresh
SLACK_CMD login --no-prompt
— do not retry the same ticket.
Use
--team <team_id>
on individual commands to target a specific workspace without switching globally.
由Agent全程驱动此流程——无需单独的终端窗口,无需浏览器确认
SLACK_CMD login --no-prompt
会让CLI生成一次性凭证并立即退出,而非等待标准输入。当开发者发送
/slackauthticket
斜杠命令时,Slack会在工作区模态框内显示验证码——无需浏览器步骤。Agent将验证码提交回CLI以完成登录。
1. 启动登录并捕获凭证
bash
SLACK_CMD login --no-prompt
CLI会打印
/slackauthticket <ticket>
斜杠命令并退出。捕获凭证——步骤4需要用到。示例输出:
text
📋 在你想要验证的工作区的任意Slack频道中运行以下斜杠命令

   /slackauthticket eyJ0eXAiOiJKV1QiLCJh…

? Slack随后会向你展示验证码。通过以下命令提交:
   slack login --ticket <ticket> --challenge <code>
2. 将斜杠命令交给开发者
完整展示
/slackauthticket …
一行,并要求开发者将其粘贴到想要验证的Slack工作区的消息框中发送。Slack会回复一个包含短验证码的模态框(例如
JDt1IK7X
)。
3. 收集验证码
使用
AskUserQuestion
询问开发者Slack模态框中显示的验证码。等待开发者回复——不要猜测或使用默认值。
4. 完成登录
bash
SLACK_CMD login --ticket <ticket> --challenge <code>
成功后,CLI会返回团队名称和ID。使用
SLACK_CMD auth list
验证,并将团队信息反馈给开发者。
故障排除:凭证是一次性的且有时间限制。如果步骤4因凭证无效/过期或验证码错误而失败,请重新从步骤1开始,运行新的
SLACK_CMD login --no-prompt
——不要重试同一凭证。
在单个命令上使用
--team <team_id>
可指定目标工作区,无需全局切换。

Red flags — STOP

危险信号——立即停止

If you catch yourself thinking any of these, you are about to regress to the old broken flow:
RationalizationReality
"
auth list
already shows teams, so login isn't needed."
Auth is per-team. The developer asked for a new team — drive the flow.
"
slack login
needs browser confirmation, so I can't drive it."
False with
--no-prompt
. The challenge code appears in Slack's modal, not a browser. The agent runs both
slack login
invocations itself.
"I should tell the developer to run
slack login
in a separate terminal."
Never. Step 5 is the agent's job from start to finish.
All of these mean: run
SLACK_CMD login --no-prompt
yourself and follow the four numbered steps above.

如果你有以下想法,说明你即将退回到旧的失效流程:
错误想法实际情况
"
auth list
已显示团队,所以不需要登录。"
身份验证按团队划分。开发者要求登录_新_团队——请驱动流程。
"
slack login
需要浏览器确认,所以我无法驱动。"
使用
--no-prompt
时此说法不成立。验证码显示在Slack的模态框中,而非浏览器。Agent需自行运行两次
slack login
调用。
"我应该让开发者在单独的终端窗口中运行
slack login
。"
绝对不要这样做。步骤5全程由Agent负责。
出现以上任何情况时:自行运行
SLACK_CMD login --no-prompt
,并按照上述四个编号步骤操作。

Step 6: Running an App Locally (
slack run
)

步骤6:本地运行应用(
slack run

Run
SLACK_CMD run --help
for all available flags.
运行
SLACK_CMD run --help
查看所有可用参数。

Resolve the app or team target

确定应用或团队目标

Run
SLACK_CMD app list
from the project directory to check for installed apps:
  • If an app exists: Use
    --app=<app_id>
    in the run command.
  • If no apps are listed: Use
    --team=<team_id>
    instead (get the team ID from
    SLACK_CMD auth list
    ).
从项目目录运行
SLACK_CMD app list
检查已安装的应用:
  • 如果存在应用:在运行命令中使用
    --app=<app_id>
  • 如果未列出应用:改用
    --team=<team_id>
    (从
    SLACK_CMD auth list
    获取团队ID)。

Start the dev server in the background

在后台启动开发服务器

Run this command as a background process so the developer can continue working:
If an app ID was found:
bash
cd <project-dir> && SLACK_CMD run --org-workspace-grant=all --app=<app_id>
If no apps — use the team ID:
bash
cd <project-dir> && SLACK_CMD run --org-workspace-grant=all --team=<team_id>
Tell the developer the app is running in the background. They can ask:
  • "What's the status of the dev server?" — to check on it
  • "Show me the output from slack run" — to see activity logs
  • "Stop the dev server" — to terminate the process

将此命令作为后台进程运行,以便开发者可以继续工作:
如果找到应用ID:
bash
cd <project-dir> && SLACK_CMD run --org-workspace-grant=all --app=<app_id>
如果没有应用——使用团队ID:
bash
cd <project-dir> && SLACK_CMD run --org-workspace-grant=all --team=<team_id>
告知开发者应用正在后台运行。他们可能会询问:
  • "开发服务器的状态如何?" ——检查服务器状态
  • "显示
    slack run
    的输出" ——查看活动日志
  • "停止开发服务器" ——终止进程

Step 7: Managing the Manifest

步骤7:管理Manifest

Run
SLACK_CMD manifest --help
for subcommands (
validate
,
info
) and the
--source local|remote
flag.
Use
SLACK_CMD manifest validate
before deploying or when something seems wrong with the app configuration.

运行
SLACK_CMD manifest --help
查看子命令(
validate
info
)和
--source local|remote
参数。
在部署前或应用配置出现问题时,使用
SLACK_CMD manifest validate

Step 8: Other Commands

步骤8:其他命令

For any other command group (e.g.,
trigger
,
datastore
,
env
,
collaborator
,
external-auth
,
deploy
), run
SLACK_CMD <command> --help
to discover subcommands and flags. Run
SLACK_CMD help
to see all available command groups.

对于任何其他命令组(如
trigger
datastore
env
collaborator
external-auth
deploy
),运行
SLACK_CMD <command> --help
发现子命令和参数。运行
SLACK_CMD help
查看所有可用命令组。

Notes

注意事项

  • SLACK_CMD
    is a placeholder — always substitute the actual command name resolved in Step 1.
  • Always run
    --help
    before constructing a command you have not used in the current session.
  • Interactive commands (e.g.,
    slack trigger create
    without
    --trigger-def
    ) cannot be run in the background. Tell the developer to run these in a new terminal window.
    slack login
    is not in this category — drive it inline using the
    --no-prompt
    /
    --ticket
    /
    --challenge
    flow in Step 5.
  • slack run
    runs locally for development.
    slack deploy
    deploys to Slack's hosted infrastructure. These are different operations — do not confuse them.
  • SLACK_CMD
    是占位符——请始终替换为步骤1中确定的实际命令名称。
  • 务必先运行
    --help
    ,再构建当前会话中未使用过的命令。
  • 交互式命令(如不带
    --trigger-def
    slack trigger create
    )无法在后台运行。请告知开发者在新终端窗口中运行这些命令。
    slack login
    不属于此类命令——请使用步骤5中的
    --no-prompt
    /
    --ticket
    /
    --challenge
    流程全程驱动。
  • slack run
    用于本地开发。
    slack deploy
    用于部署到Slack的托管基础设施。这是两种不同的操作——不要混淆。