Skip to content
This repository has been archived by the owner on Sep 7, 2022. It is now read-only.

Commit

Permalink
Updated to Telegram Bot API 5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasss93 committed Mar 9, 2021
1 parent da52357 commit ac824b5
Show file tree
Hide file tree
Showing 13 changed files with 327 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## v1.12 - 2021-03-10
### Changed
- Updated to Telegram Bot API 5.1

## v1.11 - 2020-11-10
### Changed
- Updated to Telegram Bot API 5.0
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,6 @@ Changelog
All notable changes to this project will be documented [here](https://github.com/Lukasss93/telegrambot-php/blob/master/CHANGELOG.md).

### Recent changes
## v1.11 - 2020-11-10
## v1.12 - 2021-03-10
### Changed
- Updated to Telegram Bot API 5.0
- Updated to Telegram Bot API 5.1
1 change: 1 addition & 0 deletions src/Constants/Emojis.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ class Emojis
public const BASKETBALL = '🏀';
public const FOOTBALL = '';
public const SLOT = '🎰';
public const BOWLING = '🎳';
}
115 changes: 112 additions & 3 deletions src/TelegramBot.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use ReflectionClass;
use TelegramBot\Types\BotCommand;
use TelegramBot\Types\Chat;
use TelegramBot\Types\ChatInviteLink;
use TelegramBot\Types\ChatMember;
use TelegramBot\Types\ChatPermissions;
use TelegramBot\Types\File;
Expand Down Expand Up @@ -654,7 +655,7 @@ public function getFile(string $file_id): File
$object = $this->mapper->map($response->result, new File());
return $object;
}

/**
* Use this method to kick a user from a group or a supergroup.
* In the case of supergroups, the user will not be able to return to the group
Expand All @@ -664,13 +665,17 @@ public function getFile(string $file_id): File
* Otherwise members may only be removed by the group's creator or by the member that added them.
* @param int|string $chat_id
* @param int $user_id
* @param ?int $until_date Date when the user will be unbanned, unix time.
* @param ?int $until_date Optional. Date when the user will be unbanned, unix time.
* If user is banned for more than 366 days or less than 30 seconds
* from the current time they are considered to be banned forever
* @param bool|null $revoke_messages Optional. Pass True to delete all messages from the chat
* for the user that is being removed.
* If False, the user will be able to see messages in the group that were
* sent before the user was removed. Always True for supergroups and channels.
* @return bool
* @throws TelegramException
*/
public function kickChatMember($chat_id, int $user_id, $until_date = null): bool
public function kickChatMember($chat_id, int $user_id, int $until_date = null, bool $revoke_messages=null): bool
{
$options = [
'chat_id' => $chat_id,
Expand All @@ -680,6 +685,10 @@ public function kickChatMember($chat_id, int $user_id, $until_date = null): bool
if ($until_date !== null) {
$options['until_date'] = $until_date;
}

if ($revoke_messages !== null) {
$options['revoke_messages'] = $revoke_messages;
}

$response = $this->endpoint('kickChatMember', $options);

Expand Down Expand Up @@ -828,6 +837,106 @@ public function exportChatInviteLink($chat_id): string
$object = $response->result;
return $object;
}

/**
* Use this method to create an additional invite link for a chat.
* The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
* The link can be revoked using the method
* {@see https://core.telegram.org/bots/api#revokechatinvitelink revokeChatInviteLink}.
* Returns the new invite link as {@see https://core.telegram.org/bots/api#chatinvitelink ChatInviteLink} object.
* @param int|string $chat_id Unique identifier for the target chat or username of the target channel (in the
* format @channelusername)
* @param int|null $expire_date Optional. Point in time (Unix timestamp) when the link will expire
* @param int|null $member_limit Optional. Maximum number of users that can be members of the chat simultaneously
* after joining the chat via this invite link; 1-99999
* @return ChatInviteLink
* @throws TelegramException
* @see https://core.telegram.org/bots/api#createchatinvitelink
*/
public function createChatInviteLink($chat_id, int $expire_date=null, int $member_limit=null): ChatInviteLink
{
$options=[
'chat_id' => $chat_id,
];

if($expire_date!==null){
$options['expire_date']=$expire_date;
}

if($member_limit!==null){
$options['member_limit']=$expire_date;
}

$response = $this->endpoint('createChatInviteLink', $options);

/** @var ChatInviteLink $object */
$object = $this->mapper->map($response->result, new ChatInviteLink());
return $object;
}

/**
* Use this method to edit a non-primary invite link created by the bot.
* The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
* Returns the edited invite link as a
* {@see https://core.telegram.org/bots/api#chatinvitelink ChatInviteLink} object.
* @param int|string $chat_id Unique identifier for the target chat or username of the target channel (in the
* format @channelusername)
* @param string $invite_link The invite link to edit
* @param int|null $expire_date Optional. Point in time (Unix timestamp) when the link will expire
* @param int|null $member_limit Optional. Maximum number of users that can be members of the chat simultaneously
* after joining the chat via this invite link; 1-99999
* @return ChatInviteLink
* @throws JsonMapper_Exception
* @throws TelegramException
* @see https://core.telegram.org/bots/api#editchatinvitelink
*/
public function editChatInviteLink($chat_id, string $invite_link, int $expire_date=null, int $member_limit=null): ChatInviteLink
{
$options=[
'chat_id' => $chat_id,
'invite_link'=>$invite_link,
];

if($expire_date!==null){
$options['expire_date']=$expire_date;
}

if($member_limit!==null){
$options['member_limit']=$expire_date;
}

$response = $this->endpoint('editChatInviteLink', $options);

/** @var ChatInviteLink $object */
$object = $this->mapper->map($response->result, new ChatInviteLink());
return $object;
}

/**
* Use this method to revoke an invite link created by the bot. If the primary link is revoked,
* a new link is automatically generated.
* The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
* Returns the revoked invite link as
* {@see https://core.telegram.org/bots/api#chatinvitelink ChatInviteLink} object.
* @param int|string $chat_id Unique identifier for the target chat or username of the target channel (in the
* format @channelusername)
* @param string $invite_link The invite link to edit
* @return ChatInviteLink
* @throws JsonMapper_Exception
* @throws TelegramException
* @see https://core.telegram.org/bots/api#revokechatinvitelink
*/
public function revokeChatInviteLink($chat_id, string $invite_link): ChatInviteLink
{
$response = $this->endpoint('revokeChatInviteLink', [
'chat_id' => $chat_id,
'invite_link'=>$invite_link,
]);

/** @var ChatInviteLink $object */
$object = $this->mapper->map($response->result, new ChatInviteLink());
return $object;
}

/**
* Use this method to set a new profile photo for the chat. Photos can't be changed for private chats.
Expand Down
48 changes: 48 additions & 0 deletions src/Types/ChatInviteLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace TelegramBot\Types;

/**
* Represents an invite link for a chat.
* @see https://core.telegram.org/bots/api#chatinvitelink
*/
class ChatInviteLink
{
/**
* 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 $invite_link
*/
public $invite_link;

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

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

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

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

/**
* Optional. Maximum number of users that can be members of the chat simultaneously
* after joining the chat via this invite link; 1-99999
* @var int $member_limit
*/
public $member_limit;
}
15 changes: 15 additions & 0 deletions src/Types/ChatMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ class ChatMember
* @var bool $can_be_edited
*/
public $can_be_edited;

/**
* Optional. Administrators only.
* True, if the administrator can access the chat event log, chat statistics, message statistics in channels,
* see channel members, see anonymous administrators in supergroups and ignore slow mode.
* Implied by any other administrator privilege
* @var bool $can_manage_chat
*/
public $can_manage_chat;

/**
* Optional. Administrators only. True, if the administrator can post in the channel, channels only
Expand All @@ -55,6 +64,12 @@ class ChatMember
* @var bool $can_delete_messages
*/
public $can_delete_messages;

/**
* Optional. Administrators only. True, if the administrator can manage voice chats
* @var bool $can_manage_voice_chats
*/
public $can_manage_voice_chats;

/**
* Optional. Administrators only. True, if the administrator can restrict, ban or unban chat members
Expand Down
46 changes: 46 additions & 0 deletions src/Types/ChatMemberUpdated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace TelegramBot\Types;

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

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

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

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

/**
* New information about the chat member
* @var ChatMember $new_chat_member
*/
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 $invite_link
*/
public $invite_link;
}
26 changes: 25 additions & 1 deletion src/Types/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,12 @@ class Message
* @var bool $channel_chat_created
*/
public $channel_chat_created;

