Store bot token and chat id in their own respective fields.

This commit is contained in:
Skorpios committed 2025-02-02 23:50:09 -08:00
1 parent d3fb41acfe
commit 8f9406261f
2 files changed
+11 -3

No files matched your search

+10
View File
@@ -10,6 +10,15 @@ const NotificationSchema = mongoose.Schema(
type: String,
enum: ["email", "sms", "discord", "slack", "telegram"],
},
webhookUrl: {
type: String,
},
botToken: {
type: String,
},
chatId: {
type: String,
},
address: {
type: String,
},
@@ -76,4 +85,5 @@ NotificationSchema.pre("findOneAndUpdate", function (next) {
}
next();
});
export default mongoose.model("Notification", NotificationSchema);
+1 -3
View File
@@ -18,7 +18,7 @@ class NotificationService {
this.networkService = networkService;
}
async sendWebhookNotification(networkResponse, address, platform) {
async sendWebhookNotification(networkResponse, address, platform, botToken, chatId) {
const { monitor, status } = networkResponse;
let message;
let url = address;
@@ -28,7 +28,6 @@ class NotificationService {
} else if (platform === 'discord') {
message = { content: `Monitor ${monitor.name} is ${status ? "up" : "down"}. URL: ${monitor.url}` };
} else if (platform === 'telegram') {
const [botToken, chatId] = address.split('|').map(part => part?.trim());
if (!botToken || !chatId) {
return false;
}
@@ -58,7 +57,6 @@ class NotificationService {
}
/**
* Sends an email notification for hardware infrastructure alerts
*