Skip to content

Commit 094d4c1

Browse files
authored
Add basic slack bot scaffolding (#21)
1 parent 9b97e77 commit 094d4c1

File tree

10 files changed

+559
-0
lines changed

10 files changed

+559
-0
lines changed

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ process-repo-queue = "aieng_bot_maintain.cli:process_repo_queue_cli"
4242
[tool.hatchling.build.targets.wheel]
4343
packages = ["src/aieng_bot_maintain"]
4444

45+
[tool.hatchling.build.targets.wheel.shared-data]
46+
"src/aieng_bot_maintain/py.typed" = "aieng_bot_maintain/py.typed"
47+
4548
[dependency-groups]
4649
dev = [
4750
"codecov>=2.1.13",
@@ -91,6 +94,7 @@ warn_unused_ignores = true
9194
implicit_reexport = false
9295
strict_equality = true
9396
extra_checks = true
97+
mypy_path = "src:slack_bot/stubs"
9498

9599
[tool.ruff]
96100
include = ["*.py", "pyproject.toml", "*.ipynb"]

slack_bot/.env.example

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Slack Bot Configuration
2+
# Copy this file to .env and fill in your actual tokens and secrets
3+
4+
# Bot User OAuth Token (starts with xoxb-)
5+
SLACK_BOT_TOKEN=xoxb-your-bot-token-here
6+
7+
# App-Level Token for Socket Mode (starts with xapp-)
8+
SLACK_APP_TOKEN=xapp-your-app-level-token-here
9+
10+
# Signing Secret from Basic Information
11+
SLACK_SIGNING_SECRET=your-signing-secret-here

slack_bot/.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Environment variables
2+
.env
3+
4+
# Python
5+
__pycache__/
6+
*.py[cod]
7+
*$py.class
8+
*.so
9+
.Python
10+
11+
# Virtual environments
12+
venv/
13+
env/
14+
ENV/
15+
16+
# IDE
17+
.vscode/
18+
.idea/
19+
*.swp
20+
*.swo
21+
*~
22+
23+
# OS
24+
.DS_Store
25+
Thumbs.db

slack_bot/README.md

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
# AI Engineering Maintenance Bot - Slack Integration
2+
3+
A Slack bot that provides information about the AI Engineering Maintenance Bot through slash commands.
4+
5+
## Features
6+
7+
- `/aieng-bot version` - Display version and metadata information about the bot
8+
- Responds to @mentions with helpful information
9+
- Rich formatted responses with links to repository and dashboard
10+
11+
## Prerequisites
12+
13+
- Python 3.12 or higher
14+
- A Slack workspace where you have permission to install apps
15+
- Access to the Slack API dashboard
16+
17+
## Installation Instructions
18+
19+
### Step 1: Create a Slack App
20+
21+
1. Go to [https://api.slack.com/apps](https://api.slack.com/apps)
22+
2. Click **"Create New App"**
23+
3. Select **"From an app manifest"**
24+
4. Choose your workspace from the dropdown
25+
5. Click **"Next"**
26+
27+
### Step 2: Configure with Manifest
28+
29+
1. Select the **YAML** tab
30+
2. Copy the contents of `manifest.yaml` from this directory
31+
3. Paste it into the text field
32+
4. Click **"Next"**
33+
5. Review the configuration summary
34+
6. Click **"Create"**
35+
36+
### Step 3: Enable Socket Mode
37+
38+
1. In your app settings, go to **"Socket Mode"** in the left sidebar
39+
2. Toggle **"Enable Socket Mode"** to **On**
40+
3. You'll be prompted to create an app-level token:
41+
- Token Name: `socket-token` (or any name you prefer)
42+
- Add scope: `connections:write`
43+
4. Click **"Generate"**
44+
5. **Copy the app-level token** (starts with `xapp-`) - you'll need this later
45+
6. Click **"Done"**
46+
47+
### Step 4: Get Bot Token
48+
49+
1. In your app settings, go to **"OAuth & Permissions"** in the left sidebar
50+
2. Under **"OAuth Tokens for Your Workspace"**, click **"Install to Workspace"**
51+
3. Review the permissions and click **"Allow"**
52+
4. **Copy the Bot User OAuth Token** (starts with `xoxb-`) - you'll need this later
53+
54+
### Step 5: Get Signing Secret
55+
56+
1. In your app settings, go to **"Basic Information"** in the left sidebar
57+
2. Scroll down to **"App Credentials"**
58+
3. **Copy the Signing Secret** - you'll need this later
59+
60+
### Step 6: Set Up Environment Variables
61+
62+
Create a `.env` file in the `slack_bot` directory with your tokens:
63+
64+
```bash
65+
# Required for Slack bot
66+
SLACK_BOT_TOKEN=xoxb-your-bot-token-here
67+
SLACK_APP_TOKEN=xapp-your-app-level-token-here
68+
SLACK_SIGNING_SECRET=your-signing-secret-here
69+
```
70+
71+
**Important:** Never commit the `.env` file to version control. Add it to `.gitignore`.
72+
73+
### Step 7: Install Dependencies
74+
75+
This project uses [uv](https://github.com/astral-sh/uv) for dependency management:
76+
77+
```bash
78+
cd slack_bot
79+
uv sync
80+
```
81+
82+
### Step 8: Run the Bot
83+
84+
```bash
85+
python app.py
86+
```
87+
88+
You should see:
89+
```
90+
⚡️ AI Engineering Maintenance Bot is running!
91+
```
92+
93+
## Usage
94+
95+
Once the bot is running and installed in your workspace:
96+
97+
### Slash Command
98+
99+
In any Slack channel where the bot is present:
100+
101+
```
102+
/aieng-bot version
103+
```
104+
105+
This will display:
106+
- Bot version
107+
- Project name and description
108+
- Links to the GitHub repository
109+
- Link to the dashboard
110+
111+
### Mention the Bot
112+
113+
You can also mention the bot in a channel:
114+
115+
```
116+
@AI Engineering Maintenance Bot
117+
```
118+
119+
The bot will respond with usage instructions.
120+
121+
## Deployment
122+
123+
### Running as a Service
124+
125+
For production use, you should run the bot as a systemd service or in a container.
126+
127+
#### Docker (Recommended)
128+
129+
Create a `Dockerfile`:
130+
131+
```dockerfile
132+
FROM python:3.12-slim
133+
134+
WORKDIR /app
135+
136+
# Install uv
137+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
138+
139+
# Copy dependency files
140+
COPY pyproject.toml .
141+
142+
# Install dependencies
143+
RUN uv pip install --system -e .
144+
145+
# Copy application
146+
COPY app.py .
147+
148+
CMD ["python", "app.py"]
149+
```
150+
151+
Build and run:
152+
153+
```bash
154+
docker build -t aieng-bot-slack .
155+
docker run -d --name aieng-bot-slack \
156+
--env-file .env \
157+
aieng-bot-slack
158+
```
159+
160+
#### Systemd Service
161+
162+
Create `/etc/systemd/system/aieng-bot-slack.service`:
163+
164+
```ini
165+
[Unit]
166+
Description=AI Engineering Maintenance Bot Slack Integration
167+
After=network.target
168+
169+
[Service]
170+
Type=simple
171+
User=your-user
172+
WorkingDirectory=/path/to/aieng-bot-maintain/slack_bot
173+
Environment="SLACK_BOT_TOKEN=xoxb-your-token"
174+
Environment="SLACK_APP_TOKEN=xapp-your-token"
175+
Environment="SLACK_SIGNING_SECRET=your-secret"
176+
ExecStart=/usr/bin/python3 app.py
177+
Restart=always
178+
179+
[Install]
180+
WantedBy=multi-user.target
181+
```
182+
183+
Enable and start:
184+
185+
```bash
186+
sudo systemctl enable aieng-bot-slack
187+
sudo systemctl start aieng-bot-slack
188+
```
189+
190+
## Troubleshooting
191+
192+
### Bot doesn't respond to commands
193+
194+
1. Check that the bot is running (`python app.py` should show "⚡️ AI Engineering Maintenance Bot is running!")
195+
2. Verify Socket Mode is enabled in your app settings
196+
3. Confirm all environment variables are set correctly
197+
4. Check that the app is installed in your workspace
198+
199+
### "Invalid token" errors
200+
201+
- Make sure you're using the correct token types:
202+
- `SLACK_BOT_TOKEN` should start with `xoxb-`
203+
- `SLACK_APP_TOKEN` should start with `xapp-`
204+
- Regenerate tokens if needed from the Slack API dashboard
205+
206+
### Command not found in Slack
207+
208+
1. Go to your app settings → Slash Commands
209+
2. Verify `/aieng-bot` is listed
210+
3. Try reinstalling the app to your workspace
211+
212+
## Security Notes
213+
214+
- **Never commit tokens or secrets to version control**
215+
- Add `.env` to your `.gitignore` file
216+
- Use environment variables or a secrets manager for production deployments
217+
- Rotate tokens regularly following your organization's security policies
218+
- Limit app installation to only necessary workspaces
219+
220+
## Architecture
221+
222+
The bot uses:
223+
- **Slack Bolt for Python** - Official Slack framework for building apps
224+
- **Socket Mode** - Eliminates need for public URLs and webhook endpoints
225+
- **aieng-bot-maintain package** - Imports version information from the main project
226+
227+
## Links
228+
229+
- [Slack API Documentation](https://api.slack.com/)
230+
- [Slack Bolt Python Documentation](https://docs.slack.dev/tools/bolt-python/)
231+
- [Socket Mode Guide](https://api.slack.com/apis/connections/socket)
232+
- [App Manifests Reference](https://api.slack.com/reference/manifests)
233+
234+
## Support
235+
236+
For issues or questions:
237+
- Open an issue at [GitHub Issues](https://github.com/VectorInstitute/aieng-bot-maintain/issues)
238+
- Check the main project [README](../README.md)
239+
- Review the [CLAUDE.md](../CLAUDE.md) for project architecture details

0 commit comments

Comments
 (0)