Skip to content

Update send_message.py#89

Closed
allctrl wants to merge 1 commit intolove-apples:mainfrom
allctrl:patch-1
Closed

Update send_message.py#89
allctrl wants to merge 1 commit intolove-apples:mainfrom
allctrl:patch-1

Conversation

@allctrl
Copy link
Copy Markdown

@allctrl allctrl commented Apr 6, 2026

Некорректно шлёт сообщения, если указан parse_mode.

Некорректно шлёт сообщения, если указан parse_mode.
Olegt0rr

This comment was marked as outdated.


if self.format is not None:
json["format"] = self.format.value
json["format"] = self.format
Copy link
Copy Markdown
Collaborator

@Olegt0rr Olegt0rr Apr 6, 2026

Choose a reason for hiding this comment

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

Отличная находка!

Было бы здорово добавить тест, проверяющий регрессию в этой части (например, прямую передачу 'HTML' без использования enum)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@allctrl up :)

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

PR aims to fix incorrect message sending when parse_mode/format is specified by adjusting how the format field is placed into the JSON payload for the POST /messages API call.

Changes:

  • Updated SendMessage.fetch() to send format in the JSON payload without using .value.

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


if self.format is not None:
json["format"] = self.format.value
json["format"] = self.format
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

json["format"] is now set to self.format (a ParseMode/TextFormat enum), while the rest of the codebase (e.g., EditMessage.fetch) serializes enums via .value, and existing tests assert the string value is sent (see tests/test_format_parameter.py::test_send_message_fetch_uses_format_in_json). This change will likely break tests and introduces inconsistent request payload types. Consider normalizing to a plain string (e.g., str(self.format) or .value with a fallback for already-string inputs) and update/add tests accordingly if supporting raw string parse_mode is the goal.

Suggested change
json["format"] = self.format
json["format"] = getattr(self.format, "value", self.format)

Copilot uses AI. Check for mistakes.
@bish-x
Copy link
Copy Markdown
Contributor

bish-x commented Apr 12, 2026

Привет! Отличная находка с .value@Olegt0rr тоже это отметил.

Эта проблема уже решена в PR #91 (замерджен), где:

  • Убран .value и в send_message.py, и в edit_message.py
  • В __init__ добавлена конвертация строки в enum для обратной совместимости
  • Добавлены регрессионные тесты (передача "html" строкой без enum)

Возможно, этот PR можно закрыть?

@Olegt0rr Olegt0rr closed this Apr 12, 2026
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.

4 participants