Conversation
…rdButton Add style and icon_custom_emoji_id to InlineKeyboardButton and KeyboardButton
There was a problem hiding this comment.
Pull request overview
This PR updates the telebot.types button models to support Telegram Bot API 9.4 keyboard button enhancements (custom emoji icons and button styling), enabling bots to serialize these new fields into outgoing payloads.
Changes:
- Added
icon_custom_emoji_idandstyleparameters toKeyboardButton. - Added
icon_custom_emoji_idandstyleparameters toInlineKeyboardButton. - Updated
to_dict()serialization and docstrings to reflect the new fields.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| :param icon_custom_emoji_id: Optional. Custom emoji identifier to be shown on the button. | ||
| Can only be used if the bot has a Telegram Premium subscription. | ||
| :type icon_custom_emoji_id: :obj:`str` | ||
|
|
There was a problem hiding this comment.
The class-level note for InlineKeyboardButton says “You must use exactly one of the optional fields”, but icon_custom_emoji_id and style are additional optional fields meant to be used alongside an action field (e.g., callback_data/url). As documented now, it reads like style/icon_custom_emoji_id are mutually exclusive with the rest, which would be misleading. Please clarify the docstring to scope the exclusivity requirement to the button action fields only.
| :param icon_custom_emoji_id: Optional. Custom emoji identifier to be shown on the button. | |
| Can only be used if the bot has a Telegram Premium subscription. | |
| :type icon_custom_emoji_id: :obj:`str` | |
| Note: Exactly one of the *action* parameters (such as ``url``, ``callback_data``, ``web_app``, ``login_url``, | |
| ``switch_inline_query``, ``switch_inline_query_current_chat``, ``switch_inline_query_chosen_chat``, | |
| ``callback_game``, ``pay`` or ``copy_text`` should be used for a single button. The following parameters are | |
| additional and may be used alongside one of these action parameters. | |
| :param icon_custom_emoji_id: Optional. Custom emoji identifier to be shown on the button. | |
| Can only be used if the bot has a Telegram Premium subscription. | |
| :type icon_custom_emoji_id: :obj:`str` |
There was a problem hiding this comment.
Can only be used if the bot has a Telegram Premium subscription. -> Can only be used if the bot owner has a Telegram Premium subscription.
telebot/types.py
Outdated
| if self.icon_custom_emoji_id is not None: | ||
| json_dict['icon_custom_emoji_id'] = self.icon_custom_emoji_id | ||
| if self.style is not None: | ||
| json_dict['style'] = self.style |
There was a problem hiding this comment.
New fields icon_custom_emoji_id and style are added to InlineKeyboardButton/KeyboardButton, but there are no unit tests asserting (a) to_dict() includes them and (b) InlineKeyboardButton.de_json() correctly populates them. Since tests/test_types.py already covers inline keyboard button JSON round-tripping, adding cases for these new fields would prevent regressions.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@ranjitsingha We'll push the full update in the nearest time. Such fragmentary update may make some mess, so we let it stay unmerged for some time. |
Sure |
Clarified the requirement for Telegram Premium subscription in the icon_custom_emoji_id parameter.
|
#2553, you can help test, thanks! |
Summary
This PR implements Bot API 9.4 features for keyboard buttons, adding support for custom emoji icons and button styling.
Changes
icon_custom_emoji_idparameter toInlineKeyboardButtonclassstyleparameter toInlineKeyboardButtonclassicon_custom_emoji_idparameter toKeyboardButtonclassstyleparameter toKeyboardButtonclassto_dict()methods to serialize the new fieldsThese changes allow bots with Telegram Premium subscription to display custom emojis on buttons and change button colors using style parameters.
References
Testing