Skip to content

Commit

Permalink
Merge pull request #153 from DJTommek/pr/api-type-updates
Browse files Browse the repository at this point in the history
TelegramTypes updates
  • Loading branch information
unreal4u authored Sep 17, 2023
2 parents b0f7eff + d453691 commit dba9442
Show file tree
Hide file tree
Showing 7 changed files with 368 additions and 7 deletions.
81 changes: 81 additions & 0 deletions src/Telegram/Types/ChatInviteLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

declare(strict_types=1);

namespace unreal4u\TelegramAPI\Telegram\Types;

use unreal4u\TelegramAPI\Abstracts\TelegramTypes;

/**
* Represents an invite link for a chat.
*
* @see https://core.telegram.org/bots/api#chatinvitelink
*/
class ChatInviteLink extends TelegramTypes
{
/**
* The invite link. If the link was created by another chat administrator, then the second part of the link will be
* replaced with “…”.
* @var string
*/
public $invite_link;

/**
* Creator of the link
* @var User
*/
public $creator;

/**
* True, if users joining the chat via the link need to be approved by chat administrators
* @var bool
*/
public $creates_join_request = false;

/**
* True, if the link is primary
* @var bool
*/
public $is_primary = false;

/**
* True, if the link is revoked
* @var bool
*/
public $is_revoked = false;

/**
* Optional. Invite link name
* @var string
*/
public $name;

/**
* Optional. Point in time (Unix timestamp) when the link will expire or has been expired
* @var int
*/
public $expire_date;

/**
* Optional. The maximum number of users that can be members of the chat simultaneously after joining the chat via
* this invite link; 1-99999
* @var int
*/
public $member_limit;

/**
* Optional. Number of pending join requests created using this link
* @var int
*/
public $pending_join_request_count;

public function mapSubObjects(string $key, array $data): TelegramTypes
{
switch ($key) {
case 'creator':
return new User($data, $this->logger);
}

return parent::mapSubObjects($key, $data);
}
}
73 changes: 73 additions & 0 deletions src/Telegram/Types/ChatJoinRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

declare(strict_types=1);

namespace unreal4u\TelegramAPI\Telegram\Types;

use unreal4u\TelegramAPI\Abstracts\TelegramTypes;

/**
* Represents a join request sent to a chat.
*
* @see https://core.telegram.org/bots/api#chatjoinrequest
*/
class ChatJoinRequest extends TelegramTypes
{
/**
* Chat to which the request was sent
*
* @var Chat
*/
public $chat;

/**
* User that sent the join request
*
* @var User
*/
public $from;

/**
* Identifier of a private chat with the user who sent the join request. The bot can use this identifier
* for 24 hours to send messages until the join request is processed, assuming no other administrator contacted
* the user.
*
* @var int
*/
public $user_chat_id;

/**
* Date the request was sent in Unix time
*
* @var int
*/
public $date;

/**
* Optional. Bio of the user.
*
* @var string
*/
public $bio;

/**
* Optional. Chat invite link that was used by the user to send the join request
*
* @var ChatInviteLink
*/
public $invite_link;

public function mapSubObjects(string $key, array $data): TelegramTypes
{
switch ($key) {
case 'chat':
return new Chat($data, $this->logger);
case 'from':
return new User($data, $this->logger);
case 'invite_link':
return new ChatInviteLink($data, $this->logger);
}

return parent::mapSubObjects($key, $data);
}
}
74 changes: 74 additions & 0 deletions src/Telegram/Types/ChatMemberUpdated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

declare(strict_types=1);

namespace unreal4u\TelegramAPI\Telegram\Types;

use unreal4u\TelegramAPI\Abstracts\TelegramTypes;

