From 4936b1914429d6283141f6e4f5872dfff86e49cd Mon Sep 17 00:00:00 2001 From: jneeee Date: Wed, 15 Apr 2026 17:41:16 -0700 Subject: [PATCH] fix(cron): guard telegram import in _send_to_platform against ImportError Wrap the TelegramAdapter import in _send_to_platform() with a try/except ImportError guard, matching the existing Feishu pattern in the same function. When python-telegram-bot is not installed, the import no longer crashes the cron scheduler. Instead, MAX_MESSAGE_LENGTH falls back to a hardcoded 4096. The _send_telegram() function already had its own ImportError guard for the telegram package; this fixes the remaining bare import of TelegramAdapter in the platform-routing function. --- tools/send_message_tool.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/send_message_tool.py b/tools/send_message_tool.py index 8c673c170..27edf0eec 100644 --- a/tools/send_message_tool.py +++ b/tools/send_message_tool.py @@ -327,10 +327,16 @@ async def _send_to_platform(platform, pconfig, chat_id, message, thread_id=None, """ from gateway.config import Platform from gateway.platforms.base import BasePlatformAdapter, utf16_len - from gateway.platforms.telegram import TelegramAdapter from gateway.platforms.discord import DiscordAdapter from gateway.platforms.slack import SlackAdapter + # Telegram adapter import is optional (requires python-telegram-bot) + try: + from gateway.platforms.telegram import TelegramAdapter + _telegram_available = True + except ImportError: + _telegram_available = False + # Feishu adapter import is optional (requires lark-oapi) try: from gateway.platforms.feishu import FeishuAdapter @@ -349,7 +355,7 @@ async def _send_to_platform(platform, pconfig, chat_id, message, thread_id=None, # Platform message length limits (from adapter class attributes) _MAX_LENGTHS = { - Platform.TELEGRAM: TelegramAdapter.MAX_MESSAGE_LENGTH, + Platform.TELEGRAM: TelegramAdapter.MAX_MESSAGE_LENGTH if _telegram_available else 4096, Platform.DISCORD: DiscordAdapter.MAX_MESSAGE_LENGTH, Platform.SLACK: SlackAdapter.MAX_MESSAGE_LENGTH, }