slack-automation
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSlack 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.pyEnvironment Setup
环境配置
bash
undefinedbash
undefinedRequired in .env
需在.env文件中配置
SLACK_BOT_TOKEN=xoxb-your-bot-token
undefinedSLACK_BOT_TOKEN=xoxb-your-bot-token
undefinedRequired Bot Scopes
所需Bot权限范围
| Scope | Purpose |
|---|---|
| List public channels |
| Read public channel messages |
| List private channels |
| Read private channel messages |
| Create channels |
| 权限范围 | 用途 |
|---|---|
| 列出公开频道 |
| 读取公开频道消息 |
| 列出私有频道 |
| 读取私有频道消息 |
| 创建频道 |
Common Usage
常用操作
Search Channels
搜索频道
bash
python scripts/slack_search.py search "internal" --limit 10bash
python scripts/slack_search.py search "internal" --limit 10Read Channel Messages
读取频道消息
bash
python scripts/slack_search.py read "internal-client" --days 7bash
python scripts/slack_search.py read "internal-client" --days 7Create Channel
创建频道
bash
python scripts/create_slack_channel.py "project-alpha" --privatebash
python scripts/create_slack_channel.py "project-alpha" --privateChannel Naming Pattern
频道命名规范
For client channels:
internal-{client-name}- e.g., ,
internal-microsoftinternal-acme-corp
客户频道命名格式:
internal-{client-name}- 示例:,
internal-microsoftinternal-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 in
SLACK_BOT_TOKENfile (never commit to git).env - Bot tokens start with - never expose in logs or output
xoxb- - Rotate tokens via Slack App settings if compromised
- Use environment variables, not hardcoded values
- 将存储在.env文件中(绝不要提交到git)
SLACK_BOT_TOKEN - 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:
- - List public channels (read-only)
channels:read - - Read public channel messages (read-only)
channels:history - - List private channels bot is in (read-only)
groups:read - - Read private channel messages (read-only)
groups:history - - Create channels (write access)
channels:manage
- Bot can only access channels it has been invited to
- Review scopes at: Slack App Settings > OAuth & Permissions
- 根据你的使用场景请求最小必要权限:
- - 列出公开频道(只读)
channels:read - - 读取公开频道消息(只读)
channels:history - - 列出Bot已加入的私有频道(只读)
groups:read - - 读取私有频道消息(只读)
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, etc.channels:history - 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 for correct
.envvalueSLACK_BOT_TOKEN - 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 and
groups:readscopes are addedgroups:history - 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:
- Fetch messages from news/announcements channels
- Categorize and filter relevant content
- Generate formatted newsletter section via content-generation
技能:slack-automation → content-generation
使用场景:汇总内部资讯用于每周新闻通讯
流程:
- 从新闻/公告频道获取消息
- 分类并筛选相关内容
- 通过content-generation生成格式化的新闻通讯板块
Slack and Meeting Context
Slack与会议上下文
Skills: slack-automation → transcript-search
Use case: Find related meetings when researching Slack discussions
Flow:
- Search Slack for client name or topic
- Extract date ranges and participant names
- Search transcript-search for related meeting recordings
技能:slack-automation → transcript-search
使用场景:研究Slack讨论时查找相关会议
流程:
- 在Slack中搜索客户名称或主题
- 提取日期范围和参与者姓名
- 通过transcript-search搜索相关会议录音
Slack Reports to Drive
Slack报告同步到云端硬盘
Skills: slack-automation → google-workspace
Use case: Archive categorized Slack summaries to Google Drive
Flow:
- Fetch and categorize messages from internal channels
- Generate formatted report document
- Upload to Google Drive via google-workspace
技能:slack-automation → google-workspace
使用场景:将分类后的Slack摘要归档到Google云端硬盘
流程:
- 获取并分类内部频道的消息
- 生成格式化的报告文档
- 通过google-workspace上传到Google云端硬盘