Conversation
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>
Reviewer's GuideAdds 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 stylesequenceDiagram
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
Class diagram for new KeyboardButtonStyle integrationclassDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Summary of ChangesHello @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 Highlights
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
| def read(b: raw.types.KeyboardButtonStyle) -> KeyboardButtonStyle | None: | |
| def read(b: raw.types.KeyboardButtonStyle | None) -> KeyboardButtonStyle | None: |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
KeyboardButton.read, the return type forraw.types.KeyboardButtonnow depends on whetherstyleis present (KeyboardButtonvsstr); consider making this behavior explicit and consistent (e.g., always returning aKeyboardButtoninstance) to avoid surprising type differences at call sites. - In
KeyboardButtonStyle.read, the parameter is annotated asraw.types.KeyboardButtonStylebut you also pass and handleNone; consider updating the type hint toraw.types.KeyboardButtonStyle | None(and similarly wherestyleis 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.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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:
Enhancements: