Skip to content

Commit

Permalink
fix #660 prepare parse mode for input_message_content (#661)
Browse files Browse the repository at this point in the history
* fix #660 prepare parse mode for input_message_content of InlineQueryResult

* remove redundant get

* black lint

* add towncrier patch note
  • Loading branch information
darksidecat committed Aug 16, 2021
1 parent 7cb0ac1 commit 71eb5fc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES/660.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prepare parse mode for InputMessageContent in AnswerInlineQuery method
9 changes: 8 additions & 1 deletion aiogram/methods/answer_inline_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,12 @@ class AnswerInlineQuery(TelegramMethod[bool]):

def build_request(self, bot: Bot) -> Request:
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)
21 changes: 20 additions & 1 deletion tests/test_api/test_methods/test_answer_inline_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from aiogram import Bot
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

pytestmark = pytest.mark.asyncio
Expand Down Expand Up @@ -40,3 +40,22 @@ def test_parse_mode(self, bot: MockedBot):
new_bot = Bot(token="42:TEST", parse_mode="HTML")
request = query.build_request(new_bot)
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"

0 comments on commit 71eb5fc

Please sign in to comment.