mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 10:11:52 +00:00
Add ShippingQuery.answer
This commit is contained in:
parent
cf12da0c4a
commit
83730276bc
4 changed files with 64 additions and 1 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
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 .shipping_address import ShippingAddress
|
from .shipping_address import ShippingAddress
|
||||||
from .user import User
|
from .user import User
|
||||||
|
from ..methods import AnswerShippingQuery
|
||||||
|
from ..types import ShippingOption
|
||||||
|
|
||||||
|
|
||||||
class ShippingQuery(TelegramObject):
|
class ShippingQuery(TelegramObject):
|
||||||
|
|
@ -26,3 +28,24 @@ class ShippingQuery(TelegramObject):
|
||||||
"""Bot specified invoice payload"""
|
"""Bot specified invoice payload"""
|
||||||
shipping_address: ShippingAddress
|
shipping_address: ShippingAddress
|
||||||
"""User specified shipping address"""
|
"""User specified shipping address"""
|
||||||
|
|
||||||
|
def answer(
|
||||||
|
self,
|
||||||
|
ok: bool,
|
||||||
|
shipping_options: Optional[List[ShippingOption]] = None,
|
||||||
|
error_message: Optional[str] = None,
|
||||||
|
) -> AnswerShippingQuery:
|
||||||
|
"""
|
||||||
|
:param ok:
|
||||||
|
:param shipping_options:
|
||||||
|
:param error_message:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
from ..methods import AnswerShippingQuery
|
||||||
|
|
||||||
|
return AnswerShippingQuery(
|
||||||
|
shipping_query_id=self.id,
|
||||||
|
ok=ok,
|
||||||
|
shipping_options=shipping_options,
|
||||||
|
error_message=error_message,
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -58,3 +58,5 @@ return AnswerShippingQuery(...)
|
||||||
|
|
||||||
- [Official documentation](https://core.telegram.org/bots/api#answershippingquery)
|
- [Official documentation](https://core.telegram.org/bots/api#answershippingquery)
|
||||||
- [aiogram.types.ShippingOption](../types/shipping_option.md)
|
- [aiogram.types.ShippingOption](../types/shipping_option.md)
|
||||||
|
- [aiogram.types.ShippingQuery](../types/shipping_query.md)
|
||||||
|
- [Aliases](../types/shipping_query.md#aliases)
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,22 @@ This object contains information about an incoming shipping query.
|
||||||
- `from aiogram.api.types import ShippingQuery`
|
- `from aiogram.api.types import ShippingQuery`
|
||||||
- `from aiogram.api.types.shipping_query import ShippingQuery`
|
- `from aiogram.api.types.shipping_query import ShippingQuery`
|
||||||
|
|
||||||
|
## 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_shipping_query](../methods/answer_shipping_query.md) | Answer to shipping query |
|
||||||
|
|
||||||
|
|
||||||
## Related pages:
|
## Related pages:
|
||||||
|
|
||||||
- [Official documentation](https://core.telegram.org/bots/api#shippingquery)
|
- [Official documentation](https://core.telegram.org/bots/api#shippingquery)
|
||||||
- [aiogram.types.ShippingAddress](../types/shipping_address.md)
|
- [aiogram.types.ShippingAddress](../types/shipping_address.md)
|
||||||
- [aiogram.types.User](../types/user.md)
|
- [aiogram.types.User](../types/user.md)
|
||||||
|
- [aiogram.methods.AnswerShippingQuery](../methods/answer_shipping_query.md)
|
||||||
|
|
|
||||||
24
tests/test_api/test_types/test_shipping_query.py
Normal file
24
tests/test_api/test_types/test_shipping_query.py
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
from aiogram.api.methods import AnswerShippingQuery
|
||||||
|
from aiogram.api.types import ShippingAddress, ShippingQuery, User
|
||||||
|
|
||||||
|
|
||||||
|
class TestInlineQuery:
|
||||||
|
def test_answer_alias(self):
|
||||||
|
shipping_query = ShippingQuery(
|
||||||
|
id="id",
|
||||||
|
from_user=User(id=42, is_bot=False, first_name="name"),
|
||||||
|
invoice_payload="payload",
|
||||||
|
shipping_address=ShippingAddress(
|
||||||
|
country_code="foo",
|
||||||
|
state="foo",
|
||||||
|
city="foo",
|
||||||
|
street_line1="foo",
|
||||||
|
street_line2="foo",
|
||||||
|
post_code="foo",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
api_method = shipping_query.answer(True)
|
||||||
|
|
||||||
|
assert isinstance(api_method, AnswerShippingQuery)
|
||||||
|
assert api_method.shipping_query_id == shipping_query.id
|
||||||
Loading…
Add table
Add a link
Reference in a new issue