Fix bug in edit_message_media action for Telegram bot (#162762)

This commit is contained in:
hanwg
2026-02-12 00:55:14 +08:00
committed by Franck Nijhof
parent 6a5f7bf424
commit fb79fa37f8
2 changed files with 26 additions and 8 deletions
+25 -7
View File
@@ -659,23 +659,41 @@ class TelegramNotificationService:
media: InputMedia
if media_type == InputMediaType.ANIMATION:
media = InputMediaAnimation(file_content, caption=kwargs.get(ATTR_CAPTION))
media = InputMediaAnimation(
file_content,
caption=kwargs.get(ATTR_CAPTION),
parse_mode=params[ATTR_PARSER],
)
elif media_type == InputMediaType.AUDIO:
media = InputMediaAudio(file_content, caption=kwargs.get(ATTR_CAPTION))
media = InputMediaAudio(
file_content,
caption=kwargs.get(ATTR_CAPTION),
parse_mode=params[ATTR_PARSER],
)
elif media_type == InputMediaType.DOCUMENT:
media = InputMediaDocument(file_content, caption=kwargs.get(ATTR_CAPTION))
media = InputMediaDocument(
file_content,
caption=kwargs.get(ATTR_CAPTION),
parse_mode=params[ATTR_PARSER],
)
elif media_type == InputMediaType.PHOTO:
media = InputMediaPhoto(file_content, caption=kwargs.get(ATTR_CAPTION))
media = InputMediaPhoto(
file_content,
caption=kwargs.get(ATTR_CAPTION),
parse_mode=params[ATTR_PARSER],
)
else:
media = InputMediaVideo(file_content, caption=kwargs.get(ATTR_CAPTION))
media = InputMediaVideo(
file_content,
caption=kwargs.get(ATTR_CAPTION),
parse_mode=params[ATTR_PARSER],
)
return await self._send_msg(
self.bot.edit_message_media,
"Error editing message media",
params[ATTR_MESSAGE_TAG],
media=media,
caption=kwargs.get(ATTR_CAPTION),
parse_mode=params[ATTR_PARSER],
chat_id=chat_id,
message_id=message_id,
inline_message_id=inline_message_id,
@@ -1163,7 +1163,7 @@ async def test_edit_message_media(
mock.assert_called_once()
assert mock.call_args[1]["media"].__class__.__name__ == expected_media_class
assert mock.call_args[1]["media"].caption == "mock caption"
assert mock.call_args[1]["parse_mode"] == PARSER_MD
assert mock.call_args[1]["media"].parse_mode == PARSER_MD
assert mock.call_args[1]["chat_id"] == 123456
assert mock.call_args[1]["message_id"] == 12345
assert mock.call_args[1]["reply_markup"] == InlineKeyboardMarkup(