mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
* fix #660 prepare parse mode for input_message_content of InlineQueryResult * remove redundant get * black lint * add towncrier patch note
This commit is contained in:
parent
7cb0ac1ee2
commit
71eb5fc44e
3 changed files with 29 additions and 2 deletions
1
CHANGES/660.bugfix
Normal file
1
CHANGES/660.bugfix
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Prepare parse mode for InputMessageContent in AnswerInlineQuery method
|
||||||
|
|
@ -37,5 +37,12 @@ class AnswerInlineQuery(TelegramMethod[bool]):
|
||||||
|
|
||||||
def build_request(self, bot: Bot) -> Request:
|
def build_request(self, bot: Bot) -> Request:
|
||||||
data: Dict[str, Any] = self.dict()
|
data: Dict[str, Any] = self.dict()
|
||||||
prepare_parse_mode(bot, data["results"])
|
|
||||||
|
input_message_contents = []
|
||||||
|
for result in data["results"]:
|
||||||
|
input_message_content = result.get("input_message_content", None)
|
||||||
|
if input_message_content is not None:
|
||||||
|
input_message_contents.append(input_message_content)
|
||||||
|
|
||||||
|
prepare_parse_mode(bot, data["results"] + input_message_contents)
|
||||||
return Request(method="answerInlineQuery", data=data)
|
return Request(method="answerInlineQuery", data=data)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import pytest
|
||||||
|
|
||||||
from aiogram import Bot
|
from aiogram import Bot
|
||||||
from aiogram.methods import AnswerInlineQuery, Request
|
from aiogram.methods import AnswerInlineQuery, Request
|
||||||
from aiogram.types import InlineQueryResult, InlineQueryResultPhoto
|
from aiogram.types import InlineQueryResult, InlineQueryResultPhoto, InputTextMessageContent
|
||||||
from tests.mocked_bot import MockedBot
|
from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
pytestmark = pytest.mark.asyncio
|
pytestmark = pytest.mark.asyncio
|
||||||
|
|
@ -40,3 +40,22 @@ class TestAnswerInlineQuery:
|
||||||
new_bot = Bot(token="42:TEST", parse_mode="HTML")
|
new_bot = Bot(token="42:TEST", parse_mode="HTML")
|
||||||
request = query.build_request(new_bot)
|
request = query.build_request(new_bot)
|
||||||
assert request.data["results"][0]["parse_mode"] == "HTML"
|
assert request.data["results"][0]["parse_mode"] == "HTML"
|
||||||
|
|
||||||
|
def test_parse_mode_input_message_content(self, bot: MockedBot):
|
||||||
|
query = AnswerInlineQuery(
|
||||||
|
inline_query_id="query id",
|
||||||
|
results=[
|
||||||
|
InlineQueryResultPhoto(
|
||||||
|
id="result id",
|
||||||
|
photo_url="photo",
|
||||||
|
thumb_url="thumb",
|
||||||
|
input_message_content=InputTextMessageContent(message_text="test"),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
request = query.build_request(bot)
|
||||||
|
assert request.data["results"][0]["input_message_content"]["parse_mode"] is None
|
||||||
|
|
||||||
|
new_bot = Bot(token="42:TEST", parse_mode="HTML")
|
||||||
|
request = query.build_request(new_bot)
|
||||||
|
assert request.data["results"][0]["input_message_content"]["parse_mode"] == "HTML"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue