通知 TG_API_HOST 参数移除默认 https 协议,参数包含协议

This commit is contained in:
whyour 2023-12-01 09:21:27 +08:00
parent 5afec03548
commit 897b710527
4 changed files with 88 additions and 87 deletions

View File

@ -66,7 +66,7 @@ export class TelegramBotNotification extends NotificationBaseInfo {
public telegramBotProxyHost = ''; public telegramBotProxyHost = '';
public telegramBotProxyPort = ''; public telegramBotProxyPort = '';
public telegramBotProxyAuth = ''; public telegramBotProxyAuth = '';
public telegramBotApiHost = 'api.telegram.org'; public telegramBotApiHost = 'https://api.telegram.org';
} }
export class DingtalkBotNotification extends NotificationBaseInfo { export class DingtalkBotNotification extends NotificationBaseInfo {

View File

@ -234,7 +234,8 @@ export default class NotificationService {
telegramBotUserId, telegramBotUserId,
} = this.params; } = this.params;
const authStr = telegramBotProxyAuth ? `${telegramBotProxyAuth}@` : ''; const authStr = telegramBotProxyAuth ? `${telegramBotProxyAuth}@` : '';
const url = `https://${telegramBotApiHost ? telegramBotApiHost : 'api.telegram.org' const url = `${
telegramBotApiHost ? telegramBotApiHost : 'https://api.telegram.org'
}/bot${telegramBotToken}/sendMessage`; }/bot${telegramBotToken}/sendMessage`;
let agent; let agent;
if (telegramBotProxyHost && telegramBotProxyPort) { if (telegramBotProxyHost && telegramBotProxyPort) {
@ -661,7 +662,7 @@ export default class NotificationService {
); );
if (!formatUrl && !formatBody) { if (!formatUrl && !formatBody) {
throw new Error('Url 或者 Body 中必须包含 $title') throw new Error('Url 或者 Body 中必须包含 $title');
} }
const headers = parseHeaders(webhookHeaders); const headers = parseHeaders(webhookHeaders);

View File

@ -73,7 +73,7 @@ let TG_PROXY_HOST = ''; //例如:127.0.0.1(环境变量名:TG_PROXY_HOST)
let TG_PROXY_PORT = '';// 例如:1080(环境变量名:TG_PROXY_PORT) let TG_PROXY_PORT = '';// 例如:1080(环境变量名:TG_PROXY_PORT)
let TG_PROXY_AUTH = '';// tg代理配置认证参数 let TG_PROXY_AUTH = '';// tg代理配置认证参数
// Telegram api自建的反向代理地址(不懂可忽略,telegram机器人通知推送功能中非必填),默认tg官方api(环境变量名:TG_API_HOST) // Telegram api自建的反向代理地址(不懂可忽略,telegram机器人通知推送功能中非必填),默认tg官方api(环境变量名:TG_API_HOST)
let TG_API_HOST = 'api.telegram.org'; let TG_API_HOST = 'https://api.telegram.org';
// =======================================钉钉机器人通知设置区域=========================================== // =======================================钉钉机器人通知设置区域===========================================
// 此处填你钉钉 bot 的webhook例如5a544165465465645d0f31dca676e7bd07415asdasd // 此处填你钉钉 bot 的webhook例如5a544165465465645d0f31dca676e7bd07415asdasd
// (环境变量名 DD_BOT_TOKEN) // (环境变量名 DD_BOT_TOKEN)
@ -645,7 +645,7 @@ function tgBotNotify(text, desp) {
return new Promise((resolve) => { return new Promise((resolve) => {
if (TG_BOT_TOKEN && TG_USER_ID) { if (TG_BOT_TOKEN && TG_USER_ID) {
const options = { const options = {
url: `https://${TG_API_HOST}/bot${TG_BOT_TOKEN}/sendMessage`, url: `${TG_API_HOST}/bot${TG_BOT_TOKEN}/sendMessage`,
json: { json: {
chat_id: `${TG_USER_ID}`, chat_id: `${TG_USER_ID}`,
text: `${text}\n\n${desp}`, text: `${text}\n\n${desp}`,

View File

@ -534,7 +534,7 @@ def telegram_bot(title: str, content: str) -> None:
print("tg 服务启动") print("tg 服务启动")
if push_config.get("TG_API_HOST"): if push_config.get("TG_API_HOST"):
url = f"https://{push_config.get('TG_API_HOST')}/bot{push_config.get('TG_BOT_TOKEN')}/sendMessage" url = f"{push_config.get('TG_API_HOST')}/bot{push_config.get('TG_BOT_TOKEN')}/sendMessage"
else: else:
url = ( url = (
f"https://api.telegram.org/bot{push_config.get('TG_BOT_TOKEN')}/sendMessage" f"https://api.telegram.org/bot{push_config.get('TG_BOT_TOKEN')}/sendMessage"