No description
- Python 69%
- HTML 30.3%
- Dockerfile 0.7%
|
All checks were successful
Docker Publish / build-and-push (push) Successful in 1m34s
|
||
|---|---|---|
| .forgejo/workflows | ||
| .kilocode/rules | ||
| templates | ||
| tests | ||
| .dockerignore | ||
| .env.example | ||
| .gitignore | ||
| app.py | ||
| config.ini.example | ||
| database.py | ||
| docker-compose.yaml | ||
| Dockerfile | ||
| logging_config.py | ||
| morgonslack.py | ||
| pyproject.toml | ||
| README.md | ||
| TECH.md | ||
| uv.lock | ||
MorgonSlack
A Python script that posts messages to the most active Slack thread of the day, helping you join the morning conversation without starting a new thread.
Features
- Automatically finds the most active Slack thread from today
- Posts your message as a reply to that thread
- Falls back to posting a new message if no active threads are found
- Uses browser-based authentication (no admin app approval needed)
Installation
Prerequisites
- Python 3.11+
- uv (Python package manager)
- Dependencies are managed via
pyproject.toml
Setup
-
Install dependencies:
uv sync -
Set up configuration:
# Create config directory mkdir -p ~/.config/morgonslack # Copy the example config file cp config.ini.example ~/.config/morgonslack/config.ini # Edit the config file with your credentials nano ~/.config/morgonslack/config.ini
Docker Deployment
For containerized deployment using Docker and docker-compose.
Prerequisites
- Docker and docker-compose installed
- Slack credentials (token, cookie, channel)
Setup
-
Create environment file:
# Create .env file in project root touch .env -
Configure environment variables in
.env:SLACK_TOKEN=xoxc-your-token-here SLACK_COOKIE=xoxd-your-cookie-here SLACK_CHANNEL=#your-channel
Build and Run
# Build the image
docker-compose build
# Run with environment variables
docker-compose up -d
# View logs
docker-compose logs -f
# Stop the service
docker-compose down
The Flask application will be available at http://localhost:5000 with web endpoints for posting WFH/WFO messages.
Configuration
The configuration file is located at ~/.config/morgonslack/config.ini
Config File Format
[slack]
# Client token (starts with 'xoxc-')
# Found in browser developer tools when logged into Slack
token = xoxc-your-token-here
# Session cookie value (the 'd' cookie)
# This authenticates the token. It looks like "xoxd-..." or a long hex string.
# To find it: In browser developer tools, go to Application > Cookies,
# find the 'd' cookie and copy its value (without the "d=" prefix).
cookie = xoxd-your-cookie-here
# Channel to post to
# You can use the channel name (e.g. #general) or the channel ID.
# To find channel ID: In Slack, right-click channel name > Copy link,
# the ID is the part after "channel/" in the URL.
channel = #your-channel
How to Get Your Slack Credentials
-
Token:
- Open Slack in your browser
- Open Developer Tools (F12 or Ctrl+Shift+I)
- Go to the Network tab
- Refresh the page and look for API calls
- Find the Authorization header - it contains your token
-
Cookie:
- In Developer Tools, go to Application > Cookies
- Find the cookie named "d"
- Copy the value (not including "d=")
Usage
Command Line
# Post a message to the most active thread
uv run python morgonslack.py "Good Morning, WFH"
# Post a different message
uv run python morgonslack.py "Working from office today"
# Post a longer message
uv run python morgonslack.py "Good morning everyone! Starting my day with some coffee and code."
Web Interface
When running with Docker, access the web interface at http://localhost:5000:
- Visit
/for the main interface to post WFH/WFO messages - Visit
/statsto view statistics and analytics of your WFH/WFO patterns - Visit
/wfhto post a random WFH message - Visit
/wfoto post a random WFO message
How It Works
- The script loads your Slack credentials from
~/.config/morgonslack/config.ini - It retrieves all messages from today in your specified channel
- It finds the message with the most replies (most active thread)
- If a thread is found, it posts your message as a reply to that thread
- If no active threads are found, it posts your message as a new message
Error Handling
- Missing config file: The script will exit with a helpful error message pointing you to create the config file
- Invalid credentials: If your token or cookie is invalid/expired, the script will show an authentication error
- Network issues: Any network problems will be displayed with details
Security
- Never commit your config.ini file - it contains sensitive credentials
- The config.ini file is already in .gitignore to prevent accidental commits
- Use browser-based authentication to avoid needing admin app approval
Troubleshooting
"invalid_auth" error
- Your token or cookie may be expired
- Try logging out and back into Slack in your browser
- Update your credentials in the config file
No active threads found
- Make sure you're using the correct channel name/ID
- Check that there are actually threaded conversations in your channel today
- The script only looks at messages from the current day (00:00:00 onwards)
License
This project is open source and available for personal use.