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
3k stars 662 forks source link

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

Open miladkhodaverdi23 opened 1 month ago

miladkhodaverdi23 commented 1 month 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 1 month ago

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 :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.26% -0.70% - Complexity 614 616 +2 ============================================ Files 133 133 Lines 1797 1815 +18 ============================================ - Hits 754 749 -5 - Misses 1043 1066 +23 ```

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