Skip to content

feat: full-fidelity message data in get_history / get_messages - #133

Merged
chigwell merged 2 commits into
chigwell:mainfrom
artgas1:feat/full-message-fidelity-upstream
Jun 3, 2026
Merged

feat: full-fidelity message data in get_history / get_messages#133
chigwell merged 2 commits into
chigwell:mainfrom
artgas1:feat/full-message-fidelity-upstream

Conversation

@artgas1

@artgas1 artgas1 commented May 26, 2026

Copy link
Copy Markdown
Contributor

Problem

get_history / get_messages were lossy: they returned only id/sender/date/reply/text (+ the recently added media flag) and dropped everything else the Telethon message object already carries in the same response. So albums, forwards, edits, inline buttons, hidden link URLs, service messages etc. were invisible without extra calls.

Change

  • New message_to_dict(msg) — API-faithful, compact (empty fields omitted): media, grouped_id (album), reply_to, forwarded (date/from_name), via_bot_id, edited, pinned, engagement (views/forwards/reactions), comments, inline buttons, link_urls (entity URLs), service action, ttl_period, sender_id, out.
  • get_history → returns these full dicts (JSON via format_tool_result).
  • get_messagesformat_message_line with all key flags (📎 media, album, forwarded, edited, via_bot, pinned, buttons, service) and [empty] when no text.
  • Fix get_media_label: check web_preview before photo so link-preview images aren't mislabeled 📎 photo.

No extra API calls — all data is already on the fetched message. Builds on #132.

🤖 Generated with Claude Code

Listings were lossy — they returned only id/sender/date/reply/text and
dropped everything else the Telethon message object already carries in the
same response. Now they reflect the API object faithfully.

- New message_to_dict(msg): media, grouped_id (album), reply_to, forwarded,
  via_bot_id, edited, pinned, engagement (views/forwards/reactions), comments,
  inline buttons, link_urls (hidden entity URLs), service action, ttl_period,
  sender_id, out. Empty fields omitted.
- get_history → returns these full dicts (JSON via format_tool_result).
- get_messages → format_message_line with all key flags (📎 media, album,
  forwarded, edited, via_bot, pinned, buttons, service) + [empty] for no text.
- Fix get_media_label: check web_preview BEFORE photo so link-preview images
  are not mislabeled as "📎 photo".

No extra API calls — all data is already on the fetched message.

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>

@chigwell chigwell left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @artgas1, thank you for your contribution! Could I please ask you to rewrite the comments in the code in English to keep them consistent with the rest of the codebase? Thank you!

Comment thread telegram_mcp/tools/messages.py Outdated
Comment thread telegram_mcp/tools/messages.py Outdated
try:
# стикер/голос/видео/аудио/гиф — это тоже document, поэтому проверяем их РАНЬШЕ document
# Веб-превью ссылки — НЕ вложение. Проверяем ПЕРВЫМ: у сообщения со
# ссылкой Telethon отдаёт картинку превью через msg.photo, иначе она

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# ссылкой Telethon отдаёт картинку превью через msg.photo, иначе она
# link, Telethon returns the preview image via msg.photo; otherwise it would

Comment thread telegram_mcp/tools/messages.py Outdated
# стикер/голос/видео/аудио/гиф — это тоже document, поэтому проверяем их РАНЬШЕ document
# Веб-превью ссылки — НЕ вложение. Проверяем ПЕРВЫМ: у сообщения со
# ссылкой Telethon отдаёт картинку превью через msg.photo, иначе она
# ложно пометилась бы как "photo".

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# ложно пометилась бы как "photo".
# be incorrectly classified as a "photo".

Comment thread telegram_mcp/tools/messages.py Outdated
# ложно пометилась бы как "photo".
if getattr(msg, "web_preview", None) is not None:
return ""
# Стикер/голос/видео/аудио/гиф — это тоже document, проверяем РАНЬШЕ document.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Стикер/голос/видео/аудио/гиф — это тоже document, проверяем РАНЬШЕ document.
# Sticker/voice/video/audio/GIF are also represented as documents, so check
# them BEFORE the generic document handler.

