From 9ea0bc609a3912a86f88ad0b0b0d2b80e4b7a51f Mon Sep 17 00:00:00 2001 From: xuchao3 Date: Thu, 12 Jun 2025 13:56:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0telegram=20api=E4=BB=A3?= =?UTF-8?q?=E7=90=86=E5=9C=B0=E5=9D=80=20#4266?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/core/config.py | 4 +++- app/modules/telegram/telegram.py | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/core/config.py b/app/core/config.py index db80a9dd..558d4030 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -243,7 +243,7 @@ class ConfigModel(BaseModel): GITHUB_TOKEN: Optional[str] = None # Github代理服务器,格式:https://mirror.ghproxy.com/ GITHUB_PROXY: Optional[str] = '' - # pip镜像站点,格式:https://pypi.tuna.tsinghua.edu.cn/simple + # pip镜像站点,格式:https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple PIP_PROXY: Optional[str] = '' # 指定的仓库Github token,多个仓库使用,分隔,格式:{user1}/{repo1}:ghp_****,{user2}/{repo2}:github_pat_**** REPO_GITHUB_TOKEN: Optional[str] = None @@ -286,6 +286,8 @@ class ConfigModel(BaseModel): DEFAULT_SUB: Optional[str] = "zh-cn" # Docker Client API地址 DOCKER_CLIENT_API: Optional[str] = "tcp://127.0.0.1:38379" + # telegram bot api 地址,格式:https://api.telegram.org + TG_API_URL: Optional[str] = None class Settings(BaseSettings, ConfigModel, LogConfigModel): diff --git a/app/modules/telegram/telegram.py b/app/modules/telegram/telegram.py index 3c33e071..90ad80e0 100644 --- a/app/modules/telegram/telegram.py +++ b/app/modules/telegram/telegram.py @@ -4,6 +4,7 @@ import uuid from pathlib import Path from threading import Event from typing import Optional, List, Dict +from urllib.parse import urljoin import telebot from telebot import apihelper @@ -17,8 +18,11 @@ from app.utils.common import retry from app.utils.http import RequestUtils from app.utils.string import StringUtils -apihelper.proxy = settings.PROXY - +if settings.TG_API_URL: + apihelper.API_URL = urljoin(settings.TG_API_URL, '/bot{0}/{1}') + apihelper.FILE_URL = urljoin(settings.TG_API_URL, '/file/bot{0}/{1}') +else: + apihelper.proxy = settings.PROXY class Telegram: _ds_url = f"http://127.0.0.1:{settings.PORT}/api/v1/message?token={settings.API_TOKEN}"