Skip to content

Test#54

Merged
5hojib merged 8 commits intodevfrom
test
Feb 9, 2026
Merged

Test#54
5hojib merged 8 commits intodevfrom
test

Conversation

@5hojib
Copy link
Member

@5hojib 5hojib commented Feb 9, 2026

Summary by Sourcery

Add support for configurable button styles across keyboard button types and integrate the new style type into serialization, deserialization, and documentation.

New Features:

  • Introduce a KeyboardButtonStyle type to represent button appearance options such as primary, danger, success, and custom icons.
  • Allow InlineKeyboardButton, KeyboardButton, and InlineKeyboardButtonBuy to accept an optional style attribute and propagate it through read/write conversions.

Enhancements:

  • Wire KeyboardButtonStyle through LoginUrl button creation and export it from the bots_and_keyboards package and top-level namespace.
  • Update compiler docs to reference the new KeyboardButtonStyle type in the bot keyboards section.

5hojib and others added 7 commits February 8, 2026 23:05
This change adds support for the new button styles introduced by Telegram.
Users can now use the `style` parameter in `InlineKeyboardButton`,
`KeyboardButton`, and `InlineKeyboardButtonBuy`.

New type `KeyboardButtonStyle` is added to support:
- `bg_primary`
- `bg_danger`
- `bg_success`
- `icon`

The `KeyboardButton.read` method maintains backward compatibility by
returning a string for plain text buttons without styles.
The `LoginUrl.write` method was also updated to support passing styles.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Signed-off-by: 5hojib <yesiamshojib@gmail.com>
Signed-off-by: 5hojib <yesiamshojib@gmail.com>
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Feb 9, 2026

Reviewer's Guide

Adds support for Telegram button styles via a new KeyboardButtonStyle type, wiring it through inline and reply keyboard button models, their read/write conversions to raw API types, and updating exports and documentation accordingly.

Sequence diagram for writing an InlineKeyboardButton with style

sequenceDiagram
    participant Client as Client
    participant IKB as InlineKeyboardButton
    participant KBS as KeyboardButtonStyle
    participant RAW as raw_types_KeyboardButtonCallback

    Client->>IKB: write(client)
    activate IKB
    IKB->>KBS: style.write() [if style is not None]
    activate KBS
    KBS-->>IKB: raw_types_KeyboardButtonStyle
    deactivate KBS
    IKB-->>RAW: create KeyboardButtonCallback(text, data, requires_password, style)
    deactivate IKB
    RAW-->>Client: raw KeyboardButtonCallback
Loading

Class diagram for new KeyboardButtonStyle integration

classDiagram
    class KeyboardButtonStyle {
        +bool bg_primary
        +bool bg_danger
        +bool bg_success
        +int icon
        +KeyboardButtonStyle read(b)
        +raw_types_KeyboardButtonStyle write()
    }

    class KeyboardButton {
        +str text
        +bool request_contact
        +bool request_location
        +RequestPeerTypeChannel request_chat
        +RequestPeerTypeUser request_user
        +WebAppInfo web_app
        +KeyboardButtonStyle style
        +KeyboardButton read(b)
        +raw_types_KeyboardButton write()
    }

    class InlineKeyboardButton {
        +str text
        +str url
        +LoginUrl login_url
        +int user_id
        +str switch_inline_query
        +str switch_inline_query_current_chat
        +CallbackGame callback_game
        +bool requires_password
        +str copy_text
        +KeyboardButtonStyle style
        +InlineKeyboardButton read(b)
        +raw_base_KeyboardButton write(client)
    }

    class InlineKeyboardButtonBuy {
        +str text
        +KeyboardButtonStyle style
        +InlineKeyboardButtonBuy read(b)
        +raw_types_KeyboardButtonBuy write(client)
    }

    class LoginUrl {
        +str url
        +str forward_text
        +int button_id
        +bool request_write_access
        +LoginUrl read(b)
        +raw_types_InputKeyboardButtonUrlAuth write(text, bot, style)
    }

    class raw_types_KeyboardButtonStyle {
        +bool bg_primary
        +bool bg_danger
        +bool bg_success
        +int icon
    }

    class raw_types_KeyboardButtonUrlAuth {
        +str text
        +str url
        +raw_types_InputUser bot
        +str fwd_text
        +bool request_write_access
        +raw_types_KeyboardButtonStyle style
    }

    class raw_types_KeyboardButton {
        +str text
        +raw_types_KeyboardButtonStyle style
    }

    class raw_types_KeyboardButtonRequestPhone {
        +str text
        +raw_types_KeyboardButtonStyle style
    }

    class raw_types_KeyboardButtonRequestGeoLocation {
        +str text
        +raw_types_KeyboardButtonStyle style
    }

    class raw_types_KeyboardButtonSimpleWebView {
        +str text
        +str url
        +raw_types_KeyboardButtonStyle style
    }

    class raw_types_KeyboardButtonCopy {
        +str text
        +str copy_text
        +raw_types_KeyboardButtonStyle style
    }

    class raw_types_KeyboardButtonCallback {
        +str text
        +bytes data
        +bool requires_password
        +raw_types_KeyboardButtonStyle style
    }

    KeyboardButtonStyle --> raw_types_KeyboardButtonStyle : writes
    KeyboardButtonStyle <-- raw_types_KeyboardButtonStyle : reads

    KeyboardButton --> KeyboardButtonStyle : has style
    InlineKeyboardButton --> KeyboardButtonStyle : has style
    InlineKeyboardButtonBuy --> KeyboardButtonStyle : has style
    LoginUrl --> KeyboardButtonStyle : uses style in write

    KeyboardButton --> raw_types_KeyboardButton : write()
    KeyboardButton --> raw_types_KeyboardButtonRequestPhone : write()
    KeyboardButton --> raw_types_KeyboardButtonRequestGeoLocation : write()
    KeyboardButton --> raw_types_KeyboardButtonSimpleWebView : write()

    InlineKeyboardButton --> raw_types_KeyboardButtonCallback : write()
    InlineKeyboardButton --> raw_types_KeyboardButtonCopy : write()

    LoginUrl --> raw_types_KeyboardButtonUrlAuth : write()

    raw_types_KeyboardButtonUrlAuth --> raw_types_KeyboardButtonStyle : has style
    raw_types_KeyboardButton --> raw_types_KeyboardButtonStyle : has style
    raw_types_KeyboardButtonRequestPhone --> raw_types_KeyboardButtonStyle : has style
    raw_types_KeyboardButtonRequestGeoLocation --> raw_types_KeyboardButtonStyle : has style
    raw_types_KeyboardButtonSimpleWebView --> raw_types_KeyboardButtonStyle : has style
    raw_types_KeyboardButtonCopy --> raw_types_KeyboardButtonStyle : has style
    raw_types_KeyboardButtonCallback --> raw_types_KeyboardButtonStyle : has style
