Summary
Build a uutils/slack_uu.py module for Slack automation — send messages, monitor channels, and receive notifications programmatically.
Motivation
Automate research group communications, experiment notifications, and channel monitoring on Slack (e.g., Stanford research group Slack workspaces).
Proposed Implementation
API
- Slack Web API (official, well-supported)
- Full-featured: send messages, read channels, upload files, react, etc.
- Auth: Bot Token or User Token via Slack App
- Python SDK:
pip install slack-sdk
- Docs: https://api.slack.com/methods
Module structure
class SlackClient:
@classmethod
def from_token(cls, token_file="~/keys/slack_bot_token.txt") -> "SlackClient"
def send_message(self, channel, text, thread_ts=None) -> dict
def upload_file(self, channel, file_path, title="") -> dict
def list_channels(self) -> list[dict]
def get_unread_messages(self, channel) -> list[dict]
def get_channel_history(self, channel, limit=50) -> list[dict]
Use cases
- Experiment notifications: "Training run X finished with accuracy Y"
- Channel monitoring: Check for unread messages in key channels
- File sharing: Upload plots/results to a channel
- Scheduled messages: Daily summaries, reminders
🔐 Secrets & Security
- Bot token stored in
~/keys/slack_bot_token.txt — NEVER in the repo
- Alternatively:
~/keys/slack_credentials.json with workspace + token
.gitignore already excludes credential patterns
- Use bot tokens (xoxb-) with minimal scopes, not user tokens
🧑 Human Interaction Required
- One-time: Create a Slack App at https://api.slack.com/apps (~10 min)
- One-time: Install app to workspace (requires workspace admin approval if restricted)
- One-time: Copy Bot Token to
~/keys/slack_bot_token.txt
- One-time: Invite the bot to relevant channels (
/invite @botname)
💻 Machine Uptime
- Sending messages: does NOT require machine to stay on (one-shot)
- Monitoring channels on a schedule: machine must be on at scheduled time
- Real-time monitoring (websocket): machine must stay on continuously
- Recommendation: use cron for periodic checks, not real-time socket
Tasks
Summary
Build a
uutils/slack_uu.pymodule for Slack automation — send messages, monitor channels, and receive notifications programmatically.Motivation
Automate research group communications, experiment notifications, and channel monitoring on Slack (e.g., Stanford research group Slack workspaces).
Proposed Implementation
API
pip install slack-sdkModule structure
Use cases
🔐 Secrets & Security
~/keys/slack_bot_token.txt— NEVER in the repo~/keys/slack_credentials.jsonwith workspace + token.gitignorealready excludes credential patterns🧑 Human Interaction Required
~/keys/slack_bot_token.txt/invite @botname)💻 Machine Uptime
Tasks
slack_uu.pywith token-based authslack-sdktopyproject.toml