mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 10:11:52 +00:00
Add InlineQuery.answer
This commit is contained in:
parent
6bba2da814
commit
65002b9280
4 changed files with 67 additions and 1 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import TYPE_CHECKING, Optional
|
from typing import TYPE_CHECKING, List, Optional
|
||||||
|
|
||||||
from pydantic import Field
|
from pydantic import Field
|
||||||
|
|
||||||
|
|
@ -9,6 +9,8 @@ from .base import TelegramObject
|
||||||
if TYPE_CHECKING: # pragma: no cover
|
if TYPE_CHECKING: # pragma: no cover
|
||||||
from .location import Location
|
from .location import Location
|
||||||
from .user import User
|
from .user import User
|
||||||
|
from .inline_query_result import InlineQueryResult
|
||||||
|
from ..methods import AnswerInlineQuery
|
||||||
|
|
||||||
|
|
||||||
class InlineQuery(TelegramObject):
|
class InlineQuery(TelegramObject):
|
||||||
|
|
@ -29,3 +31,33 @@ class InlineQuery(TelegramObject):
|
||||||
"""Offset of the results to be returned, can be controlled by the bot"""
|
"""Offset of the results to be returned, can be controlled by the bot"""
|
||||||
location: Optional[Location] = None
|
location: Optional[Location] = None
|
||||||
"""Sender location, only for bots that request user location"""
|
"""Sender location, only for bots that request user location"""
|
||||||
|
|
||||||
|
def answer(
|
||||||
|
self,
|
||||||
|
results: List[InlineQueryResult],
|
||||||
|
cache_time: Optional[int] = None,
|
||||||
|
is_personal: Optional[bool] = None,
|
||||||
|
next_offset: Optional[str] = None,
|
||||||
|
switch_pm_text: Optional[str] = None,
|
||||||
|
switch_pm_parameter: Optional[str] = None,
|
||||||
|
) -> AnswerInlineQuery:
|
||||||
|
"""
|
||||||
|
:param results:
|
||||||
|
:param cache_time:
|
||||||
|
:param is_personal:
|
||||||
|
:param next_offset:
|
||||||
|
:param switch_pm_text:
|
||||||
|
:param switch_pm_parameter:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
from ..methods import AnswerInlineQuery
|
||||||
|
|
||||||
|
return AnswerInlineQuery(
|
||||||
|
inline_query_id=self.id,
|
||||||
|
results=results,
|
||||||
|
cache_time=cache_time,
|
||||||
|
is_personal=is_personal,
|
||||||
|
next_offset=next_offset,
|
||||||
|
switch_pm_text=switch_pm_text,
|
||||||
|
switch_pm_parameter=switch_pm_parameter,
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -62,4 +62,6 @@ return AnswerInlineQuery(...)
|
||||||
## Related pages:
|
## Related pages:
|
||||||
|
|
||||||
- [Official documentation](https://core.telegram.org/bots/api#answerinlinequery)
|
- [Official documentation](https://core.telegram.org/bots/api#answerinlinequery)
|
||||||
|
- [aiogram.types.InlineQuery](../types/inline_query.md)
|
||||||
- [aiogram.types.InlineQueryResult](../types/inline_query_result.md)
|
- [aiogram.types.InlineQueryResult](../types/inline_query_result.md)
|
||||||
|
- [Aliases](../types/inline_query.md#aliases)
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,23 @@ This object represents an incoming inline query. When the user sends an empty qu
|
||||||
- `from aiogram.api.types import InlineQuery`
|
- `from aiogram.api.types import InlineQuery`
|
||||||
- `from aiogram.api.types.inline_query import InlineQuery`
|
- `from aiogram.api.types.inline_query import InlineQuery`
|
||||||
|
|
||||||
|
## Aliases
|
||||||
|
|
||||||
|
Aliases is always returns related API method (Awaitable) and can be used directly or as answer's into webhook.
|
||||||
|
|
||||||
|
### Answer
|
||||||
|
|
||||||
|
This method has the same specification with the API but without `inline_query_id` argument.
|
||||||
|
|
||||||
|
| Answer method | Alias for | Description |
|
||||||
|
| - | - | - |
|
||||||
|
| `answer` | [Bot.answer_inline_query](../methods/answer_inline_query.md) | Answer to inline query |
|
||||||
|
|
||||||
|
|
||||||
## Related pages:
|
## Related pages:
|
||||||
|
|
||||||
- [Official documentation](https://core.telegram.org/bots/api#inlinequery)
|
- [Official documentation](https://core.telegram.org/bots/api#inlinequery)
|
||||||
- [aiogram.types.Location](../types/location.md)
|
- [aiogram.types.Location](../types/location.md)
|
||||||
- [aiogram.types.User](../types/user.md)
|
- [aiogram.types.User](../types/user.md)
|
||||||
|
- [aiogram.methods.AnswerInlineQuery](../methods/answer_inline_query.md)
|
||||||
|
|
||||||
|
|
|
||||||
17
tests/test_api/test_types/test_inline_query.py
Normal file
17
tests/test_api/test_types/test_inline_query.py
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
from aiogram.api.methods import AnswerInlineQuery
|
||||||
|
from aiogram.api.types import InlineQuery, User
|
||||||
|
|
||||||
|
|
||||||
|
class TestInlineQuery:
|
||||||
|
def test_answer_alias(self):
|
||||||
|
inline_query = InlineQuery(
|
||||||
|
id="id",
|
||||||
|
from_user=User(id=42, is_bot=False, first_name="name"),
|
||||||
|
query="query",
|
||||||
|
offset="",
|
||||||
|
)
|
||||||
|
|
||||||
|
api_method = inline_query.answer([])
|
||||||
|
|
||||||
|
assert isinstance(api_method, AnswerInlineQuery)
|
||||||
|
assert api_method.inline_query_id == inline_query.id
|
||||||
Loading…
Add table
Add a link
Reference in a new issue