- Notifications
You must be signed in to change notification settings - Fork5.7k
Business info#4183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Business info#4183
Changes fromall commits
Commits
Show all changes
17 commits Select commitHold shift + click to select a range
1c510e3
Add `BusinessIntro` class and `Chat.business_intro`.
aelkheir0a9a6dd
Add `business_intro` tests.
aelkheir1a5259a
Add toc entry for `BusinessIntro`.
aelkheir955b561
Merge remote-tracking branch 'upstream/api-7.2' into business-info
aelkheir11e1cb2
Add `BusinessLocation` and `Chat.business_location`.
aelkheir3111a69
Add tests for `business_location`.
aelkheir3ea8c15
Add doc entries for `BisnessLocation`.
aelkheir2f61888
Freeze added classes (cause of a test failure).
aelkheiree35700
Fix accidental fixture rename.
aelkheiree43314
Add `BusinessOpeningHours` and related code.
aelkheir88ce711
Add tests
aelkheirda3df0e
Add doc refs
aelkheireb8d32b
Adress review comments.
aelkheire7d6e78
Adapt tests in `test_chat` for testing new properties.
aelkheir2fcf167
Merge remote-tracking branch 'upstream/api-7.2' into business-info
aelkheir9c1af08
Update BusinessOpeningHourInterval example
harshil219784450
Add `{opening/closing}_time` and tests.
aelkheirFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletionsdocs/source/telegram.at-tree.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletionsdocs/source/telegram.businessintro.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
BusinessIntro | ||
================== | ||
..autoclass::telegram.BusinessIntro | ||
:members: | ||
:show-inheritance: |
6 changes: 6 additions & 0 deletionsdocs/source/telegram.businesslocation.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
BusinessLocation | ||
================== | ||
..autoclass::telegram.BusinessLocation | ||
:members: | ||
:show-inheritance: |
6 changes: 6 additions & 0 deletionsdocs/source/telegram.businessopeninghours.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
BusinessOpeningHours | ||
==================== | ||
..autoclass::telegram.BusinessOpeningHours | ||
:members: | ||
:show-inheritance: |
6 changes: 6 additions & 0 deletionsdocs/source/telegram.businessopeninghoursinterval.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
BusinessOpeningHoursInterval | ||
============================ | ||
..autoclass::telegram.BusinessOpeningHoursInterval | ||
:members: | ||
:show-inheritance: |
13 changes: 12 additions & 1 deletiontelegram/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
262 changes: 261 additions & 1 deletiontelegram/_business.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -20,9 +20,11 @@ | ||
"""This module contains the Telegram Business related classes.""" | ||
from datetime import datetime | ||
from typing import TYPE_CHECKING, Optional, Sequence, Tuple | ||
from telegram._chat import Chat | ||
from telegram._files.location import Location | ||
from telegram._files.sticker import Sticker | ||
from telegram._telegramobject import TelegramObject | ||
from telegram._user import User | ||
from telegram._utils.argumentparsing import parse_sequence_arg | ||
@@ -183,3 +185,261 @@ def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["BusinessMess | ||
data["chat"] = Chat.de_json(data.get("chat"), bot) | ||
return super().de_json(data=data, bot=bot) | ||
class BusinessIntro(TelegramObject): | ||
""" | ||
This object represents the intro of a business account. | ||
harshil21 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
Objects of this class are comparable in terms of equality. | ||
Two objects of this class are considered equal, if their | ||
:attr:`title`, :attr:`message` and :attr:`sticker` are equal. | ||
.. versionadded:: NEXT.VERSION | ||
Args: | ||
title (:obj:`str`, optional): Title text of the business intro. | ||
message (:obj:`str`, optional): Message text of the business intro. | ||
sticker (:class:`telegram.Sticker`, optional): Sticker of the business intro. | ||
Attributes: | ||
title (:obj:`str`): Optional. Title text of the business intro. | ||
message (:obj:`str`): Optional. Message text of the business intro. | ||
sticker (:class:`telegram.Sticker`): Optional. Sticker of the business intro. | ||
""" | ||
__slots__ = ( | ||
"message", | ||
"sticker", | ||
"title", | ||
) | ||
def __init__( | ||
self, | ||
title: Optional[str] = None, | ||
message: Optional[str] = None, | ||
sticker: Optional[Sticker] = None, | ||
*, | ||
api_kwargs: Optional[JSONDict] = None, | ||
): | ||
super().__init__(api_kwargs=api_kwargs) | ||
self.title: Optional[str] = title | ||
self.message: Optional[str] = message | ||
self.sticker: Optional[Sticker] = sticker | ||
self._id_attrs = (self.title, self.message, self.sticker) | ||
self._freeze() | ||
@classmethod | ||
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["BusinessIntro"]: | ||
"""See :meth:`telegram.TelegramObject.de_json`.""" | ||
data = cls._parse_data(data) | ||
if not data: | ||
return None | ||
data["sticker"] = Sticker.de_json(data.get("sticker"), bot) | ||
return super().de_json(data=data, bot=bot) | ||
class BusinessLocation(TelegramObject): | ||
""" | ||
This object represents the location of a business account. | ||
Objects of this class are comparable in terms of equality. | ||
Two objects of this class are considered equal, if their | ||
:attr:`address` is equal. | ||
.. versionadded:: NEXT.VERSION | ||
Args: | ||
address (:obj:`str`): Address of the business. | ||
location (:class:`telegram.Location`, optional): Location of the business. | ||
Attributes: | ||
address (:obj:`str`): Address of the business. | ||
location (:class:`telegram.Location`): Optional. Location of the business. | ||
""" | ||
__slots__ = ( | ||
"address", | ||
"location", | ||
) | ||
def __init__( | ||
self, | ||
address: str, | ||
location: Optional[Location] = None, | ||
*, | ||
api_kwargs: Optional[JSONDict] = None, | ||
): | ||
super().__init__(api_kwargs=api_kwargs) | ||
self.address: str = address | ||
self.location: Optional[Location] = location | ||
self._id_attrs = (self.address,) | ||
self._freeze() | ||
@classmethod | ||
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["BusinessLocation"]: | ||
"""See :meth:`telegram.TelegramObject.de_json`.""" | ||
data = cls._parse_data(data) | ||
if not data: | ||
return None | ||
data["location"] = Location.de_json(data.get("location"), bot) | ||
return super().de_json(data=data, bot=bot) | ||
class BusinessOpeningHoursInterval(TelegramObject): | ||
""" | ||
This object represents the time intervals describing business opening hours. | ||
Objects of this class are comparable in terms of equality. | ||
Two objects of this class are considered equal, if their | ||
:attr:`opening_minute` and :attr:`closing_minute` are equal. | ||
.. versionadded:: NEXT.VERSION | ||
Examples: | ||
A day has (24 * 60 =) 1440 minutes, a week has (7 * 1440 =) 10080 minutes. | ||
Starting the the minute's sequence from Monday, example values of | ||
:attr:`opening_minute`, :attr:`closing_minute` will map to the following day times: | ||
* Monday - 8am to 8:30pm: | ||
- ``opening_minute = 480`` :guilabel:`8 * 60` | ||
- ``closing_minute = 1230`` :guilabel:`20 * 60 + 30` | ||
* Tuesday - 24 hours: | ||
- ``opening_minute = 1440`` :guilabel:`24 * 60` | ||
- ``closing_minute = 2879`` :guilabel:`2 * 24 * 60 - 1` | ||
* Sunday - 12am - 11:58pm: | ||
- ``opening_minute = 8640`` :guilabel:`6 * 24 * 60` | ||
- ``closing_minute = 10078`` :guilabel:`7 * 24 * 60 - 2` | ||
Args: | ||
opening_minute (:obj:`int`): The minute's sequence number in a week, starting on Monday, | ||
marking the start of the time interval during which the business is open; | ||
0 - 7 * 24 * 60. | ||
closing_minute (:obj:`int`): The minute's | ||
sequence number in a week, starting on Monday, marking the end of the time interval | ||
during which the business is open; 0 - 8 * 24 * 60 | ||
Attributes: | ||
opening_minute (:obj:`int`): The minute's sequence number in a week, starting on Monday, | ||
marking the start of the time interval during which the business is open; | ||
0 - 7 * 24 * 60. | ||
closing_minute (:obj:`int`): The minute's | ||
sequence number in a week, starting on Monday, marking the end of the time interval | ||
during which the business is open; 0 - 8 * 24 * 60 | ||
""" | ||
__slots__ = ("_closing_time", "_opening_time", "closing_minute", "opening_minute") | ||
def __init__( | ||
self, | ||
opening_minute: int, | ||
closing_minute: int, | ||
*, | ||
api_kwargs: Optional[JSONDict] = None, | ||
): | ||
super().__init__(api_kwargs=api_kwargs) | ||
self.opening_minute: int = opening_minute | ||
self.closing_minute: int = closing_minute | ||
harshil21 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
self._opening_time: Optional[Tuple[int, int, int]] = None | ||
self._closing_time: Optional[Tuple[int, int, int]] = None | ||
self._id_attrs = (self.opening_minute, self.closing_minute) | ||
self._freeze() | ||
def _parse_minute(self, minute: int) -> Tuple[int, int, int]: | ||
return (minute // 1440, minute % 1440 // 60, minute % 1440 % 60) | ||
@property | ||
def opening_time(self) -> Tuple[int, int, int]: | ||
"""Convenience attribute. A :obj:`tuple` parsed from :attr:`opening_minute`. It contains | ||
the `weekday`, `hour` and `minute` in the same ranges as :attr:`datetime.datetime.weekday`, | ||
:attr:`datetime.datetime.hour` and :attr:`datetime.datetime.minute` | ||
Returns: | ||
Tuple[:obj:`int`, :obj:`int`, :obj:`int`]: | ||
""" | ||
if self._opening_time is None: | ||
self._opening_time = self._parse_minute(self.opening_minute) | ||
return self._opening_time | ||
@property | ||
def closing_time(self) -> Tuple[int, int, int]: | ||
"""Convenience attribute. A :obj:`tuple` parsed from :attr:`closing_minute`. It contains | ||
the `weekday`, `hour` and `minute` in the same ranges as :attr:`datetime.datetime.weekday`, | ||
:attr:`datetime.datetime.hour` and :attr:`datetime.datetime.minute` | ||
Returns: | ||
Tuple[:obj:`int`, :obj:`int`, :obj:`int`]: | ||
""" | ||
if self._closing_time is None: | ||
self._closing_time = self._parse_minute(self.closing_minute) | ||
return self._closing_time | ||
class BusinessOpeningHours(TelegramObject): | ||
""" | ||
This object represents the opening hours of a business account. | ||
Objects of this class are comparable in terms of equality. | ||
Two objects of this class are considered equal, if their | ||
:attr:`time_zone_name` and :attr:`opening_hours` are equal. | ||
.. versionadded:: NEXT.VERSION | ||
Args: | ||
time_zone_name (:obj:`str`): Unique name of the time zone for which the opening | ||
hours are defined. | ||
opening_hours (Sequence[:class:`telegram.BusinessOpeningHoursInterval`]): List of | ||
time intervals describing business opening hours. | ||
Attributes: | ||
time_zone_name (:obj:`str`): Unique name of the time zone for which the opening | ||
hours are defined. | ||
opening_hours (Sequence[:class:`telegram.BusinessOpeningHoursInterval`]): List of | ||
time intervals describing business opening hours. | ||
""" | ||
__slots__ = ("opening_hours", "time_zone_name") | ||
def __init__( | ||
self, | ||
time_zone_name: str, | ||
opening_hours: Sequence[BusinessOpeningHoursInterval], | ||
*, | ||
api_kwargs: Optional[JSONDict] = None, | ||
): | ||
super().__init__(api_kwargs=api_kwargs) | ||
self.time_zone_name: str = time_zone_name | ||
self.opening_hours: Sequence[BusinessOpeningHoursInterval] = parse_sequence_arg( | ||
opening_hours | ||
) | ||
self._id_attrs = (self.time_zone_name, self.opening_hours) | ||
self._freeze() | ||
@classmethod | ||
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["BusinessOpeningHours"]: | ||
"""See :meth:`telegram.TelegramObject.de_json`.""" | ||
data = cls._parse_data(data) | ||
if not data: | ||
return None | ||
data["opening_hours"] = BusinessOpeningHoursInterval.de_list( | ||
data.get("opening_hours"), bot | ||
) | ||
return super().de_json(data=data, bot=bot) |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.