From ae5dfc3bee950267123ae2fbd1c11e7ce36626ea Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Mon, 20 Jan 2025 18:45:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dtg=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E4=B8=AD=E5=AD=98=E5=9C=A8.=E5=92=8C*?= =?UTF-8?q?=E5=B0=B1=E4=BC=9A=E5=8F=91=E9=80=81=E5=A4=B1=E8=B4=A5=E7=9A=84?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/pipeline/src/core/executor.ts | 2 +- packages/core/pipeline/src/notification/api.ts | 6 +++--- .../src/plugins/plugin-notification/telegram/index.ts | 5 ++++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/core/pipeline/src/core/executor.ts b/packages/core/pipeline/src/core/executor.ts index cf29d8d46..e21a33b7c 100644 --- a/packages/core/pipeline/src/core/executor.ts +++ b/packages/core/pipeline/src/core/executor.ts @@ -435,7 +435,7 @@ export class Executor { content, userId: this.pipeline.userId, pipeline: this.pipeline, - result: this.lastRuntime.pipeline.status, + result: this.lastRuntime?.pipeline?.status, pipelineId: this.pipeline.id, historyId: this.runtime.id, errorMessage, diff --git a/packages/core/pipeline/src/notification/api.ts b/packages/core/pipeline/src/notification/api.ts index 161ca1960..fe465e042 100644 --- a/packages/core/pipeline/src/notification/api.ts +++ b/packages/core/pipeline/src/notification/api.ts @@ -121,11 +121,11 @@ export abstract class BaseNotification implements INotification { async onTestRequest() { await this.doSend({ userId: 0, - title: "【Certd】测试通知,标题长度测试、测试、测试", - content: "测试通知", + title: "【Certd】测试通知【*.foo.com】,标题长度测试、测试、测试", + content: "测试通知,*.foo.com", pipeline: { id: 1, - title: "测试流水线", + title: "证书申请成功【测试流水线】", } as any, pipelineId: 1, historyId: 1, diff --git a/packages/ui/certd-server/src/plugins/plugin-notification/telegram/index.ts b/packages/ui/certd-server/src/plugins/plugin-notification/telegram/index.ts index 434ca2eba..8ea01da5e 100644 --- a/packages/ui/certd-server/src/plugins/plugin-notification/telegram/index.ts +++ b/packages/ui/certd-server/src/plugins/plugin-notification/telegram/index.ts @@ -58,13 +58,16 @@ export class TelegramNotification extends BaseNotification { }) skipSslVerify: boolean; + replaceText(text: string) { + return text.replaceAll('.', '\\.').replaceAll('*', '\\*'); + } async send(body: NotificationBody) { if (!this.botToken || !this.chatId) { throw new Error('Bot Token 和聊天ID不能为空'); } // 构建消息内容 - const messageContent = `*${body.title}*\n\n${body.content}\n\n[查看详情](${body.url})`; + const messageContent = `${this.replaceText(body.title)}\n\n${this.replaceText(body.content)}\n\n[查看详情](${body.url})`; // Telegram API URL const url = `https://api.telegram.org/bot${this.botToken}/sendMessage`;