Skip to content

Commit 06f3b79

Browse files
paneveshtclaude
andcommitted
feat(chats): report avatar presence (has_photo) in get_chat
The entity carries ChatPhoto/ChatPhotoEmpty (chats/channels) or UserProfilePhoto/UserProfilePhotoEmpty (users); surface a boolean so callers can detect chats that have no avatar set without downloading media. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 4956950 commit 06f3b79

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

telegram_mcp/tools/chats.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,14 @@ async def get_chat(chat_id: Union[int, str], account: str = None) -> str:
637637
record["bot"] = bool(entity.bot)
638638
record["verified"] = bool(entity.verified)
639639

640+
# Photo presence — the entity carries ChatPhoto/ChatPhotoEmpty (chats/channels)
641+
# or UserProfilePhoto/UserProfilePhotoEmpty (users). Surfaced so callers can
642+
# detect chats that have no avatar set.
643+
photo = getattr(entity, "photo", None)
644+
record["has_photo"] = photo is not None and not isinstance(
645+
photo, (types.ChatPhotoEmpty, types.UserProfilePhotoEmpty)
646+
)
647+
640648
# Get unread count + last activity for THIS specific peer.
641649
#
642650
# NOTE: do NOT use get_dialogs(limit=1, offset_peer=entity) here. In

tests/test_get_chat.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from types import SimpleNamespace
44

55
import pytest
6+
from telethon.tl import types as tl_types
67

78
from telegram_mcp.tools import chats
89

@@ -116,3 +117,29 @@ async def test_get_chat_marks_archived_from_folder_id(monkeypatch):
116117

117118
assert payload["archived"] is True
118119
assert payload["last_message"]["sender"] == "Ada Lovelace"
120+
121+
122+
@pytest.mark.asyncio
123+
@pytest.mark.parametrize(
124+
"photo, expected",
125+
[
126+
# Any real ChatPhoto/UserProfilePhoto object means an avatar is set
127+
(SimpleNamespace(photo_id=42), True),
128+
(tl_types.ChatPhotoEmpty(), False),
129+
(tl_types.UserProfilePhotoEmpty(), False),
130+
(None, False),
131+
],
132+
)
133+
async def test_get_chat_reports_avatar_presence(monkeypatch, photo, expected):
134+
entity = SimpleNamespace(title="Avatar Probe", username=None, photo=photo)
135+
last_msg = SimpleNamespace(
136+
date=datetime.datetime(2026, 7, 19, 1, 0, 0, tzinfo=datetime.timezone.utc),
137+
message="hi",
138+
sender=SimpleNamespace(first_name="Ada", last_name=None, title=None),
139+
)
140+
client = FakeChatClient(entity, last_msg)
141+
_patch(monkeypatch, client, entity)
142+
143+
payload = _parse(await chats.get_chat(chat_id=-100123, account=None))
144+
145+
assert payload["has_photo"] is expected

0 commit comments

Comments
 (0)