Добавлено управление поведением при отсутствии исходного сообщения #31
Conversation
…методе send_callback. Теперь можно выбрасывать исключение или отправлять уведомление без сообщения.
There was a problem hiding this comment.
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.
| 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, | ||
| ) |
There was a problem hiding this comment.
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.
| 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 с возможностью изменить текст, вложения и параметры уведомления. |
There was a problem hiding this comment.
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.
| async def send_callback( | ||
| self, | ||
| callback_id: str, | ||
| message: MessageForCallback, | ||
| notification=None, | ||
| ): |
There was a problem hiding this comment.
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.
closes #30
Добавлено управление поведением при отсутствии исходного сообщения в методе send_callback.
Можно выбрасывать исключение или отправлять уведомление без сообщения