Skip to content

Commit 6fedece

Browse files
Added unique_gift and gift
1 parent b05d209 commit 6fedece

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

telebot/types.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,12 @@ class Message(JsonDeserializable):
11241124
:param chat_shared: Optional. Service message: a chat was shared with the bot
11251125
:type chat_shared: :class:`telebot.types.ChatShared`
11261126

1127+
:param gift: Optional. Service message: a regular gift was sent or received
1128+
:type gift: :class:`telebot.types.GiftInfo`
1129+
1130+
:param unique_gift: Optional. Service message: a unique gift was sent or received
1131+
:type unique_gift: :class:`telebot.types.UniqueGiftInfo`
1132+
11271133
:param connected_website: Optional. The domain name of the website on which the user has logged in. More about
11281134
Telegram Login »
11291135
:type connected_website: :obj:`str`
@@ -1431,6 +1437,12 @@ def de_json(cls, json_string):
14311437
opts['paid_media'] = PaidMediaInfo.de_json(obj['paid_media'])
14321438
if 'refunded_payment' in obj:
14331439
opts['refunded_payment'] = RefundedPayment.de_json(obj['refunded_payment'])
1440+
if 'gift' in obj:
1441+
opts['gift'] = GiftInfo.de_json(obj['gift'])
1442+
content_type = 'gift'
1443+
if 'unique_gift' in obj:
1444+
opts['unique_gift'] = UniqueGiftInfo.de_json(obj['unique_gift'])
1445+
content_type = 'unique_gift'
14341446

14351447
return cls(message_id, from_user, date, chat, content_type, opts, json_string)
14361448

@@ -1549,6 +1561,8 @@ def __init__(self, message_id, from_user, date, chat, content_type, options, jso
15491561
self.video_chat_participants_invited: Optional[VideoChatParticipantsInvited] = None
15501562
self.web_app_data: Optional[WebAppData] = None
15511563
self.message_auto_delete_timer_changed: Optional[MessageAutoDeleteTimerChanged] = None
1564+
self.gift : Optional[GiftInfo] = None
1565+
self.unique_gift : Optional[UniqueGiftInfo] = None
15521566

15531567

15541568
for key in options:
@@ -12180,4 +12194,91 @@ def to_dict(self):
1218012194
return data
1218112195

1218212196

12197+
class GiftInfo(JsonDeserializable):
12198+
"""
12199+
This object describes a service message about a regular gift that was sent or received.
12200+
12201+
Telegram documentation: https://core.telegram.org/bots/api#giftinfo
12202+
12203+
:param gift: Information about the gift
12204+
:type gift: :class:`Gift`
12205+
12206+
:param owned_gift_id: Optional. Unique identifier of the received gift for the bot; only present for gifts received on behalf of business accounts
12207+
:type owned_gift_id: :obj:`str`
1218312208

12209+
:param convert_star_count: Optional. Number of Telegram Stars that can be claimed by the receiver by converting the gift; omitted if conversion to Telegram Stars is impossible
12210+
:type convert_star_count: :obj:`int`
12211+
12212+
:param prepaid_upgrade_star_count: Optional. Number of Telegram Stars that were prepaid by the sender for the ability to upgrade the gift
12213+
:type prepaid_upgrade_star_count: :obj:`int`
12214+
12215+
:param can_be_upgraded: Optional. True, if the gift can be upgraded to a unique gift
12216+
:type can_be_upgraded: :obj:`bool`
12217+
12218+
:param text: Optional. Text of the message that was added to the gift
12219+
:type text: :obj:`str`
12220+
12221+
:param entities: Optional. Special entities that appear in the text
12222+
:type entities: :obj:`list` of :class:`MessageEntity`
12223+
12224+
:param is_private: Optional. True, if the sender and gift text are shown only to the gift receiver; otherwise, everyone will be able to see them
12225+
:type is_private: :obj:`bool`
12226+
12227+
:return: Instance of the class
12228+
:rtype: :class:`GiftInfo`
12229+
"""
12230+
def __init__(self, gift: Gift, owned_gift_id: Optional[str] = None, convert_star_count: Optional[int] = None,
12231+
prepaid_upgrade_star_count: Optional[int] = None, can_be_upgraded: Optional[bool] = None,
12232+
text: Optional[str] = None, entities: Optional[List[MessageEntity]] = None,
12233+
is_private: Optional[bool] = None, **kwargs):
12234+
self.gift: Gift = gift
12235+
self.owned_gift_id: Optional[str] = owned_gift_id
12236+
self.convert_star_count: Optional[int] = convert_star_count
12237+
self.prepaid_upgrade_star_count: Optional[int] = prepaid_upgrade_star_count
12238+
self.can_be_upgraded: Optional[bool] = can_be_upgraded
12239+
self.text: Optional[str] = text
12240+
self.entities: Optional[List[MessageEntity]] = entities
12241+
self.is_private: Optional[bool] = is_private
12242+
@classmethod
12243+
def de_json(cls, json_string):
12244+
if json_string is None: return None
12245+
obj = cls.check_json(json_string)
12246+
obj['gift'] = Gift.de_json(obj['gift'])
12247+
if 'entities' in obj:
12248+
obj['entities'] = [MessageEntity.de_json(entity) for entity in obj['entities']]
12249+
return cls(**obj)
12250+
12251+
class UniqueGiftInfo(JsonDeserializable):
12252+
"""
12253+
This object describes a service message about a unique gift that was sent or received.
12254+
12255+
Telegram documentation: https://core.telegram.org/bots/api#uniquegiftinfo
12256+
12257+
:param gift: Information about the gift
12258+
:type gift: :class:`UniqueGift`
12259+
12260+
:param origin: Origin of the gift. Currently, either “upgrade” or “transfer”
12261+
:type origin: :obj:`str`
12262+
12263+
:param owned_gift_id: Optional. Unique identifier of the received gift for the bot; only present for gifts received on behalf of business accounts
12264+
:type owned_gift_id: :obj:`str`
12265+
12266+
:param transfer_star_count: Optional. Number of Telegram Stars that must be paid to transfer the gift; omitted if the bot cannot transfer the gift
12267+
:type transfer_star_count: :obj:`int`
12268+
12269+
:return: Instance of the class
12270+
:rtype: :class:`UniqueGiftInfo`
12271+
"""
12272+
def __init__(self, gift: UniqueGift, origin: str, owned_gift_id: Optional[str] = None,
12273+
transfer_star_count: Optional[int] = None, **kwargs):
12274+
self.gift: UniqueGift = gift
12275+
self.origin: str = origin
12276+
self.owned_gift_id: Optional[str] = owned_gift_id
12277+
self.transfer_star_count: Optional[int] = transfer_star_count
12278+
@classmethod
12279+
def de_json(cls, json_string):
12280+
if json_string is None: return None
12281+
obj = cls.check_json(json_string)
12282+
obj['gift'] = UniqueGift.de_json(obj['gift'])
12283+
return cls(**obj)
12284+

0 commit comments

Comments
 (0)