Skip to content

Commit b6db6a9

Browse files
Added the class CopyTextButton and the field copy_text in the class InlineKeyboardButton allowing bots to send and receive inline buttons that copy arbitrary text.
1 parent 10c88b7 commit b6db6a9

1 file changed

Lines changed: 39 additions & 1 deletion

File tree

telebot/types.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2932,6 +2932,9 @@ class InlineKeyboardButton(Dictionaryable, JsonSerializable, JsonDeserializable)
29322932
the first row and can only be used in invoice messages.
29332933
:type pay: :obj:`bool`
29342934
2935+
:param copy_text: Optional. Description of the button that copies the specified text to the clipboard.
2936+
:type copy_text: :class:`telebot.types.CopyTextButton`
2937+
29352938
:return: Instance of the class
29362939
:rtype: :class:`telebot.types.InlineKeyboardButton`
29372940
"""
@@ -2945,13 +2948,15 @@ def de_json(cls, json_string):
29452948
obj['web_app'] = WebAppInfo.de_json(obj.get('web_app'))
29462949
if 'switch_inline_query_chosen_chat' in obj:
29472950
obj['switch_inline_query_chosen_chat'] = SwitchInlineQueryChosenChat.de_json(obj.get('switch_inline_query_chosen_chat'))
2951+
if 'copy_text' in obj:
2952+
obj['copy_text'] = CopyTextButton.de_json(obj.get('copy_text'))
29482953

29492954
return cls(**obj)
29502955

29512956
def __init__(self, text: str, url: Optional[str]=None, callback_data: Optional[str]=None, web_app: Optional[WebAppInfo]=None,
29522957
switch_inline_query: Optional[str]=None, switch_inline_query_current_chat: Optional[str]=None,
29532958
switch_inline_query_chosen_chat: Optional[SwitchInlineQueryChosenChat]=None, callback_game=None, pay: Optional[bool]=None,
2954-
login_url: Optional[LoginUrl]=None, **kwargs):
2959+
login_url: Optional[LoginUrl]=None, copy_text: Optional[CopyTextButton]=None, **kwargs):
29552960
self.text: str = text
29562961
self.url: Optional[str] = url
29572962
self.callback_data: Optional[str] = callback_data
@@ -2962,6 +2967,7 @@ def __init__(self, text: str, url: Optional[str]=None, callback_data: Optional[s
29622967
self.callback_game = callback_game # Not Implemented
29632968
self.pay: Optional[bool] = pay
29642969
self.login_url: Optional[LoginUrl] = login_url
2970+
self.copy_text: Optional[CopyTextButton] = copy_text
29652971

29662972
def to_json(self):
29672973
return json.dumps(self.to_dict())
@@ -2986,6 +2992,8 @@ def to_dict(self):
29862992
json_dict['login_url'] = self.login_url.to_dict()
29872993
if self.switch_inline_query_chosen_chat is not None:
29882994
json_dict['switch_inline_query_chosen_chat'] = self.switch_inline_query_chosen_chat.to_dict()
2995+
if self.copy_text is not None:
2996+
json_dict['copy_text'] = self.copy_text.to_dict()
29892997
return json_dict
29902998

29912999

@@ -10910,3 +10918,33 @@ def de_json(cls, json_string):
1091010918
obj['from_user'] = User.de_json(obj['from_user'])
1091110919
return cls(**obj)
1091210920

10921+
10922+
class CopyTextButton(JsonSerializable, JsonDeserializable):
10923+
"""
10924+
This object represents an inline keyboard button that copies specified text to the clipboard.
10925+
10926+
Telegram documentation: https://core.telegram.org/bots/api#copytextbutton
10927+
10928+
:param text: The text to be copied to the clipboard; 1-256 characters
10929+
:type text: :obj:`str`
10930+
10931+
:return: Instance of the class
10932+
:rtype: :class:`CopyTextButton`
10933+
"""
10934+
def __init__(self, text: str, **kwargs):
10935+
self.text: str = text
10936+
10937+
def to_json(self):
10938+
return json.dumps(self.to_dict())
10939+
10940+
def to_dict(self):
10941+
data = {
10942+
'text': self.text
10943+
}
10944+
return data
10945+
10946+
@classmethod
10947+
def de_json(cls, json_string):
10948+
if json_string is None: return None
10949+
obj = cls.check_json(json_string)
10950+
return cls(**obj)

0 commit comments

Comments
 (0)