Skip to content

๐Ÿš€ slackAgent: Your AI-powered Slack assistant! Built with LlamaIndex, ChromaDB, and OpenAI embeddings, it delivers instant answers from your documents via a sleek Slack bot or Streamlit web UI. Automate workflows with n8n, expose local APIs with ngrok, and query with ease using FastAPI. Join the future of intelligent chatbots! ๐Ÿค–๐Ÿ’ฌ

Notifications You must be signed in to change notification settings

shivangsingh26/slackAgent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

13 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ slackAgent

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. โœจ


๐ŸŽ‰ Features

  • 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.

๐Ÿ“‚ Project Structure

  • 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. ๐Ÿ“„

๐Ÿ› ๏ธ Setup Instructions

๐Ÿ“‹ Prerequisites

  • Python >= 3.9 ๐Ÿ
  • Slack account + workspace
  • n8n account
  • ngrok account
  • OpenAI API key

โšก๏ธ Installation

  1. Clone the Repo ๐Ÿ“ฅ

    git clone https://github.com/shivangsingh26/slackAgent.git
    cd slackAgent
  2. Set Up Virtual Environment ๐ŸŒ

    python3 -m venv venvSlackAgent
    source venvSlackAgent/bin/activate
  3. Install Dependencies ๐Ÿ“ฆ

    pip install -r requirements.txt
  4. Configure Environment ๐Ÿ”ง

    • Create a .env file:
      OPENAI_API_KEY=your-openai-api-key
      DOCUMENTATION_DIR=./documentation
      STORAGE_DIR=./storage
      
  5. Add Documents ๐Ÿ“

    • Place files in the documentation/ folder.
  6. Generate Embeddings ๐Ÿง 

    • Run app.py to index documents:
      python3 app.py
  7. Run FastAPI Backend ๐Ÿš€

    • Start the server:
      uvicorn main:app --reload
  8. 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:
      1. Sign up at ngrok.com for an authtoken.
      2. Authenticate ngrok:
        ngrok authtoken <your-ngrok-authtoken>
      3. Run ngrok (default port 8000, adjust if needed):
        ngrok http http://localhost:8000
      4. Copy the ngrok URL (e.g., https://<random>.ngrok.io).

๐Ÿค Slack API Setup

The Slack API lets your bot read/post messages and automate tasks. The Events API sends payloads when events (e.g., messages) happen. ๐ŸŽ‰

  1. Create a Slack app at api.slack.com. ๐Ÿ› ๏ธ
  2. 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.
  3. Enable Event Subscriptions with your ngrok URL (e.g., https://<random>.ngrok.io/slack/events). ๐Ÿ”—
  4. Subscribe to bot events:
    • message.channels ๐Ÿ“ข: Triggers on public channel messages.
    • message.im ๐Ÿ’Œ: Triggers on direct messages.
  5. 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.
  6. Add the bot (slackAgentApp) to your Slack workspace. ๐Ÿค–

โš™๏ธ n8n Workflow Setup

Automate with n8n! ๐Ÿ› ๏ธ Visualize the workflow:

Excalidraw Workflow n8n Workflow

  1. Create an n8n workflow with these nodes:
    • Webhook ๐ŸŒ: Captures Slack events and verifies challenges.
    • Set Node ๐Ÿ“: Extracts user_query and channel_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.
  2. Authenticate the Slack node with your workspace. ๐Ÿ”‘
  3. Run the workflow and test with a Slack query (e.g., @slackAgentApp how to install dependencies). ๐Ÿš€

๐ŸŒ Streamlit UI Setup (Alternative)

Skip Slack and use a web interface! ๐ŸŒ Check out the UI:

Streamlit UI

  1. 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.
  2. Run the Streamlit app:
    streamlit run chatbot_frontend.py

๐ŸŽฅ Demo

See slackAgent in action! ๐Ÿš€

Demo


๐ŸŽฎ Usage

Chat with the bot in Slack or use the Streamlit UI! ๐Ÿ’ฌ

Slack Bot Interaction On Channel Slack Bot Interaction On DM

  • Slack: Ping the bot (e.g., @slackAgentApp how to install dependencies).
  • Streamlit: Open the web UI, type a query, and get answers! ๐ŸŒ

๐Ÿงช Example

Slack Query:

@slackAgentApp How do I install dependencies?

Response:

Run `pip install -r requirements.txt` in your virtual environment. ๐Ÿ“ฆ

๐Ÿง  Technical Details

  • Document Indexing (app.py):
    • Loads files from documentation/ with SimpleDirectoryReader. ๐Ÿ“„
    • Creates OpenAI embeddings via VectorStoreIndex. ๐Ÿง 
    • Stores in ChromaDB at storage/developer_documents_collection. ๐Ÿ’พ
  • Query Handling (main.py):
    • FastAPI /query endpoint processes questions. ๐Ÿš€
    • Uses precomputed index from storage/ for fast responses. โšก

๐Ÿค Contributing

Love slackAgent? Contribute! ๐Ÿ™Œ Open an issue or submit a pull request to make it even better. ๐ŸŒŸ

About

๐Ÿš€ slackAgent: Your AI-powered Slack assistant! Built with LlamaIndex, ChromaDB, and OpenAI embeddings, it delivers instant answers from your documents via a sleek Slack bot or Streamlit web UI. Automate workflows with n8n, expose local APIs with ngrok, and query with ease using FastAPI. Join the future of intelligent chatbots! ๐Ÿค–๐Ÿ’ฌ

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages