- Add interactive chat mode with persistent configuration storage - Implement real-time message receiving with polling mechanism - Add threading support for simultaneous send/receive operations - Create MessageReceiver class for handling incoming messages - Add commands: /listen, /stop, /history for two-way communication - Display sent messages in terminal with timestamps - Support for environment variables and .env file loading - Enhanced error handling and user-friendly prompts - Update README with comprehensive two-way communication documentation - Maintain backward compatibility with original CLI functionality |
||
|---|---|---|
| .. | ||
| .env | ||
| env_template.txt | ||
| README.md | ||
| requirements.txt | ||
| slack_poster.py | ||
Slack Two-Way Chat CLI
A powerful command-line tool for two-way communication with Slack channels. Send and receive messages in real-time with both CLI and interactive chat modes.
Installation
- Install dependencies:
pip install -r requirements.txt
Usage
Interactive Two-Way Chat Mode (Recommended)
Start an interactive chat session where you can send and receive messages:
python slack_poster.py --chat
python slack_poster.py -i
In chat mode, you can:
- Type messages directly to send them to Slack
- Use
/listento start receiving messages from others in real-time - View message history with
/history - Use commands to manage your configuration
- Have your token and channel ID automatically saved for future sessions
Command Line Mode
Send a single message using command line arguments:
python slack_poster.py --token <SLACK_TOKEN> --channel <CHANNEL_ID> --message "<MESSAGE>"
Interactive CLI Mode
If any parameter is missing, the tool will prompt you interactively:
python slack_poster.py
Examples
# Interactive chat mode
python slack_poster.py --chat
# Single message via CLI
python slack_poster.py -t xoxb-1234567890-1234567890-abcdefghijklmnopqrstuvwx -c C04ABC123 -m "Hello World!"
# CLI with prompts for missing parameters
python slack_poster.py
Parameters
--tokenor-t: Slack Bot/User OAuth token (e.g., xoxb-...)--channelor-c: Slack channel ID (e.g., C04ABC123)--messageor-m: Message text to post--chator-ior--interactive: Start interactive chat mode
Interactive Chat Commands
When in chat mode, you can use the following commands:
/helpor/h- Show help message with all available commands/quitor/qor/exit- Exit the chat/token <token>- Set or update your Slack token/channel <id>- Set or update the channel ID/status- Show current configuration (token and channel)/clear- Clear all saved configuration/test- Send a test message to verify your configuration/listen- Start listening for incoming messages in real-time/stop- Stop listening for messages/history [n]- Show recent message history (default: 10 messages)<message>- Send any text as a message to the current channel
Two-Way Communication Features
The tool now supports full two-way communication with Slack channels:
Real-Time Message Receiving
- Use
/listento start receiving messages from others in the channel - Messages appear automatically with timestamps and sender names
- Polls for new messages every 2 seconds for near real-time experience
- Use
/stopto stop listening when needed
Message History
- Use
/historyto view recent messages in the channel - Specify number of messages:
/history 20(default: 10, max: 50) - Shows messages with timestamps and sender information
Threading Support
- Send and receive messages simultaneously
- Background thread handles incoming messages
- Clean shutdown when exiting the application
Configuration Storage
The tool automatically saves your Slack token and channel ID to slack_config.json in the current directory. This allows you to:
- Skip entering credentials on subsequent runs
- Switch between different tokens/channels using commands
- Maintain persistent configuration across sessions
Error Handling
The tool handles various error scenarios:
- Invalid token
- Channel not found
- Bot not in channel
- Rate limiting
- Network issues
- Empty messages
Getting Slack Credentials
- Go to https://api.slack.com/apps
- Create a new app or select existing one
- Go to "OAuth & Permissions"
- Add the following scopes:
chat:write- Send messageschannels:history- Read channel messagesgroups:history- Read private channel messagesim:history- Read direct messagesmpim:history- Read group direct messagesusers:read- Get user information
- Install the app to your workspace
- Copy the Bot User OAuth Token (starts with
xoxb-)
Channel ID
To get a channel ID:
- Open Slack in your browser
- Navigate to the channel
- The channel ID is in the URL:
https://app.slack.com/client/T1234567890/C04ABC123 - Use the part after
/C(e.g.,C04ABC123)