Add comments API

Schema 0.0.33 adds comments to channel posts:

- GET    /messages/{messageId}/comments               getComments()
- GET    /messages/{messageId}/comments/{commentId}   getCommentById()
- POST   /messages/{messageId}/comments               sendComment()
- PUT    /messages/{messageId}/comments               editComment()
- DELETE /messages/{messageId}/comments               deleteComment()

Comments get their own models (CommentMessage, CommentMessageBody,
CommentLinkedMessage): unlike Message they have no attachments and
no public URL. README coverage map and docs updated.
This commit is contained in:
Timofey
2026-09-28 00:17:27 +05:00
parent 1bfeb17a15
commit c8f3b8e33d
10 changed files with 677 additions and 0 deletions
+60
View File
@@ -29,6 +29,10 @@ use BushlanovDev\MaxMessengerBot\Models\Attachments\ShareAttachment;
use BushlanovDev\MaxMessengerBot\Models\BotCommand;
use BushlanovDev\MaxMessengerBot\Models\BotCommandsInfo;
use BushlanovDev\MaxMessengerBot\Models\BotInfo;
use BushlanovDev\MaxMessengerBot\Models\Markup\QuoteMarkup;
use BushlanovDev\MaxMessengerBot\Models\CommentLinkedMessage;
use BushlanovDev\MaxMessengerBot\Models\CommentMessage;
use BushlanovDev\MaxMessengerBot\Models\CommentMessageBody;
use BushlanovDev\MaxMessengerBot\Models\Chat;
use BushlanovDev\MaxMessengerBot\Models\ChatList;
use BushlanovDev\MaxMessengerBot\Models\ChatMember;
@@ -67,6 +71,10 @@ use Psr\Log\LoggerInterface;
#[UsesClass(BotInfo::class)]
#[UsesClass(BotCommand::class)]
#[UsesClass(BotCommandsInfo::class)]
#[UsesClass(CommentMessage::class)]
#[UsesClass(CommentMessageBody::class)]
#[UsesClass(CommentLinkedMessage::class)]
#[UsesClass(QuoteMarkup::class)]
#[UsesClass(Result::class)]
#[UsesClass(Subscription::class)]
#[UsesClass(ArrayOf::class)]
@@ -198,6 +206,58 @@ final class ModelFactoryTest extends TestCase
$this->assertNull($botCommands->commands[1]->description);
}
#[Test]
public function createCommentMessageHydratesBodyMarkupAndLink(): void
{
$comment = $this->factory->createCommentMessage([
'timestamp' => 1,
'recipient' => ['chat_type' => 'channel', 'chat_id' => -100, 'post_id' => 'mid.post'],
'body' => [
'mid' => 'mid.comment',
'seq' => 3,
'text' => 'Quoted reply',
'markup' => [['type' => 'quote', 'from' => 0, 'length' => 6]],
],
'sender' => ['user_id' => 42, 'first_name' => 'Anna', 'is_bot' => false],
'link' => [
'type' => 'reply',
'message' => [
'mid' => 'mid.parent',
'seq' => 2,
'text' => 'Parent',
'markup' => [['type' => 'strong', 'from' => 0, 'length' => 6]],
],
],
]);
$this->assertInstanceOf(CommentMessage::class, $comment);
$this->assertSame('mid.post', $comment->recipient->postId);
$this->assertSame('Quoted reply', $comment->body->text);
$this->assertInstanceOf(QuoteMarkup::class, $comment->body->markup[0]);
$this->assertSame(42, $comment->sender?->userId);
$this->assertInstanceOf(CommentLinkedMessage::class, $comment->link);
$this->assertInstanceOf(StrongMarkup::class, $comment->link->message->markup[0]);
$this->assertNull($comment->stat);
}
#[Test]
public function createCommentMessagesAndSendResponseUnwrapComments(): void
{
$data = [
'timestamp' => 1,
'recipient' => ['chat_type' => 'channel', 'chat_id' => -100],
'body' => ['mid' => 'mid.comment', 'seq' => 1],
];
$list = $this->factory->createCommentMessages(['messages' => [$data, $data]]);
$sent = $this->factory->createCommentMessageFromSendResponse(['message' => $data]);
$this->assertCount(2, $list);
$this->assertContainsOnlyInstancesOf(CommentMessage::class, $list);
$this->assertSame([], $this->factory->createCommentMessages([]));
$this->assertSame('mid.comment', $sent->body->mid);
}
#[Test]
public function createBotInfoHandlesNullCommands(): void
{