Slack & Discord Webhook Alerts
Get real-time, beautifully formatted operational alerts delivered straight to your team's Slack channels or Discord servers without paying for third-party alert SaaS.
Automatic Channel Type Detection
Stacklenzz inspects your webhook URL automatically to output native, visually rich payload cards for each platform:
Detects hooks.slack.com URLs and formats alerts using Slack Block Kit UI with colored attachments, status badges, formatted stack traces, and local timestamps.
Detects discord.com/api/webhooks URLs and formats alerts using rich Discord Embed cards with color-coded sidebar indicators and metadata fields.
Express Setup & Environment Variables
Pass your webhook configuration directly into setupObservability(app) or use standard environment variables:
import express from "express";
import { setupObservability } from "@stacklenzz/server";
const app = express();
setupObservability(app, {
serviceName: "bookme-express-api",
environment: "production",
alerts: {
webhookUrl: process.env.SLACK_WEBHOOK_URL || process.env.DISCORD_WEBHOOK_URL,
alertOn5xxCrash: true, // Fire instant alert on 5xx server crash (bypasses cooldown)
errorRateThreshold: 5.0, // Trigger alert if 5xx error rate exceeds 5%
p95LatencyThresholdMs: 1000,// Trigger warning if P95 response latency exceeds 1000ms
cooldownMinutes: 15, // Smart cooldown for threshold metric alerts
},
});NestJS Webhook Setup
In your NestJS root module (AppModule), pass the alert options into ObservabilityModule.forRoot() or forRootAsync():
import { Module } from "@nestjs/common";
import { ObservabilityModule } from "@stacklenzz/server";
@Module({
imports: [
ObservabilityModule.forRoot({
serviceName: "bookme-nestjs-api",
environment: "production",
alerts: {
webhookUrl: process.env.SLACK_WEBHOOK_URL || process.env.DISCORD_WEBHOOK_URL,
alertOn5xxCrash: true,
errorRateThreshold: 3.0,
cooldownMinutes: 15,
},
}),
],
})
export class AppModule {}🧪 How to Test Alerts
You can test your webhook integration by adding your Slack or Discord URL to your .env file:
# For Slack SLACK_WEBHOOK_URL=https://hooks.slack.com/services/YOUR_WORKSPACE/YOUR_CHANNEL/YOUR_TOKEN # Or For Discord DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/YOUR_WEBHOOK_ID/YOUR_WEBHOOK_TOKEN
Trigger a test 5xx server crash endpoint using curl:
curl http://localhost:4000/api/error
You will immediately receive an alert payload notification in your Slack channel or Discord server showing the exact crash message, endpoint route, HTTP status 500, and timestamp!