Merge pull request #60 from artgas1/fix/archive-unarchive

fix: use correct Telegram API for archive/unarchive chat
This commit is contained in:
Eugene Evstafev 2026-02-09 10:09:23 +00:00 committed by GitHub
commit 73ea210cb3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

14
main.py
View file

@ -16,7 +16,7 @@ from dotenv import load_dotenv
from mcp.server.fastmcp import FastMCP from mcp.server.fastmcp import FastMCP
from mcp.types import ToolAnnotations from mcp.types import ToolAnnotations
from pythonjsonlogger import jsonlogger from pythonjsonlogger import jsonlogger
from telethon import TelegramClient, functions, utils from telethon import TelegramClient, functions, types, utils
from telethon.sessions import StringSession from telethon.sessions import StringSession
from telethon.tl.types import ( from telethon.tl.types import (
User, User,
@ -2870,9 +2870,11 @@ async def archive_chat(chat_id: Union[int, str]) -> str:
Archive a chat. Archive a chat.
""" """
try: try:
entity = await client.get_entity(chat_id)
peer = utils.get_input_peer(entity)
await client( await client(
functions.messages.ToggleDialogPinRequest( functions.folders.EditPeerFoldersRequest(
peer=await client.get_entity(chat_id), pinned=True folder_peers=[types.InputFolderPeer(peer=peer, folder_id=1)]
) )
) )
return f"Chat {chat_id} archived." return f"Chat {chat_id} archived."
@ -2891,9 +2893,11 @@ async def unarchive_chat(chat_id: Union[int, str]) -> str:
Unarchive a chat. Unarchive a chat.
""" """
try: try:
entity = await client.get_entity(chat_id)
peer = utils.get_input_peer(entity)
await client( await client(
functions.messages.ToggleDialogPinRequest( functions.folders.EditPeerFoldersRequest(
peer=await client.get_entity(chat_id), pinned=False folder_peers=[types.InputFolderPeer(peer=peer, folder_id=0)]
) )
) )
return f"Chat {chat_id} unarchived." return f"Chat {chat_id} unarchived."