/**
* Optional. Service message: auto-delete timer settings changed in the chat
* @var MessageAutoDeleteTimerChanged $message_auto_delete_timer_changed
*/
public $message_auto_delete_timer_changed;

/**
* Optional. The group has been migrated to a supergroup with the specified identifier.
Expand Down Expand Up @@ -342,7 +348,25 @@ class Message
* @var ProximityAlertTriggered $proximity_alert_triggered
*/
public $proximity_alert_triggered;


/**
* Optional. Service message: voice chat started
* @var VoiceChatStarted $voice_chat_started
*/
public $voice_chat_started;

/**
* Optional. Service message: voice chat ended
* @var VoiceChatEnded $voice_chat_ended
*/
public $voice_chat_ended;

/**
* Optional. Service message: new participants invited to a voice chat
* @var VoiceChatParticipantsInvited $voice_chat_participants_invited
*/
public $voice_chat_participants_invited;

/**
* Optional. Optional. Inline keyboard attached to the message.
* "login_url" buttons are represented as ordinary "url" buttons.
Expand Down
16 changes: 16 additions & 0 deletions src/Types/MessageAutoDeleteTimerChanged.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace TelegramBot\Types;

/**
* This object represents a service message about a change in auto-delete timer settings.
* @see https://core.telegram.org/bots/api#voicechatended
*/
class MessageAutoDeleteTimerChanged
{
/**
* New auto-delete time for messages in the chat
* @var int $message_auto_delete_time
*/
public $message_auto_delete_time;
}
14 changes: 14 additions & 0 deletions src/Types/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ class Update
*/
public $poll_answer;

/**
* Optional. The bot's chat member status was updated in a chat.
* For private chats, this update is received only when the bot is blocked or unblocked by the user.
* @var ChatMemberUpdated $my_chat_member
*/
public $my_chat_member;

/**
* Optional. A chat member's status was updated in a chat. The bot must be an administrator in the chat and must
* explicitly specify “chat_member” in the list of allowed_updates to receive these updates.
* @var ChatMemberUpdated $chat_member
*/
public $chat_member;

/**
* Return the current update type
* @return bool|string
Expand Down
Loading

0 comments on commit ac824b5

Please sign in to comment.