Skip to content

Conversation

@D-Sokol
Copy link

@D-Sokol D-Sokol commented Jul 28, 2025

Add widgets RequestUsers and RequestChat for missing telegram reply keyboard features.
https://core.telegram.org/bots/api#keyboardbutton

Summary by CodeRabbit

  • New Features

    • Added new keyboard buttons to request chat and user information in dialogs, expanding interactive options for end-users.
    • Introduced support for Telegram's specialized request buttons for both user and chat data collection.
  • Improvements

    • Enhanced configuration options for keyboard buttons, allowing more granular requests (e.g., user type, chat properties).

@coderabbitai
Copy link

coderabbitai bot commented Jul 28, 2025

Walkthrough

Two new keyboard widget classes, RequestChat and RequestUsers, are introduced to support Telegram's chat and user request buttons. These classes are added to the public API and demonstrated in an example dialog. Type hints for the when parameter in related widgets are updated for consistency.

Changes

Cohort / File(s) Change Summary
Example Usage Update
example/mega/bot_dialogs/reply_buttons.py
Imports and utilizes the new RequestChat and RequestUsers widgets, adding "Send chat" and "Send user" buttons to the reply keyboard layout in the example dialog.
Public API Exposure
src/aiogram_dialog/widgets/kbd/__init__.py
Adds RequestChat and RequestUsers to the module's __all__ list and updates the import statement to include these new widgets, making them available for external use.
Widget Implementation and Type Hint Updates
src/aiogram_dialog/widgets/kbd/request.py
Introduces the RequestChat and RequestUsers widget classes, each supporting Telegram's respective keyboard request features. Updates the type hint for the when parameter in all relevant widget classes to use the WhenCondition type. Adjusts imports to accommodate new Telegram types and the WhenCondition type. No changes to existing logic beyond these additions and type hint refinements.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Bot
    participant ReplyKeyboard

    Bot->>ReplyKeyboard: Build keyboard with RequestContact, RequestLocation, RequestChat, RequestUsers
    User->>Bot: Clicks "Send chat" or "Send user"
    Bot->>User: Receives chat/user info via Telegram API
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Poem

🐰
Two new buttons join the dance,
For chats and users, here’s your chance!
Widgets hop in, type hints align,
The keyboard grows—how very fine!
With every click, a world anew,
This rabbit cheers the work you do!

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dfaa3ca and 3b813c3.

📒 Files selected for processing (3)
  • example/mega/bot_dialogs/reply_buttons.py (2 hunks)
  • src/aiogram_dialog/widgets/kbd/__init__.py (2 hunks)
  • src/aiogram_dialog/widgets/kbd/request.py (4 hunks)
🔇 Additional comments (8)
src/aiogram_dialog/widgets/kbd/__init__.py (2)

33-33: LGTM! Proper API exposure for new keyboard widgets.

The new RequestChat and RequestUsers widgets are correctly added to the public API following the existing alphabetical ordering convention.

Also applies to: 37-37


84-84: LGTM! Import statement correctly updated.

The import statement properly includes the new classes alongside existing request widgets from the .request module.

example/mega/bot_dialogs/reply_buttons.py (2)

5-5: LGTM! Correct imports for new request widgets.

The new RequestChat and RequestUsers widgets are properly imported and will be available for use in the dialog.

Also applies to: 8-8


22-22: LGTM! Good example usage of the new request widgets.

The RequestChat and RequestUsers buttons are properly configured with distinct request_id values and appropriate parameters for demonstration purposes. The max_quantity=1 parameter for RequestUsers is a sensible default for an example.

Also applies to: 24-24

src/aiogram_dialog/widgets/kbd/request.py (4)

1-1: LGTM! Import statements properly updated.

The new imports correctly include the necessary Telegram types for the new request widgets and the WhenCondition type for improved type safety.

Also applies to: 3-9, 13-13


23-23: LGTM! Type hints improved for consistency.

The when parameter type hints are consistently updated to use the more specific WhenCondition type instead of the generic union, improving type safety across all request widgets.

Also applies to: 135-135, 160-160


43-81: LGTM! Well-implemented RequestUsers widget.

The RequestUsers class implementation follows the established patterns and correctly:

  • Accepts comprehensive parameters matching the Telegram Bot API specification
  • Properly constructs the KeyboardButtonRequestUsers object
  • Implements the async render method consistently with other request widgets
  • Uses appropriate type hints including the new union syntax (bool | None)

The parameter set covers all available options for user request filtering as per the Telegram API.


83-129: LGTM! Comprehensive RequestChat widget implementation.

The RequestChat class implementation is well-structured and correctly:

  • Provides extensive configuration options matching the Telegram Bot API for chat requests
  • Properly handles optional parameters with appropriate defaults
  • Uses ChatAdministratorRights type for administrator rights parameters
  • Constructs the KeyboardButtonRequestChat object correctly
  • Follows the established async render pattern

The comprehensive parameter set allows for flexible chat filtering based on various criteria like channel status, forum status, username requirements, and administrator rights.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@D-Sokol
Copy link
Author

D-Sokol commented Jul 28, 2025

Duplicate of #412

def __init__(
self,
text: Text,
request_id: int,
Copy link
Owner

@Tishka17 Tishka17 Jul 28, 2025

Choose a reason for hiding this comment

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

Why not generate request id?

I'd expect that request for old dialog is not processed by new on

Copy link
Author

Choose a reason for hiding this comment

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

Currently messages from all request widgets may be handled only with a separate MessageHandler in the same window, as it has no on_click or anything, so this concern is probably irrelevant. In the current setting user-provided request ids is more convenient than generated ones. I consider this as an analogue of widget_id that some other widgets have and which is mandatory.
Also, request_id must be unique only within a message, so hard-coded values like 1, 2 etc should not cause any troubles.

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.

2 participants