Skip to content

Добавлено управление поведением при отсутствии исходного сообщения #31

Merged
love-apples merged 1 commit intolove-apples:mainfrom
Olegt0rr:bugfix/optional-message-and-body
Feb 14, 2026
Merged

Добавлено управление поведением при отсутствии исходного сообщения #31
love-apples merged 1 commit intolove-apples:mainfrom
Olegt0rr:bugfix/optional-message-and-body

Conversation

@Olegt0rr
Copy link
Copy Markdown
Collaborator

@Olegt0rr Olegt0rr commented Feb 12, 2026

closes #30

Добавлено управление поведением при отсутствии исходного сообщения в методе send_callback.
Можно выбрасывать исключение или отправлять уведомление без сообщения

…методе send_callback. Теперь можно выбрасывать исключение или отправлять уведомление без сообщения.
Copilot AI review requested due to automatic review settings February 12, 2026 15:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Добавляет управляемое поведение для MessageCallback.answer() в ситуации, когда исходное сообщение отсутствует (например, удалено): либо выбрасывать исключение при попытке “изменить” сообщение, либо отправлять callback-уведомление без payload message.

Changes:

  • Добавлен параметр raise_if_not_exists в MessageCallback.answer() и логика обработки self.message/body is None.
  • Обновлены тесты на поведение answer() при message=None (ожидание исключения при изменении и отправка notification-only).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
maxapi/types/updates/message_callback.py Новая ветка логики для отсутствующего исходного сообщения и новый параметр управления поведением.
tests/test_messagecallback_none.py Тесты для нового поведения: raise при попытке изменения и notification-only без сообщения.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +100 to +115
if original_body is None:
# если пытаются изменить контент/вложение/связь
if (
raise_if_not_exists
and (new_text is not None or link is not None or format is not None)
):
raise ValueError(
"Невозможно изменить сообщение: исходное сообщение отсутствует"
)

# отправляем только уведомление (без поля message)
return await self._ensure_bot().send_callback(
callback_id=self.callback.callback_id,
message=None,
notification=notification,
)
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

When original_body is None and raise_if_not_exists=False, any provided new_text/link/format are silently ignored and the call is sent with message=None. This makes answer() not honor its parameters in that mode; consider either always raising when edits are requested, or still building/sending a MessageForCallback from the provided args (e.g., with empty attachments) so the request reflects the caller intent.

Copilot uses AI. Check for mistakes.
Comment on lines 65 to 75
async def answer(
self,
notification: Optional[str] = None,
new_text: Optional[str] = None,
link: Optional[NewMessageLink] = None,
notify: bool = True,
format: Optional[ParseMode] = None,
raise_if_not_exists: bool = True,
) -> "SendedCallback":
"""
Отправляет ответ на callback с возможностью изменить текст, вложения и параметры уведомления.
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

PR description mentions adding behavior control in send_callback, but the actual behavior change is implemented in MessageCallback.answer() (including a new argument and raising ValueError). If send_callback itself is intended to change, update the implementation accordingly; otherwise, please adjust the PR description to match the code change.

Copilot uses AI. Check for mistakes.
Comment on lines +16 to +21
async def send_callback(
self,
callback_id: str,
message: MessageForCallback,
notification=None,
):
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

DummyBot.send_callback is annotated as taking message: MessageForCallback, but the tests now expect message can be None (assert bot.last["message"] is None). Update the signature/type hints to accept Optional[MessageForCallback] (and ideally default it to None) to match Bot.send_callback. Also, the current parameter indentation doesn’t match the repo’s Black formatting and will be reformatted.

Copilot uses AI. Check for mistakes.
@Olegt0rr Olegt0rr marked this pull request as draft February 12, 2026 15:56
@love-apples love-apples marked this pull request as ready for review February 14, 2026 23:12
@love-apples love-apples merged commit 5d17568 into love-apples:main Feb 14, 2026
11 of 12 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.

MessageCallback.answer() при self.message is None

3 participants