From 382246d89e82d305730cb6ea56bced242f115d76 Mon Sep 17 00:00:00 2001 From: gvidonind-commits <45360663+artgas1@users.noreply.github.com> Date: Mon, 9 Feb 2026 06:36:27 +0300 Subject: [PATCH] fix: use correct Telegram API for archive/unarchive chat archive_chat and unarchive_chat were using ToggleDialogPinRequest which pins/unpins dialogs instead of archiving them. Replace with folders.EditPeerFoldersRequest using folder_id=1 (Archive) and folder_id=0 (Main) which is the correct API for moving chats to/from the Archive folder. --- main.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 454ab2b..2c7f9d5 100644 --- a/main.py +++ b/main.py @@ -16,7 +16,7 @@ from dotenv import load_dotenv from mcp.server.fastmcp import FastMCP from mcp.types import ToolAnnotations from pythonjsonlogger import jsonlogger -from telethon import TelegramClient, functions, utils +from telethon import TelegramClient, functions, types, utils from telethon.sessions import StringSession from telethon.tl.types import ( User, @@ -2870,9 +2870,11 @@ async def archive_chat(chat_id: Union[int, str]) -> str: Archive a chat. """ try: + entity = await client.get_entity(chat_id) + peer = utils.get_input_peer(entity) await client( - functions.messages.ToggleDialogPinRequest( - peer=await client.get_entity(chat_id), pinned=True + functions.folders.EditPeerFoldersRequest( + folder_peers=[types.InputFolderPeer(peer=peer, folder_id=1)] ) ) return f"Chat {chat_id} archived." @@ -2891,9 +2893,11 @@ async def unarchive_chat(chat_id: Union[int, str]) -> str: Unarchive a chat. """ try: + entity = await client.get_entity(chat_id) + peer = utils.get_input_peer(entity) await client( - functions.messages.ToggleDialogPinRequest( - peer=await client.get_entity(chat_id), pinned=False + functions.folders.EditPeerFoldersRequest( + folder_peers=[types.InputFolderPeer(peer=peer, folder_id=0)] ) ) return f"Chat {chat_id} unarchived."