Skip to content

Commit

Permalink
Merge branch 'api-6.0' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
TiiFuchs committed Apr 24, 2022
2 parents ab14185 + 27cc26c commit 1c6c9aa
Show file tree
Hide file tree
Showing 33 changed files with 456 additions and 61 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
### Notes
- [:ledger: View file changes][Unreleased]
### Added
- Bot API 6.0 See https://core.telegram.org/bots/api#april-16-2022 (@TiiFuchs)
### Changed
### Deprecated
- 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.
To reflect that change we marked the corresponding VoiceChat classes as deprecated and created new classes for the VideoChat events.
### Removed
### Fixed
### Security
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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

[![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)
[![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)
[![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)
[![Donate](https://img.shields.io/badge/%F0%9F%92%99-Donate%20%2F%20Support%20Us-blue.svg)](#donate)

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

The Bot can:
- Retrieve updates with [webhook](#webhook-installation) and [getUpdates](#getupdates-installation) methods.
- Supports all types and methods according to Telegram Bot API 5.7 (January 2022).
- Supports all types and methods according to Telegram Bot API 6.0 (April 2022).
- Supports supergroups.
- Handle commands in chat with other bots.
- Manage Channel from the bot admin interface.
Expand Down
13 changes: 7 additions & 6 deletions src/DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ public static function insertMessageRequest(Message $message): bool
`new_chat_title`, `new_chat_photo`, `delete_chat_photo`, `group_chat_created`,
`supergroup_chat_created`, `channel_chat_created`, `message_auto_delete_timer_changed`, `migrate_to_chat_id`, `migrate_from_chat_id`,
`pinned_message`, `invoice`, `successful_payment`, `connected_website`, `passport_data`, `proximity_alert_triggered`,
`voice_chat_scheduled`, `voice_chat_started`, `voice_chat_ended`, `voice_chat_participants_invited`, `reply_markup`
`video_chat_scheduled`, `video_chat_started`, `video_chat_ended`, `video_chat_participants_invited`, `web_app_data`, `reply_markup`
) VALUES (
:message_id, :user_id, :chat_id, :sender_chat_id, :date, :forward_from, :forward_from_chat, :forward_from_message_id,
:forward_signature, :forward_sender_name, :forward_date,
Expand All @@ -1147,7 +1147,7 @@ public static function insertMessageRequest(Message $message): bool
:new_chat_title, :new_chat_photo, :delete_chat_photo, :group_chat_created,
:supergroup_chat_created, :channel_chat_created, :message_auto_delete_timer_changed, :migrate_to_chat_id, :migrate_from_chat_id,
:pinned_message, :invoice, :successful_payment, :connected_website, :passport_data, :proximity_alert_triggered,
:voice_chat_scheduled, :voice_chat_started, :voice_chat_ended, :voice_chat_participants_invited, :reply_markup
:video_chat_scheduled, :video_chat_started, :video_chat_ended, :video_chat_participants_invited, :web_app_data, :reply_markup
)
');

Expand Down Expand Up @@ -1220,10 +1220,11 @@ public static function insertMessageRequest(Message $message): bool
$sth->bindValue(':connected_website', $message->getConnectedWebsite());
$sth->bindValue(':passport_data', $message->getPassportData());
$sth->bindValue(':proximity_alert_triggered', $message->getProximityAlertTriggered());
$sth->bindValue(':voice_chat_scheduled', $message->getVoiceChatScheduled());
$sth->bindValue(':voice_chat_started', $message->getVoiceChatStarted());
$sth->bindValue(':voice_chat_ended', $message->getVoiceChatEnded());
$sth->bindValue(':voice_chat_participants_invited', $message->getVoiceChatParticipantsInvited());
$sth->bindValue(':video_chat_scheduled', $message->getVideoChatScheduled());
$sth->bindValue(':video_chat_started', $message->getVideoChatStarted());
$sth->bindValue(':video_chat_ended', $message->getVideoChatEnded());
$sth->bindValue(':video_chat_participants_invited', $message->getVideoChatParticipantsInvited());
$sth->bindValue(':web_app_data', $message->getWebAppData());
$sth->bindValue(':reply_markup', $message->getReplyMarkup());

return $sth->execute();
Expand Down
35 changes: 35 additions & 0 deletions src/Entities/ChatAdministratorRights.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Longman\TelegramBot\Entities;

/**
* Represents the rights of an administrator in a chat.
*
* @method bool getIsAnonymous() True, if the user's presence in the chat is hidden
* @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
* @method bool getCanDeleteMessages() True, if the administrator can delete messages of other users
* @method bool getCanManageVideoChats() True, if the administrator can manage video chats
* @method bool getCanRestrictMembers() True, if the administrator can restrict, ban or unban chat members
* @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)
* @method bool getCanChangeInfo() True, if the user is allowed to change the chat title, photo and other settings
* @method bool getCanInviteUsers() True, if the user is allowed to invite new users to the chat
* @method bool getCanPostMessages() Optional. True, if the administrator can post in the channel; channels only
* @method bool getCanEditMessages() Optional. True, if the administrator can edit messages of other users and can pin messages; channels only
* @method bool getCanPinMessages() Optional. True, if the user is allowed to pin messages; groups and supergroups only
*
* @method $this setIsAnonymous(bool $is_anonymous) True, if the user's presence in the chat is hidden
* @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
* @method $this setCanDeleteMessages(bool $can_delete_messages) True, if the administrator can delete messages of other users
* @method $this setCanManageVideoChats(bool $can_manage_video_chats) True, if the administrator can manage video chats
* @method $this setCanRestrictMembers(bool $can_restrict_members) True, if the administrator can restrict, ban or unban chat members
* @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)
* @method $this setCanChangeInfo(bool $can_change_info) True, if the user is allowed to change the chat title, photo and other settings
* @method $this setCanInviteUsers(bool $can_invite_users) True, if the user is allowed to invite new users to the chat
* @method $this setCanPostMessages(bool $can_post_messages) Optional. True, if the administrator can post in the channel; channels only
* @method $this setCanEditMessages(bool $can_edit_messages) Optional. True, if the administrator can edit messages of other users and can pin messages; channels only
* @method $this setCanPinMessages(bool $can_pin_messages) Optional. True, if the user is allowed to pin messages; groups and supergroups only
*/
class ChatAdministratorRights extends Entity
{

}
2 changes: 1 addition & 1 deletion src/Entities/ChatMember/ChatMemberAdministrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @method bool getCanPostMessages() True, if the administrator can post in the channel; channels only
* @method bool getCanEditMessages() True, if the administrator can edit messages of other users and can pin messages; channels only
* @method bool getCanDeleteMessages() True, if the administrator can delete messages of other users
* @method bool getCanManageVoiceChats() True, if the administrator can manage voice chats
* @method bool getCanManageVideoChats() True, if the administrator can manage video chats
* @method bool getCanRestrictMembers() True, if the administrator can restrict, ban or unban chat members
* @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)
* @method bool getCanChangeInfo() True, if the user is allowed to change the chat title, photo and other settings
Expand Down
6 changes: 5 additions & 1 deletion src/Entities/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ abstract class Factory
{
abstract public static function make(array $data, string $bot_username): Entity;

public static function resolveEntityClass(string $class, array $property, string $bot_username = ''): Entity
public static function resolveEntityClass(string $class, mixed $property, string $bot_username = ''): Entity
{
if (is_a($property, $class)) {
return $property;
}

if (is_subclass_of($class, Factory::class)) {
return $class::make($property, $bot_username);
}
Expand Down
13 changes: 8 additions & 5 deletions src/Entities/InlineKeyboardButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@
* @method string getUrl() Optional. HTTP url to be opened when button is pressed
* @method LoginUrl getLoginUrl() Optional. An HTTP URL used to automatically authorize the user. Can be used as a replacement for the Telegram Login Widget.
* @method string getCallbackData() Optional. Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes
* @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.
* @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.
* @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.
* @method CallbackGame getCallbackGame() Optional. Description of the game that will be launched when the user presses the button.
* @method bool getPay() Optional. Specify True, to send a Pay button.
*
* @method $this setText(string $text) Label text on the button
* @method $this setUrl(string $url) Optional. HTTP url to be opened when button is pressed
* @method $this setLoginUrl(LoginUrl $login_url) Optional. HTTP url to be opened when button is pressed
* @method $this setLoginUrl(LoginUrl $login_url) Optional. HTTP url to be opened when button is pressed
* @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
* @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.
* @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.
* @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.
* @method $this setCallbackGame(CallbackGame $callback_game) Optional. Description of the game that will be launched when the user presses the button.
Expand All @@ -52,6 +54,7 @@ public static function couldBe(array $data): bool
array_key_exists('url', $data) ||
array_key_exists('login_url', $data) ||
array_key_exists('callback_data', $data) ||
array_key_exists('web_app', $data) ||
array_key_exists('switch_inline_query', $data) ||
array_key_exists('switch_inline_query_current_chat', $data) ||
array_key_exists('callback_game', $data) ||
Expand All @@ -70,7 +73,7 @@ protected function validate(): void

$num_params = 0;

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

if ($num_params !== 1) {
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!');
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!');
}
}

Expand All @@ -93,8 +96,8 @@ protected function validate(): void
public function __call($method, $args)
{
// Only 1 of these can be set, so clear the others when setting a new one.
if (in_array($method, ['setUrl', 'setLoginUrl', 'setCallbackData', 'setSwitchInlineQuery', 'setSwitchInlineQueryCurrentChat', 'setCallbackGame', 'setPay'], true)) {
unset($this->url, $this->login_url, $this->callback_data, $this->switch_inline_query, $this->switch_inline_query_current_chat, $this->callback_game, $this->pay);
if (in_array($method, ['setUrl', 'setLoginUrl', 'setCallbackData', 'setWebApp', 'setSwitchInlineQuery', 'setSwitchInlineQueryCurrentChat', 'setCallbackGame', 'setPay'], true)) {
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);
}

return parent::__call($method, $args);
Expand Down
Loading

0 comments on commit 1c6c9aa

Please sign in to comment.