slack-automation

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Slack Automation

Slack自动化

Overview

概述

Interact with Slack workspaces for channel management, message reading, and content analysis. All operations are read-only unless creating channels.
与Slack工作区进行交互,实现频道管理、消息读取和内容分析。除非创建频道,否则所有操作均为只读。

Quick Decision Tree

快速决策树

What do you need?
├── Search for channels by name
│   └── references/search.md
│   └── Script: scripts/slack_search.py search
├── Read messages from a channel
│   └── references/fetch-news.md
│   └── Script: scripts/fetch_slack_news.py
├── Create a new channel
│   └── references/create-channel.md
│   └── Script: scripts/create_slack_channel.py
└── Categorize/analyze messages
    └── references/categorize.md
    └── Script: scripts/categorize_slack_messages.py
你需要什么功能?
├── 按名称搜索频道
│   └── 参考文档:references/search.md
│   └── 脚本:scripts/slack_search.py search
├── 读取频道消息
│   └── 参考文档:references/fetch-news.md
│   └── 脚本:scripts/fetch_slack_news.py
├── 创建新频道
│   └── 参考文档:references/create-channel.md
│   └── 脚本:scripts/create_slack_channel.py
└── 消息分类/分析
    └── 参考文档:references/categorize.md
    └── 脚本:scripts/categorize_slack_messages.py

Environment Setup

环境配置

bash
undefined
bash
undefined

Required in .env

需在.env文件中配置

SLACK_BOT_TOKEN=xoxb-your-bot-token
undefined
SLACK_BOT_TOKEN=xoxb-your-bot-token
undefined

Required Bot Scopes

所需Bot权限范围

ScopePurpose
channels:read
List public channels
channels:history
Read public channel messages
groups:read
List private channels
groups:history
Read private channel messages
channels:manage
Create channels
权限范围用途
channels:read
列出公开频道
channels:history
读取公开频道消息
groups:read
列出私有频道
groups:history
读取私有频道消息
channels:manage
创建频道

Common Usage

常用操作

Search Channels

搜索频道

bash
python scripts/slack_search.py search "internal" --limit 10
bash
python scripts/slack_search.py search "internal" --limit 10

Read Channel Messages

读取频道消息

bash
python scripts/slack_search.py read "internal-client" --days 7
bash
python scripts/slack_search.py read "internal-client" --days 7

Create Channel

创建频道

bash
python scripts/create_slack_channel.py "project-alpha" --private
bash
python scripts/create_slack_channel.py "project-alpha" --private

Channel Naming Pattern

频道命名规范

For client channels:
internal-{client-name}
  • e.g.,
    internal-microsoft
    ,
    internal-acme-corp
客户频道命名格式:
internal-{client-name}
  • 示例:
    internal-microsoft
    ,
    internal-acme-corp

Cost

成本

Free - Slack API has no per-request cost. Rate limited to ~50 requests/minute.
免费 - Slack API无单次请求费用,速率限制约为每分钟50次请求。

Security Notes

安全注意事项

Credential Handling

凭证处理

  • Store
    SLACK_BOT_TOKEN
    in
    .env
    file (never commit to git)
  • Bot tokens start with
    xoxb-
    - never expose in logs or output
  • Rotate tokens via Slack App settings if compromised
  • Use environment variables, not hardcoded values
  • SLACK_BOT_TOKEN
    存储在.env文件中(绝不要提交到git)
  • Bot令牌以
    xoxb-
    开头 - 绝不要在日志或输出中暴露
  • 如果令牌泄露,通过Slack应用设置轮换令牌
  • 使用环境变量,不要硬编码值

Data Privacy

