mirror of https://github.com/certd/certd
fix: 修复tg消息内容中存在.和*就会发送失败的bug
parent
6ab83b662a
commit
ae5dfc3bee
|
@ -435,7 +435,7 @@ export class Executor {
|
||||||
content,
|
content,
|
||||||
userId: this.pipeline.userId,
|
userId: this.pipeline.userId,
|
||||||
pipeline: this.pipeline,
|
pipeline: this.pipeline,
|
||||||
result: this.lastRuntime.pipeline.status,
|
result: this.lastRuntime?.pipeline?.status,
|
||||||
pipelineId: this.pipeline.id,
|
pipelineId: this.pipeline.id,
|
||||||
historyId: this.runtime.id,
|
historyId: this.runtime.id,
|
||||||
errorMessage,
|
errorMessage,
|
||||||
|
|
|
@ -121,11 +121,11 @@ export abstract class BaseNotification implements INotification {
|
||||||
async onTestRequest() {
|
async onTestRequest() {
|
||||||
await this.doSend({
|
await this.doSend({
|
||||||
userId: 0,
|
userId: 0,
|
||||||
title: "【Certd】测试通知,标题长度测试、测试、测试",
|
title: "【Certd】测试通知【*.foo.com】,标题长度测试、测试、测试",
|
||||||
content: "测试通知",
|
content: "测试通知,*.foo.com",
|
||||||
pipeline: {
|
pipeline: {
|
||||||
id: 1,
|
id: 1,
|
||||||
title: "测试流水线",
|
title: "证书申请成功【测试流水线】",
|
||||||
} as any,
|
} as any,
|
||||||
pipelineId: 1,
|
pipelineId: 1,
|
||||||
historyId: 1,
|
historyId: 1,
|
||||||
|
|
|
@ -58,13 +58,16 @@ export class TelegramNotification extends BaseNotification {
|
||||||
})
|
})
|
||||||
skipSslVerify: boolean;
|
skipSslVerify: boolean;
|
||||||
|
|
||||||
|
replaceText(text: string) {
|
||||||
|
return text.replaceAll('.', '\\.').replaceAll('*', '\\*');
|
||||||
|
}
|
||||||
async send(body: NotificationBody) {
|
async send(body: NotificationBody) {
|
||||||
if (!this.botToken || !this.chatId) {
|
if (!this.botToken || !this.chatId) {
|
||||||
throw new Error('Bot Token 和聊天ID不能为空');
|
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
|
// Telegram API URL
|
||||||
const url = `https://api.telegram.org/bot${this.botToken}/sendMessage`;
|
const url = `https://api.telegram.org/bot${this.botToken}/sendMessage`;
|
||||||
|
|
Loading…
Reference in New Issue