@@ -6,6 +6,7 @@ import { Telegraf } from "telegraf";
66
77import prisma from "@/prisma/db" ;
88import { ServerWithHealthCheck , TelegramNotificationChannelConfig } from "@/src/core/definitions" ;
9+ import { app } from "@/src/core/config" ;
910
1011export async function createNotificationChannel ( data : any ) : Promise < void > {
1112 await prisma . notificationChannel . create ( { data } ) ;
@@ -67,7 +68,10 @@ export async function deleteNotificationChannel(id: number): Promise<void> {
6768 revalidatePath ( `/notification-channels/${ id } ` ) ;
6869}
6970
70- export async function sendNotificationViaTelegramChannel ( server : ServerWithHealthCheck ) : Promise < void > {
71+ export async function sendNotificationViaTelegramChannel (
72+ server : ServerWithHealthCheck ,
73+ errorMessage : string
74+ ) : Promise < void > {
7175 const channel = await getNotificationChannelById ( server . healthCheck ! . notificationChannelId ! ) ;
7276
7377 if ( ! channel ) {
@@ -85,10 +89,16 @@ export async function sendNotificationViaTelegramChannel(server: ServerWithHealt
8589 const userId = config . chatId ;
8690
8791 const message = config . messageTemplate
92+ . replaceAll ( "{{errorMessage}}" , errorMessage )
8893 . replaceAll ( "{{serverName}}" , server . name )
8994 . replaceAll ( "{{serverHostnameOrIp}}" , server . hostnameOrIp ) ;
9095
91- await bot . telegram . sendMessage ( userId , message ) ;
96+ await bot . telegram . sendMessage ( userId , message , {
97+ parse_mode : "Markdown" ,
98+ link_preview_options : {
99+ is_disabled : true
100+ }
101+ } ) ;
92102}
93103
94104export async function testTelegramNotificationChannel (
@@ -116,10 +126,7 @@ export async function testTelegramNotificationChannel(
116126 }
117127
118128 if ( ! config . messageTemplate ) {
119- return {
120- ok : false ,
121- message : "Message Template is required"
122- } ;
129+ config . messageTemplate = app . defaultTelegramNotificationTemplate ;
123130 }
124131
125132 try {
@@ -132,10 +139,16 @@ export async function testTelegramNotificationChannel(
132139 const userId = config . chatId ;
133140
134141 const message = config . messageTemplate
142+ . replaceAll ( "{{errorMessage}}" , "Example server error message" )
135143 . replaceAll ( "{{serverName}}" , "Example Server" )
136144 . replaceAll ( "{{serverHostnameOrIp}}" , "10.11.12.13" ) ;
137145
138- await bot . telegram . sendMessage ( userId , message ) ;
146+ await bot . telegram . sendMessage ( userId , message , {
147+ parse_mode : "Markdown" ,
148+ link_preview_options : {
149+ is_disabled : true
150+ }
151+ } ) ;
139152
140153 return {
141154 ok : true ,
0 commit comments