Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions telegram_mcp/tools/chats.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,14 @@ async def get_chat(chat_id: Union[int, str], account: str = None) -> str:
record["bot"] = bool(entity.bot)
record["verified"] = bool(entity.verified)

# Photo presence — the entity carries ChatPhoto/ChatPhotoEmpty (chats/channels)
# or UserProfilePhoto/UserProfilePhotoEmpty (users). Surfaced so callers can
# detect chats that have no avatar set.
photo = getattr(entity, "photo", None)
record["has_photo"] = photo is not None and not isinstance(
photo, (types.ChatPhotoEmpty, types.UserProfilePhotoEmpty)
)

# Get unread count + last activity for THIS specific peer.
#
# NOTE: do NOT use get_dialogs(limit=1, offset_peer=entity) here. In
Expand Down
27 changes: 27 additions & 0 deletions tests/test_get_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from types import SimpleNamespace

import pytest
from telethon.tl import types as tl_types

from telegram_mcp.tools import chats

Expand Down Expand Up @@ -116,3 +117,29 @@ async def test_get_chat_marks_archived_from_folder_id(monkeypatch):

assert payload["archived"] is True
assert payload["last_message"]["sender"] == "Ada Lovelace"


@pytest.mark.asyncio
@pytest.mark.parametrize(
"photo, expected",
[
# Any real ChatPhoto/UserProfilePhoto object means an avatar is set
(SimpleNamespace(photo_id=42), True),
(tl_types.ChatPhotoEmpty(), False),
(tl_types.UserProfilePhotoEmpty(), False),
(None, False),
],
)
async def test_get_chat_reports_avatar_presence(monkeypatch, photo, expected):
entity = SimpleNamespace(title="Avatar Probe", username=None, photo=photo)
last_msg = SimpleNamespace(
date=datetime.datetime(2026, 7, 19, 1, 0, 0, tzinfo=datetime.timezone.utc),
message="hi",
sender=SimpleNamespace(first_name="Ada", last_name=None, title=None),
)
client = FakeChatClient(entity, last_msg)
_patch(monkeypatch, client, entity)

payload = _parse(await chats.get_chat(chat_id=-100123, account=None))

assert payload["has_photo"] is expected
Loading