/**
* This object represents changes in the status of a chat member.
*
* @see https://core.telegram.org/bots/api#chatmemberupdated
*/
class ChatMemberUpdated extends TelegramTypes
{
/**
* Chat the user belongs to
* @var Chat
*/
public $chat;

/**
* Performer of the action, which resulted in the change
* @var User
*/
public $from;

/**
* Date the change was done in Unix time
* @var int
*/
public $date;

/**
* Previous information about the chat member
* @var ChatMember
*/
public $old_chat_member;

/**
* New information about the chat member
* @var ChatMember
*/
public $new_chat_member;

/**
* Optional. Chat invite link, which was used by the user to join the chat; for joining by invite link events only.
* @var ChatInviteLink
*/
public $invite_link;

/**
* Optional. True, if the user joined the chat via a chat folder invite link
* @var bool
*/
public $via_chat_folder_invite_link;

public function mapSubObjects(string $key, array $data): TelegramTypes
{
switch ($key) {
case 'chat':
return new Chat($data, $this->logger);
case 'from':
return new User($data, $this->logger);
case 'old_chat_member':
case 'new_chat_member':
return new ChatMember($data, $this->logger);
case 'invite_link':
return new ChatInviteLink($data, $this->logger);
}

return parent::mapSubObjects($key, $data);
}
}
53 changes: 52 additions & 1 deletion src/Telegram/Types/ChatPermissions.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace unreal4u\TelegramAPI\Telegram\Types;

Expand All @@ -27,9 +27,52 @@ class ChatPermissions extends TelegramTypes
* implies can_send_messages
*
* @var bool
* @deprecated Use more granual permissions instead (Bot API 6.5, February 3, 2023 https://core.telegram.org/bots/api-changelog#february-3-2023)
*/
public $can_send_media_messages;

/**
* Optional. True, if the user is allowed to send audios
*
* @var bool
*/
public $can_send_audios;

/**
* Optional. True, if the user is allowed to send documents
*
* @var bool
*/
public $can_send_documents;

/**
* Optional. True, if the user is allowed to send photos
*
* @var bool
*/
public $can_send_photos;

/**
* Optional. True, if the user is allowed to send videos
*
* @var bool
*/
public $can_send_videos;

/**
* Optional. True, if the user is allowed to send video notes
*
* @var bool
*/
public $can_send_video_notes;

/**
* Optional. True, if the user is allowed to send voice notes
*
* @var bool
*/
public $can_send_voice_notes;

/**
* Optional. True, if the user is allowed to send polls, implies can_send_messages
*
Expand Down Expand Up @@ -74,4 +117,12 @@ class ChatPermissions extends TelegramTypes
* @var bool
*/
public $can_pin_messages;

/**
* Optional. True, if the user is allowed to create forum topics. If omitted defaults to the
* value of can_pin_messages
*
* @var bool
*/
public $can_manage_topics;
}
41 changes: 40 additions & 1 deletion src/Telegram/Types/Sticker.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
*/
class Sticker extends TelegramTypes
{
public const TYPE_REGULAR = 'regular';
public const TYPE_MASK = 'mask';
public const TYPE_CUSTOM_EMOJI = 'custom_emoji';

/**
* Unique identifier for this file
* Identifier for this file, which can be used to download or reuse the file
* @var string
*/
public $file_id = '';
Expand All @@ -29,6 +33,14 @@ class Sticker extends TelegramTypes
*/
public $file_unique_id = '';

/**
* Type of the sticker, currently one of “regular”, “mask”, “custom_emoji”. The type of the sticker is independent
* from its format, which is determined by the fields is_animated and is_video.
*
* @var string
*/
public $type = '';

/**
* Photo width
* @var int
Expand All @@ -49,6 +61,14 @@ class Sticker extends TelegramTypes
*/
public $is_animated = false;

/**
* True, if the sticker is video sticker
* @see https://telegram.org/blog/video-stickers-better-reactions
*
* @var bool
*/
public $is_video = false;

/**
* Optional. Sticker thumbnail in .webp or .jpg format
* @var PhotoSize
Expand All @@ -73,12 +93,31 @@ class Sticker extends TelegramTypes
*/
public $set_name = '';

/**
* Optional. For premium regular stickers, premium animation for the sticker
* @var File
*/
public $premium_animation = '';

/**
* Optional. For mask stickers, the position where the mask should be placed
* @var MaskPosition
*/
public $mask_position;

/**
* Optional. For custom emoji stickers, unique identifier of the custom emoji
* @var string
*/
public $custom_emoji_id = '';

/**
* Optional. True, if the sticker must be repainted to a text color in messages, the color of the Telegram Premium
* badge in emoji status, white color on chat photos, or another appropriate color in other places
* @var bool
*/
public $needs_repainting = false;

/**
* Optional. File size
* @var int
Expand Down
Loading

0 comments on commit dba9442

Please sign in to comment.