@momen124/ai-monitor-notifiers
v1.0.0
Published
Notification providers for AI Monitor - Telegram, Slack, Email
Maintainers
Readme
@momen124/ai-monitor-notifiers
Notification providers for AI Monitor
Telegram, Slack, Email, and Multi-channel support
✨ Features
- 📱 Telegram - Send alerts via Telegram bot
- 💬 Slack - Beautiful formatted messages via webhook
- 📧 Email - HTML and text emails via SMTP
- 🔀 Multi-Channel - Send to multiple channels simultaneously
- 🔌 Plug-and-Play - Works seamlessly with
@momen124/ai-monitor-core - 🌳 Tree-Shakeable - Only bundle what you use
📦 Installation
# Install core package
npm install @momen124/ai-monitor-core
# Install notifiers package
npm install @momen124/ai-monitor-notifiers
# Install peer dependencies for the notifiers you want to use
npm install telegram # For Telegram
npm install axios # For Slack
npm install nodemailer # For Email🚀 Quick Start
Telegram Notifier
import { AIMonitor } from "@momen124/ai-monitor-core";
import { TelegramNotifier } from "@momen124/ai-monitor-notifiers";
const monitor = new AIMonitor({
notifiers: [
new TelegramNotifier({
token: "YOUR_BOT_TOKEN",
chatId: "YOUR_CHAT_ID",
}),
],
});
await monitor.start();Slack Notifier
import { SlackNotifier } from "@momen124/ai-monitor-notifiers";
const monitor = new AIMonitor({
notifiers: [
new SlackNotifier({
webhookUrl: "https://hooks.slack.com/services/YOUR/WEBHOOK/URL",
}),
],
});Email Notifier
import { EmailNotifier } from "@momen124/ai-monitor-notifiers";
const monitor = new AIMonitor({
notifiers: [
new EmailNotifier({
host: "smtp.gmail.com",
port: 587,
secure: false,
auth: {
user: "[email protected]",
pass: "your-app-password",
},
from: "AI Monitor <[email protected]>",
to: ["[email protected]", "[email protected]"],
}),
],
});Multi-Channel Notifier
Send to all channels at once:
import {
MultiNotifier,
TelegramNotifier,
SlackNotifier,
} from "@momen124/ai-monitor-notifiers";
const monitor = new AIMonitor({
notifiers: [
new MultiNotifier({
notifiers: [
new TelegramNotifier({
/* ... */
}),
new SlackNotifier({
/* ... */
}),
new EmailNotifier({
/* ... */
}),
],
}),
],
});
// Alert will be sent to all three channels
await monitor.alert({
severity: "CRITICAL",
title: "System Down",
message: "Production server is not responding",
});📚 API Reference
TelegramNotifier
new TelegramNotifier(config: ITelegramConfig)
interface ITelegramConfig {
token: string; // Bot token from @BotFather
chatId: string; // Chat ID to send messages to
parseMode?: 'Markdown' | 'HTML'; // Message format (default: 'Markdown')
disableWebPagePreview?: boolean; // Disable link previews (default: true)
}Getting Telegram credentials:
- Create bot via @BotFather
- Get chat ID by messaging @userinfobot
SlackNotifier
new SlackNotifier(config: ISlackConfig)
interface ISlackConfig {
webhookUrl: string; // Slack webhook URL
}Getting Slack webhook:
- Go to https://api.slack.com/apps
- Create an app → Incoming Webhooks → Add to Workspace
- Copy webhook URL
EmailNotifier
new EmailNotifier(config: IEmailConfig)
interface IEmailConfig {
host: string; // SMTP server host
port: number; // SMTP server port
secure?: boolean; // Use TLS (default: false)
auth: {
user: string; // SMTP username
pass: string; // SMTP password
};
from: string; // From address
to: string | string[]; // Recipient(s)
}MultiNotifier
new MultiNotifier(config: IMultiNotifierConfig)
interface IMultiNotifierConfig {
notifiers: INotifier[]; // Array of notifiers
stopOnFirstError?: boolean; // Stop on first failure (default: false)
}🎨 Message Formatting
Alert Messages
All notifiers format alerts with:
- Severity emoji (🚨 Critical, âš ï¸ Warning, â„¹ï¸ Info)
- Title and message
- Timestamp
- Optional metrics
Pipeline Status
- Status emoji (✅ Success, ⌠Failure, âš ï¸ Unstable, â¹ï¸ Aborted)
- Job name and build number
- Duration
- Changes list (if provided)
- Build URL (if provided)
Deployment Notifications
- Environment and version
- Status
- Duration
- Changes
- Environment URL
Daily Reports
- Overall health status
- Summary metrics (alerts, auto-fixes, uptime)
- Top issues list
🎯 Examples
Conditional Notifiers
const notifiers = [];
// Always use Telegram
notifiers.push(
new TelegramNotifier({
/* ... */
}),
);
// Use Slack only in production
if (process.env.NODE_ENV === "production") {
notifiers.push(
new SlackNotifier({
/* ... */
}),
);
}
// Use Email for critical alerts
notifiers.push(
new EmailNotifier({
/* ... */
}),
);
const monitor = new AIMonitor({ notifiers });Error Handling
const monitor = new AIMonitor({
notifiers: [
new MultiNotifier({
notifiers: [telegram, slack, email],
stopOnFirstError: false, // Continue even if one fails
}),
],
});
// If Slack fails, Telegram and Email still receive notificationsCustom Notifier
Create your own notifier:
import type { INotifier, IAlert } from "@momen124/ai-monitor-core";
class DiscordNotifier implements INotifier {
constructor(private webhookUrl: string) {}
async send(message: string): Promise<void> {
await fetch(this.webhookUrl, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ content: message }),
});
}
async sendAlert(alert: IAlert): Promise<void> {
const message = `**${alert.severity}**: ${alert.title}\n${alert.message}`;
await this.send(message);
}
// Implement other methods...
}
// Use it!
const monitor = new AIMonitor({
notifiers: [new DiscordNotifier("YOUR_WEBHOOK")],
});🔧 Troubleshooting
Telegram not sending messages
- Verify bot token is correct
- Ensure chat ID is correct (message the bot first)
- Check internet connectivity
- Install
telegrampackage:npm install telegram
Slack webhook failing
- Verify webhook URL is correct and active
- Check Slack app permissions
- Install
axiospackage:npm install axios
Email not sending
- Verify SMTP credentials
- Check firewall/port access (usually 587 or 465)
- For Gmail, use an App Password
- Install
nodemailerpackage:npm install nodemailer
📖 Related Packages
- @momen124/ai-monitor-core - Core monitoring functionality
📠License
MIT © AKER Team
Made with â¤ï¸ by the AKER Team
