Skip to content

fix(contacts): find direct chat when get_contact_chats is called with a username - #308

Merged
chigwell merged 1 commit into
chigwell:mainfrom
axisrow:ao/telegram-mcp-2/fix/297-contact-chats-username
Oct 17, 2026
Merged

chigwell merged 1 commit into
chigwell:mainfrom
axisrow:ao/telegram-mcp-2/fix/297-contact-chats-username

Conversation

@axisrow

@axisrow axisrow commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What changed

get_contact_chats compared dialog.entity.id == contact_id, where contact_id is the raw argument: for a username call it is a string, so the int-vs-str comparison was always False and the direct chat was never matched. The comparison now uses the resolved contact.id, mirroring get_direct_chat_by_contact (contacts.py:163).

Before

Contact Alice (id=999, @alice_smith) has an existing private chat:

get_contact_chats(contact_id="@alice_smith")
→ "No chats found with Alice Smith (ID: @alice_smith)."

get_contact_chats(contact_id=999)
→ {"results": [{"chat_id": 999, "type": "Private", ...}]}

Same contact: the username lookup reported nothing, the numeric lookup worked.

After

Same contact, same calls:

get_contact_chats(contact_id="@alice_smith")
→ {"results": [{"chat_id": 999, "type": "Private", "unread": 2}],
   "contact_name": "Alice Smith", "contact_id": "@alice_smith"}

get_contact_chats(contact_id=999)
→ {"results": [{"chat_id": 999, "type": "Private", ...}]}

Both forms now return the private chat; the numeric path is unchanged.

Tests

  • New tests/test_contact_chats.py: direct chat found by @username (failed before) + numeric-id regression case.
  • Full suite: uv run pytest -q → 1196 passed.

Fixes #297

🤖 Generated with Claude Code

…t_chats

get_contact_chats compared dialog.entity.id against the raw contact_id
argument, so a username string never matched any dialog (int vs str,
always False) and the tool reported "No chats found". Compare against
the resolved contact.id instead, mirroring get_direct_chat_by_contact.

Fixes chigwell#297 (chigwell/telegram-mcp)

Co-Authored-By: Claude Code <[email protected]>
@chigwell
chigwell merged commit fe8c042 into chigwell:main Oct 17, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

get_contact_chats never finds the direct chat when called with a username

2 participants