修复通知

This commit is contained in:
hanhh 2021-09-19 23:00:21 +08:00
parent aa08f489d7
commit f482796cdf

View File

@ -80,21 +80,25 @@ export default class NotificationService {
private async serverChan() {
const { serverChanKey } = this.params;
const url = serverChanKey.includes('SCT')
? `https://sctapi.ftqq.com/${SCKEY}.send`
: `https://sc.ftqq.com/${SCKEY}.send`;
const url = serverChanKey.startsWith('SCT')
? `https://sctapi.ftqq.com/${serverChanKey}.send`
: `https://sc.ftqq.com/${serverChanKey}.send`;
const res: any = await got
.post(url, {
timeout: this.timeout,
retry: 0,
body: `text=${this.title}&desp=${this.content}`,
body: `title=${this.title}&desp=${this.content}`,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
})
.json();
return res.errno === 0 || res.data.errno === 0;
}
private async bark() {
const { barkPush, barkSound, barkGroup } = this.params;
let { barkPush, barkSound, barkGroup } = this.params;
if (!barkPush.startsWith('http') && !barkPush.startsWith('https')) {
barkPush = `https://api.day.app/${barkPush}`;
}
const url = `${barkPush}/${encodeURIComponent(
this.title,
)}/${encodeURIComponent(
@ -119,8 +123,12 @@ export default class NotificationService {
telegramBotToken,
telegramBotUserId,
} = this.params;
const url = `https://${telegramBotApiHost}/bot${telegramBotToken}/sendMessage`;
const options = {
const url = `https://${
telegramBotApiHost ? telegramBotApiHost : 'api.telegram.org'
}/bot${telegramBotToken}/sendMessage`;
let agent;
if (telegramBotProxyHost && telegramBotProxyPort) {
const options: any = {
keepAlive: true,
keepAliveMsecs: 1000,
maxSockets: 256,
@ -129,16 +137,18 @@ export default class NotificationService {
};
const httpAgent = new HttpProxyAgent(options);
const httpsAgent = new HttpsProxyAgent(options);
agent = {
http: httpAgent,
https: httpsAgent,
};
}
const res: any = await got
.post(url, {
timeout: this.timeout,
retry: 0,
body: `chat_id=${telegramBotUserId}&text=${this.title}\n\n${this.content}&disable_web_page_preview=true`,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
agent: {
http: httpAgent,
https: httpsAgent,
},
agent,
})
.json();
return !!res.ok;