Added getSubscriptions method

This commit is contained in:
Alex
2025-07-07 21:05:18 +03:00
parent f3a7b2b3ba
commit 45020eab52
6 changed files with 148 additions and 15 deletions
+11 -11
View File
@@ -5,21 +5,21 @@ declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Models;
/**
* Information about the current bot, which is identified using an access token.
* Information about the current bot.
*/
final readonly class BotInfo extends AbstractModel
{
/**
* @param int $user_id ID user
* @param string $first_name User display name
* @param string|null $last_name User's display last name
* @param string|null $username Unique public name of the user, may be null if the user is not available or no name is set
* @param bool $is_bot Is the user a bot
* @param int $last_activity_time User last activity time in MAX (Unix time in milliseconds). May be irrelevant if the user has disabled the "online" status in the settings
* @param string|null $description User description, may be null if the user has not filled it in (up to 16000 characters)
* @param string|null $avatar_url Avatar URL
* @param string|null $full_avatar_url Larger Avatar URL
* @param BotCommand[]|null $commands Commands supported by the bot (up to 32 elements)
* @param int $user_id ID user.
* @param string $first_name User display name.
* @param string|null $last_name User's display last name.
* @param string|null $username Unique public name of the user, may be null if the user is not available or no name is set.
* @param bool $is_bot Is the user a bot.
* @param int $last_activity_time User last activity time in MAX (Unix time in milliseconds). May be irrelevant if the user has disabled the "online" status in the settings.
* @param string|null $description User description, may be null if the user has not filled it in (up to 16000 characters).
* @param string|null $avatar_url Avatar URL.
* @param string|null $full_avatar_url Larger Avatar URL.
* @param BotCommand[]|null $commands Commands supported by the bot (up to 32 elements).
*/
public function __construct(
public int $user_id,
+48
View File
@@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Models;
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
/**
* Information about webhook subscriptions.
*/
final readonly class Subscription extends AbstractModel
{
/**
* @param string $url URL webhook.
* @param int $time Unix-time of creating a subscription.
* @param UpdateType[]|null $update_types List of update types.
* @param string|null $version Version of the API.
*/
public function __construct(
public string $url,
public int $time,
public ?array $update_types,
public ?string $version,
) {
}
/**
* @inheritdoc
*/
public static function fromArray(array $data): static
{
$updateTypes = null;
if (isset($data['update_types']) && is_array($data['update_types'])) {
$updateTypes = array_map(
fn (string $typeValue): UpdateType => UpdateType::from($typeValue),
$data['update_types'],
);
}
return new static(
(string)$data['url'],
(int)$data['time'],
$updateTypes,
$data['version'] ?? null,
);
}
}