Skip to content

Commit 5898931

Browse files
Added the field icon_custom_emoji_id to the classes KeyboardButton and InlineKeyboardButton, allowing bots to show a custom emoji on buttons if they are able to use custom emoji in the message.
1 parent 74f0b2b commit 5898931

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

telebot/types.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2905,10 +2905,15 @@ class KeyboardButton(Dictionaryable, JsonSerializable):
29052905

29062906
Telegram Documentation: https://core.telegram.org/bots/api#keyboardbutton
29072907

2908-
:param text: Text of the button. If none of the optional fields are used, it will be sent as a message when the button is
2909-
pressed
2908+
:param text: Text of the button. If none of the fields other than text, icon_custom_emoji_id, and style are used,
2909+
it will be sent as a message when the button is pressed
29102910
:type text: :obj:`str`
29112911

2912+
:param icon_custom_emoji_id: Optional. Unique identifier of the custom emoji shown before the text of the button.
2913+
Can only be used by bots that purchased additional usernames on Fragment or in the messages directly sent by the bot to private, group and supergroup chats
2914+
if the owner of the bot has a Telegram Premium subscription.
2915+
:type icon_custom_emoji_id: :obj:`str`
2916+
29122917
:param request_contact: Optional. If True, the user's phone number will be sent as a contact when the button is
29132918
pressed. Available in private chats only.
29142919
:type request_contact: :obj:`bool`
@@ -2942,14 +2947,16 @@ class KeyboardButton(Dictionaryable, JsonSerializable):
29422947
def __init__(self, text: str, request_contact: Optional[bool]=None,
29432948
request_location: Optional[bool]=None, request_poll: Optional[KeyboardButtonPollType]=None,
29442949
web_app: Optional[WebAppInfo]=None, request_user: Optional[KeyboardButtonRequestUser]=None,
2945-
request_chat: Optional[KeyboardButtonRequestChat]=None, request_users: Optional[KeyboardButtonRequestUsers]=None):
2950+
request_chat: Optional[KeyboardButtonRequestChat]=None, request_users: Optional[KeyboardButtonRequestUsers]=None,
2951+
icon_custom_emoji_id: Optional[str]=None, **kwargs):
29462952
self.text: str = text
29472953
self.request_contact: Optional[bool] = request_contact
29482954
self.request_location: Optional[bool] = request_location
29492955
self.request_poll: Optional[KeyboardButtonPollType] = request_poll
29502956
self.web_app: Optional[WebAppInfo] = web_app
29512957
self.request_chat: Optional[KeyboardButtonRequestChat] = request_chat
29522958
self.request_users: Optional[KeyboardButtonRequestUsers] = request_users
2959+
self.icon_custom_emoji_id: Optional[str] = icon_custom_emoji_id
29532960
if request_user is not None:
29542961
log_deprecation_warning('The parameter "request_user" is deprecated, use "request_users" instead')
29552962
if self.request_users is None:
@@ -2974,6 +2981,8 @@ def to_dict(self):
29742981
json_dict['request_users'] = self.request_users.to_dict()
29752982
if self.request_chat is not None:
29762983
json_dict['request_chat'] = self.request_chat.to_dict()
2984+
if self.icon_custom_emoji_id is not None:
2985+
json_dict['icon_custom_emoji_id'] = self.icon_custom_emoji_id
29772986
return json_dict
29782987

29792988

@@ -3097,6 +3106,11 @@ class InlineKeyboardButton(Dictionaryable, JsonSerializable, JsonDeserializable)
30973106
:param text: Label text on the button
30983107
:type text: :obj:`str`
30993108

3109+
:param icon_custom_emoji_id: Optional. Unique identifier of the custom emoji shown before the text of the button.
3110+
Can only be used by bots that purchased additional usernames on Fragment or in the messages directly sent by the bot to private,
3111+
group and supergroup chats if the owner of the bot has a Telegram Premium subscription.
3112+
:type icon_custom_emoji_id: :obj:`str`
3113+
31003114
:param url: Optional. HTTP or tg:// URL to be opened when the button is pressed. Links tg://user?id=<user_id> can be
31013115
used to mention a user by their ID without using a username, if this is allowed by their privacy settings.
31023116
:type url: :obj:`str`
@@ -3162,7 +3176,7 @@ def de_json(cls, json_string):
31623176
def __init__(self, text: str, url: Optional[str]=None, callback_data: Optional[str]=None, web_app: Optional[WebAppInfo]=None,
31633177
switch_inline_query: Optional[str]=None, switch_inline_query_current_chat: Optional[str]=None,
31643178
switch_inline_query_chosen_chat: Optional[SwitchInlineQueryChosenChat]=None, callback_game=None, pay: Optional[bool]=None,
3165-
login_url: Optional[LoginUrl]=None, copy_text: Optional[CopyTextButton]=None, **kwargs):
3179+
login_url: Optional[LoginUrl]=None, copy_text: Optional[CopyTextButton]=None, icon_custom_emoji_id: Optional[str]=None, **kwargs):
31663180
self.text: str = text
31673181
self.url: Optional[str] = url
31683182
self.callback_data: Optional[str] = callback_data
@@ -3174,6 +3188,7 @@ def __init__(self, text: str, url: Optional[str]=None, callback_data: Optional[s
31743188
self.pay: Optional[bool] = pay
31753189
self.login_url: Optional[LoginUrl] = login_url
31763190
self.copy_text: Optional[CopyTextButton] = copy_text
3191+
self.icon_custom_emoji_id: Optional[str] = icon_custom_emoji_id
31773192

31783193
def to_json(self):
31793194
return json.dumps(self.to_dict())
@@ -3200,6 +3215,8 @@ def to_dict(self):
32003215
json_dict['switch_inline_query_chosen_chat'] = self.switch_inline_query_chosen_chat.to_dict()
32013216
if self.copy_text is not None:
32023217
json_dict['copy_text'] = self.copy_text.to_dict()
3218+
if self.icon_custom_emoji_id is not None:
3219+
json_dict['icon_custom_emoji_id'] = self.icon_custom_emoji_id
32033220
return json_dict
32043221

32053222

0 commit comments

Comments
 (0)