File size: 3,215 Bytes
5fd100c
 
 
 
 
 
 
 
 
 
 
 
005a292
 
c6a2a56
 
 
 
 
6532466
005a292
6532466
 
 
 
 
c6a2a56
 
 
 
005a292
 
 
 
 
 
64566ca
005a292
 
 
 
 
 
 
 
 
64566ca
005a292
c6a2a56
 
6532466
 
 
 
 
 
 
b9c8796
 
 
 
 
 
 
 
 
 
 
 
6532466
 
 
 
 
 
 
 
 
 
64566ca
 
6532466
 
 
 
 
 
 
 
 
 
 
 
 
64566ca
 
6532466
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
---
title: CTP Slack Bot
emoji: 🦥
colorFrom: indigo
colorTo: indigo
sdk: docker
pinned: false
short_description: Spring 2025 CTP Slack Bot RAG system
---



# CTP Slack Bot

## _Modus Operandi_ in a Nutshell

* Intelligently responds to Slack messages based on a repository of data.
* Periodically checks for new content to add to its repository.

## Tech Stack

* Hugging Face Spaces for hosting and serverless API
* Google Drive for reference data (i.e., the material to be incorporated into the bot’s knowledge base)
* MongoDB for data persistence
* Docker for containerization
* Python
    * FastAPI for serving HTTP requests
    * httpx for making HTTP requests
    * APScheduler for running periodic tasks in the background
    * See `pyproject.toml` for additional Python packages.

## General Project Structure

* `src/`
    * `ctp_slack_bot/`
        * `api/`: FastAPI application structure
            * `routes.py`: API endpoint definitions
        * `core/`: fundamental components like configuration (using pydantic), logging setup (loguru), and custom exceptions
        * `db/`: database connection
            * `repositories/`: repository pattern implementation
        * `models/`: Pydantic models for data validation and serialization
        * `services/`: business logic
        * `tasks/`: background scheduled jobs
        * `utils/`: reusable utilities
* `tests/`: unit tests
* `scripts/`: utility scripts for development, deployment, etc.
    * `run-dev.sh`: script to run the application locally
* `notebooks/`: Jupyter notebooks for exploration and model development
* `.env`: local environment variables for development purposes (to be created for local use only from `.env.template`)
* `Dockerfile`: Docker container build definition

## How to Run the Application

### Normally

Just run the Docker image. 😉

Build it with:

```sh
docker build . -t ctp-slack-bot
```

Run it with:

```sh
docker run --env-file=.env -p 8000:8000 --name my-ctp-slack-bot-instance ctp-slack-bot
```

### For Development

Development usually requires rapid iteration. That means a change in the code ought to be reflected as soon as possible in the behavior of the application.

First, make sure you are set up with a Python virtual environment created by the Python `venv` module and that it’s activated. Then install dependencies from `pyproject.toml` within the environment using:

```sh
pip3 install -e .
```

Make a copy of `.env.template` as `.env` and define the environment variables. (You can also define them by other means, but this has the least friction.) This file should not be committed and is excluded by `.gitignore`!

If `localhost` port `8000` is free, running the following will make the application available on that port:

```sh
scripts/run-dev.sh
```

You can check that it’s reachable by visiting [http://localhost:8000/health](http://localhost:8000/health).

```text
$ curl http://localhost:8000/health
{"status":"healthy"}
```

In debug mode (`DEBUG=true`), [http://localhost:8000/env](http://localhost:8000/env) will pretty-print the non-sensitive environment variables as JSON.

Uvicorn will restart the application automatically when any source files are changed.