数据隐私

  • Messages may contain sensitive internal communications
  • Avoid storing message content in persistent logs
  • Use message links/IDs for references instead of copying content
  • Consider data retention policies for exported messages
  • User profiles include PII (names, emails, profile photos)
  • 消息可能包含敏感的内部通信内容
  • 避免将消息内容存储在持久化日志中
  • 使用消息链接/ID作为引用,而非复制内容
  • 考虑导出消息的数据保留策略
  • 用户资料包含个人身份信息(姓名、邮箱、头像)

Access Scopes

访问权限范围

  • Request minimum required scopes for your use case:
    • channels:read
      - List public channels (read-only)
    • channels:history
      - Read public channel messages (read-only)
    • groups:read
      - List private channels bot is in (read-only)
    • groups:history
      - Read private channel messages (read-only)
    • channels:manage
      - Create channels (write access)
  • Bot can only access channels it has been invited to
  • Review scopes at: Slack App Settings > OAuth & Permissions
  • 根据你的使用场景请求最小必要权限:
    • channels:read
      - 列出公开频道(只读)
    • channels:history
      - 读取公开频道消息(只读)
    • groups:read
      - 列出Bot已加入的私有频道(只读)
    • groups:history
      - 读取私有频道消息(只读)
    • channels:manage
      - 创建频道(写入权限)
  • Bot只能访问已被邀请加入的频道
  • 在Slack应用设置 > OAuth与权限中查看权限范围

Compliance Considerations

合规性考量

  • Audit Logging: Slack Enterprise Grid provides audit logs for compliance
  • Message Retention: Follow your organization's data retention policies
  • GDPR: Message content may contain EU user PII
  • eDiscovery: Exported messages may be subject to legal holds
  • Internal Communications: Treat Slack data as confidential
  • Channel Privacy: Private channel access requires explicit invitation
  • 审计日志:Slack Enterprise Grid提供审计日志以满足合规要求
  • 消息保留:遵循组织的数据保留策略
  • GDPR:消息内容可能包含欧盟用户的个人身份信息
  • 电子取证:导出的消息可能需遵守法律保全要求
  • 内部通信:将Slack数据视为机密信息
  • 频道隐私:访问私有频道需要明确邀请

Troubleshooting

故障排查

Common Issues

常见问题

Issue: Channel not found

问题:频道未找到

Symptoms: "channel_not_found" error when reading or posting Cause: Invalid channel ID, bot not in channel, or private channel Solution:
  • Verify channel ID is correct (use
    slack_search.py search
    )
  • Invite the bot to the channel (
    /invite @botname
    )
  • Check if channel is private - bot needs explicit invitation
  • Ensure channel hasn't been archived or deleted
症状:读取或发布时出现"channel_not_found"错误 原因:频道ID无效、Bot未加入频道,或频道为私有频道 解决方案
  • 验证频道ID是否正确(使用
    slack_search.py search
  • 将Bot邀请到频道(
    /invite @botname
  • 检查频道是否为私有频道 - Bot需要明确邀请才能加入
  • 确认频道未被归档或删除

Issue: Missing permissions / scope errors

问题:权限缺失/权限范围错误

Symptoms: "missing_scope" or "not_allowed_token_type" error Cause: Bot token missing required OAuth scopes Solution:
  • Go to Slack App Settings > OAuth & Permissions
  • Add required scopes:
    channels:read
    ,
    channels:history
    , etc.
  • Reinstall the app to workspace after adding scopes
  • Verify using the correct bot token (starts with
    xoxb-
    )
症状:出现"missing_scope"或"not_allowed_token_type"错误 原因:Bot令牌缺少所需的OAuth权限范围 解决方案
  • 进入Slack应用设置 > OAuth与权限
  • 添加所需权限范围:
    channels:read
    channels:history
  • 添加权限范围后重新将应用安装到工作区
  • 验证使用的是正确的Bot令牌(以
    xoxb-
    开头)

Issue: Token expired or invalid

问题:令牌过期或无效

Symptoms: "invalid_auth" or "token_revoked" error Cause: OAuth token expired, revoked, or incorrectly configured Solution:
  • Reauthorize the bot in Slack App settings
  • Regenerate the bot token if revoked
  • Check
    .env
    for correct
    SLACK_BOT_TOKEN
    value
  • Verify no whitespace or special characters in token
症状:出现"invalid_auth"或"token_revoked"错误 原因:OAuth令牌过期、被撤销,或配置错误 解决方案
  • 在Slack应用设置中重新授权Bot
  • 如果令牌被撤销,重新生成Bot令牌
  • 检查.env文件中的
    SLACK_BOT_TOKEN
    值是否正确
  • 验证令牌中无空格或特殊字符

Issue: Rate limited

问题:触发速率限制

Symptoms: "ratelimited" error or 429 status code Cause: Too many API requests in short period Solution:
  • Add delays between requests (1-2 seconds)
  • Reduce batch size for bulk operations
  • Implement exponential backoff on retries
  • Slack allows ~50 requests/minute for most endpoints
症状:出现"ratelimited"错误或429状态码 原因:短时间内发送了过多API请求 解决方案
  • 在请求之间添加延迟(1-2秒)
  • 减少批量操作的批次大小
  • 在重试时实现指数退避策略
  • Slack大多数端点允许每分钟约50次请求

Issue: Private channel access denied

问题:私有频道访问被拒绝

Symptoms: Can't read private channel despite having scopes Cause: Bot not added to the private channel Solution:
  • Have a channel member invite the bot:
    /invite @botname
  • Ensure
    groups:read
    and
    groups:history
    scopes are added
  • Verify bot has been reinstalled after adding scopes
症状:即使拥有权限范围,仍无法读取私有频道 原因:Bot未被添加到私有频道 解决方案
  • 由频道成员邀请Bot:
    /invite @botname
  • 确保已添加
    groups:read
    groups:history
    权限范围
  • 确认添加权限范围后已重新安装Bot

Resources

资源

  • references/search.md - Channel search and message reading
  • references/fetch-news.md - Fetch news from channels
  • references/create-channel.md - Create new channels
  • references/categorize.md - AI message categorization
  • references/search.md - 频道搜索与消息读取
  • references/fetch-news.md - 从频道获取资讯
  • references/create-channel.md - 创建新频道
  • references/categorize.md - AI消息分类

Integration Patterns

集成模式

Slack to Newsletter

Slack转新闻通讯

Skills: slack-automation → content-generation Use case: Summarize internal news for weekly newsletter Flow:
  1. Fetch messages from news/announcements channels
  2. Categorize and filter relevant content
  3. Generate formatted newsletter section via content-generation
技能:slack-automation → content-generation 使用场景:汇总内部资讯用于每周新闻通讯 流程
  1. 从新闻/公告频道获取消息
  2. 分类并筛选相关内容
  3. 通过content-generation生成格式化的新闻通讯板块

Slack and Meeting Context

Slack与会议上下文

Skills: slack-automation → transcript-search Use case: Find related meetings when researching Slack discussions Flow:
  1. Search Slack for client name or topic
  2. Extract date ranges and participant names
  3. Search transcript-search for related meeting recordings
技能:slack-automation → transcript-search 使用场景:研究Slack讨论时查找相关会议 流程
  1. 在Slack中搜索客户名称或主题
  2. 提取日期范围和参与者姓名
  3. 通过transcript-search搜索相关会议录音

Slack Reports to Drive

Slack报告同步到云端硬盘

Skills: slack-automation → google-workspace Use case: Archive categorized Slack summaries to Google Drive Flow:
  1. Fetch and categorize messages from internal channels
  2. Generate formatted report document
  3. Upload to Google Drive via google-workspace
技能:slack-automation → google-workspace 使用场景:将分类后的Slack摘要归档到Google云端硬盘 流程
  1. 获取并分类内部频道的消息
  2. 生成格式化的报告文档
  3. 通过google-workspace上传到Google云端硬盘