Skip to content

Commit

Permalink
feat: Add getText method to Update class for extracting text
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
miladkhodaverdi23 committed Aug 9, 2024
1 parent cdf4d30 commit 49aeec3
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Objects/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,16 @@ public function hasCommand(): bool
{
return (bool) $this->getMessage()->get('entities', collect())->contains('type', 'bot_command');
}

public function getText()
{
return match ($this->detectType()) {
'message' => $this->message->text,
'edited_message' => $this->editedMessage->text,
'channel_post' => $this->channelPost->text,
'edited_channel_post' => $this->editedChannelPost->text,
'callback_query' => "/callback:::".$this->callbackQuery->data,

Check warning on line 191 in src/Objects/Update.php

View check run for this annotation

Codecov / codecov/patch

src/Objects/Update.php#L188-L191

Added lines #L188 - L191 were not covered by tests
default => "",
};
}
}

0 comments on commit 49aeec3

Please sign in to comment.