Skip to content

Prepare for Bot Api 9.4#2552

Closed
ranjitsingha wants to merge 7 commits intoeternnoir:masterfrom
ranjitsingha:master
Closed

Prepare for Bot Api 9.4#2552
ranjitsingha wants to merge 7 commits intoeternnoir:masterfrom
ranjitsingha:master

Conversation

@ranjitsingha
Copy link

@ranjitsingha ranjitsingha commented Feb 10, 2026

Summary

This PR implements Bot API 9.4 features for keyboard buttons, adding support for custom emoji icons and button styling.

Changes

  • Added icon_custom_emoji_id parameter to InlineKeyboardButton class
  • Added style parameter to InlineKeyboardButton class
  • Added icon_custom_emoji_id parameter to KeyboardButton class
  • Added style parameter to KeyboardButton class
  • Updated to_dict() methods to serialize the new fields
  • Updated docstrings with parameter documentation

These changes allow bots with Telegram Premium subscription to display custom emojis on buttons and change button colors using style parameters.

References

Testing

@bot.message_handler(commands=['start'])
def start(message):
    markup = InlineKeyboardMarkup()
    
    # Button with style (color) - Bot API 9.4
    btn1 = InlineKeyboardButton(
        text="🔥 Destructive Action",
        callback_data="delete",
        style="danger"  # NEW: Red button
    )
    
    btn2 = InlineKeyboardButton(
        text="✅ Confirm",
        callback_data="confirm",
        style="success"  # NEW: Green button
    )
    
    btn3 = InlineKeyboardButton(
        text="ℹ️ Info",
        callback_data="info",
        style="primary"  # NEW: Blue button
    )
    
    # Button with custom emoji icon - Bot API 9.4
    btn4 = InlineKeyboardButton(
        text="Premium Button",
        callback_data="premium",
        icon_custom_emoji_id="5368324170671202286"  # NEW: Shows custom emoji on button
    )
    
    markup.add(btn1, btn2)
    markup.add(btn3)
    markup.add(btn4)
    
    bot.send_message(message.chat.id, "Choose an action:", reply_markup=markup)

…rdButton

Add style and icon_custom_emoji_id to InlineKeyboardButton and KeyboardButton
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_id and style parameters to KeyboardButton.
  • Added icon_custom_emoji_id and style parameters to InlineKeyboardButton.
  • 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.

Comment on lines 3150 to 3154

: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`

Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
: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`

Copilot uses AI. Check for mistakes.
Copy link
Author

@ranjitsingha ranjitsingha Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Comment on lines 3219 to 3222
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
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Badiboy and others added 3 commits February 10, 2026 10:11
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>
@Badiboy
Copy link
Collaborator

Badiboy commented Feb 10, 2026

@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.

@ranjitsingha
Copy link
Author

@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

@coder2020official
Copy link
Collaborator

#2553, you can help test, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants