From dd00b4c5e6b6ae1c515d915b61306ef1aeb1876b Mon Sep 17 00:00:00 2001 From: Timofey <57951811+smotim@users.noreply.github.com> Date: Mon, 28 Sep 2026 00:28:49 +0500 Subject: [PATCH] Allow comment_removed without post_id The schema lists post_id as required, but the official TypeScript client types it as `string | null`. A null would fail with a TypeError and, unlike an unknown update type, TypeError is not caught while parsing updates. --- src/Models/Updates/CommentRemovedUpdate.php | 4 ++-- .../Models/Updates/CommentRemovedUpdateTest.php | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Models/Updates/CommentRemovedUpdate.php b/src/Models/Updates/CommentRemovedUpdate.php index 499ece8..3d1f0f4 100644 --- a/src/Models/Updates/CommentRemovedUpdate.php +++ b/src/Models/Updates/CommentRemovedUpdate.php @@ -17,14 +17,14 @@ final readonly class CommentRemovedUpdate extends AbstractUpdate * @param string $messageId Identifier of the removed comment. * @param int $chatId Chat identifier where the comment has been deleted. * @param int $userId User who deleted this comment. - * @param string $postId Identifier of the commented post. + * @param string|null $postId Identifier of the commented post. */ public function __construct( int $timestamp, public string $messageId, public int $chatId, public int $userId, - public string $postId, + public ?string $postId, ) { parent::__construct(UpdateType::CommentRemoved, $timestamp); } diff --git a/tests/Models/Updates/CommentRemovedUpdateTest.php b/tests/Models/Updates/CommentRemovedUpdateTest.php index f4774c4..177d060 100644 --- a/tests/Models/Updates/CommentRemovedUpdateTest.php +++ b/tests/Models/Updates/CommentRemovedUpdateTest.php @@ -31,4 +31,20 @@ final class CommentRemovedUpdateTest extends TestCase $this->assertSame(42, $update->userId); $this->assertSame('mid.post', $update->postId); } + + #[Test] + public function postIdMayBeNull(): void + { + // The official TypeScript client types post_id as `string | null` + $update = CommentRemovedUpdate::fromArray([ + 'update_type' => UpdateType::CommentRemoved->value, + 'timestamp' => 1678886400000, + 'message_id' => 'mid.comment', + 'chat_id' => -100, + 'user_id' => 42, + 'post_id' => null, + ]); + + $this->assertNull($update->postId); + } }