From ed0f2e853d4b5748503c271a22ad1e95f54985bf Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 4 Jan 2026 01:01:28 +0000 Subject: [PATCH] fix(main): Make _safe_send_message robust against AttributeError The `_safe_send_message` helper function was expecting a `telegram.Chat` object but was sometimes called with a `telegram.Message` object, causing an `AttributeError: 'Message' object has no attribute 'send_message'`. This commit makes the function more robust by checking if the passed object has a `.chat` attribute. If it does, the function uses that attribute to send the message; otherwise, it uses the passed object directly. This resolves the traceback seen in the `start` command handler and prevents similar errors in other parts of the code that use this helper. The function's docstring has also been updated to reflect this new, more flexible behavior. --- src/main.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.py b/src/main.py index 87af32f..1f56cdc 100644 --- a/src/main.py +++ b/src/main.py @@ -263,14 +263,16 @@ async def _safe_send_message( Pro version: Safely sends a message with language-aware parse mode. Args: - chat: Chat object to send message to + chat: Chat or Message object to send message to. text: Message text user_id: User ID for language detection reply_markup: Optional reply markup **kwargs: Additional arguments for send_message """ + # If a Message object is passed, extract its Chat object. + target_chat = chat.chat if hasattr(chat, 'chat') else chat parse_mode = _get_user_parse_mode(user_id) if user_id else get_parse_mode() - return await chat.send_message( + return await target_chat.send_message( escape_text(text, parse_mode), parse_mode=parse_mode, reply_markup=reply_markup,