Skip to content
This repository was archived by the owner on Mar 3, 2025. It is now read-only.

Commit 9c2c151

Browse files
authored
add custom base_url #2
1 parent 1a9717d commit 9c2c151

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

tg_message_adapter.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
@register_platform_adapter("telegram", "telegram 适配器", default_config_tmpl={
2323
"telegram_token": "your_token",
2424
"start_message": "Hello, I'm AstrBot!",
25-
"提示": "由于 Telegram 无法在中国大陆访问,如果你的网络环境为中国大陆,记得在 `其他配置` 处设置代理!"
25+
"telegram_api_base_url": "https://api.telegram.org/bot",
26+
"提示": "由于 Telegram 无法在中国大陆 / Iran 访问,如果你的网络环境为中国大陆 / Iran,记得在 `其他配置` 处设置代理!"
2627
})
2728
class TelegramPlatformAdapter(Platform):
2829

@@ -47,7 +48,11 @@ def meta(self) -> PlatformMetadata:
4748

4849
@override
4950
async def run(self):
50-
self.application = ApplicationBuilder().token(self.config['telegram_token']).build()
51+
base_url = self.config.get("telegram_api_base_url", "https://api.telegram.org/bot")
52+
if not base_url:
53+
base_url = "https://api.telegram.org/bot"
54+
55+
self.application = ApplicationBuilder().token(self.config['telegram_token']).base_url(base_url).build()
5156
message_handler = TelegramMessageHandler(
5257
filters=None,
5358
callback=self.convert_message
@@ -98,4 +103,4 @@ async def handle_msg(self, message: AstrBotMessage):
98103
session_id=message.session_id,
99104
client=self.client
100105
)
101-
self.commit_event(message_event)
106+
self.commit_event(message_event)

0 commit comments

Comments
 (0)