Loading

File-Level Changes

Change Details Files
Introduce KeyboardButtonStyle value object and expose it in the bots_and_keyboards package and docs.
  • Create KeyboardButtonStyle Object wrapper with bg_primary/bg_danger/bg_success/icon fields and read/write helpers to raw.types.KeyboardButtonStyle
  • Export KeyboardButtonStyle from pyrogram.types.bots_and_keyboards and include it in the Bot keyboards documentation TOC
pyrogram/types/bots_and_keyboards/keyboard_button_style.py
pyrogram/types/bots_and_keyboards/__init__.py
compiler/docs/compiler.py
Extend InlineKeyboardButton to carry an optional style and serialize/deserialize it with all supported raw keyboard button variants.
  • Add style parameter and attribute to InlineKeyboardButton constructor and docstring
  • In read(), derive a KeyboardButtonStyle from the raw button’s style attribute and pass it into all InlineKeyboardButton creation branches that support style
  • In write(), compute the raw style once and pass it to all raw KeyboardButton* constructors and login_url.write calls that support style
pyrogram/types/bots_and_keyboards/inline_keyboard_button.py
pyrogram/types/bots_and_keyboards/login_url.py
Extend reply KeyboardButton and InlineKeyboardButtonBuy to support styles in both high-level API and raw conversions.
  • Add style parameter and attribute to KeyboardButton and InlineKeyboardButtonBuy and update their docstrings
  • Update KeyboardButton.read to parse style from raw buttons and propagate it when returning KeyboardButton instances, while preserving the legacy plain-text return for simple buttons without style
  • Update KeyboardButton.write and InlineKeyboardButtonBuy.write to compute raw style and pass it to all style-capable raw button constructors, leaving request_peer buttons unchanged because their schema lacks style
pyrogram/types/bots_and_keyboards/keyboard_button.py
pyrogram/types/bots_and_keyboards/inline_keyboard_button_buy.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@gemini-code-assist
Copy link

Summary of Changes

Hello @5hojib, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant enhancement to the Pyrogram library by adding support for customizable keyboard button styles. The core change involves the creation of a KeyboardButtonStyle class, which provides properties for defining button background colors and icons. This new styling capability is then seamlessly integrated into the library's existing inline and reply keyboard button implementations, allowing for more dynamic and visually distinct bot interactions. The update also includes a minor version bump.

