Skip to content

feat: Webhook & Slack/Discord alerting integrations#249

Open
vivekchand wants to merge 1 commit intomainfrom
fix/gh-clawmetry-204-webhook-slack-discord
Open

feat: Webhook & Slack/Discord alerting integrations#249
vivekchand wants to merge 1 commit intomainfrom
fix/gh-clawmetry-204-webhook-slack-discord

Conversation

@vivekchand
Copy link
Owner

Closes #204

What

Push alert notifications to Slack, Discord, or arbitrary webhooks when ClawMetry fires budget/cost/agent alerts.

How

New alert dispatch functions:

  • _send_slack_alert(url, message, alert_type) — uses Slack incoming webhook format with colored attachments
  • _send_discord_alert(url, message, alert_type) — uses Discord embed format with color-coded severity
  • _dispatch_alert_to_channels(message, alert_type) — dispatches to all enabled channels; called from _fire_alert()

New alert_channels DB table (v2 schema):

  • Stores named Slack/Discord/webhook integrations with id, name, type, webhook_url, enabled, timestamps
  • Migration: detects and recreates table if old v1 schema (with config column) is present

New API endpoints:

  • GET /api/alerts/channels — list configured integrations
  • POST /api/alerts/channels — add new integration (type: slack|discord|webhook)
  • PUT /api/alerts/channels/<id> — update name, url, or enabled state
  • DELETE /api/alerts/channels/<id> — remove an integration
  • POST /api/alerts/channels/<id>/test — send a test alert to verify setup

Budget & Alerts modal UI:

  • New "🔗 Integrations" tab with integration list, add form (type selector + name + URL), test and delete buttons

Tests

10 new tests across TestAlertChannels class: create Slack/Discord/webhook channels, reject invalid type/missing URL, list channels, schema validation, delete, update enabled state.

All 143 tests pass.

- Add _send_slack_alert() with rich attachment format (color-coded by severity)
- Add _send_discord_alert() with Discord embed format (color-coded by severity)
- Add _get_alert_channels() / _dispatch_alert_to_channels() helpers
- All _fire_alert() calls now auto-dispatch to configured channels
- Add alert_channels DB table (v2 schema: id, name, type, webhook_url, enabled, timestamps)
- Migration: auto-detect & recreate table if old v1 schema (config column) detected
- New API endpoints:
  GET/POST /api/alerts/channels — list or create channel integrations
  PUT/DELETE /api/alerts/channels/<id> — update or remove a channel
  POST /api/alerts/channels/<id>/test — send test alert to a specific channel
- Budget & Alerts modal: new Integrations tab with add/test/delete UI
- 10 new tests, all 143 pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Webhook & Slack/Discord alerting

1 participant