-
Security: Never commit the
.envfile to version control. Ensure it's listed in your.gitignorefile to prevent accidental exposure of sensitive information. -
Slack Bot Configuration: This SlackBot operates in Socket Mode. Make sure your Slack app is configured to use Socket Mode in the Slack API dashboard. When generating the
SLACK_APP_TOKEN, select the Socket Mode option.
This SlackBot leverages OpenAI API and LangChain to provide intelligent responses within Slack. Key features include:
-
Intelligent Thread Management:
- Automatically preserves conversation context within Slack threads
- Understands the full thread history for more contextual responses
- Seamlessly handles multiple concurrent conversations
-
Advanced AI Integration:
- Powered by OpenAI's language models
- Multiple specialized tools for different tasks:
- Web Search: Access to current information
- Vector Search: Query internal documents and guidelines
-
Performance Optimized:
- Efficient thread history management using Slack API
- Configurable timeouts and retry mechanisms
- Detailed logging for monitoring and debugging
-
Easy Setup:
- Simple configuration through environment variables
- Docker support for easy deployment
- Flexible tool enabling/disabling
app_mentions:read
channels:history
chat:write
groups:history
im:history
im:read
im:write
app_mention
message.groups
message.im
You can run the project using either pipenv or Docker (recommended).
Create a .env file in the project root directory and add the following environment variables:
Refer to .env.dev for guidance.
# Environment
ENVIRONMENT=dev
DEBUG=false # Enable detailed error messages
# OpenAI API
MODEL_NAME=gpt-4 # Or gpt-3.5-turbo
OPENAI_API_KEY=your_openai_api_key
MODEL_TEMPERATURE=0 # 0-1, lower for more focused responses
MODEL_TIMEOUT=30 # Seconds
MAX_AGENT_ITERATIONS=3
# Slack
SLACK_APP_TOKEN=your_slack_app_token
SLACK_BOT_TOKEN=your_slack_bot_token
SLACK_BOT_ID=your_slack_bot_id
API_TIMEOUT=60 # Slack API timeout
# Vector Store Configuration
VECTOR_STORE_PATH=./vector_store
VECTOR_CHUNK_SIZE=100
VECTOR_CHUNK_OVERLAP=20
VECTOR_DOC_PATH=./vector_file/sample.txt
# Tools Configuration
ENABLE_SEARCH=true
ENABLE_VECTOR=true
# Langsmith (Optional)
LANGCHAIN_TRACING_V2=true
LANGCHAIN_API_KEY=your_langsmith_api_key
LANGCHAIN_PROJECT=your_project_name
LANGCHAIN_ENDPOINT=https://api.smith.langchain.com-
Install pipenv:
pip install pipenv -
Clone the repository:
git clone https://github.com/02tYasui/slackbot.git
cd slackbot- Install project dependencies using pipenv:
pipenv install- Activate pipenv environment:
pipenv shell- Run the SlackBot:
python src/app.py- Clone the repository:
git clone https://github.com/02tYasui/slackbot.git
cd slackbot- Build and run Docker container:
docker compose up --buildThe bot uses the following components:
-
Slack Integration:
- Socket Mode for real-time communication
- Thread history tracking for context awareness
- Automatic mention detection and response
-
Language Model:
- OpenAI's GPT models for natural language processing
- Configurable temperature and timeout settings
- Error handling and retry mechanisms
-
Tools:
- Web Search: DuckDuckGo integration for current information
- Vector Search: Document retrieval using ChromaDB
- Customizable tool configuration via environment variables
-
Logging and Monitoring:
- Detailed logging with file and line information
- Performance metrics tracking
- Debug mode for development
The bot includes comprehensive error handling:
- API timeouts and retry logic
- Invalid input detection
- Detailed error logging
- User-friendly error messages
- Debug mode for development
Contributions are welcome! Please feel free to submit a Pull Request.