mirror of
https://github.com/BushlanovDev/max-bot-api-client-php.git
synced 2026-10-06 20:10:31 +00:00
Add fields and markup added in schema 0.0.33
- Recipient::$postId: the commented post, set for comments - ContactAttachmentPayload::$hash: hash of the VCF info - ChatPatch: document the description field (up to 16000 chars, empty string removes it) - QuoteMarkup and MarkupType::Quote. createMarkupElement() threw "Unknown or unsupported markup type" on a quote block, so a message with a quote could not be parsed at all New constructor parameters are optional and last, so existing positional calls keep working; toArray() of these models now also carries the new keys.
This commit is contained in:
@@ -15,4 +15,5 @@ enum MarkupType: string
|
||||
case UserMention = 'user_mention';
|
||||
case Heading = 'heading';
|
||||
case Highlighted = 'highlighted';
|
||||
case Quote = 'quote';
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ use BushlanovDev\MaxMessengerBot\Models\Markup\HeadingMarkup;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Markup\HighlightedMarkup;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Markup\LinkMarkup;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Markup\MonospacedMarkup;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Markup\QuoteMarkup;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Markup\StrikethroughMarkup;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Markup\StrongMarkup;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Markup\UnderlineMarkup;
|
||||
@@ -506,6 +507,7 @@ readonly class ModelFactory
|
||||
MarkupType::Underline => UnderlineMarkup::fromArray($data),
|
||||
MarkupType::Heading => HeadingMarkup::fromArray($data),
|
||||
MarkupType::Highlighted => HighlightedMarkup::fromArray($data),
|
||||
MarkupType::Quote => QuoteMarkup::fromArray($data),
|
||||
MarkupType::Link => LinkMarkup::fromArray($data),
|
||||
MarkupType::UserMention => UserMentionMarkup::fromArray($data),
|
||||
default => throw new LogicException(
|
||||
|
||||
@@ -15,10 +15,12 @@ final readonly class ContactAttachmentPayload extends AbstractModel
|
||||
/**
|
||||
* @param string|null $vcfInfo User info in VCF format.
|
||||
* @param UserWithPhoto|null $maxInfo User info if the contact is a Max user.
|
||||
* @param string|null $hash Hash of the user info in VCF format.
|
||||
*/
|
||||
public function __construct(
|
||||
public ?string $vcfInfo,
|
||||
public ?UserWithPhoto $maxInfo,
|
||||
public ?string $hash = null,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\PhotoAttachmentRequ
|
||||
*
|
||||
* @property-read PhotoAttachmentRequestPayload|null $icon
|
||||
* @property-read string|null $title
|
||||
* @property-read string|null $description Up to 16000 characters; an empty string removes the description.
|
||||
* @property-read string|null $pin Message ID to be pinned.
|
||||
* @property-read bool|null $notify
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Markup;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\MarkupType;
|
||||
|
||||
/**
|
||||
* Represents a quote block in the text.
|
||||
*/
|
||||
final readonly class QuoteMarkup extends AbstractMarkup
|
||||
{
|
||||
/**
|
||||
* @param int $from Element start index (zero-based) in text.
|
||||
* @param int $length Length of the markup element.
|
||||
*/
|
||||
public function __construct(
|
||||
int $from,
|
||||
int $length,
|
||||
) {
|
||||
parent::__construct(MarkupType::Quote, $from, $length);
|
||||
}
|
||||
}
|
||||
@@ -15,11 +15,13 @@ final readonly class Recipient extends AbstractModel
|
||||
* @param ChatType $chatType Chat type (dialog, chat or channel).
|
||||
* @param int|null $userId User identifier, if message was sent to user.
|
||||
* @param int|null $chatId Chat identifier.
|
||||
* @param string|null $postId Identifier of the commented post, for comments.
|
||||
*/
|
||||
public function __construct(
|
||||
public ChatType $chatType,
|
||||
public ?int $userId,
|
||||
public ?int $chatId,
|
||||
public ?string $postId = null,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,5 +24,17 @@ final class ContactAttachmentTest extends TestCase
|
||||
$attachment = ContactAttachment::fromArray($data);
|
||||
$this->assertInstanceOf(ContactAttachment::class, $attachment);
|
||||
$this->assertSame('vcf', $attachment->payload->vcfInfo);
|
||||
$this->assertNull($attachment->payload->hash);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function payloadCarriesTheVcfHash(): void
|
||||
{
|
||||
$attachment = ContactAttachment::fromArray([
|
||||
'type' => 'contact',
|
||||
'payload' => ['vcf_info' => 'vcf', 'max_info' => null, 'hash' => 'abc123'],
|
||||
]);
|
||||
|
||||
$this->assertSame('abc123', $attachment->payload->hash);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,6 @@ final class ContactAttachmentPayloadTest extends TestCase
|
||||
$payload = new ContactAttachmentPayload('vcf_info_string', $user);
|
||||
$this->assertSame('vcf_info_string', $payload->vcfInfo);
|
||||
$this->assertSame($user, $payload->maxInfo);
|
||||
$this->assertEquals(['vcf_info' => 'vcf_info_string', 'max_info' => $user->toArray()], $payload->toArray());
|
||||
$this->assertEquals(['vcf_info' => 'vcf_info_string', 'max_info' => $user->toArray(), 'hash' => null], $payload->toArray());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ use BushlanovDev\MaxMessengerBot\Models\Markup\HeadingMarkup;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Markup\HighlightedMarkup;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Markup\LinkMarkup;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Markup\MonospacedMarkup;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Markup\QuoteMarkup;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Markup\StrikethroughMarkup;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Markup\StrongMarkup;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Markup\UnderlineMarkup;
|
||||
@@ -27,6 +28,7 @@ use PHPUnit\Framework\TestCase;
|
||||
#[CoversClass(EmphasizedMarkup::class)]
|
||||
#[CoversClass(HeadingMarkup::class)]
|
||||
#[CoversClass(HighlightedMarkup::class)]
|
||||
#[CoversClass(QuoteMarkup::class)]
|
||||
final class MarkupTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
@@ -140,4 +142,17 @@ final class MarkupTest extends TestCase
|
||||
$this->assertSame(4, $markup->length);
|
||||
$this->assertEquals($data, $markup->toArray());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function quoteMarkupIsCreatedCorrectly(): void
|
||||
{
|
||||
$data = ['type' => 'quote', 'from' => 0, 'length' => 12];
|
||||
$markup = QuoteMarkup::fromArray($data);
|
||||
|
||||
$this->assertInstanceOf(QuoteMarkup::class, $markup);
|
||||
$this->assertSame(MarkupType::Quote, $markup->type);
|
||||
$this->assertSame(0, $markup->from);
|
||||
$this->assertSame(12, $markup->length);
|
||||
$this->assertEquals($data, $markup->toArray());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ final class MessageTest extends TestCase
|
||||
'chat_type' => 'dialog',
|
||||
'user_id' => 123,
|
||||
'chat_id' => null,
|
||||
'post_id' => null,
|
||||
],
|
||||
'body' => [
|
||||
'mid' => 'mid.456.xyz',
|
||||
|
||||
@@ -29,7 +29,20 @@ final class RecipientTest extends TestCase
|
||||
$array = $receipt->toArray();
|
||||
|
||||
$this->assertIsArray($array);
|
||||
unset($array['user_id']);
|
||||
unset($array['user_id'], $array['post_id']);
|
||||
$this->assertSame($data, $array);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function commentRecipientCarriesThePostId(): void
|
||||
{
|
||||
$recipient = Recipient::fromArray([
|
||||
'chat_type' => 'channel',
|
||||
'chat_id' => -100,
|
||||
'post_id' => 'mid.post',
|
||||
]);
|
||||
|
||||
$this->assertSame('mid.post', $recipient->postId);
|
||||
$this->assertNull(Recipient::fromArray(['chat_type' => 'dialog', 'user_id' => 1])->postId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user