Highlights

  • New Feature: Keyboard Button Styling: A new KeyboardButtonStyle class has been introduced, enabling developers to customize the visual appearance of keyboard buttons with properties like background colors (primary, danger, success) and custom icons.
  • Extensive Button Type Integration: The KeyboardButtonStyle functionality has been integrated across various existing button types, including InlineKeyboardButton, InlineKeyboardButtonBuy, KeyboardButton, and LoginUrl, allowing for consistent styling throughout the bot's user interface.
  • Version Bump: The package version has been updated from v0.2.224.1 to v0.2.224.3, reflecting the new additions and changes.
Changelog
  • compiler/docs/compiler.py
    • Added KeyboardButtonStyle to the internal list of bot keyboard types, likely for documentation generation or internal referencing.
  • pyrogram/init.py
    • Updated the package version string to v0.2.224.3.
  • pyrogram/types/bots_and_keyboards/init.py
    • Imported and added KeyboardButtonStyle to the module's __all__ list, making it publicly accessible.
  • pyrogram/types/bots_and_keyboards/inline_keyboard_button.py
    • Added an optional style parameter of type KeyboardButtonStyle to the InlineKeyboardButton constructor.
    • Modified the read static method to parse and apply the style attribute from raw Telegram API objects to InlineKeyboardButton instances.
    • Updated the write async method to serialize the style attribute when converting InlineKeyboardButton objects back to raw Telegram API types.
  • pyrogram/types/bots_and_keyboards/inline_keyboard_button_buy.py
    • Added an optional style parameter of type KeyboardButtonStyle to the InlineKeyboardButtonBuy constructor.
    • Updated the read static method to handle the style attribute for buy buttons.
    • Modified the write async method to include the style attribute when converting InlineKeyboardButtonBuy objects to raw Telegram API types.
  • pyrogram/types/bots_and_keyboards/keyboard_button.py
    • Added an optional style parameter of type KeyboardButtonStyle to the KeyboardButton constructor.
    • Adjusted the read static method to parse and apply the style attribute from raw Telegram API objects to KeyboardButton instances.
    • Updated the write method to serialize the style attribute when converting KeyboardButton objects to raw Telegram API types, with a specific note that InputKeyboardButtonRequestPeer does not support styling in its schema.
  • pyrogram/types/bots_and_keyboards/keyboard_button_style.py
    • New file created, defining the KeyboardButtonStyle class with properties bg_primary, bg_danger, bg_success (booleans), and icon (integer).
    • Implemented read and write methods within KeyboardButtonStyle for conversion between its object representation and raw Telegram API types.
  • pyrogram/types/bots_and_keyboards/login_url.py
    • Added an optional style parameter to the LoginUrl's write method, allowing style information to be passed when creating InputKeyboardButtonUrlAuth objects.
Activity
  • No human activity (comments, reviews, etc.) has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for configurable button styles, which is a great enhancement. The changes are well-integrated across various keyboard button types, including the necessary serialization and deserialization logic, and the documentation has been updated accordingly. The implementation is thorough and consistent with the existing codebase. I have one minor suggestion to improve the accuracy of a type hint in the new KeyboardButtonStyle class.

self.icon = icon

@staticmethod
def read(b: raw.types.KeyboardButtonStyle) -> KeyboardButtonStyle | None:

Choose a reason for hiding this comment

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

medium

The type hint for the b parameter is raw.types.KeyboardButtonStyle, but the implementation correctly handles None as a possible value, as seen in the if not b: check. To make the type hint accurate and improve type safety, it should be updated to raw.types.KeyboardButtonStyle | None.

Suggested change
def read(b: raw.types.KeyboardButtonStyle) -> KeyboardButtonStyle | None:
def read(b: raw.types.KeyboardButtonStyle | None) -> KeyboardButtonStyle | None:

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • In KeyboardButton.read, the return type for raw.types.KeyboardButton now depends on whether style is present (KeyboardButton vs str); consider making this behavior explicit and consistent (e.g., always returning a KeyboardButton instance) to avoid surprising type differences at call sites.
  • In KeyboardButtonStyle.read, the parameter is annotated as raw.types.KeyboardButtonStyle but you also pass and handle None; consider updating the type hint to raw.types.KeyboardButtonStyle | None (and similarly where style is passed around) so the annotations accurately reflect the values being handled.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `KeyboardButton.read`, the return type for `raw.types.KeyboardButton` now depends on whether `style` is present (`KeyboardButton` vs `str`); consider making this behavior explicit and consistent (e.g., always returning a `KeyboardButton` instance) to avoid surprising type differences at call sites.
- In `KeyboardButtonStyle.read`, the parameter is annotated as `raw.types.KeyboardButtonStyle` but you also pass and handle `None`; consider updating the type hint to `raw.types.KeyboardButtonStyle | None` (and similarly where `style` is passed around) so the annotations accurately reflect the values being handled.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@5hojib 5hojib merged commit 3111b7c into dev Feb 9, 2026
4 checks passed
@5hojib 5hojib deleted the test branch February 9, 2026 02:44
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.

1 participant