From 3e93f147847f9089a97a8489bf96a85ff07390b9 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 16 Jul 2025 08:47:16 +0300 Subject: [PATCH] Added attachment LinkButton --- README.md | 19 ++++++++++-- src/Api.php | 5 --- src/ClientApiInterface.php | 1 - src/ModelFactory.php | 4 --- .../Attachments/Buttons/CallbackButton.php | 5 +++ src/Models/Attachments/Buttons/LinkButton.php | 23 ++++++++++++++ .../Attachments/Buttons/LinkButtonTest.php | 31 +++++++++++++++++++ 7 files changed, 75 insertions(+), 13 deletions(-) create mode 100644 src/Models/Attachments/Buttons/LinkButton.php create mode 100644 tests/Models/Attachments/Buttons/LinkButtonTest.php diff --git a/README.md b/README.md index 89c65a3..98fe3a9 100644 --- a/README.md +++ b/README.md @@ -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 отправит вам токен. diff --git a/src/Api.php b/src/Api.php index 4f3dd6c..d968faf 100644 --- a/src/Api.php +++ b/src/Api.php @@ -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( diff --git a/src/ClientApiInterface.php b/src/ClientApiInterface.php index 413d81f..50aec21 100644 --- a/src/ClientApiInterface.php +++ b/src/ClientApiInterface.php @@ -19,7 +19,6 @@ interface ClientApiInterface * @param array $body The request body. * * @return array 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. diff --git a/src/ModelFactory.php b/src/ModelFactory.php index 98acb95..8b69edb 100644 --- a/src/ModelFactory.php +++ b/src/ModelFactory.php @@ -21,7 +21,6 @@ class ModelFactory * @param array $data * * @return Result - * * @throws ReflectionException */ public function createResult(array $data): Result @@ -35,7 +34,6 @@ class ModelFactory * @param array $data * * @return BotInfo - * * @throws ReflectionException */ public function createBotInfo(array $data): BotInfo @@ -49,7 +47,6 @@ class ModelFactory * @param array $data * * @return Subscription - * * @throws ReflectionException */ public function createSubscription(array $data): Subscription @@ -78,7 +75,6 @@ class ModelFactory * @param array $data * * @return Message - * * @throws ReflectionException */ public function createMessage(array $data): Message diff --git a/src/Models/Attachments/Buttons/CallbackButton.php b/src/Models/Attachments/Buttons/CallbackButton.php index 7183dca..a539dbb 100644 --- a/src/Models/Attachments/Buttons/CallbackButton.php +++ b/src/Models/Attachments/Buttons/CallbackButton.php @@ -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); diff --git a/src/Models/Attachments/Buttons/LinkButton.php b/src/Models/Attachments/Buttons/LinkButton.php new file mode 100644 index 0000000..a6d98d2 --- /dev/null +++ b/src/Models/Attachments/Buttons/LinkButton.php @@ -0,0 +1,23 @@ +url = $url; + } +} diff --git a/tests/Models/Attachments/Buttons/LinkButtonTest.php b/tests/Models/Attachments/Buttons/LinkButtonTest.php new file mode 100644 index 0000000..e3720b0 --- /dev/null +++ b/tests/Models/Attachments/Buttons/LinkButtonTest.php @@ -0,0 +1,31 @@ + 'https://example.com', + 'type' => ButtonType::Link->value, + 'text' => 'Test Button', + ]; + + $resultArray = $button->toArray(); + + $this->assertSame($expectedArray, $resultArray); + } +}