Skip to content

Agent Zero AI framework

chore(telegram): remove unused imports, fix exception masking, and add explicit boundary checks

keyboardstaffeb92fde0091c
diff --git a/plugins/_telegram_integration/api/webhook.py b/plugins/_telegram_integration/api/webhook.py
index be9c11f7c..9056ae054 100644
--- a/plugins/_telegram_integration/api/webhook.py
+++ b/plugins/_telegram_integration/api/webhook.py
@@ -20,7 +20,7 @@ class TelegramWebhook(ApiHandler):
async def process(self, input: dict, request: Request) -> dict | Response:
from aiogram.types import Update
- from plugins._telegram_integration.helpers.bot_manager import get_bot, get_all_bots
+ from plugins._telegram_integration.helpers.bot_manager import get_bot
# Identify which bot this update is for
bot_name = request.args.get("bot", "")
diff --git a/plugins/_telegram_integration/helpers/handler.py b/plugins/_telegram_integration/helpers/handler.py
index 517662859..40159be5c 100644
--- a/plugins/_telegram_integration/helpers/handler.py
+++ b/plugins/_telegram_integration/helpers/handler.py
@@ -492,7 +492,10 @@ async def send_telegram_reply(
PrintStyle.error(f"Telegram reply failed: {error}")
return error
finally:
- await reply_bot.session.close()
+ try:
+ await reply_bot.session.close()
+ except Exception:
+ pass
# Helpers
diff --git a/plugins/_telegram_integration/helpers/telegram_client.py b/plugins/_telegram_integration/helpers/telegram_client.py
index bbac88e82..bd509b6ea 100644
--- a/plugins/_telegram_integration/helpers/telegram_client.py
+++ b/plugins/_telegram_integration/helpers/telegram_client.py
@@ -188,7 +188,7 @@ def _split_text(text: str, max_len: int) -> list[str]:
break
# Try to split at newline
split_at = text.rfind("\n", 0, max_len)
- if split_at < max_len // 2:
+ if split_at == -1 or split_at < max_len // 2:
split_at = max_len
chunks.append(text[:split_at])
text = text[split_at:].lstrip("\n")