Comment thread telegram_mcp/tools/messages.py Outdated


def _inline_button_texts(msg):
"""Тексты inline-кнопок сообщения (плоским списком), [] если нет."""

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Тексты inline-кнопок сообщения (плоским списком), [] если нет."""
"""Inline button texts of the message (flat list), [] if none."""

Comment thread telegram_mcp/tools/messages.py Outdated


def message_to_dict(msg) -> dict:
"""API-полный, но компактный вид сообщения Telethon (пустые поля опускаем).

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""API-полный, но компактный вид сообщения Telethon (пустые поля опускаем).
"""API-complete but compact Telethon message view (omit empty fields).

Comment thread telegram_mcp/tools/messages.py Outdated
def message_to_dict(msg) -> dict:
"""API-полный, но компактный вид сообщения Telethon (пустые поля опускаем).

Цель — чтобы вывод MCP по полноте соответствовал объекту API, а не терял

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Цельчтобы вывод MCP по полноте соответствовал объекту API, а не терял
The goal is for the MCP output to match the API object in completeness, rather

Comment thread telegram_mcp/tools/messages.py Outdated
"""API-полный, но компактный вид сообщения Telethon (пустые поля опускаем).

Цель — чтобы вывод MCP по полноте соответствовал объекту API, а не терял
данные (медиа, альбомы, пересылки, правки, кнопки, реакции и т.п.).

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
данные (медиа, альбомы, пересылки, правки, кнопки, реакции и т.п.).
than losing data such as media, albums, forwards, edits, buttons, reactions,

Comment thread telegram_mcp/tools/messages.py Outdated

Цель — чтобы вывод MCP по полноте соответствовал объекту API, а не терял
данные (медиа, альбомы, пересылки, правки, кнопки, реакции и т.п.).
Все эти поля уже приходят в объекте сообщения тем же запросом get_messages.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Все эти поля уже приходят в объекте сообщения тем же запросом get_messages.
and so on. All these fields are already present in the message object returned
by the same get_messages request.

Comment thread telegram_mcp/tools/messages.py Outdated


def format_message_line(msg) -> str:
"""Однострочный человекочитаемый вид сообщения со ВСЕМИ ключевыми флагами."""

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Однострочный человекочитаемый вид сообщения со ВСЕМИ ключевыми флагами."""
"""Single-line human-readable message representation with ALL key flags."""

artgas1 added a commit to artgas1/telegram-mcp that referenced this pull request Jun 3, 2026
Address review feedback on PR chigwell#133: translate all comments and docstrings
in telegram_mcp/tools/messages.py to English for codebase consistency.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@artgas1
artgas1 force-pushed the feat/full-message-fidelity-upstream branch from 45e9832 to 9a6e276 Compare June 3, 2026 15:44
Address review feedback on PR chigwell#133: translate all comments and docstrings
in telegram_mcp/tools/messages.py to English for codebase consistency.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@artgas1
artgas1 force-pushed the feat/full-message-fidelity-upstream branch from 9a6e276 to fd69b8b Compare June 3, 2026 17:42
@artgas1

artgas1 commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @chigwell! All comments and docstrings in telegram_mcp/tools/messages.py are now rewritten in English (applied all your suggestions + the remaining inline comments). CI is green. Ready for re-review 🙏

@chigwell
chigwell merged commit 17b5e05 into chigwell:main Jun 3, 2026
4 checks passed
KiaroSama pushed a commit to KiaroSama/telegram-mcp that referenced this pull request Aug 25, 2026
Address review feedback on PR chigwell#133: translate all comments and docstrings
in telegram_mcp/tools/messages.py to English for codebase consistency.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
KiaroSama pushed a commit to KiaroSama/telegram-mcp that referenced this pull request Aug 25, 2026
…ty-upstream

feat: full-fidelity message data in get_history / get_messages
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.

2 participants