slackAgent is an AI-powered Slack bot that answers your questions using a LlamaIndex and ChromaDB vector database! ๐ค It chats via Slack API, automates workflows with n8n, and offers a sleek Streamlit web UI. Powered by OpenAI embeddings and FastAPI, it delivers smart document retrieval with ease. โจ
- Slack Chat ๐ฌ: Answers queries in Slack channels or DMs.
- AI Search ๐: Queries documents with LlamaIndex and ChromaDB.
- Automation โ๏ธ: Streamlines tasks with n8n workflows.
- Web UI ๐: Query via a user-friendly Streamlit interface.
- Local-to-Web ๐: Exposes APIs using ngrok.
app.py
: Loads docs, creates OpenAI embeddings, stores in ChromaDB. ๐main.py
: FastAPI backend for answering queries. ๐.env
: Holds API keys and directory paths. ๐requirements.txt
: Lists dependencies (e.g.,llama-index
,chromadb
). ๐ฆstorage/
: Stores vector embeddings. ๐พdocumentation/
: Holds documents for indexing. ๐
- Python >= 3.9 ๐
- Slack account + workspace
- n8n account
- ngrok account
- OpenAI API key
-
Clone the Repo ๐ฅ
git clone https://github.com/shivangsingh26/slackAgent.git cd slackAgent
-
Set Up Virtual Environment ๐
python3 -m venv venvSlackAgent source venvSlackAgent/bin/activate
-
Install Dependencies ๐ฆ
pip install -r requirements.txt
-
Configure Environment ๐ง
- Create a
.env
file:OPENAI_API_KEY=your-openai-api-key DOCUMENTATION_DIR=./documentation STORAGE_DIR=./storage
- Create a
-
Add Documents ๐
- Place files in the
documentation/
folder.
- Place files in the
-
Generate Embeddings ๐ง
- Run
app.py
to index documents:python3 app.py
- Run
-
Run FastAPI Backend ๐
- Start the server:
uvicorn main:app --reload
- Start the server:
-
Set Up ngrok ๐
- What is ngrok? Creates a public URL for your local server. ๐
- Why use it? Lets Slack and n8n talk to your FastAPI backend. ๐
- Steps:
- Sign up at ngrok.com for an authtoken.
- Authenticate ngrok:
ngrok authtoken <your-ngrok-authtoken>
- Run ngrok (default port 8000, adjust if needed):
ngrok http http://localhost:8000
- Copy the ngrok URL (e.g.,
https://<random>.ngrok.io
).
The Slack API lets your bot read/post messages and automate tasks. The Events API sends payloads when events (e.g., messages) happen. ๐
- Create a Slack app at api.slack.com. ๐ ๏ธ
- Add these bot token scopes:
app_mentions:read
๐ฃ: Detects@slackAgent
mentions.channels:history
๐: Reads public channel message history.channels:join
๐ช: Joins public channels.channels:read
๐: Accesses public channel details.chat:write
โ๏ธ: Sends messages in channels/DMs.chat:write.public
๐ข: Posts in public channels without joining.commands
โก: Supports custom slash commands.im:history
๐ฌ: Reads DM history.im:write
๐ฉ: Sends DMs.mpim:history
๐ฅ: Reads group DM history.
- Enable Event Subscriptions with your ngrok URL (e.g.,
https://<random>.ngrok.io/slack/events
). ๐ - Subscribe to bot events:
message.channels
๐ข: Triggers on public channel messages.message.im
๐: Triggers on direct messages.
- Verify the setup:
- In n8n, set a webhook node with a challenge field for Slackโs verification.
- Set webhook to "Respond to WebHook" mode, then switch to "Immediately" after verification.
- Add the bot (
slackAgentApp
) to your Slack workspace. ๐ค
Automate with n8n! ๐ ๏ธ Visualize the workflow:
- Create an n8n workflow with these nodes:
- Webhook ๐: Captures Slack events and verifies challenges.
- Set Node ๐: Extracts
user_query
andchannel_id
. - Cleanup Node ๐งน: Removes mentions (e.g.,
@slackAgentApp
). - HTTP Server Node ๐: Sends queries to FastAPI via ngrok.
- Merge Node ๐: Combines query and response into JSON.
- Slack Node ๐ฌ: Sends responses to your Slack workspace.
- Authenticate the Slack node with your workspace. ๐
- Run the workflow and test with a Slack query (e.g.,
@slackAgentApp how to install dependencies
). ๐
Skip Slack and use a web interface! ๐ Check out the UI:
- Create an n8n workflow with:
- Webhook ๐ก: Passes queries from Streamlit to FastAPI.
- HTTP Server Node ๐: Uses ngrok to expose the server.
- Respond to Webhook ๐ค: Formats responses for Streamlit.
- Run the Streamlit app:
streamlit run chatbot_frontend.py
See slackAgent in action! ๐
Chat with the bot in Slack or use the Streamlit UI! ๐ฌ
- Slack: Ping the bot (e.g.,
@slackAgentApp how to install dependencies
). - Streamlit: Open the web UI, type a query, and get answers! ๐
Slack Query:
@slackAgentApp How do I install dependencies?
Response:
Run `pip install -r requirements.txt` in your virtual environment. ๐ฆ
- Document Indexing (
app.py
):- Loads files from
documentation/
withSimpleDirectoryReader
. ๐ - Creates OpenAI embeddings via
VectorStoreIndex
. ๐ง - Stores in ChromaDB at
storage/developer_documents_collection
. ๐พ
- Loads files from
- Query Handling (
main.py
):- FastAPI
/query
endpoint processes questions. ๐ - Uses precomputed index from
storage/
for fast responses. โก
- FastAPI
Love slackAgent? Contribute! ๐ Open an issue or submit a pull request to make it even better. ๐