Slai - Slack CLI Messenger
Send Slack messages from the command line. Configured globally, works from any directory.
Prerequisites
The slai CLI must be installed and configured:
bash
# Check if installed slai --help # If not installed, build from source cd ~/user/Projects/slack-sender ./update.sh
Configuration
Slai uses global configuration stored at:
- •macOS:
~/Library/Application Support/slai/config.toml - •Linux:
~/.config/slai/config.toml
Initial Setup
bash
# Initialize with token and default channel slai init -t "xoxp-your-token" -c "#channel-or-user-id" # Or initialize empty and set values later slai init slai config -t "xoxp-your-token" slai config -c "#default-channel"
View/Update Config
bash
# Show current config (token is masked) slai config --show # Update token slai config -t "xoxp-new-token" # Update default channel slai config -c "#new-channel"
Commands
Send a Message
bash
# Send to default channel slai send -m "Hello world!" # Send to specific channel (override default) slai send -m "Alert!" -c "#alerts" # Send DM to user (use user ID) slai send -m "Hey!" -c "U01XXXXXXXX" # Multi-line message slai send -m "Line 1 Line 2 Line 3"
Channel Formats
| Format | Example | Description |
|---|---|---|
| Channel name | #general | Public channel by name |
| Channel ID | C01234567 | Channel by Slack ID |
| User ID | U01234567 | DM to user |
Finding IDs:
- •Channel ID: Right-click channel → "View channel details" → ID at bottom
- •User ID: Click profile → "⋮" → "Copy member ID"
Common Use Cases
Deployment Notification
bash
slai send -m "Deployed v1.2.3 to production"
Script Integration
bash
#!/bin/bash set -e ./deploy.sh slai send -m "✅ Deployment successful at $(date)"
Error Alerting
bash
if ! ./build.sh; then
slai send -m "❌ Build failed!" -c "#alerts"
exit 1
fi
Git Hook (post-push)
bash
#!/bin/bash BRANCH=$(git rev-parse --abbrev-ref HEAD) slai send -m "Pushed to $BRANCH"
Troubleshooting
| Error | Solution |
|---|---|
No config found | Run slai init |
No token configured | Run slai config -t "xoxp-..." |
No channel specified | Use -c flag or set default with slai config -c "#channel" |
channel_not_found | Verify channel name/ID, ensure you're a member |
invalid_auth | Token expired or revoked, get new token |
Getting a Slack Token
- •Go to https://api.slack.com/apps
- •Create New App → From scratch
- •OAuth & Permissions → Add
chat:writeto User Token Scopes - •Install to Workspace
- •Copy User OAuth Token (starts with
xoxp-)