mirror of
https://github.com/BushlanovDev/max-bot-api-client-php.git
synced 2026-08-19 07:32:53 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 728536f064 | |||
| c5d55a5c0f | |||
| 51b105b847 |
@@ -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,
|
||||
],
|
||||
);
|
||||
```
|
||||
|
||||
|
||||
+22
-2
@@ -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<string, mixed> $queryParams Query parameters for the request.
|
||||
* @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.
|
||||
* @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.
|
||||
*
|
||||
|
||||
@@ -13,6 +13,8 @@ enum AttachmentType: string
|
||||
case Sticker = 'sticker';
|
||||
case Contact = 'contact';
|
||||
case InlineKeyboard = 'inline_keyboard';
|
||||
case ReplyKeyboard = 'reply_keyboard';
|
||||
case Location = 'location';
|
||||
case Share = 'share';
|
||||
case Data = 'data';
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Enums;
|
||||
|
||||
enum MarkupType: string
|
||||
{
|
||||
case Strong = 'strong';
|
||||
case Emphasized = 'emphasized';
|
||||
case Monospaced = 'monospaced';
|
||||
case Link = 'link';
|
||||
case Strikethrough = 'strikethrough';
|
||||
case Underline = 'underline';
|
||||
case UserMention = 'user_mention';
|
||||
case Heading = 'heading';
|
||||
case Highlighted = 'highlighted';
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Enums;
|
||||
|
||||
enum ReplyButtonType: string
|
||||
{
|
||||
case Message = 'message';
|
||||
case UserGeoLocation = 'user_geo_location';
|
||||
case UserContact = 'user_contact';
|
||||
}
|
||||
@@ -4,12 +4,48 @@ declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
||||
use BushlanovDev\MaxMessengerBot\Enums\InlineButtonType;
|
||||
use BushlanovDev\MaxMessengerBot\Enums\MarkupType;
|
||||
use BushlanovDev\MaxMessengerBot\Enums\ReplyButtonType;
|
||||
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\AbstractAttachment;
|
||||
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\LinkButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\RequestContactButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\RequestGeoLocationButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\AbstractReplyButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendContactButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendGeoLocationButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendMessageButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\ContactAttachment;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\DataAttachment;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\FileAttachment;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\InlineKeyboardAttachment;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\LocationAttachment;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\PhotoAttachment;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\ReplyKeyboardAttachment;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\ShareAttachment;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\StickerAttachment;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\VideoAttachment;
|
||||
use BushlanovDev\MaxMessengerBot\Models\BotInfo;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Chat;
|
||||
use BushlanovDev\MaxMessengerBot\Models\ChatList;
|
||||
use BushlanovDev\MaxMessengerBot\Models\ChatMember;
|
||||
use BushlanovDev\MaxMessengerBot\Models\ChatMembersList;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Markup\AbstractMarkup;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Markup\EmphasizedMarkup;
|
||||
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\StrikethroughMarkup;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Markup\StrongMarkup;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Markup\UnderlineMarkup;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Markup\UserMentionMarkup;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Message;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Result;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Subscription;
|
||||
@@ -100,9 +136,107 @@ class ModelFactory
|
||||
*/
|
||||
public function createMessage(array $data): Message
|
||||
{
|
||||
if (isset($data['body']['attachments']) && is_array($data['body']['attachments'])) {
|
||||
$data['body']['attachments'] = array_map(
|
||||
[$this, 'createAttachment'],
|
||||
$data['body']['attachments'],
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($data['body']['markup']) && is_array($data['body']['markup'])) {
|
||||
$data['body']['markup'] = array_map(
|
||||
[$this, 'createMarkupElement'],
|
||||
$data['body']['markup'],
|
||||
);
|
||||
}
|
||||
|
||||
return Message::fromArray($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a specific Attachment model based on the 'type' field.
|
||||
*
|
||||
* @param array<string, mixed> $data
|
||||
*
|
||||
* @return AbstractAttachment
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function createAttachment(array $data): AbstractAttachment
|
||||
{
|
||||
$attachmentType = AttachmentType::tryFrom($data['type'] ?? '');
|
||||
if ($attachmentType === AttachmentType::ReplyKeyboard
|
||||
&& isset($data['buttons']) && is_array($data['buttons'])) {
|
||||
$data['buttons'] = array_map(
|
||||
fn($rowOfButtons) => array_map([$this, 'createReplyButton'], $rowOfButtons),
|
||||
$data['buttons'],
|
||||
);
|
||||
}
|
||||
|
||||
if ($attachmentType === AttachmentType::InlineKeyboard
|
||||
&& isset($data['payload']['buttons']) && is_array($data['payload']['buttons'])) {
|
||||
$data['payload']['buttons'] = array_map(
|
||||
fn($rowOfButtons) => array_map([$this, 'createInlineButton'], $rowOfButtons),
|
||||
$data['payload']['buttons']
|
||||
);
|
||||
}
|
||||
|
||||
return match ($attachmentType) {
|
||||
AttachmentType::Data => DataAttachment::fromArray($data),
|
||||
AttachmentType::Share => ShareAttachment::fromArray($data),
|
||||
AttachmentType::Image => PhotoAttachment::fromArray($data),
|
||||
AttachmentType::Video => VideoAttachment::fromArray($data),
|
||||
AttachmentType::Audio => AudioAttachment::fromArray($data),
|
||||
AttachmentType::File => FileAttachment::fromArray($data),
|
||||
AttachmentType::Sticker => StickerAttachment::fromArray($data),
|
||||
AttachmentType::Contact => ContactAttachment::fromArray($data),
|
||||
AttachmentType::InlineKeyboard => InlineKeyboardAttachment::fromArray($data),
|
||||
AttachmentType::ReplyKeyboard => ReplyKeyboardAttachment::fromArray($data),
|
||||
AttachmentType::Location => LocationAttachment::fromArray($data),
|
||||
default => throw new LogicException("Unknown or unsupported attachment type: " . ($data['type'] ?? 'none')),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a specific ReplyButton model based on the 'type' field.
|
||||
*
|
||||
* @param array<string, mixed> $data
|
||||
*
|
||||
* @return AbstractReplyButton
|
||||
* @throws ReflectionException
|
||||
* @throws LogicException
|
||||
*/
|
||||
public function createReplyButton(array $data): AbstractReplyButton
|
||||
{
|
||||
return match (ReplyButtonType::tryFrom($data['type'] ?? '')) {
|
||||
ReplyButtonType::Message => SendMessageButton::fromArray($data),
|
||||
ReplyButtonType::UserContact => SendContactButton::fromArray($data),
|
||||
ReplyButtonType::UserGeoLocation => SendGeoLocationButton::fromArray($data),
|
||||
default => throw new LogicException(
|
||||
'Unknown or unsupported reply button type: ' . ($data['type'] ?? 'none')
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a specific InlineButton model based on the 'type' field.
|
||||
*
|
||||
* @param array<string, mixed> $data
|
||||
* @return AbstractInlineButton
|
||||
* @throws ReflectionException
|
||||
* @throws LogicException
|
||||
*/
|
||||
public function createInlineButton(array $data): AbstractInlineButton
|
||||
{
|
||||
return match (InlineButtonType::tryFrom($data['type'] ?? '')) {
|
||||
InlineButtonType::Callback => CallbackButton::fromArray($data),
|
||||
InlineButtonType::Link => LinkButton::fromArray($data),
|
||||
InlineButtonType::RequestContact => RequestContactButton::fromArray($data),
|
||||
InlineButtonType::RequestGeoLocation => RequestGeoLocationButton::fromArray($data),
|
||||
InlineButtonType::Chat => ChatButton::fromArray($data),
|
||||
default => throw new LogicException("Unknown or unsupported inline button type: " . ($data['type'] ?? 'none')),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* List of messages.
|
||||
*
|
||||
@@ -248,4 +382,30 @@ class ModelFactory
|
||||
{
|
||||
return VideoAttachmentDetails::fromArray($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a specific Markup model based on the 'type' field.
|
||||
*
|
||||
* @param array<string, mixed> $data
|
||||
*
|
||||
* @return AbstractMarkup
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function createMarkupElement(array $data): AbstractMarkup
|
||||
{
|
||||
return match (MarkupType::tryFrom($data['type'] ?? '')) {
|
||||
MarkupType::Strong => StrongMarkup::fromArray($data),
|
||||
MarkupType::Emphasized => EmphasizedMarkup::fromArray($data),
|
||||
MarkupType::Monospaced => MonospacedMarkup::fromArray($data),
|
||||
MarkupType::Strikethrough => StrikethroughMarkup::fromArray($data),
|
||||
MarkupType::Underline => UnderlineMarkup::fromArray($data),
|
||||
MarkupType::Heading => HeadingMarkup::fromArray($data),
|
||||
MarkupType::Highlighted => HighlightedMarkup::fromArray($data),
|
||||
MarkupType::Link => LinkMarkup::fromArray($data),
|
||||
MarkupType::UserMention => UserMentionMarkup::fromArray($data),
|
||||
default => throw new LogicException(
|
||||
'Unknown or unsupported markup type: ' . ($data['type'] ?? 'none')
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,6 +118,10 @@ abstract readonly class AbstractModel
|
||||
|
||||
$typeName = $type->getName();
|
||||
|
||||
if (is_object($value) && is_a($value, $typeName)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if ($type->isBuiltin()) {
|
||||
return match ($typeName) {
|
||||
'int' => (int)$value,
|
||||
@@ -133,7 +137,7 @@ abstract readonly class AbstractModel
|
||||
return $typeName::from($value);
|
||||
}
|
||||
|
||||
if (is_subclass_of($typeName, self::class)) {
|
||||
if (is_subclass_of($typeName, self::class) && is_array($value)) {
|
||||
return $typeName::fromArray($value);
|
||||
}
|
||||
|
||||
@@ -168,7 +172,10 @@ abstract readonly class AbstractModel
|
||||
}
|
||||
|
||||
if (is_subclass_of($itemClassName, self::class)) {
|
||||
return array_map(fn($item) => $itemClassName::fromArray($item), $value);
|
||||
return array_map(
|
||||
fn($item) => is_a($item, $itemClassName) ? $item : $itemClassName::fromArray($item),
|
||||
$value,
|
||||
);
|
||||
}
|
||||
|
||||
return $value;
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\AbstractModel;
|
||||
|
||||
/**
|
||||
* Represents a generic attachment received from the API.
|
||||
*/
|
||||
abstract readonly class AbstractAttachment extends AbstractModel
|
||||
{
|
||||
public function __construct(public AttachmentType $type)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\MediaAttachmentPayload;
|
||||
|
||||
final readonly class AudioAttachment extends AbstractAttachment
|
||||
{
|
||||
/**
|
||||
* @param MediaAttachmentPayload $payload Audio attachment payload.
|
||||
* @param string|null $transcription Audio transcription.
|
||||
*/
|
||||
public function __construct(
|
||||
public MediaAttachmentPayload $payload,
|
||||
public ?string $transcription,
|
||||
) {
|
||||
parent::__construct(AttachmentType::Audio);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\ButtonType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\AbstractModel;
|
||||
|
||||
abstract readonly class AbstractButton extends AbstractModel
|
||||
{
|
||||
public function __construct(
|
||||
public ButtonType $type,
|
||||
public string $text,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\InlineButtonType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\AbstractModel;
|
||||
|
||||
abstract readonly class AbstractInlineButton extends AbstractModel
|
||||
{
|
||||
/**
|
||||
* @param InlineButtonType $type The type of the inline button.
|
||||
* @param string $text Visible text of the button.
|
||||
*/
|
||||
public function __construct(
|
||||
public InlineButtonType $type,
|
||||
public string $text,
|
||||
) {
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -2,15 +2,15 @@
|
||||
|
||||
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;
|
||||
use BushlanovDev\MaxMessengerBot\Enums\Intent;
|
||||
|
||||
/**
|
||||
* Sends a notification with payload to a bot (via WebHook or long polling).
|
||||
*/
|
||||
final readonly class CallbackButton extends AbstractButton
|
||||
final readonly class CallbackButton extends AbstractInlineButton
|
||||
{
|
||||
public string $payload;
|
||||
public ?Intent $intent;
|
||||
@@ -22,7 +22,7 @@ final readonly class CallbackButton extends AbstractButton
|
||||
*/
|
||||
public function __construct(string $text, string $payload, ?Intent $intent = null)
|
||||
{
|
||||
parent::__construct(ButtonType::Callback, $text);
|
||||
parent::__construct(InlineButtonType::Callback, $text);
|
||||
|
||||
$this->payload = $payload;
|
||||
$this->intent = $intent;
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\InlineButtonType;
|
||||
|
||||
/**
|
||||
* Button that creates a new chat associated with the message.
|
||||
* The bot will be added as an administrator by default.
|
||||
*/
|
||||
final readonly class ChatButton extends AbstractInlineButton
|
||||
{
|
||||
/**
|
||||
* @param string $text Visible text of the button (1 to 128 characters).
|
||||
* @param string $chatTitle Title of the chat to be created (max 200 characters).
|
||||
* @param string|null $chatDescription Optional chat description (max 400 characters).
|
||||
* @param string|null $startPayload Optional payload that will be sent to the bot in a `message_chat_created` update.
|
||||
* @param int|null $uuid Optional unique identifier for the button. If not passed, it will be generated.
|
||||
*/
|
||||
public function __construct(
|
||||
string $text,
|
||||
public string $chatTitle,
|
||||
public ?string $chatDescription = null,
|
||||
public ?string $startPayload = null,
|
||||
public ?int $uuid = null,
|
||||
) {
|
||||
parent::__construct(InlineButtonType::Chat, $text);
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -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;
|
||||
|
||||
/**
|
||||
* Makes a user to follow a link.
|
||||
*/
|
||||
final readonly class LinkButton extends AbstractButton
|
||||
final readonly class LinkButton extends AbstractInlineButton
|
||||
{
|
||||
public string $url;
|
||||
|
||||
@@ -19,7 +19,7 @@ final readonly class LinkButton extends AbstractButton
|
||||
*/
|
||||
public function __construct(string $text, string $url)
|
||||
{
|
||||
parent::__construct(ButtonType::Link, $text);
|
||||
parent::__construct(InlineButtonType::Link, $text);
|
||||
|
||||
$this->url = $url;
|
||||
}
|
||||
+4
-4
@@ -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;
|
||||
+4
-4
@@ -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);
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\ReplyButtonType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\AbstractModel;
|
||||
|
||||
abstract readonly class AbstractReplyButton extends AbstractModel
|
||||
{
|
||||
/**
|
||||
* @param ReplyButtonType $type The type of the reply button.
|
||||
* @param string $text Visible text of the button.
|
||||
*/
|
||||
public function __construct(
|
||||
public ReplyButtonType $type,
|
||||
public string $text,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\ReplyButtonType;
|
||||
|
||||
final readonly class SendContactButton extends AbstractReplyButton
|
||||
{
|
||||
/**
|
||||
* @param string $text Visible text of the button.
|
||||
*/
|
||||
public function __construct(string $text)
|
||||
{
|
||||
parent::__construct(ReplyButtonType::UserContact, $text);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\ReplyButtonType;
|
||||
|
||||
final readonly class SendGeoLocationButton extends AbstractReplyButton
|
||||
{
|
||||
/**
|
||||
* @param string $text Visible text of the button.
|
||||
* @param bool $quick If `true`, sends location without asking user's confirmation.
|
||||
*/
|
||||
public function __construct(
|
||||
string $text,
|
||||
public bool $quick = false,
|
||||
) {
|
||||
parent::__construct(ReplyButtonType::UserGeoLocation, $text);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\Intent;
|
||||
use BushlanovDev\MaxMessengerBot\Enums\ReplyButtonType;
|
||||
|
||||
final readonly class SendMessageButton extends AbstractReplyButton
|
||||
{
|
||||
/**
|
||||
* @param string $text Visible text of the button.
|
||||
* @param string|null $payload Button payload.
|
||||
* @param Intent $intent Intent of button.
|
||||
*/
|
||||
public function __construct(
|
||||
string $text,
|
||||
public ?string $payload = null,
|
||||
public Intent $intent = Intent::Default,
|
||||
) {
|
||||
parent::__construct(ReplyButtonType::Message, $text);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\ContactAttachmentPayload;
|
||||
|
||||
final readonly class ContactAttachment extends AbstractAttachment
|
||||
{
|
||||
/**
|
||||
* @param ContactAttachmentPayload $payload Contact attachment payload.
|
||||
*/
|
||||
public function __construct(public ContactAttachmentPayload $payload)
|
||||
{
|
||||
parent::__construct(AttachmentType::Contact);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
||||
|
||||
/**
|
||||
* Represents an attachment containing a payload from a SendMessageButton.
|
||||
*/
|
||||
final readonly class DataAttachment extends AbstractAttachment
|
||||
{
|
||||
/**
|
||||
* @param string $data The payload from the button.
|
||||
*/
|
||||
public function __construct(public string $data)
|
||||
{
|
||||
parent::__construct(AttachmentType::Data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\FileAttachmentPayload;
|
||||
|
||||
final readonly class FileAttachment extends AbstractAttachment
|
||||
{
|
||||
/**
|
||||
* @param FileAttachmentPayload $payload File attachment payload.
|
||||
* @param string $filename Uploaded file name.
|
||||
* @param int $size File size in bytes.
|
||||
*/
|
||||
public function __construct(
|
||||
public FileAttachmentPayload $payload,
|
||||
public string $filename,
|
||||
public int $size,
|
||||
) {
|
||||
parent::__construct(AttachmentType::File);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\KeyboardPayload;
|
||||
|
||||
final readonly class InlineKeyboardAttachment extends AbstractAttachment
|
||||
{
|
||||
/**
|
||||
* @param KeyboardPayload $payload Keyboard payload.
|
||||
*/
|
||||
public function __construct(public KeyboardPayload $payload) {
|
||||
parent::__construct(AttachmentType::InlineKeyboard);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
||||
|
||||
final readonly class LocationAttachment extends AbstractAttachment
|
||||
{
|
||||
/**
|
||||
* @param float $latitude
|
||||
* @param float $longitude
|
||||
*/
|
||||
public function __construct(
|
||||
public float $latitude,
|
||||
public float $longitude,
|
||||
) {
|
||||
parent::__construct(AttachmentType::Location);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Models\AbstractModel;
|
||||
use BushlanovDev\MaxMessengerBot\Models\User;
|
||||
|
||||
/**
|
||||
* Payload of a contact attachment.
|
||||
*/
|
||||
final readonly class ContactAttachmentPayload extends AbstractModel
|
||||
{
|
||||
/**
|
||||
* @param string|null $vcfInfo User info in VCF format.
|
||||
* @param User|null $maxInfo User info if the contact is a Max user.
|
||||
*/
|
||||
public function __construct(
|
||||
public ?string $vcfInfo,
|
||||
public ?User $maxInfo,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Models\AbstractModel;
|
||||
|
||||
/**
|
||||
* Payload for a file attachment.
|
||||
*/
|
||||
final readonly class FileAttachmentPayload extends AbstractModel
|
||||
{
|
||||
/**
|
||||
* @param string $url Media attachment URL.
|
||||
* @param string $token Token to reuse the same attachment in other messages.
|
||||
*/
|
||||
public function __construct(
|
||||
public string $url,
|
||||
public string $token,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,12 @@ declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\AbstractButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\AbstractInlineButton;
|
||||
|
||||
final readonly class InlineKeyboardAttachmentRequestPayload extends AbstractAttachmentRequestPayload
|
||||
{
|
||||
/**
|
||||
* @param AbstractButton[][] $buttons
|
||||
* @param AbstractInlineButton[][] $buttons
|
||||
*/
|
||||
public function __construct(
|
||||
public array $buttons,
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Models\AbstractModel;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\AbstractInlineButton;
|
||||
|
||||
/**
|
||||
* Represents an inline keyboard structure.
|
||||
*/
|
||||
final readonly class KeyboardPayload extends AbstractModel
|
||||
{
|
||||
/**
|
||||
* @param AbstractInlineButton[][] $buttons Two-dimensional array of buttons.
|
||||
*/
|
||||
public function __construct(public array $buttons)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Models\AbstractModel;
|
||||
|
||||
/**
|
||||
* Payload for media attachments like audio or video.
|
||||
*/
|
||||
final readonly class MediaAttachmentPayload extends AbstractModel
|
||||
{
|
||||
/**
|
||||
* @param string $url Media attachment URL.
|
||||
* @param string $token Token to reuse the same attachment in other messages.
|
||||
*/
|
||||
public function __construct(
|
||||
public string $url,
|
||||
public string $token,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Models\AbstractModel;
|
||||
|
||||
/**
|
||||
* Payload for a photo attachment.
|
||||
*/
|
||||
final readonly class PhotoAttachmentPayload extends AbstractModel
|
||||
{
|
||||
/**
|
||||
* @param string $url Media attachment URL.
|
||||
* @param string $token Token to reuse the same attachment in other messages.
|
||||
* @param int $photoId Unique identifier of this image.
|
||||
*/
|
||||
public function __construct(
|
||||
public string $url,
|
||||
public string $token,
|
||||
public int $photoId,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Attributes\ArrayOf;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\AbstractReplyButton;
|
||||
|
||||
final readonly class ReplyKeyboardAttachmentRequestPayload extends AbstractAttachmentRequestPayload
|
||||
{
|
||||
/**
|
||||
* @param AbstractReplyButton[][] $buttons Two-dimensional array of buttons.
|
||||
* @param bool $direct Applicable only for chats.
|
||||
* @param int|null $directUserId If set, reply keyboard will only be shown to this participant.
|
||||
*/
|
||||
public function __construct(
|
||||
#[ArrayOf(AbstractReplyButton::class)]
|
||||
public array $buttons,
|
||||
public bool $direct = false,
|
||||
public ?int $directUserId = null,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Models\AbstractModel;
|
||||
|
||||
/**
|
||||
* Payload for a sticker attachment.
|
||||
*/
|
||||
final readonly class StickerAttachmentPayload extends AbstractModel
|
||||
{
|
||||
/**
|
||||
* @param string $url Media attachment URL.
|
||||
* @param string $code Sticker identifier.
|
||||
*/
|
||||
public function __construct(
|
||||
public string $url,
|
||||
public string $code,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Models\AbstractModel;
|
||||
|
||||
/**
|
||||
* Represents a video thumbnail image.
|
||||
*/
|
||||
final readonly class VideoThumbnail extends AbstractModel
|
||||
{
|
||||
/**
|
||||
* @param string $url Media attachment URL.
|
||||
*/
|
||||
public function __construct(public string $url)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\PhotoAttachmentPayload;
|
||||
|
||||
final readonly class PhotoAttachment extends AbstractAttachment
|
||||
{
|
||||
/**
|
||||
* @param PhotoAttachmentPayload $payload Photo attachment payload.
|
||||
*/
|
||||
public function __construct(public PhotoAttachmentPayload $payload)
|
||||
{
|
||||
parent::__construct(AttachmentType::Image);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\AbstractReplyButton;
|
||||
|
||||
final readonly class ReplyKeyboardAttachment extends AbstractAttachment
|
||||
{
|
||||
/**
|
||||
* @param AbstractReplyButton[][] $buttons
|
||||
*/
|
||||
public function __construct(public array $buttons) {
|
||||
parent::__construct(AttachmentType::ReplyKeyboard);
|
||||
}
|
||||
}
|
||||
@@ -5,13 +5,13 @@ declare(strict_types=1);
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Requests;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\AbstractButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\AbstractInlineButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\InlineKeyboardAttachmentRequestPayload;
|
||||
|
||||
final readonly class InlineKeyboardAttachmentRequest extends AbstractAttachmentRequest
|
||||
{
|
||||
/**
|
||||
* @param AbstractButton[][] $buttons
|
||||
* @param AbstractInlineButton[][] $buttons
|
||||
*/
|
||||
public function __construct(array $buttons)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Requests;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\AbstractReplyButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\ReplyKeyboardAttachmentRequestPayload;
|
||||
|
||||
final readonly class ReplyKeyboardAttachmentRequest extends AbstractAttachmentRequest
|
||||
{
|
||||
/**
|
||||
* @param AbstractReplyButton[][] $buttons
|
||||
* @param bool $direct
|
||||
* @param int|null $directUserId
|
||||
*/
|
||||
public function __construct(
|
||||
array $buttons,
|
||||
bool $direct = false,
|
||||
?int $directUserId = null
|
||||
) {
|
||||
parent::__construct(
|
||||
AttachmentType::ReplyKeyboard,
|
||||
new ReplyKeyboardAttachmentRequestPayload($buttons, $direct, $directUserId),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\ShareAttachmentRequestPayload;
|
||||
|
||||
/**
|
||||
* Represents a share (URL preview) attachment.
|
||||
*/
|
||||
final readonly class ShareAttachment extends AbstractAttachment
|
||||
{
|
||||
public function __construct(
|
||||
public ShareAttachmentRequestPayload $payload,
|
||||
public ?string $title,
|
||||
public ?string $description,
|
||||
public ?string $imageUrl,
|
||||
) {
|
||||
parent::__construct(AttachmentType::Share);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\StickerAttachmentPayload;
|
||||
|
||||
final readonly class StickerAttachment extends AbstractAttachment
|
||||
{
|
||||
/**
|
||||
* @param StickerAttachmentPayload $payload Sticker attachment payload.
|
||||
* @param int $width
|
||||
* @param int $height
|
||||
*/
|
||||
public function __construct(
|
||||
public StickerAttachmentPayload $payload,
|
||||
public int $width,
|
||||
public int $height,
|
||||
) {
|
||||
parent::__construct(AttachmentType::Sticker);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\MediaAttachmentPayload;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\VideoThumbnail;
|
||||
|
||||
final readonly class VideoAttachment extends AbstractAttachment
|
||||
{
|
||||
/**
|
||||
* @param MediaAttachmentPayload $payload Video attachment payload.
|
||||
* @param VideoThumbnail|null $thumbnail Video thumbnail.
|
||||
* @param int|null $width Video width.
|
||||
* @param int|null $height Video height.
|
||||
* @param int|null $duration Video duration in seconds.
|
||||
*/
|
||||
public function __construct(
|
||||
public MediaAttachmentPayload $payload,
|
||||
public ?VideoThumbnail $thumbnail,
|
||||
public ?int $width,
|
||||
public ?int $height,
|
||||
public ?int $duration,
|
||||
) {
|
||||
parent::__construct(AttachmentType::Video);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -24,7 +24,7 @@ final readonly class Chat extends AbstractModel
|
||||
* @param int|null $ownerId Identifier of chat owner. Visible only for chat admins
|
||||
* @param string|null $link Link on chat.
|
||||
* @param string|null $description Chat description.
|
||||
* @param User|null $dialogWithUser Another user in conversation. For `dialog` type chats only.
|
||||
* @param UserWithPhoto|null $dialogWithUser Another user in conversation. For `dialog` type chats only.
|
||||
* @param int|null $messagesCount Messages count in chat. Only for group chats and channels. Not available for dialogs.
|
||||
* @param string|null $chatMessageId Identifier of message that contains `chat` button initialized chat.
|
||||
* @param Message|null $pinnedMessage Pinned message in chat or channel. Returned only when single chat is requested.
|
||||
@@ -41,7 +41,7 @@ final readonly class Chat extends AbstractModel
|
||||
public ?int $ownerId,
|
||||
public ?string $link,
|
||||
public ?string $description,
|
||||
public ?User $dialogWithUser,
|
||||
public ?UserWithPhoto $dialogWithUser,
|
||||
public ?int $messagesCount,
|
||||
public ?string $chatMessageId,
|
||||
public ?Message $pinnedMessage,
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\MessageLinkType;
|
||||
|
||||
/**
|
||||
* Represents a forwarded or replied message linked to the main message.
|
||||
*/
|
||||
final readonly class LinkedMessage extends AbstractModel
|
||||
{
|
||||
/**
|
||||
* @param MessageLinkType $type Type of linked message (forward or reply).
|
||||
* @param MessageBody $message The body of the original message.
|
||||
* @param User|null $sender The sender of the original message. Can be null if posted on behalf of a channel.
|
||||
* @param int|null $chatId The chat where the message was originally posted (for forwarded messages).
|
||||
*/
|
||||
public function __construct(
|
||||
public MessageLinkType $type,
|
||||
public MessageBody $message,
|
||||
public ?User $sender,
|
||||
public ?int $chatId,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Markup;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\MarkupType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\AbstractModel;
|
||||
|
||||
/**
|
||||
* Base class for a text markup element.
|
||||
*/
|
||||
abstract readonly class AbstractMarkup extends AbstractModel
|
||||
{
|
||||
/**
|
||||
* @param MarkupType $type The type of the markup element.
|
||||
* @param int $from Element start index (zero-based) in text.
|
||||
* @param int $length Length of the markup element.
|
||||
*/
|
||||
public function __construct(
|
||||
public MarkupType $type,
|
||||
public int $from,
|
||||
public int $length,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Markup;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\MarkupType;
|
||||
|
||||
/**
|
||||
* Represents an *emphasized* (italic) part of the text.
|
||||
*/
|
||||
final readonly class EmphasizedMarkup 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::Emphasized, $from, $length);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Markup;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\MarkupType;
|
||||
|
||||
/**
|
||||
* Represents a # header part of the text.
|
||||
*/
|
||||
final readonly class HeadingMarkup 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::Heading, $from, $length);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Markup;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\MarkupType;
|
||||
|
||||
/**
|
||||
* Represents a ^^highlighted^^ part of the text.
|
||||
*/
|
||||
final readonly class HighlightedMarkup 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::Highlighted, $from, $length);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Markup;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\MarkupType;
|
||||
|
||||
/**
|
||||
* Represents a link in the text.
|
||||
*/
|
||||
final readonly class LinkMarkup extends AbstractMarkup
|
||||
{
|
||||
/**
|
||||
* @param int $from Element start index (zero-based) in text.
|
||||
* @param int $length Length of the markup element.
|
||||
* @param string $url Link's URL.
|
||||
*/
|
||||
public function __construct(
|
||||
int $from,
|
||||
int $length,
|
||||
public string $url,
|
||||
) {
|
||||
parent::__construct(MarkupType::Link, $from, $length);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Markup;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\MarkupType;
|
||||
|
||||
/**
|
||||
* Represents a `monospaced` part of the text.
|
||||
*/
|
||||
final readonly class MonospacedMarkup 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::Monospaced, $from, $length);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Markup;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\MarkupType;
|
||||
|
||||
/**
|
||||
* Represents a ~strikethrough~ part of the text.
|
||||
*/
|
||||
final readonly class StrikethroughMarkup 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::Strikethrough, $from, $length);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Markup;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\MarkupType;
|
||||
|
||||
/**
|
||||
* Represents a **strong** (bold) part of the text.
|
||||
*/
|
||||
final readonly class StrongMarkup 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::Strong, $from, $length);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Markup;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\MarkupType;
|
||||
|
||||
/**
|
||||
* Represents an ++underlined++ part of the text.
|
||||
*/
|
||||
final readonly class UnderlineMarkup 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::Underline, $from, $length);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Markup;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\MarkupType;
|
||||
|
||||
/**
|
||||
* Represents a user mention in the text.
|
||||
*/
|
||||
final readonly class UserMentionMarkup extends AbstractMarkup
|
||||
{
|
||||
/**
|
||||
* @param int $from Element start index (zero-based) in text.
|
||||
* @param int $length Length of the markup element.
|
||||
* @param string|null $userLink "@username" of the mentioned user.
|
||||
* @param int|null $userId Identifier of the mentioned user without a username.
|
||||
*/
|
||||
public function __construct(
|
||||
int $from,
|
||||
int $length,
|
||||
public ?string $userLink,
|
||||
public ?int $userId,
|
||||
) {
|
||||
parent::__construct(MarkupType::UserMention, $from, $length);
|
||||
}
|
||||
}
|
||||
@@ -13,15 +13,19 @@ final readonly class Message extends AbstractModel
|
||||
* @param int $timestamp Unix-time when message was created.
|
||||
* @param MessageBody $body Body of created message. Text + attachments.
|
||||
* @param Recipient $recipient Message recipient. Could be user or chat.
|
||||
* @param Sender|null $sender User who sent this message. Can be null if message has been posted on behalf of a channel.
|
||||
* @param User|null $sender User who sent this message. Can be null if message has been posted on behalf of a channel.
|
||||
* @param string|null $url Message public URL. Can be null for dialogs or non-public chats/channels.
|
||||
* @param LinkedMessage|null $link Forwarded or replied message.
|
||||
* @param MessageStat|null $stat Message statistics. Available only for channels.
|
||||
*/
|
||||
public function __construct(
|
||||
public int $timestamp,
|
||||
public MessageBody $body,
|
||||
public Recipient $recipient,
|
||||
public ?Sender $sender,
|
||||
public ?User $sender,
|
||||
public ?string $url,
|
||||
public ?LinkedMessage $link,
|
||||
public ?MessageStat $stat,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Attributes\ArrayOf;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\AbstractAttachment;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Markup\AbstractMarkup;
|
||||
|
||||
/**
|
||||
* Body of created message. Text + attachments.
|
||||
*/
|
||||
@@ -13,11 +17,17 @@ final readonly class MessageBody extends AbstractModel
|
||||
* @param string $mid Unique identifier of message.
|
||||
* @param int $seq Sequence identifier of message in chat.
|
||||
* @param string|null $text Message text.
|
||||
* @param AbstractAttachment[]|null $attachments Message attachments.
|
||||
* @param AbstractMarkup[]|null $markup Message text markup.
|
||||
*/
|
||||
public function __construct(
|
||||
public string $mid,
|
||||
public int $seq,
|
||||
public ?string $text,
|
||||
#[ArrayOf(AbstractAttachment::class)]
|
||||
public ?array $attachments,
|
||||
#[ArrayOf(AbstractMarkup::class)]
|
||||
public ?array $markup,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models;
|
||||
|
||||
/**
|
||||
* Message statistics.
|
||||
*/
|
||||
final readonly class MessageStat extends AbstractModel
|
||||
{
|
||||
/**
|
||||
* @param int $views Number of views.
|
||||
*/
|
||||
public function __construct(public int $views)
|
||||
{
|
||||
}
|
||||
}
|
||||
+2
-7
@@ -11,11 +11,9 @@ final readonly class User extends AbstractModel
|
||||
* @param string $firstName Users first name.
|
||||
* @param string|null $lastName Users last name.
|
||||
* @param string|null $username Unique public user name. Can be `null` if user is not accessible or it is not set.
|
||||
* @param bool $isBot `true` if user is bot.
|
||||
* @param bool $isBot Is the user a bot.
|
||||
* @param int $lastActivityTime Time of last user activity in Max (Unix timestamp in milliseconds).
|
||||
* @param string|null $description User description. Can be `null` if user did not fill it out.
|
||||
* @param string|null $avatarUrl URL of avatar.
|
||||
* @param string|null $fullAvatarUrl URL of avatar of a bigger size.
|
||||
* Can be outdated if user disabled its "online" status in settings.
|
||||
*/
|
||||
public function __construct(
|
||||
public int $userId,
|
||||
@@ -24,9 +22,6 @@ final readonly class User extends AbstractModel
|
||||
public ?string $username,
|
||||
public bool $isBot,
|
||||
public int $lastActivityTime,
|
||||
public ?string $description,
|
||||
public ?string $avatarUrl,
|
||||
public ?string $fullAvatarUrl,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,18 +4,18 @@ declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models;
|
||||
|
||||
/**
|
||||
* User who sent this message.
|
||||
*/
|
||||
final readonly class Sender extends AbstractModel
|
||||
final readonly class UserWithPhoto extends AbstractModel
|
||||
{
|
||||
/**
|
||||
* @param int $userId Users identifier.
|
||||
* @param string $firstName Users first name.
|
||||
* @param string|null $lastName Users last name.
|
||||
* @param string|null $username Unique public user name. Can be null if user is not accessible or it is not set.
|
||||
* @param bool $isBot Is the user a bot.
|
||||
* @param int $lastActivityTime Time of last user activity in Max (Unix timestamp in milliseconds). Can be outdated if user disabled its "online" status in settings.
|
||||
* @param string|null $username Unique public user name. Can be `null` if user is not accessible or it is not set.
|
||||
* @param bool $isBot `true` if user is bot.
|
||||
* @param int $lastActivityTime Time of last user activity in Max (Unix timestamp in milliseconds).
|
||||
* @param string|null $description UserWithPhoto description. Can be `null` if user did not fill it out.
|
||||
* @param string|null $avatarUrl URL of avatar.
|
||||
* @param string|null $fullAvatarUrl URL of avatar of a bigger size.
|
||||
*/
|
||||
public function __construct(
|
||||
public int $userId,
|
||||
@@ -24,6 +24,9 @@ final readonly class Sender extends AbstractModel
|
||||
public ?string $username,
|
||||
public bool $isBot,
|
||||
public int $lastActivityTime,
|
||||
public ?string $description,
|
||||
public ?string $avatarUrl,
|
||||
public ?string $fullAvatarUrl,
|
||||
) {
|
||||
}
|
||||
}
|
||||
+5
-7
@@ -9,15 +9,15 @@ use BushlanovDev\MaxMessengerBot\Attributes\ArrayOf;
|
||||
use BushlanovDev\MaxMessengerBot\Client;
|
||||
use BushlanovDev\MaxMessengerBot\ClientApiInterface;
|
||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
||||
use BushlanovDev\MaxMessengerBot\Enums\ButtonType;
|
||||
use BushlanovDev\MaxMessengerBot\Enums\ChatAdminPermission;
|
||||
use BushlanovDev\MaxMessengerBot\Enums\InlineButtonType;
|
||||
use BushlanovDev\MaxMessengerBot\Enums\MessageFormat;
|
||||
use BushlanovDev\MaxMessengerBot\Enums\SenderAction;
|
||||
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
|
||||
use BushlanovDev\MaxMessengerBot\Enums\UploadType;
|
||||
use BushlanovDev\MaxMessengerBot\Exceptions\SerializationException;
|
||||
use BushlanovDev\MaxMessengerBot\ModelFactory;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\CallbackButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\CallbackButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\ContactAttachmentRequestPayload;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\InlineKeyboardAttachmentRequestPayload;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\LocationAttachmentRequestPayload;
|
||||
@@ -47,14 +47,13 @@ use BushlanovDev\MaxMessengerBot\Models\Message;
|
||||
use BushlanovDev\MaxMessengerBot\Models\MessageBody;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Recipient;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Result;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Sender;
|
||||
use BushlanovDev\MaxMessengerBot\Models\User;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Subscription;
|
||||
use BushlanovDev\MaxMessengerBot\Models\UpdateList;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Updates\AbstractUpdate;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Updates\BotStartedUpdate;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Updates\MessageCreatedUpdate;
|
||||
use BushlanovDev\MaxMessengerBot\Models\UploadEndpoint;
|
||||
use BushlanovDev\MaxMessengerBot\Models\User;
|
||||
use BushlanovDev\MaxMessengerBot\Models\VideoAttachmentDetails;
|
||||
use BushlanovDev\MaxMessengerBot\Models\VideoUrls;
|
||||
use BushlanovDev\MaxMessengerBot\WebhookHandler;
|
||||
@@ -82,7 +81,7 @@ use RuntimeException;
|
||||
#[UsesClass(Message::class)]
|
||||
#[UsesClass(MessageBody::class)]
|
||||
#[UsesClass(Recipient::class)]
|
||||
#[UsesClass(Sender::class)]
|
||||
#[UsesClass(User::class)]
|
||||
#[UsesClass(CallbackButton::class)]
|
||||
#[UsesClass(InlineKeyboardAttachmentRequestPayload::class)]
|
||||
#[UsesClass(InlineKeyboardAttachmentRequest::class)]
|
||||
@@ -93,7 +92,6 @@ use RuntimeException;
|
||||
#[UsesClass(Chat::class)]
|
||||
#[UsesClass(UpdateList::class)]
|
||||
#[UsesClass(WebhookHandler::class)]
|
||||
#[UsesClass(User::class)]
|
||||
#[UsesClass(AbstractUpdate::class)]
|
||||
#[UsesClass(BotStartedUpdate::class)]
|
||||
#[UsesClass(MessageCreatedUpdate::class)]
|
||||
@@ -391,7 +389,7 @@ final class ApiTest extends TestCase
|
||||
'buttons' => [
|
||||
[
|
||||
[
|
||||
'type' => ButtonType::Callback->value,
|
||||
'type' => InlineButtonType::Callback->value,
|
||||
'text' => 'Press Me',
|
||||
'payload' => 'payload_123',
|
||||
'intent' => null,
|
||||
|
||||
+288
-6
@@ -8,7 +8,26 @@ use BushlanovDev\MaxMessengerBot\Attributes\ArrayOf;
|
||||
use BushlanovDev\MaxMessengerBot\Enums\ChatAdminPermission;
|
||||
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
|
||||
use BushlanovDev\MaxMessengerBot\ModelFactory;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\AbstractAttachment;
|
||||
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\LinkButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\RequestContactButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\RequestGeoLocationButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\AbstractReplyButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendContactButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendMessageButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\DataAttachment;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\InlineKeyboardAttachment;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\LocationAttachment;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\KeyboardPayload;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\PhotoAttachmentPayload;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\PhotoAttachmentRequestPayload;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\ShareAttachmentRequestPayload;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\PhotoAttachment;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\ReplyKeyboardAttachment;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\ShareAttachment;
|
||||
use BushlanovDev\MaxMessengerBot\Models\BotCommand;
|
||||
use BushlanovDev\MaxMessengerBot\Models\BotInfo;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Chat;
|
||||
@@ -16,11 +35,14 @@ use BushlanovDev\MaxMessengerBot\Models\ChatList;
|
||||
use BushlanovDev\MaxMessengerBot\Models\ChatMember;
|
||||
use BushlanovDev\MaxMessengerBot\Models\ChatMembersList;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Image;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Markup\AbstractMarkup;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Markup\LinkMarkup;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Markup\StrongMarkup;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Message;
|
||||
use BushlanovDev\MaxMessengerBot\Models\MessageBody;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Recipient;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Result;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Sender;
|
||||
use BushlanovDev\MaxMessengerBot\Models\User;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Subscription;
|
||||
use BushlanovDev\MaxMessengerBot\Models\UpdateList;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Updates\BotStartedUpdate;
|
||||
@@ -28,10 +50,12 @@ use BushlanovDev\MaxMessengerBot\Models\Updates\ChatTitleChangedUpdate;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Updates\MessageChatCreatedUpdate;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Updates\MessageCreatedUpdate;
|
||||
use BushlanovDev\MaxMessengerBot\Models\UploadEndpoint;
|
||||
use BushlanovDev\MaxMessengerBot\Models\User;
|
||||
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
|
||||
use BushlanovDev\MaxMessengerBot\Models\VideoAttachmentDetails;
|
||||
use BushlanovDev\MaxMessengerBot\Models\VideoUrls;
|
||||
use LogicException;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@@ -45,11 +69,11 @@ use PHPUnit\Framework\TestCase;
|
||||
#[UsesClass(Message::class)]
|
||||
#[UsesClass(MessageBody::class)]
|
||||
#[UsesClass(Recipient::class)]
|
||||
#[UsesClass(Sender::class)]
|
||||
#[UsesClass(User::class)]
|
||||
#[UsesClass(UpdateList::class)]
|
||||
#[UsesClass(BotStartedUpdate::class)]
|
||||
#[UsesClass(MessageCreatedUpdate::class)]
|
||||
#[UsesClass(User::class)]
|
||||
#[UsesClass(UserWithPhoto::class)]
|
||||
#[UsesClass(UploadEndpoint::class)]
|
||||
#[UsesClass(Chat::class)]
|
||||
#[UsesClass(Image::class)]
|
||||
@@ -61,6 +85,28 @@ use PHPUnit\Framework\TestCase;
|
||||
#[UsesClass(VideoAttachmentDetails::class)]
|
||||
#[UsesClass(PhotoAttachmentRequestPayload::class)]
|
||||
#[UsesClass(VideoUrls::class)]
|
||||
#[UsesClass(AbstractAttachment::class)]
|
||||
#[UsesClass(DataAttachment::class)]
|
||||
#[UsesClass(ShareAttachment::class)]
|
||||
#[UsesClass(ShareAttachmentRequestPayload::class)]
|
||||
#[UsesClass(LinkMarkup::class)]
|
||||
#[UsesClass(AbstractMarkup::class)]
|
||||
#[UsesClass(StrongMarkup::class)]
|
||||
#[UsesClass(PhotoAttachmentPayload::class)]
|
||||
#[UsesClass(PhotoAttachment::class)]
|
||||
#[UsesClass(AbstractReplyButton::class)]
|
||||
#[UsesClass(SendContactButton::class)]
|
||||
#[UsesClass(SendMessageButton::class)]
|
||||
#[UsesClass(ReplyKeyboardAttachment::class)]
|
||||
#[UsesClass(AbstractInlineButton::class)]
|
||||
#[UsesClass(ChatButton::class)]
|
||||
#[UsesClass(RequestContactButton::class)]
|
||||
#[UsesClass(CallbackButton::class)]
|
||||
#[UsesClass(RequestGeoLocationButton::class)]
|
||||
#[UsesClass(LinkButton::class)]
|
||||
#[UsesClass(LocationAttachment::class)]
|
||||
#[UsesClass(InlineKeyboardAttachment::class)]
|
||||
#[UsesClass(KeyboardPayload::class)]
|
||||
final class ModelFactoryTest extends TestCase
|
||||
{
|
||||
private ModelFactory $factory;
|
||||
@@ -205,7 +251,7 @@ final class ModelFactoryTest extends TestCase
|
||||
$this->assertInstanceOf(Message::class, $message);
|
||||
$this->assertInstanceOf(MessageBody::class, $message->body);
|
||||
$this->assertInstanceOf(Recipient::class, $message->recipient);
|
||||
$this->assertInstanceOf(Sender::class, $message->sender);
|
||||
$this->assertInstanceOf(User::class, $message->sender);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
@@ -255,7 +301,7 @@ final class ModelFactoryTest extends TestCase
|
||||
|
||||
$this->assertInstanceOf(Chat::class, $chat);
|
||||
$this->assertInstanceOf(Image::class, $chat->icon);
|
||||
$this->assertInstanceOf(User::class, $chat->dialogWithUser);
|
||||
$this->assertInstanceOf(UserWithPhoto::class, $chat->dialogWithUser);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
@@ -506,4 +552,240 @@ final class ModelFactoryTest extends TestCase
|
||||
$this->assertInstanceOf(VideoUrls::class, $details->urls);
|
||||
$this->assertInstanceOf(PhotoAttachmentRequestPayload::class, $details->thumbnail);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function createMessageCorrectlyHydratesPolymorphicAttachments(): void
|
||||
{
|
||||
$rawData = [
|
||||
'timestamp' => time(),
|
||||
'body' => [
|
||||
'mid' => 'mid.789.def',
|
||||
'seq' => 102,
|
||||
'text' => 'Message with data attachment',
|
||||
'attachments' => [
|
||||
['type' => 'data', 'data' => 'payload_from_reply_button'],
|
||||
[
|
||||
'type' => 'share',
|
||||
'payload' => ['url' => 'http://a.com'],
|
||||
'title' => 'Test Share',
|
||||
'description' => null,
|
||||
'image_url' => null,
|
||||
],
|
||||
['type' => 'image', 'payload' => ['photo_id' => 1, 'token' => 't', 'url' => 'u']]
|
||||
],
|
||||
'markup' => null,
|
||||
],
|
||||
'recipient' => ['chat_type' => 'dialog', 'user_id' => 123],
|
||||
|
||||
];
|
||||
|
||||
$message = $this->factory->createMessage($rawData);
|
||||
$attachments = $message->body->attachments;
|
||||
|
||||
$this->assertInstanceOf(Message::class, $message);
|
||||
$this->assertInstanceOf(MessageBody::class, $message->body);
|
||||
$this->assertIsArray($attachments);
|
||||
$this->assertCount(3, $attachments);
|
||||
|
||||
$this->assertInstanceOf(DataAttachment::class, $attachments[0]);
|
||||
$this->assertSame('payload_from_reply_button', $attachments[0]->data);
|
||||
|
||||
$this->assertInstanceOf(ShareAttachment::class, $message->body->attachments[1]);
|
||||
$this->assertSame('Test Share', $attachments[1]->title);
|
||||
|
||||
$this->assertInstanceOf(PhotoAttachment::class, $attachments[2]);
|
||||
$this->assertSame(1, $attachments[2]->payload->photoId);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function createMessageCorrectlyHydratesMarkup(): void
|
||||
{
|
||||
// ... (данные теста)
|
||||
$rawData = [
|
||||
'timestamp' => time(),
|
||||
'body' => [
|
||||
'mid' => 'mid.markup.test',
|
||||
'seq' => 200,
|
||||
'text' => 'Hello world! Visit our site.',
|
||||
'attachments' => null,
|
||||
'markup' => [
|
||||
['type' => 'strong', 'from' => 6, 'length' => 5],
|
||||
['type' => 'link', 'from' => 18, 'length' => 4, 'url' => 'https://dev.max.ru']
|
||||
]
|
||||
],
|
||||
'recipient' => ['chat_type' => 'dialog', 'user_id' => 123],
|
||||
];
|
||||
|
||||
$message = $this->factory->createMessage($rawData);
|
||||
$markup = $message->body->markup;
|
||||
|
||||
$this->assertInstanceOf(StrongMarkup::class, $markup[0]);
|
||||
$this->assertSame(6, $markup[0]->from);
|
||||
|
||||
$this->assertInstanceOf(LinkMarkup::class, $markup[1]);
|
||||
$this->assertSame('https://dev.max.ru', $markup[1]->url);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function createMarkupElementThrowsExceptionForUnknownType(): void
|
||||
{
|
||||
$this->expectException(LogicException::class);
|
||||
$this->expectExceptionMessage('Unknown or unsupported markup type: brand_new_unsupported_type');
|
||||
|
||||
$this->factory->createMarkupElement(['type' => 'brand_new_unsupported_type']);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function createAttachmentCorrectlyHydratesReplyKeyboard(): void
|
||||
{
|
||||
$data = [
|
||||
'type' => 'reply_keyboard',
|
||||
'buttons' => [
|
||||
[['type' => 'message', 'text' => 'Hello']],
|
||||
[['type' => 'user_contact', 'text' => 'My Contact']]
|
||||
]
|
||||
];
|
||||
|
||||
$attachment = $this->factory->createAttachment($data);
|
||||
|
||||
$this->assertInstanceOf(ReplyKeyboardAttachment::class, $attachment);
|
||||
$this->assertCount(2, $attachment->buttons);
|
||||
$this->assertInstanceOf(SendMessageButton::class, $attachment->buttons[0][0]);
|
||||
$this->assertInstanceOf(SendContactButton::class, $attachment->buttons[1][0]);
|
||||
$this->assertSame('My Contact', $attachment->buttons[1][0]->text);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function createReplyButtonThrowsExceptionForUnknownType(): void
|
||||
{
|
||||
$this->expectException(LogicException::class);
|
||||
$this->expectExceptionMessage('Unknown or unsupported reply button type: new_fancy_button');
|
||||
|
||||
$this->factory->createReplyButton(['type' => 'new_fancy_button']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for successful inline button creation.
|
||||
* @return array<string, array{0: array<string, mixed>, 1: class-string}>
|
||||
*/
|
||||
public static function inlineButtonProvider(): array
|
||||
{
|
||||
return [
|
||||
'CallbackButton' => [
|
||||
['type' => 'callback', 'text' => 'Press', 'payload' => 'p'],
|
||||
CallbackButton::class,
|
||||
],
|
||||
'LinkButton' => [
|
||||
['type' => 'link', 'text' => 'Visit', 'url' => 'https://a.com'],
|
||||
LinkButton::class,
|
||||
],
|
||||
'RequestContactButton' => [
|
||||
['type' => 'request_contact', 'text' => 'Share Contact'],
|
||||
RequestContactButton::class,
|
||||
],
|
||||
'RequestGeoLocationButton' => [
|
||||
['type' => 'request_geo_location', 'text' => 'Share Location', 'quick' => false],
|
||||
RequestGeoLocationButton::class,
|
||||
],
|
||||
'ChatButton' => [
|
||||
['type' => 'chat', 'text' => 'Join Chat', 'chat_title' => 'My Chat'],
|
||||
ChatButton::class,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
#[Test]
|
||||
#[DataProvider('inlineButtonProvider')]
|
||||
public function createInlineButtonSuccessfully(array $data, string $expectedClass): void
|
||||
{
|
||||
$button = $this->factory->createInlineButton($data);
|
||||
|
||||
$this->assertInstanceOf($expectedClass, $button);
|
||||
$this->assertSame($data['text'], $button->text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for invalid inline button data.
|
||||
* @return array<string, array{0: array<string, mixed>, 1: string}>
|
||||
*/
|
||||
public static function invalidInlineButtonProvider(): array
|
||||
{
|
||||
return [
|
||||
'unknown type' => [
|
||||
['type' => 'unknown_button_type', 'text' => 'Unknown'],
|
||||
'Unknown or unsupported inline button type: unknown_button_type',
|
||||
],
|
||||
'missing type' => [
|
||||
['text' => 'No type here'],
|
||||
'Unknown or unsupported inline button type: none',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
#[Test]
|
||||
#[DataProvider('invalidInlineButtonProvider')]
|
||||
public function createInlineButtonThrowsExceptionForInvalidType(array $invalidData, string $expectedMessage): void
|
||||
{
|
||||
$this->expectException(LogicException::class);
|
||||
$this->expectExceptionMessage($expectedMessage);
|
||||
|
||||
$this->factory->createInlineButton($invalidData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testing various attachment types in createAttachment.
|
||||
* @return array<string, array{0: array<string, mixed>, 1: class-string, 2: callable}>
|
||||
*/
|
||||
public static function attachmentTypeProvider(): array
|
||||
{
|
||||
return [
|
||||
'Data Attachment' => [
|
||||
['type' => 'data', 'data' => 'test_payload'],
|
||||
DataAttachment::class,
|
||||
function (TestCase $test, DataAttachment $attachment) {
|
||||
$test->assertSame('test_payload', $attachment->data);
|
||||
}
|
||||
],
|
||||
|
||||
'Location Attachment' => [
|
||||
['type' => 'location', 'latitude' => 55.751244, 'longitude' => 37.618423],
|
||||
LocationAttachment::class,
|
||||
function (TestCase $test, LocationAttachment $attachment) {
|
||||
$test->assertSame(55.751244, $attachment->latitude);
|
||||
}
|
||||
],
|
||||
|
||||
'Inline Keyboard Attachment' => [
|
||||
[
|
||||
'type' => 'inline_keyboard',
|
||||
'payload' => [
|
||||
'buttons' => [
|
||||
[['type' => 'callback', 'text' => 'Test', 'payload' => 'p']]
|
||||
]
|
||||
]
|
||||
],
|
||||
InlineKeyboardAttachment::class,
|
||||
function (TestCase $test, InlineKeyboardAttachment $attachment) {
|
||||
$test->assertInstanceOf(KeyboardPayload::class, $attachment->payload);
|
||||
$test->assertIsArray($attachment->payload->buttons);
|
||||
$test->assertInstanceOf(CallbackButton::class, $attachment->payload->buttons[0][0]);
|
||||
$test->assertSame('p', $attachment->payload->buttons[0][0]->payload);
|
||||
}
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
#[Test]
|
||||
#[DataProvider('attachmentTypeProvider')]
|
||||
public function createAttachmentSuccessfullyCreatesVariousTypes(
|
||||
array $data,
|
||||
string $expectedClass,
|
||||
callable $assertionCallback,
|
||||
): void {
|
||||
$attachment = $this->factory->createAttachment($data);
|
||||
|
||||
$this->assertInstanceOf($expectedClass, $attachment);
|
||||
|
||||
$assertionCallback($this, $attachment);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,11 @@ namespace BushlanovDev\MaxMessengerBot\Tests\Models;
|
||||
use BushlanovDev\MaxMessengerBot\Attributes\ArrayOf;
|
||||
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\AbstractModel;
|
||||
use DateTimeInterface;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ReflectionClass;
|
||||
use stdClass;
|
||||
|
||||
#[CoversClass(AbstractModel::class)]
|
||||
@@ -176,6 +178,30 @@ final class AbstractModelMappingTest extends TestCase
|
||||
$this->assertEquals($expectedArray, $resultArray);
|
||||
$this->assertArrayNotHasKey('uninitialized_prop', $resultArray);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function castValueReturnsValueAsIsForUnmanagedScalarAssignedToObjectType(): void
|
||||
{
|
||||
$dateString = '2025-08-26';
|
||||
|
||||
$reflectionClass = new ReflectionClass(ModelForUnmanagedType::class);
|
||||
$abstractModelReflection = $reflectionClass->getParentClass();
|
||||
$castValueMethod = $abstractModelReflection->getMethod('castValue');
|
||||
$castValueMethod->setAccessible(true);
|
||||
|
||||
$property = $reflectionClass->getProperty('eventDate');
|
||||
|
||||
$result = $castValueMethod->invoke(null, $dateString, $property);
|
||||
|
||||
$this->assertSame($dateString, $result);
|
||||
}
|
||||
}
|
||||
|
||||
final readonly class ModelForUnmanagedType extends AbstractModel
|
||||
{
|
||||
public function __construct(public DateTimeInterface $eventDate)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
final readonly class DummyModelForUninitializedProperty extends AbstractModel
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\AudioAttachment;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\MediaAttachmentPayload;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(AudioAttachment::class)]
|
||||
#[UsesClass(MediaAttachmentPayload::class)]
|
||||
final class AudioAttachmentTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function canBeCreatedFromArray(): void
|
||||
{
|
||||
$data = ['type' => 'audio', 'payload' => ['url' => 'u', 'token' => 't'], 'transcription' => 'Hello world.'];
|
||||
$attachment = AudioAttachment::fromArray($data);
|
||||
$this->assertInstanceOf(AudioAttachment::class, $attachment);
|
||||
$this->assertSame('Hello world.', $attachment->transcription);
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -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',
|
||||
];
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Buttons\Inline;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\ChatButton;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(ChatButton::class)]
|
||||
final class ChatButtonTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function toArrayWithRequiredParameters(): void
|
||||
{
|
||||
$button = new ChatButton(
|
||||
text: 'Discuss Topic',
|
||||
chatTitle: 'Topic Discussion',
|
||||
);
|
||||
|
||||
$expected = [
|
||||
'type' => '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());
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -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',
|
||||
];
|
||||
|
||||
+4
-4
@@ -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',
|
||||
];
|
||||
|
||||
+4
-4
@@ -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',
|
||||
];
|
||||
|
||||
+5
-5
@@ -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',
|
||||
];
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Buttons\Reply;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendContactButton;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(SendContactButton::class)]
|
||||
final class SendContactButtonTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function toArray(): void
|
||||
{
|
||||
$button = new SendContactButton('Share My Contact');
|
||||
|
||||
$expected = [
|
||||
'type' => 'user_contact',
|
||||
'text' => 'Share My Contact',
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $button->toArray());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Buttons\Reply;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendGeoLocationButton;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(SendGeoLocationButton::class)]
|
||||
final class SendGeoLocationButtonTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function toArrayWithDefaultQuick(): void
|
||||
{
|
||||
$button = new SendGeoLocationButton('Share Location');
|
||||
|
||||
$expected = [
|
||||
'type' => '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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Buttons\Reply;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\Intent;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendMessageButton;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(SendMessageButton::class)]
|
||||
final class SendMessageButtonTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function toArrayWithDefaults(): void
|
||||
{
|
||||
$button = new SendMessageButton('Click Me');
|
||||
|
||||
$expected = [
|
||||
'type' => '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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\ContactAttachment;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\ContactAttachmentPayload;
|
||||
use BushlanovDev\MaxMessengerBot\Models\User;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(ContactAttachment::class)]
|
||||
#[UsesClass(ContactAttachmentPayload::class)]
|
||||
#[UsesClass(User::class)]
|
||||
final class ContactAttachmentTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function canBeCreatedFromArray(): void
|
||||
{
|
||||
$data = ['type' => 'contact', 'payload' => ['vcf_info' => 'vcf', 'max_info' => null]];
|
||||
$attachment = ContactAttachment::fromArray($data);
|
||||
$this->assertInstanceOf(ContactAttachment::class, $attachment);
|
||||
$this->assertSame('vcf', $attachment->payload->vcfInfo);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\AbstractAttachment;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\DataAttachment;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(DataAttachment::class)]
|
||||
#[UsesClass(AbstractAttachment::class)]
|
||||
final class DataAttachmentTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function canBeCreatedAndSerialized(): void
|
||||
{
|
||||
$attachment = new DataAttachment('some_payload_from_button');
|
||||
|
||||
$this->assertSame(AttachmentType::Data, $attachment->type);
|
||||
$this->assertSame('some_payload_from_button', $attachment->data);
|
||||
|
||||
$expectedArray = [
|
||||
'type' => 'data',
|
||||
'data' => 'some_payload_from_button',
|
||||
];
|
||||
|
||||
$this->assertEquals($expectedArray, $attachment->toArray());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function canBeCreatedFromArray(): void
|
||||
{
|
||||
$data = [
|
||||
'type' => 'data',
|
||||
'data' => 'payload123',
|
||||
];
|
||||
|
||||
$attachment = DataAttachment::fromArray($data);
|
||||
|
||||
$this->assertInstanceOf(DataAttachment::class, $attachment);
|
||||
$this->assertSame(AttachmentType::Data, $attachment->type);
|
||||
$this->assertSame('payload123', $attachment->data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\FileAttachment;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\FileAttachmentPayload;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(FileAttachment::class)]
|
||||
#[UsesClass(FileAttachmentPayload::class)]
|
||||
final class FileAttachmentTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function canBeCreatedFromArray(): void
|
||||
{
|
||||
$data = [
|
||||
'type' => 'file',
|
||||
'payload' => ['url' => 'u', 'token' => 't'],
|
||||
'filename' => 'doc.pdf',
|
||||
'size' => 1024,
|
||||
];
|
||||
$attachment = FileAttachment::fromArray($data);
|
||||
$this->assertInstanceOf(FileAttachment::class, $attachment);
|
||||
$this->assertSame('doc.pdf', $attachment->filename);
|
||||
$this->assertSame(1024, $attachment->size);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\CallbackButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\InlineKeyboardAttachment;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\KeyboardPayload;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(InlineKeyboardAttachment::class)]
|
||||
#[UsesClass(KeyboardPayload::class)]
|
||||
#[UsesClass(CallbackButton::class)]
|
||||
final class InlineKeyboardAttachmentTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function canBeCreatedFromArray(): void
|
||||
{
|
||||
$data = [
|
||||
'type' => 'inline_keyboard',
|
||||
'payload' => ['buttons' => [[['type' => 'callback', 'text' => 'Press', 'payload' => 'p']]]],
|
||||
];
|
||||
$attachment = InlineKeyboardAttachment::fromArray($data);
|
||||
$this->assertInstanceOf(InlineKeyboardAttachment::class, $attachment);
|
||||
$this->assertInstanceOf(KeyboardPayload::class, $attachment->payload);
|
||||
$this->assertCount(1, $attachment->payload->buttons);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\LocationAttachment;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(LocationAttachment::class)]
|
||||
final class LocationAttachmentTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function canBeCreatedFromArray(): void
|
||||
{
|
||||
$data = ['type' => 'location', 'latitude' => 55.75, 'longitude' => 37.61];
|
||||
$attachment = LocationAttachment::fromArray($data);
|
||||
$this->assertInstanceOf(LocationAttachment::class, $attachment);
|
||||
$this->assertSame(55.75, $attachment->latitude);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Payloads;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\ContactAttachmentPayload;
|
||||
use BushlanovDev\MaxMessengerBot\Models\User;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(ContactAttachmentPayload::class)]
|
||||
#[UsesClass(User::class)]
|
||||
final class ContactAttachmentPayloadTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function canBeCreatedAndSerialized(): void
|
||||
{
|
||||
$user = User::fromArray(
|
||||
['user_id' => 101, 'first_name' => 'MaxUser', 'is_bot' => false, 'last_activity_time' => time()]
|
||||
);
|
||||
$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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Payloads;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\FileAttachmentPayload;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(FileAttachmentPayload::class)]
|
||||
final class FileAttachmentPayloadTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function canBeCreatedAndSerialized(): void
|
||||
{
|
||||
$payload = new FileAttachmentPayload('https://example.com/doc.pdf', 'file_token_456');
|
||||
$this->assertSame('https://example.com/doc.pdf', $payload->url);
|
||||
$this->assertSame('file_token_456', $payload->token);
|
||||
$this->assertEquals(['url' => 'https://example.com/doc.pdf', 'token' => 'file_token_456'], $payload->toArray());
|
||||
}
|
||||
}
|
||||
@@ -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',
|
||||
],
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Payloads;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\ModelFactory;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\AbstractAttachment;
|
||||
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\InlineKeyboardAttachment;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\KeyboardPayload;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(KeyboardPayload::class)]
|
||||
#[UsesClass(ModelFactory::class)]
|
||||
#[UsesClass(AbstractAttachment::class)]
|
||||
#[UsesClass(AbstractInlineButton::class)]
|
||||
#[UsesClass(CallbackButton::class)]
|
||||
#[UsesClass(LinkButton::class)]
|
||||
#[UsesClass(InlineKeyboardAttachment::class)]
|
||||
final class KeyboardPayloadTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function canBeCreatedFromArrayViaFactory(): void
|
||||
{
|
||||
$data = [
|
||||
'type' => 'inline_keyboard',
|
||||
'payload' => [
|
||||
'buttons' => [
|
||||
[
|
||||
['type' => 'callback', 'text' => 'Press Me', 'payload' => 'payload_123'],
|
||||
],
|
||||
[
|
||||
['type' => 'link', 'text' => 'Docs', 'url' => 'https://dev.max.ru'],
|
||||
['type' => 'callback', 'text' => 'Cancel', 'payload' => 'cancel_op'],
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$factory = new ModelFactory();
|
||||
$attachment = $factory->createAttachment($data);
|
||||
|
||||
$this->assertInstanceOf(InlineKeyboardAttachment::class, $attachment);
|
||||
$this->assertInstanceOf(KeyboardPayload::class, $attachment->payload);
|
||||
|
||||
$buttons = $attachment->payload->buttons;
|
||||
$this->assertCount(2, $buttons);
|
||||
|
||||
$this->assertCount(1, $buttons[0]);
|
||||
$this->assertInstanceOf(CallbackButton::class, $buttons[0][0]);
|
||||
$this->assertSame('payload_123', $buttons[0][0]->payload);
|
||||
|
||||
$this->assertCount(2, $buttons[1]);
|
||||
$this->assertInstanceOf(LinkButton::class, $buttons[1][0]);
|
||||
$this->assertSame('https://dev.max.ru', $buttons[1][0]->url);
|
||||
$this->assertInstanceOf(CallbackButton::class, $buttons[1][1]);
|
||||
$this->assertSame('cancel_op', $buttons[1][1]->payload);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Payloads;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\MediaAttachmentPayload;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(MediaAttachmentPayload::class)]
|
||||
final class MediaAttachmentPayloadTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function canBeCreatedAndSerialized(): void
|
||||
{
|
||||
$payload = new MediaAttachmentPayload('https://example.com/video.mp4', 'video_token_123');
|
||||
$this->assertSame('https://example.com/video.mp4', $payload->url);
|
||||
$this->assertSame('video_token_123', $payload->token);
|
||||
$this->assertEquals(
|
||||
['url' => 'https://example.com/video.mp4', 'token' => 'video_token_123'],
|
||||
$payload->toArray(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4,105 +4,33 @@ declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Payloads;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Attributes\ArrayOf;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\PhotoAttachmentRequestPayload;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\PhotoToken;
|
||||
use InvalidArgumentException;
|
||||
use BushlanovDev\MaxMessengerBot\Models\AbstractModel;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\PhotoAttachmentPayload;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(PhotoAttachmentRequestPayload::class)]
|
||||
#[UsesClass(PhotoToken::class)]
|
||||
#[UsesClass(ArrayOf::class)]
|
||||
#[CoversClass(PhotoAttachmentPayload::class)]
|
||||
#[UsesClass(AbstractModel::class)]
|
||||
final class PhotoAttachmentPayloadTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function canBeCreatedWithUrlOnly(): void
|
||||
public function canBeCreatedAndSerialized(): void
|
||||
{
|
||||
$payload = new PhotoAttachmentRequestPayload(url: 'https://example.com/photo.jpg');
|
||||
|
||||
$this->assertSame('https://example.com/photo.jpg', $payload->url);
|
||||
$this->assertNull($payload->token);
|
||||
$this->assertNull($payload->photos);
|
||||
|
||||
$expectedArray = [
|
||||
'url' => 'https://example.com/photo.jpg',
|
||||
'token' => null,
|
||||
'photos' => null,
|
||||
$data = [
|
||||
'photo_id' => 987654321,
|
||||
'token' => 'some_received_photo_token',
|
||||
'url' => 'https://cdn.max.ru/photos/image.jpg'
|
||||
];
|
||||
$this->assertEquals($expectedArray, $payload->toArray());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function canBeCreatedWithTokenOnly(): void
|
||||
{
|
||||
$payload = new PhotoAttachmentRequestPayload(token: 'uploaded_token_abc');
|
||||
$payload = PhotoAttachmentPayload::fromArray($data);
|
||||
|
||||
$this->assertSame('uploaded_token_abc', $payload->token);
|
||||
$this->assertNull($payload->url);
|
||||
$this->assertNull($payload->photos);
|
||||
$this->assertInstanceOf(PhotoAttachmentPayload::class, $payload);
|
||||
$this->assertSame(987654321, $payload->photoId);
|
||||
$this->assertSame('some_received_photo_token', $payload->token);
|
||||
$this->assertSame('https://cdn.max.ru/photos/image.jpg', $payload->url);
|
||||
|
||||
$expectedArray = [
|
||||
'token' => 'uploaded_token_abc',
|
||||
'url' => null,
|
||||
'photos' => null,
|
||||
];
|
||||
$this->assertEquals($expectedArray, $payload->toArray());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function canBeCreatedWithPhotosOnly(): void
|
||||
{
|
||||
$photos = [
|
||||
new PhotoToken('token_1'),
|
||||
new PhotoToken('token_2'),
|
||||
];
|
||||
$payload = new PhotoAttachmentRequestPayload(photos: $photos);
|
||||
|
||||
$this->assertSame($photos, $payload->photos);
|
||||
$this->assertNull($payload->url);
|
||||
$this->assertNull($payload->token);
|
||||
|
||||
$expectedArray = [
|
||||
'photos' => [
|
||||
['token' => 'token_1'],
|
||||
['token' => 'token_2'],
|
||||
],
|
||||
'url' => null,
|
||||
'token' => null,
|
||||
];
|
||||
$this->assertEquals($expectedArray, $payload->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for invalid constructor arguments.
|
||||
*
|
||||
* @return array<string, array{0: string|null, 1: string|null, 2: array|null}>
|
||||
*/
|
||||
public static function invalidPayloadProvider(): array
|
||||
{
|
||||
return [
|
||||
'all null (no arguments)' => [null, null, null],
|
||||
'url and token provided' => ['https://a.com', 'token123', null],
|
||||
'url and photos provided' => ['https://a.com', null, [new PhotoToken('t')]],
|
||||
'token and photos provided' => [null, 'token123', [new PhotoToken('t')]],
|
||||
'all three arguments provided' => ['https://a.com', 'token123', [new PhotoToken('t')]],
|
||||
];
|
||||
}
|
||||
|
||||
#[Test]
|
||||
#[DataProvider('invalidPayloadProvider')]
|
||||
public function constructorThrowsExceptionForInvalidArguments(
|
||||
?string $url,
|
||||
?string $token,
|
||||
?array $photos
|
||||
): void {
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Provide exactly one of "url", "token", or "photos" for PhotoAttachmentRequestPayload.');
|
||||
|
||||
new PhotoAttachmentRequestPayload($url, $token, $photos);
|
||||
$this->assertEquals($data, $payload->toArray());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Payloads;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\Intent;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendContactButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendMessageButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\ReplyKeyboardAttachmentRequestPayload;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(ReplyKeyboardAttachmentRequestPayload::class)]
|
||||
#[UsesClass(SendMessageButton::class)]
|
||||
#[UsesClass(SendContactButton::class)]
|
||||
final class ReplyKeyboardAttachmentRequestPayloadTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function toArrayWithDefaults(): void
|
||||
{
|
||||
$buttons = [
|
||||
[new SendMessageButton('Help')],
|
||||
[new SendContactButton('Share Contact')],
|
||||
];
|
||||
|
||||
$payload = new ReplyKeyboardAttachmentRequestPayload($buttons);
|
||||
|
||||
$expected = [
|
||||
'buttons' => [
|
||||
[
|
||||
[
|
||||
'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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Payloads;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\StickerAttachmentPayload;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(StickerAttachmentPayload::class)]
|
||||
final class StickerAttachmentPayloadTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function canBeCreatedAndSerialized(): void
|
||||
{
|
||||
$payload = new StickerAttachmentPayload('https://example.com/sticker.webp', 'sticker_code_abc');
|
||||
$this->assertSame('https://example.com/sticker.webp', $payload->url);
|
||||
$this->assertSame('sticker_code_abc', $payload->code);
|
||||
$this->assertEquals(
|
||||
['url' => 'https://example.com/sticker.webp', 'code' => 'sticker_code_abc'],
|
||||
$payload->toArray(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Payloads;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Models\AbstractModel;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\VideoThumbnail;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(VideoThumbnail::class)]
|
||||
#[UsesClass(AbstractModel::class)]
|
||||
final class VideoThumbnailTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function canBeCreatedAndSerialized(): void
|
||||
{
|
||||
$data = [
|
||||
'url' => 'https://example.com/video_thumbnail.jpg',
|
||||
];
|
||||
|
||||
$thumbnail = VideoThumbnail::fromArray($data);
|
||||
|
||||
$this->assertInstanceOf(VideoThumbnail::class, $thumbnail);
|
||||
$this->assertSame('https://example.com/video_thumbnail.jpg', $thumbnail->url);
|
||||
|
||||
$this->assertEquals($data, $thumbnail->toArray());
|
||||
|
||||
$directInstance = new VideoThumbnail('https://example.com/video_thumbnail.jpg');
|
||||
$this->assertSame('https://example.com/video_thumbnail.jpg', $directInstance->url);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\PhotoAttachmentPayload;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\PhotoAttachment;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(PhotoAttachment::class)]
|
||||
#[UsesClass(PhotoAttachmentPayload::class)]
|
||||
final class PhotoAttachmentTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function canBeCreatedFromArray(): void
|
||||
{
|
||||
$data = ['type' => 'image', 'payload' => ['photo_id' => 1, 'token' => 't', 'url' => 'u']];
|
||||
$attachment = PhotoAttachment::fromArray($data);
|
||||
$this->assertInstanceOf(PhotoAttachment::class, $attachment);
|
||||
$this->assertInstanceOf(PhotoAttachmentPayload::class, $attachment->payload);
|
||||
$this->assertSame(1, $attachment->payload->photoId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\ModelFactory;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\AbstractReplyButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendContactButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendMessageButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\ReplyKeyboardAttachment;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(ReplyKeyboardAttachment::class)]
|
||||
#[UsesClass(AbstractReplyButton::class)]
|
||||
#[UsesClass(SendContactButton::class)]
|
||||
#[UsesClass(SendMessageButton::class)]
|
||||
#[UsesClass(ModelFactory::class)]
|
||||
final class ReplyKeyboardAttachmentTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function canBeCreatedFromArrayViaFactory(): void
|
||||
{
|
||||
$data = [
|
||||
'type' => 'reply_keyboard',
|
||||
'buttons' => [
|
||||
[['type' => 'message', 'text' => 'Hello']],
|
||||
[['type' => 'user_contact', 'text' => 'My Contact']]
|
||||
]
|
||||
];
|
||||
|
||||
$factory = new ModelFactory();
|
||||
$attachment = $factory->createAttachment($data);
|
||||
|
||||
$this->assertInstanceOf(ReplyKeyboardAttachment::class, $attachment);
|
||||
$this->assertCount(2, $attachment->buttons);
|
||||
$this->assertInstanceOf(SendContactButton::class, $attachment->buttons[1][0]);
|
||||
$this->assertSame('My Contact', $attachment->buttons[1][0]->text);
|
||||
}
|
||||
}
|
||||
@@ -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',
|
||||
],
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Requests;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\Intent;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendContactButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendMessageButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\ReplyKeyboardAttachmentRequestPayload;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Requests\ReplyKeyboardAttachmentRequest;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(ReplyKeyboardAttachmentRequest::class)]
|
||||
#[UsesClass(SendMessageButton::class)]
|
||||
#[UsesClass(SendContactButton::class)]
|
||||
#[UsesClass(ReplyKeyboardAttachmentRequestPayload::class)]
|
||||
final class ReplyKeyboardAttachmentRequestTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function toArray(): void
|
||||
{
|
||||
$buttons = [
|
||||
[new SendMessageButton('Help', 'help_payload', Intent::Positive)],
|
||||
[new SendContactButton('Share Contact')],
|
||||
];
|
||||
|
||||
$request = new ReplyKeyboardAttachmentRequest(buttons: $buttons, direct: true);
|
||||
|
||||
$expectedArray = [
|
||||
'type' => '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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\AbstractAttachment;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\ShareAttachmentRequestPayload;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\ShareAttachment;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(ShareAttachment::class)]
|
||||
#[UsesClass(AbstractAttachment::class)]
|
||||
#[UsesClass(ShareAttachmentRequestPayload::class)]
|
||||
final class ShareAttachmentTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function canBeCreatedFromArray(): void
|
||||
{
|
||||
$data = [
|
||||
'type' => 'share',
|
||||
'payload' => ['url' => 'https://dev.max.ru'],
|
||||
'title' => 'Max Bot API',
|
||||
'description' => 'Documentation for Max Bot API',
|
||||
'image_url' => 'https://dev.max.ru/image.png',
|
||||
];
|
||||
|
||||
$attachment = ShareAttachment::fromArray($data);
|
||||
|
||||
$this->assertInstanceOf(ShareAttachment::class, $attachment);
|
||||
$this->assertSame(AttachmentType::Share, $attachment->type);
|
||||
$this->assertSame('Max Bot API', $attachment->title);
|
||||
$this->assertInstanceOf(ShareAttachmentRequestPayload::class, $attachment->payload);
|
||||
$this->assertSame('https://dev.max.ru', $attachment->payload->url);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\StickerAttachmentPayload;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\StickerAttachment;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(StickerAttachment::class)]
|
||||
#[UsesClass(StickerAttachmentPayload::class)]
|
||||
final class StickerAttachmentTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function canBeCreatedFromArray(): void
|
||||
{
|
||||
$data = ['type' => 'sticker', 'payload' => ['url' => 'u', 'code' => 'c'], 'width' => 128, 'height' => 128];
|
||||
$attachment = StickerAttachment::fromArray($data);
|
||||
$this->assertInstanceOf(StickerAttachment::class, $attachment);
|
||||
$this->assertSame(128, $attachment->width);
|
||||
$this->assertSame('c', $attachment->payload->code);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\MediaAttachmentPayload;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\VideoThumbnail;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\VideoAttachment;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(VideoAttachment::class)]
|
||||
#[UsesClass(MediaAttachmentPayload::class)]
|
||||
#[UsesClass(VideoThumbnail::class)]
|
||||
final class VideoAttachmentTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function canBeCreatedFromArray(): void
|
||||
{
|
||||
$data = [
|
||||
'type' => 'video',
|
||||
'payload' => ['url' => 'u', 'token' => 't'],
|
||||
'thumbnail' => ['url' => 'thumb_url'],
|
||||
'width' => 1920,
|
||||
'height' => 1080,
|
||||
'duration' => 120,
|
||||
];
|
||||
$attachment = VideoAttachment::fromArray($data);
|
||||
$this->assertInstanceOf(VideoAttachment::class, $attachment);
|
||||
$this->assertInstanceOf(MediaAttachmentPayload::class, $attachment->payload);
|
||||
$this->assertInstanceOf(VideoThumbnail::class, $attachment->thumbnail);
|
||||
$this->assertSame(120, $attachment->duration);
|
||||
}
|
||||
}
|
||||
@@ -29,9 +29,6 @@ final class CallbackTest extends TestCase
|
||||
'last_activity_time' => 1678886000,
|
||||
'last_name' => null,
|
||||
'username' => null,
|
||||
'description' => null,
|
||||
'avatar_url' => null,
|
||||
'full_avatar_url' => null,
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
@@ -6,14 +6,14 @@ namespace BushlanovDev\MaxMessengerBot\Tests\Models;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Models\Chat;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Image;
|
||||
use BushlanovDev\MaxMessengerBot\Models\User;
|
||||
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(Chat::class)]
|
||||
#[CoversClass(Image::class)]
|
||||
#[CoversClass(User::class)]
|
||||
#[CoversClass(UserWithPhoto::class)]
|
||||
final class ChatTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
@@ -42,6 +42,9 @@ final class ChatTest extends TestCase
|
||||
'username' => 'johndoe',
|
||||
'is_bot' => false,
|
||||
'last_activity_time' => 1678886400000,
|
||||
'description' => 'Description',
|
||||
'avatar_url' => 'https://example.com/avatar.jpg',
|
||||
'full_avatar_url' => 'https://example.com/full_avatar.jpg',
|
||||
],
|
||||
'messages_count' => 100,
|
||||
'chat_message_id' => 'mid.123',
|
||||
@@ -62,6 +65,7 @@ final class ChatTest extends TestCase
|
||||
$this->assertSame($data['link'], $chat->link);
|
||||
$this->assertSame($data['description'], $chat->description);
|
||||
$this->assertSame($data['dialog_with_user']['user_id'], $chat->dialogWithUser->userId);
|
||||
$this->assertSame($data['dialog_with_user']['full_avatar_url'], $chat->dialogWithUser->fullAvatarUrl);
|
||||
$this->assertSame($data['messages_count'], $chat->messagesCount);
|
||||
$this->assertSame($data['chat_message_id'], $chat->chatMessageId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\MessageLinkType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\LinkedMessage;
|
||||
use BushlanovDev\MaxMessengerBot\Models\MessageBody;
|
||||
use BushlanovDev\MaxMessengerBot\Models\User;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(LinkedMessage::class)]
|
||||
#[UsesClass(MessageBody::class)]
|
||||
#[UsesClass(User::class)]
|
||||
final class LinkedMessageTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function canBeCreatedFromArray(): void
|
||||
{
|
||||
$data = [
|
||||
'type' => 'reply',
|
||||
'message' => [
|
||||
'mid' => 'mid.original.123',
|
||||
'seq' => 10,
|
||||
'text' => 'This is the original message.',
|
||||
'attachments' => null,
|
||||
'markup' => null,
|
||||
],
|
||||
'sender' => [
|
||||
'user_id' => 101,
|
||||
'first_name' => 'Original',
|
||||
'last_name' => 'Sender',
|
||||
'is_bot' => false,
|
||||
'last_activity_time' => time() - 1000,
|
||||
],
|
||||
'chat_id' => 98765,
|
||||
];
|
||||
|
||||
$linkedMessage = LinkedMessage::fromArray($data);
|
||||
|
||||
$this->assertInstanceOf(LinkedMessage::class, $linkedMessage);
|
||||
$this->assertSame(MessageLinkType::Reply, $linkedMessage->type);
|
||||
$this->assertInstanceOf(MessageBody::class, $linkedMessage->message);
|
||||
$this->assertSame('mid.original.123', $linkedMessage->message->mid);
|
||||
$this->assertInstanceOf(User::class, $linkedMessage->sender);
|
||||
$this->assertSame(101, $linkedMessage->sender->userId);
|
||||
$this->assertSame(98765, $linkedMessage->chatId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Markup;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\MarkupType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Markup\EmphasizedMarkup;
|
||||
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\StrikethroughMarkup;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Markup\StrongMarkup;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Markup\UnderlineMarkup;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Markup\UserMentionMarkup;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(LinkMarkup::class)]
|
||||
#[CoversClass(UserMentionMarkup::class)]
|
||||
#[CoversClass(StrongMarkup::class)]
|
||||
#[CoversClass(UnderlineMarkup::class)]
|
||||
#[CoversClass(StrikethroughMarkup::class)]
|
||||
#[CoversClass(MonospacedMarkup::class)]
|
||||
#[CoversClass(EmphasizedMarkup::class)]
|
||||
#[CoversClass(HeadingMarkup::class)]
|
||||
#[CoversClass(HighlightedMarkup::class)]
|
||||
final class MarkupTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function linkMarkupIsCreatedCorrectly(): void
|
||||
{
|
||||
$data = ['type' => 'link', 'from' => 6, 'length' => 10, 'url' => 'https://dev.max.ru'];
|
||||
$markup = LinkMarkup::fromArray($data);
|
||||
$this->assertSame(MarkupType::Link, $markup->type);
|
||||
$this->assertSame('https://dev.max.ru', $markup->url);
|
||||
$this->assertEquals($data, $markup->toArray());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function userMentionMarkupIsCreatedCorrectly(): void
|
||||
{
|
||||
$data = ['type' => 'user_mention', 'from' => 17, 'length' => 8, 'user_link' => '@username', 'user_id' => 12345];
|
||||
$markup = UserMentionMarkup::fromArray($data);
|
||||
$this->assertSame(MarkupType::UserMention, $markup->type);
|
||||
$this->assertSame('@username', $markup->userLink);
|
||||
$this->assertSame(12345, $markup->userId);
|
||||
$this->assertEquals($data, $markup->toArray());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function strongMarkupIsCreatesCorrectly(): void
|
||||
{
|
||||
$data = ['type' => 'strong', 'from' => 0, 'length' => 5];
|
||||
$markup = StrongMarkup::fromArray($data);
|
||||
|
||||
$this->assertInstanceOf(StrongMarkup::class, $markup);
|
||||
$this->assertSame(MarkupType::Strong, $markup->type);
|
||||
$this->assertSame(0, $markup->from);
|
||||
$this->assertSame(5, $markup->length);
|
||||
$this->assertEquals($data, $markup->toArray());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function underlineMarkupIsCreatesCorrectly(): void
|
||||
{
|
||||
$data = ['type' => 'underline', 'from' => 1, 'length' => 4];
|
||||
$markup = UnderlineMarkup::fromArray($data);
|
||||
|
||||
$this->assertInstanceOf(UnderlineMarkup::class, $markup);
|
||||
$this->assertSame(MarkupType::Underline, $markup->type);
|
||||
$this->assertSame(1, $markup->from);
|
||||
$this->assertSame(4, $markup->length);
|
||||
$this->assertEquals($data, $markup->toArray());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function strikethroughMarkupIsCreatesCorrectly(): void
|
||||
{
|
||||
$data = ['type' => 'strikethrough', 'from' => 1, 'length' => 4];
|
||||
$markup = StrikethroughMarkup::fromArray($data);
|
||||
|
||||
$this->assertInstanceOf(StrikethroughMarkup::class, $markup);
|
||||
$this->assertSame(MarkupType::Strikethrough, $markup->type);
|
||||
$this->assertSame(1, $markup->from);
|
||||
$this->assertSame(4, $markup->length);
|
||||
$this->assertEquals($data, $markup->toArray());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function monospacedMarkupIsCreatesCorrectly(): void
|
||||
{
|
||||
$data = ['type' => 'monospaced', 'from' => 1, 'length' => 4];
|
||||
$markup = MonospacedMarkup::fromArray($data);
|
||||
|
||||
$this->assertInstanceOf(MonospacedMarkup::class, $markup);
|
||||
$this->assertSame(MarkupType::Monospaced, $markup->type);
|
||||
$this->assertSame(1, $markup->from);
|
||||
$this->assertSame(4, $markup->length);
|
||||
$this->assertEquals($data, $markup->toArray());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function emphasizedMarkupIsCreatesCorrectly(): void
|
||||
{
|
||||
$data = ['type' => 'emphasized', 'from' => 1, 'length' => 4];
|
||||
$markup = EmphasizedMarkup::fromArray($data);
|
||||
|
||||
$this->assertInstanceOf(EmphasizedMarkup::class, $markup);
|
||||
$this->assertSame(MarkupType::Emphasized, $markup->type);
|
||||
$this->assertSame(1, $markup->from);
|
||||
$this->assertSame(4, $markup->length);
|
||||
$this->assertEquals($data, $markup->toArray());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function headingMarkupIsCreatesCorrectly(): void
|
||||
{
|
||||
$data = ['type' => 'heading', 'from' => 1, 'length' => 4];
|
||||
$markup = HeadingMarkup::fromArray($data);
|
||||
|
||||
$this->assertInstanceOf(HeadingMarkup::class, $markup);
|
||||
$this->assertSame(MarkupType::Heading, $markup->type);
|
||||
$this->assertSame(1, $markup->from);
|
||||
$this->assertSame(4, $markup->length);
|
||||
$this->assertEquals($data, $markup->toArray());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function highlightedMarkupIsCreatesCorrectly(): void
|
||||
{
|
||||
$data = ['type' => 'highlighted', 'from' => 1, 'length' => 4];
|
||||
$markup = HighlightedMarkup::fromArray($data);
|
||||
|
||||
$this->assertInstanceOf(HighlightedMarkup::class, $markup);
|
||||
$this->assertSame(MarkupType::Highlighted, $markup->type);
|
||||
$this->assertSame(1, $markup->from);
|
||||
$this->assertSame(4, $markup->length);
|
||||
$this->assertEquals($data, $markup->toArray());
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,8 @@ final class MessageBodyTest extends TestCase
|
||||
'mid' => 'mid.456.xyz',
|
||||
'seq' => 101,
|
||||
'text' => 'Hello, **world**!',
|
||||
'attachments' => null,
|
||||
'markup' => null,
|
||||
];
|
||||
|
||||
$messageBody = MessageBody::fromArray($data);
|
||||
@@ -41,6 +43,8 @@ final class MessageBodyTest extends TestCase
|
||||
'mid' => 'mid.456.xyz',
|
||||
'seq' => 101,
|
||||
'text' => null,
|
||||
'attachments' => null,
|
||||
'markup' => null,
|
||||
];
|
||||
|
||||
$messageBody = MessageBody::fromArray($data);
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Models\MessageStat;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(MessageStat::class)]
|
||||
final class MessageStatTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function canBeCreatedAndSerialized(): void
|
||||
{
|
||||
$data = ['views' => 1234];
|
||||
$stat = MessageStat::fromArray($data);
|
||||
|
||||
$this->assertInstanceOf(MessageStat::class, $stat);
|
||||
$this->assertSame(1234, $stat->views);
|
||||
$this->assertEquals($data, $stat->toArray());
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user