irazasyed / telegram-bot-sdk

🤖 Telegram Bot API PHP SDK. Lets you build Telegram Bots easily! Supports Laravel out of the box.
https://telegram-bot-sdk.com
BSD 3-Clause "New" or "Revised" License
3.04k stars 671 forks source link

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

Open miladkhodaverdi23 opened 3 months ago

miladkhodaverdi23 commented 3 months ago

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!

codecov[bot] commented 3 months ago

Codecov Report

Attention: Patch coverage is 45.45455% with 24 lines in your changes missing coverage. Please review.

Project coverage is 41.09%. Comparing base (a24ba59) to head (56337f3). Report is 3 commits behind head on 3.x.

Files with missing lines Patch % Lines
src/Commands/CommandBus.php 40.62% 19 Missing :warning:
src/Objects/Update.php 55.55% 4 Missing :warning:
src/Commands/Command.php 66.66% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## 3.x #1135 +/- ## ============================================ - Coverage 41.95% 41.09% -0.87% - Complexity 614 616 +2 ============================================ Files 133 133 Lines 1797 1803 +6 ============================================ - Hits 754 741 -13 - Misses 1043 1062 +19 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.