Skip to content

Commit fb3405e

Browse files
Added the field style to the classes KeyboardButton and InlineKeyboardButton, allowing bots to change the color of buttons.
1 parent 5898931 commit fb3405e

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

telebot/types.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2914,6 +2914,9 @@ class KeyboardButton(Dictionaryable, JsonSerializable):
29142914
if the owner of the bot has a Telegram Premium subscription.
29152915
:type icon_custom_emoji_id: :obj:`str`
29162916

2917+
:param style: Optional. Style of the button. Must be one of “danger” (red), “success” (green) or “primary” (blue). If omitted, then an app-specific style is used.
2918+
:type style: :obj:`str`
2919+
29172920
:param request_contact: Optional. If True, the user's phone number will be sent as a contact when the button is
29182921
pressed. Available in private chats only.
29192922
:type request_contact: :obj:`bool`
@@ -2948,7 +2951,7 @@ def __init__(self, text: str, request_contact: Optional[bool]=None,
29482951
request_location: Optional[bool]=None, request_poll: Optional[KeyboardButtonPollType]=None,
29492952
web_app: Optional[WebAppInfo]=None, request_user: Optional[KeyboardButtonRequestUser]=None,
29502953
request_chat: Optional[KeyboardButtonRequestChat]=None, request_users: Optional[KeyboardButtonRequestUsers]=None,
2951-
icon_custom_emoji_id: Optional[str]=None, **kwargs):
2954+
icon_custom_emoji_id: Optional[str]=None, style: Optional[str]=None, **kwargs):
29522955
self.text: str = text
29532956
self.request_contact: Optional[bool] = request_contact
29542957
self.request_location: Optional[bool] = request_location
@@ -2957,6 +2960,7 @@ def __init__(self, text: str, request_contact: Optional[bool]=None,
29572960
self.request_chat: Optional[KeyboardButtonRequestChat] = request_chat
29582961
self.request_users: Optional[KeyboardButtonRequestUsers] = request_users
29592962
self.icon_custom_emoji_id: Optional[str] = icon_custom_emoji_id
2963+
self.style: Optional[str] = style
29602964
if request_user is not None:
29612965
log_deprecation_warning('The parameter "request_user" is deprecated, use "request_users" instead')
29622966
if self.request_users is None:
@@ -2983,6 +2987,8 @@ def to_dict(self):
29832987
json_dict['request_chat'] = self.request_chat.to_dict()
29842988
if self.icon_custom_emoji_id is not None:
29852989
json_dict['icon_custom_emoji_id'] = self.icon_custom_emoji_id
2990+
if self.style is not None:
2991+
json_dict['style'] = self.style
29862992
return json_dict
29872993

29882994

@@ -3111,6 +3117,10 @@ class InlineKeyboardButton(Dictionaryable, JsonSerializable, JsonDeserializable)
31113117
group and supergroup chats if the owner of the bot has a Telegram Premium subscription.
31123118
:type icon_custom_emoji_id: :obj:`str`
31133119

3120+
:param style: Optional. Style of the button. Must be one of “danger” (red), “success” (green) or “primary” (blue). If omitted,
3121+
then an app-specific style is used.
3122+
:type style: :obj:`str`
3123+
31143124
:param url: Optional. HTTP or tg:// URL to be opened when the button is pressed. Links tg://user?id=<user_id> can be
31153125
used to mention a user by their ID without using a username, if this is allowed by their privacy settings.
31163126
:type url: :obj:`str`
@@ -3176,7 +3186,7 @@ def de_json(cls, json_string):
31763186
def __init__(self, text: str, url: Optional[str]=None, callback_data: Optional[str]=None, web_app: Optional[WebAppInfo]=None,
31773187
switch_inline_query: Optional[str]=None, switch_inline_query_current_chat: Optional[str]=None,
31783188
switch_inline_query_chosen_chat: Optional[SwitchInlineQueryChosenChat]=None, callback_game=None, pay: Optional[bool]=None,
3179-
login_url: Optional[LoginUrl]=None, copy_text: Optional[CopyTextButton]=None, icon_custom_emoji_id: Optional[str]=None, **kwargs):
3189+
login_url: Optional[LoginUrl]=None, copy_text: Optional[CopyTextButton]=None, icon_custom_emoji_id: Optional[str]=None, style: Optional[str]=None, **kwargs):
31803190
self.text: str = text
31813191
self.url: Optional[str] = url
31823192
self.callback_data: Optional[str] = callback_data
@@ -3189,6 +3199,7 @@ def __init__(self, text: str, url: Optional[str]=None, callback_data: Optional[s
31893199
self.login_url: Optional[LoginUrl] = login_url
31903200
self.copy_text: Optional[CopyTextButton] = copy_text
31913201
self.icon_custom_emoji_id: Optional[str] = icon_custom_emoji_id
3202+
self.style: Optional[str] = style
31923203

31933204
def to_json(self):
31943205
return json.dumps(self.to_dict())
@@ -3217,6 +3228,8 @@ def to_dict(self):
32173228
json_dict['copy_text'] = self.copy_text.to_dict()
32183229
if self.icon_custom_emoji_id is not None:
32193230
json_dict['icon_custom_emoji_id'] = self.icon_custom_emoji_id
3231+
if self.style is not None:
3232+
json_dict['style'] = self.style
32203233
return json_dict
32213234

32223235

0 commit comments

Comments
 (0)