Skip to content

Commit

Permalink
Merge pull request #375 from defstudio/#374_implement_edited_message_…
Browse files Browse the repository at this point in the history
…option_parameter_in_TelegramUpdate

TelegramUpdate new optional parameter (edited_message)
  • Loading branch information
fabio-ivona authored May 18, 2023
2 parents 6ca8e9c + 1b02375 commit ab9ea93
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/DTO/TelegramUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ private function __construct()
* @param array{
* update_id:int,
* message?:array<string, mixed>,
* edited_message?:array<string, mixed>,
* channel_post?:array<string, mixed>,
* callback_query?:array<string, mixed>,
* my_chat_member?:array<string, mixed>,
Expand All @@ -41,6 +42,11 @@ public static function fromArray(array $data): TelegramUpdate
$update->message = Message::fromArray($data['message']);
}

if (isset($data['edited_message'])) {
/* @phpstan-ignore-next-line */
$update->message = Message::fromArray($data['edited_message']);
}

if (isset($data['channel_post'])) {
/* @phpstan-ignore-next-line */
$update->message = Message::fromArray($data['channel_post']);
Expand Down
8 changes: 8 additions & 0 deletions src/Handlers/WebhookHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@ public function handle(Request $request, TelegraphBot $bot): void
return;
}

if ($this->request->has('edited_message')) {
/* @phpstan-ignore-next-line */
$this->message = Message::fromArray($this->request->input('edited_message'));
$this->handleMessage();

return;
}

if ($this->request->has('channel_post')) {
/* @phpstan-ignore-next-line */
$this->message = Message::fromArray($this->request->input('channel_post'));
Expand Down
5 changes: 5 additions & 0 deletions tests/Unit/DTO/TelegramUpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
'date' => now()->timestamp,
'text' => 'f',
],
'edited_message' => [
'message_id' => 2,
'date' => now()->timestamp,
'text' => 'f',
],
'channel_post' => [
'message_id' => 4,
'date' => now()->timestamp,
Expand Down

0 comments on commit ab9ea93

Please sign in to comment.