diff --git a/README.md b/README.md index 6601a23..e35a3f3 100644 --- a/README.md +++ b/README.md @@ -50,14 +50,13 @@ $api->sendMessage( ```php $api->subscribe( - new \BushlanovDev\MaxMessengerBot\Models\SubscriptionRequest( - 'https://example.com/webhook', // URL на который будут приходить хуки - 'super_secret', // Секретная фраза для проверки хуков - [ - // Типы хуков которые вы хотите получать (либо ничего не указывать, чтобы получать все) - \BushlanovDev\MaxMessengerBot\Enums\UpdateType::MessageCreated, - ], - ), + url: 'https://example.com/webhook', // URL на который будут приходить хуки + secret: 'super_secret', // Секретная фраза для проверки хуков + updateTypes: [ + // Типы хуков которые вы хотите получать (либо ничего не указывать, чтобы получать все) + UpdateType::BotStarted, + UpdateType::MessageCreated, + ], ); ``` diff --git a/src/Api.php b/src/Api.php index d6810c7..470ec4f 100644 --- a/src/Api.php +++ b/src/Api.php @@ -48,9 +48,10 @@ use RuntimeException; */ class Api { - private const string API_BASE_URL = 'https://botapi.max.ru'; public const string API_VERSION = '0.0.6'; + private const string API_BASE_URL = 'https://botapi.max.ru'; + private const string METHOD_GET = 'GET'; private const string METHOD_POST = 'POST'; private const string METHOD_DELETE = 'DELETE'; @@ -88,7 +89,7 @@ class Api public function __construct( string $accessToken, ?ClientApiInterface $client = null, - ?ModelFactory $modelFactory = null + ?ModelFactory $modelFactory = null, ) { if ($client === null) { if (!class_exists(\GuzzleHttp\Client::class) || !class_exists(\GuzzleHttp\Psr7\HttpFactory::class)) { @@ -114,6 +115,25 @@ class Api $this->modelFactory = $modelFactory ?? new ModelFactory(); } + /** + * Performs a request to the Max Bot API. + * + * @param string $method The HTTP method (GET, POST, PATCH, etc.). + * @param string $uri The API endpoint (e.g., '/me', '/messages'). + * @param array $queryParams Query parameters for the request. + * @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. + * @codeCoverageIgnore + */ + public function request(string $method, string $uri, array $queryParams = [], array $body = []): array + { + return $this->client->request($method, $uri, $queryParams, $body); + } + /** * Creates a WebhookHandler instance, pre-configured with the necessary dependencies. * diff --git a/src/Enums/AttachmentType.php b/src/Enums/AttachmentType.php index 88691d2..4ff02c0 100644 --- a/src/Enums/AttachmentType.php +++ b/src/Enums/AttachmentType.php @@ -13,6 +13,7 @@ enum AttachmentType: string case Sticker = 'sticker'; case Contact = 'contact'; case InlineKeyboard = 'inline_keyboard'; + case ReplyKeyboard = 'reply_keyboard'; case Location = 'location'; case Share = 'share'; } diff --git a/src/Enums/ButtonType.php b/src/Enums/InlineButtonType.php similarity index 84% rename from src/Enums/ButtonType.php rename to src/Enums/InlineButtonType.php index 7521458..ae73749 100644 --- a/src/Enums/ButtonType.php +++ b/src/Enums/InlineButtonType.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace BushlanovDev\MaxMessengerBot\Enums; -enum ButtonType: string +enum InlineButtonType: string { case Callback = 'callback'; case Link = 'link'; @@ -12,4 +12,5 @@ enum ButtonType: string case RequestContact = 'request_contact'; case OpenApp = 'open_app'; case Message = 'message'; + case Chat = 'chat'; } diff --git a/src/Enums/ReplyButtonType.php b/src/Enums/ReplyButtonType.php new file mode 100644 index 0000000..9c9bfc7 --- /dev/null +++ b/src/Enums/ReplyButtonType.php @@ -0,0 +1,12 @@ +payload = $payload; $this->intent = $intent; diff --git a/src/Models/Attachments/Buttons/Inline/ChatButton.php b/src/Models/Attachments/Buttons/Inline/ChatButton.php new file mode 100644 index 0000000..201a3fd --- /dev/null +++ b/src/Models/Attachments/Buttons/Inline/ChatButton.php @@ -0,0 +1,31 @@ +url = $url; } diff --git a/src/Models/Attachments/Buttons/OpenAppButton.php b/src/Models/Attachments/Buttons/Inline/OpenAppButton.php similarity index 78% rename from src/Models/Attachments/Buttons/OpenAppButton.php rename to src/Models/Attachments/Buttons/Inline/OpenAppButton.php index 08008f9..4d5c2a1 100644 --- a/src/Models/Attachments/Buttons/OpenAppButton.php +++ b/src/Models/Attachments/Buttons/Inline/OpenAppButton.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons; +namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline; -use BushlanovDev\MaxMessengerBot\Enums\ButtonType; +use BushlanovDev\MaxMessengerBot\Enums\InlineButtonType; /** * Opens the bot's mini-application. */ -final readonly class OpenAppButton extends AbstractButton +final readonly class OpenAppButton extends AbstractInlineButton { public ?string $webApp; public ?int $contactId; @@ -21,7 +21,7 @@ final readonly class OpenAppButton extends AbstractButton */ public function __construct(string $text, ?string $webApp = null, ?int $contactId = null) { - parent::__construct(ButtonType::OpenApp, $text); + parent::__construct(InlineButtonType::OpenApp, $text); $this->webApp = $webApp; $this->contactId = $contactId; diff --git a/src/Models/Attachments/Buttons/RequestContactButton.php b/src/Models/Attachments/Buttons/Inline/RequestContactButton.php similarity index 62% rename from src/Models/Attachments/Buttons/RequestContactButton.php rename to src/Models/Attachments/Buttons/Inline/RequestContactButton.php index 5b4a8ba..ae7ae56 100644 --- a/src/Models/Attachments/Buttons/RequestContactButton.php +++ b/src/Models/Attachments/Buttons/Inline/RequestContactButton.php @@ -2,20 +2,20 @@ declare(strict_types=1); -namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons; +namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline; -use BushlanovDev\MaxMessengerBot\Enums\ButtonType; +use BushlanovDev\MaxMessengerBot\Enums\InlineButtonType; /** * Requests the user permission to access contact information (phone number, short link, email). */ -final readonly class RequestContactButton extends AbstractButton +final readonly class RequestContactButton extends AbstractInlineButton { /** * @param string $text Visible button text (1 to 128 characters). */ public function __construct(string $text) { - parent::__construct(ButtonType::RequestContact, $text); + parent::__construct(InlineButtonType::RequestContact, $text); } } diff --git a/src/Models/Attachments/Buttons/RequestGeoLocationButton.php b/src/Models/Attachments/Buttons/Inline/RequestGeoLocationButton.php similarity index 70% rename from src/Models/Attachments/Buttons/RequestGeoLocationButton.php rename to src/Models/Attachments/Buttons/Inline/RequestGeoLocationButton.php index 2395917..0db1f53 100644 --- a/src/Models/Attachments/Buttons/RequestGeoLocationButton.php +++ b/src/Models/Attachments/Buttons/Inline/RequestGeoLocationButton.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons; +namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline; -use BushlanovDev\MaxMessengerBot\Enums\ButtonType; +use BushlanovDev\MaxMessengerBot\Enums\InlineButtonType; /** * After pressing this type of button client sends new message with attachment of current user geo location. */ -final readonly class RequestGeoLocationButton extends AbstractButton +final readonly class RequestGeoLocationButton extends AbstractInlineButton { public bool $quick; @@ -19,7 +19,7 @@ final readonly class RequestGeoLocationButton extends AbstractButton */ public function __construct(string $text, bool $quick = false) { - parent::__construct(ButtonType::RequestGeoLocation, $text); + parent::__construct(InlineButtonType::RequestGeoLocation, $text); $this->quick = $quick; } diff --git a/src/Models/Attachments/Buttons/Reply/AbstractReplyButton.php b/src/Models/Attachments/Buttons/Reply/AbstractReplyButton.php new file mode 100644 index 0000000..5d02042 --- /dev/null +++ b/src/Models/Attachments/Buttons/Reply/AbstractReplyButton.php @@ -0,0 +1,21 @@ + [ [ [ - 'type' => ButtonType::Callback->value, + 'type' => InlineButtonType::Callback->value, 'text' => 'Press Me', 'payload' => 'payload_123', 'intent' => null, diff --git a/tests/Models/Attachments/Buttons/CallbackButtonTest.php b/tests/Models/Attachments/Buttons/Inline/CallbackButtonTest.php similarity index 78% rename from tests/Models/Attachments/Buttons/CallbackButtonTest.php rename to tests/Models/Attachments/Buttons/Inline/CallbackButtonTest.php index eda8f99..890db84 100644 --- a/tests/Models/Attachments/Buttons/CallbackButtonTest.php +++ b/tests/Models/Attachments/Buttons/Inline/CallbackButtonTest.php @@ -2,11 +2,11 @@ declare(strict_types=1); -namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Buttons; +namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Buttons\Inline; -use BushlanovDev\MaxMessengerBot\Enums\ButtonType; +use BushlanovDev\MaxMessengerBot\Enums\InlineButtonType; use BushlanovDev\MaxMessengerBot\Enums\Intent; -use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\CallbackButton; +use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\CallbackButton; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; @@ -22,7 +22,7 @@ final class CallbackButtonTest extends TestCase $expectedArray = [ 'payload' => 'test_payload', 'intent' => Intent::Default->value, - 'type' => ButtonType::Callback->value, + 'type' => InlineButtonType::Callback->value, 'text' => 'Test Button', ]; diff --git a/tests/Models/Attachments/Buttons/Inline/ChatButtonTest.php b/tests/Models/Attachments/Buttons/Inline/ChatButtonTest.php new file mode 100644 index 0000000..4ad7748 --- /dev/null +++ b/tests/Models/Attachments/Buttons/Inline/ChatButtonTest.php @@ -0,0 +1,57 @@ + 'chat', + 'text' => 'Discuss Topic', + 'chat_title' => 'Topic Discussion', + 'chat_description' => null, + 'start_payload' => null, + 'uuid' => null, + ]; + + $this->assertEquals($expected, $button->toArray()); + } + + #[Test] + public function toArrayWithAllParameters(): void + { + $button = new ChatButton( + text: 'Join Project Chat', + chatTitle: 'Project Alpha Chat', + chatDescription: 'Chat for team members of Project Alpha.', + startPayload: 'project-alpha-join', + uuid: 123456789 + ); + + $expected = [ + 'type' => 'chat', + 'text' => 'Join Project Chat', + 'chat_title' => 'Project Alpha Chat', + 'chat_description' => 'Chat for team members of Project Alpha.', + 'start_payload' => 'project-alpha-join', + 'uuid' => 123456789, + ]; + + $this->assertEquals($expected, $button->toArray()); + } +} diff --git a/tests/Models/Attachments/Buttons/LinkButtonTest.php b/tests/Models/Attachments/Buttons/Inline/LinkButtonTest.php similarity index 76% rename from tests/Models/Attachments/Buttons/LinkButtonTest.php rename to tests/Models/Attachments/Buttons/Inline/LinkButtonTest.php index e3720b0..e4abecc 100644 --- a/tests/Models/Attachments/Buttons/LinkButtonTest.php +++ b/tests/Models/Attachments/Buttons/Inline/LinkButtonTest.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Buttons; +namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Buttons\Inline; -use BushlanovDev\MaxMessengerBot\Enums\ButtonType; -use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\LinkButton; +use BushlanovDev\MaxMessengerBot\Enums\InlineButtonType; +use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\LinkButton; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; @@ -20,7 +20,7 @@ final class LinkButtonTest extends TestCase $expectedArray = [ 'url' => 'https://example.com', - 'type' => ButtonType::Link->value, + 'type' => InlineButtonType::Link->value, 'text' => 'Test Button', ]; diff --git a/tests/Models/Attachments/Buttons/OpenAppButtonTest.php b/tests/Models/Attachments/Buttons/Inline/OpenAppButtonTest.php similarity index 76% rename from tests/Models/Attachments/Buttons/OpenAppButtonTest.php rename to tests/Models/Attachments/Buttons/Inline/OpenAppButtonTest.php index 6e288df..10b3084 100644 --- a/tests/Models/Attachments/Buttons/OpenAppButtonTest.php +++ b/tests/Models/Attachments/Buttons/Inline/OpenAppButtonTest.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Buttons; +namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Buttons\Inline; -use BushlanovDev\MaxMessengerBot\Enums\ButtonType; -use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\OpenAppButton; +use BushlanovDev\MaxMessengerBot\Enums\InlineButtonType; +use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\OpenAppButton; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; @@ -21,7 +21,7 @@ final class OpenAppButtonTest extends TestCase $expectedArray = [ 'web_app' => 'MyWebApp', 'contact_id' => 123, - 'type' => ButtonType::OpenApp->value, + 'type' => InlineButtonType::OpenApp->value, 'text' => 'Test Button', ]; diff --git a/tests/Models/Attachments/Buttons/RequestContactTest.php b/tests/Models/Attachments/Buttons/Inline/RequestContactTest.php similarity index 73% rename from tests/Models/Attachments/Buttons/RequestContactTest.php rename to tests/Models/Attachments/Buttons/Inline/RequestContactTest.php index e13b344..bfd96bc 100644 --- a/tests/Models/Attachments/Buttons/RequestContactTest.php +++ b/tests/Models/Attachments/Buttons/Inline/RequestContactTest.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Buttons; +namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Buttons\Inline; -use BushlanovDev\MaxMessengerBot\Enums\ButtonType; -use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\RequestContactButton; +use BushlanovDev\MaxMessengerBot\Enums\InlineButtonType; +use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\RequestContactButton; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; @@ -19,7 +19,7 @@ final class RequestContactTest extends TestCase $button = new RequestContactButton('Test Button'); $expectedArray = [ - 'type' => ButtonType::RequestContact->value, + 'type' => InlineButtonType::RequestContact->value, 'text' => 'Test Button', ]; diff --git a/tests/Models/Attachments/Buttons/RequestGeoLocationTest.php b/tests/Models/Attachments/Buttons/Inline/RequestGeoLocationTest.php similarity index 77% rename from tests/Models/Attachments/Buttons/RequestGeoLocationTest.php rename to tests/Models/Attachments/Buttons/Inline/RequestGeoLocationTest.php index 77d2c66..da25c8f 100644 --- a/tests/Models/Attachments/Buttons/RequestGeoLocationTest.php +++ b/tests/Models/Attachments/Buttons/Inline/RequestGeoLocationTest.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Buttons; +namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Buttons\Inline; -use BushlanovDev\MaxMessengerBot\Enums\ButtonType; -use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\RequestGeoLocationButton; +use BushlanovDev\MaxMessengerBot\Enums\InlineButtonType; +use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\RequestGeoLocationButton; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; @@ -20,7 +20,7 @@ final class RequestGeoLocationTest extends TestCase $expectedArray = [ 'quick' => false, - 'type' => ButtonType::RequestGeoLocation->value, + 'type' => InlineButtonType::RequestGeoLocation->value, 'text' => 'Test Button', ]; @@ -36,7 +36,7 @@ final class RequestGeoLocationTest extends TestCase $expectedArray = [ 'quick' => true, - 'type' => ButtonType::RequestGeoLocation->value, + 'type' => InlineButtonType::RequestGeoLocation->value, 'text' => 'Test Button', ]; diff --git a/tests/Models/Attachments/Buttons/Reply/SendContactButtonTest.php b/tests/Models/Attachments/Buttons/Reply/SendContactButtonTest.php new file mode 100644 index 0000000..eb4b624 --- /dev/null +++ b/tests/Models/Attachments/Buttons/Reply/SendContactButtonTest.php @@ -0,0 +1,27 @@ + 'user_contact', + 'text' => 'Share My Contact', + ]; + + $this->assertEquals($expected, $button->toArray()); + } +} diff --git a/tests/Models/Attachments/Buttons/Reply/SendGeoLocationButtonTest.php b/tests/Models/Attachments/Buttons/Reply/SendGeoLocationButtonTest.php new file mode 100644 index 0000000..fa1ab44 --- /dev/null +++ b/tests/Models/Attachments/Buttons/Reply/SendGeoLocationButtonTest.php @@ -0,0 +1,42 @@ + 'user_geo_location', + 'text' => 'Share Location', + 'quick' => false, + ]; + + $this->assertEquals($expected, $button->toArray()); + } + + #[Test] + public function toArrayWithQuickTrue(): void + { + $button = new SendGeoLocationButton('Quick Share', true); + + $expected = [ + 'type' => 'user_geo_location', + 'text' => 'Quick Share', + 'quick' => true, + ]; + + $this->assertEquals($expected, $button->toArray()); + } +} diff --git a/tests/Models/Attachments/Buttons/Reply/SendMessageButtonTest.php b/tests/Models/Attachments/Buttons/Reply/SendMessageButtonTest.php new file mode 100644 index 0000000..4b95c1d --- /dev/null +++ b/tests/Models/Attachments/Buttons/Reply/SendMessageButtonTest.php @@ -0,0 +1,45 @@ + 'message', + 'text' => 'Click Me', + 'payload' => null, + 'intent' => 'default', + ]; + + $this->assertEquals($expected, $button->toArray()); + } + + #[Test] + public function toArrayWithAllParameters(): void + { + $button = new SendMessageButton('Confirm', 'confirm-action-123', Intent::Positive); + + $expected = [ + 'type' => 'message', + 'text' => 'Confirm', + 'payload' => 'confirm-action-123', + 'intent' => 'positive', + ]; + + $this->assertEquals($expected, $button->toArray()); + } +} diff --git a/tests/Models/Attachments/Payloads/InlineKeyboardPayloadTest.php b/tests/Models/Attachments/Payloads/InlineKeyboardPayloadTest.php index 5a57113..c9fba59 100644 --- a/tests/Models/Attachments/Payloads/InlineKeyboardPayloadTest.php +++ b/tests/Models/Attachments/Payloads/InlineKeyboardPayloadTest.php @@ -4,10 +4,10 @@ declare(strict_types=1); namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Payloads; -use BushlanovDev\MaxMessengerBot\Enums\ButtonType; +use BushlanovDev\MaxMessengerBot\Enums\InlineButtonType; use BushlanovDev\MaxMessengerBot\Enums\Intent; -use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\CallbackButton; -use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\LinkButton; +use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\CallbackButton; +use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\LinkButton; use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\InlineKeyboardAttachmentRequestPayload; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; @@ -49,7 +49,7 @@ final class InlineKeyboardPayloadTest extends TestCase 'buttons' => [ [ [ - 'type' => ButtonType::Callback->value, + 'type' => InlineButtonType::Callback->value, 'text' => 'Accept', 'payload' => 'accept_payload', 'intent' => Intent::Positive->value, @@ -57,13 +57,13 @@ final class InlineKeyboardPayloadTest extends TestCase ], [ [ - 'type' => ButtonType::Callback->value, + 'type' => InlineButtonType::Callback->value, 'text' => 'Decline', 'payload' => 'decline_payload', 'intent' => Intent::Negative->value, ], [ - 'type' => ButtonType::Link->value, + 'type' => InlineButtonType::Link->value, 'text' => 'Help', 'url' => 'https://example.com/help', ], diff --git a/tests/Models/Attachments/Payloads/ReplyKeyboardAttachmentRequestPayloadTest.php b/tests/Models/Attachments/Payloads/ReplyKeyboardAttachmentRequestPayloadTest.php new file mode 100644 index 0000000..65c90a8 --- /dev/null +++ b/tests/Models/Attachments/Payloads/ReplyKeyboardAttachmentRequestPayloadTest.php @@ -0,0 +1,99 @@ + [ + [ + [ + 'type' => 'message', + 'text' => 'Help', + 'payload' => null, + 'intent' => 'default', + ], + ], + [ + [ + 'type' => 'user_contact', + 'text' => 'Share Contact', + ], + ], + ], + 'direct' => false, + 'direct_user_id' => null, + ]; + + $this->assertEquals($expected, $payload->toArray()); + } + + #[Test] + public function toArrayWithAllParameters(): void + { + $buttons = [ + [new SendMessageButton('Confirm', 'confirm-action', Intent::Positive)], + ]; + + $payload = new ReplyKeyboardAttachmentRequestPayload( + buttons: $buttons, + direct: true, + directUserId: 987654321, + ); + + $expected = [ + 'buttons' => [ + [ + [ + 'type' => 'message', + 'text' => 'Confirm', + 'payload' => 'confirm-action', + 'intent' => 'positive', + ], + ], + ], + 'direct' => true, + 'direct_user_id' => 987654321, + ]; + + $this->assertEquals($expected, $payload->toArray()); + } + + #[Test] + public function toArrayWithEmptyButtons(): void + { + $payload = new ReplyKeyboardAttachmentRequestPayload(buttons: []); + + $expected = [ + 'buttons' => [], + 'direct' => false, + 'direct_user_id' => null, + ]; + + $this->assertEquals($expected, $payload->toArray()); + } +} diff --git a/tests/Models/Attachments/Requests/InlineKeyboardAttachmentRequestTest.php b/tests/Models/Attachments/Requests/InlineKeyboardAttachmentRequestTest.php index 46aec27..857abae 100644 --- a/tests/Models/Attachments/Requests/InlineKeyboardAttachmentRequestTest.php +++ b/tests/Models/Attachments/Requests/InlineKeyboardAttachmentRequestTest.php @@ -5,11 +5,11 @@ declare(strict_types=1); namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Requests; use BushlanovDev\MaxMessengerBot\Enums\AttachmentType; -use BushlanovDev\MaxMessengerBot\Enums\ButtonType; +use BushlanovDev\MaxMessengerBot\Enums\InlineButtonType; use BushlanovDev\MaxMessengerBot\Enums\Intent; -use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\AbstractButton; -use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\CallbackButton; -use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\LinkButton; +use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\AbstractInlineButton; +use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\CallbackButton; +use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\LinkButton; use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\InlineKeyboardAttachmentRequestPayload; use BushlanovDev\MaxMessengerBot\Models\Attachments\Requests\InlineKeyboardAttachmentRequest; use PHPUnit\Framework\Attributes\CoversClass; @@ -19,7 +19,7 @@ use PHPUnit\Framework\TestCase; #[CoversClass(InlineKeyboardAttachmentRequest::class)] #[UsesClass(InlineKeyboardAttachmentRequestPayload::class)] -#[UsesClass(AbstractButton::class)] +#[UsesClass(AbstractInlineButton::class)] #[UsesClass(CallbackButton::class)] #[UsesClass(LinkButton::class)] final class InlineKeyboardAttachmentRequestTest extends TestCase @@ -44,7 +44,7 @@ final class InlineKeyboardAttachmentRequestTest extends TestCase 'buttons' => [ [ [ - 'type' => ButtonType::Callback->value, + 'type' => InlineButtonType::Callback->value, 'text' => 'Press Me', 'payload' => 'cb_payload_1', 'intent' => null, @@ -52,7 +52,7 @@ final class InlineKeyboardAttachmentRequestTest extends TestCase ], [ [ - 'type' => ButtonType::Link->value, + 'type' => InlineButtonType::Link->value, 'text' => 'Docs', 'url' => 'https://dev.max.ru', ], @@ -82,7 +82,7 @@ final class InlineKeyboardAttachmentRequestTest extends TestCase 'buttons' => [ [ [ - 'type' => ButtonType::Callback->value, + 'type' => InlineButtonType::Callback->value, 'text' => 'Positive', 'payload' => 'ok', 'intent' => Intent::Positive->value, @@ -90,13 +90,13 @@ final class InlineKeyboardAttachmentRequestTest extends TestCase ], [ [ - 'type' => ButtonType::Callback->value, + 'type' => InlineButtonType::Callback->value, 'text' => 'Negative', 'payload' => 'no', 'intent' => Intent::Negative->value, ], [ - 'type' => ButtonType::Link->value, + 'type' => InlineButtonType::Link->value, 'text' => 'Help', 'url' => 'https://example.com/help', ], diff --git a/tests/Models/Attachments/Requests/ReplyKeyboardAttachmentRequestTest.php b/tests/Models/Attachments/Requests/ReplyKeyboardAttachmentRequestTest.php new file mode 100644 index 0000000..9d3b788 --- /dev/null +++ b/tests/Models/Attachments/Requests/ReplyKeyboardAttachmentRequestTest.php @@ -0,0 +1,59 @@ + 'reply_keyboard', + 'payload' => [ + 'buttons' => [ + [ + [ + 'type' => 'message', + 'text' => 'Help', + 'payload' => 'help_payload', + 'intent' => 'positive', + ], + ], + [ + [ + 'type' => 'user_contact', + 'text' => 'Share Contact', + ], + ], + ], + 'direct' => true, + 'direct_user_id' => null, + ], + ]; + + $this->assertEquals($expectedArray, $request->toArray()); + } +}