Enterprise-grade error monitoring with smart Slack alerts and automatic data format conversion.
β
Real-time Slack Alerts - 3 severity levels (HIGH/π¨, MEDIUM/
β
Automatic Format Conversion - Convert between JSON, CSV, TXT on-the-fly
β
Production-Ready - Used in production for 10,000+ daily users
β
File Attachments - Attach error context as files
β
Smart Parsing - Handle nested objects, arrays, errors
β
Auto Cleanup - Temporary file management
β
TypeScript Support - Full type safety
npm install prod-alert-sentry
# or
yarn add prod-alert-sentry
# π Quick Start
## 1οΈβ£ Initialize (Once at App Startup)
```ts
import alert from "prod-alert-sentry";
alert.init(
process.env.SLACK_TOKEN_ID!,
process.env.CHANNEL_NAME!,
process.env.CHANNEL_ID!
);try {
throw new Error("Database connection failed");
} catch (error) {
alert.high(error);
}Thatβs it.
Youβll instantly receive a Slack message.
| Method | Use Case |
|---|---|
alert.high() |
Critical production failures |
alert.medium() |
Warnings / performance issues |
alert.low() |
Informational events |
Example:
alert.medium("API rate limit exceeded");alert.medium("API error", {
fileData: {
service: "user-service",
errorCode: "ERR-500",
userId: 12345
},
fileType: "json",
fileName: "api-error-details",
comment: "JSON file created from object"
});alert.low("User export completed", {
fileData: [
{ id: 1, name: "John", status: "active" },
{ id: 2, name: "Jane", status: "inactive" }
],
fileType: "csv",
fileName: "user-export"
});alert.high("Server logs attached", {
fileData: "Database connection failed on port 5432",
fileType: "txt",
fileName: "server-logs"
});You can convert between formats automatically.
alert.medium("Converted data", {
fileData: { name: "John", age: 30 },
from: "json",
to: "csv",
fileName: "converted-data"
});alert.low("Import ready", {
fileData: `id,name
1,John
2,Jane`,
from: "csv",
to: "json"
});alert.low("Text converted", {
fileData: `Line 1
Line 2
Line 3`,
from: "txt",
to: "csv",
csvHeaders: ["lineNumber", "content"],
fileName: "text-to-table"
});alert.high("Debug data", {
fileData: { service: "api", status: "failed" },
from: "json",
to: "txt"
});Initializes Slack client.
alert.init(
"xoxb-your-bot-token",
"#production-alerts",
"C1234567890",
{ autoDeleteFiles: true }
);{
autoDeleteFiles?: boolean; // default: true
}Send alert with severity.
{
channelName?: string;
channelId?: string;
fileData?: any;
fileName?: string;
fileType?: "json" | "csv" | "txt";
from?: "json" | "csv" | "txt";
to?: "json" | "csv" | "txt";
csvHeaders?: string[];
comment?: string;
}- Go to https://api.slack.com/apps
- Create a new Slack App
- Add Bot Token Scopes:
chat:writefiles:write
- Install to workspace
- Copy:
- Bot Token (
xoxb-...) - Channel ID
- Bot Token (
fileTypeand
from + toChoose one mode only:
- Direct creation β
fileType - Conversion β
from+to
The library has been tested with:
- JSON β CSV
- JSON β TXT
- CSV β JSON
- CSV β TXT
- TXT β JSON
- TXT β CSV
- Array β CSV
- Error object handling
- Channel override
alert.init(
process.env.SLACK_TOKEN_ID!,
process.env.NODE_ENV === "production"
? "#production-alerts"
: "#dev-alerts",
process.env.CHANNEL_ID!
);MIT Β© Parshuram Kumar