Added attachment LinkButton

This commit is contained in:
Alex
2025-07-16 08:47:16 +03:00
parent a7c948dd95
commit 3e93f14784
7 changed files with 75 additions and 13 deletions
+16 -3
View File
@@ -1,5 +1,18 @@
# Max Bot API Client library for PHP
[![Actions status](https://github.com/BushlanovDev/max-bot-api-client-php/actions/workflows/ci.yml/badge.svg?style=flat-square)](https://github.com/BushlanovDev/max-bot-api-client-php/actions)
[![PHP version](https://img.shields.io/badge/php-%3E%3D%208.3-8892BF.svg?style=flat-square)](https://github.com/BushlanovDev/max-bot-api-client-php)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
[![Actions status](https://github.com/BushlanovDev/max-bot-api-client-php/actions/workflows/ci.yml/badge.svg?style=flat-square)](https://github.com/BushlanovDev/max-bot-api-client-php/actions)
[![PHP version](https://img.shields.io/badge/php-%3E%3D%208.3-8892BF.svg?style=flat-square)](https://github.com/BushlanovDev/max-bot-api-client-php)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
> [!IMPORTANT]
> Библиотека в стадии активной разработки.
## Быстрый старт
> Если вы новичок, то можете прочитать [официальную документацию](https://dev.max.ru/), написанную разработчиками Max
### Получение токена
Откройте диалог с [MasterBot](https://max.ru/MasterBot), следуйте инструкциям и создайте нового бота. После создания
бота MasterBot отправит вам токен.
-5
View File
@@ -65,7 +65,6 @@ class Api
* Information about the current bot, identified by an access token.
*
* @return BotInfo
*
* @throws ClientApiException
* @throws NetworkException
* @throws SerializationException
@@ -82,7 +81,6 @@ class Api
* List of all active webhook subscriptions.
*
* @return Subscription[]
*
* @throws ClientApiException
* @throws NetworkException
* @throws SerializationException
@@ -103,7 +101,6 @@ class Api
* @param UpdateType[]|null $updateTypes List of update types.
*
* @return Result
*
* @throws ClientApiException
* @throws NetworkException
* @throws SerializationException
@@ -134,7 +131,6 @@ class Api
* @param string $url URL webhook.
*
* @return Result
*
* @throws ClientApiException
* @throws NetworkException
* @throws SerializationException
@@ -163,7 +159,6 @@ class Api
* @param bool $disableLinkPreview If false, server will not generate media preview for links in text.
*
* @return Message
*
* @throws ReflectionException
*/
public function sendMessage(
-1
View File
@@ -19,7 +19,6 @@ interface ClientApiInterface
* @param array<string, mixed> $body The request body.
*
* @return array<string, mixed> The decoded JSON response as an associative array.
*
* @throws ClientApiException for API-level errors (4xx, 5xx).
* @throws NetworkException for network-related issues.
* @throws SerializationException for JSON encoding/decoding failures.
-4
View File
@@ -21,7 +21,6 @@ class ModelFactory
* @param array<string, mixed> $data
*
* @return Result
*
* @throws ReflectionException
*/
public function createResult(array $data): Result
@@ -35,7 +34,6 @@ class ModelFactory
* @param array<string, mixed> $data
*
* @return BotInfo
*
* @throws ReflectionException
*/
public function createBotInfo(array $data): BotInfo
@@ -49,7 +47,6 @@ class ModelFactory
* @param array<string, mixed> $data
*
* @return Subscription
*
* @throws ReflectionException
*/
public function createSubscription(array $data): Subscription
@@ -78,7 +75,6 @@ class ModelFactory
* @param array<string, mixed> $data
*
* @return Message
*
* @throws ReflectionException
*/
public function createMessage(array $data): Message
@@ -12,6 +12,11 @@ final readonly class CallbackButton extends AbstractButton
public string $payload;
public ?Intent $intent;
/**
* @param string $text Visible button text (1 to 128 characters).
* @param string $payload Button token (up to 1024 characters).
* @param Intent|null $intent The intent of the button. Affects how it is displayed by the client.
*/
public function __construct(string $text, string $payload, ?Intent $intent = null)
{
parent::__construct(ButtonType::Callback, $text);
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons;
use BushlanovDev\MaxMessengerBot\Enums\ButtonType;
final readonly class LinkButton extends AbstractButton
{
public string $url;
/**
* @param string $text Visible button text (1 to 128 characters).
* @param string $url Button URL (1 to 2048 characters).
*/
public function __construct(string $text, string $url)
{
parent::__construct(ButtonType::Link, $text);
$this->url = $url;
}
}
@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Buttons;
use BushlanovDev\MaxMessengerBot\Enums\ButtonType;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\LinkButton;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
#[CoversClass(LinkButton::class)]
final class LinkButtonTest extends TestCase
{
#[Test]
public function toArraySerializesCorrectly(): void
{
$button = new LinkButton('Test Button', 'https://example.com');
$expectedArray = [
'url' => 'https://example.com',
'type' => ButtonType::Link->value,
'text' => 'Test Button',
];
$resultArray = $button->toArray();
$this->assertSame($expectedArray, $resultArray);
}
}