Skip to content

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.py
index 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 dataclass
from typing import Callable, Awaitable
from aiogram import Bot, Dispatcher, Router, F
from aiogram.client.default import DefaultBotProperties
from aiogram.enums import ParseMode, ChatType
-from aiogram.exceptions import TelegramBadRequest
from 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 SimpleRequestHandler
from helpers.errors import format_error
from 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 None
bot_info = None
for 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 connection
async def test_token(token: str) -> tuple[bool, str]:
diff --git a/plugins/_telegram_integration/helpers/handler.py b/plugins/_telegram_integration/helpers/handler.py
index 917c5065d..517662859 100644
--- a/plugins/_telegram_integration/helpers/handler.py
+++ b/plugins/_telegram_integration/helpers/handler.py
@@ -6,8 +6,8 @@ import uuid
from 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, files
from helpers import message_queue as mq
from helpers.notification import NotificationManager, NotificationType, NotificationPriority
from 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"
# Transient
CTX_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 prompt
agent = context.agent0
user_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 None
diff --git a/plugins/_telegram_integration/helpers/telegram_client.py b/plugins/_telegram_integration/helpers/telegram_client.py
index 35054f73a..bbac88e82 100644
--- a/plugins/_telegram_integration/helpers/telegram_client.py
+++ b/plugins/_telegram_integration/helpers/telegram_client.py
@@ -1,11 +1,8 @@
-import asyncio
import os
-from typing import BinaryIO
from aiogram import Bot
from aiogram.exceptions import TelegramBadRequest
from 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 keyboards
def build_inline_keyboard(