Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4656,4 +4656,4 @@
}
}
}
}
}
1 change: 1 addition & 0 deletions src/Enums/ChatAdminPermission.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ enum ChatAdminPermission: string
case ChangeChatInfo = 'change_chat_info';
case PinMessage = 'pin_message';
case Write = 'write';
case EditLink = 'edit_link';
}
2 changes: 2 additions & 0 deletions src/ModelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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;
Expand Down Expand Up @@ -311,6 +312,7 @@ public function createInlineButton(array $data): AbstractInlineButton
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')
),
Expand Down
2 changes: 1 addition & 1 deletion src/Models/User.php → src/Models/AbstractUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace BushlanovDev\MaxMessengerBot\Models;

final readonly class User extends AbstractModel
abstract readonly class AbstractUser extends AbstractModel
{
/**
* @param int $userId Users identifier.
Expand Down
21 changes: 21 additions & 0 deletions src/Models/Attachments/Buttons/Inline/MessageButton.php
Original file line number Diff line number Diff line change
@@ -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);
}
}
6 changes: 3 additions & 3 deletions src/Models/Attachments/Payloads/ContactAttachmentPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads;

use BushlanovDev\MaxMessengerBot\Models\AbstractModel;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;

/**
* Payload of a contact attachment.
Expand All @@ -14,11 +14,11 @@
{
/**
* @param string|null $vcfInfo User info in VCF format.
* @param User|null $maxInfo User info if the contact is a Max user.
* @param UserWithPhoto|null $maxInfo User info if the contact is a Max user.
*/
public function __construct(
public ?string $vcfInfo,
public ?User $maxInfo,
public ?UserWithPhoto $maxInfo,
) {
}
}
15 changes: 8 additions & 7 deletions src/Models/BotInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* Information about the current bot.
*/
final readonly class BotInfo extends AbstractModel
final readonly class BotInfo extends AbstractUser
{
/**
* @param int $userId ID user.
Expand All @@ -24,17 +24,18 @@
* @param BotCommand[]|null $commands Commands supported by the bot (up to 32 elements).
*/
public function __construct(
public int $userId,
public string $firstName,
public ?string $lastName,
public ?string $username,
public bool $isBot,
public int $lastActivityTime,
int $userId,
string $firstName,
?string $lastName,
?string $username,
bool $isBot,
int $lastActivityTime,
public ?string $description,
public ?string $avatarUrl,
public ?string $fullAvatarUrl,
#[ArrayOf(BotCommand::class)]
public ?array $commands,
) {
parent::__construct($userId, $firstName, $lastName, $username, $isBot, $lastActivityTime);
}
}
6 changes: 4 additions & 2 deletions src/Models/BotPatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
/**
* 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
{
Expand Down
4 changes: 2 additions & 2 deletions src/Models/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
* @param int $timestamp Unix-time when user pressed the button.
* @param string $callbackId Identifier of the callback, unique for the message.
* @param string $payload Payload from the pressed button.
* @param User $user User who pressed the button.
* @param UserWithPhoto $user User who pressed the button.
*/
public function __construct(
public int $timestamp,
public string $callbackId,
public string $payload,
public User $user,
public UserWithPhoto $user,
) {
}
}
2 changes: 2 additions & 0 deletions src/Models/Chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* @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,
Expand All @@ -45,6 +46,7 @@ public function __construct(
public ?int $messagesCount,
public ?string $chatMessageId,
public ?Message $pinnedMessage,
public ?array $participants,
) {
}
}
2 changes: 2 additions & 0 deletions src/Models/ChatAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
/**
* @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,
) {
}
}
17 changes: 10 additions & 7 deletions src/Models/ChatMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Represents a member of a chat, including their user information and chat-specific status.
*/
final readonly class ChatMember extends AbstractModel
final readonly class ChatMember extends AbstractUser
{
/**
* @param int $userId User's identifier.
Expand All @@ -27,14 +27,15 @@
* @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,
public string $firstName,
public ?string $lastName,
public ?string $username,
public bool $isBot,
public int $lastActivityTime,
int $userId,
string $firstName,
?string $lastName,
?string $username,
bool $isBot,
int $lastActivityTime,
public ?string $description,
public ?string $avatarUrl,
public ?string $fullAvatarUrl,
Expand All @@ -44,6 +45,8 @@ public function __construct(
public int $joinTime,
#[ArrayOf(ChatAdminPermission::class)]
public ?array $permissions,
public ?string $alias,
) {
parent::__construct($userId, $firstName, $lastName, $username, $isBot, $lastActivityTime);
}
}
4 changes: 2 additions & 2 deletions src/Models/LinkedMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
/**
* @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 UserWithPhoto|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 ?UserWithPhoto $sender,
public ?int $chatId,
) {
}
Expand Down
4 changes: 2 additions & 2 deletions src/Models/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @param int $timestamp Unix-time when message was created.
* @param Recipient $recipient Message recipient. Could be user or chat.
* @param MessageBody|null $body Body of created message. Text + attachments.
* @param User|null $sender User who sent this message. Can be null if message has been posted on behalf of a channel.
* @param UserWithPhoto|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.
Expand All @@ -25,7 +25,7 @@ public function __construct(
public int $timestamp,
public Recipient $recipient,
public ?MessageBody $body,
public ?User $sender,
public ?UserWithPhoto $sender,
public ?string $url,
public ?LinkedMessage $link,
public ?MessageStat $stat,
Expand Down
6 changes: 3 additions & 3 deletions src/Models/Updates/BotAddedToChatUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace BushlanovDev\MaxMessengerBot\Models\Updates;

use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;

/**
* You will receive this update when the bot has been added to a chat.
Expand All @@ -15,13 +15,13 @@
/**
* @param int $timestamp Unix-time when the event has occurred.
* @param int $chatId Chat ID where the bot was added.
* @param User $user User who added the bot to the chat.
* @param UserWithPhoto $user User who added the bot to the chat.
* @param bool $isChannel Indicates whether the bot has been added to a channel or not.
*/
public function __construct(
int $timestamp,
public int $chatId,
public User $user,
public UserWithPhoto $user,
public bool $isChannel,
) {
parent::__construct(UpdateType::BotAdded, $timestamp);
Expand Down
6 changes: 3 additions & 3 deletions src/Models/Updates/BotRemovedFromChatUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace BushlanovDev\MaxMessengerBot\Models\Updates;

use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;

/**
* You will receive this update when the bot has been removed from a chat.
Expand All @@ -15,13 +15,13 @@
/**
* @param int $timestamp Unix-time when the event has occurred.
* @param int $chatId Chat identifier the bot was removed from.
* @param User $user User who removed the bot from the chat.
* @param UserWithPhoto $user User who removed the bot from the chat.
* @param bool $isChannel Indicates whether the bot has been removed from a channel or not.
*/
public function __construct(
int $timestamp,
public int $chatId,
public User $user,
public UserWithPhoto $user,
public bool $isChannel,
) {
parent::__construct(UpdateType::BotRemoved, $timestamp);
Expand Down
6 changes: 3 additions & 3 deletions src/Models/Updates/BotStartedUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace BushlanovDev\MaxMessengerBot\Models\Updates;

use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;

/**
* Bot gets this type of update as soon as user pressed `Start` button.
Expand All @@ -15,14 +15,14 @@
/**
* @param int $timestamp Unix-time when event has occurred.
* @param int $chatId Dialog identifier where event has occurred.
* @param User $user User pressed the 'Start' button.
* @param UserWithPhoto $user User pressed the 'Start' button.
* @param string|null $payload Additional data from deep-link passed on bot startup.
* @param string|null $userLocale Current user locale in IETF BCP 47 format.
*/
public function __construct(
int $timestamp,
public int $chatId,
public User $user,
public UserWithPhoto $user,
public ?string $payload,
public ?string $userLocale,
) {
Expand Down
6 changes: 3 additions & 3 deletions src/Models/Updates/BotStoppedUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace BushlanovDev\MaxMessengerBot\Models\Updates;

use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;

/**
* The bot receives this type of update as soon as the user stops the bot.
Expand All @@ -15,13 +15,13 @@
/**
* @param int $timestamp Unix-time when event has occurred.
* @param int $chatId Dialog identifier where event has occurred.
* @param User $user User pressed the 'Start' button.
* @param UserWithPhoto $user User pressed the 'Start' button.
* @param string|null $userLocale Current user locale in IETF BCP 47 format.
*/
public function __construct(
int $timestamp,
public int $chatId,
public User $user,
public UserWithPhoto $user,
public ?string $userLocale,
) {
parent::__construct(UpdateType::BotStopped, $timestamp);
Expand Down
6 changes: 3 additions & 3 deletions src/Models/Updates/ChatTitleChangedUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace BushlanovDev\MaxMessengerBot\Models\Updates;

use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;

/**
* Bot gets this type of update as soon as the title has been changed in a chat.
Expand All @@ -15,13 +15,13 @@
/**
* @param int $timestamp Unix-time when the event has occurred.
* @param int $chatId Chat identifier where the event has occurred.
* @param User $user User who changed the title.
* @param UserWithPhoto $user User who changed the title.
* @param string $title The new title.
*/
public function __construct(
int $timestamp,
public int $chatId,
public User $user,
public UserWithPhoto $user,
public string $title,
) {
parent::__construct(UpdateType::ChatTitleChanged, $timestamp);
Expand Down
Loading