Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Update Class to Support Command Extraction from "callback_query" #1135

Open
wants to merge 3 commits into
base: 3.x
Choose a base branch
from

Conversation

miladkhodaverdi23
Copy link

This pull request introduces a new feature to the Update class in the Telegram Bot SDK, allowing for the extraction of commands from callback_query updates. The enhancement adds a getText method that processes and retrieves command strings from callback queries, improving command handling efficiency.

Changes
New getText Method: Added to the Update class to handle command extraction from callback_query updates.

Usage:
Example Keyboard
You can use inline keyboards to send callback queries:

Keyboard::make()
    ->inline()
    ->row([
        Keyboard::inlineButton([
            'text' => 'Access',
            'callback_data'  => 'access',
        ])
    ]);

Example Command Usage
Command class utilizing the new feature:

class CallbackAccessAccountCommand extends Command implements CommandInterface
{
    protected string $name = 'callback:::access';
    protected string $description = 'Access account';

    /**
     * @throws Exception
     */
    public function handle()
    {
        // Command implementation
    }
}

Please review the changes and provide any feedback or suggestions.

Thank you!

- Replaced `getUpdate()->getMessage()->text` with `getUpdate()->getText()` to simplify text retrieval.
- Improved `relevantMessageSubString` method to better handle different message formats and avoid potential errors.
- Updated `handler` method to handle `callback_query` updates.
- Implemented command parsing for callback queries with format `/callback:::\w*`.
- Maintained existing command parsing and execution for regular messages.
- Ensured backward compatibility with previous command handling logic.
- Implemented `getText` method to retrieve text from various update types:
  - Returns message text for 'message', 'edited_message', 'channel_post', and 'edited_channel_post' types.
  - Returns formatted callback query data for 'callback_query' type.
  - Returns empty string for other types.
- Updated docblocks to reflect the new method.
- Maintained backward compatibility with deprecated methods.
Copy link

codecov bot commented Aug 9, 2024

Codecov Report

Attention: Patch coverage is 36.36364% with 14 lines in your changes missing coverage. Please review.

Project coverage is 41.26%. Comparing base (a24ba59) to head (49aeec3).
Report is 3 commits behind head on 3.x.

Files Patch % Lines
src/Commands/CommandBus.php 10.00% 9 Missing ⚠️
src/Objects/Update.php 55.55% 4 Missing ⚠️
src/Commands/Command.php 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##                3.x    #1135      +/-   ##
============================================
- Coverage     41.95%   41.26%   -0.70%     
- Complexity      614      616       +2     
============================================
  Files           133      133              
  Lines          1797     1815      +18     
============================================
- Hits            754      749       -5     
- Misses         1043     1066      +23     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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