Skip to content

Commit 1c6c9aa

Browse files
committed
Merge branch 'api-6.0' into develop
2 parents ab14185 + 27cc26c commit 1c6c9aa

33 files changed

+456
-61
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
77
### Notes
88
- [:ledger: View file changes][Unreleased]
99
### Added
10+
- Bot API 6.0 See https://core.telegram.org/bots/api#april-16-2022 (@TiiFuchs)
1011
### Changed
1112
### Deprecated
13+
- Telegram changed voice_chat_scheduled, voice_chat_started, voice_chat_ended and voice_chat_participants_invited to video_chat_scheduled, video_chat_started, video_chat_ended and video_chat_participants_invited.
14+
To reflect that change we marked the corresponding VoiceChat classes as deprecated and created new classes for the VideoChat events.
1215
### Removed
1316
### Fixed
1417
### Security

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
A Telegram Bot based on the official [Telegram Bot API]
99

10-
[![API Version](https://img.shields.io/badge/Bot%20API-5.7%20%28January%202022%29-32a2da.svg)](https://core.telegram.org/bots/api#january-31-2022)
10+
[![API Version](https://img.shields.io/badge/Bot%20API-6.0%20%28April%202022%29-32a2da.svg)](https://core.telegram.org/bots/api#april-16-2022)
1111
[![Join the bot support group on Telegram](https://img.shields.io/badge/telegram-@PHP__Telegram__Bot__Support-64659d.svg)](https://telegram.me/PHP_Telegram_Bot_Support)
1212
[![Donate](https://img.shields.io/badge/%F0%9F%92%99-Donate%20%2F%20Support%20Us-blue.svg)](#donate)
1313

@@ -78,7 +78,7 @@ This Bot aims to provide a platform where one can simply write a bot and have in
7878

7979
The Bot can:
8080
- Retrieve updates with [webhook](#webhook-installation) and [getUpdates](#getupdates-installation) methods.
81-
- Supports all types and methods according to Telegram Bot API 5.7 (January 2022).
81+
- Supports all types and methods according to Telegram Bot API 6.0 (April 2022).
8282
- Supports supergroups.
8383
- Handle commands in chat with other bots.
8484
- Manage Channel from the bot admin interface.

src/DB.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ public static function insertMessageRequest(Message $message): bool
11371137
`new_chat_title`, `new_chat_photo`, `delete_chat_photo`, `group_chat_created`,
11381138
`supergroup_chat_created`, `channel_chat_created`, `message_auto_delete_timer_changed`, `migrate_to_chat_id`, `migrate_from_chat_id`,
11391139
`pinned_message`, `invoice`, `successful_payment`, `connected_website`, `passport_data`, `proximity_alert_triggered`,
1140-
`voice_chat_scheduled`, `voice_chat_started`, `voice_chat_ended`, `voice_chat_participants_invited`, `reply_markup`
1140+
`video_chat_scheduled`, `video_chat_started`, `video_chat_ended`, `video_chat_participants_invited`, `web_app_data`, `reply_markup`
11411141
) VALUES (
11421142
:message_id, :user_id, :chat_id, :sender_chat_id, :date, :forward_from, :forward_from_chat, :forward_from_message_id,
11431143
:forward_signature, :forward_sender_name, :forward_date,
@@ -1147,7 +1147,7 @@ public static function insertMessageRequest(Message $message): bool
11471147
:new_chat_title, :new_chat_photo, :delete_chat_photo, :group_chat_created,
11481148
:supergroup_chat_created, :channel_chat_created, :message_auto_delete_timer_changed, :migrate_to_chat_id, :migrate_from_chat_id,
11491149
:pinned_message, :invoice, :successful_payment, :connected_website, :passport_data, :proximity_alert_triggered,
1150-
:voice_chat_scheduled, :voice_chat_started, :voice_chat_ended, :voice_chat_participants_invited, :reply_markup
1150+
:video_chat_scheduled, :video_chat_started, :video_chat_ended, :video_chat_participants_invited, :web_app_data, :reply_markup
11511151
)
11521152
');
11531153

@@ -1220,10 +1220,11 @@ public static function insertMessageRequest(Message $message): bool
12201220
$sth->bindValue(':connected_website', $message->getConnectedWebsite());
12211221
$sth->bindValue(':passport_data', $message->getPassportData());
12221222
$sth->bindValue(':proximity_alert_triggered', $message->getProximityAlertTriggered());
1223-
$sth->bindValue(':voice_chat_scheduled', $message->getVoiceChatScheduled());
1224-
$sth->bindValue(':voice_chat_started', $message->getVoiceChatStarted());
1225-
$sth->bindValue(':voice_chat_ended', $message->getVoiceChatEnded());
1226-
$sth->bindValue(':voice_chat_participants_invited', $message->getVoiceChatParticipantsInvited());
1223+
$sth->bindValue(':video_chat_scheduled', $message->getVideoChatScheduled());
1224+
$sth->bindValue(':video_chat_started', $message->getVideoChatStarted());
1225+
$sth->bindValue(':video_chat_ended', $message->getVideoChatEnded());
1226+
$sth->bindValue(':video_chat_participants_invited', $message->getVideoChatParticipantsInvited());
1227+
$sth->bindValue(':web_app_data', $message->getWebAppData());
12271228
$sth->bindValue(':reply_markup', $message->getReplyMarkup());
12281229

12291230
return $sth->execute();
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Longman\TelegramBot\Entities;
4+
5+
/**
6+
* Represents the rights of an administrator in a chat.
7+
*
8+
* @method bool getIsAnonymous() True, if the user's presence in the chat is hidden
9+
* @method bool getCanManageChat() 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
10+
* @method bool getCanDeleteMessages() True, if the administrator can delete messages of other users
11+
* @method bool getCanManageVideoChats() True, if the administrator can manage video chats
12+
* @method bool getCanRestrictMembers() True, if the administrator can restrict, ban or unban chat members
13+
* @method bool getCanPromoteMembers() True, if the administrator can add new administrators with a subset of their own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by the user)
14+
* @method bool getCanChangeInfo() True, if the user is allowed to change the chat title, photo and other settings
15+
* @method bool getCanInviteUsers() True, if the user is allowed to invite new users to the chat
16+
* @method bool getCanPostMessages() Optional. True, if the administrator can post in the channel; channels only
17+
* @method bool getCanEditMessages() Optional. True, if the administrator can edit messages of other users and can pin messages; channels only
18+
* @method bool getCanPinMessages() Optional. True, if the user is allowed to pin messages; groups and supergroups only
19+
*
20+
* @method $this setIsAnonymous(bool $is_anonymous) True, if the user's presence in the chat is hidden
21+
* @method $this setCanManageChat(bool $can_manage_chat) 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
22+
* @method $this setCanDeleteMessages(bool $can_delete_messages) True, if the administrator can delete messages of other users
23+
* @method $this setCanManageVideoChats(bool $can_manage_video_chats) True, if the administrator can manage video chats
24+
* @method $this setCanRestrictMembers(bool $can_restrict_members) True, if the administrator can restrict, ban or unban chat members
25+
* @method $this setCanPromoteMembers(bool $can_promote_members) True, if the administrator can add new administrators with a subset of their own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by the user)
26+
* @method $this setCanChangeInfo(bool $can_change_info) True, if the user is allowed to change the chat title, photo and other settings
27+
* @method $this setCanInviteUsers(bool $can_invite_users) True, if the user is allowed to invite new users to the chat
28+
* @method $this setCanPostMessages(bool $can_post_messages) Optional. True, if the administrator can post in the channel; channels only
29+
* @method $this setCanEditMessages(bool $can_edit_messages) Optional. True, if the administrator can edit messages of other users and can pin messages; channels only
30+
* @method $this setCanPinMessages(bool $can_pin_messages) Optional. True, if the user is allowed to pin messages; groups and supergroups only
31+
*/
32+
class ChatAdministratorRights extends Entity
33+
{
34+
35+
}

src/Entities/ChatMember/ChatMemberAdministrator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* @method bool getCanPostMessages() True, if the administrator can post in the channel; channels only
2020
* @method bool getCanEditMessages() True, if the administrator can edit messages of other users and can pin messages; channels only
2121
* @method bool getCanDeleteMessages() True, if the administrator can delete messages of other users
22-
* @method bool getCanManageVoiceChats() True, if the administrator can manage voice chats
22+
* @method bool getCanManageVideoChats() True, if the administrator can manage video chats
2323
* @method bool getCanRestrictMembers() True, if the administrator can restrict, ban or unban chat members
2424
* @method bool getCanPromoteMembers() True, if the administrator can add new administrators with a subset of their own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by the user)
2525
* @method bool getCanChangeInfo() True, if the user is allowed to change the chat title, photo and other settings

src/Entities/Factory.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ abstract class Factory
66
{
77
abstract public static function make(array $data, string $bot_username): Entity;
88

9-
public static function resolveEntityClass(string $class, array $property, string $bot_username = ''): Entity
9+
public static function resolveEntityClass(string $class, mixed $property, string $bot_username = ''): Entity
1010
{
11+
if (is_a($property, $class)) {
12+
return $property;
13+
}
14+
1115
if (is_subclass_of($class, Factory::class)) {
1216
return $class::make($property, $bot_username);
1317
}

src/Entities/InlineKeyboardButton.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@
2323
* @method string getUrl() Optional. HTTP url to be opened when button is pressed
2424
* @method LoginUrl getLoginUrl() Optional. An HTTP URL used to automatically authorize the user. Can be used as a replacement for the Telegram Login Widget.
2525
* @method string getCallbackData() Optional. Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes
26+
* @method WebAppInfo getWebApp() Optional. Description of the Web App that will be launched when the user presses the button. The Web App will be able to send an arbitrary message on behalf of the user using the method answerWebAppQuery. Available only in private chats between a user and the bot.
2627
* @method string getSwitchInlineQuery() Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot's username and the specified inline query in the input field. Can be empty, in which case just the bot’s username will be inserted.
2728
* @method string getSwitchInlineQueryCurrentChat() Optional. If set, pressing the button will insert the bot‘s username and the specified inline query in the current chat's input field. Can be empty, in which case only the bot’s username will be inserted.
2829
* @method CallbackGame getCallbackGame() Optional. Description of the game that will be launched when the user presses the button.
2930
* @method bool getPay() Optional. Specify True, to send a Pay button.
3031
*
3132
* @method $this setText(string $text) Label text on the button
3233
* @method $this setUrl(string $url) Optional. HTTP url to be opened when button is pressed
33-
* @method $this setLoginUrl(LoginUrl $login_url) Optional. HTTP url to be opened when button is pressed
34+
* @method $this setLoginUrl(LoginUrl $login_url) Optional. HTTP url to be opened when button is pressed
3435
* @method $this setCallbackData(string $callback_data) Optional. Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes
36+
* @method $this setWebApp(WebAppInfo $web_app) Optional. Description of the Web App that will be launched when the user presses the button. The Web App will be able to send an arbitrary message on behalf of the user using the method answerWebAppQuery. Available only in private chats between a user and the bot.
3537
* @method $this setSwitchInlineQuery(string $switch_inline_query) Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot's username and the specified inline query in the input field. Can be empty, in which case just the bot’s username will be inserted.
3638
* @method $this setSwitchInlineQueryCurrentChat(string $switch_inline_query_current_chat) Optional. If set, pressing the button will insert the bot‘s username and the specified inline query in the current chat's input field. Can be empty, in which case only the bot’s username will be inserted.
3739
* @method $this setCallbackGame(CallbackGame $callback_game) Optional. Description of the game that will be launched when the user presses the button.
@@ -52,6 +54,7 @@ public static function couldBe(array $data): bool
5254
array_key_exists('url', $data) ||
5355
array_key_exists('login_url', $data) ||
5456
array_key_exists('callback_data', $data) ||
57+
array_key_exists('web_app', $data) ||
5558
array_key_exists('switch_inline_query', $data) ||
5659
array_key_exists('switch_inline_query_current_chat', $data) ||
5760
array_key_exists('callback_game', $data) ||
@@ -70,7 +73,7 @@ protected function validate(): void
7073

7174
$num_params = 0;
7275

73-
foreach (['url', 'login_url', 'callback_data', 'callback_game', 'pay'] as $param) {
76+
foreach (['url', 'login_url', 'callback_data', 'web_app', 'callback_game', 'pay'] as $param) {
7477
if ($this->getProperty($param, '') !== '') {
7578
$num_params++;
7679
}
@@ -83,7 +86,7 @@ protected function validate(): void
8386
}
8487

8588
if ($num_params !== 1) {
86-
throw new TelegramException('You must use only one of these fields: url, login_url, callback_data, switch_inline_query, switch_inline_query_current_chat, callback_game, pay!');
89+
throw new TelegramException('You must use only one of these fields: url, login_url, callback_data, web_app, switch_inline_query, switch_inline_query_current_chat, callback_game, pay!');
8790
}
8891
}
8992

@@ -93,8 +96,8 @@ protected function validate(): void
9396
public function __call($method, $args)
9497
{
9598
// Only 1 of these can be set, so clear the others when setting a new one.
96-
if (in_array($method, ['setUrl', 'setLoginUrl', 'setCallbackData', 'setSwitchInlineQuery', 'setSwitchInlineQueryCurrentChat', 'setCallbackGame', 'setPay'], true)) {
97-
unset($this->url, $this->login_url, $this->callback_data, $this->switch_inline_query, $this->switch_inline_query_current_chat, $this->callback_game, $this->pay);
99+
if (in_array($method, ['setUrl', 'setLoginUrl', 'setCallbackData', 'setWebApp', 'setSwitchInlineQuery', 'setSwitchInlineQueryCurrentChat', 'setCallbackGame', 'setPay'], true)) {
100+
unset($this->url, $this->login_url, $this->callback_data, $this->web_app, $this->switch_inline_query, $this->switch_inline_query_current_chat, $this->callback_game, $this->pay);
98101
}
99102

100103
return parent::__call($method, $args);

0 commit comments

Comments
 (0)