mirror of
https://github.com/BushlanovDev/max-bot-api-client-php.git
synced 2026-08-24 23:46:50 +00:00
Added MessageButton & ChatAdminPermission::EditLink & alias in ChatAdmin & participants in Chat & first_name in BotPatch
This commit is contained in:
+1
-1
@@ -4656,4 +4656,4 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,4 +15,5 @@ enum ChatAdminPermission: string
|
||||
case ChangeChatInfo = 'change_chat_info';
|
||||
case PinMessage = 'pin_message';
|
||||
case Write = 'write';
|
||||
case EditLink = 'edit_link';
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\AbstractInlin
|
||||
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\MessageButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\OpenAppButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\RequestContactButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\RequestGeoLocationButton;
|
||||
@@ -311,6 +312,7 @@ readonly class ModelFactory
|
||||
InlineButtonType::RequestGeoLocation => RequestGeoLocationButton::fromArray($data),
|
||||
InlineButtonType::Chat => ChatButton::fromArray($data),
|
||||
InlineButtonType::OpenApp => OpenAppButton::fromArray($data),
|
||||
InlineButtonType::Message => MessageButton::fromArray($data),
|
||||
default => throw new LogicException(
|
||||
'Unknown or unsupported inline button type: ' . ($data['type'] ?? 'none')
|
||||
),
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\InlineButtonType;
|
||||
|
||||
/**
|
||||
* Button send text in chat from user.
|
||||
*/
|
||||
final readonly class MessageButton extends AbstractInlineButton
|
||||
{
|
||||
/**
|
||||
* @param string $text Text sending in chat from user.
|
||||
*/
|
||||
public function __construct(string $text)
|
||||
{
|
||||
parent::__construct(InlineButtonType::Message, $text);
|
||||
}
|
||||
}
|
||||
@@ -9,12 +9,14 @@ use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\PhotoAttachmentRequ
|
||||
/**
|
||||
* Represents the data to patch for a bot. Instantiate with named arguments.
|
||||
*
|
||||
* Example: new BotPatch(name: 'New Bot Name', description: null);
|
||||
* Example: new BotPatch(first_name: 'New Bot Name', description: null);
|
||||
*
|
||||
* @property-read string|null $name
|
||||
* @property-read string|null $first_name
|
||||
* @property-read string|null $last_name
|
||||
* @property-read string|null $description
|
||||
* @property-read BotCommand[]|null $commands
|
||||
* @property-read PhotoAttachmentRequestPayload|null $photo
|
||||
* @property-read string|null $name @deprecated Use first_name
|
||||
*/
|
||||
final readonly class BotPatch extends AbstractPatchModel
|
||||
{
|
||||
|
||||
@@ -28,6 +28,7 @@ final readonly class Chat extends AbstractModel
|
||||
* @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.
|
||||
* @param array<string, int>|null $participants List of participants in chat. Returned only when single chat is requested.
|
||||
*/
|
||||
public function __construct(
|
||||
public int $chatId,
|
||||
@@ -45,6 +46,7 @@ final readonly class Chat extends AbstractModel
|
||||
public ?int $messagesCount,
|
||||
public ?string $chatMessageId,
|
||||
public ?Message $pinnedMessage,
|
||||
public ?array $participants,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,11 +15,13 @@ final readonly class ChatAdmin extends AbstractModel
|
||||
/**
|
||||
* @param int $userId The identifier of the user to be made an admin.
|
||||
* @param ChatAdminPermission[] $permissions The list of permissions to grant to the user.
|
||||
* @param string|null $alias Alias of the user.
|
||||
*/
|
||||
public function __construct(
|
||||
public int $userId,
|
||||
#[ArrayOf(ChatAdminPermission::class)]
|
||||
public array $permissions,
|
||||
public ?string $alias = null,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ final readonly class ChatMember extends AbstractModel
|
||||
* @param bool $isAdmin True if this member is an administrator of the chat.
|
||||
* @param int $joinTime The time the user joined the chat.
|
||||
* @param ChatAdminPermission[]|null $permissions A list of permissions if the member is an admin, otherwise null.
|
||||
* @param string|null $alias Alias of the user.
|
||||
*/
|
||||
public function __construct(
|
||||
public int $userId,
|
||||
@@ -44,6 +45,7 @@ final readonly class ChatMember extends AbstractModel
|
||||
public int $joinTime,
|
||||
#[ArrayOf(ChatAdminPermission::class)]
|
||||
public ?array $permissions,
|
||||
public ?string $alias,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1671,8 +1671,8 @@ final class ApiTest extends TestCase
|
||||
|
||||
$expectedBody = [
|
||||
'admins' => [
|
||||
['user_id' => 101, 'permissions' => ['write']],
|
||||
['user_id' => 202, 'permissions' => ['pin_message']],
|
||||
['user_id' => 101, 'permissions' => ['write'], 'alias' => null],
|
||||
['user_id' => 202, 'permissions' => ['pin_message'], 'alias' => null],
|
||||
],
|
||||
];
|
||||
$rawResponse = ['success' => true];
|
||||
|
||||
@@ -458,6 +458,7 @@ final class ModelFactoryTest extends TestCase
|
||||
'is_admin' => true,
|
||||
'join_time' => 1678000000,
|
||||
'permissions' => ['pin_message', 'write'],
|
||||
'alias' => null,
|
||||
];
|
||||
|
||||
$chatMember = $this->factory->createChatMember($rawData);
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Buttons\Inline;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\InlineButtonType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\MessageButton;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(MessageButton::class)]
|
||||
final class MessageButtonTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function toArraySerializesCorrectly(): void
|
||||
{
|
||||
$button = new MessageButton('Test Button');
|
||||
|
||||
$expectedArray = [
|
||||
'type' => InlineButtonType::Message->value,
|
||||
'text' => 'Test Button',
|
||||
];
|
||||
|
||||
$resultArray = $button->toArray();
|
||||
|
||||
$this->assertSame($expectedArray, $resultArray);
|
||||
}
|
||||
}
|
||||
@@ -58,4 +58,11 @@ final class BotPatchTest extends TestCase
|
||||
$patch = new BotPatch();
|
||||
$this->assertEmpty($patch->toArray());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function toArrayFirstAndLastName(): void
|
||||
{
|
||||
$patch = new BotPatch(first_name: 'New Name', last_name: null);
|
||||
$this->assertEquals(['first_name' => 'New Name', 'last_name' => null], $patch->toArray());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ final class ChatAdminTest extends TestCase
|
||||
$expected = [
|
||||
'user_id' => 123,
|
||||
'permissions' => ['write', 'pin_message'],
|
||||
'alias' => null,
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $admin->toArray());
|
||||
|
||||
@@ -34,6 +34,7 @@ final class ChatMemberTest extends TestCase
|
||||
'is_admin' => true,
|
||||
'join_time' => 1678000000,
|
||||
'permissions' => ['pin_message', 'write'],
|
||||
'alias' => null,
|
||||
];
|
||||
|
||||
$member = ChatMember::fromArray($data);
|
||||
@@ -66,6 +67,7 @@ final class ChatMemberTest extends TestCase
|
||||
'is_admin' => false,
|
||||
'join_time' => 1678000001,
|
||||
'permissions' => null,
|
||||
'alias' => null,
|
||||
];
|
||||
|
||||
$member = ChatMember::fromArray($data);
|
||||
|
||||
@@ -48,6 +48,10 @@ final class ChatTest extends TestCase
|
||||
],
|
||||
'messages_count' => 100,
|
||||
'chat_message_id' => 'mid.123',
|
||||
'participants' => [
|
||||
'456' => 1678886400000,
|
||||
'789' => 1678886500000,
|
||||
],
|
||||
];
|
||||
|
||||
$chat = Chat::fromArray($data);
|
||||
@@ -99,5 +103,6 @@ final class ChatTest extends TestCase
|
||||
$this->assertNull($chat->dialogWithUser);
|
||||
$this->assertNull($chat->messagesCount);
|
||||
$this->assertNull($chat->chatMessageId);
|
||||
$this->assertNull($chat->participants);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user