mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-08 17:13:56 +00:00
Add CallbackQuery.answer
This commit is contained in:
parent
8e54cce58e
commit
6bba2da814
4 changed files with 56 additions and 0 deletions
|
|
@ -9,6 +9,7 @@ from .base import TelegramObject
|
|||
if TYPE_CHECKING: # pragma: no cover
|
||||
from .message import Message
|
||||
from .user import User
|
||||
from ..methods import AnswerCallbackQuery
|
||||
|
||||
|
||||
class CallbackQuery(TelegramObject):
|
||||
|
|
@ -43,3 +44,29 @@ class CallbackQuery(TelegramObject):
|
|||
data in this field."""
|
||||
game_short_name: Optional[str] = None
|
||||
"""Short name of a Game to be returned, serves as the unique identifier for the game"""
|
||||
|
||||
def answer(
|
||||
self,
|
||||
text: Optional[str] = None,
|
||||
show_alert: Optional[bool] = None,
|
||||
url: Optional[str] = None,
|
||||
cache_time: Optional[int] = None,
|
||||
) -> AnswerCallbackQuery:
|
||||
"""
|
||||
Answer to callback query
|
||||
|
||||
:param text:
|
||||
:param show_alert:
|
||||
:param url:
|
||||
:param cache_time:
|
||||
:return:
|
||||
"""
|
||||
from ..methods import AnswerCallbackQuery
|
||||
|
||||
return AnswerCallbackQuery(
|
||||
callback_query_id=self.id,
|
||||
text=text,
|
||||
show_alert=show_alert,
|
||||
url=url,
|
||||
cache_time=cache_time,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -60,3 +60,5 @@ return AnswerCallbackQuery(...)
|
|||
## Related pages:
|
||||
|
||||
- [Official documentation](https://core.telegram.org/bots/api#answercallbackquery)
|
||||
- [aiogram.types.CallbackQuery](../types/callback_query.md)
|
||||
- [Aliases](../types/callback_query.md#aliases)
|
||||
|
|
|
|||
|
|
@ -27,8 +27,21 @@ NOTE: After the user presses a callback button, Telegram clients will display a
|
|||
- `from aiogram.api.types import CallbackQuery`
|
||||
- `from aiogram.api.types.callback_query import CallbackQuery`
|
||||
|
||||
## 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 `callback_query_id` argument.
|
||||
|
||||
| Answer method | Alias for | Description |
|
||||
| - | - | - |
|
||||
| `answer` | [Bot.answer_callback_query](../methods/answer_callback_query.md) | Answer to callback query |
|
||||
|
||||
## Related pages:
|
||||
|
||||
- [Official documentation](https://core.telegram.org/bots/api#callbackquery)
|
||||
- [aiogram.types.Message](../types/message.md)
|
||||
- [aiogram.types.User](../types/user.md)
|
||||
- [aiogram.methods.AnswerCallbackQuery](../methods/answer_callback_query.md)
|
||||
|
|
|
|||
14
tests/test_api/test_types/test_callback_query.py
Normal file
14
tests/test_api/test_types/test_callback_query.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
from aiogram.api.methods import AnswerCallbackQuery
|
||||
from aiogram.api.types import CallbackQuery, User
|
||||
|
||||
|
||||
class TestCallbackQuery:
|
||||
def test_answer_alias(self):
|
||||
callback_query = CallbackQuery(
|
||||
id="id", from_user=User(id=42, is_bot=False, first_name="name"), chat_instance="chat"
|
||||
)
|
||||
|
||||
api_method = callback_query.answer()
|
||||
|
||||
assert isinstance(api_method, AnswerCallbackQuery)
|
||||
assert api_method.callback_query_id == callback_query.id
|
||||
Loading…
Add table
Add a link
Reference in a new issue