Agent Zero AI framework
refactor(telegram): cleanup dead code, unused imports, constants
keyboardstaff3389682bd13f
diff --git a/plugins/_telegram_integration/helpers/bot_manager.py b/plugins/_telegram_integration/helpers/bot_manager.pyindex 1f3d1277d..4776510f9 100644--- a/plugins/_telegram_integration/helpers/bot_manager.py+++ b/plugins/_telegram_integration/helpers/bot_manager.py@@ -1,14 +1,13 @@import asyncio-from dataclasses import dataclass, field+from dataclasses import dataclassfrom typing import Callable, Awaitablefrom aiogram import Bot, Dispatcher, Router, Ffrom aiogram.client.default import DefaultBotPropertiesfrom aiogram.enums import ParseMode, ChatType-from aiogram.exceptions import TelegramBadRequestfrom aiogram.filters import Command, CommandStart-from aiogram.types import Message, CallbackQuery, Update-from aiogram.webhook.aiohttp_server import SimpleRequestHandler, setup_application+from aiogram.types import Message, CallbackQuery+from aiogram.webhook.aiohttp_server import SimpleRequestHandlerfrom helpers.errors import format_errorfrom helpers.print_style import PrintStyle@@ -96,7 +95,6 @@ def _make_group_mention_filter(handler: Callable, bot: Bot):if message.chat.type == ChatType.PRIVATE:return# Use cached bot_info from the instance- inst = get_bot(handler.__name__.split('_')[-1]) if hasattr(handler, '__name__') else Nonebot_info = Nonefor b in _bots.values():if b.bot is bot:@@ -205,10 +203,6 @@ async def stop_bot(name: str):PrintStyle.info(f"Telegram ({name}): stopped")-async def stop_all_bots():- for name in list(_bots.keys()):- await stop_bot(name)-# Test connectionasync def test_token(token: str) -> tuple[bool, str]:diff --git a/plugins/_telegram_integration/helpers/handler.py b/plugins/_telegram_integration/helpers/handler.pyindex 917c5065d..517662859 100644--- a/plugins/_telegram_integration/helpers/handler.py+++ b/plugins/_telegram_integration/helpers/handler.py@@ -6,8 +6,8 @@ import uuidfrom aiogram.types import Message as TgMessage, CallbackQuery-from agent import Agent, AgentContext, AgentContextType, UserMessage-from helpers import guids, plugins, files+from agent import AgentContext, UserMessage+from helpers import plugins, filesfrom helpers import message_queue as mqfrom helpers.notification import NotificationManager, NotificationType, NotificationPriorityfrom helpers.persist_chat import save_tmp_chat@@ -28,7 +28,6 @@ CTX_TG_BOT = "telegram_bot"CTX_TG_CHAT_ID = "telegram_chat_id"CTX_TG_USER_ID = "telegram_user_id"CTX_TG_USERNAME = "telegram_username"-CTX_TG_LAST_MSG_ID = "telegram_last_msg_id"# TransientCTX_TG_ATTACHMENTS = "_telegram_response_attachments"@@ -210,9 +209,6 @@ async def handle_message(message: TgMessage, bot_name: str, bot_cfg: dict):text = _extract_message_content(message)attachments = await _download_attachments(instance.bot, message, bot_name=bot_name)- # Store last incoming message ID for reply threading- context.data[CTX_TG_LAST_MSG_ID] = message.message_id-# Build user message with promptagent = context.agent0user_msg = agent.read_prompt(@@ -508,10 +504,3 @@ def _format_user(user) -> str:name += f" (@{user.username})"return name.strip() or str(user.id)--def find_context_for_bot_chat(bot_name: str, chat_id: int) -> AgentContext | None:- """Find active context matching a Telegram bot + chat_id."""- for ctx in AgentContext.all():- if ctx.data.get(CTX_TG_BOT) == bot_name and ctx.data.get(CTX_TG_CHAT_ID) == chat_id:- return ctx- return Nonediff --git a/plugins/_telegram_integration/helpers/telegram_client.py b/plugins/_telegram_integration/helpers/telegram_client.pyindex 35054f73a..bbac88e82 100644--- a/plugins/_telegram_integration/helpers/telegram_client.py+++ b/plugins/_telegram_integration/helpers/telegram_client.py@@ -1,11 +1,8 @@-import asyncioimport os-from typing import BinaryIOfrom aiogram import Botfrom aiogram.exceptions import TelegramBadRequestfrom aiogram.types import (- BufferedInputFile,FSInputFile,InlineKeyboardButton,InlineKeyboardMarkup,@@ -105,26 +102,6 @@ async def send_photo(return None-async def send_file_bytes(- bot: Bot,- chat_id: int,- content: bytes,- filename: str,- caption: str = "",-) -> int | None:- """Send file from bytes content."""- try:- input_file = BufferedInputFile(content, filename=filename)- msg = await bot.send_document(- chat_id=chat_id,- document=input_file,- caption=caption[:1024] if caption else None,- )- return msg.message_id- except Exception as e:- PrintStyle.error(f"Telegram send_file_bytes failed: {format_error(e)}")- return None-# Inline keyboardsdef build_inline_keyboard(