Skip to content

Commit

Permalink
Add support for callback queries in CommandBus
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
miladkhodaverdi23 committed Aug 9, 2024
1 parent 2899b43 commit cdf4d30
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Commands/CommandBus.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ protected function parseCommand(string $text, int $offset, int $length): string
*/
protected function handler(Update $update): Update
{
if ($update->detectType() == "callback_query") {
preg_match('/\A(\/callback:::\w*)\s(.*)/', $update->getText(), $command);
[$text, $command] = $command;
$entity = [
'offset' => 0,
'length' => strlen($command),
];
$this->process($entity, $update);

return $update;
}

$message = $update->getMessage();

if ($message->has('entities')) {
Expand Down Expand Up @@ -171,7 +183,7 @@ private function parseCommandsIn(Collection $message): Collection
private function process(array $entity, Update $update): void
{
$command = $this->parseCommand(
$update->getMessage()->text,
$update->getText(),
$entity['offset'],
$entity['length']
);
Expand Down

0 comments on commit cdf4d30

Please sign in to comment.