58 lines
2.0 KiB
JavaScript
58 lines
2.0 KiB
JavaScript
"use strict";
|
|
/**
|
|
* SlackNotifier — sends anomaly notifications to a Slack webhook.
|
|
*/
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.SlackNotifier = void 0;
|
|
const SEVERITY_EMOJI = {
|
|
low: ':blue_circle:',
|
|
medium: ':yellow_circle:',
|
|
high: ':red_circle:',
|
|
critical: ':rotating_light:',
|
|
};
|
|
class SlackNotifier {
|
|
constructor(webhookUrl, frontendBaseUrl = 'http://localhost:5173') {
|
|
this.webhookUrl = webhookUrl;
|
|
this.frontendBaseUrl = frontendBaseUrl;
|
|
}
|
|
async send(anomaly, sessionId, targetUrl) {
|
|
const emoji = SEVERITY_EMOJI[anomaly.severity] ?? ':warning:';
|
|
const payload = {
|
|
text: '🐛 ABE found a bug!',
|
|
blocks: [
|
|
{
|
|
type: 'section',
|
|
text: {
|
|
type: 'mrkdwn',
|
|
text: `*ABE Bug Report*\n` +
|
|
`*Severity:* ${emoji} ${anomaly.severity.toUpperCase()}\n` +
|
|
`*Type:* ${anomaly.type}\n` +
|
|
`*Description:* ${anomaly.description}\n` +
|
|
`*Session:* ${sessionId}\n` +
|
|
`*Target:* ${targetUrl}`,
|
|
},
|
|
},
|
|
{
|
|
type: 'actions',
|
|
elements: [
|
|
{
|
|
type: 'button',
|
|
text: { type: 'plain_text', text: 'View Report' },
|
|
url: `${this.frontendBaseUrl}/anomalies/${anomaly.id}`,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
};
|
|
const res = await fetch(this.webhookUrl, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(payload),
|
|
});
|
|
if (!res.ok) {
|
|
throw new Error(`Slack webhook returned ${res.status}: ${await res.text()}`);
|
|
}
|
|
}
|
|
}
|
|
exports.SlackNotifier = SlackNotifier;
|