π Open source, privacy-first web analytics β a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
Improve alert message
Blue Mouse6306271a6a55
diff --git a/backend/apps/cloud/src/integrations/telegram/telegram.service.ts b/backend/apps/cloud/src/integrations/telegram/telegram.service.tsindex 65386bdb6..45282e208 100644--- a/backend/apps/cloud/src/integrations/telegram/telegram.service.ts+++ b/backend/apps/cloud/src/integrations/telegram/telegram.service.ts@@ -40,7 +40,7 @@ export class TelegramService {'\n\n' +'After that, you can use the bot to manage your projects.'extra = {- // @ts-expect-error ??+ // @ts-expect-error It's not typeddisable_web_page_preview: true,reply_markup: { remove_keyboard: true },}@@ -92,7 +92,7 @@ export class TelegramService {await this.userService.updateUserTelegramId(user.id, null)}- async addMessage(chatId: string, text: string, extra?: unknown) {+ async addMessage(chatId: string, text: string, extra?: ExtraReplyMessage) {await this.messageRepository.save({ chatId, text, extra })}@@ -112,6 +112,14 @@ export class TelegramService {return text.replace(charsToEscapeRegex, '\\$&')}+ escapeTelegramMarkdown(text?: string | null) {+ if (text === null || text === undefined) return ''++ // Characters to escape for legacy Markdown: _, *, `, [+ const charsToEscapeRegex = /[_*`[]/g+ return text.replace(charsToEscapeRegex, '\\$&')+ }+async sendMessage(messageId: string,chatId: string,diff --git a/backend/apps/cloud/src/task-manager/task-manager.service.ts b/backend/apps/cloud/src/task-manager/task-manager.service.tsindex 3922b032f..cfe735afd 100644--- a/backend/apps/cloud/src/task-manager/task-manager.service.ts+++ b/backend/apps/cloud/src/task-manager/task-manager.service.ts@@ -1226,22 +1226,29 @@ export class TaskManagerService {return}- // const clientUrl = this.configService.get('CLIENT_URL')- // const escapedErrorLink =- // this.telegramService.escapeTelegramMarkdownV2(- // `${clientUrl}/projects/${project.id}?tab=errors&eid=${errorDetails.eid}`,- // )- // const escapedProjectLink =- // this.telegramService.escapeTelegramMarkdownV2(- // `${clientUrl}/projects/${project.id}`,- // )-- // Values are now raw, not pre-escaped- const alertName = alert.name- const projectName = project.name- const errorName = errorDetails.name || 'N/A'- const errorMessage = errorDetails.message || 'N/A'- const filename = errorDetails.filename || 'N/A'+ const clientUrl = this.configService.get('CLIENT_URL')+ const escapedErrorLink = this.telegramService.escapeTelegramMarkdown(+ `${clientUrl}/projects/${project.id}?tab=errors&eid=${errorDetails.eid}`,+ )+ const escapedProjectLink = this.telegramService.escapeTelegramMarkdown(+ `${clientUrl}/projects/${project.id}`,+ )++ const alertName = this.telegramService.escapeTelegramMarkdown(+ alert.name,+ )+ const projectName = this.telegramService.escapeTelegramMarkdown(+ project.name,+ )+ const errorName = this.telegramService.escapeTelegramMarkdown(+ errorDetails.name || 'N/A',+ )+ const errorMessage = this.telegramService.escapeTelegramMarkdown(+ errorDetails.message || 'N/A',+ )+ const filename = this.telegramService.escapeTelegramMarkdown(+ errorDetails.filename || 'N/A',+ )let locationInfo = 'Location: Not available'if (@@ -1259,16 +1266,19 @@ export class TaskManagerService {}text =- `π Alert *${this.telegramService.escapeTelegramMarkdownV2(alertName)}* triggered\\!\n\n` +- // `Project: [${this.telegramService.escapeTelegramMarkdownV2(projectName)}]\\(${escapedProjectLink}\\)\n` +- `Project: ${projectName}\n` +- `Error: ${this.telegramService.escapeTelegramMarkdownV2(errorName)}\n` +- `Message: ${this.telegramService.escapeTelegramMarkdownV2(errorMessage)}\n\n` +- `${this.telegramService.escapeTelegramMarkdownV2(locationInfo)}\n\n` // +- // `[View error](${escapedErrorLink})`+ `π Error alert *${alertName}* triggered!\n\n` ++ `Project: [${projectName}](${escapedProjectLink})\n` ++ `Error: \`${errorName}\`\n` ++ `Message: \`${errorMessage}\`\n\n` ++ `${locationInfo}\n\n` ++ `[View error](${escapedErrorLink})`} else {- const alertName = alert.name- const projectName = project.name+ const alertName = this.telegramService.escapeTelegramMarkdown(+ alert.name,+ )+ const projectName = this.telegramService.escapeTelegramMarkdown(+ project.name,+ )let customEventInfo = ''if (@@ -1279,13 +1289,14 @@ export class TaskManagerService {}text =- `π Alert *${this.telegramService.escapeTelegramMarkdownV2(alertName)}* triggered\\!\n\n` +- `Your project *${this.telegramService.escapeTelegramMarkdownV2(projectName)}* has had *${count}${customEventInfo}* ${queryMetricString} in the last *${effectiveQueryTimeString}*\\!`+ `π Alert *${alertName}* triggered!\n\n` ++ `Your project *${projectName}* has had *${count}${customEventInfo}* ${queryMetricString} in the last *${effectiveQueryTimeString}*!`}if (project.admin?.isTelegramChatIdConfirmed) {this.telegramService.addMessage(project.admin.telegramChatId, text, {- parse_mode: 'MarkdownV2',+ parse_mode: 'Markdown',+ // @ts-expect-error It's not typeddisable_web_page_preview: true,})}