| .. | ||
| .env | ||
| .env.example | ||
| env_template.txt | ||
| README.md | ||
| requirements.txt | ||
| slack_poster.py | ||
Slack AI-Powered Two-Way Chat CLI
A powerful command-line tool for AI-powered two-way communication with Slack channels. Send and receive messages in real-time with intelligent question-answering capabilities using Perplexity AI.
Installation
- Install dependencies:
pip install -r requirements.txt
Usage
Interactive AI-Powered Two-Way Chat Mode (Recommended)
Start an interactive chat session where you can send and receive messages with AI-powered question answering:
python slack_poster.py --chat
python slack_poster.py -i
In chat mode, you can:
- Type messages directly to send them to Slack
- Ask questions and get AI-powered answers automatically
- Use
/listento start receiving messages from others in real-time - View message history with
/history - Use commands to manage your configuration
- Have your token, channel ID, and Perplexity API key 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/perplexity <key>- Set or update your Perplexity API key/status- Show current configuration (token, channel, and AI settings)/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)/ai on/off- Enable or disable AI responses<message>- Send any text as a message to the current channel
AI-Powered Question Answering Features
The tool now includes intelligent question-answering capabilities using Perplexity AI:
Automatic Question Detection
- AI automatically detects when you ask questions
- Supports various question formats: "What is...?", "How do...?", "Why...?", etc.
- Responds with intelligent, accurate answers
AI Response Examples
> What is the capital of India?
[14:30:15] You: What is the capital of India?
[OK] Message sent to #C09JKHXS9L3
[AI] Thinking...
[14:30:18] AI Bot: The capital of India is New Delhi.
[OK] AI response sent to #C09JKHXS9L3
AI Configuration
- Use
/perplexity <your-api-key>to set your Perplexity API key - Use
/ai onto enable automatic AI responses - Use
/ai offto disable AI responses - AI responses are sent to the Slack channel with 🤖 AI: prefix
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 API Credentials
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-)
Perplexity AI Credentials
- Go to https://www.perplexity.ai/
- Sign up for an account
- Go to your account settings or API section
- Generate an API key
- Copy the API key (starts with
pplx-) - Use
/perplexity <your-api-key>in the chat to set it
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)