Add missing fields and parameters to high-level API#111
Conversation
- Added missing fields to User, Chat, Message, Story, StoryViews, and Poll types. - Updated sending methods (send_message, send_photo, etc.) with new parameters: background, clear_draft, quick_reply_shortcut, allow_paid_stars, suggested_post, and more. - Updated Message bound methods (reply_*, forward, copy) to support new parameters. - Added reply_dice and reply_paid_media bound methods to Message. - Updated CallbackQuery to support business-related fields. - Fixed several type hints and potential runtime errors identified during code review.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Reviewer's GuideExtends Pyrogram’s high-level messaging, story, poll, and callback-query APIs to match recent Telegram raw API layers, wiring new business/stars/scheduling/quick-reply parameters through both client methods and Message bound methods, and enriching story, story views, and poll types with additional fields and reactions while fixing parsing/signature discrepancies. Sequence diagram for send_game with new high-level parameterssequenceDiagram
actor Developer
participant Client
participant Utils
participant SuggestedPost
participant RawAPI as raw_messages
Developer->>Client: send_game(chat_id, game_short_name,<br/> allow_paid_stars, send_as, quick_reply_shortcut,<br/> schedule_date, schedule_repeat_period, background,<br/> clear_draft, update_stickersets_order, suggested_post, message_effect_id, ...)
Client->>Client: resolve_peer(chat_id)
Client->>Client: resolve_peer(send_as) [if send_as]
Client->>Utils: get_input_peer(send_as) [if send_as]
Utils-->>Client: input_peer_send_as
Client->>Utils: get_input_quick_reply_shortcut(quick_reply_shortcut) [if provided]
Utils-->>Client: input_quick_reply_shortcut
Developer->>Client: provide schedule_date (datetime)
Client->>Utils: datetime_to_timestamp(schedule_date)
Utils-->>Client: schedule_ts
Client->>SuggestedPost: write() [if suggested_post]
SuggestedPost-->>Client: raw_suggested_post
Client->>RawAPI: messages.SendMedia<br/>(game_short_name,<br/> peer, reply_to, random_id,<br/> schedule_date=schedule_ts,<br/> schedule_repeat_period,<br/> noforwards=protect_content,<br/> allow_paid_floodskip=allow_paid_broadcast,<br/> allow_paid_stars,<br/> background, clear_draft,<br/> update_stickersets_order,<br/> send_as=input_peer_send_as,<br/> quick_reply_shortcut=input_quick_reply_shortcut,<br/> effect=message_effect_id,<br/> suggested_post=raw_suggested_post)
RawAPI-->>Client: updates (message, possibly UpdateBotNewBusinessMessage)
Client-->>Developer: Message
Class diagram for updated Story, StoryViews, Poll, and CallbackQuery typesclassDiagram
class Object
class Update
class Client
class Reaction {
+_parse(client, raw_reaction) Reaction
+_parse_count(client, raw_reaction_count) Reaction
}
class SuggestedPost {
+write() raw_type
}
class Message {
+forward(chat_id, message_thread_id, disable_notification, schedule_date, schedule_repeat_period, protect_content, allow_paid_broadcast, allow_paid_stars, drop_author, drop_media_captions, background, with_my_score, message_effect_id, video_timestamp, quick_reply_shortcut, send_as, suggested_post) Message~list~
+copy(chat_id, caption, parse_mode, caption_entities, disable_notification, reply_to_message_id, reply_to_chat_id, schedule_date, schedule_repeat_period, protect_content, allow_paid_broadcast, allow_paid_stars, message_effect_id, invert_media, quick_reply_shortcut, send_as, background, clear_draft, update_stickersets_order, suggested_post, reply_markup) Message~list~
}
class StoryViews {
+int view_count
+int forward_count
+list~Reaction~ reactions
+int reactions_count
+list~int~ recent_viewers
+_parse(client, raw_storyviews) StoryViews
}
class Story {
+int id
+int date
+int expire_date
+bool pinned
+bool close_friends
+bool contacts
+bool selected_contacts
+str caption
+list~MessageEntity~ caption_entities
+StoryViews views
+privacy privacy
+User forward_from
+list~int~ allowed_users
+list~int~ denied_users
+list~MediaArea~ media_areas
+bool out
+bool min
+Reaction sent_reaction
+list~int~ albums
+raw_type raw
+_parse(client, raw_story_item, users, chats) Story
}
class Poll {
+str id
+str question
+list~PollOption~ options
+bool is_closed
+bool is_anonymous
+str type
+bool allows_multiple_answers
+int correct_option_id
+str explanation
+list~MessageEntity~ explanation_entities
+int open_period
+datetime close_date
+bool min
+list~User~ recent_voters
+_parse(client, raw_poll, raw_poll_results, users) Poll
+_parse_update(client, raw_poll, raw_poll_results, users) Poll
}
class CallbackQuery {
+int id
+User from_user
+Message message
+str inline_message_id
+str chat_instance
+str data
+str game_short_name
+str business_connection_id
+Message reply_to_message
+list~Match~ matches
+_parse(client, raw_callback_query, users, chats) CallbackQuery
}
StoryViews --* Story : views
Reaction <-- StoryViews : uses
Reaction <-- Story : sent_reaction
Story --> StoryViews : aggregates
Story --> Reaction : uses
Story --> Client : client
Poll --> Client : client
CallbackQuery --> Message : message
CallbackQuery --> Message : reply_to_message
CallbackQuery --> Client : client
Message --> Client : _client
Message --> SuggestedPost : suggested_post
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Summary of ChangesHello, 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 significantly updates Pyrogram's high-level API to align with recent changes in the Telegram raw API, specifically up to Layer 184+. The primary goal is to enhance the API's capabilities by introducing new fields to core types and adding a comprehensive set of modern parameters to message sending and forwarding methods. This ensures that the library supports the latest Telegram features, including business-related functionalities and advanced message options, providing a more complete and up-to-date interface for developers. 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.
Hey - I've left some high level feedback:
- In
Story._parse,sent_reaction=types.Reaction._parse(client, stories.sent_reaction)should guard againststories.sent_reactionbeingNoneto avoid calling_parsewith a null value (e.g., use a conditional expression to keepsent_reactionasNonewhen absent). - The new business/quick-reply/scheduling parameters are being threaded through many send/copy/forward methods; consider extracting a small helper or shared data structure to build the common raw kwargs to reduce duplication and the risk of future drift between these call sites.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `Story._parse`, `sent_reaction=types.Reaction._parse(client, stories.sent_reaction)` should guard against `stories.sent_reaction` being `None` to avoid calling `_parse` with a null value (e.g., use a conditional expression to keep `sent_reaction` as `None` when absent).
- The new business/quick-reply/scheduling parameters are being threaded through many send/copy/forward methods; consider extracting a small helper or shared data structure to build the common raw kwargs to reduce duplication and the risk of future drift between these call sites.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request synchronizes Pyrogram's high-level API with recent changes in the Telegram raw API, adding numerous missing fields and parameters across various types and methods. The changes are extensive and well-aligned with the goal of API parity. I've identified a potential bug in CallbackQuery parsing that could lead to a KeyError, and I've also pointed out several instances where the code style could be improved for better readability and maintainability, such as avoiding shadowing built-in names and compacting verbose conditional assignments. Additionally, there are a few minor documentation inconsistencies that should be addressed.
| explanation_entities: list[types.MessageEntity] | None = None, | ||
| open_period: int | None = None, | ||
| close_date: datetime | None = None, | ||
| min: bool | None = None, |
There was a problem hiding this comment.
The parameter min shadows the Python built-in function min(). It's a best practice to avoid this. Consider renaming it to is_min for clarity and to avoid potential issues. This should be changed throughout the class (attribute self.min, docstring, etc.).
| min: bool | None = None, | |
| is_min: bool | None = None, |
| denied_users=denied_users, | ||
| media_areas=media_areas, | ||
| out=stories.out, | ||
| min=stories.min, |
| self.denied_users = denied_users | ||
| self.media_areas = media_areas | ||
| self.out = out | ||
| self.min = min |
| denied_users: list[int] | None = None, | ||
| media_areas: list[types.MediaArea] | None = None, | ||
| out: bool | None = None, | ||
| min: bool | None = None, |
There was a problem hiding this comment.
The parameter min shadows the Python built-in function min(). It's a best practice to avoid this. Consider renaming it to is_min for clarity and to avoid potential issues. This should be changed throughout the class (attribute self.min, docstring, etc.).
| min: bool | None = None, | |
| is_min: bool | None = None, |
| is_closed=False, | ||
| chosen_option_id=chosen_option_id, | ||
| correct_option_id=correct_option_id, | ||
| min=poll_results.min, |
| send_as=utils.get_input_peer(await self.resolve_peer(send_as)) | ||
| if send_as | ||
| else None, | ||
| quick_reply_shortcut=await utils.get_input_quick_reply_shortcut( | ||
| quick_reply_shortcut, | ||
| ) | ||
| if quick_reply_shortcut | ||
| else None, | ||
| allow_paid_stars=allow_paid_stars, | ||
| suggested_post=await suggested_post.write() if suggested_post else None, |
There was a problem hiding this comment.
The conditional assignments for send_as and quick_reply_shortcut are written in a multi-line format which is a bit verbose. They can be compacted into single lines for better readability, which is more conventional for Python's ternary operator.
send_as=utils.get_input_peer(await self.resolve_peer(send_as)) if send_as else None,
quick_reply_shortcut=await utils.get_input_quick_reply_shortcut(
quick_reply_shortcut
) if quick_reply_shortcut else None,
allow_paid_stars=allow_paid_stars,
suggested_post=await suggested_post.write() if suggested_post else None,| send_as=utils.get_input_peer(await self.resolve_peer(send_as)) | ||
| if send_as | ||
| else None, | ||
| quick_reply_shortcut=await utils.get_input_quick_reply_shortcut( | ||
| quick_reply_shortcut, | ||
| ) | ||
| if quick_reply_shortcut | ||
| else None, | ||
| allow_paid_stars=allow_paid_stars, | ||
| suggested_post=await suggested_post.write() if suggested_post else None, |
There was a problem hiding this comment.
The conditional assignments for send_as and quick_reply_shortcut are written in a multi-line format which is a bit verbose. They can be compacted into single lines for better readability, which is more conventional for Python's ternary operator.
send_as=utils.get_input_peer(await self.resolve_peer(send_as)) if send_as else None,
quick_reply_shortcut=await utils.get_input_quick_reply_shortcut(
quick_reply_shortcut
) if quick_reply_shortcut else None,
allow_paid_stars=allow_paid_stars,
suggested_post=await suggested_post.write() if suggested_post else None,| send_as=utils.get_input_peer(await self.resolve_peer(send_as)) | ||
| if send_as | ||
| else None, | ||
| quick_reply_shortcut=await utils.get_input_quick_reply_shortcut( | ||
| quick_reply_shortcut, | ||
| ) | ||
| if quick_reply_shortcut | ||
| else None, | ||
| allow_paid_stars=allow_paid_stars, | ||
| suggested_post=await suggested_post.write() if suggested_post else None, |
There was a problem hiding this comment.
The conditional assignments for send_as and quick_reply_shortcut are written in a multi-line format which is a bit verbose. They can be compacted into single lines for better readability, which is more conventional for Python's ternary operator.
send_as=utils.get_input_peer(await self.resolve_peer(send_as)) if send_as else None,
quick_reply_shortcut=await utils.get_input_quick_reply_shortcut(
quick_reply_shortcut
) if quick_reply_shortcut else None,
allow_paid_stars=allow_paid_stars,
suggested_post=await suggested_post.write() if suggested_post else None,| schedule_repeat_period (``int``, *optional*): | ||
| Repeat period of the scheduled message. |
There was a problem hiding this comment.
The documentation for the schedule_repeat_period parameter is out of order. It appears at the end of the parameter list in the docstring, but it's defined much earlier in the function signature. For consistency and readability, it's better to keep the docstring in the same order as the parameters in the function signature. It should be placed after schedule_date.
| quick_reply_shortcut=await utils.get_input_quick_reply_shortcut( | ||
| quick_reply_shortcut, | ||
| ) | ||
| if quick_reply_shortcut | ||
| else None, | ||
| send_as=utils.get_input_peer(await self.resolve_peer(send_as)) | ||
| if send_as | ||
| else None, | ||
| allow_paid_stars=allow_paid_stars, | ||
| suggested_post=await suggested_post.write() | ||
| if suggested_post | ||
| else None, |
There was a problem hiding this comment.
The conditional assignments for quick_reply_shortcut, send_as, and suggested_post are written in a multi-line format which is a bit verbose. They can be compacted into single lines for better readability, which is more conventional for Python's ternary operator.
quick_reply_shortcut=await utils.get_input_quick_reply_shortcut(
quick_reply_shortcut
) if quick_reply_shortcut else None,
send_as=utils.get_input_peer(await self.resolve_peer(send_as)) if send_as else None,
allow_paid_stars=allow_paid_stars,
suggested_post=await suggested_post.write() if suggested_post else None,
This PR synchronizes Pyrogram's high-level API with the recent changes in the Telegram raw API (up to Layer 184+).
Key changes:
User,Chat,Message,Story,StoryViews, andPoll.background,clear_draft,quick_reply_shortcut,allow_paid_stars, andsuggested_post.Messageclass's bound methods, ensuring parity betweenclient.send_*andmessage.reply_*.CallbackQueryand added support for business-related parameters in sending methods.tytype checker.PR created automatically by Jules for task 7625622860848842969 started by @5hojib
Summary by Sourcery
Extend high-level messaging and story types to support new Telegram features and business/bot parameters introduced in recent API layers.
New Features:
Enhancements: