Add Slack and Discord webhooks
- Dominant language
- Python
- Stars
- 1
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
### 🚀 Feature Overview
Currently, **AI Watchman** logs detected security threats locally and routes them through the internal `alert_router.py` module.
We want to extend `watchman/core/alert_router.py` to support real-time notifications via **Slack** and **Discord** webhooks whenever a high-severity threat (such as SQL Injection, Jailbreak Attempt, or Prompt Injection) is detected.
---
### 🎯 Desired Behavior
1. **Configuration:**
Allow users to specify optional webhook URLs in their `watchman.yaml` config file:
```yaml
alerts:
slack_webhook_url: "https://hooks.slack.com/services/..."
discord_webhook_url: "https://discord.com/api/webhooks/..."
min_severity: "HIGH" # LOW, MEDIUM, HIGH, CRITICAL
```
2. **Notification Dispatch:**
When an alert is triggered in `AlertRouter.dispatch()`:
- Check if Slack or Discord webhook URLs are configured.
- If threat severity satisfies `min_severity`, construct a formatted JSON payload.
- Dispatch HTTP POST request using `requests` (or `httpx`) to the webhook endpoint asynchronously/non-blockingly.
3. **Slack Payload Format Example:**
```json
{
"text": "🚨 *AI Watchman Alert* - High Severity Threat Detected!",
"attachments": [
{
"color": "#FF0000",
"fields": [
{ "title": "Threat Type", "value": "SQL Injection", "short": true },
{ "title": "Client IP", "value": "192.168.1.50", "short": true },
{ "title": "Payload Snippet", "value": "SELECT * FROM users WHERE '1'='1'", "short": false }
]
}
]
}
```
---
### 📁 Relevant Files
- `watchman/core/alert_router.py` *(Main logic to update)*
- `watchman/config/config.yaml` *(Config schema example)*
- `test_watchman.py` *(Add unit tests)*
---
### 📋 Checklist for Contributors
- [ ] Read `slack_webhook_url` and `discord_webhook_url` from config.
- [ ] Implement `send_slack_alert(alert_data)` in `alert_router.py`.
- [ ] Implement `send_discord_alert(alert_data)` in `alert_router.py`.
- [ ] Ensure webhook failures are caught gracefully (do not crash the main backend thread).
- [ ] Write unit tests mocking `requests.post()` in `test_watchman.py`.
- [ ] Update `watchman.yaml` example with commented-out webhook keys.
---
### 🤝 Need Help?
If you have any questions or need guidance getting started with the codebase, feel free to comment below! Happy contributing! 🎉
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading watchman/core/alert_router.py, especially AlertRouter.dispatch(), then inspect watchman/config/config.yaml and the existing tests in test_watchman.py. Verify how alerts and severity are represented before defining the webhook configuration and mocked HTTP behavior. Done means configured Slack and Discord notifications respect min_severity, webhook failures do not crash the backend thread, and unit tests cover the dispatch paths and updated configuration example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100