@@ -6,49 +6,53 @@ class NotificationController {
6
6
}
7
7
8
8
async triggerNotification ( req , res ) {
9
- const { monitorId, type, webhookUrl , botToken , chatId } = req . body ;
10
-
9
+ const { monitorId, type, config } = req . body ;
10
+
11
11
if ( ! monitorId || ! type ) {
12
12
return res . status ( 400 ) . json ( {
13
13
success : false ,
14
14
msg : "monitorId and type are required"
15
15
} ) ;
16
16
}
17
-
17
+
18
18
try {
19
19
const networkResponse = {
20
20
monitor : { _id : monitorId , name : "Test Monitor" , url : "http://www.google.com" } ,
21
21
status : false ,
22
22
statusChanged : true ,
23
23
prevStatus : true ,
24
24
} ;
25
-
25
+
26
26
if ( type === "telegram" ) {
27
- if ( ! botToken || ! chatId ) {
27
+ if ( ! config ?. botToken || ! config ?. chatId ) {
28
28
return res . status ( 400 ) . json ( {
29
29
success : false ,
30
30
msg : "botToken and chatId are required for Telegram notifications"
31
31
} ) ;
32
32
}
33
- await this . notificationService . sendWebhookNotification ( networkResponse , null , type , botToken , chatId ) ;
33
+ await this . notificationService . sendWebhookNotification (
34
+ networkResponse , null , type , config . botToken , config . chatId
35
+ ) ;
34
36
} else if ( type === "discord" || type === "slack" ) {
35
- if ( ! webhookUrl ) {
37
+ if ( ! config ?. webhookUrl ) {
36
38
return res . status ( 400 ) . json ( {
37
39
success : false ,
38
40
msg : `webhookUrl is required for ${ type } notifications`
39
41
} ) ;
40
42
}
41
- await this . notificationService . sendWebhookNotification ( networkResponse , webhookUrl , type ) ;
43
+ await this . notificationService . sendWebhookNotification (
44
+ networkResponse , config . webhookUrl , type
45
+ ) ;
42
46
} else if ( type === "email" ) {
43
- if ( ! req . body . address ) {
47
+ if ( ! config ? .address ) {
44
48
return res . status ( 400 ) . json ( {
45
49
success : false ,
46
50
msg : "address is required for email notifications"
47
51
} ) ;
48
52
}
49
- await this . notificationService . sendEmail ( networkResponse , req . body . address ) ;
53
+ await this . notificationService . sendEmail ( networkResponse , config . address ) ;
50
54
}
51
-
55
+
52
56
res . json ( { success : true , msg : "Notification sent successfully" } ) ;
53
57
} catch ( error ) {
54
58
logger . error ( {
@@ -60,6 +64,7 @@ class NotificationController {
60
64
res . status ( 500 ) . json ( { success : false , msg : "Failed to send notification" } ) ;
61
65
}
62
66
}
67
+
63
68
}
64
69
65
70
export default NotificationController ;
0 commit comments