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 5 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 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 ⚠️
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.09%   -0.87%     
- Complexity      614      616       +2     
============================================
  Files           133      133              
  Lines          1797     1803       +6     
============================================
- Hits            754      741      -13     
- Misses         1043     1062      +19     

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

- 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
Owner

@irazasyed irazasyed left a comment

Choose a reason for hiding this comment

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

Please fix the requested changes

@@ -1,5 +1,5 @@
{
"name": "irazasyed/telegram-bot-sdk",
"name": "miladkhodaverdi23/telegram-bot-sdk",
Copy link
Owner

Choose a reason for hiding this comment

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

Revert this change

@@ -3,6 +3,7 @@
namespace Telegram\Bot\Commands;

use Illuminate\Support\Collection;
use Mockery\Exception;
Copy link
Owner

Choose a reason for hiding this comment

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

Wrong import

* @method static bool editForumTopic(array $params)
* @method static bool closeForumTopic(array $params)
* @method static bool reopenForumTopic(array $params)
* @method static bool deleteForumTopic(array $params)
Copy link
Owner

Choose a reason for hiding this comment

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

Why are these removed?

@@ -2,7 +2,6 @@

namespace Telegram\Bot\Methods;

use Illuminate\Support\Arr;
Copy link
Owner

Choose a reason for hiding this comment

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

Why is this removed? It's in use.

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