slack-messaging

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Slack Messaging via slackcli

通过slackcli进行Slack消息操作

Send and read Slack messages from the command line using
slackcli
(shaharia-lab/slackcli).
使用
slackcli
(shaharia-lab/slackcli)从命令行发送和读取Slack消息。

Installation

安装

Download the binary:
bash
curl -sL -o /usr/local/bin/slackcli \
  "https://github.com/shaharia-lab/slackcli/releases/download/v0.1.1/slackcli-linux"
chmod +x /usr/local/bin/slackcli
macOS (Intel): replace
slackcli-linux
with
slackcli-macos
macOS (Apple Silicon): replace with
slackcli-macos-arm64
下载二进制文件:
bash
curl -sL -o /usr/local/bin/slackcli \
  "https://github.com/shaharia-lab/slackcli/releases/download/v0.1.1/slackcli-linux"
chmod +x /usr/local/bin/slackcli
macOS(Intel芯片):将
slackcli-linux
替换为
slackcli-macos
macOS(Apple Silicon芯片):替换为
slackcli-macos-arm64

Authentication

身份验证

slackcli uses browser session tokens (xoxc + xoxd) - no Slack app creation required.
slackcli使用浏览器会话令牌(xoxc + xoxd)——无需创建Slack应用。

Interactive Setup

交互式设置

bash
./scripts/extract-tokens <workspace-url>
This walks the user through extracting tokens from browser DevTools.
bash
./scripts/extract-tokens <workspace-url>
该脚本会引导用户从浏览器开发者工具中提取令牌。

Manual Setup

手动设置

bash
slackcli auth login-browser \
  --xoxd="xoxd-..." \
  --xoxc="xoxc-..." \
  --workspace-url=https://your-workspace.slack.com
bash
slackcli auth login-browser \
  --xoxd="xoxd-..." \
  --xoxc="xoxc-..." \
  --workspace-url=https://your-workspace.slack.com

Verify Auth

验证身份

bash
slackcli auth list
bash
slackcli auth list

Finding Channels

查找频道

Use
slackcli conversations list
to discover channels and their IDs:
bash
undefined
使用
slackcli conversations list
命令发现频道及其ID:
bash
undefined

List all channels

列出所有频道

slackcli conversations list
slackcli conversations list

Filter output

过滤输出结果

slackcli conversations list | grep -i "channel-name"
undefined
slackcli conversations list | grep -i "channel-name"
undefined

Sending Messages

发送消息

bash
undefined
bash
undefined

Send to a channel (use channel ID from conversations list)

发送到频道(使用conversations list命令获取的频道ID)

slackcli messages send --recipient-id=C0XXXXXXXX --message="Hello from CLI"
slackcli messages send --recipient-id=C0XXXXXXXX --message="Hello from CLI"

Send to a DM (use user's DM channel ID)

发送到私信(使用用户的私信频道ID)

slackcli messages send --recipient-id=D0XXXXXXXX --message="Hey"
slackcli messages send --recipient-id=D0XXXXXXXX --message="Hey"

Reply in a thread

回复线程消息

slackcli messages send --recipient-id=C0XXXXXXXX --message="Thread reply" --thread-ts=1769756026.624319

The `--recipient-id` is always a channel ID (C...) or DM channel ID (D...).
slackcli messages send --recipient-id=C0XXXXXXXX --message="Thread reply" --thread-ts=1769756026.624319

`--recipient-id`参数始终为频道ID(C...)或私信频道ID(D...)。

Reading Messages

读取消息

bash
undefined
bash
undefined

Read last N messages from a channel

读取频道的最后N条消息

slackcli conversations read C0XXXXXXXX --limit=10
slackcli conversations read C0XXXXXXXX --limit=10

Read as JSON (for parsing)

以JSON格式读取(用于解析)

slackcli conversations read C0XXXXXXXX --limit=10 --json
slackcli conversations read C0XXXXXXXX --limit=10 --json

Read a thread

读取线程消息

slackcli conversations read C0XXXXXXXX --thread-ts=1769756026.624319
undefined
slackcli conversations read C0XXXXXXXX --thread-ts=1769756026.624319
undefined

Listing Channels

列出频道

bash
slackcli conversations list
Returns all public channels, private channels, and DMs with their IDs.
bash
slackcli conversations list
返回所有公开频道、私有频道和私信的信息及其ID。

Testing Slack Integrations

测试Slack集成

To verify a bot or integration posted a message correctly:
bash
undefined
要验证机器人或集成是否正确发送了消息:
bash
undefined

Read the channel, check for the expected message

读取频道内容,检查是否存在预期消息

slackcli conversations read CHANNEL_ID --limit=5 --json | jq '.messages[] | select(.text | contains("expected text"))'

To send a test message and verify the round-trip:

```bash
slackcli conversations read CHANNEL_ID --limit=5 --json | jq '.messages[] | select(.text | contains("expected text"))'

要发送测试消息并验证往返流程:

```bash

Send

发送消息

slackcli messages send --recipient-id=CHANNEL_ID --message="integration test $(date +%s)"
slackcli messages send --recipient-id=CHANNEL_ID --message="integration test $(date +%s)"

Read back

读取返回的消息

slackcli conversations read CHANNEL_ID --limit=1 --json
undefined
slackcli conversations read CHANNEL_ID --limit=1 --json
undefined

Multiple Workspaces

多工作区支持

slackcli supports multiple workspaces. Run the auth flow for each workspace you need:
bash
undefined
slackcli支持多工作区。为每个需要的工作区运行身份验证流程即可:
bash
undefined

Add first workspace

添加第一个工作区

./scripts/extract-tokens https://workspace-one.slack.com
./scripts/extract-tokens https://workspace-one.slack.com

Add second workspace

添加第二个工作区

./scripts/extract-tokens https://workspace-two.slack.com
./scripts/extract-tokens https://workspace-two.slack.com

List all authenticated workspaces

列出所有已验证的工作区

slackcli auth list

When sending messages, slackcli automatically routes to the correct workspace based on the channel ID.
slackcli auth list

发送消息时,slackcli会根据频道ID自动路由到对应的工作区。

Token Notes

令牌说明

  • Browser tokens (xoxc/xoxd) act as the logged-in user, not a bot
  • Messages sent appear as the user, not an app
  • Tokens expire when the user logs out of the browser session
  • To refresh: re-extract tokens from a logged-in browser session
  • All workspace credentials are stored at
    ~/.config/slackcli/workspaces.json
  • 浏览器令牌(xoxc/xoxd)以登录用户的身份操作,而非机器人
  • 发送的消息会显示为用户本人发送,而非应用发送
  • 当用户退出浏览器会话时,令牌会过期
  • 刷新令牌:从已登录的浏览器会话中重新提取令牌
  • 所有工作区凭据都存储在
    ~/.config/slackcli/workspaces.json