mirror of
https://github.com/BushlanovDev/max-bot-api-client-php.git
synced 2026-08-17 12:13:12 +00:00
New button type clipboard
This commit is contained in:
@@ -13,4 +13,5 @@ enum InlineButtonType: string
|
||||
case OpenApp = 'open_app';
|
||||
case Message = 'message';
|
||||
case Chat = 'chat';
|
||||
case Clipboard = 'clipboard';
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ use BushlanovDev\MaxMessengerBot\Models\Attachments\AudioAttachment;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\AbstractInlineButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\CallbackButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\ChatButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\ClipboardButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\LinkButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\MessageButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\OpenAppButton;
|
||||
@@ -312,6 +313,7 @@ readonly class ModelFactory
|
||||
InlineButtonType::RequestGeoLocation => RequestGeoLocationButton::fromArray($data),
|
||||
InlineButtonType::Chat => ChatButton::fromArray($data),
|
||||
InlineButtonType::OpenApp => OpenAppButton::fromArray($data),
|
||||
InlineButtonType::Clipboard => ClipboardButton::fromArray($data),
|
||||
InlineButtonType::Message => MessageButton::fromArray($data),
|
||||
default => throw new LogicException(
|
||||
'Unknown or unsupported inline button type: ' . ($data['type'] ?? 'none')
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\InlineButtonType;
|
||||
|
||||
/**
|
||||
* Opens the bot's mini-application.
|
||||
*/
|
||||
final readonly class ClipboardButton extends AbstractInlineButton
|
||||
{
|
||||
|
||||
public ?string $payload;
|
||||
|
||||
/**
|
||||
* @param string $text Visible button text (1 to 128 characters).
|
||||
* @param string $payload Text which will be copied.
|
||||
*/
|
||||
public function __construct(string $text, string $payload)
|
||||
{
|
||||
parent::__construct(InlineButtonType::Clipboard, $text);
|
||||
|
||||
$this->payload = $payload;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Buttons\Inline;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\InlineButtonType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\ClipboardButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\OpenAppButton;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(ClipboardButton::class)]
|
||||
final class ClipboardButtonTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function toArraySerializesCorrectly(): void
|
||||
{
|
||||
$button = new ClipboardButton('display', 'copy');
|
||||
|
||||
$expectedArray = [
|
||||
'text' => 'display',
|
||||
'payload' => 'copy',
|
||||
'type' => InlineButtonType::Clipboard->value,
|
||||
|
||||
];
|
||||
|
||||
$resultArray = $button->toArray();
|
||||
|
||||
$this->assertSame($expectedArray, $resultArray);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function fromArrayHydratesCorrectly(): void
|
||||
{
|
||||
$data = [
|
||||
'type' => 'clipboard',
|
||||
'text' => 'display',
|
||||
'payload' => 'copy'
|
||||
];
|
||||
|
||||
$button = ClipboardButton::fromArray($data);
|
||||
|
||||
$this->assertInstanceOf(ClipboardButton::class, $button);
|
||||
$this->assertSame(InlineButtonType::Clipboard, $button->type);
|
||||
$this->assertSame('display', $button->text);
|
||||
$this->assertSame('copy', $button->payload);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user