Skip to content

Commit de3521c

Browse files
authored
Merge pull request #1266 from php-telegram-bot/api-5.4
Bot API 5.4
2 parents d4964d4 + d7d766c commit de3521c

File tree

9 files changed

+157
-26
lines changed

9 files changed

+157
-26
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
77
### Notes
88
- [:ledger: View file changes][Unreleased][:page_with_curl: DB migration script][unreleased-sql-migration]
99
### Added
10+
- Bot API 5.4. (@TiiFuchs, @noplanman) (#1266)
1011
### Changed
1112
### Deprecated
1213
### Removed

src/ChatAction.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,11 @@ class ChatAction
3333
*/
3434
public const UPLOAD_VIDEO = 'upload_video';
3535

36-
/**
37-
* Record Audio chat action
38-
*
39-
* @deprecated Use ChatAction::RECORD_VOICE instead
40-
*/
41-
public const RECORD_AUDIO = 'record_voice';
42-
4336
/**
4437
* Record Voice chat action
4538
*/
4639
public const RECORD_VOICE = 'record_voice';
4740

48-
/**
49-
* Upload Audio chat action
50-
*
51-
* @deprecated Use ChatAction::UPLOAD_VOICE instead
52-
*/
53-
public const UPLOAD_AUDIO = 'upload_voice';
54-
5541
/**
5642
* Upload Voice chat action
5743
*/
@@ -62,6 +48,11 @@ class ChatAction
6248
*/
6349
public const UPLOAD_DOCUMENT = 'upload_document';
6450

51+
/**
52+
* Choose Sticker chat action
53+
*/
54+
public const CHOOSE_STICKER = 'choose_sticker';
55+
6556
/**
6657
* Find Location chat action
6758
*/

src/DB.php

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ protected static function insertTelegramUpdate(
348348
?string $poll_id = null,
349349
?string $poll_answer_poll_id = null,
350350
?string $my_chat_member_updated_id = null,
351-
?string $chat_member_updated_id = null
351+
?string $chat_member_updated_id = null,
352+
?string $chat_join_request_id = null
352353
): ?bool {
353354
if ($message_id === null && $edited_message_id === null && $channel_post_id === null && $edited_channel_post_id === null && $inline_query_id === null && $chosen_inline_result_id === null && $callback_query_id === null && $shipping_query_id === null && $pre_checkout_query_id === null && $poll_id === null && $poll_answer_poll_id === null && $my_chat_member_updated_id === null && $chat_member_updated_id === null) {
354355
throw new TelegramException('message_id, edited_message_id, channel_post_id, edited_channel_post_id, inline_query_id, chosen_inline_result_id, callback_query_id, shipping_query_id, pre_checkout_query_id, poll_id, poll_answer_poll_id, my_chat_member_updated_id, chat_member_updated_id are all null');
@@ -361,9 +362,19 @@ protected static function insertTelegramUpdate(
361362
try {
362363
$sth = self::$pdo->prepare('
363364
INSERT IGNORE INTO `' . TB_TELEGRAM_UPDATE . '`
364-
(`id`, `chat_id`, `message_id`, `edited_message_id`, `channel_post_id`, `edited_channel_post_id`, `inline_query_id`, `chosen_inline_result_id`, `callback_query_id`, `shipping_query_id`, `pre_checkout_query_id`, `poll_id`, `poll_answer_poll_id`, `my_chat_member_updated_id`, `chat_member_updated_id`)
365-
VALUES
366-
(:id, :chat_id, :message_id, :edited_message_id, :channel_post_id, :edited_channel_post_id, :inline_query_id, :chosen_inline_result_id, :callback_query_id, :shipping_query_id, :pre_checkout_query_id, :poll_id, :poll_answer_poll_id, :my_chat_member_updated_id, :chat_member_updated_id)
365+
(
366+
`id`, `chat_id`, `message_id`, `edited_message_id`,
367+
`channel_post_id`, `edited_channel_post_id`, `inline_query_id`, `chosen_inline_result_id`,
368+
`callback_query_id`, `shipping_query_id`, `pre_checkout_query_id`,
369+
`poll_id`, `poll_answer_poll_id`, `my_chat_member_updated_id`, `chat_member_updated_id`,
370+
`chat_join_request_id`
371+
) VALUES (
372+
:id, :chat_id, :message_id, :edited_message_id,
373+
:channel_post_id, :edited_channel_post_id, :inline_query_id, :chosen_inline_result_id,
374+
:callback_query_id, :shipping_query_id, :pre_checkout_query_id,
375+
:poll_id, :poll_answer_poll_id, :my_chat_member_updated_id, :chat_member_updated_id,
376+
:chat_join_request_id
377+
)
367378
');
368379

369380
$sth->bindValue(':id', $update_id);
@@ -381,6 +392,7 @@ protected static function insertTelegramUpdate(
381392
$sth->bindValue(':poll_answer_poll_id', $poll_answer_poll_id);
382393
$sth->bindValue(':my_chat_member_updated_id', $my_chat_member_updated_id);
383394
$sth->bindValue(':chat_member_updated_id', $chat_member_updated_id);
395+
$sth->bindValue(':chat_join_request_id', $chat_join_request_id);
384396

385397
return $sth->execute();
386398
} catch (PDOException $e) {
@@ -547,6 +559,7 @@ public static function insertRequest(Update $update): bool
547559
$poll_answer_poll_id = null;
548560
$my_chat_member_updated_id = null;
549561
$chat_member_updated_id = null;
562+
$chat_join_request_id = null;
550563

551564
if (($message = $update->getMessage()) && self::insertMessageRequest($message)) {
552565
$chat_id = $message->getChat()->getId();
@@ -578,6 +591,8 @@ public static function insertRequest(Update $update): bool
578591
$my_chat_member_updated_id = self::$pdo->lastInsertId();
579592
} elseif (($chat_member = $update->getChatMember()) && self::insertChatMemberUpdatedRequest($chat_member)) {
580593
$chat_member_updated_id = self::$pdo->lastInsertId();
594+
} elseif (($chat_join_request = $update->getChatJoinRequest()) && self::insertChatJoinRequestRequest($chat_join_request)) {
595+
$chat_join_request_id = self::$pdo->lastInsertId();
581596
} else {
582597
return false;
583598
}
@@ -597,7 +612,8 @@ public static function insertRequest(Update $update): bool
597612
$poll_id,
598613
$poll_answer_poll_id,
599614
$my_chat_member_updated_id,
600-
$chat_member_updated_id
615+
$chat_member_updated_id,
616+
$chat_join_request_id
601617
);
602618
}
603619

@@ -989,6 +1005,54 @@ public static function insertChatMemberUpdatedRequest(ChatMemberUpdated $chat_me
9891005
}
9901006
}
9911007

1008+
/**
1009+
* Insert chat join request into database
1010+
*
1011+
* @param ChatJoinRequest $chat_join_request
1012+
*
1013+
* @return bool If the insert was successful
1014+
* @throws TelegramException
1015+
*/
1016+
public static function insertChatJoinRequestRequest(ChatJoinRequest $chat_join_request): bool
1017+
{
1018+
if (!self::isDbConnected()) {
1019+
return false;
1020+
}
1021+
1022+
try {
1023+
$sth = self::$pdo->prepare('
1024+
INSERT INTO `' . TB_CHAT_MEMBER_UPDATED . '`
1025+
(`chat_id`, `user_id`, `date`, `bio`, `invite_link`, `created_at`)
1026+
VALUES
1027+
(:chat_id, :user_id, :date, :bio, :invite_link, :created_at)
1028+
');
1029+
1030+
$date = self::getTimestamp();
1031+
$chat_id = null;
1032+
$user_id = null;
1033+
1034+
if ($chat = $chat_join_request->getChat()) {
1035+
$chat_id = $chat->getId();
1036+
self::insertChat($chat, $date);
1037+
}
1038+
if ($user = $chat_join_request->getFrom()) {
1039+
$user_id = $user->getId();
1040+
self::insertUser($user, $date);
1041+
}
1042+
1043+
$sth->bindValue(':chat_id', $chat_id);
1044+
$sth->bindValue(':user_id', $user_id);
1045+
$sth->bindValue(':date', self::getTimestamp($chat_join_request->getDate()));
1046+
$sth->bindValue(':bio', $chat_join_request->getBio());
1047+
$sth->bindValue(':invite_link', $chat_join_request->getInviteLink());
1048+
$sth->bindValue(':created_at', $date);
1049+
1050+
return $sth->execute();
1051+
} catch (PDOException $e) {
1052+
throw new TelegramException($e->getMessage());
1053+
}
1054+
}
1055+
9921056
/**
9931057
* Insert Message request in db
9941058
*

src/Entities/ChatInviteLink.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@
1818
*
1919
* @link https://core.telegram.org/bots/api#chatinvitelink
2020
*
21-
* @method string GetInviteLink() The invite link. If the link was created by another chat administrator, then the second part of the link will be replaced with “…”
22-
* @method User getCreator() Creator of the link
23-
* @method bool getIsPrimary() True, if the link is primary
24-
* @method bool getIsRevoked() True, if the link is revoked
25-
* @method int getExpireDate() Optional. Point in time (Unix timestamp) when the link will expire or has been expired
26-
* @method int getMemberLimit() Optional. Maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999
21+
* @method string GetInviteLink() The invite link. If the link was created by another chat administrator, then the second part of the link will be replaced with “…”
22+
* @method User getCreator() Creator of the link
23+
* @method bool getCreatesJoinRequest() True, if users joining the chat via the link need to be approved by chat administrators
24+
* @method bool getIsPrimary() True, if the link is primary
25+
* @method bool getIsRevoked() True, if the link is revoked
26+
* @method string getName() Optional. Invite link name
27+
* @method int getExpireDate() Optional. Point in time (Unix timestamp) when the link will expire or has been expired
28+
* @method int getMemberLimit() Optional. Maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999
29+
* @method int getPendingJoinRequestCount() Optional. Number of pending join requests created using this link
2730
*/
2831
class ChatInviteLink extends Entity
2932
{

src/Entities/ChatJoinRequest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Longman\TelegramBot\Entities;
4+
5+
/**
6+
* Class ChatJoinRequest
7+
*
8+
* Represents a join request sent to a chat.
9+
*
10+
* @link https://core.telegram.org/bots/api#chatjoinrequest
11+
*
12+
* @method Chat getChat() Chat to which the request was sent
13+
* @method User getFrom() User that sent the join request
14+
* @method int getDate() Date the request was sent in Unix time
15+
* @method string getBio() Optional. Bio of the user.
16+
* @method ChatInviteLink getInviteLink() Optional. Chat invite link that was used by the user to send the join request
17+
*/
18+
class ChatJoinRequest extends Entity
19+
{
20+
21+
protected function subEntities(): array
22+
{
23+
return [
24+
'chat' => Chat::class,
25+
'from' => User::class,
26+
'invite_link' => ChatInviteLink::class,
27+
];
28+
}
29+
30+
}

src/Entities/Update.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
* @method PollAnswer getPollAnswer() Optional. A user changed their answer in a non-anonymous poll. Bots receive new votes only in polls that were sent by the bot itself.
3434
* @method ChatMemberUpdated getMyChatMember() 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.
3535
* @method ChatMemberUpdated getChatMember() 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.
36+
* @method ChatJoinRequest getChatJoinRequest() Optional. A request to join the chat has been sent. The bot must have the can_invite_users administrator right in the chat to receive these updates.
3637
*/
3738
class Update extends Entity
3839
{
@@ -49,6 +50,7 @@ class Update extends Entity
4950
public const TYPE_POLL_ANSWER = 'poll_answer';
5051
public const TYPE_MY_CHAT_MEMBER = 'my_chat_member';
5152
public const TYPE_CHAT_MEMBER = 'chat_member';
53+
public const TYPE_CHAT_JOIN_REQUEST = 'chat_join_request';
5254

5355
/**
5456
* {@inheritdoc}
@@ -69,6 +71,7 @@ protected function subEntities(): array
6971
self::TYPE_POLL_ANSWER => PollAnswer::class,
7072
self::TYPE_MY_CHAT_MEMBER => ChatMemberUpdated::class,
7173
self::TYPE_CHAT_MEMBER => ChatMemberUpdated::class,
74+
self::TYPE_CHAT_JOIN_REQUEST => ChatJoinRequest::class,
7275
];
7376
}
7477

src/Request.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
* @method static ServerResponse createChatInviteLink(array $data) 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 revokeChatInviteLink. Returns the new invite link as ChatInviteLink object.
6565
* @method static ServerResponse editChatInviteLink(array $data) 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 ChatInviteLink object.
6666
* @method static ServerResponse revokeChatInviteLink(array $data) 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 ChatInviteLink object.
67+
* @method static ServerResponse approveChatJoinRequest(array $data) Use this method to approve a chat join request. The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right. Returns True on success.
68+
* @method static ServerResponse declineChatJoinRequest(array $data) Use this method to decline a chat join request. The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right. Returns True on success.
6769
* @method static ServerResponse setChatPhoto(array $data) Use this method to set a new profile photo for the chat. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success.
6870
* @method static ServerResponse deleteChatPhoto(array $data) Use this method to delete a chat photo. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success.
6971
* @method static ServerResponse setChatTitle(array $data) Use this method to change the title of a chat. Titles can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success.
@@ -204,6 +206,8 @@ class Request
204206
'createChatInviteLink',
205207
'editChatInviteLink',
206208
'revokeChatInviteLink',
209+
'approveChatJoinRequest',
210+
'declineChatJoinRequest',
207211
'setChatPhoto',
208212
'deleteChatPhoto',
209213
'setChatTitle',

structure.sql

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,21 @@ CREATE TABLE IF NOT EXISTS `chat_member_updated` (
260260
FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
261261
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
262262

263+
CREATE TABLE IF NOT EXISTS `chat_join_request` (
264+
`id` BIGINT UNSIGNED AUTO_INCREMENT COMMENT 'Unique identifier for this entry',
265+
`chat_id` BIGINT NOT NULL COMMENT 'Chat to which the request was sent',
266+
`user_id` BIGINT NOT NULL COMMENT 'User that sent the join request',
267+
`date` TIMESTAMP NOT NULL COMMENT 'Date the request was sent in Unix time',
268+
`bio` TEXT NOT NULL COMMENT 'Optional. Bio of the user',
269+
`invite_link` TEXT NULL COMMENT 'Optional. Chat invite link that was used by the user to send the join request',
270+
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
271+
272+
PRIMARY KEY (`id`),
273+
274+
FOREIGN KEY (`chat_id`) REFERENCES `chat` (`id`),
275+
FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
276+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
277+
263278
CREATE TABLE IF NOT EXISTS `telegram_update` (
264279
`id` bigint UNSIGNED COMMENT 'Update''s unique identifier',
265280
`chat_id` bigint NULL DEFAULT NULL COMMENT 'Unique chat identifier',
@@ -276,6 +291,7 @@ CREATE TABLE IF NOT EXISTS `telegram_update` (
276291
`poll_answer_poll_id` bigint UNSIGNED DEFAULT NULL COMMENT 'A user changed their answer in a non-anonymous poll. Bots receive new votes only in polls that were sent by the bot itself.',
277292
`my_chat_member_updated_id` BIGINT UNSIGNED NULL COMMENT '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.',
278293
`chat_member_updated_id` BIGINT UNSIGNED NULL COMMENT '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.',
294+
`chat_join_request_id` BIGINT UNSIGNED NULL COMMENT 'A request to join the chat has been sent',
279295

280296
PRIMARY KEY (`id`),
281297
KEY `message_id` (`message_id`),
@@ -292,6 +308,7 @@ CREATE TABLE IF NOT EXISTS `telegram_update` (
292308
KEY `poll_answer_poll_id` (`poll_answer_poll_id`),
293309
KEY `my_chat_member_updated_id` (`my_chat_member_updated_id`),
294310
KEY `chat_member_updated_id` (`chat_member_updated_id`),
311+
KEY `chat_join_request_id` (`chat_join_request_id`),
295312

296313
FOREIGN KEY (`chat_id`, `message_id`) REFERENCES `message` (`chat_id`, `id`),
297314
FOREIGN KEY (`edited_message_id`) REFERENCES `edited_message` (`id`),
@@ -305,7 +322,8 @@ CREATE TABLE IF NOT EXISTS `telegram_update` (
305322
FOREIGN KEY (`poll_id`) REFERENCES `poll` (`id`),
306323
FOREIGN KEY (`poll_answer_poll_id`) REFERENCES `poll_answer` (`poll_id`),
307324
FOREIGN KEY (`my_chat_member_updated_id`) REFERENCES `chat_member_updated` (`id`),
308-
FOREIGN KEY (`chat_member_updated_id`) REFERENCES `chat_member_updated` (`id`)
325+
FOREIGN KEY (`chat_member_updated_id`) REFERENCES `chat_member_updated` (`id`),
326+
FOREIGN KEY (`chat_join_request_id`) REFERENCES `chat_join_request` (`id`)
309327
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
310328

311329
CREATE TABLE IF NOT EXISTS `conversation` (
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
CREATE TABLE IF NOT EXISTS `chat_join_request` (
2+
`id` BIGINT UNSIGNED AUTO_INCREMENT COMMENT 'Unique identifier for this entry',
3+
`chat_id` BIGINT NOT NULL COMMENT 'Chat to which the request was sent',
4+
`user_id` BIGINT NOT NULL COMMENT 'User that sent the join request',
5+
`date` TIMESTAMP NOT NULL COMMENT 'Date the request was sent in Unix time',
6+
`bio` TEXT NOT NULL COMMENT 'Optional. Bio of the user',
7+
`invite_link` TEXT NULL COMMENT 'Optional. Chat invite link that was used by the user to send the join request',
8+
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
9+
10+
PRIMARY KEY (`id`),
11+
12+
FOREIGN KEY (`chat_id`) REFERENCES `chat` (`id`),
13+
FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
14+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
15+
16+
ALTER TABLE `telegram_update` ADD COLUMN `chat_join_request_id` BIGINT UNSIGNED NULL COMMENT 'A request to join the chat has been sent';
17+
ALTER TABLE `telegram_update` ADD FOREIGN KEY (`chat_join_request_id`) REFERENCES `chat_join_request` (`id`);

0 commit comments

Comments
 (0)