fix: 修复tg消息内容中存在.和*就会发送失败的bug

v2-dev
xiaojunnuo 2025-01-20 18:45:07 +08:00
parent 6ab83b662a
commit ae5dfc3bee
3 changed files with 8 additions and 5 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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`;